add_users_to_group.php 24 KB

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