add_course.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. // $Id: add_course.php 11640 2007-03-21 16:21:55Z yannoo $
  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. // name of the language file that needs to be included
  35. $language_file = "create_course";
  36. include ('../inc/global.inc.php');
  37. $this_section=SECTION_COURSES;
  38. include (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
  39. /*
  40. -----------------------------------------------------------
  41. Libraries
  42. -----------------------------------------------------------
  43. */
  44. include_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
  45. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  46. include_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  47. include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  48. include_once (api_get_path(CONFIGURATION_PATH).'course_info.conf.php');
  49. /*
  50. ==============================================================================
  51. MAIN CODE
  52. ==============================================================================
  53. */
  54. $tool_name = get_lang('CreateSite');
  55. Display :: display_header($tool_name);
  56. api_display_tool_title($tool_name);
  57. // Check access rights
  58. if (!api_is_allowed_to_create_course())
  59. {
  60. Display :: display_normal_message(get_lang("NotAllowed"));
  61. Display::display_footer();
  62. exit;
  63. }
  64. // Get all course categories
  65. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  66. $sql = "SELECT code,name FROM ".$table_course_category." WHERE auth_course_child ='TRUE' ORDER BY tree_pos";
  67. $res = api_sql_query($sql, __FILE__, __LINE__);
  68. while ($cat = mysql_fetch_array($res))
  69. {
  70. $categories[$cat['code']] = '('.$cat['code'].') '.$cat['name'];
  71. }
  72. // Build the form
  73. $form = new FormValidator('add_course');
  74. $form->add_textfield('title',get_lang('Title'),true,array('size'=>'60'));
  75. $form->addElement('static',null,null,get_lang('Ex'));
  76. $form->addElement('select', 'category_code', get_lang('Fac'), $categories);
  77. $form->addElement('static',null,null, get_lang('TargetFac'));
  78. $form->add_textfield('wanted_code', get_lang('Code'),true,array('size'=>'20','maxlength'=>20));
  79. $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);
  80. $titular= &$form->add_textfield('tutor_name', get_lang('Professors'),true,array('size'=>'60'));
  81. $form->addElement('select_language', 'course_language', get_lang('Ln'));
  82. $form->addElement('submit', null, get_lang('Ok'));
  83. $form->add_progress_bar();
  84. // Set default values
  85. if(isset($_user["language"]) && $_user["language"]!=""){
  86. $values['course_language'] = $_user["language"];
  87. }
  88. else{
  89. $values['course_language'] = get_setting('platformLanguage');
  90. }
  91. $values['tutor_name'] = $_user['firstName']." ".$_user['lastName'];
  92. $form->setDefaults($values);
  93. // Validate the form
  94. if($form->validate())
  95. {
  96. $course_values = $form->exportValues();
  97. $wanted_code = $course_values['wanted_code'];
  98. $tutor_name = $course_values['tutor_name'];
  99. $category_code = $course_values['category_code'];
  100. $title = $course_values['title'];
  101. $course_language = $course_values['course_language'];
  102. $keys = define_course_keys($wanted_code, "", $_configuration['db_prefix']);
  103. if (sizeof($keys))
  104. {
  105. $visual_code = $keys["currentCourseCode"];
  106. $code = $keys["currentCourseId"];
  107. $db_name = $keys["currentCourseDbName"];
  108. $directory = $keys["currentCourseRepository"];
  109. $expiration_date = time() + $firstExpirationDelay;
  110. prepare_course_repository($directory, $code);
  111. update_Db_course($db_name);
  112. $pictures_array=fill_course_repository($directory);
  113. fill_Db_course($db_name, $directory, $course_language,$pictures_array);
  114. register_course($code, $visual_code, $directory, $db_name, $tutor_name, $category_code, $title, $course_language, $_user['user_id'], $expiration_date);
  115. }
  116. $message = get_lang('JustCreated');
  117. $message .= " <strong>".$course_values['wanted_code']."</strong>";
  118. $message .= "<br/><br/>";
  119. $message .= '<a href="'.api_get_path(WEB_PATH).'user_portal.php">'.get_lang('Enter').'</a>';
  120. Display :: display_normal_message($message,false);
  121. }
  122. else
  123. {
  124. // Display the form
  125. $form->display();
  126. echo '<p>'.get_lang('Explanation').'</p>';
  127. }
  128. /*
  129. ==============================================================================
  130. FOOTER
  131. ==============================================================================
  132. */
  133. Display :: display_footer();
  134. ?>