lp_controller.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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 (isset($_GET['action']))
  15. {
  16. if($_GET['action'] == 'export')
  17. { //only needed on export
  18. $language_file[] = 'hotspot';
  19. $language_file[] = 'exercice';
  20. }
  21. }
  22. $language_file[] = 'course_home';
  23. $language_file[] = 'scormdocument';
  24. $language_file[] = 'scorm';
  25. $language_file[] = 'learnpath';
  26. $language_file[] = 'resourcelinker';
  27. $language_file[] = 'registration';
  28. //flag to allow for anonymous user - needs to be set before global.inc.php
  29. $use_anonymous = true;
  30. //include class definitions before session_start() to ensure availability when touching
  31. //session vars containing learning paths
  32. require_once('learnpath.class.php');
  33. if($debug>0) error_log('New LP - Included learnpath',0);
  34. require_once('learnpathItem.class.php');
  35. if($debug>0) error_log('New LP - Included learnpathItem',0);
  36. require_once('scorm.class.php');
  37. if($debug>0) error_log('New LP - Included scorm',0);
  38. require_once('scormItem.class.php');
  39. if($debug>0) error_log('New LP - Included scormItem',0);
  40. require_once('aicc.class.php');
  41. if($debug>0) error_log('New LP - Included aicc',0);
  42. require_once('aiccItem.class.php');
  43. if($debug>0) error_log('New LP - Included aiccItem',0);
  44. require_once('back_compat.inc.php');
  45. if($debug>0) error_log('New LP - Included back_compat',0);
  46. if ($is_allowed_in_course == false){
  47. api_not_allowed(true);
  48. }
  49. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  50. $lpfound = false;
  51. $myrefresh = 0;
  52. $myrefresh_id = 0;
  53. if(!empty($_SESSION['refresh']) && $_SESSION['refresh']==1){
  54. //check if we should do a refresh of the oLP object (for example after editing the LP)
  55. //if refresh is set, we regenerate the oLP object from the database (kind of flush)
  56. api_session_unregister('refresh');
  57. $myrefresh = 1;
  58. if($debug>0) error_log('New LP - Refresh asked',0);
  59. }
  60. if($debug>0) error_log('New LP - Passed refresh check',0);
  61. if(!empty($_REQUEST['dialog_box'])){
  62. $dialog_box = stripslashes(urldecode($_REQUEST['dialog_box']));
  63. }
  64. $lp_controller_touched = 1;
  65. $lp_found = false;
  66. if(isset($_SESSION['lpobject']))
  67. {
  68. if($debug>0) error_log('New LP - SESSION[lpobject] is defined',0);
  69. $oLP = unserialize($_SESSION['lpobject']);
  70. if(is_object($oLP)){
  71. if($debug>0) error_log('New LP - oLP is object',0);
  72. if($myrefresh == 1 OR (empty($oLP->cc)) OR $oLP->cc != api_get_course_id()){
  73. if($debug>0) error_log('New LP - Course has changed, discard lp object',0);
  74. if($myrefresh == 1){$myrefresh_id = $oLP->get_id();}
  75. $oLP = null;
  76. api_session_unregister('oLP');
  77. api_session_unregister('lpobject');
  78. }else{
  79. $_SESSION['oLP'] = $oLP;
  80. $lp_found = true;
  81. }
  82. }
  83. }
  84. if($debug>0) error_log('New LP - Passed data remains check',0);
  85. if($lp_found == false
  86. || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])
  87. )
  88. {
  89. if($debug>0) error_log('New LP - oLP is not object, has changed or refresh been asked, getting new',0);
  90. //regenerate a new lp object? Not always as some pages don't need the object (like upload?)
  91. if(!empty($_REQUEST['lp_id']) || !empty($myrefresh_id)){
  92. if($debug>0) error_log('New LP - lp_id is defined',0);
  93. //select the lp in the database and check which type it is (scorm/dokeos/aicc) to generate the
  94. //right object
  95. $lp_table = Database::get_course_table('lp');
  96. if(!empty($_REQUEST['lp_id'])){
  97. $lp_id = learnpath::escape_string($_REQUEST['lp_id']);
  98. }else{
  99. $lp_id = $myrefresh_id;
  100. }
  101. $sel = "SELECT * FROM $lp_table WHERE id = $lp_id";
  102. if($debug>0) error_log('New LP - querying '.$sel,0);
  103. $res = api_sql_query($sel);
  104. if(Database::num_rows($res))
  105. {
  106. $row = Database::fetch_array($res);
  107. $type = $row['lp_type'];
  108. 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);
  109. switch($type){
  110. case 1:
  111. 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);
  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. case 2:
  116. 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);
  117. $oLP = new scorm(api_get_course_id(),$lp_id,api_get_user_id());
  118. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  119. break;
  120. case 3:
  121. 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);
  122. $oLP = new aicc(api_get_course_id(),$lp_id,api_get_user_id());
  123. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  124. break;
  125. default:
  126. 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);
  127. $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
  128. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  129. break;
  130. }
  131. }
  132. }else{
  133. if($debug>0) error_log('New LP - Request[lp_id] and refresh_id were empty',0);
  134. }
  135. if($lp_found)
  136. {
  137. $_SESSION['oLP'] = $oLP;
  138. }
  139. }
  140. if($debug>0) error_log('New LP - Passed oLP creation check',0);
  141. /**
  142. * Actions switching
  143. */
  144. $_SESSION['oLP']->update_queue = array(); //reinitialises array used by javascript to update items in the TOC
  145. $_SESSION['oLP']->message = ''; //should use ->clear_message() method but doesn't work
  146. // Some common default settings for the online editor. Other settings are calculated in formvalidator module.
  147. // For editing document type lp-items specific settings are set/calculated, see learnpath.class.php
  148. //TODO: check, see if we need, it seems not working here
  149. $fck_attribute['ToolbarSet'] = 'LearnPath';
  150. $fck_attribute['Width'] = '100%';
  151. $fck_attribute['Height'] = '400';
  152. if(isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true')
  153. {
  154. if($_REQUEST['action'] != 'list' AND $_REQUEST['action'] != 'view')
  155. {
  156. if(!empty($_REQUEST['lp_id']))
  157. {
  158. $_REQUEST['action'] = 'view';
  159. }
  160. else
  161. {
  162. $_REQUEST['action'] = 'list';
  163. }
  164. }
  165. }
  166. $action = (!empty($_REQUEST['action'])?$_REQUEST['action']:'');
  167. switch($action)
  168. {
  169. case 'add_item':
  170. if(!api_is_allowed_to_edit()){
  171. api_not_allowed(true);
  172. }
  173. if($debug > 0) error_log('New LP - add item action triggered', 0);
  174. if(!$lp_found){
  175. //check if the learnpath ID was defined, otherwise send back to list
  176. error_log('New LP - No learnpath given for add item', 0);
  177. require('lp_list.php');
  178. } else {
  179. $_SESSION['refresh'] = 1;
  180. if(isset($_POST['submit_button']) && !empty($_POST['title'])) {
  181. //if a title was sumbitted
  182. if(isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
  183. //check post_time to ensure ??? (counter-hacking measure?)
  184. require('lp_add_item.php');
  185. } else {
  186. $_SESSION['post_time'] = $_POST['post_time'];
  187. if($_POST['type'] == TOOL_DOCUMENT) {
  188. if(isset($_POST['path']) && $_GET['edit'] != 'true') {
  189. $document_id = $_POST['path'];
  190. } else {
  191. $document_id = $_SESSION['oLP']->create_document($_course);
  192. }
  193. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $document_id, Security::remove_XSS($_POST['title']), $_POST['description'], $_POST['prerequisites']);
  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'], Security::remove_XSS($_POST['title']), $_POST['description'], $_POST['prerequisites'],$_POST['maxTimeAllowed']);
  197. }
  198. //display
  199. require('lp_add_item.php');
  200. }
  201. } else {
  202. require('lp_add_item.php');
  203. }
  204. }
  205. break;
  206. case 'add_lp':
  207. if(!api_is_allowed_to_edit()){
  208. api_not_allowed(true);
  209. }
  210. if($debug > 0) error_log('New LP - add_lp action triggered', 0);
  211. $_REQUEST['learnpath_name'] = trim($_REQUEST['learnpath_name']);
  212. if(!empty($_REQUEST['learnpath_name']))
  213. {
  214. $_SESSION['refresh'] = 1;
  215. if(isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time'])
  216. {
  217. require('lp_add.php');
  218. }
  219. else
  220. {
  221. $_SESSION['post_time'] = $_REQUEST['post_time'];
  222. //Kevin Van Den Haute: changed $_REQUEST['learnpath_description'] by '' because it's not used
  223. //old->$new_lp_id = learnpath::add_lp(api_get_course_id(), $_REQUEST['learnpath_name'], $_REQUEST['learnpath_description'], 'dokeos', 'manual', '');
  224. $new_lp_id = learnpath::add_lp(api_get_course_id(), Security::remove_XSS($_REQUEST['learnpath_name']), '', 'dokeos', 'manual', '');
  225. //learnpath::toggle_visibility($new_lp_id,'v');
  226. //Kevin Van Den Haute: only go further if learnpath::add_lp has returned an id
  227. if(is_numeric($new_lp_id))
  228. {
  229. //TODO maybe create a first module directly to avoid bugging the user with useless queries
  230. $_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
  231. //$_SESSION['oLP']->add_item(0,-1,'dokeos_chapter',$_REQUEST['path'],'Default');
  232. require('lp_build.php');
  233. }
  234. }
  235. }
  236. else
  237. require('lp_add.php');
  238. break;
  239. case 'admin_view':
  240. if(!api_is_allowed_to_edit()){
  241. api_not_allowed(true);
  242. }
  243. if($debug>0) error_log('New LP - admin_view action triggered',0);
  244. if(!$lp_found){ error_log('New LP - No learnpath given for admin_view', 0); require('lp_list.php'); }
  245. else
  246. {
  247. $_SESSION['refresh'] = 1;
  248. require('lp_admin_view.php');
  249. }
  250. break;
  251. case 'build':
  252. if(!api_is_allowed_to_edit()){
  253. api_not_allowed(true);
  254. }
  255. if($debug > 0) error_log('New LP - build action triggered', 0);
  256. if(!$lp_found){ error_log('New LP - No learnpath given for build', 0); require('lp_list.php'); }
  257. else
  258. {
  259. $_SESSION['refresh'] = 1;
  260. require('lp_build.php');
  261. }
  262. break;
  263. case 'delete_item':
  264. if(!api_is_allowed_to_edit()){
  265. api_not_allowed(true);
  266. }
  267. if($debug > 0) error_log('New LP - delete item action triggered', 0);
  268. if(!$lp_found){ error_log('New LP - No learnpath given for delete item', 0); require('lp_list.php'); }
  269. else
  270. {
  271. $_SESSION['refresh'] = 1;
  272. if(is_numeric($_GET['id']))
  273. {
  274. $_SESSION['oLP']->delete_item($_GET['id']);
  275. $is_success = true;
  276. }
  277. if(isset($_GET['view']) && $_GET['view'] == 'build')
  278. {
  279. require('lp_build.php');
  280. }
  281. else
  282. {
  283. require('lp_admin_view.php');
  284. }
  285. }
  286. break;
  287. case 'edit_item':
  288. if(!api_is_allowed_to_edit()){
  289. api_not_allowed(true);
  290. }
  291. if($debug > 0) error_log('New LP - edit item action triggered', 0);
  292. if(!$lp_found){ error_log('New LP - No learnpath given for edit item', 0); require('lp_list.php'); }
  293. else
  294. {
  295. $_SESSION['refresh'] = 1;
  296. if(isset($_POST['submit_button']) && !empty($_POST['title'])) {
  297. //$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
  298. //todo mp3 edit
  299. $audio = array();
  300. if (isset($_FILES['mp3'])) $audio = $_FILES['mp3'];
  301. $_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], Security::remove_XSS($_POST['title']), $_POST['description'], $_POST['prerequisites'],$audio, $_POST['maxTimeAllowed']);
  302. if(isset($_POST['content_lp'])) {
  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'], Security::remove_XSS($_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){
  364. error_log('New LP - No learnpath given for view item', 0); require('lp_list.php');
  365. } else {
  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. $lp_name=Security::remove_XSS($_REQUEST['lp_name']);
  482. $_SESSION['oLP']->set_name($lp_name);
  483. $author=$_REQUEST['lp_author'];
  484. //fixing the author name (no body or html tags)
  485. $auth_init = stripos($author,'<p>');
  486. if ( $auth_init === false ) {
  487. $auth_init = stripos($author,'<body>');
  488. $auth_end = $auth_init + stripos(substr($author,$auth_init+6),'</body>') + 7;
  489. $len = $auth_end - $auth_init +6;
  490. } else {
  491. $auth_end = strripos($author,'</p>');
  492. $len = $auth_end - $auth_init + 4;
  493. }
  494. $author_fixed=substr($author,$auth_init, $len);
  495. //$author_fixed = $author;
  496. $_SESSION['oLP']->set_author($author_fixed);
  497. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  498. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  499. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  500. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  501. if ($_REQUEST['remove_picture'])
  502. {
  503. $_SESSION['oLP']->delete_lp_image();
  504. }
  505. if ($_FILES['lp_preview_image']['size']>0)
  506. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  507. if (api_get_setting('search_enabled') === 'true')
  508. {
  509. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  510. $specific_fields = get_specific_field_list();
  511. foreach ($specific_fields as $specific_field) {
  512. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  513. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  514. if ( !empty($new_values) ) {
  515. array_walk($new_values, 'trim');
  516. delete_all_specific_field_value(api_get_course_id(), $specific_field['id'], TOOL_LEARNPATH, $_SESSION['oLP']->lp_id);
  517. foreach ($new_values as $value)
  518. {
  519. if ( !empty($value) ) {
  520. add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $_SESSION['oLP']->lp_id, $value);
  521. }
  522. }
  523. }
  524. }
  525. }
  526. require('lp_list.php');
  527. }
  528. break;
  529. case 'add_sub_item': //add an item inside a chapter
  530. if(!api_is_allowed_to_edit()){
  531. api_not_allowed(true);
  532. }
  533. if($debug>0) error_log('New LP - add sub item action triggered',0);
  534. if(!$lp_found){ error_log('New LP - No learnpath given for add sub item',0); require('lp_list.php'); }
  535. else{
  536. $_SESSION['refresh'] = 1;
  537. if(!empty($_REQUEST['parent_item_id'])){
  538. $_SESSION['from_learnpath']='yes';
  539. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.$_REQUEST['lp_id'];
  540. require('resourcelinker.php');
  541. //$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'],$_REQUEST['previous'],$_REQUEST['type'],$_REQUEST['path'],$_REQUEST['title']);
  542. }else{
  543. require('lp_admin_view.php');
  544. }
  545. }
  546. break;
  547. case 'deleteitem':
  548. case 'delete_item':
  549. if(!api_is_allowed_to_edit()){
  550. api_not_allowed(true);
  551. }
  552. if($debug>0) error_log('New LP - delete item action triggered',0);
  553. if(!$lp_found){ error_log('New LP - No learnpath given for delete item',0); require('lp_list.php'); }
  554. else{
  555. $_SESSION['refresh'] = 1;
  556. if(!empty($_REQUEST['id'])){
  557. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  558. }
  559. require('lp_admin_view.php');
  560. }
  561. break;
  562. case 'edititemprereq':
  563. case 'edit_item_prereq':
  564. if(!api_is_allowed_to_edit()){
  565. api_not_allowed(true);
  566. }
  567. if($debug>0) error_log('New LP - edit item prereq action triggered',0);
  568. if(!$lp_found){ error_log('New LP - No learnpath given for edit item prereq',0); require('lp_list.php'); }
  569. else{
  570. if(!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])){
  571. $_SESSION['refresh'] = 1;
  572. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'],$_REQUEST['prereq']);
  573. }
  574. require('lp_admin_view.php');
  575. }
  576. break;
  577. case 'restart':
  578. if($debug>0) error_log('New LP - restart action triggered',0);
  579. if(!$lp_found){ error_log('New LP - No learnpath given for restart',0); require('lp_list.php'); }
  580. else{
  581. $_SESSION['oLP']->restart();
  582. require('lp_view.php');
  583. }
  584. break;
  585. case 'last':
  586. if($debug>0) error_log('New LP - last action triggered',0);
  587. if(!$lp_found){ error_log('New LP - No learnpath given for last',0); require('lp_list.php'); }
  588. else{
  589. $_SESSION['oLP']->last();
  590. require('lp_view.php');
  591. }
  592. break;
  593. case 'first':
  594. if($debug>0) error_log('New LP - first action triggered',0);
  595. if(!$lp_found){ error_log('New LP - No learnpath given for first',0); require('lp_list.php'); }
  596. else{
  597. $_SESSION['oLP']->first();
  598. require('lp_view.php');
  599. }
  600. break;
  601. case 'next':
  602. if($debug>0) error_log('New LP - next action triggered',0);
  603. if(!$lp_found){ error_log('New LP - No learnpath given for next',0); require('lp_list.php'); }
  604. else{
  605. $_SESSION['oLP']->next();
  606. require('lp_view.php');
  607. }
  608. break;
  609. case 'previous':
  610. if($debug>0) error_log('New LP - previous action triggered',0);
  611. if(!$lp_found){ error_log('New LP - No learnpath given for previous',0); require('lp_list.php'); }
  612. else{
  613. $_SESSION['oLP']->previous();
  614. require('lp_view.php');
  615. }
  616. break;
  617. case 'content':
  618. if($debug>0) error_log('New LP - content action triggered',0);
  619. if($debug>0) error_log('New LP - Item id is '.$_GET['item_id'],0);
  620. if(!$lp_found){ error_log('New LP - No learnpath given for content',0); require('lp_list.php'); }
  621. else{
  622. $_SESSION['oLP']->save_last();
  623. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  624. $_SESSION['oLP']->start_current_item();
  625. require('lp_content.php');
  626. }
  627. break;
  628. case 'view':
  629. if($debug > 0)
  630. error_log('New LP - view action triggered', 0);
  631. if(!$lp_found)
  632. {
  633. error_log('New LP - No learnpath given for view', 0);
  634. require('lp_list.php');
  635. }
  636. else
  637. {
  638. if($debug > 0){error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0);}
  639. if ( !empty($_REQUEST['item_id']) )
  640. {
  641. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  642. }
  643. require('lp_view.php');
  644. }
  645. break;
  646. case 'save':
  647. if($debug>0) error_log('New LP - save action triggered',0);
  648. if(!$lp_found){ error_log('New LP - No learnpath given for save',0); require('lp_list.php'); }
  649. else{
  650. $_SESSION['oLP']->save_item();
  651. require('lp_save.php');
  652. }
  653. break;
  654. case 'stats':
  655. if($debug>0) error_log('New LP - stats action triggered',0);
  656. if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require('lp_list.php'); }
  657. else{
  658. $_SESSION['oLP']->save_current();
  659. $_SESSION['oLP']->save_last();
  660. //declare variables to be used in lp_stats.php
  661. $lp_id = $_SESSION['oLP']->get_id();
  662. $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  663. $user_id = api_get_user_id();
  664. $stats_charset = $_SESSION['oLP']->encoding;
  665. require('lp_stats.php');
  666. }
  667. break;
  668. case 'list':
  669. if($debug>0) error_log('New LP - list action triggered',0);
  670. if($lp_found){
  671. $_SESSION['refresh'] = 1;
  672. $_SESSION['oLP']->save_last();
  673. }
  674. require('lp_list.php');
  675. break;
  676. case 'mode':
  677. //switch between fullscreen and embedded mode
  678. if($debug>0) error_log('New LP - mode change triggered',0);
  679. $mode = $_REQUEST['mode'];
  680. if($mode == 'fullscreen'){
  681. $_SESSION['oLP']->mode = 'fullscreen';
  682. }else{
  683. $_SESSION['oLP']->mode = 'embedded';
  684. }
  685. require('lp_view.php');
  686. break;
  687. case 'switch_view_mode':
  688. if($debug>0) error_log('New LP - switch_view_mode action triggered',0);
  689. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  690. $_SESSION['refresh'] = 1;
  691. $_SESSION['oLP']->update_default_view_mode();
  692. require('lp_list.php');
  693. break;
  694. case 'switch_force_commit':
  695. if($debug>0) error_log('New LP - switch_force_commit action triggered',0);
  696. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  697. $_SESSION['refresh'] = 1;
  698. $_SESSION['oLP']->update_default_scorm_commit();
  699. require('lp_list.php');
  700. break;
  701. case 'switch_reinit':
  702. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  703. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  704. $_SESSION['refresh'] = 1;
  705. $_SESSION['oLP']->update_reinit();
  706. require('lp_list.php');
  707. break;
  708. case 'switch_scorm_debug':
  709. if($debug>0) error_log('New LP - switch_scorm_debug action triggered',0);
  710. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  711. $_SESSION['refresh'] = 1;
  712. $_SESSION['oLP']->update_scorm_debug();
  713. require('lp_list.php');
  714. break;
  715. case 'intro_cmdAdd':
  716. if($debug>0) error_log('New LP - intro_cmdAdd action triggered',0);
  717. //add introduction section page
  718. break;
  719. case 'js_api_refresh':
  720. if($debug>0) error_log('New LP - js_api_refresh action triggered',0);
  721. if(!$lp_found){ error_log('New LP - No learnpath given for js_api_refresh',0); require('lp_message.php'); }
  722. if(isset($_REQUEST['item_id'])){
  723. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  724. }
  725. require('lp_message.php');
  726. break;
  727. case 'return_to_course_homepage':
  728. if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require('lp_list.php'); }
  729. else{
  730. $_SESSION['oLP']->save_current();
  731. $_SESSION['oLP']->save_last();
  732. //declare variables to be used in lp_stats.php
  733. $lp_id = $_SESSION['oLP']->get_id();
  734. $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  735. $user_id = api_get_user_id();
  736. $stats_charset = $_SESSION['oLP']->encoding;
  737. //header('location: ../course_home/course_home.php?'.api_get_cidreq()); // This is not the preferable way to go to the homepage.
  738. header('location: '.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php');
  739. }
  740. break;
  741. case 'search':
  742. /* Include the search script, it's smart enough to know when we are
  743. * searching or not
  744. */
  745. require 'lp_list_search.php';
  746. break;
  747. default:
  748. if($debug>0) error_log('New LP - default action triggered',0);
  749. //$_SESSION['refresh'] = 1;
  750. require('lp_list.php');
  751. break;
  752. }
  753. if(!empty($_SESSION['oLP'])){
  754. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  755. if($debug>0) error_log('New LP - lpobject is serialized in session',0);
  756. }
  757. ?>