add_many_session_to_category.php 8.8 KB

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