add_many_session_to_category.php 9.8 KB

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