add_users_to_session.php 31 KB

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