add_users_to_session.php 30 KB

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