add_users_to_session.php 31 KB

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