subscribe_class2course.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. /**
  7. * Code
  8. */
  9. // name of the language file that needs to be included
  10. $language_file = 'admin';
  11. $cidReset = true;
  12. require_once '../inc/global.inc.php';
  13. $this_section=SECTION_PLATFORM_ADMIN;
  14. api_protect_admin_script();
  15. $classes = $_GET['classes'];
  16. $form_sent = 0;
  17. $error_message = '';
  18. $first_letter_class = '';
  19. $first_letter_course = '';
  20. $courses = array ();
  21. $classes = array();
  22. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  23. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  24. $tool_name = get_lang('AddClassesToACourse');
  25. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  26. Display :: display_header($tool_name);
  27. //api_display_tool_title($tool_name);
  28. if ($_POST['formSent'])
  29. {
  30. $form_sent = $_POST['formSent'];
  31. $classes = is_array($_POST['ClassList']) ? $_POST['ClassList'] : array();
  32. $courses = is_array($_POST['CourseList']) ? $_POST['CourseList'] : array();
  33. $first_letter_class = $_POST['firstLetterClass'];
  34. $first_letter_course = $_POST['firstLetterCourse'];
  35. if ($form_sent == 1)
  36. {
  37. if (count($classes) == 0 || count($courses) == 0)
  38. {
  39. Display::display_error_message(get_lang('AtLeastOneClassAndOneCourse'));
  40. }
  41. elseif (api_substr($_POST['formSubmit'], -2) == '>>') // add classes to courses
  42. {
  43. foreach ($courses as $course_code)
  44. {
  45. foreach ($classes as $class_id)
  46. {
  47. ClassManager :: subscribe_to_course($class_id, $course_code);
  48. }
  49. }
  50. Display::display_normal_message(get_lang('ClassesSubscribed'));
  51. }
  52. else // remove classes from courses
  53. {
  54. foreach ($courses as $course_code)
  55. {
  56. foreach ($classes as $class_id)
  57. {
  58. ClassManager :: unsubscribe_from_course($class_id, $course_code);
  59. }
  60. }
  61. Display::display_normal_message(get_lang('ClassesUnsubscribed'));
  62. }
  63. }
  64. }
  65. $sql = "SELECT id,name FROM $tbl_class WHERE name LIKE '".$first_letter_class."%' ORDER BY ". (count($classes) > 0 ? "(id IN('".implode("','", $classes)."')) DESC," : "")." name";
  66. $result = Database::query($sql);
  67. $db_classes = Database::store_result($result);
  68. $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";
  69. $result = Database::query($sql);
  70. $db_courses = Database::store_result($result);
  71. if (!empty ($error_message))
  72. {
  73. Display :: display_normal_message($error_message);
  74. }
  75. ?>
  76. <form name="formulaire" method="post" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  77. <input type="hidden" name="formSent" value="1"/>
  78. <table border="0" cellpadding="5" cellspacing="0" width="100%">
  79. <tr>
  80. <td width="40%" align="center">
  81. <b><?php echo get_lang('ClassList'); ?></b>
  82. <br/><br/>
  83. <?php echo get_lang('FirstLetterClass'); ?> :
  84. <select name="firstLetterClass" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  85. <option value="">--</option>
  86. <?php
  87. echo Display::get_alphabet_options($first_letter_class);
  88. ?>
  89. </select>
  90. </td>
  91. <td width="20%">&nbsp;</td>
  92. <td width="40%" align="center">
  93. <b><?php echo get_lang('CourseList'); ?> :</b>
  94. <br/><br/>
  95. <?php echo get_lang('FirstLetterCourse'); ?> :
  96. <select name="firstLetterCourse" onchange="javascript:document.formulaire.formSent.value='2'; document.formulaire.submit();">
  97. <option value="">--</option>
  98. <?php
  99. echo Display::get_alphabet_options($first_letter_course);
  100. ?>
  101. </select>
  102. </td>
  103. </tr>
  104. <tr>
  105. <td width="40%" align="center">
  106. <select name="ClassList[]" multiple="multiple" size="20" style="width:230px;">
  107. <?php
  108. foreach ($db_classes as $class)
  109. {
  110. ?>
  111. <option value="<?php echo $class['id']; ?>" <?php if(in_array($class['id'],$classes)) echo 'selected="selected"'; ?>><?php echo $class['name']; ?></option>
  112. <?php
  113. }
  114. ?>
  115. </select>
  116. </td>
  117. <td width="20%" valign="middle" align="center">
  118. <input type="submit" name="formSubmit" value="<?php echo get_lang('AddToThatCourse'); ?> &gt;&gt;"/>
  119. <br/>
  120. <input type="submit" name="formSubmit" value="&lt;&lt; <?php echo get_lang('DeleteSelectedClasses'); ?>"/>
  121. </td>
  122. <td width="40%" align="center">
  123. <select name="CourseList[]" multiple="multiple" size="20" style="width:230px;">
  124. <?php
  125. foreach ($db_courses as $course)
  126. {
  127. ?>
  128. <option value="<?php echo $course['code']; ?>" <?php if(in_array($course['code'],$courses)) echo 'selected="selected"'; ?>><?php echo '('.$course['visual_code'].') '.$course['title']; ?></option>
  129. <?php
  130. }
  131. ?>
  132. </select>
  133. </td>
  134. </tr>
  135. </table>
  136. </form>
  137. <?php
  138. /*
  139. ==============================================================================
  140. FOOTER
  141. ==============================================================================
  142. */
  143. Display :: display_footer();
  144. ?>