add_many_session_to_category.php 9.8 KB

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