lp_controller.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. <?php //$id: $
  2. /**
  3. * Controller script. Prepares the common background variables to give to the scripts corresponding to
  4. * the requested action
  5. * @package dokeos.learnpath
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. */
  8. /**
  9. * Initialisations
  10. */
  11. $debug = 0;
  12. if($debug>0) error_log('New LP -+- Entered lp_controller.php -+-',0);
  13. // name of the language file that needs to be included
  14. if($_GET['action'] == 'export')
  15. { //only needed on export
  16. $language_file[] = 'hotspot';
  17. $language_file[] = 'exercice';
  18. }
  19. $language_file[] = "course_home";
  20. $language_file[] = "scormdocument";
  21. $language_file[] = "scorm";
  22. $language_file[] = "learnpath";
  23. //flag to allow for anonymous user - needs to be set before global.inc.php
  24. $use_anonymous = true;
  25. //include class definitions before session_start() to ensure availability when touching
  26. //session vars containing learning paths
  27. require_once('learnpath.class.php');
  28. if($debug>0) error_log('New LP - Included learnpath',0);
  29. require_once('learnpathItem.class.php');
  30. if($debug>0) error_log('New LP - Included learnpathItem',0);
  31. require_once('scorm.class.php');
  32. if($debug>0) error_log('New LP - Included scorm',0);
  33. require_once('scormItem.class.php');
  34. if($debug>0) error_log('New LP - Included scormItem',0);
  35. require_once('aicc.class.php');
  36. if($debug>0) error_log('New LP - Included aicc',0);
  37. require_once('aiccItem.class.php');
  38. if($debug>0) error_log('New LP - Included aiccItem',0);
  39. require_once('back_compat.inc.php');
  40. if($debug>0) error_log('New LP - Included back_compat',0);
  41. if ($is_allowed_in_course == false){
  42. api_not_allowed(true);
  43. }
  44. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  45. $lpfound = false;
  46. $myrefresh = 0;
  47. $myrefresh_id = 0;
  48. if(!empty($_SESSION['refresh']) && $_SESSION['refresh']==1){
  49. //check if we should do a refresh of the oLP object (for example after editing the LP)
  50. //if refresh is set, we regenerate the oLP object from the database (kind of flush)
  51. api_session_unregister('refresh');
  52. $myrefresh = 1;
  53. if($debug>0) error_log('New LP - Refresh asked',0);
  54. }
  55. if($debug>0) error_log('New LP - Passed refresh check',0);
  56. if(!empty($_REQUEST['dialog_box'])){
  57. $dialog_box = stripslashes(urldecode($_REQUEST['dialog_box']));
  58. }
  59. $lp_controller_touched = 1;
  60. if(isset($_SESSION['lpobject']))
  61. {
  62. if($debug>0) error_log('New LP - SESSION[lpobject] is defined',0);
  63. $oLP = unserialize($_SESSION['lpobject']);
  64. if(is_object($oLP)){
  65. if($debug>0) error_log('New LP - oLP is object',0);
  66. if($myrefresh == 1 OR $oLP->cc != api_get_course_id()){
  67. if($debug>0) error_log('New LP - Course has changed, discard lp object',0);
  68. if($myrefresh == 1){$myrefresh_id = $oLP->get_id();}
  69. $oLP = null;
  70. api_session_unregister('oLP');
  71. api_session_unregister('lpobject');
  72. }else{
  73. $_SESSION['oLP'] = $oLP;
  74. $lp_found = true;
  75. }
  76. }
  77. }
  78. if($debug>0) error_log('New LP - Passed data remains check',0);
  79. if($lp_found == false
  80. || ($_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])
  81. )
  82. {
  83. if($debug>0) error_log('New LP - oLP is not object, has changed or refresh been asked, getting new',0);
  84. //regenerate a new lp object? Not always as some pages don't need the object (like upload?)
  85. if(!empty($_REQUEST['lp_id']) || !empty($myrefresh_id)){
  86. if($debug>0) error_log('New LP - lp_id is defined',0);
  87. //select the lp in the database and check which type it is (scorm/dokeos/aicc) to generate the
  88. //right object
  89. $lp_table = Database::get_course_table('lp');
  90. if(!empty($_REQUEST['lp_id'])){
  91. $lp_id = learnpath::escape_string($_REQUEST['lp_id']);
  92. }else{
  93. $lp_id = $myrefresh_id;
  94. }
  95. $sel = "SELECT * FROM $lp_table WHERE id = $lp_id";
  96. if($debug>0) error_log('New LP - querying '.$sel,0);
  97. $res = api_sql_query($sel);
  98. if(Database::num_rows($res))
  99. {
  100. $row = Database::fetch_array($res);
  101. $type = $row['lp_type'];
  102. if($debug>0) error_log('New LP - found row - type '.$type. ' - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(),0);
  103. switch($type){
  104. case 1:
  105. if($debug>0) error_log('New LP - found row - type dokeos - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(),0);
  106. $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
  107. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  108. break;
  109. case 2:
  110. if($debug>0) error_log('New LP - found row - type scorm - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(),0);
  111. $oLP = new scorm(api_get_course_id(),$lp_id,api_get_user_id());
  112. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  113. break;
  114. case 3:
  115. if($debug>0) error_log('New LP - found row - type aicc - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(),0);
  116. $oLP = new aicc(api_get_course_id(),$lp_id,api_get_user_id());
  117. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  118. break;
  119. default:
  120. if($debug>0) error_log('New LP - found row - type other - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(),0);
  121. $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
  122. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  123. break;
  124. }
  125. }
  126. }else{
  127. if($debug>0) error_log('New LP - Request[lp_id] and refresh_id were empty',0);
  128. }
  129. if($lp_found)
  130. {
  131. $_SESSION['oLP'] = $oLP;
  132. }
  133. }
  134. if($debug>0) error_log('New LP - Passed oLP creation check',0);
  135. /**
  136. * Actions switching
  137. */
  138. $_SESSION['oLP']->update_queue = array(); //reinitialises array used by javascript to update items in the TOC
  139. $_SESSION['oLP']->message = ''; //should use ->clear_message() method but doesn't work
  140. $fck_attribute['Width'] = '100%';
  141. $fck_attribute['Height'] = '950';
  142. $fck_attribute['ToolbarSet'] = 'Full';
  143. $fck_attribute['Config']['FullPage'] = true;
  144. if($_GET['isStudentView'] == 'true')
  145. {
  146. if($_REQUEST['action'] != 'list' AND $_REQUEST['action'] != 'view')
  147. {
  148. if(!empty($_REQUEST['lp_id']))
  149. {
  150. $_REQUEST['action'] = 'view';
  151. }
  152. else
  153. {
  154. $_REQUEST['action'] = 'list';
  155. }
  156. }
  157. }
  158. switch($_REQUEST['action'])
  159. {
  160. case 'add_item':
  161. if(!api_is_allowed_to_edit()){
  162. api_not_allowed(true);
  163. }
  164. if($debug > 0) error_log('New LP - add item action triggered', 0);
  165. if(!$lp_found)
  166. { //check if the learnpath ID was defined, otherwise send back to list
  167. error_log('New LP - No learnpath given for add item', 0);
  168. require('lp_list.php');
  169. }
  170. else
  171. {
  172. $_SESSION['refresh'] = 1;
  173. if(isset($_POST['submit_button']) && !empty($_POST['title']))
  174. { //if a title was sumbitted
  175. if(isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time'])
  176. { //check post_time to ensure ??? (counter-hacking measure?)
  177. require('lp_add_item.php');
  178. }
  179. else
  180. {
  181. $_SESSION['post_time'] = $_POST['post_time'];
  182. if($_POST['type'] == TOOL_DOCUMENT)
  183. {
  184. if(isset($_POST['path']) && $_GET['edit'] != 'true')
  185. {
  186. $document_id = $_POST['path'];
  187. }
  188. else
  189. {
  190. $document_id = $_SESSION['oLP']->create_document($_course);
  191. }
  192. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $document_id, $_POST['title'], $_POST['description'], $_POST['prerequisites']);
  193. }
  194. else
  195. { //for all other item types than documents, load the item using the item type and path rather than its ID
  196. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $_POST['path'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
  197. }
  198. //display
  199. require('lp_add_item.php');
  200. }
  201. }
  202. else
  203. {
  204. require('lp_add_item.php');
  205. }
  206. }
  207. break;
  208. case 'add_lp':
  209. if(!api_is_allowed_to_edit()){
  210. api_not_allowed(true);
  211. }
  212. if($debug > 0) error_log('New LP - add_lp action triggered', 0);
  213. $_REQUEST['learnpath_name'] = trim($_REQUEST['learnpath_name']);
  214. if(!empty($_REQUEST['learnpath_name']))
  215. {
  216. $_SESSION['refresh'] = 1;
  217. if(isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time'])
  218. {
  219. require('lp_add.php');
  220. }
  221. else
  222. {
  223. $_SESSION['post_time'] = $_REQUEST['post_time'];
  224. //Kevin Van Den Haute: changed $_REQUEST['learnpath_description'] by '' because it's not used
  225. //old->$new_lp_id = learnpath::add_lp(api_get_course_id(), $_REQUEST['learnpath_name'], $_REQUEST['learnpath_description'], 'dokeos', 'manual', '');
  226. $new_lp_id = learnpath::add_lp(api_get_course_id(), $_REQUEST['learnpath_name'], '', 'dokeos', 'manual', '');
  227. //learnpath::toggle_visibility($new_lp_id,'v');
  228. //Kevin Van Den Haute: only go further if learnpath::add_lp has returned an id
  229. if(is_numeric($new_lp_id))
  230. {
  231. //TODO maybe create a first module directly to avoid bugging the user with useless queries
  232. $_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
  233. //$_SESSION['oLP']->add_item(0,-1,'dokeos_chapter',$_REQUEST['path'],'Default');
  234. require('lp_build.php');
  235. }
  236. }
  237. }
  238. else
  239. require('lp_add.php');
  240. break;
  241. case 'admin_view':
  242. if(!api_is_allowed_to_edit()){
  243. api_not_allowed(true);
  244. }
  245. if($debug>0) error_log('New LP - admin_view action triggered',0);
  246. if(!$lp_found){ error_log('New LP - No learnpath given for admin_view', 0); require('lp_list.php'); }
  247. else
  248. {
  249. $_SESSION['refresh'] = 1;
  250. require('lp_admin_view.php');
  251. }
  252. break;
  253. case 'build':
  254. if(!api_is_allowed_to_edit()){
  255. api_not_allowed(true);
  256. }
  257. if($debug > 0) error_log('New LP - build action triggered', 0);
  258. if(!$lp_found){ error_log('New LP - No learnpath given for build', 0); require('lp_list.php'); }
  259. else
  260. {
  261. $_SESSION['refresh'] = 1;
  262. require('lp_build.php');
  263. }
  264. break;
  265. case 'delete_item':
  266. if(!api_is_allowed_to_edit()){
  267. api_not_allowed(true);
  268. }
  269. if($debug > 0) error_log('New LP - delete item action triggered', 0);
  270. if(!$lp_found){ error_log('New LP - No learnpath given for delete item', 0); require('lp_list.php'); }
  271. else
  272. {
  273. $_SESSION['refresh'] = 1;
  274. if(is_numeric($_GET['id']))
  275. {
  276. $_SESSION['oLP']->delete_item($_GET['id']);
  277. $is_success = true;
  278. }
  279. if(isset($_GET['view']) && $_GET['view'] == 'build')
  280. {
  281. require('lp_build.php');
  282. }
  283. else
  284. {
  285. require('lp_admin_view.php');
  286. }
  287. }
  288. break;
  289. case 'edit_item':
  290. if(!api_is_allowed_to_edit()){
  291. api_not_allowed(true);
  292. }
  293. if($debug > 0) error_log('New LP - edit item action triggered', 0);
  294. if(!$lp_found){ error_log('New LP - No learnpath given for edit item', 0); require('lp_list.php'); }
  295. else
  296. {
  297. $_SESSION['refresh'] = 1;
  298. if(isset($_POST['submit_button']) && !empty($_POST['title']))
  299. {
  300. $_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
  301. if(isset($_POST['content_lp']))
  302. {
  303. $_SESSION['oLP']->edit_document($_course);
  304. }
  305. $is_success = true;
  306. }
  307. if(isset($_GET['view']) && $_GET['view'] == 'build')
  308. {
  309. require('lp_edit_item.php');
  310. }
  311. else
  312. {
  313. require('lp_admin_view.php');
  314. }
  315. }
  316. break;
  317. case 'edit_item_prereq':
  318. if(!api_is_allowed_to_edit()){
  319. api_not_allowed(true);
  320. }
  321. if($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  322. if(!$lp_found){ error_log('New LP - No learnpath given for edit item prereq', 0); require('lp_list.php'); }
  323. else
  324. {
  325. if(isset($_POST['submit_button']))
  326. {
  327. $_SESSION['refresh'] = 1;
  328. $_SESSION['oLP']->edit_item_prereq($_GET['id'], $_POST['prerequisites'], $_POST['min_' . $_POST['prerequisites']], $_POST['max_' . $_POST['prerequisites']]);
  329. }
  330. require('lp_edit_item_prereq.php');
  331. }
  332. break;
  333. case 'move_item':
  334. if(!api_is_allowed_to_edit()){
  335. api_not_allowed(true);
  336. }
  337. if($debug > 0) error_log('New LP - move item action triggered', 0);
  338. if(!$lp_found){ error_log('New LP - No learnpath given for move item', 0); require('lp_list.php'); }
  339. else
  340. {
  341. $_SESSION['refresh'] = 1;
  342. if(isset($_POST['submit_button']))
  343. {
  344. $_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description']);
  345. $is_success = true;
  346. }
  347. if(isset($_GET['view']) && $_GET['view'] == 'build')
  348. {
  349. require('lp_move_item.php');
  350. }
  351. else
  352. {
  353. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  354. require('lp_admin_view.php');
  355. }
  356. }
  357. break;
  358. case 'view_item':
  359. if(!api_is_allowed_to_edit()){
  360. api_not_allowed(true);
  361. }
  362. if($debug>0) error_log('New LP - view_item action triggered', 0);
  363. if(!$lp_found){ error_log('New LP - No learnpath given for view item', 0); require('lp_list.php'); }
  364. else
  365. {
  366. $_SESSION['refresh'] = 1;
  367. require('lp_view_item.php');
  368. }
  369. break;
  370. case 'upload':
  371. if(!api_is_allowed_to_edit()){
  372. api_not_allowed(true);
  373. }
  374. if($debug>0) error_log('New LP - upload action triggered',0);
  375. $cwdir = getcwd();
  376. require('lp_upload.php');
  377. //reinit current working directory as many functions in upload change it
  378. chdir($cwdir);
  379. require('lp_list.php');
  380. break;
  381. case 'export':
  382. if(!api_is_allowed_to_edit()){
  383. api_not_allowed(true);
  384. }
  385. if($debug>0) error_log('New LP - export action triggered',0);
  386. if(!$lp_found){ error_log('New LP - No learnpath given for export',0); require('lp_list.php'); }
  387. else{
  388. $_SESSION['oLP']->scorm_export();
  389. exit();
  390. //require('lp_list.php');
  391. }
  392. break;
  393. case 'delete':
  394. if(!api_is_allowed_to_edit()){
  395. api_not_allowed(true);
  396. }
  397. if($debug>0) error_log('New LP - delete action triggered',0);
  398. if(!$lp_found){ error_log('New LP - No learnpath given for delete',0); require('lp_list.php'); }
  399. else{
  400. $_SESSION['refresh'] = 1;
  401. //remove lp from homepage if it is there
  402. //$_SESSION['oLP']->toggle_visibility((int)$_GET['lp_id'],'i');
  403. $_SESSION['oLP']->delete(null,(int)$_GET['lp_id'],'remove');
  404. api_session_unregister('oLP');
  405. require('lp_list.php');
  406. }
  407. break;
  408. case 'toggle_visible': //change lp visibility (inside lp tool)
  409. if(!api_is_allowed_to_edit()){
  410. api_not_allowed(true);
  411. }
  412. if($debug>0) error_log('New LP - visibility action triggered',0);
  413. if(!$lp_found){ error_log('New LP - No learnpath given for visibility',0); require('lp_list.php'); }
  414. else{
  415. learnpath::toggle_visibility($_REQUEST['lp_id'],$_REQUEST['new_status']);
  416. require('lp_list.php');
  417. }
  418. break;
  419. case 'toggle_publish': //change lp published status (visibility on homepage)
  420. if(!api_is_allowed_to_edit()){
  421. api_not_allowed(true);
  422. }
  423. if($debug>0) error_log('New LP - publish action triggered',0);
  424. if(!$lp_found){ error_log('New LP - No learnpath given for publish',0); require('lp_list.php'); }
  425. else{
  426. learnpath::toggle_publish($_REQUEST['lp_id'],$_REQUEST['new_status']);
  427. require('lp_list.php');
  428. }
  429. break;
  430. case 'move_lp_up': //change lp published status (visibility on homepage)
  431. if(!api_is_allowed_to_edit()){
  432. api_not_allowed(true);
  433. }
  434. if($debug>0) error_log('New LP - publish action triggered',0);
  435. if(!$lp_found)
  436. {
  437. error_log('New LP - No learnpath given for publish',0);
  438. require('lp_list.php');
  439. }
  440. else
  441. {
  442. learnpath::move_up($_REQUEST['lp_id']);
  443. require('lp_list.php');
  444. }
  445. break;
  446. case 'move_lp_down': //change lp published status (visibility on homepage)
  447. if(!api_is_allowed_to_edit()){
  448. api_not_allowed(true);
  449. }
  450. if($debug>0) error_log('New LP - publish action triggered',0);
  451. if(!$lp_found){
  452. error_log('New LP - No learnpath given for publish',0);
  453. require('lp_list.php');
  454. }
  455. else
  456. {
  457. learnpath::move_down($_REQUEST['lp_id']);
  458. require('lp_list.php');
  459. }
  460. break;
  461. case 'edit':
  462. if(!api_is_allowed_to_edit())
  463. {
  464. api_not_allowed(true);
  465. }
  466. if($debug>0) error_log('New LP - edit action triggered',0);
  467. if(!$lp_found){ error_log('New LP - No learnpath given for edit',0); require('lp_list.php'); }
  468. else{
  469. $_SESSION['refresh'] = 1;
  470. require('lp_edit.php');
  471. }
  472. break;
  473. case 'update_lp':
  474. if(!api_is_allowed_to_edit()){
  475. api_not_allowed(true);
  476. }
  477. if($debug>0) error_log('New LP - update_lp action triggered',0);
  478. if(!$lp_found){ error_log('New LP - No learnpath given for edit',0); require('lp_list.php'); }
  479. else{
  480. $_SESSION['refresh'] = 1;
  481. $_SESSION['oLP']->set_name($_REQUEST['lp_name']);
  482. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  483. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  484. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  485. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  486. require('lp_list.php');
  487. }
  488. break;
  489. case 'add_sub_item': //add an item inside a chapter
  490. if(!api_is_allowed_to_edit()){
  491. api_not_allowed(true);
  492. }
  493. if($debug>0) error_log('New LP - add sub item action triggered',0);
  494. if(!$lp_found){ error_log('New LP - No learnpath given for add sub item',0); require('lp_list.php'); }
  495. else{
  496. $_SESSION['refresh'] = 1;
  497. if(!empty($_REQUEST['parent_item_id'])){
  498. $_SESSION['from_learnpath']='yes';
  499. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.$_REQUEST['lp_id'];
  500. require('resourcelinker.php');
  501. //$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'],$_REQUEST['previous'],$_REQUEST['type'],$_REQUEST['path'],$_REQUEST['title']);
  502. }else{
  503. require('lp_admin_view.php');
  504. }
  505. }
  506. break;
  507. case 'deleteitem':
  508. case 'delete_item':
  509. if(!api_is_allowed_to_edit()){
  510. api_not_allowed(true);
  511. }
  512. if($debug>0) error_log('New LP - delete item action triggered',0);
  513. if(!$lp_found){ error_log('New LP - No learnpath given for delete item',0); require('lp_list.php'); }
  514. else{
  515. $_SESSION['refresh'] = 1;
  516. if(!empty($_REQUEST['id'])){
  517. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  518. }
  519. require('lp_admin_view.php');
  520. }
  521. break;
  522. case 'edititemprereq':
  523. case 'edit_item_prereq':
  524. if(!api_is_allowed_to_edit()){
  525. api_not_allowed(true);
  526. }
  527. if($debug>0) error_log('New LP - edit item prereq action triggered',0);
  528. if(!$lp_found){ error_log('New LP - No learnpath given for edit item prereq',0); require('lp_list.php'); }
  529. else{
  530. if(!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])){
  531. $_SESSION['refresh'] = 1;
  532. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'],$_REQUEST['prereq']);
  533. }
  534. require('lp_admin_view.php');
  535. }
  536. break;
  537. case 'restart':
  538. if($debug>0) error_log('New LP - restart action triggered',0);
  539. if(!$lp_found){ error_log('New LP - No learnpath given for restart',0); require('lp_list.php'); }
  540. else{
  541. $_SESSION['oLP']->restart();
  542. require('lp_view.php');
  543. }
  544. break;
  545. case 'last':
  546. if($debug>0) error_log('New LP - last action triggered',0);
  547. if(!$lp_found){ error_log('New LP - No learnpath given for last',0); require('lp_list.php'); }
  548. else{
  549. $_SESSION['oLP']->last();
  550. require('lp_view.php');
  551. }
  552. break;
  553. case 'first':
  554. if($debug>0) error_log('New LP - first action triggered',0);
  555. if(!$lp_found){ error_log('New LP - No learnpath given for first',0); require('lp_list.php'); }
  556. else{
  557. $_SESSION['oLP']->first();
  558. require('lp_view.php');
  559. }
  560. break;
  561. case 'next':
  562. if($debug>0) error_log('New LP - next action triggered',0);
  563. if(!$lp_found){ error_log('New LP - No learnpath given for next',0); require('lp_list.php'); }
  564. else{
  565. $_SESSION['oLP']->next();
  566. require('lp_view.php');
  567. }
  568. break;
  569. case 'previous':
  570. if($debug>0) error_log('New LP - previous action triggered',0);
  571. if(!$lp_found){ error_log('New LP - No learnpath given for previous',0); require('lp_list.php'); }
  572. else{
  573. $_SESSION['oLP']->previous();
  574. require('lp_view.php');
  575. }
  576. break;
  577. case 'content':
  578. if($debug>0) error_log('New LP - content action triggered',0);
  579. if($debug>0) error_log('New LP - Item id is '.$_GET['item_id'],0);
  580. if(!$lp_found){ error_log('New LP - No learnpath given for content',0); require('lp_list.php'); }
  581. else{
  582. $_SESSION['oLP']->save_last();
  583. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  584. $_SESSION['oLP']->start_current_item();
  585. require('lp_content.php');
  586. }
  587. break;
  588. case 'view':
  589. if($debug > 0)
  590. error_log('New LP - view action triggered', 0);
  591. if(!$lp_found)
  592. {
  593. error_log('New LP - No learnpath given for view', 0);
  594. require('lp_list.php');
  595. }
  596. else
  597. {
  598. if($debug > 0){error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0);}
  599. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  600. require('lp_view.php');
  601. }
  602. break;
  603. case 'save':
  604. if($debug>0) error_log('New LP - save action triggered',0);
  605. if(!$lp_found){ error_log('New LP - No learnpath given for save',0); require('lp_list.php'); }
  606. else{
  607. $_SESSION['oLP']->save_item();
  608. require('lp_save.php');
  609. }
  610. break;
  611. case 'stats':
  612. if($debug>0) error_log('New LP - stats action triggered',0);
  613. if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require('lp_list.php'); }
  614. else{
  615. $_SESSION['oLP']->save_current();
  616. $_SESSION['oLP']->save_last();
  617. //declare variables to be used in lp_stats.php
  618. $lp_id = $_SESSION['oLP']->get_id();
  619. $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  620. $user_id = api_get_user_id();
  621. $stats_charset = $_SESSION['oLP']->encoding;
  622. require('lp_stats.php');
  623. }
  624. break;
  625. case 'list':
  626. if($debug>0) error_log('New LP - list action triggered',0);
  627. if($lp_found){
  628. $_SESSION['refresh'] = 1;
  629. $_SESSION['oLP']->save_last();
  630. }
  631. require('lp_list.php');
  632. break;
  633. case 'mode':
  634. //switch between fullscreen and embedded mode
  635. if($debug>0) error_log('New LP - mode change triggered',0);
  636. $mode = $_REQUEST['mode'];
  637. if($mode == 'fullscreen'){
  638. $_SESSION['oLP']->mode = 'fullscreen';
  639. }else{
  640. $_SESSION['oLP']->mode = 'embedded';
  641. }
  642. require('lp_view.php');
  643. break;
  644. case 'switch_view_mode':
  645. if($debug>0) error_log('New LP - switch_view_mode action triggered',0);
  646. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  647. $_SESSION['refresh'] = 1;
  648. $_SESSION['oLP']->update_default_view_mode();
  649. require('lp_list.php');
  650. break;
  651. case 'switch_force_commit':
  652. if($debug>0) error_log('New LP - switch_force_commit action triggered',0);
  653. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  654. $_SESSION['refresh'] = 1;
  655. $_SESSION['oLP']->update_default_scorm_commit();
  656. require('lp_list.php');
  657. break;
  658. case 'switch_reinit':
  659. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  660. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  661. $_SESSION['refresh'] = 1;
  662. $_SESSION['oLP']->update_reinit();
  663. require('lp_list.php');
  664. break;
  665. case 'switch_scorm_debug':
  666. if($debug>0) error_log('New LP - switch_scorm_debug action triggered',0);
  667. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  668. $_SESSION['refresh'] = 1;
  669. $_SESSION['oLP']->update_scorm_debug();
  670. require('lp_list.php');
  671. break;
  672. case 'intro_cmdAdd':
  673. if($debug>0) error_log('New LP - intro_cmdAdd action triggered',0);
  674. //add introduction section page
  675. break;
  676. case 'js_api_refresh':
  677. if($debug>0) error_log('New LP - js_api_refresh action triggered',0);
  678. if(!$lp_found){ error_log('New LP - No learnpath given for js_api_refresh',0); require('lp_message.php'); }
  679. if(isset($_REQUEST['item_id'])){
  680. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  681. }
  682. require('lp_message.php');
  683. break;
  684. default:
  685. if($debug>0) error_log('New LP - default action triggered',0);
  686. //$_SESSION['refresh'] = 1;
  687. require('lp_list.php');
  688. break;
  689. }
  690. if(!empty($_SESSION['oLP'])){
  691. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  692. if($debug>0) error_log('New LP - lpobject is serialized in session',0);
  693. }
  694. ?>