course_add.php 8.7 KB

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