course_virtual.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. 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. $category_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
  157. $message = make_strong(get_lang('AdminCreateVirtualCourse')) . "<br/>" . get_lang('AdminCreateVirtualCourseExplanation') . "<br/>This feature is in development phase, bug reports welcome.";
  158. ?>
  159. <p><?php echo $message; ?></p>
  160. <b><?php echo get_lang('MandatoryFields') ?></b>
  161. <form method="post" action="<?php echo api_get_self(); ?>">
  162. <table>
  163. <tr valign="top">
  164. <td colspan="2">
  165. </td>
  166. </tr>
  167. <tr valign="top">
  168. <td align="right">
  169. <?php
  170. echo make_strong(get_lang('CourseTitle')) . "&nbsp;";
  171. echo "</td>";
  172. echo "<td valign=\"top\">";
  173. echo "<input type=\"Text\" name=\"".COURSE_TITLE_FORM_NAME."\" size=\"".FORM_ELEMENT_TEXT_SIZE."\" value=\"$valueIntitule\"/><br />".get_lang('Ex') ;
  174. ?>
  175. </td>
  176. </tr>
  177. <tr valign="top">
  178. <td align="right"><?php echo make_strong(get_lang('CourseFaculty')) . "&nbsp;"; ?> </td>
  179. <td>
  180. <?php
  181. echo "<select name=\"".COURSE_CATEGORY_FORM_NAME."\">";
  182. $sql_query = "SELECT code, name
  183. FROM $category_table
  184. WHERE auth_course_child ='TRUE'
  185. ORDER BY tree_pos";
  186. $category_result = api_sql_query($sql_query, __FILE__, __LINE__);
  187. while ($current_category = mysql_fetch_array($category_result))
  188. {
  189. echo "<option value=\"", $current_category["code"], "\"";
  190. echo ">(", $current_category["code"], ") ", $current_category["name"];
  191. echo "</option>\n";
  192. }
  193. ?>
  194. </select>
  195. <br /><?php echo make_strong(get_lang('TargetFac')) . "&nbsp;" ?>
  196. </td>
  197. </tr>
  198. <tr valign="top">
  199. <td align="right"><?php echo make_strong(get_lang('Code')) . "&nbsp;" ?> </td>
  200. <td>
  201. <?php
  202. echo "<input type=\"Text\" name=\"".WANTED_COURSE_CODE_FORM_NAME."\" maxlength=\"".FORM_ELEMENT_CODE_SIZE."\" value=\"$valuePublicCode\"/>
  203. <br/>" . get_lang('Max');
  204. ?>
  205. </td>
  206. </tr>
  207. <tr valign="top">
  208. <td align="right">
  209. <?php echo make_strong(get_lang('RealCourseCode')) . "&nbsp;" ?>
  210. </td>
  211. <td>
  212. <?php
  213. display_real_course_code_select(REAL_COURSE_SELECT_FORM_NAME);
  214. //echo "<input type=\"Text\" name=\"real_course_code\" maxlength=\"".FORM_ELEMENT_CODE_SIZE."\" value=\"" . htmlentities($valueTitular) . "\"/>";
  215. ?>
  216. </td>
  217. </tr>
  218. <tr valign="top">
  219. <td align="right">
  220. <?php
  221. echo make_strong(get_lang('CourseLanguage')) . "&nbsp;";
  222. ?>
  223. </td>
  224. <td> <?php display_language_select(LANGUAGE_SELECT_FORM_NAME); ?>
  225. </td>
  226. </tr>
  227. <tr valign="top">
  228. <td>
  229. </td>
  230. <td>
  231. <input type="Submit" name="submit_create_virtual_course" value="<?php echo get_lang('Ok')?>"/>
  232. </td>
  233. </tr>
  234. </table>
  235. </form>
  236. <?php
  237. }
  238. function display_main_options()
  239. {
  240. $message = "<ul><li><a href=\"?action=".CREATE_VIRTUAL_COURSE_OPTION."\">".get_lang('CreateVirtualCourse')."</a></li>";
  241. $message .= "<li><a href=\"?action=".DISPLAY_VIRTUAL_COURSE_LIST_OPTION."\">".get_lang('DisplayListVirtualCourses')."</a></li></ul>";
  242. echo $message;
  243. }
  244. function display_virtual_course_list()
  245. {
  246. $course_list = CourseManager::get_virtual_course_list();
  247. if (! is_array($course_list) )
  248. {
  249. //there are no virtual courses
  250. echo "<i>".get_lang('ThereAreNoVirtualCourses')."</i>";
  251. return;
  252. }
  253. $column_header[] = array(get_lang('Title'),true);
  254. $column_header[] = array(get_lang('Code'),true);
  255. $column_header[] = array(get_lang('VisualCode'),true);
  256. $column_header[] = array(get_lang('LinkedCourseTitle'),true);
  257. $column_header[] = array(get_lang('LinkedCourseCode'),true);
  258. $table_data = array();
  259. for($i = 0; $i < count($course_list); $i++)
  260. {
  261. $course_list[$i] = Database::generate_abstract_course_field_names($course_list[$i]);
  262. $target_course_code = $course_list[$i]["target_course_code"];
  263. $real_course_info = Database::get_course_info($target_course_code);
  264. $row = array();
  265. $row[] = $course_list[$i]["title"];
  266. $row[] = $course_list[$i]["system_code"];
  267. $row[] = $course_list[$i]["visual_code"];
  268. $row[] = $real_course_info["title"];
  269. $row[]= $real_course_info["system_code"];
  270. $table_data[] = $row;
  271. }
  272. Display::display_sortable_table($column_header,$table_data,array(),array(),array('action'=>$_GET['action']));
  273. }
  274. /*
  275. ==============================================================================
  276. TOOL LOGIC FUNCTIONS
  277. ==============================================================================
  278. */
  279. /**
  280. * Checks all parameters needed to create a virtual course.
  281. * If they are all set, the virtual course creation procedure is called.
  282. * Call this function instead of create_virtual_course
  283. */
  284. function attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category)
  285. {
  286. //better: create parameter list, check the entire list, when false display errormessage
  287. CourseManager::check_parameter_or_fail($real_course_code, "Unspecified parameter: real course id.");
  288. CourseManager::check_parameter_or_fail($course_title, "Unspecified parameter: course title.");
  289. CourseManager::check_parameter_or_fail($wanted_course_code, "Unspecified parameter: wanted course code.");
  290. CourseManager::check_parameter_or_fail($course_language, "Unspecified parameter: course language.");
  291. CourseManager::check_parameter_or_fail($course_category, "Unspecified parameter: course category.");
  292. $message = get_lang('AttemptedCreationVirtualCourse') . "<br/>";
  293. $message .= get_lang('CourseTitle') . " " . $course_title . "<br/>";
  294. $message .= get_lang('WantedCourseCode') . " " . $wanted_course_code . "<br/>";
  295. $message .= get_lang('CourseLanguage') . " " . $course_language . "<br/>";
  296. $message .= get_lang('CourseFaculty') . " " . $course_category . "<br/>";
  297. $message .= get_lang('LinkedToRealCourseCode') . " " . $real_course_code . "<br/>";
  298. Display::display_normal_message($message);
  299. $creation_success = CourseManager::create_virtual_course( $real_course_code, $course_title, $wanted_course_code, $course_language, $course_category );
  300. if ($creation_success == true)
  301. {
  302. Display::display_normal_message( $course_title . " - " . get_lang('CourseCreationSucceeded') );
  303. return true;
  304. }
  305. return false;
  306. }
  307. /*
  308. ==============================================================================
  309. MAIN CODE
  310. ==============================================================================
  311. */
  312. $action = $_GET["action"];
  313. $attempt_create_virtual_course = $_POST["submit_create_virtual_course"];
  314. //api_display_tool_title($tool_name);
  315. if ( isset($attempt_create_virtual_course) && $attempt_create_virtual_course )
  316. {
  317. $real_course_code = $_POST[REAL_COURSE_SELECT_FORM_NAME];
  318. $course_title = $_POST[COURSE_TITLE_FORM_NAME];
  319. $wanted_course_code = $_POST[WANTED_COURSE_CODE_FORM_NAME];
  320. $course_language = $_POST[LANGUAGE_SELECT_FORM_NAME];
  321. $course_category = $_POST[COURSE_CATEGORY_FORM_NAME];
  322. $message = get_lang('AttemptedCreationVirtualCourse') . "<br/>";
  323. $message .= get_lang('CourseTitle') . " " . $course_title . "<br/>";
  324. $message .= get_lang('WantedCourseCode') . " " . $wanted_course_code . "<br/>";
  325. $message .= get_lang('CourseLanguage') . " " . $course_language . "<br/>";
  326. $message .= get_lang('CourseFaculty') . " " . $course_category . "<br/>";
  327. $message .= get_lang('LinkedToRealCourseCode') . " " . $real_course_code . "<br/>";
  328. Display::display_normal_message($message);
  329. $creation_success = CourseManager::attempt_create_virtual_course($real_course_code, $course_title, $wanted_course_code, $course_language, $course_category);
  330. if ($creation_success == true)
  331. {
  332. Display::display_normal_message( $course_title . " - " . get_lang('CourseCreationSucceeded') );
  333. }
  334. else
  335. {
  336. //should display error message
  337. }
  338. echo "<br/>";
  339. }
  340. display_main_options();
  341. switch($action)
  342. {
  343. case CREATE_VIRTUAL_COURSE_OPTION:
  344. display_create_virtual_course_form();
  345. break;
  346. case DISPLAY_VIRTUAL_COURSE_LIST_OPTION:
  347. display_virtual_course_list();
  348. break;
  349. }
  350. /*
  351. ==============================================================================
  352. FOOTER
  353. ==============================================================================
  354. */
  355. Display::display_footer();
  356. ?>