course_virtual.php 12 KB

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