1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
// resetting the course id |
5
|
|
|
$cidReset = true; |
6
|
|
|
|
7
|
|
|
// including some necessary files |
8
|
|
|
require_once __DIR__.'/../inc/global.inc.php'; |
9
|
|
|
|
10
|
|
|
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; |
11
|
|
|
$usergroup = new UserGroup(); |
12
|
|
|
$data = $usergroup->get($id); |
13
|
|
|
$usergroup->protectScript($data); |
14
|
|
|
|
15
|
|
|
$xajax = new xajax(); |
16
|
|
|
$xajax->registerFunction('search_usergroup_sessions'); |
17
|
|
|
|
18
|
|
|
// setting the section (for the tabs) |
19
|
|
|
$this_section = SECTION_PLATFORM_ADMIN; |
20
|
|
|
|
21
|
|
|
// setting breadcrumbs |
22
|
|
|
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')]; |
23
|
|
|
$interbreadcrumb[] = ['url' => 'usergroups.php', 'name' => get_lang('Classes')]; |
24
|
|
|
|
25
|
|
|
// setting the name of the tool |
26
|
|
|
$tool_name = get_lang('SubscribeClassToSessions'); |
27
|
|
|
|
28
|
|
|
$add_type = 'multiple'; |
29
|
|
|
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') { |
30
|
|
|
$add_type = Security::remove_XSS($_REQUEST['add_type']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); |
34
|
|
|
$htmlHeadXtra[] = '<script> |
35
|
|
|
function add_user_to_session (code, content) { |
36
|
|
|
document.getElementById("user_to_add").value = ""; |
37
|
|
|
document.getElementById("ajax_list_users_single").innerHTML = ""; |
38
|
|
|
destination = document.getElementById("elements_in"); |
39
|
|
|
for (i=0;i<destination.length;i++) { |
40
|
|
|
if(destination.options[i].text == content) { |
41
|
|
|
return false; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
destination.options[destination.length] = new Option(content,code); |
45
|
|
|
destination.selectedIndex = -1; |
46
|
|
|
sortOptions(destination.options); |
47
|
|
|
} |
48
|
|
|
function remove_item(origin) { |
49
|
|
|
for(var i = 0 ; i<origin.options.length ; i++) { |
50
|
|
|
if(origin.options[i].selected) { |
51
|
|
|
origin.options[i]=null; |
52
|
|
|
i = i-1; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
function display_advanced_search () { |
58
|
|
|
if ($("#advancedSearch").css("display") == "none") { |
59
|
|
|
$("#advancedSearch").css("display","block"); |
60
|
|
|
$("#img_plus_and_minus").html(\' '.Display::return_icon('div_hide.gif', get_lang('Hide'), ['style' => 'vertical-align:middle']).' '.get_lang('AdvancedSearch').'\'); |
61
|
|
|
} else { |
62
|
|
|
$("#advancedSearch").css("display","none"); |
63
|
|
|
$("#img_plus_and_minus").html(\' '.Display::return_icon('div_show.gif', get_lang('Show'), ['style' => 'vertical-align:middle']).' '.get_lang('AdvancedSearch').'\'); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function validate_filter() { |
68
|
|
|
document.formulaire.add_type.value = \''.$add_type.'\'; |
69
|
|
|
document.formulaire.form_sent.value=0; |
70
|
|
|
document.formulaire.submit(); |
71
|
|
|
} |
72
|
|
|
</script>'; |
73
|
|
|
|
74
|
|
|
$errorMsg = ''; |
75
|
|
|
if (isset($_POST['form_sent']) && $_POST['form_sent']) { |
76
|
|
|
$form_sent = $_POST['form_sent']; |
77
|
|
|
$elements_posted = $_POST['elements_in_name']; |
78
|
|
|
if (!is_array($elements_posted)) { |
79
|
|
|
$elements_posted = []; |
80
|
|
|
} |
81
|
|
|
if ($form_sent == 1) { |
82
|
|
|
//added a parameter to send emails when registering a user |
83
|
|
|
$usergroup->subscribe_sessions_to_usergroup($id, $elements_posted); |
84
|
|
|
header('Location: usergroups.php'); |
85
|
|
|
exit; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
$session_list_in = $usergroup->get_sessions_by_usergroup($id); |
89
|
|
|
|
90
|
|
|
$onlyThisSessionList = []; |
91
|
|
|
if ($usergroup->allowTeachers()) { |
92
|
|
|
$userId = api_get_user_id(); |
93
|
|
|
$sessionList = SessionManager::getSessionsFollowedByUser($userId, COURSEMANAGER); |
94
|
|
|
if (!empty($sessionList)) { |
95
|
|
|
$onlyThisSessionList = array_column($sessionList, 'id'); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
$session_list = SessionManager::get_sessions_list([], ['name'], null, null, 0, $onlyThisSessionList); |
99
|
|
|
$elements_not_in = $elements_in = []; |
100
|
|
|
|
101
|
|
|
if (!empty($session_list)) { |
102
|
|
|
foreach ($session_list as $session) { |
103
|
|
|
if (in_array($session['id'], $session_list_in)) { |
104
|
|
|
$elements_in[$session['id']] = $session['name']; |
105
|
|
|
} else { |
106
|
|
|
$elements_not_in[$session['id']] = $session['name']; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$ajax_search = $add_type === 'unique' ? true : false; |
112
|
|
|
|
113
|
|
|
// checking for extra field with filter on |
114
|
|
|
function search_usergroup_sessions($needle, $type) |
115
|
|
|
{ |
116
|
|
|
global $elements_in; |
117
|
|
|
$xajax_response = new xajaxResponse(); |
118
|
|
|
$return = ''; |
119
|
|
|
if (!empty($needle) && !empty($type)) { |
120
|
|
|
if ($type == 'searchbox') { |
121
|
|
|
$session_list = SessionManager::get_sessions_list( |
122
|
|
|
['s.name' => ['operator' => 'LIKE', 'value' => "%$needle%"]] |
123
|
|
|
); |
124
|
|
|
} elseif ($type != 'single') { |
125
|
|
|
$session_list = SessionManager::get_sessions_list( |
126
|
|
|
['s.name' => ['operator' => 'LIKE', 'value' => "$needle%"]] |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
if ($type != 'single') { |
130
|
|
|
$return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">'; |
131
|
|
|
foreach ($session_list as $row) { |
|
|
|
|
132
|
|
|
if (!in_array($row['id'], array_keys($elements_in))) { |
133
|
|
|
$return .= '<option value="'.$row['id'].'">'.$row['name'].'</option>'; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
$return .= '</select>'; |
137
|
|
|
$xajax_response->addAssign( |
138
|
|
|
'ajax_list_multiple', |
139
|
|
|
'innerHTML', |
140
|
|
|
api_utf8_encode($return) |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return $xajax_response; |
146
|
|
|
} |
147
|
|
|
$xajax->processRequests(); |
148
|
|
|
|
149
|
|
|
Display::display_header($tool_name); |
150
|
|
|
|
151
|
|
|
$add = (empty($_GET['add']) ? '' : Security::remove_XSS($_GET['add'])); |
152
|
|
|
if ($add_type == 'multiple') { |
153
|
|
|
$link_add_type_unique = '<a href="'.api_get_self().'?add='.$add.'&add_type=unique">'. |
154
|
|
|
Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>'; |
155
|
|
|
$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'); |
156
|
|
|
} else { |
157
|
|
|
$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'); |
158
|
|
|
$link_add_type_multiple = '<a href="'.api_get_self().'?add='.$add.'&add_type=multiple">'. |
159
|
|
|
Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>'; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
echo '<div class="actions">'; |
163
|
|
|
echo '<a href="usergroups.php">'. |
164
|
|
|
Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>'; |
165
|
|
|
echo '<a href="javascript://" class="advanced_parameters" style="margin-top: 8px" onclick="display_advanced_search();"><span id="img_plus_and_minus"> '. |
166
|
|
|
Display::return_icon('div_show.gif', get_lang('Show'), ['style' => 'vertical-align:middle']).' '.get_lang('AdvancedSearch').'</span></a>'; |
167
|
|
|
echo '</div>'; |
168
|
|
|
echo '<div id="advancedSearch" style="display: none">'.get_lang('SearchSessions'); ?> : |
169
|
|
|
<input name="SearchSession" onchange = "xajax_search_usergroup_sessions(this.value,'searchbox')" onkeyup="this.onchange()"> |
170
|
|
|
</div> |
171
|
|
|
<form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $id; if (!empty($_GET['add'])) { |
172
|
|
|
echo '&add=true'; |
173
|
|
|
} ?>" style="margin:0px;" <?php if ($ajax_search) { |
174
|
|
|
echo ' onsubmit="valide();"'; |
175
|
|
|
}?>> |
176
|
|
|
<?php |
177
|
|
|
echo '<legend>'.$data['name'].': '.$tool_name.'</legend>'; |
178
|
|
|
echo Display::input('hidden', 'id', $id); |
179
|
|
|
echo Display::input('hidden', 'form_sent', '1'); |
180
|
|
|
echo Display::input('hidden', 'add_type', null); |
181
|
|
|
if (!empty($errorMsg)) { |
182
|
|
|
echo Display::return_message($errorMsg, 'normal'); //main API |
183
|
|
|
} |
184
|
|
|
?> |
185
|
|
|
|
186
|
|
|
<table border="0" cellpadding="5" cellspacing="0" width="100%"> |
187
|
|
|
<tr> |
188
|
|
|
<td align="center"><b><?php echo get_lang('SessionsInPlatform'); ?> :</b> |
189
|
|
|
</td> |
190
|
|
|
<td></td> |
191
|
|
|
<td align="center"><b><?php echo get_lang('SessionsInGroup'); ?> :</b></td> |
192
|
|
|
</tr> |
193
|
|
|
|
194
|
|
|
<?php if ($add_type == 'multiple') { |
195
|
|
|
?> |
196
|
|
|
<tr> |
197
|
|
|
<td align="center"> |
198
|
|
|
<?php echo get_lang('FirstLetterSessions'); ?> : |
199
|
|
|
<select name="firstLetterUser" onchange = "xajax_search_usergroup_sessions(this.value,'multiple')" > |
200
|
|
|
<option value = "%">--</option> |
201
|
|
|
<?php |
202
|
|
|
echo Display :: get_alphabet_options(); ?> |
203
|
|
|
</select> |
204
|
|
|
<?php echo '<br />'; ?> |
205
|
|
|
</td> |
206
|
|
|
<td align="center"> </td> |
207
|
|
|
</tr> |
208
|
|
|
<?php |
209
|
|
|
} ?> |
210
|
|
|
<tr> |
211
|
|
|
<td align="center"> |
212
|
|
|
<div id="content_source"> |
213
|
|
|
<?php |
214
|
|
|
if (!($add_type == 'multiple')) { |
215
|
|
|
?> |
216
|
|
|
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" /> |
217
|
|
|
<div id="ajax_list_users_single"></div> |
218
|
|
|
<?php |
219
|
|
|
} else { |
220
|
|
|
?> |
221
|
|
|
<div id="ajax_list_multiple"> |
222
|
|
|
<?php echo Display::select( |
223
|
|
|
'elements_not_in_name', |
224
|
|
|
$elements_not_in, |
225
|
|
|
'', |
226
|
|
|
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'elements_not_in', 'size' => '15px'], |
227
|
|
|
false |
228
|
|
|
); ?> |
229
|
|
|
</div> |
230
|
|
|
<?php |
231
|
|
|
} |
232
|
|
|
?> |
233
|
|
|
</div> |
234
|
|
|
</td> |
235
|
|
|
<td width="10%" valign="middle" align="center"> |
236
|
|
|
<?php |
237
|
|
|
if ($ajax_search) { |
238
|
|
|
?> |
239
|
|
|
<button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('elements_in'))" > |
240
|
|
|
<em class="fa fa-arrow-left"></em> |
241
|
|
|
</button> |
242
|
|
|
<?php |
243
|
|
|
} else { |
244
|
|
|
?> |
245
|
|
|
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))" onclick="moveItem(document.getElementById('elements_not_in'), document.getElementById('elements_in'))"> |
246
|
|
|
<em class="fa fa-arrow-right"></em> |
247
|
|
|
</button> |
248
|
|
|
<br /><br /> |
249
|
|
|
<button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))" onclick="moveItem(document.getElementById('elements_in'), document.getElementById('elements_not_in'))"> |
250
|
|
|
<em class="fa fa-arrow-left"></em> |
251
|
|
|
</button> |
252
|
|
|
<?php |
253
|
|
|
} |
254
|
|
|
?> |
255
|
|
|
<br /><br /><br /><br /><br /><br /> |
256
|
|
|
</td> |
257
|
|
|
<td align="center"> |
258
|
|
|
<?php |
259
|
|
|
echo Display::select( |
260
|
|
|
'elements_in_name[]', |
261
|
|
|
$elements_in, |
262
|
|
|
'', |
263
|
|
|
['style' => 'width:360px', 'multiple' => 'multiple', 'id' => 'elements_in', 'size' => '15px'], |
264
|
|
|
false |
265
|
|
|
); |
266
|
|
|
unset($sessionUsersList); |
267
|
|
|
?> |
268
|
|
|
</td> |
269
|
|
|
</tr> |
270
|
|
|
<tr> |
271
|
|
|
<td colspan="3" align="center"> |
272
|
|
|
<br /> |
273
|
|
|
<?php |
274
|
|
|
echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('SubscribeClassToSessions').'</button>'; |
275
|
|
|
?> |
276
|
|
|
</td> |
277
|
|
|
</tr> |
278
|
|
|
</table> |
279
|
|
|
</form> |
280
|
|
|
|
281
|
|
|
<script> |
282
|
|
|
function moveItem(origin , destination) { |
283
|
|
|
for(var i = 0 ; i<origin.options.length ; i++) { |
284
|
|
|
if(origin.options[i].selected) { |
285
|
|
|
destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value); |
286
|
|
|
origin.options[i]=null; |
287
|
|
|
i = i-1; |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
destination.selectedIndex = -1; |
291
|
|
|
sortOptions(destination.options); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
function sortOptions(options) { |
295
|
|
|
newOptions = new Array(); |
296
|
|
|
for (i = 0 ; i<options.length ; i++) |
297
|
|
|
newOptions[i] = options[i]; |
298
|
|
|
|
299
|
|
|
newOptions = newOptions.sort(mysort); |
300
|
|
|
options.length = 0; |
301
|
|
|
for(i = 0 ; i < newOptions.length ; i++) |
302
|
|
|
options[i] = newOptions[i]; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
function mysort(a, b){ |
306
|
|
|
if(a.text.toLowerCase() > b.text.toLowerCase()){ |
307
|
|
|
return 1; |
308
|
|
|
} |
309
|
|
|
if(a.text.toLowerCase() < b.text.toLowerCase()){ |
310
|
|
|
return -1; |
311
|
|
|
} |
312
|
|
|
return 0; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
function valide(){ |
316
|
|
|
var options = document.getElementById('elements_in').options; |
317
|
|
|
for (i = 0 ; i<options.length ; i++) |
318
|
|
|
options[i].selected = true; |
319
|
|
|
document.forms.formulaire.submit(); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
function loadUsersInSelect(select) { |
323
|
|
|
var xhr_object = null; |
324
|
|
|
if(window.XMLHttpRequest) // Firefox |
325
|
|
|
xhr_object = new XMLHttpRequest(); |
326
|
|
|
else if(window.ActiveXObject) // Internet Explorer |
327
|
|
|
xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); |
328
|
|
|
else // XMLHttpRequest non supporté par le navigateur |
329
|
|
|
alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); |
330
|
|
|
|
331
|
|
|
xhr_object.open("POST", "loadUsersInSelect.ajax.php"); |
332
|
|
|
xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
333
|
|
|
nosessionUsers = makepost(document.getElementById('elements_not_in')); |
334
|
|
|
sessionUsers = makepost(document.getElementById('elements_in')); |
335
|
|
|
nosessionClasses = makepost(document.getElementById('origin_classes')); |
336
|
|
|
sessionClasses = makepost(document.getElementById('destination_classes')); |
337
|
|
|
xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses); |
338
|
|
|
|
339
|
|
|
xhr_object.onreadystatechange = function() { |
340
|
|
|
if(xhr_object.readyState == 4) { |
341
|
|
|
document.getElementById('content_source').innerHTML = result = xhr_object.responseText; |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
function makepost(select){ |
347
|
|
|
var options = select.options; |
348
|
|
|
var ret = ""; |
349
|
|
|
for (i = 0 ; i<options.length ; i++) |
350
|
|
|
ret = ret + options[i].value +'::'+options[i].text+";;"; |
351
|
|
|
|
352
|
|
|
return ret; |
353
|
|
|
} |
354
|
|
|
</script> |
355
|
|
|
<?php |
356
|
|
|
Display::display_footer(); |
357
|
|
|
|