/
listreq.php
414 lines (384 loc) · 19.3 KB
/
listreq.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<?php
/* ========================================================================
* Open eClass 3.0
* E-learning and Course Management System
* ========================================================================
* Copyright 2003-2014 Greek Universities Network - GUnet
* A full copyright notice can be read in "/info/copyright.txt".
* For a full list of contributors, see "credits.txt".
*
* Open eClass is an open platform distributed in the hope that it will
* be useful (without any warranty), under the terms of the GNU (General
* Public License) as published by the Free Software Foundation.
* The full license can be read in "/info/license/license_gpl.txt".
*
* Contact address: GUnet Asynchronous eLearning Group,
* Network Operations Center, University of Athens,
* Panepistimiopolis Ilissia, 15784, Athens, Greece
* e-mail: info@openeclass.org
* ======================================================================== */
$require_usermanage_user = true;
require_once '../../include/baseTheme.php';
require_once 'include/sendMail.inc.php';
require_once 'modules/auth/auth.inc.php';
require_once 'include/lib/hierarchy.class.php';
require_once 'include/lib/user.class.php';
require_once 'hierarchy_validations.php';
$tree = new Hierarchy();
$user = new User();
$close = isset($_GET['close']) ? $_GET['close'] : (isset($_POST['close']) ? $_POST['close'] : '');
$id = isset($_GET['id']) ? intval($_GET['id']) : (isset($_POST['id']) ? intval($_POST['id']) : '');
$show = isset($_GET['show']) ? $_GET['show'] : (isset($_POST['show']) ? $_POST['show'] : '');
$columns = 'null, null, null, null, { orderable: false }';
// Deal with navigation
switch ($show) {
case "closed":
$toolName = $langReqHaveClosed;
$pagination_link = '&show=closed';
$columns = 'null, null, null, null, null, { orderable: false }';
break;
case "rejected":
$toolName = $langReqHaveBlocked;
$columns = 'null, null, null, null, null, { orderable: false }';
break;
}
load_js('datatables');
$head_content .= "<script type='text/javascript'>
$(document).ready(function() {
$('#requests_table').DataTable ({
'columns': [ $columns ],
'sPaginationType': 'full_numbers',
'bAutoWidth': true,
'searchDelay': 1000,
'order' : [[4, 'desc']],
'oLanguage': {
'sLengthMenu': '$langDisplay _MENU_ $langResults2',
'sZeroRecords': '" . $langNoResult . "',
'sInfo': '$langDisplayed _START_ $langTill _END_ $langFrom2 _TOTAL_ $langTotalResults',
'sInfoEmpty': '$langDisplayed 0 $langTill 0 $langFrom2 0 $langResults2',
'sInfoFiltered': '',
'sInfoPostFix': '',
'sSearch': '" . $langSearch . "',
'sUrl': '',
'oPaginate': {
'sFirst': '«',
'sPrevious': '‹',
'sNext': '›',
'sLast': '»'
}
}
});
$('.dataTables_filter input').attr('placeholder', '$langName, $langSurname, $langUsername');
});
</script>";
$basetoolurl = $_SERVER['SCRIPT_NAME'];
if (isset($_GET['type']) and $_GET['type'] == 'user') {
$list_status = 5;
$toolName = $langUserOpenRequests;
$reqtype = '&type=user';
$basetoolurl .= '?type=user';
$linkreg = $langUserDetails;
$linkget = '?type=user';
} else {
$list_status = 1;
$toolName = $langOpenProfessorRequests;
$reqtype = '';
$linkreg = $langProfReg;
$linkget = '';
}
$navigation[] = array('url' => 'index.php', 'name' => $langAdmin);
// id validation
if ($id > 0) {
$req = Database::get()->querySingle("SELECT faculty_id FROM user_request WHERE id = ?d", $id);
if ($req->faculty_id > 0) {
validateNode($req->faculty_id, isDepartmentAdmin());
}
}
// department admin additional query where clause
$depqryadd = '';
if (isDepartmentAdmin()) {
$subtrees = $tree->buildSubtrees($user->getAdminDepartmentIds($uid));
$depqryadd = ' AND faculty_id IN (' . implode(', ', $subtrees) . ')';
}
// Display Actions Toolbar
$tool_content .= "
<div id='operations_container'>" .
action_bar(array(
array('title' => $linkreg,
'url' => "newuseradmin.php$linkget",
'icon' => 'fa-plus-circle',
'level' => 'primary-label',
'button-class' => 'btn-success'),
array('title' => $langReqHaveClosed,
'url' => "$_SERVER[SCRIPT_NAME]?show=closed$reqtype",
'icon' => 'fa-close',
'level' => 'primary'),
array('title' => $langReqHaveBlocked,
'url' => "$_SERVER[SCRIPT_NAME]?show=rejected$reqtype",
'icon' => 'fa-ban',
'level' => 'primary'),
array('title' => $langBack,
'url' => "$basetoolurl",
'icon' => 'fa-reply',
'level' => 'primary')
)) .
"</div>";
// -----------------------------------
// display closed requests
// ----------------------------------
if (!empty($show) and $show == 'closed') {
if (!empty($id) and $id > 0) {
// restore request
Database::get()->query("UPDATE user_request set state = 1, date_closed = NULL WHERE id = ?d", $id);
$tool_content .= "<div class='alert alert-success'>$langReintroductionApplication</div>";
} else {
$q = "SELECT id, givenname, surname, username, email, faculty_id,
phone, am, date_open, date_closed, comment
FROM user_request
WHERE (state = 2 AND status = $list_status) ORDER BY date_closed DESC";
$sql = Database::get()->queryArray($q);
$tool_content .= "<div class='table-responsive'><table id = 'requests_table' class='table-default'>";
$tool_content .= table_header(1);
foreach ($sql as $req) {
$sort_date_open = date("Y-m-d H:i", strtotime($req->date_open));
$sort_date_closed = date("Y-m-d H:i", strtotime($req->date_closed));
$tool_content .= "<tr>";
$tool_content .= '<td>' . q($req->givenname) . " " . q($req->surname) . "";
$tool_content .= '<td>' . q($req->username) . '</td>';
$tool_content .= '<td>' . $tree->getFullPath($req->faculty_id) . '</td>';
$tool_content .= "<td class='text-center' data-sort='$sort_date_open'>
<small>" . nice_format(date('Y-m-d', strtotime($req->date_open))) . "</small></td>";
$tool_content .= "<td class='text-center' data-sort='$sort_date_closed'>
<small>" . nice_format(date('Y-m-d', strtotime($req->date_closed))) . "</small></td>";
$tool_content .= "<td class='option-btn-cell'>";
$tool_content .= action_button(array(
array('title' => $langRestore,
'url' => "$_SERVER[SCRIPT_NAME]?id=$req->id&show=closed$reqtype",
'icon' => 'fa-retweet')));
$tool_content .= "</td></tr>";
}
$tool_content .= "</table></div>";
}
// -----------------------------------
// display rejected requests
// ----------------------------------
} elseif (!empty($show) && ($show == 'rejected')) {
if (!empty($id) && ($id > 0)) {
// restore request
Database::get()->query("UPDATE user_request set state = 1, date_closed = NULL WHERE id = ?d", $id);
$tool_content .= "<div class='alert alert-success'>$langReintroductionApplication</div>";
} else {
$tool_content .= "<div class='table-responsive'><table id = 'requests_table' class='table-default'>";
$tool_content .= table_header(2);
$sql = Database::get()->queryArray("SELECT id, givenname, surname, username, email,
faculty_id, phone, am, date_open, date_closed, comment
FROM user_request
WHERE (state = 3 AND status = $list_status $depqryadd) ORDER BY date_closed DESC");
$tool_content .= "<tbody>";
foreach ($sql as $req) {
$sort_date_open = date("Y-m-d H:i", strtotime($req->date_open));
$sort_date_closed = date("Y-m-d H:i", strtotime($req->date_closed));
$tool_content .= "<tr>";
$tool_content .= "<td>" . q($req->givenname) . " " . q($req->surname) . "</td>";
$tool_content .= "<td>" . q($req->username) . " </td>";
$tool_content .= "<td>" . $tree->getFullPath($req->faculty_id) . "</td>";
$tool_content .= "<td class='text-center' data-sort='$sort_date_open'>
<small>" . nice_format(date('Y-m-d', strtotime($req->date_open))) . "</small></td>";
$tool_content .= "<td class='text-center' data-sort='$sort_date_closed'>
<small>" . nice_format(date('Y-m-d', strtotime($req->date_closed))) . "</small></td>";
$tool_content .= "<td class='option-btn-cell'>";
$tool_content .= action_button(array(
array('title' => $langRestore,
'url' => "$_SERVER[SCRIPT_NAME]?id=$req->id&show=closed$reqtype",
'icon' => 'fa-retweet')));
$tool_content .= "</td></tr>";
}
}
$tool_content .= "</tbody>";
$tool_content .= "</table>";
$tool_content .= "</div>";
// ------------------------------
// close request
// ------------------------------
} elseif (!empty($close)) {
switch ($close) {
case '1':
Database::get()->query("UPDATE user_request
SET state = 2,
date_closed = " . DBHelper::timeAfter() . "
WHERE id = ?d", $id);
if ($list_status == 1) {
$tool_content .= "<div class='alert alert-info'>$langProfessorRequestClosed</div>";
} else {
$tool_content .= "<div class='alert alert-info'$langRequestStudent</div>";
}
break;
case '2':
$submit = isset($_POST['submit']) ? $_POST['submit'] : '';
if (!empty($submit)) {
if (!isset($_POST['token']) || !validate_csrf_token($_POST['token'])) csrf_token_error();
// post the comment and do the delete action
if (!empty($_POST['comment'])) {
$sql = "UPDATE user_request
SET state = 3,
date_closed = " . DBHelper::timeAfter() . ",
comment = ?s
WHERE id = ?d";
if (Database::get()->query($sql, $_POST['comment'], $id)->affectedRows > 0) {
if (isset($_POST['sendmail']) and ( $_POST['sendmail'] == 1)) {
$telephone = get_config('phone');
$administratorName = get_config('admin_name');
$emailhelpdesk = get_config('email_helpdesk');
$emailsubject = $langemailsubjectBlocked;
$emailHeader = "
<!-- Header Section -->
<div id='mail-header'>
<div>
<br>
<div id='header-title'>$langemailbodyBlocked</div>
</div>
</div>";
$emailMain = "
<!-- Body Section -->
<div id='mail-body'>
<br>
<div id='mail-body-inner'>
".q($_POST['comment'])."<br><br>
<ul id='forum-category'>
<li><span><b>$langManager $siteName:</b></span> <span class='left-space'>$administratorName</span></li>
<li><span><b>$langPhone:</b></span> <span class='left-space'>$telephone</span></li>
<li><span><b>$langEmail:</b></span> <span class='left-space'>$emailhelpdesk</span></li>
</ul>
</div>
</div>";
$emailbody = $emailHeader.$emailMain;
$emailPlainBody = html2text($emailbody);
send_mail_multipart('', '', "$_POST[prof_givenname] $_POST[prof_surname]", $_POST['prof_email'], $emailsubject, $emailPlainBody, $emailbody);
}
$tool_content .= "<div class='alert alert-success'>" . (($list_status == 1) ? $langTeacherRequestHasRejected : $langRequestReject);
$tool_content .= " $langRequestMessageHasSent <b>" . q($_POST['prof_email']) . "</b></div>";
$tool_content .= "<br><p><b>$langComments:</b><br>" . q($_POST['comment']) . "</p>";
}
}
} else {
// display the form
$d = Database::get()->querySingle("SELECT comment, givenname, surname, email, status FROM user_request WHERE id = ?d", $id);
$warning = ($d->status == 5) ? $langWarnReject : $langGoingRejectRequest;
$tool_content .= "<form action='$_SERVER[SCRIPT_NAME]' method='post'>
<div class='alert alert-warning'>$warning</div>
<table class='table-default'>
<tr><th class='left'>$langName</th>
<td>" . q($d->givenname) . "</td></tr>
<tr><th class='left'>$langSurname</th>
<td>" . q($d->surname) . "</td></tr>
<tr><th class='left'>$langEmail</th>
<td>" . q($d->email) . "</td></tr>
<tr><th class='left'>$langComments</th>
<td>
<input type='hidden' name='id' value='" . $id . "'>
<input type='hidden' name='close' value='2'>
<input type='hidden' name='prof_givenname' value='" . q($d->givenname) . "'>
<input type='hidden' name='prof_surname' value='" . q($d->surname) . "'>
<textarea class='auth_input' name='comment' rows='5' cols='60'>" . q($d->comment) . "</textarea>
</td></tr>
<tr><th class='left'>$langRequestSendMessage</th>
<td> <input type='text' class='auth_input' name='prof_email' value='" . q($d->email) . "'>
<input type='checkbox' name='sendmail' value='1' checked='yes'> <small>($langGroupValidate)</small>
</td></tr>
<tr><th class='left'> </th>
<td><input class='btn btn-primary' type='submit' name='submit' value='" . q($langRejectRequest) . "'> <small>($langRequestDisplayMessage)</small></td>
</tr></table>
". generate_csrf_token_form_field() ."
</form>";
}
break;
default:
break;
} // end of switch
}
// -----------------------------------
// display all requests
// -----------------------------------
else {
$sql = Database::get()->queryArray("SELECT id, givenname, surname, username, faculty_id, date_open, comment, password FROM user_request
WHERE (state = 1 AND status = $list_status $depqryadd) ORDER BY date_open DESC");
if (count($sql) > 0) {
$tool_content .= "<div class='table-responsive'><table id='requests_table' class='table-default'>";
$tool_content .= table_header();
$tool_content .= "<tbody>";
foreach ($sql as $req) {
$sort_date = date("Y-m-d H:i", strtotime($req->date_open));
$tool_content .= "<td>" . q($req->givenname) . " " . q($req->surname) . "</td>";
$tool_content .= "<td>" . q($req->username) . "</td>";
$tool_content .= "<td>" . $tree->getFullPath($req->faculty_id) . "</td>";
$tool_content .= "<td data-sort='$sort_date'>
<small>" . nice_format(date('Y-m-d', strtotime($req->date_open))) . "</small></td>";
$tool_content .= "<td class='option_btn_cell'>";
switch ($req->password) {
case 'pop3':
$link = "../auth/ldapnewprofadmin.php?id=$req->id&auth=2";
$authmethod = "($langViaPop)";
break;
case 'imap':
$link = "../auth/ldapnewprofadmin.php?id=$req->id&auth=3";
$authmethod = "($langViaImap)";
break;
case 'ldap':
$link = "../auth/ldapnewprofadmin.php?id=$req->id&auth=4";
$authmethod = "($langViaLdap)";
break;
case 'db':
$link = "../auth/ldapnewprofadmin.php?id=$req->id&auth=5";
$authmethod = "($langViaDB)";
break;
case 'shibboleth':
$link = "../auth/ldapnewprofadmin.php?id=$req->id&auth=6";
$authmethod = "($langViaShibboleth)";
break;
case 'cas':
$link = "../auth/ldapnewprofadmin.php?id=$req->id&auth=7";
$authmethod = "($langViaCAS)";
break;
default:
$link = "newuseradmin.php?id=$req->id";
$authmethod = '';
break;
}
$tool_content .= action_button(array(
array('title' => "$langElaboration $authmethod",
'icon' => 'fa-edit',
'url' => $link)
));
$tool_content .= "</td></tr>";
}
$tool_content .= "</tbody>";
$tool_content .= "</table>";
$tool_content .= "</div>";
} else {
$tool_content .= "<div class='alert alert-warning'>$langUserNoRequests</div>";
}
}
draw($tool_content, 3, null, $head_content);
/**
* @brief function to display table header
* @return string
*/
function table_header($addon = FALSE) {
global $langSurnameName, $langFaculty, $langUsername, $langDateRequest, $langDateClosed, $langDateReject;
$string = "<thead>";
$datestring = '';
if ($addon == 1) {
$datestring = "<th class='text-center'>$langDateClosed</th>";
} else if ($addon == 2) {
$datestring = "<th class='text-center'>$langDateReject</th>";
}
$string .= "<tr class='list-header'>
<th scope='col'><div class='text-center'>$langSurnameName</div></th>
<th scope='col'><div class='text-center'>$langUsername</div></th>
<th scope='col'><div class='text-center'>$langFaculty</div></th>
<th class='text-center'>$langDateRequest</th>";
$string .= $datestring;
$string .= "<th scope='col'>" . icon('fa-gears') . "</th>";
$string .= "</tr></thead>";
return $string;
}