course_edit.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. // $Id: course_edit.php 10204 2006-11-26 20:46:53Z pcool $
  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 = 'admin';
  33. $cidReset = true;
  34. include ('../inc/global.inc.php');
  35. $this_section=SECTION_PLATFORM_ADMIN;
  36. api_protect_admin_script();
  37. include (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  38. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  39. $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
  40. $course_code = isset($_GET['course_code']) ? $_GET['course_code'] : $_POST['code'];
  41. $noPHP_SELF = true;
  42. $tool_name = get_lang('ModifyCourseInfo');
  43. //$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('PlatformAdmin'));
  44. $interbreadcrumb[] = array ("url" => "course_list.php", "name" => get_lang('AdminCourses'));
  45. /*
  46. -----------------------------------------------------------
  47. Libraries
  48. -----------------------------------------------------------
  49. */
  50. /*
  51. ==============================================================================
  52. FUNCTIONS
  53. ==============================================================================
  54. */
  55. /*
  56. ==============================================================================
  57. MAIN CODE
  58. ==============================================================================
  59. */
  60. // Get all course categories
  61. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  62. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
  63. $res = api_sql_query($sql, __FILE__, __LINE__);
  64. while ($cat = mysql_fetch_array($res))
  65. {
  66. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  67. }
  68. // Build the form
  69. $form = new FormValidator('update_course');
  70. $form->addElement('hidden','code',$course_code);
  71. $form->add_textfield('visual_code', get_lang('CourseCode'));
  72. $form->applyFilter('visual_code','strtoupper');
  73. $form->add_textfield('tutor_name', get_lang('CourseTitular'));
  74. $form->add_textfield( 'title', get_lang('Title'),true, array ('size' => '60'));
  75. $form->addElement('select', 'category_code', get_lang('CourseFaculty'), $categories);
  76. $form->add_textfield( 'department_name', get_lang('CourseDepartment'), false,array ('size' => '60'));
  77. $form->add_textfield( 'department_url', get_lang('CourseDepartmentURL'),false, array ('size' => '60'));
  78. $form->addElement('select_language', 'course_language', get_lang('CourseLanguage'));
  79. $form->addElement('radio', 'visibility', get_lang("CourseAccess"), get_lang('OpenToTheWorld'), COURSE_VISIBILITY_OPEN_WORLD);
  80. $form->addElement('radio', 'visibility', null, get_lang('OpenToThePlatform'), COURSE_VISIBILITY_OPEN_PLATFORM);
  81. $form->addElement('radio', 'visibility', null, get_lang('Private'), COURSE_VISIBILITY_REGISTERED);
  82. $form->addElement('radio', 'visibility', null, get_lang('CourseVisibilityClosed'), COURSE_VISIBILITY_CLOSED);
  83. $form->addElement('radio', 'subscribe', get_lang('Subscription'), get_lang('Allowed'), 1);
  84. $form->addElement('radio', 'subscribe', null, get_lang('Denied'), 0);
  85. $form->addElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
  86. $form->addElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
  87. $form->addElement('text','disk_quota',get_lang('CourseQuota'));
  88. $form->addRule('disk_quota', get_lang('ThisFieldIsRequired'),'required');
  89. $form->addRule('disk_quota',get_lang('ThisFieldShouldBeNumeric'),'numeric');
  90. $form->addElement('submit', null, get_lang('Ok'));
  91. // Set some default values
  92. $sql = "SELECT * FROM $course_table WHERE code='".mysql_real_escape_string($course_code)."'";
  93. $result = api_sql_query($sql, __FILE__, __LINE__);
  94. if (mysql_num_rows($result) != 1)
  95. {
  96. header('Location: course_list.php');
  97. exit ();
  98. }
  99. $course = mysql_fetch_array($result,MYSQL_ASSOC);
  100. $course_db_name = $course['db_name'];
  101. $form->setDefaults($course);
  102. // Validate form
  103. if( $form->validate())
  104. {
  105. $course = $form->exportValues();
  106. $dbName = $_POST['dbName'];
  107. $course_code = $course['code'];
  108. $visual_code = $course['visual_code'];
  109. $tutor_name = $course['tutor_name'];
  110. $title = $course['title'];
  111. $category_code = $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. $visibility = $course['visibility'];
  117. $subscribe = $course['subscribe'];
  118. $unsubscribe = $course['unsubscribe'];
  119. if (!stristr($department_url, 'http://'))
  120. {
  121. $department_url = 'http://'.$department_url;
  122. }
  123. $sql = "UPDATE $course_table SET course_language='".mysql_real_escape_string($course_language)."',
  124. title='".mysql_real_escape_string($title)."',
  125. category_code='".mysql_real_escape_string($category_code)."',
  126. tutor_name='".mysql_real_escape_string($tutor_name)."',
  127. visual_code='".mysql_real_escape_string($visual_code)."',
  128. department_name='".mysql_real_escape_string($department_name)."',
  129. department_url='".mysql_real_escape_string($department_url)."',
  130. disk_quota='".mysql_real_escape_string($disk_quota)."',
  131. visibility = '".mysql_real_escape_string($visibility)."',
  132. subscribe = '".mysql_real_escape_string($subscribe)."',
  133. unsubscribe='".mysql_real_escape_string($unsubscribe)."'
  134. WHERE code='".mysql_real_escape_string($course_code)."'";
  135. api_sql_query($sql, __FILE__, __LINE__);
  136. $forum_config_table = Database::get_course_table(TOOL_FORUM_CONFIG_TABLE,$course_db_name);
  137. $sql = "UPDATE ".$forum_config_table." SET default_lang='".mysql_real_escape_string($course_language)."'";
  138. header('Location: course_list.php');
  139. exit ();
  140. }
  141. Display::display_header($tool_name);
  142. //api_display_tool_title($tool_name);
  143. // Display the form
  144. $form->display();
  145. /*
  146. ==============================================================================
  147. FOOTER
  148. ==============================================================================
  149. */
  150. Display :: display_footer();
  151. ?>