add_users_to_session.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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[] = array(
  19. 'url' => 'index.php',
  20. 'name' => get_lang('PlatformAdmin')
  21. );
  22. $interbreadcrumb[] = array(
  23. 'url' => 'session_list.php',
  24. 'name' => get_lang('SessionList')
  25. );
  26. $interbreadcrumb[] = array(
  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 = array();
  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[] = array(
  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, array('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 = array();
  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 = array();
  241. $sessions = array();
  242. $noPHP_SELF = true;
  243. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  244. $form_sent = $_POST['form_sent'];
  245. $firstLetterUser = $_POST['firstLetterUser'];
  246. $firstLetterSession = $_POST['firstLetterSession'];
  247. $UserList = $_POST['sessionUsersList'];
  248. if (!is_array($UserList)) {
  249. $UserList = array();
  250. }
  251. if ($form_sent == 1) {
  252. //added a parameter to send emails when registering a user
  253. SessionManager::subscribe_users_to_session($id_session, $UserList, null, true);
  254. header('Location: resume_session.php?id_session='.$id_session);
  255. exit;
  256. }
  257. }
  258. $session_info = SessionManager::fetch($id_session);
  259. Display::display_header($tool_name);
  260. $nosessionUsersList = $sessionUsersList = array();
  261. $ajax_search = $add_type === 'unique' ? true : false;
  262. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  263. if ($ajax_search) {
  264. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  265. FROM $tbl_user u
  266. INNER JOIN $tbl_session_rel_user
  267. ON
  268. $tbl_session_rel_user.user_id = u.user_id AND
  269. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
  270. $tbl_session_rel_user.session_id = ".intval($id_session)."
  271. WHERE u.status <> ".DRH." AND u.status<>6 $order_clause";
  272. if (api_is_multiple_url_enabled()) {
  273. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  274. $access_url_id = api_get_current_access_url_id();
  275. if ($access_url_id != -1) {
  276. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  277. FROM $tbl_user u
  278. INNER JOIN $tbl_session_rel_user
  279. ON
  280. $tbl_session_rel_user.user_id = u.user_id AND
  281. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
  282. $tbl_session_rel_user.session_id = ".intval($id_session)."
  283. INNER JOIN $tbl_user_rel_access_url url_user
  284. ON (url_user.user_id=u.user_id)
  285. WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
  286. $order_clause";
  287. }
  288. }
  289. $result = Database::query($sql);
  290. $users = Database::store_result($result);
  291. foreach ($users as $user) {
  292. $sessionUsersList[$user['user_id']] = $user;
  293. }
  294. unset($users); //clean to free memory
  295. } else {
  296. //Filter by Extra Fields
  297. $use_extra_fields = false;
  298. if (is_array($extra_field_list)) {
  299. if (is_array($new_field_list) && count($new_field_list) > 0) {
  300. $result_list = array();
  301. foreach ($new_field_list as $new_field) {
  302. $varname = 'field_'.$new_field['variable'];
  303. if (UserManager::is_extra_field_available($new_field['variable'])) {
  304. if (isset($_POST[$varname]) && $_POST[$varname] != '0') {
  305. $use_extra_fields = true;
  306. $extra_field_result[] = UserManager::get_extra_user_data_by_value(
  307. $new_field['variable'],
  308. $_POST[$varname]
  309. );
  310. }
  311. }
  312. }
  313. }
  314. }
  315. if ($use_extra_fields) {
  316. $final_result = array();
  317. if (count($extra_field_result) > 1) {
  318. for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
  319. if (is_array($extra_field_result[$i + 1])) {
  320. $final_result = array_intersect(
  321. $extra_field_result[$i],
  322. $extra_field_result[$i + 1]
  323. );
  324. }
  325. }
  326. } else {
  327. $final_result = $extra_field_result[0];
  328. }
  329. $where_filter = '';
  330. if (api_is_multiple_url_enabled()) {
  331. if (is_array($final_result) && count($final_result) > 0) {
  332. $where_filter = " AND u.user_id IN ('".implode("','", $final_result)."') ";
  333. } else {
  334. //no results
  335. $where_filter = " AND u.user_id = -1";
  336. }
  337. } else {
  338. if (is_array($final_result) && count($final_result) > 0) {
  339. $where_filter = " WHERE u.user_id IN ('".implode("','", $final_result)."') ";
  340. } else {
  341. //no results
  342. $where_filter = " WHERE u.user_id = -1";
  343. }
  344. }
  345. }
  346. if ($use_extra_fields) {
  347. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  348. FROM $tbl_user u
  349. LEFT JOIN $tbl_session_rel_user
  350. ON $tbl_session_rel_user.user_id = u.user_id AND
  351. $tbl_session_rel_user.session_id = '$id_session' AND
  352. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  353. $where_filter AND u.status<>".DRH." AND u.status<>6
  354. $order_clause";
  355. } else {
  356. $sql = "SELECT user_id, lastname, firstname, username, session_id
  357. FROM $tbl_user u
  358. LEFT JOIN $tbl_session_rel_user
  359. ON $tbl_session_rel_user.user_id = u.user_id AND
  360. $tbl_session_rel_user.session_id = '$id_session' AND
  361. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  362. WHERE u.status <> ".DRH." AND u.status<>6
  363. $order_clause";
  364. }
  365. if (api_is_multiple_url_enabled()) {
  366. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  367. $access_url_id = api_get_current_access_url_id();
  368. if ($access_url_id != -1) {
  369. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  370. FROM $tbl_user u
  371. LEFT JOIN $tbl_session_rel_user
  372. ON
  373. $tbl_session_rel_user.user_id = u.user_id AND
  374. $tbl_session_rel_user.session_id = '$id_session' AND
  375. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  376. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
  377. WHERE access_url_id = $access_url_id $where_filter AND u.status<>".DRH." AND u.status<>6
  378. $order_clause";
  379. }
  380. }
  381. $result = Database::query($sql);
  382. $users = Database::store_result($result, 'ASSOC');
  383. foreach ($users as $uid => $user) {
  384. if ($user['session_id'] != $id_session) {
  385. $nosessionUsersList[$user['user_id']] = array(
  386. 'fn' => $user['firstname'],
  387. 'ln' => $user['lastname'],
  388. 'un' => $user['username']
  389. );
  390. unset($users[$uid]);
  391. }
  392. }
  393. unset($users); //clean to free memory
  394. //filling the correct users in list
  395. $sql = "SELECT user_id, lastname, firstname, username, session_id
  396. FROM $tbl_user u
  397. LEFT JOIN $tbl_session_rel_user
  398. ON
  399. $tbl_session_rel_user.user_id = u.id AND
  400. $tbl_session_rel_user.session_id = '$id_session' AND
  401. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  402. WHERE u.status <> ".DRH." AND u.status<>6 $order_clause";
  403. if (api_is_multiple_url_enabled()) {
  404. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  405. $access_url_id = api_get_current_access_url_id();
  406. if ($access_url_id != -1) {
  407. $sql = "SELECT u.user_id, lastname, firstname, username, session_id
  408. FROM $tbl_user u
  409. LEFT JOIN $tbl_session_rel_user
  410. ON
  411. $tbl_session_rel_user.user_id = u.user_id AND
  412. $tbl_session_rel_user.session_id = '$id_session' AND
  413. $tbl_session_rel_user.relation_type<>".SESSION_RELATION_TYPE_RRHH."
  414. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=u.user_id)
  415. WHERE access_url_id = $access_url_id AND u.status<>".DRH." AND u.status<>6
  416. $order_clause";
  417. }
  418. }
  419. $result = Database::query($sql);
  420. $users = Database::store_result($result, 'ASSOC');
  421. foreach ($users as $uid => $user) {
  422. if ($user['session_id'] == $id_session) {
  423. $sessionUsersList[$user['user_id']] = $user;
  424. if (array_key_exists($user['user_id'], $nosessionUsersList)) {
  425. unset($nosessionUsersList[$user['user_id']]);
  426. }
  427. }
  428. unset($users[$uid]);
  429. }
  430. unset($users); //clean to free memory
  431. }
  432. if ($add_type === 'multiple') {
  433. $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>';
  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">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
  438. }
  439. $link_add_group = '<a href="usergroups.php">'.
  440. Display::return_icon('multiple.gif', get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups').'</a>';
  441. ?>
  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" action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $id_session; ?><?php if (!empty($_GET['add'])) echo '&add=true'; ?>" style="margin:0px;" <?php if ($ajax_search) {echo ' onsubmit="valide();"'; }?>>
  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('FilterUsers').'</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. ?>
  475. <input type="hidden" name="form_sent" value="1" />
  476. <input type="hidden" name="add_type" />
  477. <div class="row">
  478. <div class="span5">
  479. <div class="multiple_select_header">
  480. <b><?php echo get_lang('UserListInPlatform') ?> :</b>
  481. <?php if ($add_type == 'multiple') { ?>
  482. <?php echo get_lang('FirstLetterUser'); ?> :
  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. ?>
  488. </select>
  489. <?php } ?>
  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)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($enreg['fn'], $enreg['ln']).' ('.$enreg['un'].')'; ?></option>
  506. <?php
  507. }
  508. ?>
  509. </select>
  510. </div>
  511. <input type="checkbox" onchange="checked_in_no_session(this.checked);" name="user_with_any_session" id="user_with_any_session_id">
  512. <label for="user_with_any_session_id"><?php echo get_lang('UsersRegisteredInNoSession'); ?></label>
  513. <?php
  514. }
  515. unset($nosessionUsersList);
  516. ?>
  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. ?>
  538. </div>
  539. <br />
  540. <br />
  541. <?php
  542. if (isset($_GET['add'])) {
  543. echo '<button class="btn btn-primary" type="button" value="" onclick="valide()" >'.get_lang('FinishSessionCreation').'</button>';
  544. } else {
  545. //@todo see that the call to "valide()" doesn't duplicate the onsubmit of the form (necessary to avoid delete on "enter" key pressed)
  546. echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeUsersToSession').'</button>';
  547. }
  548. ?>
  549. </div>
  550. <div class="span5">
  551. <div class="multiple_select_header">
  552. <b><?php echo get_lang('UserListInSession') ?> :</b>
  553. </div>
  554. <select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15" class="span5">
  555. <?php
  556. foreach ($sessionUsersList as $enreg) {
  557. ?>
  558. <option value="<?php echo $enreg['user_id']; ?>"><?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
  559. <?php
  560. }
  561. unset($sessionUsersList);
  562. ?>
  563. </select>
  564. </div>
  565. </div>
  566. </form>
  567. <script>
  568. function moveItem(origin , destination) {
  569. for (var i = 0 ; i<origin.options.length ; i++) {
  570. if (origin.options[i].selected) {
  571. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  572. origin.options[i]=null;
  573. i = i-1;
  574. }
  575. }
  576. destination.selectedIndex = -1;
  577. sortOptions(destination.options);
  578. }
  579. function sortOptions(options)
  580. {
  581. newOptions = new Array();
  582. for (i = 0 ; i<options.length ; i++)
  583. newOptions[i] = options[i];
  584. newOptions = newOptions.sort(mysort);
  585. options.length = 0;
  586. for (i = 0 ; i < newOptions.length ; i++)
  587. options[i] = newOptions[i];
  588. }
  589. function mysort(a, b)
  590. {
  591. if (a.text.toLowerCase() > b.text.toLowerCase()) {
  592. return 1;
  593. }
  594. if (a.text.toLowerCase() < b.text.toLowerCase()) {
  595. return -1;
  596. }
  597. return 0;
  598. }
  599. function valide()
  600. {
  601. var options = document.getElementById('destination_users').options;
  602. for (i = 0 ; i<options.length ; i++)
  603. options[i].selected = true;
  604. document.forms.formulaire.submit();
  605. }
  606. function loadUsersInSelect(select)
  607. {
  608. var xhr_object = null;
  609. if(window.XMLHttpRequest) // Firefox
  610. xhr_object = new XMLHttpRequest();
  611. else if(window.ActiveXObject) // Internet Explorer
  612. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  613. else // XMLHttpRequest non supporté par le navigateur
  614. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  615. //xhr_object.open("GET", "loadUsersInSelect.ajax.php?id_session=<?php echo $id_session ?>&letter="+select.options[select.selectedIndex].text, false);
  616. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  617. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  618. nosessionUsers = makepost(document.getElementById('origin_users'));
  619. sessionUsers = makepost(document.getElementById('destination_users'));
  620. nosessionClasses = makepost(document.getElementById('origin_classes'));
  621. sessionClasses = makepost(document.getElementById('destination_classes'));
  622. xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
  623. xhr_object.onreadystatechange = function() {
  624. if (xhr_object.readyState == 4) {
  625. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  626. //alert(xhr_object.responseText);
  627. }
  628. }
  629. }
  630. function makepost(select)
  631. {
  632. var options = select.options;
  633. var ret = "";
  634. for (i = 0 ; i<options.length ; i++)
  635. ret = ret + options[i].value +'::'+options[i].text+";;";
  636. return ret;
  637. }
  638. </script>
  639. <?php
  640. } else {
  641. api_not_allowed();
  642. }
  643. Display::display_footer();