<?php
class Contenu extends BaseModel
{
    public static $tableName = 'contenu';
    public function __construct()
    {

    }

    public static function ajouter()
    {
        global $BD;



        if (isset($_FILES["document"]) AND strlen($_FILES["document"]["name"])>0) {
            $folder = '../media/';
            $tmp_name = $_FILES["document"]["tmp_name"];

            $name = $_FILES["document"]["name"];

            $img = pathinfo($_FILES["document"]['name']);
            $lien = "fichier".$_REQUEST['id'].'.'.$img["extension"];
            move_uploaded_file($tmp_name, $folder.$lien);

            $insert = $BD->prepare("UPDATE `contenu` SET `couverture`=? WHERE id=?");
            $insert->execute(array($lien,$_REQUEST['id']));
        }
        
        if (isset($_REQUEST['description'])) {
            $insert = $BD->prepare("UPDATE contenu SET contenu=? WHERE id=?");
            $insert->execute(array($_REQUEST["description"],$_REQUEST['id']
            )) or die('Erreur : ' . $insert->errorInfo()[2]);
        }
        

        if ($_REQUEST['id'] == 1) {
            header('Location: ../objectif');
        }
        if ($_REQUEST['id'] == 2) {
            header('Location: ../presentation');
        }
        if ($_REQUEST['id'] == 3) {
            header('Location: ../presentation2');
        }
        if ($_REQUEST['id'] == 4) {
            header('Location: ../presentation3');
        }
        if ($_REQUEST['id'] == 5) {
            header('Location: ../organigramme');
        }
        if ($_REQUEST['id'] == 6) {
            header('Location: ../planning');
        }
        if ($_REQUEST['id'] == 7) {
            header('Location: ../candotraining');
        }

    }
    public static function modifier()
    {
        global $BD;

        $insert = $BD->prepare("UPDATE `caracteristique` SET `idcategorie`=?, `intitule`=?, `type`=? WHERE id=?");
        $insert->execute(array(
            $_REQUEST["idcategorie"], $_REQUEST["intitule"], $_REQUEST["type"],$_REQUEST['id']
        )) or die('Erreur : ' . $insert->errorInfo()[2]);

        header('Location: ../caracteristique');

    }
    public static function delete()
    {
        global $BD;

        $delete = $BD->query("DELETE FROM caracteristique WHERE id IN (".$_REQUEST['id'].")");
        header('Location: ../caracteristique');
    }
}