-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin_email_manager.php
297 lines (270 loc) · 11.5 KB
/
admin_email_manager.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<?php
/**
* admin_email_manager.php
* Interface de gestion des mails automatiques
* Dernière modification : $Date: 2009-04-14 12:59:17 $
* @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_email_manager.php,v 1.11 2009-04-14 12:59:17 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
*/
/**
* $Log: admin_email_manager.php,v $
* Revision 1.11 2009-04-14 12:59:17 grr
* *** empty log message ***
*
* Revision 1.10 2009-04-09 14:52:31 grr
* *** empty log message ***
*
* Revision 1.9 2009-02-27 13:28:19 grr
* *** empty log message ***
*
*
*/
include "include/admin.inc.php";
$grr_script_name = "admin_email_manager.php";
$id_area = isset($_GET["id_area"]) ? $_GET["id_area"] : NULL;
$room = isset($_GET["room"]) ? $_GET["room"] : NULL;
if (isset($room)) settype($room,"integer");
if (!isset($id_area)) settype($id_area,"integer");
$back = '';
if (isset($_SERVER['HTTP_REFERER'])) $back = my_htmlspecialcharacters($_SERVER['HTTP_REFERER']);
if(authGetUserLevel(getUserName(),-1,'area') < 4)
{
$day = date("d");
$month = date("m");
$year = date("Y");
showAccessDenied($day, $month, $year, '',$back);
exit();
}
// tableau des ressources auxquelles l'utilisateur n'a pas accès
$tab_rooms_noaccess = verif_acces_ressource(getUserName(), 'all');
if (isset($_POST['mail1'])) {
if (isset($_POST['send_always_mail_to_creator']))
$temp = '1';
else
$temp = '0';
if (!saveSetting("send_always_mail_to_creator", $temp)) {
echo "Erreur lors de l'enregistrement de send_always_mail_to_creator !<br />";
die();
}
}
$reg_admin_login = isset($_GET["reg_admin_login"]) ? $_GET["reg_admin_login"] : NULL;
$action = isset($_GET["action"]) ? $_GET["action"] : NULL;
$msg='';
if ($reg_admin_login) {
// On commence par vérifier que le professeur n'est pas déjà présent dans cette liste.
if ($room !=-1) {
// Ressource
// On vérifie que la ressource $room existe
$test = grr_sql_query1("select id from ".TABLE_PREFIX."_room where id='".$room."'");
if ($test == -1) {
showAccessDenied('', '', '', '',$back);
exit();
}
if (in_array($room,$tab_rooms_noaccess)) {
showAccessDenied('','','', '',$back);
exit();
}
// La ressource existe : on vérifie les privilèges de l'utilisateur
if(authGetUserLevel(getUserName(),$room) < 4)
{
showAccessDenied('','','', '',$back);
exit();
}
$sql = "SELECT * FROM ".TABLE_PREFIX."_j_mailuser_room WHERE (login = '$reg_admin_login' and id_room = '$room')";
$res = grr_sql_query($sql);
$test = grr_sql_count($res);
if ($test != "0") {
$msg = get_vocab("warning_exist");
} else {
if ($reg_admin_login != '') {
$sql = "INSERT INTO ".TABLE_PREFIX."_j_mailuser_room SET login= '$reg_admin_login', id_room = '$room'";
if (grr_sql_command($sql) < 0) {fatal_error(1, "<p>" . grr_sql_error());} else {$msg=get_vocab("add_user_succeed");}
}
}
}
}
if ($action) {
if ($action == "del_admin") {
if(authGetUserLevel(getUserName(),$room) < 4)
{
showAccessDenied($day, $month, $year, '',$back);
exit();
}
$sql = "DELETE FROM ".TABLE_PREFIX."_j_mailuser_room WHERE (login='".$_GET['login_admin']."' and id_room = '$room')";
if (grr_sql_command($sql) < 0) {fatal_error(1, "<p>" . grr_sql_error());} else {$msg=get_vocab("del_user_succeed");}
}
}
# print the page header
print_header("","","","",$type="with_session", $page="admin");
// Affichage de la colonne de gauche
include "admin_col_gauche.php";
affiche_pop_up($msg,"admin");
if (empty($room)) $room = -1;
echo "<h2>".get_vocab('admin_email_manager.php').grr_help("aide_grr_mail_auto")."</h2>\n";
if (getSettingValue("automatic_mail") != 'yes')
echo "<h3 class=\"avertissement\">".get_vocab("attention_mail_automatique_désactive")."</h3>";
echo get_vocab("explain_automatic_mail3")."<br /><br /><hr />\n";
echo "<form action=\"admin_email_manager.php\" method=\"post\">\n";
echo "<div><input type=\"checkbox\" name=\"send_always_mail_to_creator\" value=\"y\" ";
if (getSettingValue('send_always_mail_to_creator')=='1')
echo ' checked="checked" ';
echo ' />'."\n";
echo get_vocab("explain_automatic_mail1");
echo "\n".'<br /><br /><div style="text-align:center;"><input type="submit" name="mail1" value="'.get_vocab('save').'" /></div></div></form><hr />';
echo get_vocab("explain_automatic_mail2")."<br />";
echo $msg;
# Table with areas, rooms.
echo "\n<table><tr>\n";
$this_area_name = "";
$this_room_name = "";
# Show all areas
echo "<td ><p><b>".get_vocab("areas")."</b></p>\n";
$out_html = "<form id=\"area\" action=\"admin_email_manager.php\" method=\"post\">\n<div><select name=\"area\" onchange=\"area_go()\">\n";
$out_html .= "<option value=\"admin_email_manager.php?id_area=-1\">".get_vocab('select')."</option>\n";
$sql = "select id, area_name from ".TABLE_PREFIX."_area order by area_name";
$res = grr_sql_query($sql);
if ($res) for ($i = 0; ($row = grr_sql_row($res, $i)); $i++)
{
$selected = ($row[0] == $id_area) ? "selected=\"selected\"" : "";
$link = "admin_email_manager.php?id_area=$row[0]";
// On affiche uniquement les domaines administrés par l'utilisateur
if(authGetUserLevel(getUserName(),$row[0],'area') >= 4)
$out_html .= "<option $selected value=\"$link\">" . my_htmlspecialcharacters($row[1])."</option>\n";
}
$out_html .= "</select></div>
<script type=\"text/javascript\" >
<!--
function area_go()
{
box = document.getElementById(\"area\").area;
destination = box.options[box.selectedIndex].value;
if (destination) location.href = destination;
}
// -->
</script>
<noscript>
<div><input type=\"submit\" value=\"Change\" /></div>
</noscript>
</form>";
echo $out_html;
$this_area_name = grr_sql_query1("select area_name from ".TABLE_PREFIX."_area where id=$id_area");
$this_room_name = grr_sql_query1("select room_name from ".TABLE_PREFIX."_room where id=$room");
$this_room_name_des = grr_sql_query1("select description from ".TABLE_PREFIX."_room where id=$room");
echo "</td>\n";
# Show all rooms in the current area
echo "<td><p><b>".get_vocab("rooms")."</b></p>";
# should we show a drop-down for the room list, or not?
$out_html = "<form id=\"room\" action=\"admin_email_manager.php\" method=\"post\">\n<div><select name=\"room\" onchange=\"room_go()\">\n";
$out_html .= "<option value=\"admin_email_manager.php?id_area=$id_area&room=-1\">".get_vocab('select')."</option>\n";
$sql = "select id, room_name, description from ".TABLE_PREFIX."_room where area_id=$id_area ";
// on ne cherche pas parmi les ressources invisibles pour l'utilisateur
foreach($tab_rooms_noaccess as $key){
$sql .= " and id != $key ";
};
$sql .= "order by room_name";
$res = grr_sql_query($sql);
if ($res) for ($i = 0; ($row = grr_sql_row($res, $i)); $i++)
{
if ($row[2]) {$temp = " (".my_htmlspecialcharacters($row[2]).")";} else {$temp="";}
$selected = ($row[0] == $room) ? "selected=\"selected\"" : "";
$link = "admin_email_manager.php?id_area=$id_area&room=$row[0]";
$out_html .= "<option $selected value=\"$link\">" . my_htmlspecialcharacters($row[1].$temp)."</option>\n";
}
$out_html .= "</select></div>\n
<script type=\"text/javascript\" >
<!--
function room_go()
{
box = document.getElementById(\"room\").room;
destination = box.options[box.selectedIndex].value;
if (destination) location.href = destination;
}
// -->
</script>
<noscript>
<div><input type=\"submit\" value=\"Change\" /></div>
</noscript>
</form>";
echo $out_html;
echo "</td>\n";
echo "</tr></table>\n";
# Don't continue if this area has no rooms:
if ($id_area <= 0)
{
echo "<h1>".get_vocab("no_area")."</h1>";
// fin de l'affichage de la colonne de droite
echo "</td></tr></table></body></html>";
exit;
}
# Show area and room:
if ($this_room_name_des!='-1') {$this_room_name_des = " (".$this_room_name_des.")";} else {$this_room_name_des='';}
if ($room=='-1') {
echo "<h1>".get_vocab("no_room")."</h1>";
// fin de l'affichage de la colonne de droite
echo "</td></tr></table></body></html>";
exit;
} else {
echo "<table border=\"1\" cellpadding=\"5\"><tr><td>";
$sql = "SELECT u.login, u.nom, u.prenom FROM ".TABLE_PREFIX."_utilisateurs u, ".TABLE_PREFIX."_j_mailuser_room j WHERE (j.id_room='$room' and u.login=j.login) order by u.nom, u.prenom";
$res = grr_sql_query($sql);
$nombre = grr_sql_count($res);
if ($nombre!=0) echo "<h3>".get_vocab("mail_user_list")."</h3>";
if ($res) for ($i = 0; ($row = grr_sql_row($res, $i)); $i++)
{
$login_admin = $row[0];
$nom_admin = my_htmlspecialcharacters($row[1]);
$prenom_admin = my_htmlspecialcharacters($row[2]);
echo "<b>";
echo "$nom_admin $prenom_admin</b> | <a href='admin_email_manager.php?action=del_admin&login_admin=".urlencode($login_admin)."&room=$room&id_area=$id_area'>".get_vocab("delete")."</a><br />";
}
if ($nombre == 0) {
echo "<h3><span class=\"avertissement\">".get_vocab("no_mail_user_list")."</span></h3>";
}
}
?>
<h3><?php echo get_vocab("add_user_to_list"); ?></h3>
<form action="admin_email_manager.php" method='get'>
<div><select size="1" name="reg_admin_login">
<option value=''><?php echo get_vocab("nobody"); ?></option>
<?php
$sql = "SELECT DISTINCT login, nom, prenom FROM ".TABLE_PREFIX."_utilisateurs WHERE (etat!='inactif' and email!='' and statut!='visiteur' ) order by nom, prenom";
$res = grr_sql_query($sql);
if ($res) for ($i = 0; ($row = grr_sql_row($res, $i)); $i++) {
if (authUserAccesArea($row[0],$id_area) == 1) {
echo "<option value=\"$row[0]\">".my_htmlspecialcharacters($row[1])." ".my_htmlspecialcharacters($row[2])." </option>";
}
}
?>
</select>
<input type="hidden" name="add_admin" value="yes" />
<input type="hidden" name="id_area" value="<?php echo $id_area;?>" />
<input type="hidden" name="room" value="<?php echo $room;?>" />
<input type="submit" value="Enregistrer" /></div>
</form>
</td></tr></table>
<?php
// fin de l'affichage de la colonne de droite
echo "</td></tr></table>";
?>
</body>
</html>