/
admin_room_del.php
153 lines (153 loc) · 6.18 KB
/
admin_room_del.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* admin_room_del
* Interface de confirmation de suppression d'un domaine ou d'une ressource
* de l'application GRR
* Dernière modification : $Date: 2009-09-29 18:02:56 $
* @author Laurent Delineau <laurent.delineau@ac-poitiers.fr>
* @copyright Copyright 2003-2008 Laurent Delineau
* @link http://www.gnu.org/licenses/licenses.html
* @package admin
* @version $Id: admin_room_del.php,v 1.11 2009-09-29 18:02:56 grr Exp $
* @filesource
*
* This file is part of GRR.
*
* GRR is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GRR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRR; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
include "include/admin.inc.php";
$grr_script_name = "admin_room_del.php";
$type = isset($_GET["type"]) ? $_GET["type"] : NULL;
$confirm = isset($_GET["confirm"]) ? $_GET["confirm"] : NULL;
$room = isset($_GET["room"]) ? $_GET["room"] : NULL;
$id_area = isset($_POST["id_area"]) ? $_POST["id_area"] : (isset($_GET["id_area"]) ? $_GET["id_area"] : NULL);
$id_site = isset($_POST['id_site']) ? $_POST['id_site'] : (isset($_GET['id_site']) ? $_GET['id_site'] : -1);
if (isset($room))
settype($room,"integer");
if (isset($id_area))
settype($id_area,"integer");
if (isset($id_site))
settype($id_site,"integer");
if (isset($_SERVER['HTTP_REFERER']))
$back = htmlspecialchars($_SERVER['HTTP_REFERER']);
if ($type == "room")
{
if ((authGetUserLevel(getUserName(),$room) < 4) || (!verif_acces_ressource(getUserName(), $room)))
{
showAccessDenied($back);
exit();
}
if (isset($confirm))
{
//They have confirmed it already, so go blast!
//First take out all appointments for this room
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_entry WHERE room_id=$room");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_entry_moderate WHERE room_id=$room");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_j_mailuser_room WHERE id_room=$room");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_j_user_room WHERE id_room=$room");
//Now take out the room itself
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_room WHERE id=$room");
//Go back to the admin page
header("Location: admin_room.php?id_area=$id_area&id_site=$id_site");
die();
}
else
{
//print the page header
print_header("", "", "", $type="with_session");
echo "<div class=\"page_sans_col_gauche\">";
//We tell them how bad what theyre about to do is
//Find out how many appointments would be deleted
$sql = "SELECT name, start_time, end_time FROM ".TABLE_PREFIX."_entry WHERE room_id=$room";
$res = grr_sql_query($sql);
if (!$res)
echo grr_sql_error();
else if (grr_sql_count($res) > 0)
{
echo get_vocab("deletefollowing") . ":<ul>";
for ($i = 0; ($row = grr_sql_row($res, $i)); $i++)
{
echo "<li>$row[0] (";
echo time_date_string($row[1],$dformat) . " -> ";
echo time_date_string($row[2],$dformat) . ")";
}
echo "</ul>";
}
echo "<h1 style=\"text-align:center;\">" . get_vocab("sure") . "</h1>";
echo "<h1 style=\"text-align:center;\"><a href=\"admin_room_del.php?type=room&room=$room&confirm=Y&id_area=$id_area\">" . get_vocab("YES") . "!</a> <a href=\"admin_room.php?id_area=$id_area\">" . get_vocab("NO") . "!</a></h1>";
echo "</div>";
}
}
if ($type == "area")
{
// Seul l'admin peut supprimer un domaine
if (authGetUserLevel(getUserName(), $id_area, 'area') < 5)
{
showAccessDenied($back);
exit();
}
//We are only going to let them delete an area if there are
//no rooms. its easier
$n = grr_sql_query1("SELECT count(*) FROM ".TABLE_PREFIX."_room WHERE area_id=$id_area");
if ($n == 0)
{
// Suppression des champ additionnels
$sqlstring = "SELECT id FROM ".TABLE_PREFIX."_overload WHERE id_area='".$id_area."'";
$result = grr_sql_query($sqlstring);
for ($i = 0; ($field_row = grr_sql_row($result, $i)); $i++)
{
$id_overload = $field_row[0];
// Suppression des données dans les réservations déjà effectuées
grrDelOverloadFromEntries($id_overload);
$sql = "DELETE FROM ".TABLE_PREFIX."_overload WHERE id=$id_overload;";
grr_sql_command($sql);
}
//OK, nothing there, lets blast it away
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_area WHERE id=$id_area");
grr_sql_command("update ".TABLE_PREFIX."_utilisateurs set default_area = '-1', default_room = '-1' WHERE default_area='".$id_area."'");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_area_periodes WHERE id_area=$id_area");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_j_useradmin_area WHERE id_area=$id_area");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_j_type_area WHERE id_area=$id_area");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_j_user_area WHERE id_area=$id_area");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_j_site_area WHERE id_area=$id_area");
$test = grr_sql_query1("select VALUE from ".TABLE_PREFIX."_setting WHERE NAME='default_area'");
if ($test == $id_area)
{
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_setting WHERE NAME='default_area'");
grr_sql_command("DELETE FROM ".TABLE_PREFIX."_setting WHERE NAME='default_room'");
// Settings
require_once("./include/settings.class.php");
//Chargement des valeurs de la table settingS
if (!Settings::load())
die("Erreur chargement settings");
}
//Redirect back to the admin page
header("Location: admin_room.php?id_site=$id_site");
die();
}
else
{
//There are rooms left in the area
//print the page header
print_header("", "", "", $type="with_session");
//print_banner("", "", "", "", $type = "with_session", $page = "admin");
echo "<div class=\"page_sans_col_gauche\">";
echo "<p>".get_vocab('delarea');
echo "<br /><a href=\"admin_room.php?id_area=$id_area&id_site=$id_site\">" . get_vocab('back') . "</a></p></div>";
}
}
?>
</body>
</html>