course_add.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  54. $sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status=1 ORDER BY lastname,firstname";
  55. //filtering teachers when creating a course
  56. if ($_configuration['multiple_access_urls']==true){
  57. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  58. $sql = "SELECT u.user_id,lastname,firstname FROM $table_user as u
  59. INNER JOIN $access_url_rel_user_table url_rel_user
  60. 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 BY lastname,firstname ";
  61. }
  62. $res = api_sql_query($sql,__FILE__,__LINE__);
  63. $teachers = array();
  64. $teachers[0] = '-- '.get_lang('NoManager').' --';
  65. while($obj = mysql_fetch_object($res))
  66. {
  67. $teachers[$obj->user_id] = $obj->lastname.' '.$obj->firstname;
  68. }
  69. $dbnamelength = strlen($_configuration['db_prefix']);
  70. //Ensure the database prefix + database name do not get over 40 characters
  71. $maxlength = 40 - $dbnamelength;
  72. // Build the form
  73. $form = new FormValidator('update_course');
  74. $form->addElement('header', '', $tool_name);
  75. $form->add_textfield( 'visual_code', get_lang('CourseCode'),false,array('size'=>'20','maxlength'=>20));
  76. $form->applyFilter('visual_code','api_strtoupper');
  77. $form->applyFilter('visual_code','html_filter');
  78. $form->addRule('wanted_code',get_lang('Max'),'maxlength',$maxlength);
  79. $form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers);
  80. $form->applyFilter('tutor_id','html_filter');
  81. $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, 'multiple=multiple size=5');
  82. $form->applyFilter('course_teachers','html_filter');
  83. //Title
  84. $form->add_textfield('title', get_lang('Title'),true, array ('size' => '60'));
  85. $form->applyFilter('title','html_filter');
  86. $form->applyFilter('title','trim');
  87. $categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
  88. $form->applyFilter('category_code','html_filter');
  89. CourseManager::select_and_sort_categories($categories_select);
  90. //Course department
  91. $form->add_textfield('department_name', get_lang('CourseDepartment'),false, array ('size' => '60'));
  92. $form->applyFilter('department_name','html_filter');
  93. $form->applyFilter('department_name','trim');
  94. //Department URL
  95. $form->add_textfield('department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
  96. $form->applyFilter('department_url','html_filter');
  97. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  98. $form->applyFilter('select_language','html_filter');
  99. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  100. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  101. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  102. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  103. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  104. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  105. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  106. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  107. $form->add_textfield('disk_quota',get_lang('CourseQuota'));
  108. $form->addRule('disk_quota',get_lang('ThisFieldShouldBeNumeric'),'numeric');
  109. $form->add_progress_bar();
  110. $form->addElement('style_submit_button','submit', get_lang('CreateCourse'),'class="add"');
  111. // Set some default values
  112. $values['course_language'] = get_setting('platformLanguage');
  113. $values['disk_quota'] = get_setting('default_document_quotum');
  114. $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
  115. $values['subscribe'] = 1;
  116. $values['unsubscribe'] = 0;
  117. reset($teachers);
  118. $values['course_teachers'] = key($teachers);
  119. $form->setDefaults($values);
  120. // Validate form
  121. if( $form->validate()) {
  122. $course = $form->exportValues();
  123. $code = $course['visual_code'];
  124. $tutor_name = $teachers[$course['tutor_id']];
  125. $teacher_id = $course['tutor_id'];
  126. $course_teachers = $course['course_teachers'];
  127. $test=false;
  128. //The course tutor has been selected in the teachers list so we must remove him to avoid double records in the database
  129. foreach($course_teachers as $key=>$value){
  130. if($value==$teacher_id){
  131. unset($course_teachers[$key]);
  132. break;
  133. }
  134. }
  135. $title = $course['title'];
  136. $category = $course['category_code'];
  137. $department_name = $course['department_name'];
  138. $department_url = $course['department_url'];
  139. $course_language = $course['course_language'];
  140. $disk_quota = $course['disk_quota'];
  141. if (!stristr($department_url, 'http://'))
  142. {
  143. $department_url = 'http://'.$department_url;
  144. }
  145. if(trim($code) == ''){
  146. $code = generate_course_code(api_substr($title,0,$maxlength));
  147. }
  148. $keys = define_course_keys($code, "", $_configuration['db_prefix']);
  149. if (sizeof($keys))
  150. {
  151. $currentCourseCode = $keys["currentCourseCode"];
  152. $currentCourseId = $keys["currentCourseId"];
  153. $currentCourseDbName = $keys["currentCourseDbName"];
  154. $currentCourseRepository = $keys["currentCourseRepository"];
  155. $expiration_date = time() + $firstExpirationDelay;
  156. prepare_course_repository($currentCourseRepository, $currentCourseId);
  157. update_Db_course($currentCourseDbName);
  158. $pictures_array=fill_course_repository($currentCourseRepository);
  159. fill_Db_course($currentCourseDbName, $currentCourseRepository, $course_language,$pictures_array);
  160. register_course($currentCourseId, $currentCourseCode, $currentCourseRepository, $currentCourseDbName, $tutor_name, $category, $title, $course_language, $teacher_id, $expiration_date,$course_teachers);
  161. $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."'";
  162. api_sql_query($sql,__FILE__,__LINE__);
  163. header('Location: course_list.php');
  164. exit ();
  165. }
  166. }
  167. Display::display_header($tool_name);
  168. // Display the form
  169. $form->display();
  170. /*
  171. ==============================================================================
  172. FOOTER
  173. ==============================================================================
  174. */
  175. Display :: display_footer();
  176. ?>