add_users_to_session.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // resetting the course id
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $xajax = new xajax();
  10. $xajax->registerFunction('search_users');
  11. // setting the section (for the tabs)
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. $id_session = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  14. $addProcess = isset($_GET['add']) ? Security::remove_XSS($_GET['add']) : null;
  15. SessionManager::protectSession($id_session);
  16. // setting breadcrumbs
  17. $interbreadcrumb[] = ['url' => 'session_list.php', 'name' => get_lang('SessionList')];
  18. $interbreadcrumb[] = [
  19. 'url' => 'resume_session.php?id_session='.$id_session,
  20. 'name' => get_lang('SessionOverview'),
  21. ];
  22. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  23. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  24. // setting the name of the tool
  25. $tool_name = get_lang('SubscribeUsersToSession');
  26. $add_type = 'unique';
  27. if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
  28. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  29. }
  30. $page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
  31. // Checking for extra field with filter on
  32. $extra_field_list = UserManager::get_extra_fields();
  33. $new_field_list = [];
  34. if (is_array($extra_field_list)) {
  35. foreach ($extra_field_list as $extra_field) {
  36. //if is enabled to filter and is a "<select>" field type
  37. if ($extra_field[8] == 1 && $extra_field[2] == ExtraField::FIELD_TYPE_SELECT) {
  38. $new_field_list[] = [
  39. 'name' => $extra_field[3],
  40. 'type' => $extra_field[2],
  41. 'variable' => $extra_field[1],
  42. 'data' => $extra_field[9],
  43. ];
  44. }
  45. if ($extra_field[8] == 1 && $extra_field[2] == ExtraField::FIELD_TYPE_TAG) {
  46. $options = UserManager::get_extra_user_data_for_tags($extra_field[1]);
  47. $new_field_list[] = [
  48. 'name' => $extra_field[3],
  49. 'type' => $extra_field[2],
  50. 'variable' => $extra_field[1],
  51. 'data' => $options['options'],
  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. $needle = Database::escape_string($needle);
  70. $order_clause = ' ORDER BY lastname, firstname, username';
  71. $showOfficialCode = false;
  72. $orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
  73. if ($orderListByOfficialCode === 'true') {
  74. $showOfficialCode = true;
  75. $order_clause = ' ORDER BY official_code, lastname, firstname, username';
  76. }
  77. if (api_is_session_admin()
  78. && api_get_setting('prevent_session_admins_to_manage_all_users') === 'true'
  79. ) {
  80. $order_clause = " AND user.creator_id = ".api_get_user_id().$order_clause;
  81. }
  82. $cond_user_id = '';
  83. // Only for single & multiple
  84. if (in_array($type, ['single', 'multiple'])) {
  85. if (!empty($id_session)) {
  86. $id_session = (int) $id_session;
  87. // check id_user from session_rel_user table
  88. $sql = "
  89. SELECT user_id FROM $tbl_session_rel_user
  90. WHERE session_id = $id_session AND relation_type <> ".SESSION_RELATION_TYPE_RRHH;
  91. $res = Database::query($sql);
  92. $user_ids = [];
  93. if (Database::num_rows($res) > 0) {
  94. while ($row = Database::fetch_row($res)) {
  95. $user_ids[] = (int) $row[0];
  96. }
  97. }
  98. if (count($user_ids) > 0) {
  99. $cond_user_id = ' AND user.id NOT IN('.implode(",", $user_ids).')';
  100. }
  101. }
  102. }
  103. switch ($type) {
  104. case 'single':
  105. // search users where username or firstname or lastname begins likes $needle
  106. $sql = "
  107. SELECT user.id, username, lastname, firstname, official_code
  108. FROM $tbl_user user
  109. WHERE
  110. (
  111. username LIKE '$needle%'
  112. OR lastname LIKE '$needle%'
  113. OR firstname LIKE '$needle%'
  114. )
  115. AND user.status <> 6
  116. AND user.status <> ".DRH."
  117. $order_clause LIMIT 11
  118. ";
  119. break;
  120. case 'multiple':
  121. $sql = "
  122. SELECT user.id, username, lastname, firstname, official_code
  123. FROM $tbl_user user
  124. WHERE
  125. lastname LIKE '$needle%'
  126. AND user.status <> ".DRH."
  127. AND user.status <> 6 $cond_user_id
  128. $order_clause
  129. ";
  130. break;
  131. case 'any_session':
  132. $sql = "
  133. SELECT DISTINCT user.id, username, lastname, firstname, official_code
  134. FROM $tbl_user user
  135. LEFT OUTER JOIN $tbl_session_rel_user s ON (s.user_id = user.id)
  136. WHERE
  137. s.user_id IS NULL
  138. AND user.status <> ".DRH."
  139. AND user.status <> 6 $cond_user_id
  140. $order_clause
  141. ";
  142. break;
  143. }
  144. if (api_is_multiple_url_enabled()) {
  145. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  146. $access_url_id = api_get_current_access_url_id();
  147. if ($access_url_id != -1) {
  148. switch ($type) {
  149. case 'single':
  150. $sql = "
  151. SELECT user.id, username, lastname, firstname, official_code
  152. FROM $tbl_user user
  153. INNER JOIN $tbl_user_rel_access_url url_user
  154. ON (url_user.user_id = user.id)
  155. WHERE
  156. access_url_id = '$access_url_id' AND
  157. (
  158. username LIKE '$needle%' OR
  159. lastname LIKE '$needle%' OR
  160. firstname LIKE '$needle%'
  161. ) AND
  162. user.status <> 6 AND
  163. user.status <> ".DRH."
  164. $order_clause LIMIT 11
  165. ";
  166. break;
  167. case 'multiple':
  168. $sql = "
  169. SELECT user.id, username, lastname, firstname, official_code
  170. FROM $tbl_user user
  171. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=user.id)
  172. WHERE
  173. access_url_id = $access_url_id
  174. AND lastname LIKE '$needle%'
  175. AND user.status <> ".DRH."
  176. AND user.status <> 6 $cond_user_id
  177. $order_clause
  178. ";
  179. break;
  180. case 'any_session':
  181. $sql = "
  182. SELECT DISTINCT user.id, username, lastname, firstname, official_code
  183. FROM $tbl_user user
  184. LEFT OUTER JOIN $tbl_session_rel_user s
  185. ON (s.user_id = user.id)
  186. INNER JOIN $tbl_user_rel_access_url url_user
  187. ON (url_user.user_id = user.id)
  188. WHERE
  189. access_url_id = $access_url_id
  190. AND s.user_id IS null
  191. AND user.status <> ".DRH."
  192. AND user.status <> 6 $cond_user_id
  193. $order_clause
  194. ";
  195. break;
  196. }
  197. }
  198. }
  199. $rs = Database::query($sql);
  200. $i = 0;
  201. if ($type == 'single') {
  202. while ($user = Database:: fetch_array($rs)) {
  203. $i++;
  204. if ($i <= 10) {
  205. $person_name =
  206. $user['lastname'].' '.$user['firstname'].' ('.$user['username'].') '.$user['official_code'];
  207. if ($showOfficialCode) {
  208. $officialCode = !empty($user['official_code']) ? $user['official_code'].' - ' : '? - ';
  209. $person_name =
  210. $officialCode.$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')';
  211. }
  212. $return .= Display::url(
  213. $person_name,
  214. 'javascript: void(0);',
  215. ['onclick' => "add_user_to_session('".$user['id']."', '".addslashes($person_name)."');"]
  216. ).'<br>';
  217. } else {
  218. $return .= '...<br />';
  219. }
  220. }
  221. $xajax_response->addAssign('ajax_list_users_single', 'innerHTML', api_utf8_encode($return));
  222. } else {
  223. $return .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
  224. while ($user = Database:: fetch_array($rs)) {
  225. $person_name =
  226. $user['lastname'].' '.$user['firstname'].' ('.$user['username'].') '.$user['official_code'];
  227. if ($showOfficialCode) {
  228. $officialCode = !empty($user['official_code']) ? $user['official_code'].' - ' : '? - ';
  229. $person_name = $officialCode.$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')';
  230. }
  231. $return .= '<option value="'.$user['id'].'">'.$person_name.' </option>';
  232. }
  233. $return .= '</select>';
  234. $xajax_response->addAssign('ajax_list_users_multiple', 'innerHTML', api_utf8_encode($return));
  235. }
  236. }
  237. return $xajax_response;
  238. }
  239. $xajax->processRequests();
  240. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  241. $htmlHeadXtra[] = '
  242. <script>
  243. function add_user_to_session (code, content) {
  244. document.getElementById("user_to_add").value = "";
  245. document.getElementById("ajax_list_users_single").innerHTML = "";
  246. destination = document.getElementById("destination_users");
  247. for (i=0;i<destination.length;i++) {
  248. if(destination.options[i].text == content) {
  249. return false;
  250. }
  251. }
  252. destination.options[destination.length] = new Option(content,code);
  253. destination.selectedIndex = -1;
  254. $("#remove_user").show();
  255. sortOptions(destination.options);
  256. }
  257. function remove_item(origin) {
  258. for(var i = 0 ; i<origin.options.length ; i++) {
  259. if(origin.options[i].selected) {
  260. origin.options[i]=null;
  261. i = i-1;
  262. }
  263. }
  264. }
  265. function validate_filter() {
  266. document.formulaire.add_type.value = \''.$add_type.'\';
  267. document.formulaire.form_sent.value=0;
  268. document.formulaire.submit();
  269. }
  270. function checked_in_no_session(checked) {
  271. $("#first_letter_user")
  272. .find("option")
  273. .attr("selected", false);
  274. xajax_search_users(checked, "any_session");
  275. }
  276. function change_select(val) {
  277. $("#user_with_any_session_id").attr("checked", false);
  278. xajax_search_users(val,"multiple");
  279. }
  280. </script>';
  281. $form_sent = 0;
  282. $errorMsg = $firstLetterUser = $firstLetterSession = '';
  283. $UserList = $SessionList = [];
  284. $sessions = [];
  285. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  286. $form_sent = $_POST['form_sent'];
  287. $UserList = isset($_POST['sessionUsersList']) ? $_POST['sessionUsersList'] : [];
  288. if (!is_array($UserList)) {
  289. $UserList = [];
  290. }
  291. if ($form_sent == 1) {
  292. //$notEmptyList = api_get_configuration_value('session_multiple_subscription_students_list_avoid_emptying');
  293. // Added a parameter to send emails when registering a user
  294. SessionManager::subscribeUsersToSession(
  295. $id_session,
  296. $UserList,
  297. null,
  298. false
  299. );
  300. Display::addFlash(Display::return_message(get_lang('Updated')));
  301. header('Location: resume_session.php?id_session='.$id_session);
  302. exit;
  303. }
  304. }
  305. $session_info = SessionManager::fetch($id_session);
  306. Display::display_header($tool_name);
  307. $nosessionUsersList = $sessionUsersList = [];
  308. $where_filter = null;
  309. $ajax_search = $add_type == 'unique' ? true : false;
  310. //$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  311. // On this screen, it doesn't make sense to order users by firstname. Always use lastname first
  312. // api_get_person_name() calls have been removed because ordering users in a simple list must always
  313. // be done by lastname, even if we like to show user names with the firstname first.
  314. // By simple logic, lastnames are the smallest common denominator
  315. $order_clause = ' ORDER BY lastname, firstname, username';
  316. $showOfficialCode = false;
  317. $orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
  318. if ($orderListByOfficialCode === 'true') {
  319. $showOfficialCode = true;
  320. $order_clause = ' ORDER BY official_code, lastname, firstname, username';
  321. }
  322. if ($ajax_search) {
  323. $sessionUserInfo = SessionManager::getTotalUserCoursesInSession($id_session);
  324. // Filter the user list in all courses in the session
  325. foreach ($sessionUserInfo as $sessionUser) {
  326. // filter students in session
  327. if ($sessionUser['status_in_session'] != 0) {
  328. continue;
  329. }
  330. if (!array_key_exists($sessionUser['id'], $sessionUsersList)) {
  331. continue;
  332. }
  333. }
  334. unset($users); //clean to free memory
  335. } else {
  336. // Filter by Extra Fields
  337. $extra_field_result = [];
  338. $use_extra_fields = false;
  339. if (is_array($extra_field_list)) {
  340. if (is_array($new_field_list) && count($new_field_list) > 0) {
  341. $result_list = [];
  342. foreach ($new_field_list as $new_field) {
  343. $varname = 'field_'.$new_field['variable'];
  344. $fieldtype = $new_field['type'];
  345. if (UserManager::is_extra_field_available($new_field['variable'])) {
  346. if (isset($_POST[$varname]) && $_POST[$varname] != '0') {
  347. $use_extra_fields = true;
  348. if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
  349. $extra_field_result[] = UserManager::get_extra_user_data_by_tags(
  350. intval($_POST['field_id']),
  351. $_POST[$varname]
  352. );
  353. } else {
  354. $extra_field_result[] = UserManager::get_extra_user_data_by_value(
  355. $new_field['variable'],
  356. $_POST[$varname]
  357. );
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. if ($use_extra_fields) {
  365. $final_result = [];
  366. if (count($extra_field_result) > 1) {
  367. for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
  368. if (is_array($extra_field_result[$i + 1])) {
  369. $final_result = array_intersect(
  370. $extra_field_result[$i],
  371. $extra_field_result[$i + 1]
  372. );
  373. }
  374. }
  375. } else {
  376. $final_result = $extra_field_result[0];
  377. }
  378. if (api_is_multiple_url_enabled()) {
  379. if (is_array($final_result) && count($final_result) > 0) {
  380. $where_filter = " AND u.id IN ('".implode("','", $final_result)."') ";
  381. } else {
  382. //no results
  383. $where_filter = " AND u.id = -1";
  384. }
  385. } else {
  386. if (is_array($final_result) && count($final_result) > 0) {
  387. $where_filter = " WHERE u.id IN ('".implode("','", $final_result)."') ";
  388. } else {
  389. //no results
  390. $where_filter = " WHERE u.id = -1";
  391. }
  392. }
  393. }
  394. if (api_is_session_admin() && api_get_setting('prevent_session_admins_to_manage_all_users') === 'true') {
  395. $order_clause = " AND u.creator_id = ".api_get_user_id().$order_clause;
  396. }
  397. if ($use_extra_fields) {
  398. $sql = "
  399. SELECT u.id, lastname, firstname, username, session_id, official_code
  400. FROM $tbl_user u
  401. LEFT JOIN $tbl_session_rel_user su
  402. ON su.user_id = u.id
  403. AND su.session_id = $id_session
  404. AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  405. $where_filter
  406. AND u.status <> ".DRH."
  407. AND u.status <> 6
  408. $order_clause
  409. ";
  410. } else {
  411. $sql = "
  412. SELECT u.id, lastname, firstname, username, session_id, official_code
  413. FROM $tbl_user u
  414. LEFT JOIN $tbl_session_rel_user su
  415. ON su.user_id = u.id
  416. AND su.session_id = $id_session
  417. AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  418. WHERE u.status <> ".DRH." AND u.status <> 6
  419. $order_clause
  420. ";
  421. }
  422. if (api_is_multiple_url_enabled()) {
  423. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  424. $access_url_id = api_get_current_access_url_id();
  425. if ($access_url_id != -1) {
  426. $sql = "
  427. SELECT u.id, lastname, firstname, username, session_id, official_code
  428. FROM $tbl_user u
  429. LEFT JOIN $tbl_session_rel_user su
  430. ON su.user_id = u.id
  431. AND su.session_id = $id_session
  432. AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  433. INNER JOIN $tbl_user_rel_access_url url_user
  434. ON (url_user.user_id = u.id)
  435. WHERE access_url_id = $access_url_id $where_filter
  436. AND u.status <> ".DRH."
  437. AND u.status<>6
  438. $order_clause
  439. ";
  440. }
  441. }
  442. $result = Database::query($sql);
  443. $users = Database::store_result($result, 'ASSOC');
  444. foreach ($users as $uid => $user) {
  445. if ($user['session_id'] != $id_session) {
  446. $nosessionUsersList[$user['id']] = [
  447. 'fn' => $user['firstname'],
  448. 'ln' => $user['lastname'],
  449. 'un' => $user['username'],
  450. 'official_code' => $user['official_code'],
  451. ];
  452. unset($users[$uid]);
  453. }
  454. }
  455. unset($users); //clean to free memory
  456. // filling the correct users in list
  457. $sql = "
  458. SELECT u.id, lastname, firstname, username, session_id, official_code
  459. FROM $tbl_user u
  460. LEFT JOIN $tbl_session_rel_user
  461. ON $tbl_session_rel_user.user_id = u.id
  462. AND $tbl_session_rel_user.session_id = $id_session
  463. AND $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  464. WHERE u.status <> ".DRH." AND u.status <> 6 $order_clause
  465. ";
  466. if (api_is_multiple_url_enabled()) {
  467. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  468. $access_url_id = api_get_current_access_url_id();
  469. if ($access_url_id != -1) {
  470. $sql = "
  471. SELECT u.id, lastname, firstname, username, session_id, official_code
  472. FROM $tbl_user u
  473. LEFT JOIN $tbl_session_rel_user
  474. ON $tbl_session_rel_user.user_id = u.id
  475. AND $tbl_session_rel_user.session_id = $id_session
  476. AND $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  477. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id = u.id)
  478. WHERE access_url_id = $access_url_id
  479. AND u.status <> ".DRH."
  480. AND u.status <> 6
  481. $order_clause
  482. ";
  483. }
  484. }
  485. $result = Database::query($sql);
  486. $users = Database::store_result($result, 'ASSOC');
  487. foreach ($users as $uid => $user) {
  488. if ($user['session_id'] == $id_session) {
  489. $sessionUsersList[$user['id']] = $user;
  490. if (array_key_exists($user['id'], $nosessionUsersList)) {
  491. unset($nosessionUsersList[$user['id']]);
  492. }
  493. }
  494. unset($users[$uid]);
  495. }
  496. unset($users); //clean to free memory
  497. }
  498. if ($add_type == 'multiple') {
  499. $link_add_type_unique =
  500. '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.$addProcess.'&add_type=unique">'.
  501. Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
  502. $link_add_type_multiple = Display::url(Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'), '');
  503. } else {
  504. $link_add_type_unique = Display::url(Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'), '');
  505. $link_add_type_multiple =
  506. '<a href="'.api_get_self().'?id_session='.$id_session.'&amp;add='.$addProcess.'&amp;add_type=multiple">'
  507. .Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
  508. }
  509. $link_add_group = Display::url(
  510. Display::return_icon('multiple.gif', get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups'),
  511. api_get_path(WEB_CODE_PATH).'admin/usergroups.php'
  512. );
  513. $newLinks = Display::url(
  514. Display::return_icon('teacher.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
  515. get_lang('EnrollTrainersFromExistingSessions'),
  516. api_get_path(WEB_CODE_PATH).'session/add_teachers_to_session.php?id='.$id_session
  517. );
  518. $newLinks .= Display::url(
  519. Display::return_icon('user.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
  520. get_lang('EnrollStudentsFromExistingSessions'),
  521. api_get_path(WEB_CODE_PATH).'session/add_students_to_session.php?id='.$id_session
  522. );
  523. ?>
  524. <div class="actions">
  525. <?php
  526. echo $link_add_type_unique;
  527. echo $link_add_type_multiple;
  528. echo $link_add_group;
  529. echo $newLinks;
  530. ?>
  531. </div>
  532. <form name="formulaire" method="post"
  533. action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $id_session; ?><?php if (!empty($addProcess)) {
  534. echo '&add=true';
  535. } ?>" <?php if ($ajax_search) {
  536. echo ' onsubmit="valide();"';
  537. } ?>>
  538. <?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') </legend>'; ?>
  539. <?php
  540. if ($add_type == 'multiple') {
  541. if (is_array($extra_field_list)) {
  542. if (is_array($new_field_list) && count($new_field_list) > 0) {
  543. echo '<h3>'.get_lang('FilterUsers').'</h3>';
  544. foreach ($new_field_list as $new_field) {
  545. echo $new_field['name'];
  546. $varname = 'field_'.$new_field['variable'];
  547. $fieldtype = $new_field['type'];
  548. echo '&nbsp;<select name="'.$varname.'">';
  549. echo '<option value="0">--'.get_lang('Select').'--</option>';
  550. foreach ($new_field['data'] as $option) {
  551. $checked = '';
  552. if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
  553. if (isset($_POST[$varname])) {
  554. if ($_POST[$varname] == $option['tag']) {
  555. $checked = 'selected="true"';
  556. }
  557. }
  558. echo '<option value="'.$option['tag'].'" '.$checked.'>'.$option['tag'].'</option>';
  559. } else {
  560. if (isset($_POST[$varname])) {
  561. if ($_POST[$varname] == $option[1]) {
  562. $checked = 'selected="true"';
  563. }
  564. }
  565. echo '<option value="'.$option[1].'" '.$checked.'>'.$option[2].'</option>';
  566. }
  567. }
  568. echo '</select>';
  569. $extraHidden =
  570. $fieldtype == ExtraField::FIELD_TYPE_TAG ? '<input type="hidden" name="field_id" value="'
  571. .$option['field_id'].'" />' : '';
  572. echo $extraHidden;
  573. echo '&nbsp;&nbsp;';
  574. }
  575. echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
  576. echo '<br /><br />';
  577. }
  578. }
  579. }
  580. ?>
  581. <input type="hidden" name="form_sent" value="1"/>
  582. <input type="hidden" name="add_type"/>
  583. <?php
  584. if (!empty($errorMsg)) {
  585. echo Display::return_message($errorMsg); //main API
  586. }
  587. ?>
  588. <div id="multiple-add-session" class="row">
  589. <div class="col-md-4">
  590. <div class="form-group">
  591. <?php
  592. if (!($add_type == 'multiple')) {
  593. ?>
  594. <input
  595. placeholder="<?php echo get_lang('Search'); ?>"
  596. type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')"
  597. class="form-control"/>
  598. <div id="ajax_list_users_single" class="select-list-ajax"></div>
  599. <?php
  600. } else {
  601. ?>
  602. <div id="ajax_list_users_multiple">
  603. <select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15"
  604. class="form-control">
  605. <?php
  606. foreach ($nosessionUsersList as $uid => $enreg) {
  607. ?>
  608. <option value="<?php echo $uid; ?>" <?php if (in_array($uid, $UserList)) {
  609. echo 'selected="selected"';
  610. } ?>>
  611. <?php
  612. $personName = $enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].') '
  613. .$enreg['official_code'];
  614. if ($showOfficialCode) {
  615. $officialCode =
  616. !empty($enreg['official_code']) ? $enreg['official_code'].' - '
  617. : '? - ';
  618. $personName =
  619. $officialCode.$enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].')';
  620. }
  621. echo $personName; ?>
  622. </option>
  623. <?php
  624. } ?>
  625. </select>
  626. </div>
  627. <input type="checkbox" onchange="checked_in_no_session(this.checked);"
  628. name="user_with_any_session" id="user_with_any_session_id">
  629. <label
  630. for="user_with_any_session_id"><?php echo get_lang('UsersRegisteredInNoSession'); ?></label>
  631. <?php
  632. }
  633. unset($nosessionUsersList);
  634. ?>
  635. </div>
  636. </div>
  637. <div class="col-md-4">
  638. <?php if ($add_type == 'multiple') {
  639. ?>
  640. <?php echo get_lang('FirstLetterUser'); ?> :
  641. <select id="first_letter_user" name="firstLetterUser" onchange="change_select(this.value);">
  642. <option value="%">--</option>
  643. <?php
  644. echo Display:: get_alphabet_options(); ?>
  645. </select>
  646. <br/>
  647. <br/>
  648. <?php
  649. } ?>
  650. <div class="control-course">
  651. <?php
  652. if ($ajax_search) {
  653. ?>
  654. <?php
  655. } else {
  656. ?>
  657. <div class="separate-action">
  658. <button name="add_user" class="btn btn-primary" type="button"
  659. onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))"
  660. onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))">
  661. <em class="fa fa-chevron-right"></em>
  662. </button>
  663. </div>
  664. <div class="separate-action">
  665. <button name="remove_user" class="btn btn-primary" type="button"
  666. onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))"
  667. onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
  668. <em class="fa fa-chevron-left"></em>
  669. </button>
  670. </div>
  671. <?php
  672. }
  673. if (!empty($addProcess)) {
  674. echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'
  675. .get_lang('FinishSessionCreation').'</button>';
  676. } else {
  677. echo '<button name="next" class="btn btn-success" type="button" value="" onclick="valide()" >'
  678. .get_lang('SubscribeUsersToSession').'</button>';
  679. }
  680. ?>
  681. </div>
  682. </div>
  683. <div class="col-md-4">
  684. <select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15"
  685. class="form-control">
  686. </select>
  687. <br />
  688. <button style="display:none" id="remove_user" name="remove_user" class="btn btn-danger" type="button"
  689. onclick="remove_item(document.getElementById('destination_users'))">
  690. <?php echo get_lang('Remove'); ?> <em class="fa fa-trash"></em>
  691. </button>
  692. </div>
  693. </div>
  694. </form>
  695. <script>
  696. function moveItem(origin, destination) {
  697. for (var i = 0; i < origin.options.length; i++) {
  698. if (origin.options[i].selected) {
  699. destination.options[destination.length] = new Option(origin.options[i].text, origin.options[i].value);
  700. origin.options[i] = null;
  701. i = i - 1;
  702. }
  703. }
  704. destination.selectedIndex = -1;
  705. sortOptions(destination.options);
  706. }
  707. function sortOptions(options) {
  708. newOptions = new Array();
  709. for (i = 0; i < options.length; i++)
  710. newOptions[i] = options[i];
  711. newOptions = newOptions.sort(mysort);
  712. options.length = 0;
  713. for (i = 0; i < newOptions.length; i++)
  714. options[i] = newOptions[i];
  715. }
  716. function mysort(a, b) {
  717. if (a.text.toLowerCase() > b.text.toLowerCase()) {
  718. return 1;
  719. }
  720. if (a.text.toLowerCase() < b.text.toLowerCase()) {
  721. return -1;
  722. }
  723. return 0;
  724. }
  725. function valide() {
  726. var options = document.getElementById('destination_users').options;
  727. for (i = 0; i < options.length; i++)
  728. options[i].selected = true;
  729. document.forms.formulaire.submit();
  730. }
  731. function loadUsersInSelect(select) {
  732. var xhr_object = null;
  733. if (window.XMLHttpRequest) // Firefox
  734. xhr_object = new XMLHttpRequest();
  735. else if (window.ActiveXObject) // Internet Explorer
  736. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  737. else // XMLHttpRequest non supporté par le navigateur
  738. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  739. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  740. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  741. nosessionUsers = makepost(document.getElementById('origin_users'));
  742. sessionUsers = makepost(document.getElementById('destination_users'));
  743. nosessionClasses = makepost(document.getElementById('origin_classes'));
  744. sessionClasses = makepost(document.getElementById('destination_classes'));
  745. xhr_object.send("nosessionusers=" + nosessionUsers + "&sessionusers=" + sessionUsers + "&nosessionclasses=" + nosessionClasses + "&sessionclasses=" + sessionClasses);
  746. xhr_object.onreadystatechange = function () {
  747. if (xhr_object.readyState == 4) {
  748. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  749. }
  750. }
  751. }
  752. function makepost(select) {
  753. var options = select.options;
  754. var ret = "";
  755. for (i = 0; i < options.length; i++)
  756. ret = ret + options[i].value + '::' + options[i].text + ";;";
  757. return ret;
  758. }
  759. </script>
  760. <?php
  761. Display::display_footer();