add_users_to_session.php 30 KB

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