course_virtual.php 14 KB

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