subscribe_class2course.php 4.9 KB

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