subscribe_class2course.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. // $Id: subscribe_class2course.php 20441 2009-05-10 07:39:15Z ivantcholakov $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) Olivier Brouckaert
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * @package dokeos.admin
  23. ==============================================================================
  24. */
  25. // name of the language file that needs to be included
  26. $language_file = 'admin';
  27. $cidReset = true;
  28. require ('../inc/global.inc.php');
  29. $this_section=SECTION_PLATFORM_ADMIN;
  30. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  31. require_once (api_get_path(LIBRARY_PATH).'classmanager.lib.php');
  32. api_protect_admin_script();
  33. $classes = $_GET['classes'];
  34. $form_sent = 0;
  35. $error_message = '';
  36. $first_letter_class = '';
  37. $first_letter_course = '';
  38. $courses = array ();
  39. $classes = array();
  40. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  41. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  42. $tool_name = get_lang('AddClassesToACourse');
  43. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  44. Display :: display_header($tool_name);
  45. //api_display_tool_title($tool_name);
  46. if ($_POST['formSent'])
  47. {
  48. $form_sent = $_POST['formSent'];
  49. $classes = is_array($_POST['ClassList']) ? $_POST['ClassList'] : array();
  50. $courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array();
  51. $first_letter_class = $_POST['firstLetterClass'];
  52. $first_letter_course = $_POST['firstLetterCourse'];
  53. if ($form_sent == 1)
  54. {
  55. if (count($classes) == 0 || count($courses) == 0)
  56. {
  57. Display::display_error_message(get_lang('AtLeastOneClassAndOneCourse'));
  58. }
  59. elseif (api_substr($_POST['formSubmit'], -2) == '>>') // add classes to courses
  60. {
  61. foreach ($courses as $course_code)
  62. {
  63. foreach ($classes as $class_id)
  64. {
  65. ClassManager :: subscribe_to_course($class_id, $course_code);
  66. }
  67. }
  68. Display::display_normal_message(get_lang('ClassesSubscribed'));
  69. }
  70. else // remove classes from courses
  71. {
  72. foreach ($courses as $course_code)
  73. {
  74. foreach ($classes as $class_id)
  75. {
  76. ClassManager :: unsubscribe_from_course($class_id, $course_code);
  77. }
  78. }
  79. Display::display_normal_message(get_lang('ClassesUnsubscribed'));
  80. }
  81. }
  82. }
  83. $sql = "SELECT id,name FROM $tbl_class WHERE name LIKE '".$first_letter_class."%' ORDER BY ". (count($classes) > 0 ? "(id IN('".implode("','", $classes)."')) DESC," : "")." name";
  84. $result = Database::query($sql);
  85. $db_classes = Database::store_result($result);
  86. $sql = "SELECT code,visual_code,title FROM $tbl_course WHERE visual_code LIKE '".$first_letter_course."%' ORDER BY ". (count($courses) > 0 ? "(code IN('".implode("','", $courses)."')) DESC," : "")." visual_code";
  87. $result = Database::query($sql);
  88. $db_courses = Database::store_result($result);
  89. if (!empty ($error_message))
  90. {
  91. Display :: display_normal_message($error_message);
  92. }
  93. ?>
  94. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  95. <input type="hidden" name="formSent" value="1"/>
  96. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  97. <tr>
  98. <td width="40%" align="center">
  99. <b><?php echo get_lang('ClassList'); ?></b>
  100. <br/><br/>
  101. <?php echo get_lang('FirstLetterClass'); ?> :
  102. <select name="firstLetterClass" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  103. <option value="">--</option>
  104. <?php
  105. echo Display::get_alphabet_options($first_letter_class);
  106. ?>
  107. </select>
  108. </td>
  109. <td width="20%">&nbsp;</td>
  110. <td width="40%" align="center">
  111. <b><?php echo get_lang('CourseList'); ?> :</b>
  112. <br/><br/>
  113. <?php echo get_lang('FirstLetterCourse'); ?> :
  114. <select name="firstLetterCourse" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  115. <option value="">--</option>
  116. <?php
  117. echo Display::get_alphabet_options($first_letter_course);
  118. ?>
  119. </select>
  120. </td>
  121. </tr>
  122. <tr>
  123. <td width="40%" align="center">
  124. <select name="ClassList[]" multiple="multiple" size="20" style="width:230px;">
  125. <?php
  126. foreach ($db_classes as $class)
  127. {
  128. ?>
  129. <option value="<?php echo $class['id']; ?>" <?php if(in_array($class['id'],$classes)) echo 'selected="selected"'; ?>><?php echo $class['name']; ?></option>
  130. <?php
  131. }
  132. ?>
  133. </select>
  134. </td>
  135. <td width="20%" valign="middle" align="center">
  136. <input type="submit" name="formSubmit" value="<?php echo get_lang('AddToThatCourse'); ?> &gt;&gt;"/>
  137. <br/>
  138. <input type="submit" name="formSubmit" value="&lt;&lt; <?php echo get_lang('DeleteSelectedClasses'); ?>"/>
  139. </td>
  140. <td width="40%" align="center">
  141. <select name="CourseList[]" multiple="multiple" size="20" style="width:230px;">
  142. <?php
  143. foreach ($db_courses as $course)
  144. {
  145. ?>
  146. <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
  147. <?php
  148. }
  149. ?>
  150. </select>
  151. </td>
  152. </tr>
  153. </table>
  154. </form>
  155. <?php
  156. /*
  157. ==============================================================================
  158. FOOTER
  159. ==============================================================================
  160. */
  161. Display :: display_footer();
  162. ?>