course_add.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. // $Id: course_add.php 20441 2009-05-10 07:39:15Z ivantcholakov $
  3. /* For licensing terms, see /dokeos_license.txt */
  4. /**
  5. ==============================================================================
  6. * @package dokeos.admin
  7. ==============================================================================
  8. */
  9. /*
  10. ==============================================================================
  11. INIT SECTION
  12. ==============================================================================
  13. */
  14. // name of the language file that needs to be included
  15. $language_file = array('admin','create_course');
  16. $cidReset = true;
  17. require_once ('../inc/global.inc.php');
  18. $this_section=SECTION_PLATFORM_ADMIN;
  19. api_protect_admin_script();
  20. require_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  21. require_once (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
  22. require_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
  23. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  24. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  25. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  26. $tool_name = get_lang('AddCourse');
  27. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  28. /*
  29. ==============================================================================
  30. MAIN CODE
  31. ==============================================================================
  32. */
  33. global $_configuration;
  34. // Get all possible teachers
  35. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  36. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  37. $sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status=1".$order_clause;
  38. //filtering teachers when creating a course
  39. if ($_configuration['multiple_access_urls']==true){
  40. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  41. $sql = "SELECT u.user_id,lastname,firstname FROM $table_user as u
  42. INNER JOIN $access_url_rel_user_table url_rel_user
  43. 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;
  44. }
  45. $res = Database::query($sql,__FILE__,__LINE__);
  46. $teachers = array();
  47. $teachers[0] = '-- '.get_lang('NoManager').' --';
  48. while($obj = Database::fetch_object($res))
  49. {
  50. $teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
  51. }
  52. $dbnamelength = strlen($_configuration['db_prefix']);
  53. //Ensure the database prefix + database name do not get over 40 characters
  54. $maxlength = 40 - $dbnamelength;
  55. // Build the form
  56. $form = new FormValidator('update_course');
  57. $form->addElement('header', '', $tool_name);
  58. //Title
  59. $form->add_textfield('title', get_lang('Title'),true, array ('size' => '60'));
  60. $form->applyFilter('title','html_filter');
  61. $form->applyFilter('title','trim');
  62. // code
  63. $form->add_textfield( 'visual_code', get_lang('CourseCode'),false,array('size'=>'20','maxlength'=>20));
  64. $form->applyFilter('visual_code','api_strtoupper');
  65. $form->applyFilter('visual_code','html_filter');
  66. $form->addRule('visual_code',get_lang('Max'),'maxlength',$maxlength);
  67. $form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers);
  68. $form->applyFilter('tutor_id','html_filter');
  69. $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, 'multiple=multiple size=5');
  70. $form->applyFilter('course_teachers','html_filter');
  71. $categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
  72. $form->applyFilter('category_code','html_filter');
  73. CourseManager::select_and_sort_categories($categories_select);
  74. //Course department
  75. $form->add_textfield('department_name', get_lang('CourseDepartment'),false, array ('size' => '60'));
  76. $form->applyFilter('department_name','html_filter');
  77. $form->applyFilter('department_name','trim');
  78. //Department URL
  79. $form->add_textfield('department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
  80. $form->applyFilter('department_url','html_filter');
  81. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  82. $form->applyFilter('select_language','html_filter');
  83. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  84. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  85. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  86. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  87. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  88. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  89. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  90. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  91. $form->add_textfield('disk_quota',get_lang('CourseQuota'));
  92. $form->addRule('disk_quota',get_lang('ThisFieldShouldBeNumeric'),'numeric');
  93. $form->add_progress_bar();
  94. $form->addElement('style_submit_button','submit', get_lang('CreateCourse'),'class="add"');
  95. // Set some default values
  96. $values['course_language'] = api_get_setting('platformLanguage');
  97. $values['disk_quota'] = api_get_setting('default_document_quotum');
  98. $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
  99. $values['subscribe'] = 1;
  100. $values['unsubscribe'] = 0;
  101. reset($teachers);
  102. $values['course_teachers'] = key($teachers);
  103. $form->setDefaults($values);
  104. // Validate form
  105. if( $form->validate()) {
  106. $course = $form->exportValues();
  107. $code = $course['visual_code'];
  108. $tutor_name = $teachers[$course['tutor_id']];
  109. $teacher_id = $course['tutor_id'];
  110. $course_teachers = $course['course_teachers'];
  111. $test=false;
  112. //The course tutor has been selected in the teachers list so we must remove him to avoid double records in the database
  113. foreach($course_teachers as $key=>$value){
  114. if($value==$teacher_id){
  115. unset($course_teachers[$key]);
  116. break;
  117. }
  118. }
  119. $title = $course['title'];
  120. $category = $course['category_code'];
  121. $department_name = $course['department_name'];
  122. $department_url = $course['department_url'];
  123. $course_language = $course['course_language'];
  124. $disk_quota = $course['disk_quota'];
  125. if (!stristr($department_url, 'http://'))
  126. {
  127. $department_url = 'http://'.$department_url;
  128. }
  129. if(trim($code) == ''){
  130. $code = generate_course_code(api_substr($title,0,$maxlength));
  131. }
  132. $keys = define_course_keys($code, "", $_configuration['db_prefix']);
  133. if (sizeof($keys))
  134. {
  135. $currentCourseCode = $keys["currentCourseCode"];
  136. $currentCourseId = $keys["currentCourseId"];
  137. $currentCourseDbName = $keys["currentCourseDbName"];
  138. $currentCourseRepository = $keys["currentCourseRepository"];
  139. $expiration_date = time() + $firstExpirationDelay;
  140. prepare_course_repository($currentCourseRepository, $currentCourseId);
  141. update_Db_course($currentCourseDbName);
  142. $pictures_array=fill_course_repository($currentCourseRepository);
  143. fill_Db_course($currentCourseDbName, $currentCourseRepository, $course_language,$pictures_array);
  144. register_course($currentCourseId, $currentCourseCode, $currentCourseRepository, $currentCourseDbName, $tutor_name, $category, $title, $course_language, $teacher_id, $expiration_date,$course_teachers);
  145. $sql = "UPDATE $table_course SET disk_quota = '".$disk_quota."', visibility = '".Database::escape_string($course['visibility'])."', subscribe = '".Database::escape_string($course['subscribe'])."', unsubscribe='".Database::escape_string($course['unsubscribe'])."' WHERE code = '".$currentCourseId."'";
  146. Database::query($sql,__FILE__,__LINE__);
  147. header('Location: course_list.php');
  148. exit ();
  149. }
  150. }
  151. Display::display_header($tool_name);
  152. // Display the form
  153. $form->display();
  154. /*
  155. ==============================================================================
  156. FOOTER
  157. ==============================================================================
  158. */
  159. Display :: display_footer();
  160. ?>