course_edit.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. /* Initialization section */
  7. // name of the language file that needs to be included
  8. $language_file = 'admin';
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  14. $course_code = isset($_GET['course_code']) ? $_GET['course_code'] : $_POST['code'];
  15. $noPHP_SELF = true;
  16. $tool_name = get_lang('ModifyCourseInfo');
  17. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  18. $interbreadcrumb[] = array ("url" => "course_list.php", "name" => get_lang('CourseList'));
  19. // Get all course categories
  20. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  21. //Get the course infos
  22. $course = api_get_course_info($course_code);
  23. if (empty($course)) {
  24. header('Location: course_list.php');
  25. exit;
  26. }
  27. // Get course teachers
  28. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  29. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  30. $sql = "SELECT user.user_id,lastname,firstname FROM $table_user as user,$table_course_user as course_user
  31. WHERE course_user.status='1' AND course_user.user_id=user.user_id AND course_user.c_id ='".$course['real_id']."'".$order_clause;
  32. $res = Database::query($sql);
  33. $course_teachers = array();
  34. while ($obj = Database::fetch_object($res)) {
  35. $course_teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
  36. }
  37. // Get all possible teachers without the course teachers
  38. if (api_is_multiple_url_enabled()) {
  39. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  40. $sql = "SELECT u.user_id,lastname,firstname FROM $table_user as u
  41. INNER JOIN $access_url_rel_user_table url_rel_user
  42. ON (u.user_id=url_rel_user.user_id) WHERE url_rel_user.access_url_id=".api_get_current_access_url_id()." AND status = 1 or status = 2 ".$order_clause;
  43. } else {
  44. $sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status = 1 or status = 2 ".$order_clause;
  45. }
  46. $res = Database::query($sql);
  47. $teachers = array();
  48. $platform_teachers[0] = '-- '.get_lang('NoManager').' --';
  49. while ($obj = Database::fetch_object($res)) {
  50. if (!array_key_exists($obj->user_id,$course_teachers)) {
  51. $teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
  52. }
  53. if (isset($course['tutor_name']) && isset($course_teachers[$obj->user_id]) && $course['tutor_name']== $course_teachers[$obj->user_id]) {
  54. $course['tutor_name']=$obj->user_id;
  55. }
  56. //We add in the array platform teachers
  57. $platform_teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
  58. }
  59. //Case where there is no teacher in the course
  60. if (count($course_teachers)==0) {
  61. $sql='SELECT tutor_name FROM '.$course_table.' WHERE code="'.$course_code.'"';
  62. $res = Database::query($sql);
  63. $tutor_name=Database::result($res,0,0);
  64. $course['tutor_name']=array_search($tutor_name,$platform_teachers);
  65. }
  66. // Build the form
  67. $form = new FormValidator('update_course');
  68. $form->addElement('hidden','code',$course_code);
  69. //title
  70. $form->add_textfield('title', get_lang('Title'), true, array ('class' => 'span6'));
  71. $form->applyFilter('title','html_filter');
  72. $form->applyFilter('title','trim');
  73. // Code
  74. $element = $form->addElement('text', 'real_code', array(get_lang('CourseCode'), get_lang('ThisValueCantBeChanged')));
  75. $element->freeze();
  76. // Id
  77. $element = $form->addElement('text', 'real_id', 'id');
  78. $element->freeze();
  79. // visual code
  80. $form->add_textfield('visual_code', array(get_lang('VisualCode'), get_lang('OnlyLettersAndNumbers'), get_lang('ThisValueIsUsedInTheCourseURL')), true, array('class' => 'span4'));
  81. $form->applyFilter('visual_code','strtoupper');
  82. $form->applyFilter('visual_code','html_filter');
  83. //$form->addElement('text', tutor_name', get_lang('CourseTitular'));
  84. //$form->addElement('select', 'tutor_name', get_lang('CourseTitular'), $platform_teachers, array('style'=>'width:350px','id'=>'tutor_name_id', 'class'=>'chzn-select'));
  85. //$form->applyFilter('tutor_name','html_filter');
  86. //$form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, 'multiple=multiple size="4" style="width: 150px;"');
  87. $group=array();
  88. $group[] = $form->createElement('select', 'platform_teachers', '', $teachers, ' id="platform_teachers" multiple=multiple size="4" style="width:300px;"');
  89. $group[] = $form->createElement('select', 'course_teachers', '', $course_teachers, ' id="course_teachers" multiple=multiple size="4" style="width:300px;"');
  90. $element_template = <<<EOT
  91. <div class="control-group">
  92. <label>
  93. <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->{label}
  94. </label>
  95. <div class="controls">
  96. <table cellpadding="0" cellspacing="0">
  97. <tr>
  98. <!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> <td>{element}</td>
  99. </tr>
  100. </table>
  101. </div>
  102. </div>
  103. EOT;
  104. $renderer = $form->defaultRenderer();
  105. $renderer -> setElementTemplate($element_template, 'group');
  106. $form -> addGroup($group,'group',get_lang('CourseTeachers'),'</td><td width="80" align="center">'.
  107. '<input class="arrowr" style="width:30px;height:30px;padding-right:12px" type="button" onclick="moveItem(document.getElementById(\'platform_teachers\'), document.getElementById(\'course_teachers\'))" ><br><br>' .
  108. '<input class="arrowl" style="width:30px;height:30px;padding-left:13px" type="button" onclick="moveItem(document.getElementById(\'course_teachers\'), document.getElementById(\'platform_teachers\'))" ></td><td>');
  109. $categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), array() , array('style'=>'width:350px','id'=>'category_code_id', 'class'=>'chzn-select'));
  110. $categories_select->addOption('-','');
  111. CourseManager::select_and_sort_categories($categories_select);
  112. $form->add_textfield( 'department_name', get_lang('CourseDepartment'), false,array ('size' => '60'));
  113. $form->applyFilter('department_name','html_filter');
  114. $form->applyFilter('department_name','trim');
  115. $form->add_textfield( 'department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
  116. $form->applyFilter('department_url','html_filter');
  117. $form->applyFilter('department_url','trim');
  118. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  119. $form->applyFilter('select_language','html_filter');
  120. $group = array();
  121. $group[]= $form->createElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  122. $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  123. $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  124. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  125. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
  126. $form->addGroup($group,'', get_lang('CourseAccess'), '<br />');
  127. $group = array();
  128. $group[]= $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  129. $group[]= $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  130. $form->addGroup($group,'', get_lang('Subscription'), '<br />');
  131. $group = array();
  132. $group[]= $form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  133. $group[]= $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  134. $form->addGroup($group,'', get_lang('Unsubscription'), '<br />');
  135. $form->addElement('text','disk_quota',array(get_lang('CourseQuota'), null, get_lang('MB')));
  136. $form->addRule('disk_quota', get_lang('ThisFieldIsRequired'),'required');
  137. $form->addRule('disk_quota',get_lang('ThisFieldShouldBeNumeric'),'numeric');
  138. //Extra fields
  139. $extra_field = new ExtraField('course');
  140. $extra = $extra_field->addElements($form, $course_code);
  141. $htmlHeadXtra[] ='
  142. <script>
  143. $(function() {
  144. '.$extra['jquery_ready_content'].'
  145. });
  146. </script>';
  147. $form->addElement('style_submit_button', 'button', get_lang('ModifyCourseInfo'),'onclick="valide()"; class="save"');
  148. // Set some default values
  149. //$course['disk_quota'] = round($course['disk_quota']/1024/1024, 1);
  150. $course['disk_quota'] = round(DocumentManager::get_course_quota($course_code) /1024/1024, 1);
  151. $course['title'] = api_html_entity_decode($course['title'], ENT_QUOTES, $charset);
  152. $course['real_code'] = $course['code'];
  153. $form->setDefaults($course);
  154. // Validate form
  155. if ($form->validate()) {
  156. $course = $form->getSubmitValues();
  157. $visual_code = CourseManager::generate_course_code($course['visual_code']);
  158. // make sure to rebase the disk quota (shown in MB but stored in bytes)
  159. $course['disk_quota'] = $course['disk_quota']*1024*1024;
  160. CourseManager::update($course);
  161. // Check if the visual code is already used by *another* course
  162. $visual_code_is_used = false;
  163. $warn = get_lang('TheFollowingCoursesAlreadyUseThisVisualCode').':';
  164. if (!empty($visual_code)) {
  165. $list = CourseManager::get_courses_info_from_visual_code($visual_code);
  166. foreach ($list as $course_temp) {
  167. if ($course_temp['code'] != $course_code) {
  168. $visual_code_is_used = true;
  169. $warn .= ' '.$course_temp['title'].' ('.$course_temp['code'].'),';
  170. }
  171. }
  172. $warn = substr($warn,0,-1);
  173. }
  174. if ($visual_code_is_used) {
  175. header('Location: course_list.php?action=show_msg&warn='.urlencode($warn));
  176. exit;
  177. } else {
  178. header('Location: course_list.php');
  179. exit;
  180. }
  181. }
  182. Display::display_header($tool_name);
  183. echo "<script>
  184. function valide() {
  185. var options = document.getElementById('course_teachers').options;
  186. for (i = 0 ; i<options.length ; i++) {
  187. options[i].selected = true;
  188. }
  189. document.update_course.submit();
  190. }
  191. </script>";
  192. //api_display_tool_title($tool_name);
  193. // Display the form
  194. $form->display();
  195. /* FOOTER */
  196. Display :: display_footer();