add_users_to_session.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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 = "
  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 = array();
  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 type="text/javascript">
  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. sortOptions(destination.options);
  257. }
  258. function remove_item(origin) {
  259. for(var i = 0 ; i<origin.options.length ; i++) {
  260. if(origin.options[i].selected) {
  261. origin.options[i]=null;
  262. i = i-1;
  263. }
  264. }
  265. }
  266. function validate_filter() {
  267. document.formulaire.add_type.value = \''.$add_type.'\';
  268. document.formulaire.form_sent.value=0;
  269. document.formulaire.submit();
  270. }
  271. function checked_in_no_session(checked) {
  272. $("#first_letter_user")
  273. .find("option")
  274. .attr("selected", false);
  275. xajax_search_users(checked, "any_session");
  276. }
  277. function change_select(val) {
  278. $("#user_with_any_session_id").attr("checked", false);
  279. xajax_search_users(val,"multiple");
  280. }
  281. </script>';
  282. $form_sent = 0;
  283. $errorMsg = $firstLetterUser = $firstLetterSession = '';
  284. $UserList = $SessionList = array();
  285. $sessions = array();
  286. $noPHP_SELF = true;
  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 = $_POST['sessionUsersList'];
  292. if (!is_array($UserList)) {
  293. $UserList = array();
  294. }
  295. if ($form_sent == 1) {
  296. // Added a parameter to send emails when registering a user
  297. SessionManager::subscribe_users_to_session(
  298. $id_session,
  299. $UserList,
  300. null,
  301. true
  302. );
  303. header('Location: resume_session.php?id_session='.$id_session);
  304. exit;
  305. }
  306. }
  307. $session_info = SessionManager::fetch($id_session);
  308. Display::display_header($tool_name);
  309. $nosessionUsersList = $sessionUsersList = array();
  310. $where_filter = null;
  311. $ajax_search = $add_type == 'unique' ? true : false;
  312. //$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  313. // On this screen, it doesn't make sense to order users by firstname. Always use lastname first
  314. // api_get_person_name() calls have been removed because ordering users in a simple list must always
  315. // be done by lastname, even if we like to show user names with the firstname first.
  316. // By simple logic, lastnames are the smallest common denominator
  317. $order_clause = ' ORDER BY lastname, firstname, username';
  318. $showOfficialCode = false;
  319. $orderListByOfficialCode = api_get_setting('order_user_list_by_official_code');
  320. if ($orderListByOfficialCode === 'true') {
  321. $showOfficialCode = true;
  322. $order_clause = ' ORDER BY official_code, lastname, firstname, username';
  323. }
  324. if ($ajax_search) {
  325. $sql = "
  326. SELECT u.id, u.lastname, u.firstname, u.username, session_id, u.official_code
  327. FROM $tbl_user u
  328. INNER JOIN $tbl_session_rel_user su
  329. ON su.user_id = u.id
  330. AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  331. AND su.session_id = ".intval($id_session)."
  332. WHERE u.status<>".DRH."
  333. AND u.status <> 6
  334. $order_clause
  335. ";
  336. if (api_is_multiple_url_enabled()) {
  337. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  338. $access_url_id = api_get_current_access_url_id();
  339. if ($access_url_id != -1) {
  340. $sql = "
  341. SELECT u.id, u.lastname, u.firstname, u.username, session_id, u.official_code
  342. FROM $tbl_user u
  343. INNER JOIN $tbl_session_rel_user su
  344. ON su.user_id = u.id
  345. AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  346. AND su.session_id = ".intval($id_session)."
  347. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id = u.id)
  348. WHERE access_url_id = $access_url_id
  349. AND u.status <> ".DRH."
  350. AND u.status <> 6
  351. $order_clause
  352. ";
  353. }
  354. }
  355. $result = Database::query($sql);
  356. $users = Database::store_result($result);
  357. foreach ($users as $user) {
  358. $sessionUsersList[$user['id']] = $user;
  359. }
  360. unset($users); //clean to free memory
  361. } else {
  362. // Filter by Extra Fields
  363. $extra_field_result = [];
  364. $use_extra_fields = false;
  365. if (is_array($extra_field_list)) {
  366. if (is_array($new_field_list) && count($new_field_list) > 0) {
  367. $result_list = array();
  368. foreach ($new_field_list as $new_field) {
  369. $varname = 'field_'.$new_field['variable'];
  370. $fieldtype = $new_field['type'];
  371. if (UserManager::is_extra_field_available($new_field['variable'])) {
  372. if (isset($_POST[$varname]) && $_POST[$varname] != '0') {
  373. $use_extra_fields = true;
  374. if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
  375. $extra_field_result[] = UserManager::get_extra_user_data_by_tags(
  376. intval($_POST['field_id']),
  377. $_POST[$varname]
  378. );
  379. } else {
  380. $extra_field_result[] = UserManager::get_extra_user_data_by_value(
  381. $new_field['variable'],
  382. $_POST[$varname]
  383. );
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390. if ($use_extra_fields) {
  391. $final_result = array();
  392. if (count($extra_field_result) > 1) {
  393. for ($i = 0; $i < count($extra_field_result) - 1; $i++) {
  394. if (is_array($extra_field_result[$i + 1])) {
  395. $final_result = array_intersect(
  396. $extra_field_result[$i],
  397. $extra_field_result[$i + 1]
  398. );
  399. }
  400. }
  401. } else {
  402. $final_result = $extra_field_result[0];
  403. }
  404. if (api_is_multiple_url_enabled()) {
  405. if (is_array($final_result) && count($final_result) > 0) {
  406. $where_filter = " AND u.id IN ('".implode("','", $final_result)."') ";
  407. } else {
  408. //no results
  409. $where_filter = " AND u.id = -1";
  410. }
  411. } else {
  412. if (is_array($final_result) && count($final_result) > 0) {
  413. $where_filter = " WHERE u.id IN ('".implode("','", $final_result)."') ";
  414. } else {
  415. //no results
  416. $where_filter = " WHERE u.id = -1";
  417. }
  418. }
  419. }
  420. if (api_is_session_admin() && api_get_setting('prevent_session_admins_to_manage_all_users') === 'true') {
  421. $order_clause = " AND u.creator_id = ".api_get_user_id().$order_clause;
  422. }
  423. if ($use_extra_fields) {
  424. $sql = "
  425. SELECT u.id, lastname, firstname, username, session_id, official_code
  426. FROM $tbl_user u
  427. LEFT JOIN $tbl_session_rel_user su
  428. ON su.user_id = u.id
  429. AND su.session_id = $id_session
  430. AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  431. $where_filter
  432. AND u.status <> ".DRH."
  433. AND u.status <> 6
  434. $order_clause
  435. ";
  436. } else {
  437. $sql = "
  438. SELECT u.id, lastname, firstname, username, session_id, official_code
  439. FROM $tbl_user u
  440. LEFT JOIN $tbl_session_rel_user su
  441. ON su.user_id = u.id
  442. AND su.session_id = $id_session
  443. AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  444. WHERE u.status <> ".DRH." AND u.status <> 6
  445. $order_clause
  446. ";
  447. }
  448. if (api_is_multiple_url_enabled()) {
  449. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  450. $access_url_id = api_get_current_access_url_id();
  451. if ($access_url_id != -1) {
  452. $sql = "
  453. SELECT u.id, lastname, firstname, username, session_id, official_code
  454. FROM $tbl_user u
  455. LEFT JOIN $tbl_session_rel_user su
  456. ON su.user_id = u.id
  457. AND su.session_id = $id_session
  458. AND su.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  459. INNER JOIN $tbl_user_rel_access_url url_user
  460. ON (url_user.user_id = u.id)
  461. WHERE access_url_id = $access_url_id $where_filter
  462. AND u.status <> ".DRH."
  463. AND u.status<>6
  464. $order_clause
  465. ";
  466. }
  467. }
  468. $result = Database::query($sql);
  469. $users = Database::store_result($result, 'ASSOC');
  470. foreach ($users as $uid => $user) {
  471. if ($user['session_id'] != $id_session) {
  472. $nosessionUsersList[$user['id']] = array(
  473. 'fn' => $user['firstname'],
  474. 'ln' => $user['lastname'],
  475. 'un' => $user['username'],
  476. 'official_code' => $user['official_code']
  477. );
  478. unset($users[$uid]);
  479. }
  480. }
  481. unset($users); //clean to free memory
  482. // filling the correct users in list
  483. $sql = "
  484. SELECT u.id, lastname, firstname, username, session_id, official_code
  485. FROM $tbl_user u
  486. LEFT JOIN $tbl_session_rel_user
  487. ON $tbl_session_rel_user.user_id = u.id
  488. AND $tbl_session_rel_user.session_id = $id_session
  489. AND $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  490. WHERE u.status <> ".DRH." AND u.status <> 6 $order_clause
  491. ";
  492. if (api_is_multiple_url_enabled()) {
  493. $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  494. $access_url_id = api_get_current_access_url_id();
  495. if ($access_url_id != -1) {
  496. $sql = "
  497. SELECT u.id, lastname, firstname, username, session_id, official_code
  498. FROM $tbl_user u
  499. LEFT JOIN $tbl_session_rel_user
  500. ON $tbl_session_rel_user.user_id = u.id
  501. AND $tbl_session_rel_user.session_id = $id_session
  502. AND $tbl_session_rel_user.relation_type <> ".SESSION_RELATION_TYPE_RRHH."
  503. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id = u.id)
  504. WHERE access_url_id = $access_url_id
  505. AND u.status <> ".DRH."
  506. AND u.status <> 6
  507. $order_clause
  508. ";
  509. }
  510. }
  511. $result = Database::query($sql);
  512. $users = Database::store_result($result, 'ASSOC');
  513. foreach ($users as $uid => $user) {
  514. if ($user['session_id'] == $id_session) {
  515. $sessionUsersList[$user['id']] = $user;
  516. if (array_key_exists($user['id'], $nosessionUsersList)) {
  517. unset($nosessionUsersList[$user['id']]);
  518. }
  519. }
  520. unset($users[$uid]);
  521. }
  522. unset($users); //clean to free memory
  523. }
  524. if ($add_type == 'multiple') {
  525. $link_add_type_unique =
  526. '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.$addProcess.'&add_type=unique">'.
  527. Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
  528. $link_add_type_multiple = Display::url(Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple'), '');
  529. } else {
  530. $link_add_type_unique = Display::url(Display::return_icon('single.gif').get_lang('SessionAddTypeUnique'), '');
  531. $link_add_type_multiple =
  532. '<a href="'.api_get_self().'?id_session='.$id_session.'&amp;add='.$addProcess.'&amp;add_type=multiple">'
  533. .Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
  534. }
  535. $link_add_group = Display::url(
  536. Display::return_icon('multiple.gif', get_lang('RegistrationByUsersGroups')).get_lang('RegistrationByUsersGroups'),
  537. api_get_path(WEB_CODE_PATH).'admin/usergroups.php'
  538. );
  539. $newLinks = Display::url(
  540. Display::return_icon('teacher.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
  541. get_lang('EnrollTrainersFromExistingSessions'),
  542. api_get_path(WEB_CODE_PATH).'session/add_teachers_to_session.php?id='.$id_session
  543. );
  544. $newLinks .= Display::url(
  545. Display::return_icon('user.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
  546. get_lang('EnrollStudentsFromExistingSessions'),
  547. api_get_path(WEB_CODE_PATH).'session/add_students_to_session.php?id='.$id_session
  548. );
  549. ?>
  550. <div class="actions">
  551. <?php
  552. echo $link_add_type_unique;
  553. echo $link_add_type_multiple;
  554. echo $link_add_group;
  555. echo $newLinks;
  556. ?>
  557. </div>
  558. <form name="formulaire" method="post"
  559. action="<?php echo api_get_self(); ?>?page=<?php echo $page; ?>&id_session=<?php echo $id_session; ?><?php if (!empty($addProcess)) {
  560. echo '&add=true';
  561. } ?>" <?php if ($ajax_search) {
  562. echo ' onsubmit="valide();"';
  563. } ?>>
  564. <?php echo '<legend>'.$tool_name.' ('.$session_info['name'].') </legend>'; ?>
  565. <?php
  566. if ($add_type == 'multiple') {
  567. if (is_array($extra_field_list)) {
  568. if (is_array($new_field_list) && count($new_field_list) > 0) {
  569. echo '<h3>'.get_lang('FilterUsers').'</h3>';
  570. foreach ($new_field_list as $new_field) {
  571. echo $new_field['name'];
  572. $varname = 'field_'.$new_field['variable'];
  573. $fieldtype = $new_field['type'];
  574. echo '&nbsp;<select name="'.$varname.'">';
  575. echo '<option value="0">--'.get_lang('Select').'--</option>';
  576. foreach ($new_field['data'] as $option) {
  577. $checked = '';
  578. if ($fieldtype == ExtraField::FIELD_TYPE_TAG) {
  579. if (isset($_POST[$varname])) {
  580. if ($_POST[$varname] == $option['tag']) {
  581. $checked = 'selected="true"';
  582. }
  583. }
  584. echo '<option value="'.$option['tag'].'" '.$checked.'>'.$option['tag'].'</option>';
  585. } else {
  586. if (isset($_POST[$varname])) {
  587. if ($_POST[$varname] == $option[1]) {
  588. $checked = 'selected="true"';
  589. }
  590. }
  591. echo '<option value="'.$option[1].'" '.$checked.'>'.$option[2].'</option>';
  592. }
  593. }
  594. echo '</select>';
  595. $extraHidden =
  596. $fieldtype == ExtraField::FIELD_TYPE_TAG ? '<input type="hidden" name="field_id" value="'
  597. .$option['field_id'].'" />' : '';
  598. echo $extraHidden;
  599. echo '&nbsp;&nbsp;';
  600. }
  601. echo '<input type="button" value="'.get_lang('Filter').'" onclick="validate_filter()" />';
  602. echo '<br /><br />';
  603. }
  604. }
  605. }
  606. ?>
  607. <input type="hidden" name="form_sent" value="1"/>
  608. <input type="hidden" name="add_type"/>
  609. <?php
  610. if (!empty($errorMsg)) {
  611. echo Display::return_message($errorMsg); //main API
  612. }
  613. ?>
  614. <div id="multiple-add-session" class="row">
  615. <div class="col-md-4">
  616. <div class="form-group">
  617. <label><?php echo get_lang('UserListInPlatform') ?> </label>
  618. <?php
  619. if (!($add_type == 'multiple')) {
  620. ?>
  621. <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')"
  622. class="form-control"/>
  623. <div id="ajax_list_users_single" class="select-list-ajax"></div>
  624. <?php
  625. } else {
  626. ?>
  627. <div id="ajax_list_users_multiple">
  628. <select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15"
  629. class="form-control">
  630. <?php
  631. foreach ($nosessionUsersList as $uid => $enreg) {
  632. ?>
  633. <option value="<?php echo $uid; ?>" <?php if (in_array($uid, $UserList)) {
  634. echo 'selected="selected"';
  635. } ?>>
  636. <?php
  637. $personName = $enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].') '
  638. .$enreg['official_code'];
  639. if ($showOfficialCode) {
  640. $officialCode =
  641. !empty($enreg['official_code']) ? $enreg['official_code'].' - '
  642. : '? - ';
  643. $personName =
  644. $officialCode.$enreg['ln'].' '.$enreg['fn'].' ('.$enreg['un'].')';
  645. }
  646. echo $personName;
  647. ?>
  648. </option>
  649. <?php
  650. }
  651. ?>
  652. </select>
  653. </div>
  654. <input type="checkbox" onchange="checked_in_no_session(this.checked);"
  655. name="user_with_any_session" id="user_with_any_session_id">
  656. <label
  657. for="user_with_any_session_id"><?php echo get_lang('UsersRegisteredInNoSession'); ?></label>
  658. <?php
  659. }
  660. unset($nosessionUsersList);
  661. ?>
  662. </div>
  663. </div>
  664. <div class="col-md-4">
  665. <?php if ($add_type == 'multiple') { ?>
  666. <?php echo get_lang('FirstLetterUser'); ?> :
  667. <select id="first_letter_user" name="firstLetterUser" onchange="change_select(this.value);">
  668. <option value="%">--</option>
  669. <?php
  670. echo Display:: get_alphabet_options();
  671. ?>
  672. </select>
  673. <br/>
  674. <br/>
  675. <?php } ?>
  676. <div class="control-course">
  677. <?php
  678. if ($ajax_search) {
  679. ?>
  680. <div class="separate-action">
  681. <button class="btn btn-primary" type="button"
  682. onclick="remove_item(document.getElementById('destination_users'))">
  683. <em class="fa fa-chevron-left"></em>
  684. </button>
  685. </div>
  686. <?php
  687. } else {
  688. ?>
  689. <div class="separate-action">
  690. <button class="btn btn-primary" type="button"
  691. onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))"
  692. onclick="moveItem(document.getElementById('origin_users'), document.getElementById('destination_users'))">
  693. <em class="fa fa-chevron-right"></em>
  694. </button>
  695. </div>
  696. <div class="separate-action">
  697. <button class="btn btn-primary" type="button"
  698. onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))"
  699. onclick="moveItem(document.getElementById('destination_users'), document.getElementById('origin_users'))">
  700. <em class="fa fa-chevron-left"></em>
  701. </button>
  702. </div>
  703. <?php
  704. }
  705. if (!empty($addProcess)) {
  706. echo '<button class="btn btn-success" type="button" value="" onclick="valide()" >'
  707. .get_lang('FinishSessionCreation').'</button>';
  708. } else {
  709. echo '<button class="btn btn-success" type="button" value="" onclick="valide()" >'
  710. .get_lang('SubscribeUsersToSession').'</button>';
  711. }
  712. ?>
  713. </div>
  714. </div>
  715. <div class="col-md-4">
  716. <label><?php echo get_lang('UserListInSession') ?> :</label>
  717. <select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15"
  718. class="form-control">
  719. <?php
  720. foreach ($sessionUsersList as $enreg) {
  721. ?>
  722. <option value="<?php echo $enreg['id']; ?>">
  723. <?php
  724. $personName = $enreg['lastname'].' '.$enreg['firstname'].' ('.$enreg['username'].') '
  725. .$enreg['official_code'];
  726. if ($showOfficialCode) {
  727. $officialCode =
  728. !empty($enreg['official_code']) ? $enreg['official_code'].' - ' : '? - ';
  729. $personName =
  730. $officialCode.$enreg['lastname'].' '.$enreg['firstname'].' ('.$enreg['username']
  731. .')';
  732. }
  733. echo $personName;
  734. ?>
  735. </option>
  736. <?php
  737. }
  738. unset($sessionUsersList);
  739. ?>
  740. </select>
  741. </div>
  742. </div>
  743. </form>
  744. <script>
  745. function moveItem(origin, destination) {
  746. for (var i = 0; i < origin.options.length; i++) {
  747. if (origin.options[i].selected) {
  748. destination.options[destination.length] = new Option(origin.options[i].text, origin.options[i].value);
  749. origin.options[i] = null;
  750. i = i - 1;
  751. }
  752. }
  753. destination.selectedIndex = -1;
  754. sortOptions(destination.options);
  755. }
  756. function sortOptions(options) {
  757. newOptions = new Array();
  758. for (i = 0; i < options.length; i++)
  759. newOptions[i] = options[i];
  760. newOptions = newOptions.sort(mysort);
  761. options.length = 0;
  762. for (i = 0; i < newOptions.length; i++)
  763. options[i] = newOptions[i];
  764. }
  765. function mysort(a, b) {
  766. if (a.text.toLowerCase() > b.text.toLowerCase()) {
  767. return 1;
  768. }
  769. if (a.text.toLowerCase() < b.text.toLowerCase()) {
  770. return -1;
  771. }
  772. return 0;
  773. }
  774. function valide() {
  775. var options = document.getElementById('destination_users').options;
  776. for (i = 0; i < options.length; i++)
  777. options[i].selected = true;
  778. document.forms.formulaire.submit();
  779. }
  780. function loadUsersInSelect(select) {
  781. var xhr_object = null;
  782. if (window.XMLHttpRequest) // Firefox
  783. xhr_object = new XMLHttpRequest();
  784. else if (window.ActiveXObject) // Internet Explorer
  785. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  786. else // XMLHttpRequest non supporté par le navigateur
  787. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  788. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  789. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  790. nosessionUsers = makepost(document.getElementById('origin_users'));
  791. sessionUsers = makepost(document.getElementById('destination_users'));
  792. nosessionClasses = makepost(document.getElementById('origin_classes'));
  793. sessionClasses = makepost(document.getElementById('destination_classes'));
  794. xhr_object.send("nosessionusers=" + nosessionUsers + "&sessionusers=" + sessionUsers + "&nosessionclasses=" + nosessionClasses + "&sessionclasses=" + sessionClasses);
  795. xhr_object.onreadystatechange = function () {
  796. if (xhr_object.readyState == 4) {
  797. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  798. }
  799. }
  800. }
  801. function makepost(select) {
  802. var options = select.options;
  803. var ret = "";
  804. for (i = 0; i < options.length; i++)
  805. ret = ret + options[i].value + '::' + options[i].text + ";;";
  806. return ret;
  807. }
  808. </script>
  809. <?php
  810. Display::display_footer();