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

Source for file course_virtual.php

Documentation is available at course_virtual.php

  1. <?php // $Id: course_virtual.php 12272 2007-05-03 14:40:45Z elixir_julian $ 
  2. /*
  3. ============================================================================== 
  4.     Dokeos - elearning and course management software
  5.     
  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) Roan Embrechts (Vrije Universiteit Brussel)
  10.     
  11.     For a full list of contributors, see "credits.txt".
  12.     The full license can be read in "license.txt".
  13.     
  14.     This program is free software; you can redistribute it and/or
  15.     modify it under the terms of the GNU General Public License
  16.     as published by the Free Software Foundation; either version 2
  17.     of the License, or (at your option) any later version.
  18.     
  19.     See the GNU General Public License for more details.
  20.     
  21.     Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  22.     Mail: info@dokeos.com
  23. ============================================================================== 
  24. */
  25. /**
  26. ============================================================================== 
  27. *    @author Roan Embrechts - initial admin interface
  28. *    @package dokeos.admin
  29. ============================================================================== 
  30. */
  31.  
  32. /*
  33. ============================================================================== 
  34.         INIT SECTION
  35. ============================================================================== 
  36. */ 
  37.  
  38. // name of the language file that needs to be included 
  39. $language_file 'admin'
  40. $extra_lang_file "create_course";
  41.  
  42. // global settings initialisation 
  43. // also provides access to main api (inc/lib/main_api.lib.php)
  44. include("../inc/global.inc.php")
  45. $this_section=SECTION_PLATFORM_ADMIN;
  46.  
  47.  
  48. if (isset($extra_lang_file)) include(api_get_path(INCLUDE_PATH)."../lang/english/".$extra_lang_file.".inc.php");
  49. if (isset($extra_lang_file)) include(api_get_path(INCLUDE_PATH)."../lang/".$language_interface."/".$extra_lang_file.".inc.php");
  50.  
  51. /*
  52. -----------------------------------------------------------
  53.     Libraries
  54. -----------------------------------------------------------
  55. */ 
  56.  
  57. include_once(api_get_path(LIBRARY_PATH'course.lib.php');
  58.  
  59. /*
  60. -----------------------------------------------------------
  61.     Constants
  62. -----------------------------------------------------------
  63. */ 
  64.  
  65. define ("CREATE_VIRTUAL_COURSE_OPTION""create_virtual_course");
  66. define ("DISPLAY_VIRTUAL_COURSE_LIST_OPTION""display_virtual_course_list");
  67.  
  68. define ("FORM_ELEMENT_CODE_SIZE""20");
  69. define ("FORM_ELEMENT_TEXT_SIZE""60");
  70. define ("SELECT_BOX_SIZE""10");
  71.  
  72. define ("COURSE_TITLE_FORM_NAME""course_title");
  73. define ("LANGUAGE_SELECT_FORM_NAME" "course_language");
  74. define ("REAL_COURSE_SELECT_FORM_NAME" "real_course_code");
  75. define ("WANTED_COURSE_CODE_FORM_NAME" "wanted_course_code");
  76. define ("COURSE_CATEGORY_FORM_NAME" "course_category");
  77.  
  78. /*
  79. -----------------------------------------------------------
  80.     Header
  81. -----------------------------------------------------------
  82. */ 
  83.  
  84. $tool_name get_lang('AdminManageVirtualCourses')// title of the page (should come from the language file) 
  85.  
  86. $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  87.  
  88. Display::display_header($tool_name);
  89.  
  90. /*
  91. ============================================================================== 
  92.         DISPLAY FUNCTIONS
  93. ============================================================================== 
  94. */ 
  95.  
  96. function make_strong($text)
  97. {
  98.     return "<strong>" $text "</strong>";
  99. }
  100.  
  101.  
  102. /**
  103. *    Return a list of language directories.
  104. *    @todo function does not belong here, move to code library,
  105. *     also see infocours.php and index.php which contain a similar function
  106. */
  107. function get_language_folder_list($dirname)
  108. {
  109.     if($dirname[strlen($dirname)-1]!='/'$dirname.='/';
  110.     $handle=opendir($dirname);
  111.     while ($entries readdir($handle))
  112.     {
  113.         if ($entries=='.' || $entries=='..' || $entries=='CVS'continue;
  114.         if (is_dir($dirname.$entries))
  115.         {
  116.             $language_list[$entries;
  117.         }
  118.     }
  119.     closedir($handle);
  120.     return $language_list;
  121. }
  122.  
  123. /**
  124. * Displays a select element (drop down menu) so the user can select
  125. * the course language.
  126. @todo function does not belong here, move to (display?) library,
  127. @todo language display used apparently no longer existing array, converted to english for now.
  128. *  but we should switch to display the real language names.
  129. */
  130. function display_language_select($element_name)
  131. {
  132.     global $platformLanguage;
  133.     
  134.     //get language list
  135.     $dirname api_get_path(SYS_PATH)."main/lang/";
  136.     $language_list get_language_folder_list($dirname);
  137.     sort($language_list);
  138.     
  139.     //build array with strings to display
  140.     foreach ($language_list as $this_language)
  141.     {    
  142.         $language_to_display[$this_language$this_language;
  143.     }
  144.     
  145.     //sort alphabetically
  146.     //warning: key,value association needs to be maintained --> asort instead of sort
  147.     asort($language_to_display);
  148.              
  149.     $user_selected_language $_SESSION["user_language_choice"];
  150.     if (isset($user_selected_language) ) $user_selected_language $platformLanguage;
  151.     
  152.     //display
  153.     echo "<select name=\"$element_name\">";
  154.     foreach ($language_to_display as $key => $value)
  155.     {
  156.         if ($key == $user_selected_language$option_end "selected >";
  157.         else $option_end ">";
  158.         echo "<option value=\"$key\" $option_end";
  159.  
  160.         echo $value;
  161.         echo "</option>\n";
  162.     }
  163.     echo "</select>";
  164. }
  165.  
  166. /**
  167. *    This code creates a select form element to let the user
  168. *    choose a real course to link to.
  169. *
  170. *    We display the course code, but internally store the course id.
  171. */
  172. function display_real_course_code_select($element_name)
  173. {    
  174.     $real_course_list CourseManager::get_real_course_list();
  175.             
  176.     echo "<select name=\"$element_name\" size=\"".SELECT_BOX_SIZE."\" >\n";
  177.     foreach($real_course_list as $real_course)
  178.     {
  179.         $course_code $real_course["code"];
  180.         echo "<option value=\""$course_code ."\">";
  181.         echo $course_code;
  182.         echo "</option>\n";
  183.     }
  184.     echo "</select>\n";
  185. }
  186.  
  187.  
  188. {
  189.     $category_table Database::get_main_table(TABLE_MAIN_CATEGORY);
  190.  
  191.     $message make_strong(get_lang('AdminCreateVirtualCourse')) "<br/>" get_lang('AdminCreateVirtualCourseExplanation'"<br/>This feature is in development phase, bug reports welcome.";
  192.     ?>
  193.     <p><?php echo $message;    ?></p>
  194.     <b><?php echo get_lang('MandatoryFields'?></b>
  195.     <form method="post" action="<?php echo api_get_self()?>">
  196.     <table>
  197.     <tr valign="top">
  198.     <td colspan="2">
  199.     
  200.     </td>
  201.     </tr>
  202.     
  203.     <tr valign="top">
  204.     <td align="right">
  205.         <?php
  206.             echo make_strong(get_lang('CourseTitle')) "&nbsp;";
  207.             echo "</td>";
  208.             echo "<td valign=\"top\">";
  209.             echo "<input type=\"Text\" name=\"".COURSE_TITLE_FORM_NAME."\" size=\"".FORM_ELEMENT_TEXT_SIZE."\" value=\"$valueIntitule\"/><br />".get_lang('Ex';
  210.         ?>
  211.     </td>
  212.     </tr>
  213.     
  214.     <tr valign="top">
  215.     <td align="right"><?php echo make_strong(get_lang('CourseFaculty')) "&nbsp;"?> </td>
  216.     <td>
  217.         <?php
  218.             echo "<select name=\"".COURSE_CATEGORY_FORM_NAME."\">";
  219.             
  220.             $sql_query "SELECT code, name
  221.                                     FROM $category_table
  222.                                     WHERE auth_course_child ='TRUE'
  223.                                     ORDER BY tree_pos";
  224.             $category_result api_sql_query($sql_query__FILE____LINE__);
  225.         
  226.             while ($current_category mysql_fetch_array($category_result))
  227.             {
  228.                 echo "<option value=\""$current_category["code"]"\"";
  229.                 echo ">("$current_category["code"]") "$current_category["name"];
  230.                 echo "</option>\n";
  231.             }
  232.         ?>
  233.     </select>
  234.     <br /><?php echo make_strong(get_lang('TargetFac'))  "&nbsp;" ?>
  235.     </td>
  236.     </tr>
  237.     
  238.     <tr valign="top">
  239.     <td align="right"><?php echo make_strong(get_lang('Code'))  "&nbsp;" ?> </td>
  240.     <td>
  241.     <?php
  242.     echo "<input type=\"Text\" name=\"".WANTED_COURSE_CODE_FORM_NAME."\" maxlength=\"".FORM_ELEMENT_CODE_SIZE."\" value=\"$valuePublicCode\"/>
  243.     <br/>get_lang('Max');
  244.     ?>
  245.     </td>
  246.     </tr>
  247.     
  248.     <tr valign="top">
  249.     <td align="right">
  250.     <?php echo make_strong(get_lang('RealCourseCode'))  "&nbsp;" ?> 
  251.     </td>
  252.     <td>
  253.         <?php
  254.             //echo "<input type=\"Text\" name=\"real_course_code\" maxlength=\"".FORM_ELEMENT_CODE_SIZE."\" value=\"" . htmlentities($valueTitular) . "\"/>";
  255.         ?>
  256.     </td>
  257.     </tr>
  258.     
  259.     <tr valign="top">
  260.     <td align="right">
  261.         <?php 
  262.             echo make_strong(get_lang('CourseLanguage')) "&nbsp;";
  263.         ?> 
  264.     </td>
  265.  
  266.     </td>
  267.     </tr>
  268.     <tr valign="top">
  269.     <td>
  270.     </td>
  271.     <td>
  272.     <input type="Submit" name="submit_create_virtual_course" value="<?php echo get_lang('Ok')?>"/>
  273.     </td>
  274.     </tr>
  275.     </table>
  276.     </form>
  277.     <?php
  278. }
  279.  
  280. {
  281.     $message "<ul><li><a href=\"?action=".CREATE_VIRTUAL_COURSE_OPTION."\">".get_lang('CreateVirtualCourse')."</a></li>";
  282.     $message .= "<li><a href=\"?action=".DISPLAY_VIRTUAL_COURSE_LIST_OPTION."\">".get_lang('DisplayListVirtualCourses')."</a></li></ul>";
  283.     echo $message;
  284. }
  285.  
  286. {
  287.     $course_list CourseManager::get_virtual_course_list();
  288.     if (is_array($course_list) )
  289.     {
  290.         //there are no virtual courses
  291.         echo "<i>".get_lang('ThereAreNoVirtualCourses')."</i>";
  292.         return;
  293.     }
  294.     
  295.     $column_header[array(get_lang('Title'),true);                    
  296.     $column_header[array(get_lang('Code'),true);                
  297.     $column_header[array(get_lang('VisualCode'),true);                
  298.     $column_header[array(get_lang('LinkedCourseTitle'),true);    
  299.     $column_header[array(get_lang('LinkedCourseCode'),true);        
  300.     $table_data array();
  301.     for($i 0$i count($course_list)$i++)
  302.     {
  303.         $course_list[$iDatabase::generate_abstract_course_field_names($course_list[$i]);
  304.         $target_course_code $course_list[$i]["target_course_code"];
  305.         $real_course_info Database::get_course_info($target_course_code);
  306.         
  307.         $row array();
  308.         $row[$course_list[$i]["title"];
  309.         $row[$course_list[$i]["system_code"];
  310.         $row[$course_list[$i]["visual_code"];
  311.         $row[$real_course_info["title"];
  312.         $row[]$real_course_info["system_code"];
  313.         $table_data[$row;
  314.     }
  315.     Display::display_sortable_table($column_header,$table_data,array(),array(),array('action'=>$_GET['action']));
  316. }
  317.  
  318.  
  319. /*
  320. ============================================================================== 
  321.         TOOL LOGIC FUNCTIONS
  322. ============================================================================== 
  323. */
  324.  
  325. /**
  326. *    Checks all parameters needed to create a virtual course.
  327. *    If they are all set, the virtual course creation procedure is called.
  328. *    Call this function instead of create_virtual_course
  329. */
  330. function attempt_create_virtual_course($real_course_code$course_title$wanted_course_code$course_language$course_category)
  331. {        
  332.     //better: create parameter list, check the entire list, when false display errormessage    
  333.     CourseManager::check_parameter_or_fail($real_course_code"Unspecified parameter: real course id.");
  334.     CourseManager::check_parameter_or_fail($course_title"Unspecified parameter: course title.");
  335.     CourseManager::check_parameter_or_fail($wanted_course_code"Unspecified parameter: wanted course code.");
  336.     CourseManager::check_parameter_or_fail($course_language"Unspecified parameter: course language.");
  337.     CourseManager::check_parameter_or_fail($course_category"Unspecified parameter: course category.");
  338.     
  339.     $message get_lang('AttemptedCreationVirtualCourse'"<br/>";
  340.     $message .= get_lang('CourseTitle'" " $course_title "<br/>";
  341.     $message .= get_lang('WantedCourseCode'" " $wanted_course_code "<br/>";
  342.     $message .= get_lang('CourseLanguage'" " $course_language "<br/>";
  343.     $message .= get_lang('CourseFaculty'" " $course_category "<br/>";
  344.     $message .= get_lang('LinkedToRealCourseCode'" " $real_course_code "<br/>";
  345.     
  346.     Display::display_normal_message($message);
  347.     
  348.     $creation_success CourseManager::create_virtual_course$real_course_code$course_title$wanted_course_code$course_language$course_category );
  349.     
  350.     if ($creation_success == true)
  351.     {
  352.         Display::display_normal_message$course_title " - " get_lang('CourseCreationSucceeded') );
  353.         return true;
  354.     }
  355.     return false;
  356. }
  357.     
  358. /*
  359. ============================================================================== 
  360.         MAIN CODE
  361. ============================================================================== 
  362. */ 
  363.  
  364. $action $_GET["action"];
  365. $attempt_create_virtual_course $_POST["submit_create_virtual_course"];
  366.  
  367. //api_display_tool_title($tool_name);
  368.  
  369. if isset($attempt_create_virtual_course&& $attempt_create_virtual_course )
  370. {
  371.     $real_course_code $_POST[REAL_COURSE_SELECT_FORM_NAME];
  372.     $course_title $_POST[COURSE_TITLE_FORM_NAME];
  373.     $wanted_course_code $_POST[WANTED_COURSE_CODE_FORM_NAME];
  374.     $course_language $_POST[LANGUAGE_SELECT_FORM_NAME];
  375.     $course_category $_POST[COURSE_CATEGORY_FORM_NAME];
  376.     
  377.     $message get_lang('AttemptedCreationVirtualCourse'"<br/>";
  378.     $message .= get_lang('CourseTitle'" " $course_title "<br/>";
  379.     $message .= get_lang('WantedCourseCode'" " $wanted_course_code "<br/>";
  380.     $message .= get_lang('CourseLanguage'" " $course_language "<br/>";
  381.     $message .= get_lang('CourseFaculty'" " $course_category "<br/>";
  382.     $message .= get_lang('LinkedToRealCourseCode'" " $real_course_code "<br/>";
  383.     
  384.     Display::display_normal_message($message);
  385.     
  386.     $creation_success CourseManager::attempt_create_virtual_course($real_course_code$course_title$wanted_course_code$course_language$course_category);
  387.     
  388.     if ($creation_success == true)
  389.     {
  390.         Display::display_normal_message$course_title " - " get_lang('CourseCreationSucceeded') );
  391.     }
  392.     else
  393.     {
  394.         //should display error message
  395.     }
  396.     echo "<br/>";
  397. }
  398.  
  399.  
  400.  
  401. switch($action)
  402. {
  403.                             display_create_virtual_course_form();
  404.                             break;
  405.                             display_virtual_course_list();
  406.                             break;
  407. }
  408.  
  409. /*
  410. ==============================================================================
  411.         FOOTER 
  412. ==============================================================================
  413. */ 
  414. ?>

Documentation generated on Thu, 12 Jun 2008 13:16:41 -0500 by phpDocumentor 1.4.1