course_virtual.php 12 KB

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