dashboard_add_sessions_to_user.php 9.0 KB

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