add_users_to_session.php 31 KB

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