FrameBeurk File
Fmbk/Module/Rhum/Sujet/Maj/deplaceSujet.php
<?php //FrameBeurk V0.65 Copyright ToolOscope 2016. Licence CeCILL-C.
//lecture de la section où placer le sujet
$result1 = db_QUERY("SELECT IdEtat FROM Rhum_Section WHERE IdSection = '$IdLie'");
if (list($IdEtatSection) = db_FETCH_ROW($result1)) {
if ($IdEtatSection != Beurk_id('V'))
Beurk_messageEtape('Section fermée', true, 'IdLie');
else {
$result2 = db_QUERY("SELECT IdSection, IdEtat, IdSujetRef, NoVersion FROM Rhum_Sujet WHERE IdSujet = '$IdMaj'");
if (list($IdSection, $IdEtatSujet, $IdSujetRef, $NoVersionCourante) = db_FETCH_ROW($result2)) {
if ($IdSection == $IdLie)
Beurk_messageEtape('Sujet déjà dans cette section', true, 'IdLie');
elseif ($IdSujetRef != 0 && $IdSujetRef != $IdMaj)
Beurk_messageEtape('Ce sujet est une suite', true, 'IdLie'); // --> déplacer le sujet initial !
else {
if ($IdSujetRef == 0) { // pas de suite à ce sujet
$requete = array('UPDATE' => 'Rhum_Sujet',
'SET' => array('IdSection' => $IdLie), //IdEtat et Version mis à jour par Beurk_modifieEntite
'WHERE' => "IdSujet = '$IdMaj'");
if (Beurk_modifieEntite($requete, 'Sujet déplacé', $IdEtatSujet, $NoVersionCourante, $IdMaj))
Beurk_modifieRelation($IdMaj, $CONFIG['Relation']['estElementDe']['Id'], $IdSection, $IdLie);
} else { // sujet avec suite(s)
$requete = "UPDATE Rhum_Sujet SET IdSection = '$IdLie', NoVersion = NoVersion + 1 WHERE IdSujetRef = '$IdSujetRef'";
db_QUERY($requete);
// création des nouvelles versions des noeuds sujets
$requete = "INSERT INTO Beurk_Historique (IdNoeud, NoVersion, IdEtat, IdUser, AdresseIp, IdActMaj, IdMaj, TsAction)
SELECT IdSujet, NoVersion, IdEtat, '" . $DIALOG['IdUser'] . "', '" . $_SERVER['REMOTE_ADDR'] . "', '" . $CONFIG['Action'][$ActMaj]['Id'] . "', '" . $IdMaj . "', '" . $DIALOG['TempsDebSession'] . "'
FROM Rhum_Sujet WHERE IdSujetRef = '$IdSujetRef'";
if (! db_QUERY($requete))
Beurk_messageEtape('Modification des noeuds sujets en erreur', true);
// mise à jour des relations
db_QUERY("UPDATE Beurk_Lien SET IdLie = '" . $IdLie . "'
WHERE IdRelation = '" . $CONFIG['Relation']['estElementDe']['Id'] . "' AND IdLie = '" . $IdSection . "' AND IdNoeud IN
(SELECT IdSujet FROM Rhum_Sujet WHERE IdSujetRef = '" . $IdSujetRef . "')");
}
if ($TRANSAC['Maj']['Erreur'] == false) {
// mise à jour des sections (noeuds inchangés)
if ($IdEtatSujet == Beurk_id('R')) { // si le sujet est archivé
db_QUERY('UPDATE Rhum_Section SET NbrSujetsArchives = NbrSujetsArchives + 1, TsMajElements = ' . $TRANSAC['Stat']['TsBeurkIni'] . " WHERE IdSection = '$IdLie'");
db_QUERY("UPDATE Rhum_Section SET NbrSujetsArchives = NbrSujetsArchives - 1 WHERE IdSection = '$IdSection'");
} else {
db_QUERY('UPDATE Rhum_Section SET NbrSujets = NbrSujets + 1, TsMajElements = ' . $TRANSAC['Stat']['TsBeurkIni'] . " WHERE IdSection = '$IdLie'");
db_QUERY("UPDATE Rhum_Section SET NbrSujets = NbrSujets - 1 WHERE IdSection = '$IdSection'");
}
}
}
} else Beurk_messageEtape('Sujet inconnu', true);
db_FREE($result2);
}
} else Beurk_messageEtape('Section inconnue', true);
db_FREE($result1);