course_edit.php 9.7 KB

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