add_users_to_session.php 35 KB

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