yannick_lp_admin_view.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Patrick Cool
  9. Copyright (c) Denes Nagy
  10. Copyright (c) Yannick Warnier
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * This is a learning path creation and player tool in Dokeos - previously learnpath_handler.php
  24. *
  25. * @author Patrick Cool
  26. * @author Denes Nagy
  27. * @author Roan Embrechts, refactoring and code cleaning
  28. * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update for new SCORM tool
  29. * @package dokeos.learnpath
  30. ==============================================================================
  31. */
  32. /*
  33. ==============================================================================
  34. INIT SECTION
  35. ==============================================================================
  36. */
  37. // setting the language file
  38. //$langFile = "learnpath";
  39. //require_once('back_compat.inc.php');
  40. $this_section=SECTION_COURSES;
  41. api_protect_course_script();
  42. /*
  43. -----------------------------------------------------------
  44. Libraries
  45. -----------------------------------------------------------
  46. */
  47. //the main_api.lib.php, database.lib.php and display.lib.php
  48. //libraries are included by default
  49. include('learnpath_functions.inc.php');
  50. //include('../resourcelinker/resourcelinker.inc.php');
  51. include('resourcelinker.inc.php');
  52. //rewrite the language file, sadly overwritten by resourcelinker.inc.php
  53. $langFile = "learnpath";
  54. /*
  55. -----------------------------------------------------------
  56. Header and action code
  57. -----------------------------------------------------------
  58. */
  59. $htmlHeadXtra[] = "<link rel='stylesheet' type='text/css' href='../css/learnpath.css' />";
  60. /*
  61. -----------------------------------------------------------
  62. Constants and variables
  63. -----------------------------------------------------------
  64. */
  65. $is_allowed_to_edit = api_is_allowed_to_edit();
  66. $tbl_lp = Database::get_course_table('lp');
  67. $tbl_lp_item = Database::get_course_table('lp_item');
  68. $tbl_lp_view = Database::get_course_table('lp_view');
  69. $isStudentView = (int) $_REQUEST['isStudentView'];
  70. $learnpath_id = (int) $_REQUEST['lp_id'];
  71. $submit = $_POST['submit_button'];
  72. /*
  73. $chapter_id = $_GET['chapter_id'];
  74. $title = $_POST['title'];
  75. $description = $_POST['description'];
  76. $Submititem = $_POST['Submititem'];
  77. $action = $_REQUEST['action'];
  78. $id = (int) $_REQUEST['id'];
  79. $type = $_REQUEST['type'];
  80. $direction = $_REQUEST['direction'];
  81. $moduleid = $_REQUEST['moduleid'];
  82. $prereq = $_REQUEST['prereq'];
  83. $type = $_REQUEST['type'];
  84. */
  85. /*
  86. ==============================================================================
  87. MAIN CODE
  88. ==============================================================================
  89. */
  90. // using the resource linker as a tool for adding resources to the learning path
  91. if ($action=="add" and $type=="learnpathitem")
  92. {
  93. $htmlHeadXtra[] = "<script language='JavaScript' type='text/javascript'> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
  94. }
  95. if ( (! $is_allowed_to_edit) or ($isStudentView) )
  96. {
  97. error_log('New LP - User not authorized in lp_admin_view.php');
  98. header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
  99. }
  100. //from here on, we are admin because of the previous condition, so don't check anymore
  101. $sql_query = "SELECT * FROM $tbl_lp WHERE id = $learnpath_id";
  102. $result=api_sql_query($sql_query);
  103. $therow=Database::fetch_array($result);
  104. $admin_output = '';
  105. /*
  106. -----------------------------------------------------------
  107. Course admin section
  108. - all the functions not available for students - always available in this case (page only shown to admin)
  109. -----------------------------------------------------------
  110. */
  111. /*==================================================
  112. SHOWING THE ADMIN TOOLS
  113. ==================================================*/
  114. //Preparing the form to add a new module
  115. $add_module_form = '
  116. <form name="form1" method="post" action="lp_controller">
  117. <input type="hidden" name="action" value="add_item">
  118. <input type="hidden" name="lp_id" value="'.$learnpath_id.'">
  119. <input type="hidden" name="parent" value="0">
  120. <input type="hidden" name="previous" value="-1">
  121. <input type="hidden" name="type" value="dokeos_module">
  122. <input type="hidden" name="path" value="">
  123. <h4>'.get_lang('_add_learnpath_module').'</h4>
  124. <table width="400" border="0" cellspacing="2" cellpadding="0">
  125. <tr>
  126. <td align="right">'.get_lang('_title').'</td>
  127. <td><input name="title" type="text" value="" size="50"></td>
  128. </tr>
  129. <tr>
  130. <td align="right">&nbsp;</td>
  131. <td><input type="submit" name="submit_button" value="'.get_lang('Ok').'"></td>
  132. </tr>
  133. </table>
  134. </form>';
  135. if (($_REQUEST['action']=="add_item" and $type=="dokeos_module" and !$submit))
  136. {
  137. //this is when the user has selected the "add module" link previously, so we don't display it this time
  138. }
  139. else
  140. {
  141. //in case the user hasn't selected the "add module" link previously, first quick-check the database to remove the
  142. //useless step of asking the user to click on "add module" if the only possible action is to add a module
  143. $sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $learnpath_id AND item_type = 'dokeos_module'";
  144. $result=api_sql_query($sql,__FILE__,__LINE__);
  145. if (Database::num_rows($result) <= 0)
  146. {
  147. $admin_output .= "<br />There is no main chapter at the moment. Please add one using the following form. This is a required step in the learning path building process.<br />";
  148. $admin_output .= $add_module_form;
  149. }else{
  150. $admin_output .= "<ul>\n";
  151. $admin_output .= "<li><a href='lp_controller.php?action=add_item&lp_id=$learnpath_id&type=dokeos_module&parent=0&previous=-1&path='>" . get_lang("_add_learnpath_module") . "</a></li>\n";
  152. $admin_output .= "</ul>\n\n";
  153. }
  154. }
  155. /*==================================================
  156. EDITING A LEARNPATH ITEM: showing one of the forms
  157. ==================================================*/
  158. if ($_REQUEST['action']=="edititem" and !empty($_REQUEST['id']) AND empty($_REQUEST['submit_item']))
  159. {
  160. error_log('New LP - edit_item action in lp_admin_view',0);
  161. $id = (int) $_REQUEST['id'];
  162. $sql="SELECT * FROM $tbl_lp_item WHERE id=$id";
  163. $result=api_sql_query($sql,__FILE__,__LINE__);
  164. $row=Database::fetch_array($result);
  165. $id=$row['id'];
  166. $title = $row['title'];
  167. if(empty($title)){
  168. $title = rl_get_resource_name(api_get_course_id(),$learnpath_id,$_REQUEST['id']);
  169. }
  170. $admin_output .= '<h4>'.get_lang('_edit_learnpath_item').'</h4>
  171. <form name="edititem" method="post" action="">
  172. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  173. <input type="hidden" name="action" value="edititem">
  174. <tr>
  175. <td align="right" valign="top">'.get_lang('_title').'</td>
  176. <td><input name="title" type="text" id="title3" size="50" value="'.$title.'"></td>
  177. </tr>';
  178. //<tr>
  179. // <td align="right" valign="top">'.get_lang('_description').'</td>
  180. // <td><textarea name="description" cols="45" id="textarea">'.$row["description"].'</textarea></td>
  181. //</tr>
  182. $admin_output .= ' <tr>
  183. <td align="right" valign="top">&nbsp;</td>
  184. <td><input name="submit_item" type="submit" id="Submititem" value="'.get_lang('Ok').'"></td>
  185. </tr>
  186. </table>
  187. </form>';
  188. }
  189. /*==================================================
  190. prerequisites setting start
  191. ==================================================*/
  192. if ($_REQUEST['action']=="edititemprereq" and !empty($_REQUEST['id']) AND empty($_REQUEST['submit_item']))
  193. {
  194. $id = (int) $_REQUEST['id'];
  195. $sql="SELECT * FROM $tbl_lp_item WHERE id=$id";
  196. $result=api_sql_query($sql,__FILE__,__LINE__);
  197. $row=Database::fetch_array($result);
  198. $id=$row['id'];
  199. $title = $row['title'];
  200. if(empty($title)){
  201. $title = rl_get_resource_name(api_get_course_id(), $learnpath_id, $id);
  202. }
  203. $admin_output .= "<h4>";
  204. $admin_output .= get_lang('_add_prereq')." : ";
  205. $admin_output .= $title;
  206. $admin_output .= '</h4>
  207. <form name="edititemprereq" method="post" action="">
  208. <input type="hidden" name="action" value="edititemprereq">
  209. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  210. <tr>
  211. <td align="right" valign="top"></td>
  212. <td><table border="0" cellspacing="1" cellpadding="0">';
  213. //$learnpath_items = learnpath_items($id); the LP object should be available here
  214. $learnpath_items = learnpath::get_brother_items($id);
  215. //if there is any test before the current item, we show the completion limit column
  216. //TODO
  217. //This section has been made inactive for now because it should use the prerequisite's
  218. //mastery score as a limit. Also, this script should instead use the new prerequisites
  219. //language from AICC (see wiki), so it should actually be completely different
  220. /*
  221. $teststhere = false;
  222. for ($i=0; $i<count($learnpath_items); $i++)
  223. {
  224. if ((($learnpath_items[$i]["item_type"]==TOOL_QUIZ)
  225. or ($learnpath_items[$i]["item_type"]=='HotPotatoes'))
  226. and ($row["display_order"] > $learnpath_items[$i]["display_order"]))
  227. {
  228. $teststhere = true;
  229. }
  230. }
  231. if ($teststhere)
  232. {
  233. $admin_output .= "<tr><td colspan='2'></td><td>".get_lang('CompletionLimit')."</td></tr>";
  234. }
  235. */
  236. $checked='';
  237. if (empty($row["prerequisite"])) { $checked = 'checked'; }
  238. $admin_output .= "<tr><td><input class=\"checkbox\" type=\"radio\" name=\"prereq\" value=\"\" $checked></td><td>- ".get_lang('_none')." -</td></tr>";
  239. for ($i=0; $i<count($learnpath_items); $i++)
  240. {
  241. if ($row["display_order"] > $learnpath_items[$i]["display_order"])
  242. {
  243. /*
  244. $testrow = false;
  245. if (($learnpath_items[$i]["item_type"]==TOOL_QUIZ)
  246. or ($learnpath_items[$i]["item_type"]=='HotPotatoes'))
  247. {
  248. $testrow = true;
  249. }
  250. */
  251. $checked = '';
  252. if ($row["prerequisite"]==$learnpath_items[$i]["id"])
  253. {
  254. $checked='checked';
  255. }
  256. $admin_output .= '<tr><td><input class="checkbox" type="radio" name="prereq" value="'.$learnpath_items[$i]['id'].'" '.$checked.' ></td><td>';
  257. $admin_output .= rl_get_resource_name(api_get_course_id(), $learnpath_id, $learnpath_items[$i]['id']);
  258. $admin_output .= "</td>";
  259. /*
  260. if ($testrow)
  261. {
  262. //if (!$checked) { $disabled='disabled'; }
  263. $admin_output .= "<td align=center><input type=text name='completion_limit[{$learnpath_items[$i]['id']}]' size=4 maxlength=20 $disabled value=$completion_limit></td>";
  264. }
  265. */
  266. $admin_output .= "</tr>";
  267. }
  268. }
  269. $learnpath_chapters = learnpath::get_brother_chapters($row['parent_item_id']);
  270. $c=$row['parent_item_id']; //we are now in this chapter
  271. $sql="SELECT * FROM $tbl_lp_item WHERE id=$c AND item_type='dokeos_module'";
  272. $result=api_sql_query($sql,__FILE__,__LINE__);
  273. $row_chapter=Database::fetch_array($result);
  274. for ($i=0; $i<count($learnpath_chapters); $i++)
  275. {
  276. if ($row_chapter["display_order"] > $learnpath_chapters[$i]["display_order"])
  277. {
  278. $checked='';
  279. if (($row["prereq_id"]==$learnpath_chapters[$i]["id"]) and ($row["prereq_type"]=='c')) { $checked='checked'; }
  280. $admin_output .= "<tr><td bgcolor='#cccccc'><input type='radio' name='prereq' value='".$learnpath_chapters[$i]["id"]."' $checked ></td><td bgcolor='#cccccc'>".$learnpath_chapters[$i]['title']."</td></tr>";
  281. }
  282. }
  283. $admin_output .= '
  284. </table></td>
  285. </tr>
  286. <tr>
  287. <td align="right" valign="top">&nbsp;</td>
  288. <td><input name="submit_item" type="submit" id="Submititem" value="'.get_lang('Ok').'"></td>
  289. </tr>
  290. </table>
  291. </form>';
  292. }
  293. /*==================================================
  294. prerequisites setting end
  295. ==================================================*/
  296. /*==================================================
  297. EDITING / ADDING A NEW LEARNPATH chapter: showing the form
  298. ==================================================*/
  299. if (($_REQUEST['action']=="add_item"))
  300. // and $type=="learnpathcategory") or $action=="editmodule")
  301. {
  302. if (!$submit)
  303. {
  304. /*
  305. if ($action=="editmodule")
  306. {
  307. $sql="SELECT * FROM $tbl_lp_item WHERE (id='$id' and lp_id=$learnpath_id AND item_type='dokeos_chapter')";
  308. $result=api_sql_query($sql,__FILE__,__LINE__);
  309. $row=Database::fetch_array($result);
  310. }
  311. */
  312. $admin_output .= '
  313. <form name="form1" method="post" action="">
  314. <h4>';
  315. if ($action=="add")
  316. { $admin_output .= get_lang('_add_learnpath_module'); }
  317. else
  318. { $admin_output .= get_lang('_edit_learnpath_module'); }
  319. $admin_output .= '
  320. </h4>
  321. <table width="400" border="0" cellspacing="2" cellpadding="0">
  322. <tr>
  323. <td align="right">'.get_lang('_title').'</td>
  324. <td><input name="title" type="text" value="'.$row["chapter_name"].'" size="50"></td>
  325. </tr>';
  326. if ( $action=='editmodule' )
  327. {
  328. // on edition, allow the user to modify the description (if he really wants it)
  329. $admin_output .= '<tr>
  330. <td align="right" valign="top">'.get_lang('_description').'</td>'
  331. .'<td><textarea name="description" cols="45">'.$row["chapter_description"].'</textarea></td>'
  332. .'</tr>';
  333. }else
  334. {
  335. //on addition, only give a title field, so ignore the description field
  336. $admin_output .= "<input type='hidden' name='description' value='' />";
  337. }
  338. $admin_output .= '
  339. <tr>
  340. <td align="right">&nbsp;</td>
  341. <td><input type="submit" name="submit_button" value="'.get_lang('Ok').'"></td>
  342. </tr>
  343. </table>
  344. </form>';
  345. } // if (!$submit)
  346. } // if ($action=="add" and $type=="learnpathcategory")
  347. $interbreadcrumb[]= array ("url"=>"lp_controller.php?action=list", "name"=> get_lang("_learning_path"));
  348. $interbreadcrumb[]= array ("url"=>$_SERVER['PHP_SELF']."?action=admin_view&lp_id=$learnpath_id", "name" => stripslashes("{$therow['name']}"));
  349. Display::display_header(null,'Path');
  350. //api_display_tool_title($therow['name']);
  351. $suredel = get_lang('AreYouSureToDelete');
  352. $suredelstep = get_lang('AreYouSureToDeleteSteps');
  353. ?>
  354. <script type='text/javascript'>
  355. /* <![CDATA[ */
  356. function confirmation (name)
  357. {
  358. if (name!='Users' && name!='Assignments' && name!='Document' && name!='Forum' && name!='Agenda' && name!='Groups' && name!='Link _self' && name!='Dropbox' && name!='Course_description' && name!='Exercise' && name!='Introduction_text')
  359. {
  360. if (confirm("<?php echo $suredel; ?> "+ name + " <?php echo $suredelstep;?>?"))
  361. {return true;}
  362. else
  363. {return false;}
  364. }
  365. else
  366. {
  367. if (confirm("<?php echo $suredel; ?> "+ name + "?"))
  368. {return true;}
  369. else
  370. {return false;}
  371. }
  372. }
  373. </script>
  374. <?php
  375. echo $admin_output;
  376. /*
  377. -----------------------------------------------------------
  378. DISPLAY SECTION
  379. -----------------------------------------------------------
  380. */
  381. ?>
  382. <table border="0" cellspacing="0" cellpadding="1" width="100%" class="data_table">
  383. <tr>
  384. <td colspan='8'>
  385. </td>
  386. </tr>
  387. <?php
  388. display_learnpath_chapters();
  389. echo "</table>";
  390. $learnpath_has_chapters = learnpath_chapters($learnpath_id);
  391. if ($learnpath_has_chapters)
  392. {
  393. echo "<br /><br /><font color='#999999' size='1'>".get_lang('_short_help')."</font>";
  394. }
  395. /*
  396. ==============================================================================
  397. FOOTER
  398. ==============================================================================
  399. */
  400. Display::display_footer();
  401. ?>