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