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