add_users_to_session.php 31 KB

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