add_users_to_session.php 30 KB

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