add_course.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. // $Id: add_course.php 9527 2006-10-17 09:38:49Z elixir_inter $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004-2005 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) 2005 Bart Mollet, Hogeschool Gent
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * This script allows professors and administrative staff to create course sites.
  24. * @author X X main author
  25. * @author Roan Embrechts, refactoring
  26. * @package dokeos.create_course
  27. ==============================================================================
  28. */
  29. /*
  30. ==============================================================================
  31. INIT SECTION
  32. ==============================================================================
  33. */
  34. $langFile = "create_course";
  35. include ('../inc/global.inc.php');
  36. $this_section=SECTION_COURSES;
  37. include (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
  38. /*
  39. -----------------------------------------------------------
  40. Libraries
  41. -----------------------------------------------------------
  42. */
  43. include_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
  44. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  45. include_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  46. include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  47. include_once (api_get_path(CONFIGURATION_PATH).'course_info.conf.php');
  48. /*
  49. ==============================================================================
  50. MAIN CODE
  51. ==============================================================================
  52. */
  53. $tool_name = get_lang('CreateSite');
  54. Display :: display_header($tool_name);
  55. api_display_tool_title($tool_name);
  56. // Check access rights
  57. if (!api_is_allowed_to_create_course())
  58. {
  59. Display :: display_normal_message(get_lang("NotAllowed"));
  60. Display::display_footer();
  61. exit;
  62. }
  63. // Get all course categories
  64. $table_course_category = Database :: get_main_table(MAIN_CATEGORY_TABLE);
  65. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
  66. $res = api_sql_query($sql, __FILE__, __LINE__);
  67. while ($cat = mysql_fetch_array($res))
  68. {
  69. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  70. }
  71. // Build the form
  72. $form = new FormValidator('add_course');
  73. $form->add_textfield('title',get_lang('Title'),true,array('size'=>'60'));
  74. $form->addElement('static',null,null,get_lang('Ex'));
  75. $form->addElement('select', 'category_code', get_lang('Fac'), $categories);
  76. $form->addElement('static',null,null, get_lang('TargetFac'));
  77. $form->add_textfield('wanted_code', get_lang('Code'),true,array('size'=>'20','maxlength'=>20));
  78. $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);
  79. $titular= &$form->add_textfield('tutor_name', get_lang('Professors'),true,array('size'=>'60', 'readonly'=>'true'));
  80. $form->addElement('select_language', 'course_language', get_lang('Ln'));
  81. $form->addElement('submit', null, get_lang('Ok'));
  82. $form->add_progress_bar();
  83. // Set default values
  84. $values['course_language'] = get_setting('platformLanguage');
  85. $values['tutor_name'] = $_user['lastName']." ".$_user['firstName'];
  86. $form->setDefaults($values);
  87. // Validate the form
  88. if($form->validate())
  89. {
  90. $course_values = $form->exportValues();
  91. $wanted_code = $course_values['wanted_code'];
  92. $tutor_name = $course_values['tutor_name'];
  93. $category_code = $course_values['category_code'];
  94. $title = $course_values['title'];
  95. $course_language = $course_values['course_language'];
  96. $keys = define_course_keys($wanted_code, "", $dbNamePrefix);
  97. if (sizeof($keys))
  98. {
  99. $visual_code = $keys["currentCourseCode"];
  100. $code = $keys["currentCourseId"];
  101. $db_name = $keys["currentCourseDbName"];
  102. $directory = $keys["currentCourseRepository"];
  103. $expiration_date = time() + $firstExpirationDelay;
  104. prepare_course_repository($directory, $code);
  105. update_Db_course($db_name);
  106. fill_course_repository($directory);
  107. fill_Db_course($db_name, $directory, $course_language);
  108. register_course($code, $visual_code, $directory, $db_name, $tutor_name, $category_code, $title, $course_language, $_uid, $expiration_date);
  109. }
  110. $message = get_lang('JustCreated');
  111. $message .= " <strong>".$course_values['wanted_code']."</strong>";
  112. $message .= "<br/><br/>";
  113. $message .= '<a href="'.api_get_path(WEB_PATH).'user_portal.php">'.get_lang('Enter').'</a>';
  114. Display :: display_normal_message($message);
  115. }
  116. else
  117. {
  118. // Display the form
  119. $form->display();
  120. echo '<p>'.get_lang('Explanation').'</p>';
  121. }
  122. /*
  123. ==============================================================================
  124. FOOTER
  125. ==============================================================================
  126. */
  127. Display :: display_footer();
  128. ?>