security_check();
if ($resultat_session == 'c') {
header("Location: ../utilisateurs/mon_compte.php?change_mdp=yes");
die();
} else if ($resultat_session == '0') {
header("Location: ../logout.php?auto=1");
die();
}
// Check access
if (!checkAccess()) {
header("Location: ../logout.php?auto=1");
die();
}
// Pour garder une trace du retour
$_SESSION["retour"] = 'admin_ct';
// Suppression d'un ou plusieurs cahiers de texte
if (isset($_POST['sup_ct'])) {
check_token();
//$sql="SELECT DISTINCT id_groupe, id_login FROM ct_entry ORDER BY id_groupe;";
$sql="SELECT DISTINCT id_groupe FROM ct_entry ORDER BY id_groupe;";
//echo "$sql
\n";
$query = sql_query($sql);
$msg = '';
for ($i=0; ($row=sql_row($query,$i)); $i++) {
$id_groupe = $row[0];
//$id_prop = $row[1];
//$temp = "sup".$id_groupe."_".$id_prop;
$temp = "sup".$id_groupe;
//echo "\$temp=$temp
\n";
if (isset($_POST[$temp])) {
$id_prop=$_POST[$temp];
$error = 'no';
$sql="SELECT id_ct FROM ct_entry WHERE (id_groupe='".$id_groupe."' and id_login = '".$id_prop."');";
//echo "$sql
\n";
$appel_ct=sql_query($sql);
if (($appel_ct) and (sql_count($appel_ct)!=0)) {
for ($k=0; ($row2 = sql_row($appel_ct,$k)); $k++) {
$id_ctexte = $row2[0];
$sql="select emplacement from ct_documents where id_ct='".$id_ctexte."';";
//echo "$sql
\n";
$appel_doc = sql_query($sql);
for ($j=0; ($row3 = sql_row($appel_doc,$j)); $j++) {
$empl = $row3[0];
if ($empl != -1) $del = @unlink($empl);
}
$sql="delete from ct_documents where id_ct='".$id_ctexte."';";
//echo "$sql
\n";
$del_doc = sql_query($sql);
if (!($del_doc)) $error = 'yes';
$sql="delete from ct_entry where id_ct = '".$id_ctexte."';";
//echo "$sql
\n";
$del_ct = sql_query($sql);
if (!($del_ct)) $error = 'yes';
}
if ($error == 'no') {
$msg .= "Suppression des notices dans ct_entry réussie pour $id_prop sur le groupe n°$id_groupe.
";
} else {
$msg .= "Il y a eu un problème lors de la suppression des notices dans ct_entry pour $id_prop sur le groupe n°$id_groupe.
";
}
} else {
$msg .= "Pas de notice à supprimer dans ct_entry pour $id_prop sur le groupe n°$id_groupe.
";
}
}
}
//$sql="SELECT DISTINCT id_groupe, id_login FROM ct_devoirs_entry ORDER BY id_groupe;";
$sql="SELECT DISTINCT id_groupe FROM ct_devoirs_entry ORDER BY id_groupe;";
//echo "$sql
\n";
$query = sql_query($sql);
for ($i=0; ($row=sql_row($query,$i)); $i++) {
$id_groupe = $row[0];
//$id_prop = $row[1];
//$temp = "sup".$id_groupe."_".$id_prop;
$temp = "sup".$id_groupe;
if (isset($_POST[$temp])) {
$id_prop=$_POST[$temp];
$error = 'no';
$sql="SELECT id_ct FROM ct_devoirs_entry WHERE (id_groupe='".$id_groupe."' and id_login = '".$id_prop."');";
//echo "$sql
\n";
$appel_ct_devoirs_entry=sql_query($sql);
if (($appel_ct_devoirs_entry) and (sql_count($appel_ct_devoirs_entry)!=0)) {
$del_ct_devoirs = sql_query("delete FROM ct_devoirs_entry WHERE (id_groupe='".$id_groupe."' and id_login = '".$id_prop."')");
if (!($del_ct_devoirs)) {$error = 'yes';}
if ($error == 'no') {
$msg .= "Suppression des notices dans ct_devoirs_entry réussie pour $id_prop sur le groupe n°$id_groupe.
";
} else {
$msg .= "Il y a eu un problème lors de la suppression des notices dans ct_devoirs_entry pour $id_prop sur le groupe n°$id_groupe.
";
}
} else {
$msg .= "Pas de notice à supprimer dans ct_devoirs_entry pour $id_prop sur le groupe n°$id_groupe.
";
}
}
}
//$sql="SELECT DISTINCT id_groupe, id_login FROM ct_private_entry ORDER BY id_groupe;";
$sql="SELECT DISTINCT id_groupe FROM ct_private_entry ORDER BY id_groupe;";
$query=sql_query($sql);
for ($i=0; ($row=sql_row($query,$i)); $i++) {
$id_groupe = $row[0];
//$id_prop = $row[1];
//$temp = "sup".$id_groupe."_".$id_prop;
$temp = "sup".$id_groupe;
if (isset($_POST[$temp])) {
$id_prop=$_POST[$temp];
$error = 'no';
$sql="SELECT id_ct FROM ct_private_entry WHERE (id_groupe='".$id_groupe."' and id_login = '".$id_prop."');";
//echo "$sql
\n";
$appel_ct_private_entry=sql_query($sql);
if (($appel_ct_private_entry) and (sql_count($appel_ct_private_entry)!=0)) {
$del_ct_devoirs = sql_query("delete FROM ct_private_entry WHERE (id_groupe='".$id_groupe."' and id_login = '".$id_prop."')");
if (!($del_ct_devoirs)) $error = 'yes';
if ($error == 'no') {
$msg .= "Suppression des notices dans ct_private_entry réussie pour $id_prop sur le groupe n°$id_groupe.
";
} else {
$msg .= "Il y a eu un problème lors de la suppression des notices dans ct_devoirs_entry pour $id_prop sur le groupe n°$id_groupe.
";
}
} else {
$msg .= "Pas de notice à supprimer dans ct_private_entry pour $id_prop sur le groupe n°$id_groupe.
";
}
}
}
}
// Modification d'un cahier de texte - Etape 2
if (isset($_POST['action'])) {
check_token();
$id_groupe = $_POST['id_groupe'];
$id_prop = $_POST['id_prop'];
if ($_POST['action'] == 'change_groupe') {
$id_former_group = $_POST['id_former_group'];
$sql1 = sql_query("UPDATE ct_entry SET id_groupe='".$id_groupe."' WHERE (id_groupe='".$id_former_group."' and id_login='".$id_prop."')");
$sql2 = sql_query("UPDATE ct_devoirs_entry SET id_groupe='".$id_groupe."' WHERE (id_groupe='".$id_former_group."' and id_login='".$id_prop."')");
if (($sql1) and ($sql2)) {
$msg = "Le changement de groupe a été effectué.";
} else {
$msg = "Il y a eu un problème lors du changement de groupe.";
}
}
if ($_POST['action'] == 'change_prop') {
$sql1 = sql_query("UPDATE ct_entry SET id_login='".$id_prop."' WHERE (id_groupe='".$id_groupe."')");
$sql2 = sql_query("UPDATE ct_entry SET id_login='".$id_prop."' WHERE (id_groupe='".$id_groupe."')");
if (($sql1) and ($sql2)) {
$msg = "Le changement de propriétaire a été effectué.";
} else {
$msg = "Il y a eu un problème lors du changement de propriétaire.";
}
}
}
//===================================================
// header
$titre_page = "Administration des cahiers de texte";
require_once("../lib/header.inc.php");
//===================================================
//debug_var();
// Modification d'un cahier de texte - Etape 1
if (isset($_GET['action'])) {
check_token(false);
echo "
Le tableau ci-dessous présentent l'ensemble des cahiers de texte actuellement en ligne. Les problèmes sont signalés en rouge.
Vous pouvez modifier le groupe ou le propriétaire d'un cahier de texte en cliquant sur le lien correspondant.
Vous pouvez également supprimer définitivement un cahier de texte (notices et documents joints).