dokeos-create_course
[ class tree: dokeos-create_course ] [ index: dokeos-create_course ] [ all elements ]

Source for file add_course.php

Documentation is available at add_course.php

  1. <?php
  2. // $Id: add_course.php 15568 2008-06-12 05:23:42Z yannoo $
  3. /*
  4. ==============================================================================
  5.     Dokeos - elearning and course management software
  6.  
  7.     Copyright (c) 2004-2005 Dokeos S.A.
  8.     Copyright (c) 2003 Ghent University (UGent)
  9.     Copyright (c) 2001 Universite catholique de Louvain (UCL)
  10.     Copyright (c) 2005 Bart Mollet, Hogeschool Gent
  11.  
  12.     For a full list of contributors, see "credits.txt".
  13.     The full license can be read in "license.txt".
  14.  
  15.     This program is free software; you can redistribute it and/or
  16.     modify it under the terms of the GNU General Public License
  17.     as published by the Free Software Foundation; either version 2
  18.     of the License, or (at your option) any later version.
  19.  
  20.     See the GNU General Public License for more details.
  21.  
  22.     Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  23.     Mail: info@dokeos.com
  24. ==============================================================================
  25. */
  26. /**
  27. ==============================================================================
  28. * This script allows professors and administrative staff to create course sites.
  29. @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  30. @author Roan Embrechts, refactoring
  31. @package dokeos.create_course
  32. ==============================================================================
  33. */
  34.  
  35. // name of the language file that needs to be included 
  36. $language_file "create_course";
  37.  
  38. // including the global file
  39. include ('../inc/global.inc.php');
  40.  
  41. // section for the tabs
  42. $this_section=SECTION_COURSES;
  43.  
  44. // include configuration file
  45. include (api_get_path(CONFIGURATION_PATH).'add_course.conf.php');
  46.  
  47. // include additional libraries
  48. include_once (api_get_path(LIBRARY_PATH).'add_course.lib.inc.php');
  49. include_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  50. include_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  51. include_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  52. include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  53. include_once (api_get_path(CONFIGURATION_PATH).'course_info.conf.php');
  54.  
  55. // Displaying the header
  56. $tool_name get_lang('CreateSite');
  57. Display :: display_header($tool_name);
  58.  
  59. // Displaying the tool title
  60. // Check access rights
  61. {
  62.     Display :: display_error_message(get_lang("NotAllowed"));
  63.     exit;
  64. }
  65. // Get all course categories
  66. $table_course_category Database :: get_main_table(TABLE_MAIN_CATEGORY);
  67. $table_course Database :: get_main_table(TABLE_MAIN_COURSE);
  68.  
  69. // Build the form
  70. $categories array();
  71. $form new FormValidator('add_course');
  72. $form->add_textfield('title',get_lang('Title'),true,array('size'=>'60'));
  73. $form->addElement('static',null,null,get_lang('Ex'));
  74. $categories_select $form->addElement('select''category_code'get_lang('Fac')$categories);
  75. $form->addElement('static',null,nullget_lang('TargetFac'));
  76. $form->add_textfield('wanted_code'get_lang('Code'),false,array('size'=>'20','maxlength'=>20));
  77. $form->addRule('wanted_code',get_lang('Max'),'maxlength',20);
  78. $titular&$form->add_textfield('tutor_name'get_lang('Professors'),true,array('size'=>'60'));
  79. $form->addElement('select_language''course_language'get_lang('Ln'));
  80. $form->addElement('submit'nullget_lang('Ok'));
  81. $form->add_progress_bar();
  82.  
  83. // Set default values
  84. if(isset($_user["language"]&& $_user["language"]!="")
  85. {
  86.     $values['course_language'$_user["language"];
  87. }
  88. else
  89. {
  90.     $values['course_language'get_setting('platformLanguage');
  91. }
  92.  
  93. $values['tutor_name'$_user['firstName']." ".$_user['lastName'];
  94. $form->setDefaults($values);
  95. // Validate the form
  96. if($form->validate())
  97. {
  98.     $course_values $form->exportValues();
  99.     $wanted_code $course_values['wanted_code'];
  100.     $tutor_name $course_values['tutor_name'];
  101.     $category_code $course_values['category_code'];
  102.     $title $course_values['title'];
  103.     $course_language $course_values['course_language'];
  104.     
  105.     if(trim($wanted_code== ''){
  106.         $wanted_code generate_course_code(substr($title,0,20));
  107.     }
  108.     
  109.     $keys define_course_keys($wanted_code""$_configuration['db_prefix']);
  110.     
  111.     $sql_check sprintf('SELECT * FROM '.$table_course.' WHERE visual_code = "%s"',Database :: escape_string($wanted_code));
  112.     //$result_check = mysql_query($sql_check);
  113.     $result_check api_sql_query($sql_check,__FILE__,__LINE__)//I don't know why this api function doesn't work...
  114.     if(Database::num_rows($result_check)<1)
  115.     {
  116.         if (sizeof($keys))
  117.         {
  118.             $visual_code $keys["currentCourseCode"];
  119.             $code $keys["currentCourseId"];
  120.             $db_name $keys["currentCourseDbName"];
  121.             $directory $keys["currentCourseRepository"];
  122.             $expiration_date time($firstExpirationDelay;
  123.             prepare_course_repository($directory$code);
  124.             update_Db_course($db_name);
  125.             $pictures_array=fill_course_repository($directory);
  126.             fill_Db_course($db_name$directory$course_language,$pictures_array);
  127.             register_course($code$visual_code$directory$db_name$tutor_name$category_code$title$course_languageapi_get_user_id()$expiration_date);
  128.         }
  129.         $message get_lang('JustCreated');
  130.         $message .= " <strong>".$visual_code."</strong>";
  131.         $message .= "<br /><br /><br />";
  132.         $message .= '<a class="bottom-link" href="'.api_get_path(WEB_PATH).'user_portal.php">'.get_lang('Enter').'</a>';
  133.         Display :: display_confirmation_message($message,false);
  134.     }
  135.     else
  136.     {
  137.         Display :: display_error_message(get_lang('CourseCodeAlreadyExists'),false);
  138.         $form->display();
  139.         echo '<p>'.get_lang('CourseCodeAlreadyExistExplained').'</p>';
  140.     }
  141.         
  142. }
  143. else
  144. {
  145.     // Display the form
  146.     $form->display();
  147.     echo '<p>'.get_lang('Explanation').'</p>';
  148. }
  149. /*
  150. ==============================================================================
  151.         FOOTER
  152. ==============================================================================
  153. */
  154. ?>

Documentation generated on Thu, 12 Jun 2008 12:54:11 -0500 by phpDocumentor 1.4.1