add_users_to_session.php 29 KB

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