chamilo /
chamilo-lms
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* For licensing terms, see /license.txt */ |
||
| 3 | /** |
||
| 4 | * @package chamilo.admin |
||
| 5 | */ |
||
| 6 | // resetting the course id |
||
| 7 | $cidReset=true; |
||
| 8 | |||
| 9 | // including some necessary files |
||
| 10 | require_once '../inc/global.inc.php'; |
||
| 11 | |||
| 12 | $xajax = new xajax(); |
||
| 13 | |||
| 14 | //$xajax->debugOn(); |
||
| 15 | $xajax->registerFunction('search_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' => 'index.php','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_sessions($needle,$type) { |
||
| 123 | global $elements_in; |
||
| 124 | $xajax_response = new xajaxResponse(); |
||
| 125 | $return = ''; |
||
| 126 | if (!empty($needle) && !empty($type)) { |
||
| 127 | if ($type == 'single') { |
||
|
0 ignored issues
–
show
|
|||
| 128 | // search users where username or firstname or lastname begins likes $needle |
||
| 129 | /* $sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user |
||
| 130 | WHERE (username LIKE "'.$needle.'%" |
||
| 131 | OR firstname LIKE "'.$needle.'%" |
||
| 132 | OR lastname LIKE "'.$needle.'%") AND user.user_id<>"'.$user_anonymous.'" AND user.status<>'.DRH.''. |
||
| 133 | $order_clause. |
||
| 134 | ' LIMIT 11';*/ |
||
| 135 | } else if ($type == 'searchbox') { |
||
| 136 | $session_list = SessionManager::get_sessions_list( |
||
| 137 | array('s.name' => array('operator' => 'LIKE', 'value' => "%$needle%")) |
||
| 138 | ); |
||
| 139 | } else { |
||
| 140 | $session_list = SessionManager::get_sessions_list( |
||
| 141 | array('s.name' => array('operator' => 'LIKE', 'value' => "$needle%")) |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | $i=0; |
||
| 145 | View Code Duplication | if ($type=='single') { |
|
| 146 | } else { |
||
| 147 | $return .= '<select id="elements_not_in" name="elements_not_in_name[]" multiple="multiple" size="15" style="width:360px;">'; |
||
| 148 | |||
| 149 | foreach ($session_list as $row ) { |
||
| 150 | if (!in_array($row['id'], array_keys($elements_in))) { |
||
| 151 | $return .= '<option value="'.$row['id'].'">'.$row['name'].'</option>'; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | $return .= '</select>'; |
||
| 155 | $xajax_response -> addAssign('ajax_list_multiple','innerHTML',api_utf8_encode($return)); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | return $xajax_response; |
||
| 160 | } |
||
| 161 | $xajax->processRequests(); |
||
| 162 | |||
| 163 | Display::display_header($tool_name); |
||
| 164 | |||
| 165 | View Code Duplication | if ($add_type == 'multiple') { |
|
| 166 | $link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>'; |
||
| 167 | $link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'); |
||
| 168 | } else { |
||
| 169 | $link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'); |
||
| 170 | $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>'; |
||
| 171 | } |
||
| 172 | |||
| 173 | echo '<div class="actions">'; |
||
| 174 | echo '<a href="usergroups.php">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>'; |
||
| 175 | 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>'; |
||
| 176 | echo '</div>'; |
||
| 177 | echo '<div id="advancedSearch" style="display: none">'. get_lang('SearchSessions'); ?> : |
||
| 178 | <input name="SearchSession" onchange = "xajax_search_sessions(this.value,'searchbox')" onkeyup="this.onchange()"> |
||
| 179 | </div> |
||
| 180 | <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();"';}?>> |
||
| 181 | <?php |
||
| 182 | echo '<legend>'.$data['name'].': '.$tool_name.'</legend>'; |
||
| 183 | |||
| 184 | View Code Duplication | if ($add_type=='multiple') { |
|
| 185 | if (is_array($extra_field_list)) { |
||
| 186 | if (is_array($new_field_list) && count($new_field_list)>0 ) { |
||
| 187 | echo '<h3>'.get_lang('FilterUsers').'</h3>'; |
||
| 188 | foreach ($new_field_list as $new_field) { |
||
| 189 | echo $new_field['name']; |
||
| 190 | $varname = 'field_'.$new_field['variable']; |
||
| 191 | echo ' <select name="'.$varname.'">'; |
||
| 192 | echo '<option value="0">--'.get_lang('Select').'--</option>'; |
||
| 193 | foreach ($new_field['data'] as $option) { |
||
| 194 | $checked=''; |
||
| 195 | if (isset($_POST[$varname])) { |
||
| 196 | if ($_POST[$varname]==$option[1]) { |
||
| 197 | $checked = 'selected="true"'; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>'; |
||
| 201 | } |
||
| 202 | echo '</select>'; |
||
| 203 | echo ' '; |
||
| 204 | } |
||
| 205 | echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />'; |
||
| 206 | echo '<br /><br />'; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | echo Display::input('hidden','id',$id); |
||
| 211 | echo Display::input('hidden','form_sent','1'); |
||
| 212 | echo Display::input('hidden','add_type',null); |
||
| 213 | if(!empty($errorMsg)) { |
||
| 214 | Display::display_normal_message($errorMsg); //main API |
||
| 215 | } |
||
| 216 | ?> |
||
| 217 | |||
| 218 | <table border="0" cellpadding="5" cellspacing="0" width="100%"> |
||
| 219 | <tr> |
||
| 220 | <td align="center"><b><?php echo get_lang('SessionsInPlatform') ?> :</b> |
||
| 221 | </td> |
||
| 222 | <td></td> |
||
| 223 | <td align="center"><b><?php echo get_lang('SessionsInGroup') ?> :</b></td> |
||
| 224 | </tr> |
||
| 225 | |||
| 226 | <?php if ($add_type=='multiple') { ?> |
||
| 227 | <tr> |
||
| 228 | <td align="center"> |
||
| 229 | <?php echo get_lang('FirstLetterSessions'); ?> : |
||
| 230 | <select name="firstLetterUser" onchange = "xajax_search_sessions(this.value,'multiple')" > |
||
| 231 | <option value = "%">--</option> |
||
| 232 | <?php |
||
| 233 | echo Display :: get_alphabet_options(); |
||
| 234 | ?> |
||
| 235 | </select> |
||
| 236 | <?php echo '<br />'; ?> |
||
| 237 | </td> |
||
| 238 | <td align="center"> </td> |
||
| 239 | </tr> |
||
| 240 | <?php } ?> |
||
| 241 | <tr> |
||
| 242 | <td align="center"> |
||
| 243 | <div id="content_source"> |
||
| 244 | <?php |
||
| 245 | View Code Duplication | if (!($add_type=='multiple')) { |
|
| 246 | ?> |
||
| 247 | <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" /> |
||
| 248 | <div id="ajax_list_users_single"></div> |
||
| 249 | <?php |
||
| 250 | } else { |
||
| 251 | ?> |
||
| 252 | <div id="ajax_list_multiple"> |
||
| 253 | <?php echo Display::select('elements_not_in_name',$elements_not_in, '',array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_not_in','size'=>'15px'),false); ?> |
||
| 254 | </div> |
||
| 255 | <?php |
||
| 256 | } |
||
| 257 | ?> |
||
| 258 | </div> |
||
| 259 | </td> |
||
| 260 | <td width="10%" valign="middle" align="center"> |
||
| 261 | <?php |
||
| 262 | if ($ajax_search) { |
||
| 263 | ?> |
||
| 264 | <button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('elements_in'))" > |
||
| 265 | <em class="fa fa-arrow-left"></em> |
||
| 266 | </button> |
||
| 267 | <?php |
||
| 268 | } else { |
||
| 269 | ?> |
||
| 270 | <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'))"> |
||
| 271 | <em class="fa fa-arrow-right"></em> |
||
| 272 | </button> |
||
| 273 | <br /><br /> |
||
| 274 | <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'))"> |
||
| 275 | <em class="fa fa-arrow-left"></em> |
||
| 276 | </button> |
||
| 277 | <?php |
||
| 278 | } |
||
| 279 | ?> |
||
| 280 | <br /><br /><br /><br /><br /><br /> |
||
| 281 | </td> |
||
| 282 | <td align="center"> |
||
| 283 | <?php |
||
| 284 | echo Display::select('elements_in_name[]', $elements_in, '', array('style'=>'width:360px', 'multiple'=>'multiple','id'=>'elements_in','size'=>'15px'),false ); |
||
| 285 | unset($sessionUsersList); |
||
| 286 | ?> |
||
| 287 | </td> |
||
| 288 | </tr> |
||
| 289 | <tr> |
||
| 290 | <td colspan="3" align="center"> |
||
| 291 | <br /> |
||
| 292 | <?php |
||
| 293 | echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('SubscribeClassToSessions').'</button>'; |
||
| 294 | ?> |
||
| 295 | </td> |
||
| 296 | </tr> |
||
| 297 | </table> |
||
| 298 | </form> |
||
| 299 | |||
| 300 | <script type="text/javascript"> |
||
| 301 | function moveItem(origin , destination) { |
||
| 302 | for(var i = 0 ; i<origin.options.length ; i++) { |
||
| 303 | if(origin.options[i].selected) { |
||
| 304 | destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value); |
||
| 305 | origin.options[i]=null; |
||
| 306 | i = i-1; |
||
| 307 | } |
||
| 308 | } |
||
| 309 | destination.selectedIndex = -1; |
||
| 310 | sortOptions(destination.options); |
||
| 311 | } |
||
| 312 | |||
| 313 | function sortOptions(options) { |
||
| 314 | newOptions = new Array(); |
||
| 315 | for (i = 0 ; i<options.length ; i++) |
||
| 316 | newOptions[i] = options[i]; |
||
| 317 | |||
| 318 | newOptions = newOptions.sort(mysort); |
||
| 319 | options.length = 0; |
||
| 320 | for(i = 0 ; i < newOptions.length ; i++) |
||
| 321 | options[i] = newOptions[i]; |
||
| 322 | } |
||
| 323 | |||
| 324 | function mysort(a, b){ |
||
| 325 | if(a.text.toLowerCase() > b.text.toLowerCase()){ |
||
| 326 | return 1; |
||
| 327 | } |
||
| 328 | if(a.text.toLowerCase() < b.text.toLowerCase()){ |
||
| 329 | return -1; |
||
| 330 | } |
||
| 331 | return 0; |
||
| 332 | } |
||
| 333 | |||
| 334 | function valide(){ |
||
| 335 | var options = document.getElementById('elements_in').options; |
||
| 336 | for (i = 0 ; i<options.length ; i++) |
||
| 337 | options[i].selected = true; |
||
| 338 | document.forms.formulaire.submit(); |
||
| 339 | } |
||
| 340 | |||
| 341 | function loadUsersInSelect(select) { |
||
| 342 | var xhr_object = null; |
||
| 343 | if(window.XMLHttpRequest) // Firefox |
||
| 344 | xhr_object = new XMLHttpRequest(); |
||
| 345 | else if(window.ActiveXObject) // Internet Explorer |
||
| 346 | xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); |
||
| 347 | else // XMLHttpRequest non supporté par le navigateur |
||
| 348 | alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); |
||
| 349 | |||
| 350 | xhr_object.open("POST", "loadUsersInSelect.ajax.php"); |
||
| 351 | xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
||
| 352 | nosessionUsers = makepost(document.getElementById('elements_not_in')); |
||
| 353 | sessionUsers = makepost(document.getElementById('elements_in')); |
||
| 354 | nosessionClasses = makepost(document.getElementById('origin_classes')); |
||
| 355 | sessionClasses = makepost(document.getElementById('destination_classes')); |
||
| 356 | xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses); |
||
| 357 | |||
| 358 | xhr_object.onreadystatechange = function() { |
||
| 359 | if(xhr_object.readyState == 4) { |
||
| 360 | document.getElementById('content_source').innerHTML = result = xhr_object.responseText; |
||
| 361 | //alert(xhr_object.responseText); |
||
| 362 | } |
||
| 363 | } |
||
| 364 | } |
||
| 365 | |||
| 366 | function makepost(select){ |
||
| 367 | var options = select.options; |
||
| 368 | var ret = ""; |
||
| 369 | for (i = 0 ; i<options.length ; i++) |
||
| 370 | ret = ret + options[i].value +'::'+options[i].text+";;"; |
||
| 371 | |||
| 372 | return ret; |
||
| 373 | } |
||
| 374 | </script> |
||
| 375 | <?php |
||
| 376 | Display::display_footer(); |
||
| 377 |
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.