course_add.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. // $Id: course_add.php 14291 2008-02-14 08:17:23Z 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).'course.lib.php');
  41. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  42. $table_course = Database::get_main_table(TABLE_MAIN_COURSE);
  43. $tool_name = get_lang('AddCourse');
  44. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  45. /*
  46. ==============================================================================
  47. MAIN CODE
  48. ==============================================================================
  49. */
  50. // Get all possible teachers
  51. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  52. $sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status=1 ORDER BY lastname,firstname";
  53. $res = api_sql_query($sql,__FILE__,__LINE__);
  54. $teachers = array();
  55. $teachers[0] = '-- '.get_lang('NoManager').' --';
  56. while($obj = mysql_fetch_object($res))
  57. {
  58. $teachers[$obj->user_id] = $obj->lastname.' '.$obj->firstname;
  59. }
  60. // Build the form
  61. $form = new FormValidator('update_course');
  62. $form->add_textfield( 'visual_code', get_lang('CourseCode'),false,array('size'=>'20','maxlength'=>20));
  63. $form->applyFilter('visual_code','strtoupper');
  64. $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);
  65. $form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers);
  66. $form->addElement('select', 'course_teachers', get_lang('CourseTeachers'), $teachers, 'multiple=multiple size=5');
  67. $form->add_textfield('title', get_lang('Title'),true, array ('size' => '60'));
  68. $categories_select = $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
  69. CourseManager::select_and_sort_categories($categories_select);
  70. $form->add_textfield('department_name', get_lang('CourseDepartment'),false, array ('size' => '60'));
  71. $form->add_textfield('department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
  72. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  73. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  74. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  75. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  76. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  77. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  78. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  79. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  80. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  81. $form->add_textfield('disk_quota',get_lang('CourseQuota'));
  82. $form->addRule('disk_quota',get_lang('ThisFieldShouldBeNumeric'),'numeric');
  83. $form->add_progress_bar();
  84. $form->addElement('submit', null, get_lang('Ok'));
  85. // Set some default values
  86. $values['course_language'] = get_setting('platformLanguage');
  87. $values['disk_quota'] = get_setting('default_document_quotum');
  88. $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
  89. $values['subscribe'] = 1;
  90. $values['unsubscribe'] = 0;
  91. reset($teachers);
  92. $values['course_teachers'] = key($teachers);
  93. $form->setDefaults($values);
  94. // Validate form
  95. if( $form->validate())
  96. {
  97. $course = $form->exportValues();
  98. $code = $course['visual_code'];
  99. $tutor_name = $teachers[$course['tutor_id']];
  100. $teacher_id = $course['tutor_id'];
  101. $course_teachers = $course['course_teachers'];
  102. $test=false;
  103. //The course tutor has been selected in the teachers list so we must remove him to avoid double records in the database
  104. foreach($course_teachers as $key=>$value){
  105. if($value==$teacher_id){
  106. unset($course_teachers[$key]);
  107. break;
  108. }
  109. }
  110. $title = $course['title'];
  111. $category = $course['category_code'];
  112. $department_name = $course['department_name'];
  113. $department_url = $course['department_url'];
  114. $course_language = $course['course_language'];
  115. $disk_quota = $course['disk_quota'];
  116. if (!stristr($department_url, 'http://'))
  117. {
  118. $department_url = 'http://'.$department_url;
  119. }
  120. if(trim($code) == ''){
  121. $code = generate_course_code(substr($title,0,20));
  122. }
  123. $keys = define_course_keys($code, "", $_configuration['db_prefix']);
  124. if (sizeof($keys))
  125. {
  126. $currentCourseCode = $keys["currentCourseCode"];
  127. $currentCourseId = $keys["currentCourseId"];
  128. $currentCourseDbName = $keys["currentCourseDbName"];
  129. $currentCourseRepository = $keys["currentCourseRepository"];
  130. $expiration_date = time() + $firstExpirationDelay;
  131. prepare_course_repository($currentCourseRepository, $currentCourseId);
  132. update_Db_course($currentCourseDbName);
  133. $pictures_array=fill_course_repository($currentCourseRepository);
  134. fill_Db_course($currentCourseDbName, $currentCourseRepository, $course_language,$pictures_array);
  135. register_course($currentCourseId, $currentCourseCode, $currentCourseRepository, $currentCourseDbName, $tutor_name, $category, $title, $course_language, $teacher_id, $expiration_date,$course_teachers);
  136. $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."'";
  137. api_sql_query($sql,__FILE__,__LINE__);
  138. header('Location: course_list.php');
  139. exit ();
  140. }
  141. }
  142. Display::display_header($tool_name);
  143. // Display the form
  144. $form->display();
  145. /*
  146. ==============================================================================
  147. FOOTER
  148. ==============================================================================
  149. */
  150. Display :: display_footer();
  151. ?>