add_users_to_session.php 29 KB

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