course_add.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. /* INITIALIZATION SECTION */
  7. // Language files that need to be included.
  8. $language_file = array('admin', 'create_course');
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. $tool_name = get_lang('AddCourse');
  14. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  15. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  16. /* MAIN CODE */
  17. global $_configuration;
  18. // Get all possible teachers.
  19. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  20. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  21. $sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status=1".$order_clause;
  22. // Filtering teachers when creating a course.
  23. if (api_is_multiple_url_enabled()) {
  24. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  25. $sql = "SELECT u.user_id,lastname,firstname FROM $table_user as u
  26. INNER JOIN $access_url_rel_user_table url_rel_user
  27. 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".$order_clause;
  28. }
  29. $res = Database::query($sql);
  30. $teachers = array();
  31. //$teachers[0] = '-- '.get_lang('NoManager').' --';
  32. while($obj = Database::fetch_object($res)) {
  33. $teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
  34. }
  35. // Build the form.
  36. $form = new FormValidator('update_course');
  37. $form->addElement('header', '', $tool_name);
  38. // Title
  39. $form->add_textfield('title', get_lang('Title'), true, array ('class' => 'span6'));
  40. $form->applyFilter('title', 'html_filter');
  41. $form->applyFilter('title', 'trim');
  42. // Code
  43. $form->add_textfield('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('class' => 'span3', 'maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE));
  44. $form->applyFilter('visual_code', 'api_strtoupper');
  45. $form->applyFilter('visual_code', 'html_filter');
  46. $form->addRule('visual_code', get_lang('Max'), 'maxlength', CourseManager::MAX_COURSE_LENGTH_CODE);
  47. //$form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers, array('style' => 'width:350px', 'class'=>'chzn-select', 'id'=>'tutor_id'));
  48. //$form->applyFilter('tutor_id', 'html_filter');
  49. $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, ' id="course_teachers" class="chzn-select" style="width:350px" multiple="multiple" ');
  50. $form->applyFilter('course_teachers', 'html_filter');
  51. $categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), array(), array('style' => 'width:350px', 'class'=>'chzn-select', 'id'=>'category_code'));
  52. $categories_select->addOption('-','');
  53. $form->applyFilter('category_code', 'html_filter');
  54. //This function fills the category_code select ...
  55. CourseManager::select_and_sort_categories($categories_select);
  56. // Course department
  57. $form->add_textfield('department_name', get_lang('CourseDepartment'), false, array ('size' => '60'));
  58. $form->applyFilter('department_name', 'html_filter');
  59. $form->applyFilter('department_name', 'trim');
  60. // Department URL
  61. $form->add_textfield('department_url', get_lang('CourseDepartmentURL'), false, array ('size' => '60'));
  62. $form->applyFilter('department_url', 'html_filter');
  63. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  64. $form->applyFilter('select_language', 'html_filter');
  65. $form->addElement('checkbox', 'exemplary_content', '', get_lang('FillWithExemplaryContent'));
  66. $group = array();
  67. $group[]= $form->createElement('radio', 'visibility', get_lang('CourseAccess'), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  68. $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  69. $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  70. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  71. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityHidden'), COURSE_VISIBILITY_HIDDEN);
  72. $form->addGroup($group,'', get_lang('CourseAccess'), '<br />');
  73. $group = array();
  74. $group[]= $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  75. $group[]= $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  76. $form->addGroup($group,'', get_lang('Subscription'), '<br />');
  77. $group = array();
  78. $group[]= $form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  79. $group[]= $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  80. $form->addGroup($group,'', get_lang('Unsubscription'), '<br />');
  81. $form->addElement('text','disk_quota',array(get_lang('CourseQuota'), null, get_lang('MB')));
  82. $form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
  83. $obj = new GradeModel();
  84. $obj->fill_grade_model_select_in_form($form);
  85. $form->add_progress_bar();
  86. $form->addElement('style_submit_button', 'submit', get_lang('CreateCourse'), 'class="add"');
  87. // Set some default values.
  88. $values['course_language'] = api_get_setting('platformLanguage');
  89. $values['disk_quota'] = round(api_get_setting('default_document_quotum')/1024/1024, 1);
  90. $default_course_visibility = api_get_setting('courses_default_creation_visibility');
  91. if (isset($default_course_visibility)) {
  92. $values['visibility'] = api_get_setting('courses_default_creation_visibility');
  93. } else {
  94. $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
  95. }
  96. $values['subscribe'] = 1;
  97. $values['unsubscribe'] = 0;
  98. reset($teachers);
  99. //$values['course_teachers'] = key($teachers);
  100. $form->setDefaults($values);
  101. // Validate the form
  102. if ($form->validate()) {
  103. $course = $form->exportValues();
  104. //$tutor_name = $teachers[$course['tutor_id']];
  105. $course['user_id'] = isset($course['tutor_id']) ? $course['tutor_id'] : null;
  106. $course['teachers'] = isset($course['course_teachers']) ? $course['course_teachers'] : null;
  107. $course['disk_quota'] = $course['disk_quota']*1024*1024;
  108. $course['exemplary_content'] = empty($course['exemplary_content']) ? false : true;
  109. //$course['tutor_name'] = $tutor_name;
  110. $course['wanted_code'] = $course['visual_code'];
  111. $course['gradebook_model_id'] = isset($course['gradebook_model_id']) ? $course['gradebook_model_id'] : null;
  112. $course_info = CourseManager::create_course($course);
  113. header('Location: course_list.php'.($course_info===false?'?action=show_msg&warn='.api_get_last_failure():''));
  114. exit;
  115. }
  116. // Display the form.
  117. $content = $form->return_form();
  118. $tpl = $app['template'];
  119. $app['title'] = $tool_name;
  120. $tpl->assign('content', $content);
  121. $tpl->display_one_col_template();