add_users_to_session.php 30 KB

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