add_many_session_to_category.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. if (api_get_multiple_access_url()) {
  124. $table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  125. $access_url_id = api_get_current_access_url_id();
  126. $sql = "SELECT s.id, s.name FROM $tbl_session s INNER JOIN $table_access_url_rel_session u ON s.id = u.session_id $where AND u.access_url_id = $access_url_id ORDER BY name";
  127. } else {
  128. $sql = "SELECT id, name FROM $tbl_session $where ORDER BY name";
  129. }
  130. $result=Database::query($sql);
  131. $rows_session = Database::store_result($result);
  132. ?>
  133. <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();"';}?>>
  134. <?php echo '<legend>'.$tool_name.'</legend>'; ?>
  135. <input type="hidden" name="formSent" value="1" />
  136. <?php
  137. if(!empty($errorMsg)) {
  138. Display::display_error_message($errorMsg); //main API
  139. }
  140. if(!empty($OkMsg)) {
  141. Display::display_confirmation_message($OkMsg); //main API
  142. }
  143. /*
  144. *
  145. * The a/b/c Filter is not a priority
  146. *
  147. * <td width="45%" align="center">
  148. <?php echo get_lang('FirstLetterCourse'); ?> :
  149. <select name="firstLetterCourse" onchange = "xajax_search_courses(this.value,'multiple')">
  150. <option value="%">--</option>
  151. <?php
  152. echo Display :: get_alphabet_options();
  153. echo Display :: get_numeric_options(0,9,'');
  154. ?>
  155. </select>
  156. </td>
  157. */
  158. ?>
  159. <table border="0" cellpadding="5" cellspacing="0" width="100%" align="center">
  160. <tr>
  161. <td align="left"></td>
  162. <td align="left"></td>
  163. <td align="center">
  164. <b><?php echo get_lang('SessionCategoryName') ?> :</b><br />
  165. <select name="CategorySessionId" style="width: 320px;" onchange="javascript:send();" >
  166. <option value="0" ></option>
  167. <?php
  168. if (!empty($rows_session_category)) {
  169. foreach($rows_session_category as $category) {
  170. if($category['id'] == $Categoryid)
  171. echo '<option value="'.$category['id'].'" selected>'.$category['name'].'</option>';
  172. else
  173. echo '<option value="'.$category['id'].'">'.$category['name'].'</option>';
  174. }
  175. }
  176. ?>
  177. </select>
  178. </td>
  179. </tr>
  180. <tr>
  181. <td width="45%" align="center"><b><?php echo get_lang('SessionListInPlatform') ?> :</b></td>
  182. <td width="10%">&nbsp;</td>
  183. <td align="center" width="45%"><b><?php echo get_lang('SessionListInCategory') ?> :</b></td>
  184. </tr>
  185. <?php if($add_type == 'multiple') { ?>
  186. <tr>
  187. <td>&nbsp;</td></tr>
  188. <?php } ?>
  189. <tr>
  190. <td width="45%" align="center">
  191. <div id="ajax_list_courses_multiple">
  192. <select id="origin" name="NoSessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
  193. <?php
  194. foreach($rows_session as $enreg) {
  195. ?>
  196. <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>
  197. <?php } ?>
  198. </select></div>
  199. <?php unset($nosessionCourses); ?>
  200. </td>
  201. <td width="10%" valign="middle" align="center">
  202. <?php
  203. if ($ajax_search) {
  204. ?>
  205. <button class="arrowl" type="button" onclick="remove_item(document.getElementById('destination'))"></button>
  206. <?php
  207. } else {
  208. ?>
  209. <button class="arrowr" type="button" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))" onclick="moveItem(document.getElementById('origin'), document.getElementById('destination'))"></button>
  210. <br /><br />
  211. <button class="arrowl" type="button" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))" onclick="moveItem(document.getElementById('destination'), document.getElementById('origin'))"></button>
  212. <?php
  213. }
  214. ?>
  215. <br /><br /><br /><br /><br /><br />
  216. <?php
  217. echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeSessionsToCategory').'</button>';
  218. ?>
  219. </td>
  220. <td width="45%" align="center">
  221. <select id='destination' name="SessionCategoryList[]" multiple="multiple" size="20" style="width:320px;">
  222. <?php
  223. foreach($rows_category_session as $enreg) { ?>
  224. <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>
  225. <?php } ?>
  226. </select></td>
  227. </tr>
  228. </table>
  229. </form>
  230. <script type="text/javascript">
  231. <!--
  232. function moveItem(origin , destination) {
  233. for(var i = 0 ; i<origin.options.length ; i++) {
  234. if(origin.options[i].selected) {
  235. destination.options[destination.length] = new Option(origin.options[i].text,origin.options[i].value);
  236. origin.options[i]=null;
  237. i = i-1;
  238. }
  239. }
  240. destination.selectedIndex = -1;
  241. sortOptions(destination.options);
  242. }
  243. function sortOptions(options) {
  244. newOptions = new Array();
  245. for (i = 0 ; i<options.length ; i++) {
  246. newOptions[i] = options[i];
  247. }
  248. newOptions = newOptions.sort(mysort);
  249. options.length = 0;
  250. for(i = 0 ; i < newOptions.length ; i++){
  251. options[i] = newOptions[i];
  252. }
  253. }
  254. function mysort(a, b){
  255. if(a.text.toLowerCase() > b.text.toLowerCase()){
  256. return 1;
  257. }
  258. if(a.text.toLowerCase() < b.text.toLowerCase()){
  259. return -1;
  260. }
  261. return 0;
  262. }
  263. function valide(){
  264. var options = document.getElementById('destination').options;
  265. for (i = 0 ; i<options.length ; i++)
  266. options[i].selected = true;
  267. document.forms.formulaire.submit();
  268. }
  269. -->
  270. </script>
  271. <?php
  272. /* FOOTER */
  273. Display::display_footer();