add_edit_users_to_session.php 37 KB

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