add_many_session_to_category.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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']) ? $_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. }
  107. $sql = "SELECT id, name FROM $tbl_session $where ORDER BY name";
  108. $result = Database::query($sql);
  109. $rows_session = Database::store_result($result);
  110. ?>
  111. <form name="formulaire" method="post"
  112. action="<?php echo api_get_self(); ?>?page=<?php echo $page;
  113. if (!empty($_GET['add'])) {
  114. echo '&add=true';
  115. } ?>" style="margin:0px;">
  116. <?php echo '<legend>' . $tool_name . '</legend>'; ?>
  117. <input type="hidden" name="formSent" value="1"/>
  118. <?php
  119. if (!empty($errorMsg)) {
  120. Display::display_error_message($errorMsg); //main API
  121. }
  122. if (!empty($OkMsg)) {
  123. Display::display_confirmation_message($OkMsg); //main API
  124. }
  125. /*
  126. *
  127. * The a/b/c Filter is not a priority
  128. *
  129. * <td width="45%" align="center">
  130. <?php echo get_lang('FirstLetterCourse'); ?> :
  131. <select name="firstLetterCourse" onchange = "xajax_search_courses(this.value,'multiple')">
  132. <option value="%">--</option>
  133. <?php
  134. echo Display :: get_alphabet_options();
  135. echo Display :: get_numeric_options(0,9,'');
  136. ?>
  137. </select>
  138. </td>
  139. */
  140. ?>
  141. <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
  142. <tr>
  143. <td align="left"></td>
  144. <td align="left"></td>
  145. <td align="center">
  146. <b><?php echo get_lang('SessionCategoryName') ?> :</b><br/>
  147. <select name="CategorySessionId" style="width: 320px;" onchange="javascript:send();">
  148. <option value="0"></option>
  149. <?php
  150. if (!empty($rows_session_category)) {
  151. foreach ($rows_session_category as $category) {
  152. if ($category['id'] == $Categoryid) {
  153. echo '<option value="' . $category['id'] . '" selected>' . $category['name'] . '</option>';
  154. } else {
  155. echo '<option value="' . $category['id'] . '">' . $category['name'] . '</option>';
  156. }
  157. }
  158. }
  159. ?>
  160. </select>
  161. </td>
  162. </tr>
  163. <tr>
  164. <td width="45%" align="center"><b><?php echo get_lang('SessionListInPlatform') ?> :</b></td>
  165. <td width="10%">&nbsp;</td>
  166. <td align="center" width="45%"><b><?php echo get_lang('SessionListInCategory') ?> :</b></td>
  167. </tr>
  168. <?php if ($add_type == 'multiple') { ?>
  169. <tr>
  170. <td>&nbsp;</td>
  171. </tr>
  172. <?php } ?>
  173. <tr>
  174. <td width="45%" align="center">
  175. <div id="ajax_list_courses_multiple">
  176. <select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20"
  177. style="width:320px;">
  178. <?php
  179. foreach ($rows_session as $enreg) {
  180. ?>
  181. <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="' . htmlspecialchars(
  182. $enreg['name'],
  183. ENT_QUOTES
  184. ) . '"';
  185. if (in_array(
  186. $enreg['id'],
  187. $CourseList
  188. )
  189. ) {
  190. echo 'selected="selected"';
  191. } ?>><?php echo $enreg['name']; ?></option>
  192. <?php } ?>
  193. </select></div>
  194. <?php unset($nosessionCourses); ?>
  195. </td>
  196. <td width="10%" valign="middle" align="center">
  197. <button class="arrowr" type="button"
  198. onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"
  199. onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"></button>
  200. <br/><br/>
  201. <button class="arrowl" type="button"
  202. onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"
  203. onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"></button>
  204. <br/><br/><br/><br/><br/><br/>
  205. <?php
  206. echo '<button class="save" type="button" value="" onclick="valide()" >' . get_lang('SubscribeSessionsToCategory').'</button>';
  207. ?>
  208. </td>
  209. <td width="45%" align="center">
  210. <select id='destination' name="SessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
  211. <?php
  212. foreach ($rows_category_session as $enreg) {
  213. ?>
  214. <option value="<?php echo $enreg['id']; ?>" <?php echo 'title="' . htmlspecialchars(
  215. $enreg['name'],
  216. ENT_QUOTES
  217. ) . '"';
  218. if (in_array(
  219. $enreg['id'],
  220. $CourseList
  221. )
  222. ) {
  223. echo 'selected="selected"';
  224. } ?>><?php echo $enreg['name']; ?></option>
  225. <?php } ?>
  226. </select>
  227. </td>
  228. </tr>
  229. </table>
  230. </form>
  231. <script>
  232. function valide() {
  233. var options = document.getElementById('destination').options;
  234. for (i = 0; i < options.length; i++)
  235. options[i].selected = true;
  236. document.forms.formulaire.submit();
  237. }
  238. </script>