dashboard_add_users_to_user.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Interface for assigning users to Human Resources Manager
  5. * @package chamilo.admin
  6. */
  7. // name of the language file that needs to be included
  8. $language_file='admin';
  9. // resetting the course id
  10. $cidReset=true;
  11. // including some necessary dokeos files
  12. require_once '../inc/global.inc.php';
  13. global $_configuration;
  14. // create an ajax object
  15. $xajax = new xajax();
  16. $xajax -> registerFunction ('search_users');
  17. // setting the section (for the tabs)
  18. $this_section = SECTION_PLATFORM_ADMIN;
  19. // Access restrictions
  20. api_protect_admin_script(true);
  21. // setting breadcrumbs
  22. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  23. $interbreadcrumb[] = array('url' => 'user_list.php','name' => get_lang('UserList'));
  24. // Database Table Definitions
  25. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  26. $tbl_access_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  27. // initializing variables
  28. $id_session=intval($_GET['id_session']);
  29. $user_id = intval($_GET['user']);
  30. $user_info = api_get_user_info($user_id);
  31. $user_anonymous = api_get_anonymous_id();
  32. $current_user_id = api_get_user_id();
  33. // setting the name of the tool
  34. if (UserManager::is_admin($user_id)) {
  35. $tool_name= get_lang('AssignUsersToPlatformAdministrator');
  36. } else if ($user_info['status'] == SESSIONADMIN) {
  37. $tool_name= get_lang('AssignUsersToSessionsAdministrator');
  38. } else {
  39. $tool_name= get_lang('AssignUsersToHumanResourcesManager');
  40. }
  41. $add_type = 'multiple';
  42. if(isset($_GET['add_type']) && $_GET['add_type']!=''){
  43. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  44. }
  45. if (!api_is_platform_admin()) {
  46. api_not_allowed(true);
  47. }
  48. function search_users($needle,$type) {
  49. global $_configuration,$tbl_access_url_rel_user, $tbl_user, $user_anonymous, $current_user_id, $user_id;
  50. $xajax_response = new XajaxResponse();
  51. $return = '';
  52. if(!empty($needle) && !empty($type)) {
  53. // xajax send utf8 datas... datas in db can be non-utf8 datas
  54. $charset = api_get_system_encoding();
  55. $needle = api_convert_encoding($needle, $charset, 'utf-8');
  56. $assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id);
  57. $assigned_users_id = array_keys($assigned_users_to_hrm);
  58. $without_assigned_users = '';
  59. if (count($assigned_users_id) > 0) {
  60. $without_assigned_users = " AND user.user_id NOT IN(".implode(',',$assigned_users_id).")";
  61. }
  62. if ($_configuration['multiple_access_urls']) {
  63. $sql = "SELECT user.user_id, username, lastname, firstname FROM $tbl_user user LEFT JOIN $tbl_access_url_rel_user au ON (au.user_id = user.user_id)
  64. WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND status NOT IN(".DRH.", ".SESSIONADMIN.") AND user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id) $without_assigned_users AND access_url_id = ".api_get_current_access_url_id()."";
  65. } else {
  66. $sql = "SELECT user_id, username, lastname, firstname FROM $tbl_user user
  67. WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND status NOT IN(".DRH.", ".SESSIONADMIN.") AND user_id NOT IN ($user_anonymous, $current_user_id, $user_id) $without_assigned_users";
  68. }
  69. $rs = Database::query($sql);
  70. $return .= '<select id="origin" name="NoAssignedUsersList[]" multiple="multiple" size="20" style="width:340px;">';
  71. while($user = Database :: fetch_array($rs)) {
  72. $person_name = api_get_person_name($user['firstname'], $user['lastname']);
  73. $return .= '<option value="'.$user['user_id'].'" title="'.htmlspecialchars($person_name,ENT_QUOTES).'">'.$person_name.' ('.$user['username'].')</option>';
  74. }
  75. $return .= '</select>';
  76. $xajax_response -> addAssign('ajax_list_users_multiple','innerHTML',api_utf8_encode($return));
  77. }
  78. return $xajax_response;
  79. }
  80. $xajax -> processRequests();
  81. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  82. $htmlHeadXtra[] = '<script>
  83. function valide() {
  84. var options = document.getElementById("destination").options;
  85. for (i = 0 ; i<options.length ; i++) {
  86. options[i].selected = true;
  87. }
  88. document.forms.formulaire.submit();
  89. }
  90. function remove_item(origin) {
  91. for(var i = 0 ; i<origin.options.length ; i++) {
  92. if(origin.options[i].selected) {
  93. origin.options[i]=null;
  94. i = i-1;
  95. }
  96. }
  97. }
  98. </script>';
  99. $formSent=0;
  100. $errorMsg = $firstLetterUser = '';
  101. $UserList = array();
  102. $msg = '';
  103. if (intval($_POST['formSent']) == 1) {
  104. $user_list = $_POST['UsersList'];
  105. $affected_rows = UserManager::suscribe_users_to_hr_manager($user_id,$user_list);
  106. if ($affected_rows) {
  107. $msg = get_lang('AssignedUsersHaveBeenUpdatedSuccessfully');
  108. }
  109. }
  110. // display header
  111. Display::display_header($tool_name);
  112. // actions
  113. echo '<div class="actions">
  114. <span style="float: right;margin:0px;padding:0px;">
  115. <a href="dashboard_add_courses_to_user.php?user='.$user_id.'">'.Display::return_icon('course_add.gif', get_lang('AssignCourses'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignCourses').'</a>
  116. <a href="dashboard_add_sessions_to_user.php?user='.$user_id.'">'.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignSessions').'</a></span>
  117. </div>';
  118. echo Display::page_header(sprintf(get_lang('AssignUsersToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])));
  119. $assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id);
  120. $assigned_users_id = array_keys($assigned_users_to_hrm);
  121. $without_assigned_users = '';
  122. if (count($assigned_users_id) > 0) {
  123. $without_assigned_users = " user.user_id NOT IN(".implode(',',$assigned_users_id).") AND ";
  124. }
  125. $search_user = '';
  126. if (isset($_POST['firstLetterUser'])) {
  127. $needle = Database::escape_string($_POST['firstLetterUser']);
  128. $search_user ="AND ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%'";
  129. }
  130. if ($_configuration['multiple_access_urls']) {
  131. $sql = "SELECT user.user_id, username, lastname, firstname FROM $tbl_user user LEFT JOIN $tbl_access_url_rel_user au ON (au.user_id = user.user_id)
  132. WHERE $without_assigned_users user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND status NOT IN(".DRH.", ".SESSIONADMIN.") $search_user AND access_url_id = ".api_get_current_access_url_id()."
  133. ORDER BY firstname";
  134. } else {
  135. $sql = "SELECT user_id, username, lastname, firstname FROM $tbl_user user
  136. WHERE $without_assigned_users user_id NOT IN ($user_anonymous, $current_user_id, $user_id) AND status NOT IN(".DRH.", ".SESSIONADMIN.") $search_user
  137. ORDER BY firstname ";
  138. }
  139. $result = Database::query($sql);
  140. ?>
  141. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>?user=<?php echo $user_id ?>" style="margin:0px;" <?php if($ajax_search){echo ' onsubmit="valide();"';}?>>
  142. <input type="hidden" name="formSent" value="1" />
  143. <?php
  144. if(!empty($msg)) {
  145. Display::display_normal_message($msg); //main API
  146. }
  147. ?>
  148. <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
  149. <tr>
  150. <td align="left"></td>
  151. <td align="left"></td>
  152. <td width="" align="center"> &nbsp; </td>
  153. </tr>
  154. <tr>
  155. <td width="45%" align="center"><b><?php echo get_lang('UserListInPlatform') ?> :</b></td>
  156. <td width="10%">&nbsp;</td>
  157. <td align="center" width="45%"><b>
  158. <?php
  159. if (UserManager::is_admin($user_id)) {
  160. echo get_lang('AssignedUsersListToPlatformAdministrator');
  161. } else if ($user_info['status'] == SESSIONADMIN) {
  162. echo get_lang('AssignedUsersListToSessionsAdministrator');
  163. } else {
  164. echo get_lang('AssignedUsersListToHumanResourcesManager');
  165. }
  166. ?>
  167. :</b></td>
  168. </tr>
  169. <?php if($add_type == 'multiple') { ?>
  170. <tr><td width="45%" align="center">
  171. <?php echo get_lang('FirstLetterUser');?> :
  172. <select name="firstLetterUser" onchange = "xajax_search_users(this.value,'multiple')">
  173. <option value="%">--</option>
  174. <?php
  175. echo Display :: get_alphabet_options($_POST['firstLetterUser']);
  176. ?>
  177. </select>
  178. </td>
  179. <td>&nbsp;</td></tr>
  180. <?php } ?>
  181. <tr>
  182. <td width="45%" align="center">
  183. <div id="ajax_list_users_multiple">
  184. <select id="origin" name="NoAssignedUsersList[]" multiple="multiple" size="20" style="width:340px;">
  185. <?php
  186. while ($enreg = Database::fetch_array($result)) {
  187. $person_name = api_get_person_name($enreg['firstname'], $enreg['lastname']);
  188. ?>
  189. <option value="<?php echo $enreg['user_id']; ?>" <?php echo 'title="'.htmlspecialchars($person_name,ENT_QUOTES).'"';?>><?php echo $person_name.' ('.$enreg['username'].')'; ?></option>
  190. <?php } ?>
  191. </select></div>
  192. </td>
  193. <td width="10%" valign="middle" align="center">
  194. <?php
  195. if ($ajax_search) {
  196. ?>
  197. <button class="arrowl" type="button" onclick="remove_item(document.getElementById('destination'))"></button>
  198. <?php
  199. }
  200. else
  201. {
  202. ?>
  203. <button class="arrowr" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"></button>
  204. <br /><br />
  205. <button class="arrowl" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"></button>
  206. <?php
  207. }
  208. ?>
  209. <br /><br /><br /><br /><br /><br />
  210. <?php
  211. echo '<button class="save" type="button" value="" onclick="valide()" >'.$tool_name.'</button>';
  212. ?>
  213. </td>
  214. <td width="45%" align="center">
  215. <select id='destination' name="UsersList[]" multiple="multiple" size="20" style="width:320px;">
  216. <?php
  217. if (is_array($assigned_users_to_hrm)) {
  218. foreach($assigned_users_to_hrm as $enreg) {
  219. $person_name = api_get_person_name($enreg['firstname'], $enreg['lastname']);
  220. ?>
  221. <option value="<?php echo $enreg['user_id']; ?>" <?php echo 'title="'.htmlspecialchars($person_name,ENT_QUOTES).'"'; ?>><?php echo $person_name.' ('.$enreg['username'].')'; ?></option>
  222. <?php }
  223. }?>
  224. </select></td>
  225. </tr>
  226. </table>
  227. </form>
  228. <?php
  229. Display::display_footer();