dashboard_add_sessions_to_user.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Interface for assigning sessions 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_sessions');
  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_session = Database::get_main_table(TABLE_MAIN_SESSION);
  26. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  27. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  28. // initializing variables
  29. $id_session=intval($_GET['id_session']);
  30. $user_id = intval($_GET['user']);
  31. $user_info = api_get_user_info($user_id);
  32. $user_anonymous = api_get_anonymous_id();
  33. $current_user_id = api_get_user_id();
  34. // setting the name of the tool
  35. if (UserManager::is_admin($user_id)) {
  36. $tool_name= get_lang('AssignSessionsToPlatformAdministrator');
  37. } else if ($user_info['status'] == SESSIONADMIN) {
  38. $tool_name= get_lang('AssignSessionsToSessionsAdministrator');
  39. } else {
  40. $tool_name= get_lang('AssignSessionsToHumanResourcesManager');
  41. }
  42. $add_type = 'multiple';
  43. if(isset($_GET['add_type']) && $_GET['add_type']!=''){
  44. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  45. }
  46. if (!api_is_platform_admin() && !api_is_session_admin()) {
  47. api_not_allowed(true);
  48. }
  49. function search_sessions($needle,$type) {
  50. global $_configuration, $tbl_session_rel_access_url, $tbl_session, $user_id;
  51. $xajax_response = new XajaxResponse();
  52. $return = '';
  53. if(!empty($needle) && !empty($type)) {
  54. // xajax send utf8 datas... datas in db can be non-utf8 datas
  55. $charset = api_get_system_encoding();
  56. $needle = api_convert_encoding($needle, $charset, 'utf-8');
  57. $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id);
  58. $assigned_sessions_id = array_keys($assigned_sessions_to_hrm);
  59. $without_assigned_sessions = '';
  60. if (count($assigned_sessions_id) > 0) {
  61. $without_assigned_sessions = " AND s.id NOT IN(".implode(',',$assigned_sessions_id).")";
  62. }
  63. if ($_configuration['multiple_access_urls']) {
  64. $sql = " SELECT s.id, s.name FROM $tbl_session s LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
  65. WHERE s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()."";
  66. } else {
  67. $sql = "SELECT s.id, s.name FROM $tbl_session s
  68. WHERE s.name LIKE '$needle%' $without_assigned_sessions ";
  69. }
  70. $rs = Database::query($sql);
  71. $return .= '<select id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20" style="width:340px;">';
  72. while($session = Database :: fetch_array($rs)) {
  73. $return .= '<option value="'.$session['id'].'" title="'.htmlspecialchars($session['name'],ENT_QUOTES).'">'.$session['name'].'</option>';
  74. }
  75. $return .= '</select>';
  76. $xajax_response->addAssign('ajax_list_sessions_multiple','innerHTML',api_utf8_encode($return));
  77. }
  78. return $xajax_response;
  79. }
  80. $xajax->processRequests();
  81. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  82. $htmlHeadXtra[] = '
  83. <script type="text/javascript">
  84. <!--
  85. function moveItem(origin , destination) {
  86. for(var i = 0 ; i<origin.options.length ; i++) {
  87. if(origin.options[i].selected) {
  88. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  89. origin.options[i]=null;
  90. i = i-1;
  91. }
  92. }
  93. destination.selectedIndex = -1;
  94. sortOptions(destination.options);
  95. }
  96. function sortOptions(options) {
  97. var newOptions = new Array();
  98. for (i = 0 ; i<options.length ; i++) {
  99. newOptions[i] = options[i];
  100. }
  101. newOptions = newOptions.sort(mysort);
  102. options.length = 0;
  103. for(i = 0 ; i < newOptions.length ; i++){
  104. options[i] = newOptions[i];
  105. }
  106. }
  107. function mysort(a, b) {
  108. if (a.text.toLowerCase() > b.text.toLowerCase()) {
  109. return 1;
  110. }
  111. if (a.text.toLowerCase() < b.text.toLowerCase()) {
  112. return -1;
  113. }
  114. return 0;
  115. }
  116. function valide() {
  117. var options = document.getElementById("destination").options;
  118. for (i = 0 ; i<options.length ; i++) {
  119. options[i].selected = true;
  120. }
  121. document.forms.formulaire.submit();
  122. }
  123. function remove_item(origin) {
  124. for(var i = 0 ; i<origin.options.length ; i++) {
  125. if(origin.options[i].selected) {
  126. origin.options[i]=null;
  127. i = i-1;
  128. }
  129. }
  130. }
  131. -->
  132. </script>';
  133. $formSent=0;
  134. $errorMsg = $firstLetterSession = '';
  135. $UserList = array();
  136. $msg = '';
  137. if (intval($_POST['formSent']) == 1) {
  138. $sessions_list = $_POST['SessionsList'];
  139. $affected_rows = SessionManager::suscribe_sessions_to_hr_manager($user_id,$sessions_list);
  140. if ($affected_rows) {
  141. $msg = get_lang('AssignedSessionsHaveBeenUpdatedSuccessfully');
  142. }
  143. }
  144. // display header
  145. Display::display_header($tool_name);
  146. // actions
  147. echo '<div class="actions">';
  148. if ($user_info['status'] != SESSIONADMIN) {
  149. echo '<span style="float: right;margin:0px;padding:0px;">
  150. <a href="dashboard_add_users_to_user.php?user='.$user_id.'">'.Display::return_icon('add_user_big.gif', get_lang('AssignUsers'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignUsers').'</a>
  151. <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>
  152. </span>';
  153. }
  154. echo '</div>';
  155. echo Display::page_header(sprintf(get_lang('AssignSessionsToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])));
  156. $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id);
  157. $assigned_sessions_id = array_keys($assigned_sessions_to_hrm);
  158. $without_assigned_sessions = '';
  159. if (count($assigned_sessions_id) > 0) {
  160. $without_assigned_sessions = " AND s.id NOT IN(".implode(',',$assigned_sessions_id).")";
  161. }
  162. $needle = '%';
  163. if (isset($_POST['firstLetterSession'])) {
  164. $needle = Database::escape_string($_POST['firstLetterSession']);
  165. $needle = "$needle%";
  166. }
  167. if ($_configuration['multiple_access_urls']) {
  168. $sql = " SELECT s.id, s.name FROM $tbl_session s LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
  169. WHERE s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()."
  170. ORDER BY s.name";
  171. } else {
  172. $sql = " SELECT s.id, s.name FROM $tbl_session s
  173. WHERE s.name LIKE '$needle%' $without_assigned_sessions
  174. ORDER BY s.name
  175. ";
  176. }
  177. $result = Database::query($sql);
  178. ?>
  179. <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();"';}?>>
  180. <input type="hidden" name="formSent" value="1" />
  181. <?php
  182. if(!empty($msg)) {
  183. Display::display_normal_message($msg); //main API
  184. }
  185. ?>
  186. <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
  187. <tr>
  188. <td align="left"></td>
  189. <td align="left"></td>
  190. <td width="" align="center"> &nbsp; </td>
  191. </tr>
  192. <tr>
  193. <td width="45%" align="center"><b><?php echo get_lang('SessionsListInPlatform') ?> :</b></td>
  194. <td width="10%">&nbsp;</td>
  195. <td align="center" width="45%"><b>
  196. <?php
  197. if (UserManager::is_admin($user_id)) {
  198. echo get_lang('AssignedSessionsListToPlatformAdministrator');
  199. } else if ($user_info['status'] == SESSIONADMIN) {
  200. echo get_lang('AssignedSessionsListToSessionsAdministrator');
  201. } else {
  202. echo get_lang('AssignedSessionsListToHumanResourcesManager');
  203. }
  204. ?>
  205. : </b></td>
  206. </tr>
  207. <?php if($add_type == 'multiple') { ?>
  208. <tr><td width="45%" align="center">
  209. <?php echo get_lang('FirstLetterSession');?> :
  210. <select name="firstLetterSession" onchange = "xajax_search_sessions(this.value, 'multiple')">
  211. <option value="%">--</option>
  212. <?php
  213. echo Display :: get_alphabet_options($_POST['firstLetterSession']);
  214. ?>
  215. </select>
  216. </td>
  217. <td>&nbsp;</td></tr>
  218. <?php } ?>
  219. <tr>
  220. <td width="45%" align="center">
  221. <div id="ajax_list_sessions_multiple">
  222. <select id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20" style="width:340px;">
  223. <?php
  224. while ($enreg = Database::fetch_array($result)) {
  225. ?>
  226. <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'],ENT_QUOTES).'"';?>><?php echo $enreg['name']; ?></option>
  227. <?php } ?>
  228. </select></div>
  229. </td>
  230. <td width="10%" valign="middle" align="center">
  231. <?php
  232. if ($ajax_search) {
  233. ?>
  234. <button class="arrowl" type="button" onclick="remove_item(document.getElementById('destination'))"></button>
  235. <?php
  236. }
  237. else
  238. {
  239. ?>
  240. <button class="arrowr" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"></button>
  241. <br /><br />
  242. <button class="arrowl" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"></button>
  243. <?php
  244. }
  245. ?>
  246. <br /><br /><br /><br /><br /><br />
  247. <?php
  248. echo '<button class="save" type="button" value="" onclick="valide()" >'.$tool_name.'</button>';
  249. ?>
  250. </td>
  251. <td width="45%" align="center">
  252. <select id='destination' name="SessionsList[]" multiple="multiple" size="20" style="width:320px;">
  253. <?php
  254. if (is_array($assigned_sessions_to_hrm)) {
  255. foreach($assigned_sessions_to_hrm as $enreg) {
  256. ?>
  257. <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'],ENT_QUOTES).'"'; ?>><?php echo $enreg['name'] ?></option>
  258. <?php }
  259. }?>
  260. </select></td>
  261. </tr>
  262. </table>
  263. </form>
  264. <?php
  265. Display::display_footer();