add_users_to_group.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // resetting the course id
  7. $cidReset = true;
  8. // including some necessary files
  9. require_once '../inc/global.inc.php';
  10. // setting the section (for the tabs)
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. // Access restrictions
  13. api_protect_admin_script(true);
  14. // setting breadcrumbs
  15. $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  16. $interbreadcrumb[] = array('url' => 'group_list.php','name' => get_lang('GroupList'));
  17. // Database Table Definitions
  18. $tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
  19. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  20. $tbl_group_rel_user = Database::get_main_table(TABLE_USERGROUP_REL_USER);
  21. $tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  22. $needle = null;
  23. $user_anonymous = api_get_anonymous_id();
  24. // setting the name of the tool
  25. $tool_name = get_lang('SubscribeUsersToGroup');
  26. $group_id = intval($_GET['id']);
  27. $without_user_id = null;
  28. $add_type = 'multiple';
  29. if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
  30. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  31. }
  32. //checking for extra field with filter on
  33. $xajax = new xajax();
  34. $xajax->registerFunction('search_users');
  35. function search_users($needle, $type, $relation_type)
  36. {
  37. global $tbl_user, $tbl_user_rel_access_url, $tbl_group_rel_user, $group_id;
  38. $xajax_response = new xajaxResponse();
  39. $return = $return_origin = $return_destination = '';
  40. $without_user_id = $without_user_id = $condition_relation = '';
  41. if (!empty($group_id) && !empty($relation_type)) {
  42. $group_id = intval($group_id);
  43. $relation_type = intval($relation_type);
  44. // get user_id from relation type and group id
  45. $sql = "SELECT user_id FROM $tbl_group_rel_user
  46. WHERE group_id = '$group_id'
  47. AND relation_type IN (".GROUP_USER_PERMISSION_ADMIN.",".GROUP_USER_PERMISSION_READER.",".GROUP_USER_PERMISSION_PENDING_INVITATION.",".GROUP_USER_PERMISSION_MODERATOR.", ".GROUP_USER_PERMISSION_HRM.") ";
  48. $res = Database::query($sql);
  49. $user_ids = array();
  50. if (Database::num_rows($res) > 0) {
  51. while ($row = Database::fetch_row($res)) {
  52. $user_ids[] = $row[0];
  53. }
  54. $without_user_id = " AND user.user_id NOT IN(".implode(',', $user_ids).") ";
  55. }
  56. $condition_relation = " AND groups.relation_type = '$relation_type' ";
  57. // data for destination user list
  58. $sql = "SELECT user.user_id, user.username, user.lastname, user.firstname
  59. FROM $tbl_group_rel_user groups
  60. INNER JOIN $tbl_user user ON user.user_id = groups.user_id
  61. WHERE groups.group_id = '$group_id' $condition_relation ";
  62. $rs_destination = Database::query($sql);
  63. if (Database::num_rows($rs_destination) > 0) {
  64. $return_destination .= '<select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
  65. while ($row = Database::fetch_array($rs_destination)) {
  66. $person_name = api_get_person_name($row['firstname'], $row['lastname']);
  67. $return_destination .= '<option value="'.$row['user_id'].'">'.
  68. $person_name.' ('.$row['username'].')</option>';
  69. }
  70. $return_destination .= '</select>';
  71. } else {
  72. $return_destination .= '<select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15" style="width:360px;"></select>';
  73. }
  74. $xajax_response->addAssign('ajax_destination_list','innerHTML', api_utf8_encode($return_destination));
  75. } else {
  76. $return_destination .= '<select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15" style="width:360px;"></select>';
  77. $xajax_response->addAssign('ajax_destination_list','innerHTML', api_utf8_encode($return_destination));
  78. if ($type == 'single') {
  79. $return.= '';
  80. $xajax_response->addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));
  81. } else {
  82. $return_origin .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;"></select>';
  83. $xajax_response->addAssign('ajax_origin_list_multiple', 'innerHTML', api_utf8_encode($return_origin));
  84. }
  85. }
  86. if (!empty($needle) && !empty($type)) {
  87. $user_anonymous = api_get_anonymous_id();
  88. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  89. if ($type == 'single') {
  90. if (!empty($group_id) && !empty($relation_type)) {
  91. // search users where username or firstname or lastname begins likes $needle
  92. $sql = "SELECT user_id, username, lastname, firstname
  93. FROM $tbl_user user
  94. WHERE (username LIKE '$needle%' OR firstname LIKE '$needle%' OR lastname LIKE '$needle%')
  95. AND user_id<>'$user_anonymous' $without_user_id $order_clause LIMIT 11";
  96. if (api_is_multiple_url_enabled()) {
  97. $access_url_id = api_get_current_access_url_id();
  98. if ($access_url_id != -1) {
  99. $sql = "SELECT user.user_id, username, lastname, firstname FROM $tbl_user user
  100. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=user.user_id)
  101. WHERE access_url_id = '$access_url_id' AND (username LIKE '$needle%' OR firstname LIKE '$needle%' OR lastname LIKE '$needle%')
  102. AND user.user_id<>'$user_anonymous' $without_user_id $order_clause LIMIT 11 ";
  103. }
  104. }
  105. $rs_single = Database::query($sql);
  106. $i=0;
  107. while ($user = Database :: fetch_array($rs_single)) {
  108. $i++;
  109. if ($i<=10) {
  110. $person_name = api_get_person_name($user['firstname'], $user['lastname']);
  111. $return .= '<a href="javascript: void(0);" onclick="javascript: add_user(\''.$user['user_id'].'\',\''.$person_name.' ('.$user['username'].')'.'\')">'.$person_name.' ('.$user['username'].')</a><br />';
  112. } else {
  113. $return .= '...<br />';
  114. }
  115. }
  116. $xajax_response->addAssign('ajax_list_users_single','innerHTML',api_utf8_encode($return));
  117. } else {
  118. $xajax_response->addAlert(get_lang('YouMustChooseARelationType'));
  119. $xajax_response->addClear('user_to_add', 'value');
  120. }
  121. } else {
  122. // multiple
  123. if (!empty($group_id) && !empty($relation_type)) {
  124. $sql = "SELECT user_id, username, lastname, firstname FROM $tbl_user user
  125. WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND user_id<>'$user_anonymous' $without_user_id $order_clause ";
  126. if (api_is_multiple_url_enabled()) {
  127. $access_url_id = api_get_current_access_url_id();
  128. if ($access_url_id != -1) {
  129. $sql = "SELECT user.user_id, username, lastname, firstname
  130. FROM $tbl_user user
  131. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=user.user_id)
  132. WHERE
  133. access_url_id = '$access_url_id' AND
  134. ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND
  135. user.user_id<>'$user_anonymous' $without_user_id $order_clause ";
  136. }
  137. }
  138. $rs_multiple = Database::query($sql);
  139. $return_origin .= '<select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">';
  140. while ($user = Database :: fetch_array($rs_multiple)) {
  141. $person_name = api_get_person_name($user['firstname'], $user['lastname']);
  142. $return_origin .= '<option value="'.$user['user_id'].'">'.
  143. $person_name.' ('.$user['username'].')</option>';
  144. }
  145. $return_origin .= '</select>';
  146. $xajax_response->addAssign('ajax_origin_list_multiple', 'innerHTML', api_utf8_encode($return_origin));
  147. }
  148. }
  149. }
  150. return $xajax_response;
  151. }
  152. $xajax->processRequests();
  153. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  154. $htmlHeadXtra[] = '
  155. <script>
  156. function add_user (code, content) {
  157. destination = document.getElementById("destination_users");
  158. for (i=0;i<destination.length;i++) {
  159. if (destination.options[i].text == content) {
  160. return false;
  161. }
  162. }
  163. destination.options[destination.length] = new Option(content,code);
  164. destination.selectedIndex = -1;
  165. sortOptions(destination.options);
  166. }
  167. function remove_item(origin)
  168. {
  169. for(var i = 0 ; i<origin.options.length ; i++) {
  170. if(origin.options[i].selected) {
  171. origin.options[i]=null;
  172. i = i-1;
  173. }
  174. }
  175. }
  176. function validate_filter() {
  177. document.formulaire.add_type.value = \''.$add_type.'\';
  178. document.formulaire.form_sent.value=0;
  179. document.formulaire.submit();
  180. }
  181. </script>';
  182. $form_sent = 0;
  183. $errorMsg = $firstLetterUser = $firstLetterSession='';
  184. $UserList = $SessionList = array();
  185. $users = $sessions = array();
  186. $noPHP_SELF = true;
  187. $group_info = GroupPortalManager::get_group_data($group_id);
  188. $group_name = $group_info['name'];
  189. Display::display_header($group_name);
  190. if (isset($_POST['form_sent']) && $_POST['form_sent']) {
  191. $form_sent = $_POST['form_sent'];
  192. $firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null;
  193. $UserList = $_POST['sessionUsersList'];
  194. $group_id = intval($_POST['id']);
  195. $relation_type = intval($_POST['relation']);
  196. if (!is_array($UserList)) {
  197. $UserList = array();
  198. }
  199. if ($form_sent == 1) {
  200. $users_by_group = GroupPortalManager::get_users_by_group($group_id, null, array($relation_type));
  201. $user_id_relation = array_keys($users_by_group);
  202. $user_relation_diff = array_diff($user_id_relation, $UserList);
  203. if (!empty($user_relation_diff)) {
  204. foreach ($user_relation_diff as $user_id) {
  205. GroupPortalManager::delete_user_rel_group($user_id, $group_id);
  206. }
  207. }
  208. $result = GroupPortalManager::add_users_to_groups($UserList, array($group_id), $relation_type);
  209. Display :: display_confirmation_message(get_lang('UsersEdited'));
  210. }
  211. }
  212. $nosessionUsersList = $sessionUsersList = array();
  213. $ajax_search = $add_type == 'unique' ? true : false;
  214. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  215. if ($ajax_search) {
  216. // data for destination list
  217. if (isset($_POST['id']) && isset($_POST['relation'])) {
  218. // data for destination user list
  219. $id = intval($_POST['id']);
  220. $relation_type = intval($_POST['relation']);
  221. $condition_relation = " AND groups.relation_type = '$relation_type' ";
  222. $sql = "SELECT user.user_id, user.username, user.lastname, user.firstname
  223. FROM $tbl_group_rel_user groups
  224. INNER JOIN $tbl_user user ON user.user_id = groups.user_id
  225. WHERE groups.group_id = '$id' $condition_relation ";
  226. $rs_destination = Database::query($sql);
  227. if (Database::num_rows($rs_destination) > 0) {
  228. while ($row_destination_list = Database::fetch_array($rs_destination)) {
  229. $sessionUsersList[$row_destination_list['user_id']] = $row_destination_list ;
  230. }
  231. }
  232. }
  233. } else {
  234. $many_users = false;
  235. $sql = "SELECT count(user_id) FROM $tbl_user user
  236. WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND
  237. user_id<>'$user_anonymous' $without_user_id ";
  238. if (api_is_multiple_url_enabled()) {
  239. $access_url_id = api_get_current_access_url_id();
  240. if ($access_url_id != -1) {
  241. $sql = "SELECT count(user.user_id) FROM $tbl_user user
  242. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=user.user_id)
  243. WHERE
  244. access_url_id = '$access_url_id' AND
  245. ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND
  246. user.user_id<>'$user_anonymous' $without_user_id ";
  247. }
  248. }
  249. $rs_count = Database::query($sql);
  250. $row_count = 0;
  251. if (Database::num_rows($rs_count)) {
  252. $row_count = Database::fetch_row($rs_count);
  253. $row_count = $row_count[0];
  254. }
  255. if ($row_count > 2) {
  256. $many_users = true;
  257. }
  258. // data for origin list
  259. if (isset($_GET['id'])) {
  260. $id = intval($_GET['id']);
  261. $needle = isset($_POST['firstLetterUser']) ? Database::escape_string($_POST['firstLetterUser']) : null;
  262. $needle = api_convert_encoding($needle, $charset, 'utf-8');
  263. $user_anonymous = api_get_anonymous_id();
  264. // get user_id from relation type and group id
  265. $sql = "SELECT user_id FROM $tbl_group_rel_user
  266. WHERE group_id = $id
  267. AND relation_type IN (".GROUP_USER_PERMISSION_ADMIN.", ".GROUP_USER_PERMISSION_READER.",".GROUP_USER_PERMISSION_PENDING_INVITATION.",".GROUP_USER_PERMISSION_MODERATOR.", ".GROUP_USER_PERMISSION_HRM.") ";
  268. $res = Database::query($sql);
  269. $user_ids = array();
  270. if (Database::num_rows($res) > 0) {
  271. while ($row = Database::fetch_row($res)) {
  272. $user_ids[] = $row[0];
  273. }
  274. $without_user_id = " AND user.user_id NOT IN(".implode(',', $user_ids).") ";
  275. }
  276. $sql = "SELECT user_id, username, lastname, firstname FROM $tbl_user user
  277. WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND user_id<>'$user_anonymous' $without_user_id $order_clause ";
  278. if (api_is_multiple_url_enabled()) {
  279. $access_url_id = api_get_current_access_url_id();
  280. if ($access_url_id != -1) {
  281. $sql = "SELECT user.user_id, username, lastname, firstname FROM $tbl_user user
  282. INNER JOIN $tbl_user_rel_access_url url_user ON (url_user.user_id=user.user_id)
  283. WHERE access_url_id = '$access_url_id'
  284. AND ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%'
  285. AND user.user_id<>'$user_anonymous' $without_user_id $order_clause ";
  286. }
  287. }
  288. $rs_origin_list = Database::query($sql);
  289. while ($row_origin_list = Database::fetch_array($rs_origin_list)) {
  290. $nosessionUsersList[$row_origin_list['user_id']] = $row_origin_list;
  291. }
  292. }
  293. // data for destination list
  294. if (isset($_POST['id']) && isset($_POST['relation'])) {
  295. // data for destination user list
  296. $id = intval($_POST['id']);
  297. $relation_type = intval($_POST['relation']);
  298. $condition_relation = " AND groups.relation_type = '$relation_type' ";
  299. $sql = "SELECT user.user_id, user.username, user.lastname, user.firstname
  300. FROM $tbl_group_rel_user groups
  301. INNER JOIN $tbl_user user ON user.user_id = groups.user_id
  302. WHERE groups.group_id = '$id' $condition_relation ";
  303. $rs_destination = Database::query($sql);
  304. if (Database::num_rows($rs_destination) > 0) {
  305. while ($row_destination_list = Database::fetch_array($rs_destination)) {
  306. $sessionUsersList[$row_destination_list['user_id']] = $row_destination_list ;
  307. }
  308. }
  309. }
  310. }
  311. if ($add_type == 'multiple') {
  312. $link_add_type_unique = '<a href="'.api_get_self().'?id='.$group_id.'&add_type=unique">'.Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
  313. $link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple');
  314. } else {
  315. $link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique');
  316. $link_add_type_multiple = '<a href="'.api_get_self().'?id='.$group_id.'&add_type=multiple">'.Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
  317. }
  318. ?>
  319. <div class="actions">
  320. <?php echo $link_add_type_unique ?>&nbsp;|&nbsp;<?php echo $link_add_type_multiple ?>
  321. </div>
  322. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?id=<?php echo $group_id; ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
  323. <?php echo '<legend>'.$tool_name.' ('.$group_info['name'].')</legend>'; ?>
  324. <?php if ($add_type=='multiple') { ?>
  325. <select name="relation" id="relation" onchange="xajax_search_users(document.getElementById('firstLetterUser').value,'multiple',this.value)">
  326. <?php } else { ?>
  327. <select name="relation" id="relation" onchange="xajax_search_users(document.getElementById('user_to_add').value,'single',this.value);">
  328. <?php } ?>
  329. <option value=""><?php echo get_lang('SelectARelationType')?></option>
  330. <option value="<?php echo GROUP_USER_PERMISSION_ADMIN ?>" <?php echo ((isset($_POST['relation']) && $_POST['relation']==GROUP_USER_PERMISSION_ADMIN)?'selected=selected':'') ?> > <?php echo get_lang('Admin') ?></option>
  331. <option value="<?php echo GROUP_USER_PERMISSION_READER ?>" <?php echo ((isset($_POST['relation']) && $_POST['relation']==GROUP_USER_PERMISSION_READER)?'selected=selected':'') ?> > <?php echo get_lang('Reader') ?></option>
  332. <option value="<?php echo GROUP_USER_PERMISSION_PENDING_INVITATION ?>" <?php echo ((isset($_POST['relation']) && $_POST['relation']==GROUP_USER_PERMISSION_PENDING_INVITATION)?'selected=selected':'') ?> > <?php echo get_lang('PendingInvitation') ?></option>
  333. <option value="<?php echo GROUP_USER_PERMISSION_MODERATOR ?>" <?php echo ((isset($_POST['relation']) && $_POST['relation']==GROUP_USER_PERMISSION_MODERATOR)?'selected=selected':'') ?> > <?php echo get_lang('Moderator') ?></option>
  334. <option value="<?php echo GROUP_USER_PERMISSION_HRM ?>" <?php echo ((isset($_POST['relation']) && $_POST['relation']==GROUP_USER_PERMISSION_HRM)?'selected=selected':'') ?> > <?php echo get_lang('Drh') ?></option>
  335. </select>
  336. <input type="hidden" name="form_sent" value="1" />
  337. <input type="hidden" name="id" value="<?php echo $group_id ?>" />
  338. <input type="hidden" name="add_type" value="<?php echo $add_type ?>" />
  339. <?php
  340. if (!empty($errorMsg)) {
  341. Display::display_normal_message($errorMsg);
  342. }
  343. ?>
  344. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  345. <tr>
  346. <td align="center"><b><?php echo get_lang('UserListInPlatform') ?> :</b>
  347. </td>
  348. <td>&nbsp;</td>
  349. <td align="center"><b><?php echo get_lang('UsersInGroup') ?> :</b></td>
  350. </tr>
  351. <?php if ($add_type=='multiple') { ?>
  352. <tr>
  353. <td align="center">
  354. <?php echo get_lang('FirstLetterUser'); ?> :
  355. <div id="firstLetter">
  356. <select name="firstLetterUser" id="firstLetterUser" onchange = "xajax_search_users(this.value,'multiple',document.getElementById('relation').value)" >
  357. <option value = "%"><?php echo get_lang('All') ?></option>
  358. <?php
  359. $selected_letter = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null;
  360. echo Display :: get_alphabet_options($selected_letter);
  361. ?>
  362. </select>
  363. </div>
  364. </td>
  365. <td align="center">&nbsp;</td>
  366. </tr>
  367. <?php } ?>
  368. <tr>
  369. <td align="center">
  370. <div id="content_source">
  371. <?php
  372. if (!($add_type=='multiple')) {
  373. ?>
  374. <input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single',document.getElementById('relation').value)" />
  375. <div id="ajax_list_users_single"></div>
  376. <?php
  377. } else {
  378. ?>
  379. <div id="ajax_origin_list_multiple">
  380. <select id="origin_users" name="nosessionUsersList[]" multiple="multiple" size="15" style="width:360px;">
  381. <?php
  382. if (!empty($nosessionUsersList)) {
  383. foreach($nosessionUsersList as $enreg) {
  384. ?>
  385. <option value="<?php echo $enreg['user_id']; ?>" > <?php echo $enreg['firstname'].' '.$enreg['lastname'].' ('.$enreg['username'].')'; ?></option>
  386. <?php
  387. }
  388. }
  389. ?>
  390. </select>
  391. </div>
  392. <?php
  393. }
  394. unset($nosessionUsersList);
  395. ?>
  396. </div>
  397. </td>
  398. <td width="10%" valign="middle" align="center">
  399. <?php
  400. if ($ajax_search) {
  401. ?>
  402. <button class="btn btn-default" type="button" onclick="remove_item(document.getElementById('destination_users'))" ><i class="fa fa-arrow-left"></i></button>
  403. <?php
  404. } else {
  405. ?>
  406. <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'))"><i class="fa fa-arrow-right"></i></button>
  407. <br /><br />
  408. <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'))"><i class="fa fa-arrow-left"></i></button>
  409. <?php
  410. }
  411. ?>
  412. <br /><br /><br /><br /><br />
  413. </td>
  414. <td align="center">
  415. <div id="ajax_destination_list">
  416. <select id="destination_users" name="sessionUsersList[]" multiple="multiple" size="15" style="width:360px;">
  417. <?php
  418. if (!empty($sessionUsersList)) {
  419. foreach($sessionUsersList as $enreg) { ?>
  420. <option value="<?php echo $enreg['user_id']; ?>">
  421. <?php echo $enreg['firstname'].' '.$enreg['lastname'].' ('.$enreg['username'].')'; ?>
  422. </option>
  423. <?php }
  424. } unset($sessionUsersList);
  425. ?>
  426. </select>
  427. </div>
  428. </td>
  429. </tr>
  430. <tr>
  431. <td colspan="3" align="center">
  432. <br />
  433. <?php
  434. echo '<button class="btn btn-success" type="button" value="" onclick="valide()" ><i class="fa fa-floppy-o"></i> '.get_lang('SubscribeUsersToGroup').'</button>';
  435. ?>
  436. </td>
  437. </tr>
  438. </table>
  439. </form>
  440. <script>
  441. function moveItem(origin , destination) {
  442. for (var i = 0 ; i<origin.options.length ; i++) {
  443. if (origin.options[i].selected) {
  444. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  445. origin.options[i]=null;
  446. i = i-1;
  447. }
  448. }
  449. destination.selectedIndex = -1;
  450. sortOptions(destination.options);
  451. }
  452. function sortOptions(options) {
  453. newOptions = new Array();
  454. for (i = 0 ; i<options.length ; i++)
  455. newOptions[i] = options[i];
  456. newOptions = newOptions.sort(mysort);
  457. options.length = 0;
  458. for(i = 0 ; i < newOptions.length ; i++)
  459. options[i] = newOptions[i];
  460. }
  461. function mysort(a, b) {
  462. if (a.text.toLowerCase() > b.text.toLowerCase()){
  463. return 1;
  464. }
  465. if (a.text.toLowerCase() < b.text.toLowerCase()){
  466. return -1;
  467. }
  468. return 0;
  469. }
  470. function valide() {
  471. var relation_select = document.getElementById('relation');
  472. if (relation_select && relation_select.value=="") {
  473. alert("<?php echo get_lang('YouMustChooseARelationType')?>");
  474. return false;
  475. } else {
  476. var options = document.getElementById('destination_users').options;
  477. for (i = 0 ; i<options.length ; i++)
  478. options[i].selected = true;
  479. document.forms.formulaire.submit();
  480. }
  481. }
  482. function loadUsersInSelect(select) {
  483. var xhr_object = null;
  484. if (window.XMLHttpRequest) // Firefox
  485. xhr_object = new XMLHttpRequest();
  486. else if(window.ActiveXObject) // Internet Explorer
  487. xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  488. else // XMLHttpRequest non supporté par le navigateur
  489. alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  490. xhr_object.open("POST", "loadUsersInSelect.ajax.php");
  491. xhr_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  492. nosessionUsers = makepost(document.getElementById('origin_users'));
  493. sessionUsers = makepost(document.getElementById('destination_users'));
  494. nosessionClasses = makepost(document.getElementById('origin_classes'));
  495. sessionClasses = makepost(document.getElementById('destination_classes'));
  496. xhr_object.send("nosessionusers="+nosessionUsers+"&sessionusers="+sessionUsers+"&nosessionclasses="+nosessionClasses+"&sessionclasses="+sessionClasses);
  497. xhr_object.onreadystatechange = function() {
  498. if(xhr_object.readyState == 4) {
  499. document.getElementById('content_source').innerHTML = result = xhr_object.responseText;
  500. //alert(xhr_object.responseText);
  501. }
  502. }
  503. }
  504. function makepost(select) {
  505. var options = select.options;
  506. var ret = "";
  507. for (i = 0 ; i<options.length ; i++)
  508. ret = ret + options[i].value +'::'+options[i].text+";;";
  509. return ret;
  510. }
  511. </script>
  512. <?php
  513. Display::display_footer();