add_users_to_session.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $cidReset = true;
  4. require_once __DIR__.'/../inc/global.inc.php';
  5. $xajax = new xajax();
  6. $xajax->registerFunction('search_users');
  7. // setting the section (for the tabs)
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. $id_session = intval($_GET['id_session']);
  10. SessionManager::protect_teacher_session_edit($id_session);
  11. // setting breadcrumbs
  12. if (api_is_platform_admin()) {
  13. $interbreadcrumb[] = [
  14. 'url' => 'index.php',
  15. 'name' => get_lang('Administration'),
  16. ];
  17. $interbreadcrumb[] = [
  18. 'url' => 'session_list.php',
  19. 'name' => get_lang('Session list'),
  20. ];
  21. $interbreadcrumb[] = [
  22. 'url' => "resume_session.php?id_session=".$id_session,
  23. "name" => get_lang('Session overview'),
  24. ];
  25. }
  26. $allowTutors = api_get_setting('allow_tutors_to_assign_students_to_session');
  27. $extra_field_list = [];
  28. if ($allowTutors == 'true') {
  29. // Database Table Definitions
  30. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  31. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  32. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  33. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  34. // setting the name of the tool
  35. $tool_name = get_lang('Subscribe users to this session');
  36. $add_type = 'unique';
  37. if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
  38. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  39. }
  40. $page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
  41. // Checking for extra field with filter on
  42. $extra_field_list = UserManager::get_extra_fields();
  43. $new_field_list = [];
  44. if (is_array($extra_field_list)) {
  45. foreach ($extra_field_list as $extra_field) {
  46. //if is enabled to filter and is a "<select>" field type
  47. if ($extra_field[8] == 1 && $extra_field[2] == 4) {
  48. $new_field_list[] = [
  49. 'name' => $extra_field[3],
  50. 'variable' => $extra_field[1],
  51. 'data' => $extra_field[9],
  52. ];
  53. }
  54. }
  55. }
  56. function search_users($needle, $type)
  57. {
  58. global $id_session;
  59. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  60. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  61. $xajax_response = new xajaxResponse();
  62. $return = '';
  63. if (!empty($needle) && !empty($type)) {
  64. //normal behaviour
  65. if ($type == 'any_session' && $needle == 'false') {
  66. $type = 'multiple';
  67. $needle = '';
  68. }
  69. // xajax send utf8 datas... datas in db can be non-utf8 datas
  70. $charset = api_get_system_encoding();
  71. $needle = Database::escape_string($needle);
  72. $needle = api_convert_encoding($needle, $charset, 'utf-8');
  73. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  74. $cond_user_id = '';
  75. //Only for single & multiple
  76. if (in_array($type, ['single', 'multiple'])) {
  77. if (!empty($id_session)) {
  78. $id_session = intval($id_session);
  79. // check id_user from session_rel_user table
  80. $sql = 'SELECT user_id FROM '.$tbl_session_rel_user.'
  81. WHERE session_id ="'.$id_session.'" AND relation_type<>'.SESSION_RELATION_TYPE_RRHH.' ';
  82. $res = Database::query($sql);
  83. $user_ids = [];
  84. if (Database::num_rows($res) > 0) {
  85. while ($row = Database::fetch_row($res)) {
  86. $user_ids[] = (int) $row[0];
  87. }
  88. }
  89. if (count($user_ids) > 0) {
  90. $cond_user_id = ' AND user.user_id NOT IN('.implode(",", $user_ids).')';
  91. }
  92. }
  93. }
  94. switch ($type) {
  95. case 'single':
  96. // search users where username or firstname or lastname begins likes $needle
  97. $sql = 'SELECT user.user_id, username, lastname, firstname
  98. FROM '.$tbl_user.' user
  99. WHERE (username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%"
  100. OR lastname LIKE "'.$needle.'%") AND user.status<>6 AND user.status<>'.DRH.''.
  101. $order_clause.
  102. ' LIMIT 11';
  103. break;
  104. case 'multiple':
  105. $sql = 'SELECT user.user_id, username, lastname, firstname
  106. FROM '.$tbl_user.' user
  107. WHERE '.(api_sort_by_first_name() ? 'firstname' : 'lastname').'
  108. LIKE "'.$needle.'%" AND
  109. user.status<>'.DRH.' AND
  110. user.status<>6 '.$cond_user_id.
  111. $order_clause;
  112. break;
  113. case 'any_session':
  114. $sql = 'SELECT DISTINCT user.user_id, username, lastname, firstname
  115. FROM '.$tbl_user.' user
  116. LEFT OUTER JOIN '.$tbl_session_rel_user.' s ON (s.user_id = user.user_id)
  117. WHERE
  118. s.user_id IS NULL AND
  119. user.status <>'.DRH.' AND
  120. user.status <> 6 '.$cond_user_id.
  121. $order_clause;
  122. break;
  123. }
  124. if (api_is_multiple_url_enabled()) {
  125. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  126. $access_url_id = api_get_current_access_url_id();
  127. if ($access_url_id != -1) {
  128. switch ($type) {
  129. case 'single':
  130. $sql = 'SELECT user.user_id, username, lastname, firstname
  131. FROM '.$tbl_user.' user
  132. INNER JOIN '.$tbl_user_rel_access_url.' url_user
  133. ON (url_user.user_id=user.user_id)
  134. WHERE
  135. access_url_id = '.$access_url_id.' AND
  136. (username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%" OR lastname LIKE "'.$needle.'%") AND
  137. user.status<>6 AND
  138. user.status<>'.DRH.' '.
  139. $order_clause.
  140. ' LIMIT 11';
  141. break;
  142. case 'multiple':
  143. $sql = 'SELECT user.user_id, username, lastname, firstname
  144. FROM '.$tbl_user.' user
  145. INNER JOIN '.$tbl_user_rel_access_url.' url_user
  146. ON (url_user.user_id=user.user_id)
  147. WHERE access_url_id = '.$access_url_id.' AND
  148. '.(api_sort_by_first_name() ? 'firstname' : 'lastname').' LIKE "'.$needle.'%" AND user.status<>'.DRH.' AND user.status<>6 '.$cond_user_id.
  149. $order_clause;
  150. break;
  151. case 'any_session':
  152. $sql = 'SELECT DISTINCT user.user_id, username, lastname, firstname
  153. FROM '.$tbl_user.' user
  154. LEFT OUTER JOIN '.$tbl_session_rel_user.' s
  155. ON (s.user_id = user.user_id)
  156. INNER JOIN '.$tbl_user_rel_access_url.' url_user
  157. ON (url_user.user_id=user.user_id)
  158. WHERE
  159. access_url_id = '.$access_url_id.' AND
  160. s.user_id IS null AND
  161. user.status<>'.DRH.' AND
  162. user.status<>6 '.$cond_user_id.
  163. $order_clause;
  164. break;
  165. }
  166. }
  167. }
  168. $rs = Database::query($sql);
  169. $i = 0;
  170. if ($type == 'single') {
  171. while ($user = Database::fetch_array($rs)) {
  172. $i++;
  173. if ($i <= 10) {
  174. $person_name = api_get_person_name($user['firstname'], $user['lastname']);
  175. $return .= '<a href="javascript: void(0);" onclick="javascript: add_user_to_session(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
  176. } else {
  177. $return .= '...<br />';
  178. }
  179. }
  180. $xajax_response->addAssign('ajax_list_users_single', 'innerHTML', api_utf8_encode($return));
  181. } else {
  182. $return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
  183. while ($user = Database :: fetch_array($rs)) {
  184. $person_name = api_get_person_name($user['firstname'], $user['lastname']);
  185. $return .= '<option value="'.$user['user_id'].'">'.$person_name.' ('.$user['username'].')</option>';
  186. }
  187. $return .= '</select>';
  188. $xajax_response->addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return));
  189. }
  190. }
  191. return $xajax_response;
  192. }
  193. $xajax->processRequests();
  194. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  195. $htmlHeadXtra[] = '<script>
  196. function add_user_to_session (code, content) {
  197. document.getElementById("user_to_add").value = "";
  198. document.getElementById("ajax_list_users_single").innerHTML = "";
  199. destination = document.getElementById("destination_users");
  200. for (i=0;i<destination.length;i++) {
  201. if(destination.options[i].text == content) {
  202. return false;
  203. }
  204. }
  205. destination.options[destination.length] = new Option(content,code);
  206. destination.selectedIndex = -1;
  207. sortOptions(destination.options);
  208. }
  209. function remove_item(origin) {
  210. for(var i = 0 ; i<origin.options.length ; i++) {
  211. if(origin.options[i].selected) {
  212. origin.options[i]=null;
  213. i = i-1;
  214. }
  215. }
  216. }
  217. function validate_filter() {
  218. document.formulaire.add_type.value = \''.$add_type.'\';
  219. document.formulaire.form_sent.value=0;
  220. document.formulaire.submit();
  221. }
  222. function checked_in_no_session(checked) {
  223. $("#first_letter_user")
  224. .find("option")
  225. .attr("selected", false);
  226. xajax_search_users(checked, "any_session");
  227. }
  228. function change_select(val) {
  229. $("#user_with_any_session_id").attr("checked", false);
  230. xajax_search_users(val,"multiple");
  231. }
  232. </script>';
  233. $form_sent = 0;
  234. $firstLetterUser = $firstLetterSession = '';
  235. $UserList = $SessionList = [];
  236. $sessions = [];
  237. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  238. $form_sent = $_POST['form_sent'];
  239. $firstLetterUser = $_POST['firstLetterUser'];
  240. $firstLetterSession = $_POST['firstLetterSession'];
  241. $UserList = $_POST['sessionUsersList'];
  242. if (!is_array($UserList)) {
  243. $UserList = [];
  244. }
  245. if ($form_sent == 1) {
  246. //added a parameter to send emails when registering a user
  247. SessionManager::subscribeUsersToSession($id_session, $UserList, null, true);
  248. header('Location: resume_session.php?id_session='.$id_session);
  249. exit;
  250. }
  251. }
  252. $session_info = SessionManager::fetch($id_session);
  253. Display::display_header($tool_name);
  254. $nosessionUsersList = $sessionUsersList = [];
  255. $ajax_search = $add_type === 'unique' ? true : false;
  256. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  257. if ($ajax_search) {
  258. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  259. FROM $tbl_user u
  260. INNER JOIN $tbl_session_rel_user
  261. ON
  262. $tbl_session_rel_user.user_id = u.user_id AND
  263. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
  264. $tbl_session_rel_user.session_id = ".intval($id_session)."
  265. WHERE u.status <> ".DRH." AND u.status<>6 $order_clause";
  266. if (api_is_multiple_url_enabled()) {
  267. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  268. $access_url_id = api_get_current_access_url_id();
  269. if ($access_url_id != -1) {
  270. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  271. FROM $tbl_user u
  272. INNER JOIN $tbl_session_rel_user
  273. ON
  274. $tbl_session_rel_user.user_id = u.user_id AND
  275. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
  276. $tbl_session_rel_user.session_id = ".intval($id_session)."
  277. INNER JOIN $tbl_user_rel_access_url url_user
  278. ON (url_user.user_id=u.user_id)
  279. WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
  280. $order_clause";
  281. }
  282. }
  283. $result = Database::query($sql);
  284. $users = Database::store_result($result);
  285. foreach ($users as $user) {
  286. $sessionUsersList[$user['user_id']] = $user;
  287. }
  288. unset($users); //clean to free memory
  289. } else {
  290. //Filter by Extra Fields
  291. $use_extra_fields = false;
  292. if (is_array($extra_field_list)) {
  293. if (is_array($new_field_list) && count($new_field_list) > 0) {
  294. $result_list = [];
  295. foreach ($new_field_list as $new_field) {
  296. $varname = 'field_'.$new_field['variable'];
  297. if (UserManager::is_extra_field_available($new_field['variable'])) {
  298. if (isset($_POST[$varname]) && $_POST[$varname] != '0') {
  299. $use_extra_fields = true;
  300. $extra_field_result[] = UserManager::get_extra_user_data_by_value(
  301. $new_field['variable'],
  302. $_POST[$varname]
  303. );
  304. }
  305. }
  306. }
  307. }
  308. }
  309. if ($use_extra_fields) {
  310. $final_result = [];
  311. if (count($extra_field_result) > 1) {
  312. for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
  313. if (is_array($extra_field_result[$i + 1])) {
  314. $final_result = array_intersect(
  315. $extra_field_result[$i],
  316. $extra_field_result[$i + 1]
  317. );
  318. }
  319. }
  320. } else {
  321. $final_result = $extra_field_result[0];
  322. }
  323. $where_filter = '';
  324. if (api_is_multiple_url_enabled()) {
  325. if (is_array($final_result) && count($final_result) > 0) {
  326. $where_filter = " AND u.user_id IN ('".implode("','", $final_result)."') ";
  327. } else {
  328. //no results
  329. $where_filter = " AND u.user_id = -1";
  330. }
  331. } else {
  332. if (is_array($final_result) && count($final_result) > 0) {
  333. $where_filter = " WHERE u.user_id IN ('".implode("','", $final_result)."') ";
  334. } else {
  335. //no results
  336. $where_filter = " WHERE u.user_id = -1";
  337. }
  338. }
  339. }
  340. if ($use_extra_fields) {
  341. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  342. FROM $tbl_user u
  343. LEFT JOIN $tbl_session_rel_user
  344. ON $tbl_session_rel_user.user_id = u.user_id AND
  345. $tbl_session_rel_user.session_id = '$id_session' AND
  346. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  347. $where_filter AND u.status<>".DRH." AND u.status<>6
  348. $order_clause";
  349. } else {
  350. $sql = "SELECT user_id, lastname, firstname, username, session_id
  351. FROM $tbl_user u
  352. LEFT JOIN $tbl_session_rel_user
  353. ON $tbl_session_rel_user.user_id = u.user_id AND
  354. $tbl_session_rel_user.session_id = '$id_session' AND
  355. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  356. WHERE u.status <> ".DRH." AND u.status<>6
  357. $order_clause";
  358. }
  359. if (api_is_multiple_url_enabled()) {
  360. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  361. $access_url_id = api_get_current_access_url_id();
  362. if ($access_url_id != -1) {
  363. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  364. FROM $tbl_user u
  365. LEFT JOIN $tbl_session_rel_user
  366. ON
  367. $tbl_session_rel_user.user_id = u.user_id AND
  368. $tbl_session_rel_user.session_id = '$id_session' AND
  369. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  370. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
  371. WHERE access_url_id = $access_url_id $where_filter AND u.status<>".DRH." AND u.status<>6
  372. $order_clause";
  373. }
  374. }
  375. $result = Database::query($sql);
  376. $users = Database::store_result($result, 'ASSOC');
  377. foreach ($users as $uid => $user) {
  378. if ($user['session_id'] != $id_session) {
  379. $nosessionUsersList[$user['user_id']] = [
  380. 'fn' => $user['firstname'],
  381. 'ln' => $user['lastname'],
  382. 'un' => $user['username'],
  383. ];
  384. unset($users[$uid]);
  385. }
  386. }
  387. unset($users); //clean to free memory
  388. //filling the correct users in list
  389. $sql = "SELECT user_id, lastname, firstname, username, session_id
  390. FROM $tbl_user u
  391. LEFT JOIN $tbl_session_rel_user
  392. ON
  393. $tbl_session_rel_user.user_id = u.id AND
  394. $tbl_session_rel_user.session_id = '$id_session' AND
  395. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  396. WHERE u.status <> ".DRH." AND u.status<>6 $order_clause";
  397. if (api_is_multiple_url_enabled()) {
  398. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  399. $access_url_id = api_get_current_access_url_id();
  400. if ($access_url_id != -1) {
  401. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  402. FROM $tbl_user u
  403. LEFT JOIN $tbl_session_rel_user
  404. ON
  405. $tbl_session_rel_user.user_id = u.user_id AND
  406. $tbl_session_rel_user.session_id = '$id_session' AND
  407. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  408. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
  409. WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
  410. $order_clause";
  411. }
  412. }
  413. $result = Database::query($sql);
  414. $users = Database::store_result($result, 'ASSOC');
  415. foreach ($users as $uid => $user) {
  416. if ($user['session_id'] == $id_session) {
  417. $sessionUsersList[$user['user_id']] = $user;
  418. if (array_key_exists($user['user_id'], $nosessionUsersList)) {
  419. unset($nosessionUsersList[$user['user_id']]);
  420. }
  421. }
  422. unset($users[$uid]);
  423. }
  424. unset($users); //clean to free memory
  425. }
  426. if ($add_type === 'multiple') {
  427. $link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=unique">'.
  428. Display::return_icon('single.gif').get_lang('Single registration').'</a>';
  429. $link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('Multiple registration');
  430. } else {
  431. $link_add_type_unique = Display::return_icon('single.gif').get_lang('Single registration');
  432. $link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.Security::remove_XSS($_GET['add']).'&add_type=multiple">'.
  433. Display::return_icon('multiple.gif').get_lang('Multiple registration').'</a>';
  434. }
  435. $link_add_group = '<a href="usergroups.php">'.
  436. Display::return_icon('multiple.gif', get_lang('Enrolment by classes')).get_lang('Enrolment by classes').'</a>'; ?>
  437. <div class="actions">
  438. <?php echo $link_add_type_unique; ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple; ?>&nbsp;|&nbsp;<?php echo $link_add_group; ?>
  439. </div>
  440. <form name="formulaire" method="post"
  441. action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $id_session; ?><?php if (!empty($_GET['add'])) {
  442. echo '&add=true';
  443. } ?>" style="margin:0px;" <?php if ($ajax_search) {
  444. echo ' onsubmit="valide();"';
  445. } ?>>
  446. <?php echo '<legend>'.$tool_name.' ('.$session->getName().') </legend>'; ?>
  447. <?php
  448. if ($add_type === 'multiple') {
  449. if (is_array($extra_field_list)) {
  450. if (is_array($new_field_list) && count($new_field_list) > 0) {
  451. echo '<h3>'.get_lang('Filter users').'</h3>';
  452. foreach ($new_field_list as $new_field) {
  453. echo $new_field['name'];
  454. $varname = 'field_'.$new_field['variable'];
  455. echo '&nbsp;<select name="'.$varname.'">';
  456. echo '<option value="0">--'.get_lang('Select').'--</option>';
  457. foreach ($new_field['data'] as $option) {
  458. $checked = '';
  459. if (isset($_POST[$varname])) {
  460. if ($_POST[$varname] == $option[1]) {
  461. $checked = 'selected="true"';
  462. }
  463. }
  464. echo '<option value="'.$option[1].'" '.$checked.'>'.$option[1].'</option>';
  465. }
  466. echo '</select>';
  467. echo '&nbsp;&nbsp;';
  468. }
  469. echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
  470. echo '<br /><br />';
  471. }
  472. }
  473. } ?>
  474. <input type="hidden" name="form_sent" value="1" />
  475. <input type="hidden" name="add_type" />
  476. <div class="row">
  477. <div class="span5">
  478. <div class="multiple_select_header">
  479. <b><?php echo get_lang('Portal users list'); ?> :</b>
  480. <?php if ($add_type == 'multiple') {
  481. ?>
  482. <?php echo get_lang('First letter (last name)'); ?> :
  483. <select id="first_letter_user" name="firstLetterUser" onchange = "change_select(this.value);" >
  484. <option value = "%">--</option>
  485. <?php
  486. echo Display :: get_alphabet_options(); ?>
  487. </select>
  488. <?php
  489. } ?>
  490. </div>
  491. <div id="content_source">
  492. <?php
  493. if (!($add_type == 'multiple')) {
  494. ?>
  495. <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" />
  496. <div id="ajax_list_users_single"></div>
  497. <?php
  498. } else {
  499. ?>
  500. <div id="ajax_list_users_multiple">
  501. <select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" class="span5">
  502. <?php
  503. foreach ($nosessionUsersList as $uid => $enreg) {
  504. ?>
  505. <option value="<?php echo $uid; ?>" <?php if (in_array($uid, $UserList)) {
  506. echo 'selected="selected"';
  507. } ?>><?php echo api_get_person_name($enreg['fn'], $enreg['ln']).' ('.$enreg['un'].')'; ?></option>
  508. <?php
  509. } ?>
  510. </select>
  511. </div>
  512. <input type="checkbox" onchange="checked_in_no_session(this.checked);" name="user_with_any_session" id="user_with_any_session_id">
  513. <label for="user_with_any_session_id"><?php echo get_lang('Users not registered in any session'); ?></label>
  514. <?php
  515. }
  516. unset($nosessionUsersList); ?>
  517. </div>
  518. </div>
  519. <div class="span2">
  520. <div style="padding-top:54px;width:auto;text-align: center;">
  521. <?php
  522. if ($ajax_search) {
  523. ?>
  524. <button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('destination_users'))" ><em class="fa fa-arrow-left"></em></button>
  525. <?php
  526. } else {
  527. ?>
  528. <button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))" onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))">
  529. <em class="fa fa-arrow-right"></em>
  530. </button>
  531. <br /><br />
  532. <button class="btn btn-default" type="button" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))" onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
  533. <em class="fa fa-arrow-left"></em>
  534. </button>
  535. <?php
  536. } ?>
  537. </div>
  538. <br />
  539. <br />
  540. <?php
  541. if (isset($_GET['add'])) {
  542. echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('Finish session creation').'</button>';
  543. } else {
  544. //@todo see that the call to "valide()" doesn't duplicate the onsubmit of the form (necessary to avoid delete on "enter" key pressed)
  545. echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('Subscribe users to this session').'</button>';
  546. } ?>
  547. </div>
  548. <div class="span5">
  549. <div class="multiple_select_header">
  550. <b><?php echo get_lang('List of users registered in this session'); ?> :</b>
  551. </div>
  552. <select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15" class="span5">
  553. <?php
  554. foreach ($sessionUsersList as $enreg) {
  555. ?>
  556. <option value="<?php echo $enreg['user_id']; ?>"><?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
  557. <?php
  558. }
  559. unset($sessionUsersList); ?>
  560. </select>
  561. </div>
  562. </div>
  563. </form>
  564. <script>
  565. function moveItem(origin , destination) {
  566. for (var i = 0 ; i<origin.options.length ; i++) {
  567. if (origin.options[i].selected) {
  568. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  569. origin.options[i]=null;
  570. i = i-1;
  571. }
  572. }
  573. destination.selectedIndex = -1;
  574. sortOptions(destination.options);
  575. }
  576. function sortOptions(options)
  577. {
  578. newOptions = new Array();
  579. for (i = 0 ; i<options.length ; i++)
  580. newOptions[i] = options[i];
  581. newOptions = newOptions.sort(mysort);
  582. options.length = 0;
  583. for (i = 0 ; i < newOptions.length ; i++)
  584. options[i] = newOptions[i];
  585. }
  586. function mysort(a, b)
  587. {
  588. if (a.text.toLowerCase() > b.text.toLowerCase()) {
  589. return 1;
  590. }
  591. if (a.text.toLowerCase() < b.text.toLowerCase()) {
  592. return -1;
  593. }
  594. return 0;
  595. }
  596. function valide()
  597. {
  598. var options = document.getElementById('destination_users').options;
  599. for (i = 0 ; i<options.length ; i++)
  600. options[i].selected = true;
  601. document.forms.formulaire.submit();
  602. }
  603. function loadUsersInSelect(select)
  604. {
  605. var xhr_object = null;
  606. if(window.XMLHttpRequest) // Firefox
  607. xhr_object = new XMLHttpRequest();
  608. else if(window.ActiveXObject) // Internet Explorer
  609. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  610. else // XMLHttpRequest non supporté par le navigateur
  611. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  612. //xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session; ?>&letter="+select.options[select.selectedIndex].text, false);
  613. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  614. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  615. nosessionUsers = makepost(document.getElementById('origin_users'));
  616. sessionUsers = makepost(document.getElementById('destination_users'));
  617. nosessionClasses = makepost(document.getElementById('origin_classes'));
  618. sessionClasses = makepost(document.getElementById('destination_classes'));
  619. xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
  620. xhr_object.onreadystatechange = function() {
  621. if (xhr_object.readyState == 4) {
  622. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  623. //alert(xhr_object.responseText);
  624. }
  625. }
  626. }
  627. function makepost(select)
  628. {
  629. var options = select.options;
  630. var ret = "";
  631. for (i = 0 ; i<options.length ; i++)
  632. ret = ret + options[i].value +'::'+options[i].text+";;";
  633. return ret;
  634. }
  635. </script>
  636. <?php
  637. } else {
  638. api_not_allowed();
  639. }
  640. Display::display_footer();