add_users_to_session.php 31 KB

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