add_many_session_to_category.php 8.3 KB

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