add_many_session_to_category.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. $Categoryid = intval($_POST['CategorySessionId']);
  83. if ($_POST['formSent']) {
  84. $formSent=$_POST['formSent'];
  85. $SessionCategoryList = $_POST['SessionCategoryList'];
  86. if($Categoryid != 0 && count($SessionCategoryList)>0 ){
  87. $session_id = join(',', $SessionCategoryList);
  88. $sql = "UPDATE $tbl_session SET session_category_id = $Categoryid WHERE id in ($session_id) ";
  89. Database::query($sql);
  90. //header('Location: session_list.php?id_category='.$Categoryid);
  91. header('Location: add_many_session_to_category.php?id_category='.$Categoryid.'&msg=ok');
  92. exit;
  93. } else {
  94. header('Location: add_many_session_to_category.php?msg=error');
  95. exit;
  96. }
  97. }
  98. if (isset($_GET['id_category'])) {
  99. $Categoryid = intval($_GET['id_category']);
  100. }
  101. if(isset($_GET['msg']) && $_GET['msg']=='error'){
  102. $errorMsg = get_lang('MsgErrorSessionCategory');
  103. }
  104. if(isset($_GET['msg']) && $_GET['msg']=='ok'){
  105. $OkMsg = get_lang('SessionCategoryUpdate');
  106. }
  107. // display the dokeos header
  108. Display::display_header($tool_name);
  109. $where ='';
  110. $rows_category_session = array();
  111. if((isset($_POST['CategorySessionId']) && $_POST['formSent'] == 0) || isset($_GET['id_category']) ) {
  112. $where = 'WHERE session_category_id !='.$Categoryid;
  113. $sql = 'SELECT id, name FROM '.$tbl_session .' WHERE session_category_id ='.$Categoryid.' ORDER BY name';
  114. $result=Database::query($sql);
  115. $rows_category_session = Database::store_result($result);
  116. }
  117. $rows_session_category = SessionManager::get_all_session_category();
  118. if (empty($rows_session_category)) {
  119. Display::display_warning_message(get_lang('YouNeedToAddASessionCategoryFirst'));
  120. Display::display_footer();
  121. exit;
  122. }
  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. <?php echo '<legend>'.$tool_name.'</legend>'; ?>
  129. <input type="hidden" name="formSent" value="1" />
  130. <?php
  131. if(!empty($errorMsg)) {
  132. Display::display_error_message($errorMsg); //main API
  133. }
  134. if(!empty($OkMsg)) {
  135. Display::display_confirmation_message($OkMsg); //main API
  136. }
  137. /*
  138. *
  139. * The a/b/c Filter is not a priority
  140. *
  141. * <td width="45%" align="center">
  142. <?php echo get_lang('FirstLetterCourse'); ?> :
  143. <select name="firstLetterCourse" onchange = "xajax_search_courses(this.value,'multiple')">
  144. <option value="%">--</option>
  145. <?php
  146. echo Display :: get_alphabet_options();
  147. echo Display :: get_numeric_options(0,9,'');
  148. ?>
  149. </select>
  150. </td>
  151. */
  152. ?>
  153. <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
  154. <tr>
  155. <td align="left"></td>
  156. <td align="left"></td>
  157. <td align="center">
  158. <b><?php echo get_lang('SessionCategoryName') ?> :</b><br />
  159. <select name="CategorySessionId" style="width: 320px;" onchange="javascript:send();" >
  160. <option value="0" ></option>
  161. <?php
  162. if (!empty($rows_session_category)) {
  163. foreach($rows_session_category as $category) {
  164. if($category['id'] == $Categoryid)
  165. echo '<option value="'.$category['id'].'" selected>'.$category['name'].'</option>';
  166. else
  167. echo '<option value="'.$category['id'].'">'.$category['name'].'</option>';
  168. }
  169. }
  170. ?>
  171. </select>
  172. </td>
  173. </tr>
  174. <tr>
  175. <td width="45%" align="center"><b><?php echo get_lang('SessionListInPlatform') ?> :</b></td>
  176. <td width="10%">&nbsp;</td>
  177. <td align="center" width="45%"><b><?php echo get_lang('SessionListInCategory') ?> :</b></td>
  178. </tr>
  179. <?php if($add_type == 'multiple') { ?>
  180. <tr>
  181. <td>&nbsp;</td></tr>
  182. <?php } ?>
  183. <tr>
  184. <td width="45%" align="center">
  185. <div id="ajax_list_courses_multiple">
  186. <select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
  187. <?php
  188. foreach($rows_session as $enreg) {
  189. ?>
  190. <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>
  191. <?php } ?>
  192. </select></div>
  193. <?php unset($nosessionCourses); ?>
  194. </td>
  195. <td width="10%" valign="middle" align="center">
  196. <?php
  197. if ($ajax_search) {
  198. ?>
  199. <button class="arrowl" type="button" onclick="remove_item(document.getElementById('destination'))"></button>
  200. <?php
  201. } else {
  202. ?>
  203. <button class="arrowr" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"></button>
  204. <br /><br />
  205. <button class="arrowl" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"></button>
  206. <?php
  207. }
  208. ?>
  209. <br /><br /><br /><br /><br /><br />
  210. <?php
  211. echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeSessionsToCategory').'</button>';
  212. ?>
  213. </td>
  214. <td width="45%" align="center">
  215. <select id='destination' name="SessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
  216. <?php
  217. foreach($rows_category_session as $enreg) { ?>
  218. <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>
  219. <?php } ?>
  220. </select></td>
  221. </tr>
  222. </table>
  223. </form>
  224. <script type="text/javascript">
  225. <!--
  226. function moveItem(origin , destination) {
  227. for(var i = 0 ; i<origin.options.length ; i++) {
  228. if(origin.options[i].selected) {
  229. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  230. origin.options[i]=null;
  231. i = i-1;
  232. }
  233. }
  234. destination.selectedIndex = -1;
  235. sortOptions(destination.options);
  236. }
  237. function sortOptions(options) {
  238. newOptions = new Array();
  239. for (i = 0 ; i<options.length ; i++) {
  240. newOptions[i] = options[i];
  241. }
  242. newOptions = newOptions.sort(mysort);
  243. options.length = 0;
  244. for(i = 0 ; i < newOptions.length ; i++){
  245. options[i] = newOptions[i];
  246. }
  247. }
  248. function mysort(a, b){
  249. if(a.text.toLowerCase() > b.text.toLowerCase()){
  250. return 1;
  251. }
  252. if(a.text.toLowerCase() < b.text.toLowerCase()){
  253. return -1;
  254. }
  255. return 0;
  256. }
  257. function valide(){
  258. var options = document.getElementById('destination').options;
  259. for (i = 0 ; i<options.length ; i++)
  260. options[i].selected = true;
  261. document.forms.formulaire.submit();
  262. }
  263. -->
  264. </script>
  265. <?php
  266. /* FOOTER */
  267. Display::display_footer();