yannick_lp_controller.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. * @author Kevin Van Den Haute <kevin@develop-it.be>
  8. */
  9. /**
  10. * Initialisations
  11. */
  12. $debug = 0;
  13. if($debug>0) error_log('New LP -+- Entered lp_controller.php -+-',0);
  14. $langFile[] = "scormdocument";
  15. $langFile[] = "scorm";
  16. $langFile[] = "learnpath";
  17. //include class definitions before session_start() to ensure availability when touching
  18. //session vars containing learning paths
  19. require_once('learnpath.class.php');
  20. if($debug>0) error_log('New LP - Included learnpath',0);
  21. require_once('learnpathItem.class.php');
  22. if($debug>0) error_log('New LP - Included learnpathItem',0);
  23. require_once('scorm.class.php');
  24. if($debug>0) error_log('New LP - Included scorm',0);
  25. require_once('scormItem.class.php');
  26. if($debug>0) error_log('New LP - Included scormItem',0);
  27. require_once('aicc.class.php');
  28. if($debug>0) error_log('New LP - Included aicc',0);
  29. require_once('aiccItem.class.php');
  30. if($debug>0) error_log('New LP - Included aiccItem',0);
  31. require_once('temp.lib.php');
  32. if($debug>0) error_log('New LP - Included temp',0);
  33. require_once('back_compat.inc.php');
  34. if($debug>0) error_log('New LP - Included back_compat',0);
  35. api_protect_course_script();
  36. //TODO @TODO define tool, action and task to give as parameters to:
  37. //$is_allowed_to_edit = api_is_allowed_to_edit();
  38. if ($is_allowed_in_course == false){
  39. Display::display_header('');
  40. api_not_allowed();
  41. Display::display_footer();
  42. }
  43. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor.lib.php");
  44. $lpfound = false;
  45. $myrefresh = 0;
  46. $myrefresh_id = 0;
  47. if(!empty($_SESSION['refresh']) && $_SESSION['refresh']==1){
  48. //check if we should do a refresh of the oLP object (for example after editing the LP)
  49. //if refresh is set, we regenerate the oLP object from the database (kind of flush)
  50. api_session_unregister('refresh');
  51. $myrefresh = 1;
  52. if($debug>0) error_log('New LP - Refresh asked',0);
  53. }
  54. if($debug>0) error_log('New LP - Passed refresh check',0);
  55. if(!empty($_REQUEST['dialog_box'])){
  56. $dialog_box = learnpath::escape_string(urldecode($_REQUEST['dialog_box']));
  57. }
  58. $lp_controller_touched = 1;
  59. if(isset($_SESSION['lpobject']))
  60. {
  61. if($debug>0) error_log('New LP - SESSION[lpobject] is defined',0);
  62. $oLP = unserialize($_SESSION['lpobject']);
  63. if(is_object($oLP)){
  64. if($debug>0) error_log('New LP - oLP is object',0);
  65. if($myrefresh == 1 OR $oLP->cc != api_get_course_id()){
  66. if($debug>0) error_log('New LP - Course has changed, discard lp object',0);
  67. if($myrefresh == 1){$myrefresh_id = $oLP->get_id();}
  68. $oLP = null;
  69. api_session_unregister('oLP');
  70. api_session_unregister('lpobject');
  71. }else{
  72. $_SESSION['oLP'] = $oLP;
  73. $lp_found = true;
  74. }
  75. }
  76. }
  77. if($debug>0) error_log('New LP - Passed data remains check',0);
  78. if($lp_found == false
  79. || ($_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])
  80. )
  81. {
  82. if($debug>0) error_log('New LP - oLP is not object, has changed or refresh been asked, getting new',0);
  83. //regenerate a new lp object? Not always as some pages don't need the object (like upload?)
  84. if(!empty($_REQUEST['lp_id']) || !empty($myrefresh_id)){
  85. if($debug>0) error_log('New LP - lp_id is defined',0);
  86. //select the lp in the database and check which type it is (scorm/dokeos/aicc) to generate the
  87. //right object
  88. $lp_table = Database::get_course_table('lp');
  89. if(!empty($_REQUEST['lp_id'])){
  90. $lp_id = escape_txt($_REQUEST['lp_id']);
  91. }else{
  92. $lp_id = $myrefresh_id;
  93. }
  94. $sel = "SELECT * FROM $lp_table WHERE id = $lp_id";
  95. if($debug>0) error_log('New LP - querying '.$sel,0);
  96. $res = api_sql_query($sel);
  97. if(Database::num_rows($res))
  98. {
  99. $row = Database::fetch_array($res);
  100. $type = $row['lp_type'];
  101. 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);
  102. switch($type){
  103. case 1:
  104. $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
  105. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  106. break;
  107. case 2:
  108. $oLP = new scorm(api_get_course_id(),$lp_id,api_get_user_id());
  109. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  110. break;
  111. default:
  112. $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
  113. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  114. break;
  115. }
  116. }
  117. }else{
  118. if($debug>0) error_log('New LP - Request[lp_id] and refresh_id were empty',0);
  119. }
  120. if($lp_found)
  121. {
  122. $_SESSION['oLP'] = $oLP;
  123. }
  124. }
  125. if($debug>0) error_log('New LP - Passed oLP creation check',0);
  126. /**
  127. * Actions switching
  128. */
  129. $_SESSION['oLP']->update_queue = array(); //reinitialises array used by javascript to update items in the TOC
  130. $_SESSION['oLP']->message = ''; //should use ->clear_message() method but doesn't work
  131. switch($_REQUEST['action'])
  132. {
  133. case 'admin_view':
  134. if($debug>0) error_log('New LP - admin_view action triggered',0);
  135. $_SESSION['refresh'] = 1;
  136. require('lp_admin_view.php');
  137. break;
  138. case 'upload':
  139. if($debug>0) error_log('New LP - upload action triggered',0);
  140. $cwdir = getcwd();
  141. require('lp_upload.php');
  142. //reinit current working directory as many functions in upload change it
  143. chdir($cwdir);
  144. require('lp_list.php');
  145. break;
  146. case 'export':
  147. if($debug>0) error_log('New LP - export action triggered',0);
  148. if(!$lp_found){ error_log('New LP - No learnpath given for export',0); require('lp_list.php'); }
  149. else{
  150. if($_SESSION['oLP']->get_type()==2){
  151. $_SESSION['oLP']->export_zip();
  152. }
  153. //require('lp_list.php');
  154. }
  155. break;
  156. case 'delete':
  157. if($debug>0) error_log('New LP - delete action triggered',0);
  158. if(!$lp_found){ error_log('New LP - No learnpath given for delete',0); require('lp_list.php'); }
  159. else{
  160. $_SESSION['refresh'] = 1;
  161. $_SESSION['oLP']->delete(null,null,'remove');
  162. api_session_unregister('oLP');
  163. //require('lp_delete.php');
  164. require('lp_list.php');
  165. }
  166. break;
  167. case 'toggle_visible': //change lp visibility
  168. if($debug>0) error_log('New LP - publish action triggered',0);
  169. if(!$lp_found){ error_log('New LP - No learnpath given for publish',0); require('lp_list.php'); }
  170. else{
  171. learnpath::toggle_visibility($_REQUEST['lp_id'],$_REQUEST['new_status']);
  172. require('lp_list.php');
  173. }
  174. break;
  175. case 'edit':
  176. if($debug>0) error_log('New LP - edit action triggered',0);
  177. if(!$lp_found){ error_log('New LP - No learnpath given for edit',0); require('lp_list.php'); }
  178. else{
  179. $_SESSION['refresh'] = 1;
  180. require('lp_edit.php');
  181. //require('lp_admin_view.php');
  182. }
  183. break;
  184. case 'update_lp':
  185. if($debug>0) error_log('New LP - update_lp action triggered',0);
  186. if(!$lp_found){ error_log('New LP - No learnpath given for edit',0); require('lp_list.php'); }
  187. else{
  188. $_SESSION['refresh'] = 1;
  189. $_SESSION['oLP']->set_name($_REQUEST['lp_name']);
  190. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  191. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  192. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  193. require('lp_list.php');
  194. }
  195. break;
  196. case 'add_lp':
  197. if($debug>0) error_log('New LP - add_lp action triggered',0);
  198. //call learnpath creation abstract method with course_id, learnpath_name, learnpath_description, type_of_lp, origin_of_creation, file_name
  199. if(!empty($_REQUEST['learnpath_name'])){
  200. $_SESSION['refresh'] = 1;
  201. $new_lp_id = learnpath::add_lp(api_get_course_id(),$_REQUEST['learnpath_name'],$_REQUEST['learnpath_description'],'dokeos','manual','');
  202. //TODO maybe create a first module directly to avoid bugging the user with useless queries
  203. $_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
  204. $_SESSION['oLP']->add_item(0,-1,'dokeos_chapter',$_REQUEST['path'],'Default');
  205. }
  206. require('lp_list.php');
  207. break;
  208. case 'add_item':
  209. if($debug>0) error_log('New LP - add item action triggered',0);
  210. if(!$lp_found){ error_log('New LP - No learnpath given for add item',0); require('lp_list.php'); }
  211. else{
  212. $_SESSION['refresh'] = 1;
  213. if(!empty($_REQUEST['submit_button']) && !empty($_REQUEST['title'])){
  214. $_SESSION['oLP']->add_item($_REQUEST['parent'],$_REQUEST['previous'],$_REQUEST['type'],$_REQUEST['path'],$_REQUEST['title']);
  215. }
  216. require('lp_admin_view.php');
  217. }
  218. break;
  219. case 'add_module':
  220. if($debug > 0)
  221. error_log('New LP - add item action triggered', 0);
  222. if(!$lp_found)
  223. {
  224. error_log('New LP - No learnpath given for add item', 0);
  225. require('lp_list.php');
  226. }
  227. else
  228. {
  229. //$_SESSION['refresh'] = 1;
  230. if(isset($_POST['cmdSubmit']))
  231. {
  232. $_SESSION['oLP']->add_item(0, -1, 'dokeos_module', '', $_POST['txtTitle']);
  233. }
  234. require('lp_view.php');
  235. }
  236. break;
  237. case 'add_document':
  238. if($debug > 0)
  239. error_log('New LP - add item action triggered', 0);
  240. if(!$lp_found)
  241. {
  242. error_log('New LP - No learnpath given for add item', 0);
  243. require('lp_list.php');
  244. }
  245. else
  246. {
  247. //$_SESSION['refresh'] = 1;
  248. if(isset($_POST['cmdSubmit']))
  249. {
  250. $_SESSION['oLP']->add_item(0, -1, 'dokeos_document', '', $_POST['txtTitle']);
  251. }
  252. require('lp_view.php');
  253. }
  254. break;
  255. case 'add_sub_item': //add an item inside a chapter
  256. if($debug>0) error_log('New LP - add sub item action triggered',0);
  257. if(!$lp_found){ error_log('New LP - No learnpath given for add sub item',0); require('lp_list.php'); }
  258. else{
  259. $_SESSION['refresh'] = 1;
  260. if(!empty($_REQUEST['parent_item_id'])){
  261. $_SESSION['from_learnpath']='yes';
  262. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.$_REQUEST['lp_id'];
  263. require('resourcelinker.php');
  264. //$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'],$_REQUEST['previous'],$_REQUEST['type'],$_REQUEST['path'],$_REQUEST['title']);
  265. }else{
  266. require('lp_admin_view.php');
  267. }
  268. }
  269. break;
  270. case 'deleteitem':
  271. case 'delete_item':
  272. if($debug>0) error_log('New LP - delete item action triggered',0);
  273. if(!$lp_found){ error_log('New LP - No learnpath given for delete item',0); require('lp_list.php'); }
  274. else{
  275. $_SESSION['refresh'] = 1;
  276. if(!empty($_REQUEST['id'])){
  277. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  278. }
  279. require('lp_admin_view.php');
  280. }
  281. break;
  282. case 'edititem':
  283. case 'edit_item':
  284. if($debug>0) error_log('New LP - edit item action triggered',0);
  285. if(!$lp_found){ error_log('New LP - No learnpath given for edit item',0); require('lp_list.php'); }
  286. else{
  287. if(!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])){
  288. $_SESSION['refresh'] = 1;
  289. $_SESSION['oLP']->edit_item($_REQUEST['id'], $_REQUEST['title']);
  290. }
  291. require('lp_admin_view.php');
  292. }
  293. break;
  294. case 'edititemprereq':
  295. case 'edit_item_prereq':
  296. if($debug>0) error_log('New LP - edit item prereq action triggered',0);
  297. if(!$lp_found){ error_log('New LP - No learnpath given for edit item prereq',0); require('lp_list.php'); }
  298. else{
  299. if(!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])){
  300. $_SESSION['refresh'] = 1;
  301. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'],$_REQUEST['prereq']);
  302. }
  303. require('lp_admin_view.php');
  304. }
  305. break;
  306. case 'restart':
  307. if($debug>0) error_log('New LP - restart action triggered',0);
  308. if(!$lp_found){ error_log('New LP - No learnpath given for restart',0); require('lp_list.php'); }
  309. else{
  310. $_SESSION['oLP']->restart();
  311. require('lp_view.php');
  312. }
  313. break;
  314. case 'last':
  315. if($debug>0) error_log('New LP - last action triggered',0);
  316. if(!$lp_found){ error_log('New LP - No learnpath given for last',0); require('lp_list.php'); }
  317. else{
  318. $_SESSION['oLP']->last();
  319. require('lp_view.php');
  320. }
  321. break;
  322. case 'first':
  323. if($debug>0) error_log('New LP - first action triggered',0);
  324. if(!$lp_found){ error_log('New LP - No learnpath given for first',0); require('lp_list.php'); }
  325. else{
  326. $_SESSION['oLP']->first();
  327. require('lp_view.php');
  328. }
  329. break;
  330. case 'next':
  331. if($debug>0) error_log('New LP - next action triggered',0);
  332. if(!$lp_found){ error_log('New LP - No learnpath given for next',0); require('lp_list.php'); }
  333. else{
  334. $_SESSION['oLP']->next();
  335. require('lp_view.php');
  336. }
  337. break;
  338. case 'previous':
  339. if($debug>0) error_log('New LP - previous action triggered',0);
  340. if(!$lp_found){ error_log('New LP - No learnpath given for previous',0); require('lp_list.php'); }
  341. else{
  342. $_SESSION['oLP']->previous();
  343. require('lp_view.php');
  344. }
  345. break;
  346. case 'content':
  347. if($debug>0) error_log('New LP - content action triggered',0);
  348. if($debug>0) error_log('New LP - Item id is '.$_GET['item_id'],0);
  349. if(!$lp_found){ error_log('New LP - No learnpath given for content',0); require('lp_list.php'); }
  350. else{
  351. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  352. $_SESSION['oLP']->start_current_item();
  353. require('lp_content.php');
  354. }
  355. break;
  356. case 'view':
  357. if($debug > 0)
  358. error_log('New LP - view action triggered', 0);
  359. if(!$lp_found)
  360. {
  361. error_log('New LP - No learnpath given for view', 0);
  362. require('lp_list.php');
  363. }
  364. else
  365. {
  366. if($debug > 0)
  367. error_log('New LP - trying to set current item to ' . $_REQUEST['item_id'], 0);
  368. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  369. require('lp_view.php');
  370. }
  371. break;
  372. case 'save':
  373. if($debug>0) error_log('New LP - save action triggered',0);
  374. if(!$lp_found){ error_log('New LP - No learnpath given for save',0); require('lp_list.php'); }
  375. else{
  376. $_SESSION['oLP']->save_item();
  377. require('lp_save.php');
  378. }
  379. break;
  380. case 'stats':
  381. if($debug>0) error_log('New LP - stats action triggered',0);
  382. if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require('lp_list.php'); }
  383. else{
  384. $_SESSION['oLP']->save_current();
  385. $_SESSION['oLP']->save_last();
  386. require('lp_stats.php');
  387. }
  388. break;
  389. case 'list':
  390. if($debug>0) error_log('New LP - list action triggered',0);
  391. if($lp_found){
  392. $_SESSION['refresh'] = 1;
  393. $_SESSION['oLP']->save_last();
  394. }
  395. require('lp_list.php');
  396. break;
  397. case 'mode':
  398. //switch between fullscreen and embedded mode
  399. if($debug>0) error_log('New LP - mode change triggered',0);
  400. $mode = $_REQUEST['mode'];
  401. if($mode == 'fullscreen'){
  402. $_SESSION['oLP']->mode = 'fullscreen';
  403. }else{
  404. $_SESSION['oLP']->mode = 'embedded';
  405. }
  406. require('lp_view.php');
  407. break;
  408. case 'switch_view_mode':
  409. if($debug>0) error_log('New LP - switch_view_mode action triggered',0);
  410. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  411. $_SESSION['refresh'] = 1;
  412. $_SESSION['oLP']->update_default_view_mode();
  413. require('lp_list.php');
  414. break;
  415. case 'switch_force_commit':
  416. if($debug>0) error_log('New LP - switch_force_commit action triggered',0);
  417. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  418. $_SESSION['refresh'] = 1;
  419. $_SESSION['oLP']->update_default_scorm_commit();
  420. require('lp_list.php');
  421. break;
  422. case 'switch_reinit':
  423. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  424. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  425. $_SESSION['refresh'] = 1;
  426. $_SESSION['oLP']->update_reinit();
  427. require('lp_list.php');
  428. break;
  429. case 'switch_scorm_debug':
  430. if($debug>0) error_log('New LP - switch_scorm_debug action triggered',0);
  431. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  432. $_SESSION['refresh'] = 1;
  433. $_SESSION['oLP']->update_scorm_debug();
  434. require('lp_list.php');
  435. break;
  436. case 'intro_cmdAdd':
  437. if($debug>0) error_log('New LP - intro_cmdAdd action triggered',0);
  438. //add introduction section page
  439. break;
  440. case 'moveitem':
  441. case 'move_item':
  442. if($debug > 0)
  443. error_log('New LP - move_item action triggered', 0);
  444. if(!$lp_found)
  445. {
  446. error_log('New LP - No learnpath given for move_item', 0);
  447. require('lp_list.php');
  448. }
  449. if(!empty($_REQUEST['direction']) && !empty($_REQUEST['id']))
  450. {
  451. $_SESSION['refresh'] = 1;
  452. $_SESSION['oLP']->move_item($_REQUEST['id'], $_REQUEST['direction']);
  453. }
  454. require('lp_admin_view.php');
  455. break;
  456. case 'js_api_refresh':
  457. if($debug>0) error_log('New LP - js_api_refresh action triggered',0);
  458. if(!$lp_found){ error_log('New LP - No learnpath given for js_api_refresh',0); require('lp_message.php'); }
  459. if(isset($_REQUEST['item_id'])){
  460. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  461. }
  462. require('lp_message.php');
  463. break;
  464. default:
  465. if($debug>0) error_log('New LP - default action triggered',0);
  466. //$_SESSION['refresh'] = 1;
  467. require('lp_list.php');
  468. break;
  469. }
  470. if(!empty($_SESSION['oLP'])){
  471. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  472. if($debug>0) error_log('New LP - lpobject is serialized in session',0);
  473. }
  474. ?>