add_course.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. // $Id: add_course.php 14291 2008-02-14 08:17:23Z 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 Patrick Cool <patrick.cool@UGent.be>, Ghent University
  25. * @author Roan Embrechts, refactoring
  26. * @package dokeos.create_course
  27. ==============================================================================
  28. */
  29. // name of the language file that needs to be included
  30. $language_file = "create_course";
  31. // including the global file
  32. include ('../inc/global.inc.php');
  33. // section for the tabs
  34. $this_section=SECTION_COURSES;
  35. // include configuration file
  36. include (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
  37. // include additional libraries
  38. include_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
  39. include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  40. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  41. include_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  42. include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  43. include_once (api_get_path(CONFIGURATION_PATH).'course_info.conf.php');
  44. // Displaying the header
  45. $tool_name = get_lang('CreateSite');
  46. Display :: display_header($tool_name);
  47. // Displaying the tool title
  48. api_display_tool_title($tool_name);
  49. // Check access rights
  50. if (!api_is_allowed_to_create_course())
  51. {
  52. Display :: display_error_message(get_lang("NotAllowed"));
  53. Display::display_footer();
  54. exit;
  55. }
  56. // Get all course categories
  57. $table_course_category = Database :: get_main_table(TABLE_MAIN_CATEGORY);
  58. $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  59. // Build the form
  60. $form = new FormValidator('add_course');
  61. $form->add_textfield('title',get_lang('Title'),true,array('size'=>'60'));
  62. $form->addElement('static',null,null,get_lang('Ex'));
  63. $categories_select = $form->addElement('select', 'category_code', get_lang('Fac'), $categories);
  64. CourseManager::select_and_sort_categories($categories_select);
  65. $form->addElement('static',null,null, get_lang('TargetFac'));
  66. $form->add_textfield('wanted_code', get_lang('Code'),false,array('size'=>'20','maxlength'=>20));
  67. $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);
  68. $titular= &$form->add_textfield('tutor_name', get_lang('Professors'),true,array('size'=>'60'));
  69. $form->addElement('select_language', 'course_language', get_lang('Ln'));
  70. $form->addElement('submit', null, get_lang('Ok'));
  71. $form->add_progress_bar();
  72. // Set default values
  73. if(isset($_user["language"]) && $_user["language"]!="")
  74. {
  75. $values['course_language'] = $_user["language"];
  76. }
  77. else
  78. {
  79. $values['course_language'] = get_setting('platformLanguage');
  80. }
  81. $values['tutor_name'] = $_user['firstName']." ".$_user['lastName'];
  82. $form->setDefaults($values);
  83. // Validate the form
  84. if($form->validate())
  85. {
  86. $course_values = $form->exportValues();
  87. $wanted_code = $course_values['wanted_code'];
  88. $tutor_name = $course_values['tutor_name'];
  89. $category_code = $course_values['category_code'];
  90. $title = $course_values['title'];
  91. $course_language = $course_values['course_language'];
  92. if(trim($wanted_code) == ''){
  93. $wanted_code = generate_course_code(substr($title,0,20));
  94. }
  95. $keys = define_course_keys($wanted_code, "", $_configuration['db_prefix']);
  96. $sql_check = sprintf('SELECT * FROM '.$table_course.' WHERE visual_code = "%s"',Database :: escape_string($wanted_code));
  97. //$result_check = mysql_query($sql_check);
  98. $result_check = api_sql_query($sql_check,__FILE__,__LINE__); //I don't know why this api function doesn't work...
  99. if(Database::num_rows($result_check)<1)
  100. {
  101. if (sizeof($keys))
  102. {
  103. $visual_code = $keys["currentCourseCode"];
  104. $code = $keys["currentCourseId"];
  105. $db_name = $keys["currentCourseDbName"];
  106. $directory = $keys["currentCourseRepository"];
  107. $expiration_date = time() + $firstExpirationDelay;
  108. prepare_course_repository($directory, $code);
  109. update_Db_course($db_name);
  110. $pictures_array=fill_course_repository($directory);
  111. fill_Db_course($db_name, $directory, $course_language,$pictures_array);
  112. register_course($code, $visual_code, $directory, $db_name, $tutor_name, $category_code, $title, $course_language, api_get_user_id(), $expiration_date);
  113. }
  114. $message = get_lang('JustCreated');
  115. $message .= " <strong>".$visual_code."</strong>";
  116. $message .= "<br/><br/>";
  117. $message .= '<a href="'.api_get_path(WEB_PATH).'user_portal.php">'.get_lang('Enter').'</a>';
  118. Display :: display_confirmation_message($message,false);
  119. }
  120. else
  121. {
  122. Display :: display_error_message(get_lang('CourseCodeAlreadyExists'),false);
  123. $form->display();
  124. echo '<p>'.get_lang('CourseCodeAlreadyExistExplained').'</p>';
  125. }
  126. }
  127. else
  128. {
  129. // Display the form
  130. $form->display();
  131. echo '<p>'.get_lang('Explanation').'</p>';
  132. }
  133. /*
  134. ==============================================================================
  135. FOOTER
  136. ==============================================================================
  137. */
  138. Display :: display_footer();
  139. ?>