add_users_to_session.php 33 KB

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