add_many_session_to_category.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. * @todo use formvalidator
  6. */
  7. ////require_once '../inc/global.inc.php';
  8. $xajax = new xajax();
  9. $xajax->registerFunction('search_courses');
  10. // setting the section (for the tabs)
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. // Access restrictions
  13. api_protect_admin_script(true);
  14. // setting breadcrumbs
  15. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  16. $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'session/session_list.php', 'name' => get_lang('SessionList'));
  17. // Database Table Definitions
  18. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  19. // setting the name of the tool
  20. $tool_name = get_lang('SubscribeSessionsToCategory');
  21. $id_session = isset($_GET['id_session']) ? intval($_GET['id_session']) : null;
  22. $add_type = 'multiple';
  23. if (isset($_GET['add_type']) && $_GET['add_type'] != '') {
  24. $add_type = Security::remove_XSS($_REQUEST['add_type']);
  25. }
  26. if (!api_is_platform_admin() && !api_is_session_admin()) {
  27. $sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id=' . $id_session;
  28. $rs = Database::query($sql);
  29. if (Database::result($rs, 0, 0) != $_user['user_id']) {
  30. api_not_allowed(true);
  31. }
  32. }
  33. $xajax->processRequests();
  34. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  35. $htmlHeadXtra[] = '<script>
  36. function add_course_to_session (code, content) {
  37. document.getElementById("course_to_add").value = "";
  38. document.getElementById("ajax_list_courses_single").innerHTML = "";
  39. destination = document.getElementById("destination");
  40. for (i=0;i<destination.length;i++) {
  41. if(destination.options[i].text == content) {
  42. return false;
  43. }
  44. }
  45. destination.options[destination.length] = new Option(content,code);
  46. destination.selectedIndex = -1;
  47. sortOptions(destination.options);
  48. }
  49. function send() {
  50. if (document.formulaire.CategorySessionId.value!=0) {
  51. document.formulaire.formSent.value=0;
  52. document.formulaire.submit();
  53. }
  54. }
  55. function remove_item(origin)
  56. {
  57. for(var i = 0 ; i<origin.options.length ; i++) {
  58. if(origin.options[i].selected) {
  59. origin.options[i]=null;
  60. i = i-1;
  61. }
  62. }
  63. }
  64. </script>';
  65. $formSent = 0;
  66. $errorMsg = $firstLetterCourse = $firstLetterSession = '';
  67. $CourseList = $SessionList = array();
  68. $courses = $sessions = array();
  69. $Categoryid = isset($_POST['CategorySessionId']) ? intval($_POST['CategorySessionId']) : null;
  70. if (isset($_POST['formSent']) && $_POST['formSent']) {
  71. $formSent = $_POST['formSent'];
  72. $SessionCategoryList = $_POST['SessionCategoryList'];
  73. if ($Categoryid != 0 && count($SessionCategoryList) > 0) {
  74. $session_id = join(',', $SessionCategoryList);
  75. $sql = "UPDATE $tbl_session SET session_category_id = $Categoryid WHERE id in ($session_id) ";
  76. Database::query($sql);
  77. header('Location: add_many_session_to_category.php?id_category=' . $Categoryid . '&msg=ok');
  78. exit;
  79. } else {
  80. header('Location: add_many_session_to_category.php?msg=error');
  81. exit;
  82. }
  83. }
  84. if (isset($_GET['id_category'])) {
  85. $Categoryid = intval($_GET['id_category']);
  86. }
  87. if (isset($_GET['msg']) && $_GET['msg'] == 'error') {
  88. $errorMsg = get_lang('MsgErrorSessionCategory');
  89. }
  90. if (isset($_GET['msg']) && $_GET['msg'] == 'ok') {
  91. $OkMsg = get_lang('SessionCategoryUpdate');
  92. }
  93. $page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
  94. Display::display_header($tool_name);
  95. $where = '';
  96. $rows_category_session = array();
  97. if ((isset($_POST['CategorySessionId']) && $_POST['formSent'] == 0) || isset($_GET['id_category'])) {
  98. $where = 'WHERE session_category_id !=' . $Categoryid;
  99. $sql = 'SELECT id, name FROM ' . $tbl_session . ' WHERE session_category_id =' . $Categoryid . ' ORDER BY name';
  100. $result = Database::query($sql);
  101. $rows_category_session = Database::store_result($result);
  102. }
  103. $rows_session_category = SessionManager::get_all_session_category();
  104. if (empty($rows_session_category)) {
  105. Display::display_warning_message(get_lang('YouNeedToAddASessionCategoryFirst'));
  106. Display::display_footer();
  107. exit;
  108. }
  109. if (api_get_multiple_access_url()) {
  110. $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  111. $access_url_id = api_get_current_access_url_id();
  112. $sql = "SELECT s.id, s.name FROM $tbl_session s INNER JOIN $table_access_url_rel_session u ON s.id = u.session_id $where AND u.access_url_id = $access_url_id ORDER BY name";
  113. } else {
  114. $sql = "SELECT id, name FROM $tbl_session $where ORDER BY name";
  115. }
  116. $result=Database::query($sql);
  117. $rows_session = Database::store_result($result);
  118. ?>
  119. <form name="formulaire" method="post"
  120. action="<?php echo api_get_self(); ?>?page=<?php echo $page;
  121. if (!empty($_GET['add'])) {
  122. echo '&add=true';
  123. } ?>" style="margin:0px;">
  124. <?php echo '<legend>' . $tool_name . '</legend>'; ?>
  125. <input type="hidden" name="formSent" value="1"/>
  126. <?php
  127. if (!empty($errorMsg)) {
  128. Display::display_error_message($errorMsg); //main API
  129. }
  130. if (!empty($OkMsg)) {
  131. Display::display_confirmation_message($OkMsg); //main API
  132. }
  133. /*
  134. *
  135. * The a/b/c Filter is not a priority
  136. *
  137. * <td width="45%" align="center">
  138. <?php echo get_lang('FirstLetterCourse'); ?> :
  139. <select name="firstLetterCourse" onchange = "xajax_search_courses(this.value,'multiple')">
  140. <option value="%">--</option>
  141. <?php
  142. echo Display :: get_alphabet_options();
  143. echo Display :: get_numeric_options(0,9,'');
  144. ?>
  145. </select>
  146. </td>
  147. */
  148. ?>
  149. <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
  150. <tr>
  151. <td align="left"></td>
  152. <td align="left"></td>
  153. <td align="center">
  154. <b><?php echo get_lang('SessionCategoryName') ?> :</b><br/>
  155. <select name="CategorySessionId" style="width: 320px;" onchange="javascript:send();">
  156. <option value="0"></option>
  157. <?php
  158. if (!empty($rows_session_category)) {
  159. foreach ($rows_session_category as $category) {
  160. if ($category['id'] == $Categoryid) {
  161. echo '<option value="' . $category['id'] . '" selected>' . $category['name'] . '</option>';
  162. } else {
  163. echo '<option value="' . $category['id'] . '">' . $category['name'] . '</option>';
  164. }
  165. }
  166. }
  167. ?>
  168. </select>
  169. </td>
  170. </tr>
  171. <tr>
  172. <td width="45%" align="center"><b><?php echo get_lang('SessionListInPlatform') ?> :</b></td>
  173. <td width="10%">&nbsp;</td>
  174. <td align="center" width="45%"><b><?php echo get_lang('SessionListInCategory') ?> :</b></td>
  175. </tr>
  176. <?php if ($add_type == 'multiple') { ?>
  177. <tr>
  178. <td>&nbsp;</td>
  179. </tr>
  180. <?php } ?>
  181. <tr>
  182. <td width="45%" align="center">
  183. <div id="ajax_list_courses_multiple">
  184. <select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20"
  185. style="width:320px;">
  186. <?php
  187. foreach ($rows_session as $enreg) {
  188. ?>
  189. <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="' . htmlspecialchars(
  190. $enreg['name'],
  191. ENT_QUOTES
  192. ) . '"';
  193. if (in_array(
  194. $enreg['id'],
  195. $CourseList
  196. )
  197. ) {
  198. echo 'selected="selected"';
  199. } ?>><?php echo $enreg['name']; ?></option>
  200. <?php } ?>
  201. </select></div>
  202. <?php unset($nosessionCourses); ?>
  203. </td>
  204. <td width="10%" valign="middle" align="center">
  205. <button class="arrowr" type="button"
  206. onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"
  207. onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"></button>
  208. <br/><br/>
  209. <button class="arrowl" type="button"
  210. onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"
  211. onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"></button>
  212. <br/><br/><br/><br/><br/><br/>
  213. <?php
  214. echo '<button class="save" type="button" value="" onclick="valide()" >' . get_lang('SubscribeSessionsToCategory').'</button>';
  215. ?>
  216. </td>
  217. <td width="45%" align="center">
  218. <select id='destination' name="SessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
  219. <?php
  220. foreach ($rows_category_session as $enreg) {
  221. ?>
  222. <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="' . htmlspecialchars(
  223. $enreg['name'],
  224. ENT_QUOTES
  225. ) . '"';
  226. if (in_array(
  227. $enreg['id'],
  228. $CourseList
  229. )
  230. ) {
  231. echo 'selected="selected"';
  232. } ?>><?php echo $enreg['name']; ?></option>
  233. <?php } ?>
  234. </select>
  235. </td>
  236. </tr>
  237. </table>
  238. </form>
  239. <script>
  240. function valide() {
  241. var options = document.getElementById('destination').options;
  242. for (i = 0; i < options.length; i++)
  243. options[i].selected = true;
  244. document.forms.formulaire.submit();
  245. }
  246. </script>