course_add.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  14. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  15. $tool_name = get_lang('AddCourse');
  16. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  17. $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
  18. /* MAIN CODE */
  19. global $_configuration;
  20. // Get all possible teachers.
  21. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  22. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  23. $sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status=1".$order_clause;
  24. // Filtering teachers when creating a course.
  25. if ($_configuration['multiple_access_urls']) {
  26. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  27. $sql = "SELECT u.user_id,lastname,firstname FROM $table_user as u
  28. INNER JOIN $access_url_rel_user_table url_rel_user
  29. 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;
  30. }
  31. $res = Database::query($sql);
  32. $teachers = array();
  33. //$teachers[0] = '-- '.get_lang('NoManager').' --';
  34. while($obj = Database::fetch_object($res)) {
  35. $teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
  36. }
  37. $dbnamelength = strlen($_configuration['db_prefix']);
  38. // Ensure the database prefix + database name do not get over 40 characters.
  39. $maxlength = 40 - $dbnamelength;
  40. // Build the form.
  41. $form = new FormValidator('update_course');
  42. $form->addElement('header', '', $tool_name);
  43. // Title
  44. $form->add_textfield('title', get_lang('Title'), true, array ('size' => '60'));
  45. $form->applyFilter('title', 'html_filter');
  46. $form->applyFilter('title', 'trim');
  47. // Code
  48. $form->add_textfield('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('size' => '20', 'maxlength' => 20));
  49. $form->applyFilter('visual_code', 'api_strtoupper');
  50. $form->applyFilter('visual_code', 'html_filter');
  51. $form->addRule('visual_code', get_lang('Max'), 'maxlength', $maxlength);
  52. //$form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers, array('style' => 'width:350px', 'class'=>'chzn-select', 'id'=>'tutor_id'));
  53. //$form->applyFilter('tutor_id', 'html_filter');
  54. $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, ' id="course_teachers" class="chzn-select" style="width:350px" multiple="multiple" ');
  55. $form->applyFilter('course_teachers', 'html_filter');
  56. $categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories, array('style' => 'width:350px', 'class'=>'chzn-select', 'id'=>'category_code'));
  57. $categories_select->addOption('-','');
  58. $form->applyFilter('category_code', 'html_filter');
  59. //This function fills the category_code select ...
  60. CourseManager::select_and_sort_categories($categories_select);
  61. // Course department
  62. $form->add_textfield('department_name', get_lang('CourseDepartment'), false, array ('size' => '60'));
  63. $form->applyFilter('department_name', 'html_filter');
  64. $form->applyFilter('department_name', 'trim');
  65. // Department URL
  66. $form->add_textfield('department_url', get_lang('CourseDepartmentURL'), false, array ('size' => '60'));
  67. $form->applyFilter('department_url', 'html_filter');
  68. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  69. $form->applyFilter('select_language', 'html_filter');
  70. $form->addElement('checkbox', 'exemplary_content', '', get_lang('FillWithExemplaryContent'));
  71. $group = array();
  72. $group[]= $form->createElement('radio', 'visibility', get_lang('CourseAccess'), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  73. $group[]= $form->createElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  74. $group[]= $form->createElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  75. $group[]= $form->createElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  76. $form->addGroup($group,'', get_lang('CourseAccess'), '<br />');
  77. $group = array();
  78. $group[]= $form->createElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  79. $group[]= $form->createElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  80. $form->addGroup($group,'', get_lang('Subscription'), '<br />');
  81. $group = array();
  82. $group[]= $form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  83. $group[]= $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  84. $form->addGroup($group,'', get_lang('Unsubscription'), '<br />');
  85. $form->addElement('text','disk_quota',array(get_lang('CourseQuota'), null, get_lang('MB')));
  86. $form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
  87. $form->add_progress_bar();
  88. $form->addElement('style_submit_button', 'submit', get_lang('CreateCourse'), 'class="add"');
  89. // Set some default values.
  90. $values['course_language'] = api_get_setting('platformLanguage');
  91. $values['disk_quota'] = round(api_get_setting('default_document_quotum')/1024/1024, 1);
  92. $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
  93. $values['subscribe'] = 1;
  94. $values['unsubscribe'] = 0;
  95. reset($teachers);
  96. //$values['course_teachers'] = key($teachers);
  97. $form->setDefaults($values);
  98. // Validate the form
  99. if ($form->validate()) {
  100. $course = $form->exportValues();
  101. $code = $course['visual_code'];
  102. //$tutor_name = $teachers[$course['tutor_id']];
  103. $teacher_id = $course['tutor_id'];
  104. $course_teachers = $course['course_teachers'];
  105. $course['disk_quota'] = $course['disk_quota']*1024*1024;
  106. $course['exemplary_content'] = empty($course['exemplary_content']) ? false : true;
  107. $course['teachers'] = $course_teachers;
  108. //$course['tutor_name'] = $tutor_name;
  109. $course['user_id'] = $teacher_id;
  110. $course['wanted_code'] = $course['visual_code'];
  111. $course_info = CourseManager::create_course($course);
  112. header('Location: course_list.php');
  113. exit;
  114. }
  115. // Display the form.
  116. $content = $form->return_form();
  117. $tpl = new Template($tool_name);
  118. $tpl->assign('actions', $actions);
  119. $tpl->assign('message', $message);
  120. $tpl->assign('content', $content);
  121. $tpl->display_one_col_template();