add_users_to_session.php 27 KB

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