dashboard_add_sessions_to_user.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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>
  84. function valide() {
  85. var options = document.getElementById("destination").options;
  86. for (i = 0 ; i<options.length ; i++) {
  87. options[i].selected = true;
  88. }
  89. document.forms.formulaire.submit();
  90. }
  91. function remove_item(origin) {
  92. for(var i = 0 ; i<origin.options.length ; i++) {
  93. if(origin.options[i].selected) {
  94. origin.options[i]=null;
  95. i = i-1;
  96. }
  97. }
  98. }
  99. -->
  100. </script>';
  101. $formSent=0;
  102. $errorMsg = $firstLetterSession = '';
  103. $UserList = array();
  104. $msg = '';
  105. if (intval($_POST['formSent']) == 1) {
  106. $sessions_list = $_POST['SessionsList'];
  107. $affected_rows = SessionManager::suscribe_sessions_to_hr_manager($user_id,$sessions_list);
  108. if ($affected_rows) {
  109. $msg = get_lang('AssignedSessionsHaveBeenUpdatedSuccessfully');
  110. }
  111. }
  112. // display header
  113. Display::display_header($tool_name);
  114. // actions
  115. echo '<div class="actions">';
  116. if ($user_info['status'] != SESSIONADMIN) {
  117. echo '<span style="float: right;margin:0px;padding:0px;">
  118. <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>
  119. <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>
  120. </span>';
  121. }
  122. echo '</div>';
  123. echo Display::page_header(sprintf(get_lang('AssignSessionsToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])));
  124. $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id);
  125. $assigned_sessions_id = array_keys($assigned_sessions_to_hrm);
  126. $without_assigned_sessions = '';
  127. if (count($assigned_sessions_id) > 0) {
  128. $without_assigned_sessions = " AND s.id NOT IN(".implode(',',$assigned_sessions_id).")";
  129. }
  130. $needle = '%';
  131. if (isset($_POST['firstLetterSession'])) {
  132. $needle = Database::escape_string($_POST['firstLetterSession']);
  133. $needle = "$needle%";
  134. }
  135. if ($_configuration['multiple_access_urls']) {
  136. $sql = " SELECT s.id, s.name FROM $tbl_session s LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id)
  137. WHERE s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()."
  138. ORDER BY s.name";
  139. } else {
  140. $sql = " SELECT s.id, s.name FROM $tbl_session s
  141. WHERE s.name LIKE '$needle%' $without_assigned_sessions
  142. ORDER BY s.name
  143. ";
  144. }
  145. $result = Database::query($sql);
  146. ?>
  147. <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();"';}?>>
  148. <input type="hidden" name="formSent" value="1" />
  149. <?php
  150. if(!empty($msg)) {
  151. Display::display_normal_message($msg); //main API
  152. }
  153. ?>
  154. <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
  155. <tr>
  156. <td align="left"></td>
  157. <td align="left"></td>
  158. <td width="" align="center"> &nbsp; </td>
  159. </tr>
  160. <tr>
  161. <td width="45%" align="center"><b><?php echo get_lang('SessionsListInPlatform') ?> :</b></td>
  162. <td width="10%">&nbsp;</td>
  163. <td align="center" width="45%"><b>
  164. <?php
  165. if (UserManager::is_admin($user_id)) {
  166. echo get_lang('AssignedSessionsListToPlatformAdministrator');
  167. } else if ($user_info['status'] == SESSIONADMIN) {
  168. echo get_lang('AssignedSessionsListToSessionsAdministrator');
  169. } else {
  170. echo get_lang('AssignedSessionsListToHumanResourcesManager');
  171. }
  172. ?>
  173. : </b></td>
  174. </tr>
  175. <?php if($add_type == 'multiple') { ?>
  176. <tr><td width="45%" align="center">
  177. <?php echo get_lang('FirstLetterSession');?> :
  178. <select name="firstLetterSession" onchange = "xajax_search_sessions(this.value, 'multiple')">
  179. <option value="%">--</option>
  180. <?php
  181. echo Display :: get_alphabet_options($_POST['firstLetterSession']);
  182. ?>
  183. </select>
  184. </td>
  185. <td>&nbsp;</td></tr>
  186. <?php } ?>
  187. <tr>
  188. <td width="45%" align="center">
  189. <div id="ajax_list_sessions_multiple">
  190. <select id="origin" name="NoAssignedSessionsList[]" multiple="multiple" size="20" style="width:340px;">
  191. <?php
  192. while ($enreg = Database::fetch_array($result)) {
  193. ?>
  194. <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'],ENT_QUOTES).'"';?>><?php echo $enreg['name']; ?></option>
  195. <?php } ?>
  196. </select></div>
  197. </td>
  198. <td width="10%" valign="middle" align="center">
  199. <?php
  200. if ($ajax_search) {
  201. ?>
  202. <button class="arrowl" type="button" onclick="remove_item(document.getElementById('destination'))"></button>
  203. <?php
  204. }
  205. else
  206. {
  207. ?>
  208. <button class="arrowr" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"></button>
  209. <br /><br />
  210. <button class="arrowl" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"></button>
  211. <?php
  212. }
  213. ?>
  214. <br /><br /><br /><br /><br /><br />
  215. <?php
  216. echo '<button class="save" type="button" value="" onclick="valide()" >'.$tool_name.'</button>';
  217. ?>
  218. </td>
  219. <td width="45%" align="center">
  220. <select id='destination' name="SessionsList[]" multiple="multiple" size="20" style="width:320px;">
  221. <?php
  222. if (is_array($assigned_sessions_to_hrm)) {
  223. foreach($assigned_sessions_to_hrm as $enreg) {
  224. ?>
  225. <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['name'],ENT_QUOTES).'"'; ?>><?php echo $enreg['name'] ?></option>
  226. <?php }
  227. }?>
  228. </select></td>
  229. </tr>
  230. </table>
  231. </form>
  232. <?php
  233. Display::display_footer();