course_add.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. // $Id: course_add.php 9403 2006-10-10 10:21:34Z bmol $
  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. $langFile = array('admin','create_course');
  32. $cidReset = true;
  33. require_once ('../inc/global.inc.php');
  34. $this_section=SECTION_PLATFORM_ADMIN;
  35. api_protect_admin_script();
  36. require_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  37. require_once (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
  38. require_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
  39. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  40. $table_course = Database::get_main_table(MAIN_COURSE_TABLE);
  41. $tool_name = get_lang('AddCourse');
  42. //$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('PlatformAdmin'));
  43. /*
  44. ==============================================================================
  45. MAIN CODE
  46. ==============================================================================
  47. */
  48. // Get all course categories
  49. $table_course_category = Database :: get_main_table(MAIN_CATEGORY_TABLE);
  50. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
  51. $res = api_sql_query($sql, __FILE__, __LINE__);
  52. while ($cat = mysql_fetch_array($res))
  53. {
  54. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  55. }
  56. // Get all possible teachers
  57. $table_user = Database :: get_main_table(MAIN_USER_TABLE);
  58. $sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status=1 ORDER BY lastname,firstname";
  59. $res = api_sql_query($sql,__FILE__,__LINE__);
  60. $teachers = array();
  61. while($obj = mysql_fetch_object($res))
  62. {
  63. $teachers[$obj->user_id] = $obj->lastname.' '.$obj->firstname;
  64. }
  65. // Build the form
  66. $form = new FormValidator('update_course');
  67. $form->add_textfield( 'visual_code', get_lang('CourseCode'),true,array('size'=>'20','maxlength'=>20));
  68. $form->applyFilter('visual_code','strtoupper');
  69. $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);
  70. $form->addElement('select', 'tutor_id', get_lang('CourseTitular'), $teachers);
  71. $form->add_textfield('title', get_lang('Title'),true, array ('size' => '60'));
  72. $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
  73. $form->add_textfield('department_name', get_lang('CourseDepartment'),false, array ('size' => '60'));
  74. $form->add_textfield('department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
  75. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  76. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  77. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  78. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  79. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  80. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  81. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  82. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  83. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  84. $form->add_textfield('disk_quota',get_lang('CourseQuota'));
  85. $form->addRule('disk_quota',get_lang('ThisFieldShouldBeNumeric'),'numeric');
  86. $form->add_progress_bar();
  87. $form->addElement('submit', null, get_lang('Ok'));
  88. // Set some default values
  89. $values['course_language'] = get_setting('platformLanguage');
  90. $values['disk_quota'] = get_setting('default_document_quotum');
  91. $values['visibility'] = COURSE_VISIBILITY_OPEN_PLATFORM;
  92. $values['subscribe'] = 1;
  93. $values['unsubscribe'] = 0;
  94. $form->setDefaults($values);
  95. // Validate form
  96. if( $form->validate())
  97. {
  98. $course = $form->exportValues();
  99. $code = $course['visual_code'];
  100. $tutor_name = $teachers[$course['tutor_id']];
  101. $teacher_id = $course['tutor_id'];
  102. $title = $course['title'];
  103. $category = $course['category_code'];
  104. $department_name = $course['department_name'];
  105. $department_url = $course['department_url'];
  106. $course_language = $course['course_language'];
  107. $disk_quota = $course['disk_quota'];
  108. if (!stristr($department_url, 'http://'))
  109. {
  110. $department_url = 'http://'.$department_url;
  111. }
  112. $keys = define_course_keys($code, "", $dbNamePrefix);
  113. if (sizeof($keys))
  114. {
  115. $currentCourseCode = $keys["currentCourseCode"];
  116. $currentCourseId = $keys["currentCourseId"];
  117. $currentCourseDbName = $keys["currentCourseDbName"];
  118. $currentCourseRepository = $keys["currentCourseRepository"];
  119. $expiration_date = time() + $firstExpirationDelay;
  120. prepare_course_repository($currentCourseRepository, $currentCourseId);
  121. update_Db_course($currentCourseDbName);
  122. fill_course_repository($currentCourseRepository);
  123. fill_Db_course($currentCourseDbName, $currentCourseRepository, $course_language);
  124. register_course($currentCourseId, $currentCourseCode, $currentCourseRepository, $currentCourseDbName, $tutor_name, $category, $title, $course_language, $teacher_id, $expiration_date);
  125. $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."'";
  126. api_sql_query($sql,__FILE__,__LINE__);
  127. header('Location: course_list.php');
  128. exit ();
  129. }
  130. }
  131. Display::display_header($tool_name);
  132. //api_display_tool_title($tool_name);
  133. // Display the form
  134. $form->display();
  135. /*
  136. ==============================================================================
  137. FOOTER
  138. ==============================================================================
  139. */
  140. Display :: display_footer();
  141. ?>