course_add.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. // $Id: course_add.php 13972 2007-12-06 10:32:41Z elixir_inter $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  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, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * @package dokeos.admin
  24. ==============================================================================
  25. */
  26. /*
  27. ==============================================================================
  28. INIT SECTION
  29. ==============================================================================
  30. */
  31. // name of the language file that needs to be included
  32. $language_file = array('admin','create_course');
  33. $cidReset = true;
  34. require_once ('../inc/global.inc.php');
  35. $this_section=SECTION_PLATFORM_ADMIN;
  36. api_protect_admin_script();
  37. require_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  38. require_once (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
  39. require_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
  40. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  41. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  42. $tool_name = get_lang('AddCourse');
  43. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  44. /*
  45. ==============================================================================
  46. MAIN CODE
  47. ==============================================================================
  48. */
  49. // Get all course categories
  50. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  51. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
  52. $res = api_sql_query($sql, __FILE__, __LINE__);
  53. while ($cat = mysql_fetch_array($res))
  54. {
  55. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  56. }
  57. // Get all possible teachers
  58. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  59. $sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status=1 ORDER BY lastname,firstname";
  60. $res = api_sql_query($sql,__FILE__,__LINE__);
  61. $teachers = array();
  62. while($obj = mysql_fetch_object($res))
  63. {
  64. $teachers[$obj->user_id] = $obj->lastname.' '.$obj->firstname;
  65. }
  66. // Build the form
  67. $form = new FormValidator('update_course');
  68. $form->add_textfield( 'visual_code', get_lang('CourseCode'),false,array('size'=>'20','maxlength'=>20));
  69. $form->applyFilter('visual_code','strtoupper');
  70. $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);
  71. $form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers);
  72. $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, 'multiple=multiple size=5');
  73. $form->add_textfield('title', get_lang('Title'),true, array ('size' => '60'));
  74. $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
  75. $form->add_textfield('department_name', get_lang('CourseDepartment'),false, array ('size' => '60'));
  76. $form->add_textfield('department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
  77. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  78. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  79. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  80. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  81. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  82. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  83. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  84. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  85. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  86. $form->add_textfield('disk_quota',get_lang('CourseQuota'));
  87. $form->addRule('disk_quota',get_lang('ThisFieldShouldBeNumeric'),'numeric');
  88. $form->add_progress_bar();
  89. $form->addElement('submit', null, get_lang('Ok'));
  90. // Set some default values
  91. $values['course_language'] = get_setting('platformLanguage');
  92. $values['disk_quota'] = get_setting('default_document_quotum');
  93. $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
  94. $values['subscribe'] = 1;
  95. $values['unsubscribe'] = 0;
  96. reset($teachers);
  97. $values['course_teachers'] = key($teachers);
  98. $form->setDefaults($values);
  99. // Validate form
  100. if( $form->validate())
  101. {
  102. $course = $form->exportValues();
  103. $code = $course['visual_code'];
  104. $tutor_name = $teachers[$course['tutor_id']];
  105. $teacher_id = $course['tutor_id'];
  106. $course_teachers = $course['course_teachers'];
  107. $test=false;
  108. //The course tutor has been selected in the teachers list so we must remove him to avoid double records in the database
  109. foreach($course_teachers as $key=>$value){
  110. if($value==$teacher_id){
  111. unset($course_teachers[$key]);
  112. break;
  113. }
  114. }
  115. $title = $course['title'];
  116. $category = $course['category_code'];
  117. $department_name = $course['department_name'];
  118. $department_url = $course['department_url'];
  119. $course_language = $course['course_language'];
  120. $disk_quota = $course['disk_quota'];
  121. if (!stristr($department_url, 'http://'))
  122. {
  123. $department_url = 'http://'.$department_url;
  124. }
  125. if(trim($code) == ''){
  126. $code = generate_course_code(substr($title,0,20));
  127. }
  128. $keys = define_course_keys($code, "", $_configuration['db_prefix']);
  129. if (sizeof($keys))
  130. {
  131. $currentCourseCode = $keys["currentCourseCode"];
  132. $currentCourseId = $keys["currentCourseId"];
  133. $currentCourseDbName = $keys["currentCourseDbName"];
  134. $currentCourseRepository = $keys["currentCourseRepository"];
  135. $expiration_date = time() + $firstExpirationDelay;
  136. prepare_course_repository($currentCourseRepository, $currentCourseId);
  137. update_Db_course($currentCourseDbName);
  138. $pictures_array=fill_course_repository($currentCourseRepository);
  139. fill_Db_course($currentCourseDbName, $currentCourseRepository, $course_language,$pictures_array);
  140. register_course($currentCourseId, $currentCourseCode, $currentCourseRepository, $currentCourseDbName, $tutor_name, $category, $title, $course_language, $teacher_id, $expiration_date,$course_teachers);
  141. $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."'";
  142. api_sql_query($sql,__FILE__,__LINE__);
  143. header('Location: course_list.php');
  144. exit ();
  145. }
  146. }
  147. Display::display_header($tool_name);
  148. // Display the form
  149. $form->display();
  150. /*
  151. ==============================================================================
  152. FOOTER
  153. ==============================================================================
  154. */
  155. Display :: display_footer();
  156. ?>