Files
MYSOPHAL/ajax/publication.php
2025-08-07 13:15:31 +01:00

74 lines
2.4 KiB
PHP

<?php
if (!defined('GLPI_ROOT')) {
define('GLPI_ROOT', dirname(__DIR__));
}
include_once GLPI_ROOT . '/inc/based_config.php';
include ('../front/publications_fonctions.php');
// Init Timer to compute time of display
$TIMER_DEBUG = new Timer();
$TIMER_DEBUG->start();
/// TODO try to remove them if possible
include_once (GLPI_ROOT . "/inc/db.function.php");
// Standard includes
include_once (GLPI_ROOT . "/inc/config.php");
//disbled errors =>pour le variable res (Ajax)
ini_set('display_errors', 0);
Session::checkLoginUser();
global $DB;
// print("<pre>".print_r($_POST,true)."</pre>");
//print("<pre>".print_r($_FILES,true)."</pre>");
if(isset($_POST)){
switch ($_POST['function']) {
case "publication":
if( $_POST["action"] == 'add'){
addPublication($_POST , $_FILES);
Html::redirect($CFG_GLPI["root_doc"]."/front/publications.php");
}else if($_POST["action"] == 'update'){
updatePublication($_POST , $_FILES);
Html::redirect($CFG_GLPI["root_doc"]."/front/publications.php");
}else if($_POST["action"] == 'delete'){
deletePublication($_POST);
}
break;
case "jaime":
if( $_POST["value"] != 'deleted'){
$isJaime = isJaime($_POST["id_publication"] , $_SESSION["glpiID"]);
if($isJaime == false){
$stmt = $DB->prepare("INSERT INTO publication_reactions( id_publication , id_user , type , reaction) VALUES ( ? , ? , 'jaime' , ? )");
$stmt->bind_param("iis",$_POST["id_publication"], $_SESSION["glpiID"] , $_POST["value"]);
$stmt->execute();
}else{
$stmt = $DB->prepare("UPDATE publication_reactions SET reaction = ? where id_publication = ? and id_user = ? and type ='jaime' ");
$stmt->bind_param("sii", $_POST["value"] , $_POST["id_publication"] , $_SESSION["glpiID"]);
$stmt->execute();
}
}else if( $_POST["value"] == 'deleted'){
//$DB->query("DELETE FROM publication_reactions WHERE id_publication='".(int)$_POST["id_publication"]."' and id_user = '".$_SESSION["glpiID"]."' and type = 'jaime' ");
}
break;
case "commentaire":
if( $_POST["action"] == 'add'){
addCommentaire($_POST);
}elseif( $_POST["action"] == 'update'){
//updateCommentaire($_POST);
}elseif( $_POST["action"] == 'delete'){
//deleteCommentaire($_POST);
}
break;
}
}