course_virtual.php 12 KB

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