lp_controller.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  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, $_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'], $_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(), $_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'], $_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'], $_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. $_SESSION['oLP']->set_name($_REQUEST['lp_name']);
  482. $author= $_REQUEST['lp_author'];
  483. //fixing the author name (no body or html tags)
  484. $auth_init = stripos($author,'<p>');
  485. if ( $auth_init === false ) {
  486. $auth_init = stripos($author,'<body>');
  487. $auth_end = $auth_init + stripos(substr($author,$auth_init+6),'</body>') + 7;
  488. $len = $auth_end - $auth_init +6;
  489. } else {
  490. $auth_end = strripos($author,'</p>');
  491. $len = $auth_end - $auth_init + 4;
  492. }
  493. $author_fixed=substr($author,$auth_init, $len);
  494. //$author_fixed = $author;
  495. $_SESSION['oLP']->set_author($author_fixed);
  496. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  497. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  498. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  499. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  500. if ($_REQUEST['remove_picture'])
  501. {
  502. $_SESSION['oLP']->delete_lp_image();
  503. }
  504. if ($_FILES['lp_preview_image']['size']>0)
  505. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  506. if (api_get_setting('search_enabled') === 'true')
  507. {
  508. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  509. $specific_fields = get_specific_field_list();
  510. foreach ($specific_fields as $specific_field) {
  511. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  512. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  513. if ( !empty($new_values) ) {
  514. array_walk($new_values, 'trim');
  515. delete_all_specific_field_value(api_get_course_id(), $specific_field['id'], TOOL_LEARNPATH, $_SESSION['oLP']->lp_id);
  516. foreach ($new_values as $value)
  517. {
  518. if ( !empty($value) ) {
  519. add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $_SESSION['oLP']->lp_id, $value);
  520. }
  521. }
  522. }
  523. }
  524. }
  525. require('lp_list.php');
  526. }
  527. break;
  528. case 'add_sub_item': //add an item inside a chapter
  529. if(!api_is_allowed_to_edit()){
  530. api_not_allowed(true);
  531. }
  532. if($debug>0) error_log('New LP - add sub item action triggered',0);
  533. if(!$lp_found){ error_log('New LP - No learnpath given for add sub item',0); require('lp_list.php'); }
  534. else{
  535. $_SESSION['refresh'] = 1;
  536. if(!empty($_REQUEST['parent_item_id'])){
  537. $_SESSION['from_learnpath']='yes';
  538. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.$_REQUEST['lp_id'];
  539. require('resourcelinker.php');
  540. //$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'],$_REQUEST['previous'],$_REQUEST['type'],$_REQUEST['path'],$_REQUEST['title']);
  541. }else{
  542. require('lp_admin_view.php');
  543. }
  544. }
  545. break;
  546. case 'deleteitem':
  547. case 'delete_item':
  548. if(!api_is_allowed_to_edit()){
  549. api_not_allowed(true);
  550. }
  551. if($debug>0) error_log('New LP - delete item action triggered',0);
  552. if(!$lp_found){ error_log('New LP - No learnpath given for delete item',0); require('lp_list.php'); }
  553. else{
  554. $_SESSION['refresh'] = 1;
  555. if(!empty($_REQUEST['id'])){
  556. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  557. }
  558. require('lp_admin_view.php');
  559. }
  560. break;
  561. case 'edititemprereq':
  562. case 'edit_item_prereq':
  563. if(!api_is_allowed_to_edit()){
  564. api_not_allowed(true);
  565. }
  566. if($debug>0) error_log('New LP - edit item prereq action triggered',0);
  567. if(!$lp_found){ error_log('New LP - No learnpath given for edit item prereq',0); require('lp_list.php'); }
  568. else{
  569. if(!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])){
  570. $_SESSION['refresh'] = 1;
  571. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'],$_REQUEST['prereq']);
  572. }
  573. require('lp_admin_view.php');
  574. }
  575. break;
  576. case 'restart':
  577. if($debug>0) error_log('New LP - restart action triggered',0);
  578. if(!$lp_found){ error_log('New LP - No learnpath given for restart',0); require('lp_list.php'); }
  579. else{
  580. $_SESSION['oLP']->restart();
  581. require('lp_view.php');
  582. }
  583. break;
  584. case 'last':
  585. if($debug>0) error_log('New LP - last action triggered',0);
  586. if(!$lp_found){ error_log('New LP - No learnpath given for last',0); require('lp_list.php'); }
  587. else{
  588. $_SESSION['oLP']->last();
  589. require('lp_view.php');
  590. }
  591. break;
  592. case 'first':
  593. if($debug>0) error_log('New LP - first action triggered',0);
  594. if(!$lp_found){ error_log('New LP - No learnpath given for first',0); require('lp_list.php'); }
  595. else{
  596. $_SESSION['oLP']->first();
  597. require('lp_view.php');
  598. }
  599. break;
  600. case 'next':
  601. if($debug>0) error_log('New LP - next action triggered',0);
  602. if(!$lp_found){ error_log('New LP - No learnpath given for next',0); require('lp_list.php'); }
  603. else{
  604. $_SESSION['oLP']->next();
  605. require('lp_view.php');
  606. }
  607. break;
  608. case 'previous':
  609. if($debug>0) error_log('New LP - previous action triggered',0);
  610. if(!$lp_found){ error_log('New LP - No learnpath given for previous',0); require('lp_list.php'); }
  611. else{
  612. $_SESSION['oLP']->previous();
  613. require('lp_view.php');
  614. }
  615. break;
  616. case 'content':
  617. if($debug>0) error_log('New LP - content action triggered',0);
  618. if($debug>0) error_log('New LP - Item id is '.$_GET['item_id'],0);
  619. if(!$lp_found){ error_log('New LP - No learnpath given for content',0); require('lp_list.php'); }
  620. else{
  621. $_SESSION['oLP']->save_last();
  622. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  623. $_SESSION['oLP']->start_current_item();
  624. require('lp_content.php');
  625. }
  626. break;
  627. case 'view':
  628. if($debug > 0)
  629. error_log('New LP - view action triggered', 0);
  630. if(!$lp_found)
  631. {
  632. error_log('New LP - No learnpath given for view', 0);
  633. require('lp_list.php');
  634. }
  635. else
  636. {
  637. if($debug > 0){error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0);}
  638. /*if ( !empty($_REQUEST['item_id']) )
  639. {
  640. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  641. }*/
  642. require('lp_view.php');
  643. }
  644. break;
  645. case 'save':
  646. if($debug>0) error_log('New LP - save action triggered',0);
  647. if(!$lp_found){ error_log('New LP - No learnpath given for save',0); require('lp_list.php'); }
  648. else{
  649. $_SESSION['oLP']->save_item();
  650. require('lp_save.php');
  651. }
  652. break;
  653. case 'stats':
  654. if($debug>0) error_log('New LP - stats action triggered',0);
  655. if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require('lp_list.php'); }
  656. else{
  657. $_SESSION['oLP']->save_current();
  658. $_SESSION['oLP']->save_last();
  659. //declare variables to be used in lp_stats.php
  660. $lp_id = $_SESSION['oLP']->get_id();
  661. $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  662. $user_id = api_get_user_id();
  663. $stats_charset = $_SESSION['oLP']->encoding;
  664. require('lp_stats.php');
  665. }
  666. break;
  667. case 'list':
  668. if($debug>0) error_log('New LP - list action triggered',0);
  669. if($lp_found){
  670. $_SESSION['refresh'] = 1;
  671. $_SESSION['oLP']->save_last();
  672. }
  673. require('lp_list.php');
  674. break;
  675. case 'mode':
  676. //switch between fullscreen and embedded mode
  677. if($debug>0) error_log('New LP - mode change triggered',0);
  678. $mode = $_REQUEST['mode'];
  679. if($mode == 'fullscreen'){
  680. $_SESSION['oLP']->mode = 'fullscreen';
  681. }else{
  682. $_SESSION['oLP']->mode = 'embedded';
  683. }
  684. require('lp_view.php');
  685. break;
  686. case 'switch_view_mode':
  687. if($debug>0) error_log('New LP - switch_view_mode action triggered',0);
  688. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  689. $_SESSION['refresh'] = 1;
  690. $_SESSION['oLP']->update_default_view_mode();
  691. require('lp_list.php');
  692. break;
  693. case 'switch_force_commit':
  694. if($debug>0) error_log('New LP - switch_force_commit action triggered',0);
  695. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  696. $_SESSION['refresh'] = 1;
  697. $_SESSION['oLP']->update_default_scorm_commit();
  698. require('lp_list.php');
  699. break;
  700. case 'switch_reinit':
  701. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  702. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  703. $_SESSION['refresh'] = 1;
  704. $_SESSION['oLP']->update_reinit();
  705. require('lp_list.php');
  706. break;
  707. case 'switch_scorm_debug':
  708. if($debug>0) error_log('New LP - switch_scorm_debug action triggered',0);
  709. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  710. $_SESSION['refresh'] = 1;
  711. $_SESSION['oLP']->update_scorm_debug();
  712. require('lp_list.php');
  713. break;
  714. case 'intro_cmdAdd':
  715. if($debug>0) error_log('New LP - intro_cmdAdd action triggered',0);
  716. //add introduction section page
  717. break;
  718. case 'js_api_refresh':
  719. if($debug>0) error_log('New LP - js_api_refresh action triggered',0);
  720. if(!$lp_found){ error_log('New LP - No learnpath given for js_api_refresh',0); require('lp_message.php'); }
  721. if(isset($_REQUEST['item_id'])){
  722. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  723. }
  724. require('lp_message.php');
  725. break;
  726. case 'return_to_course_homepage':
  727. if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require('lp_list.php'); }
  728. else{
  729. $_SESSION['oLP']->save_current();
  730. $_SESSION['oLP']->save_last();
  731. //declare variables to be used in lp_stats.php
  732. $lp_id = $_SESSION['oLP']->get_id();
  733. $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  734. $user_id = api_get_user_id();
  735. $stats_charset = $_SESSION['oLP']->encoding;
  736. //header('location: ../course_home/course_home.php?'.api_get_cidreq()); // This is not the preferable way to go to the homepage.
  737. header('location: '.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php');
  738. }
  739. break;
  740. case 'search':
  741. /* Include the search script, it's smart enough to know when we are
  742. * searching or not
  743. */
  744. require 'lp_list_search.php';
  745. break;
  746. default:
  747. if($debug>0) error_log('New LP - default action triggered',0);
  748. //$_SESSION['refresh'] = 1;
  749. require('lp_list.php');
  750. break;
  751. }
  752. if(!empty($_SESSION['oLP'])){
  753. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  754. if($debug>0) error_log('New LP - lpobject is serialized in session',0);
  755. }
  756. ?>