lp_controller.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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 || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])) {
  86. if($debug>0) error_log('New LP - oLP is not object, has changed or refresh been asked, getting new',0);
  87. //regenerate a new lp object? Not always as some pages don't need the object (like upload?)
  88. if(!empty($_REQUEST['lp_id']) || !empty($myrefresh_id)){
  89. if($debug>0) error_log('New LP - lp_id is defined',0);
  90. //select the lp in the database and check which type it is (scorm/dokeos/aicc) to generate the
  91. //right object
  92. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  93. if(!empty($_REQUEST['lp_id'])){
  94. $lp_id = $_REQUEST['lp_id'];
  95. } else {
  96. $lp_id = $myrefresh_id;
  97. }
  98. if (is_numeric($lp_id)) {
  99. $lp_id = Database::escape_string($lp_id);
  100. $sel = "SELECT * FROM $lp_table WHERE id = $lp_id";
  101. if($debug>0) error_log('New LP - querying '.$sel,0);
  102. $res = Database::query($sel);
  103. if(Database::num_rows($res)) {
  104. $row = Database::fetch_array($res);
  105. $type = $row['lp_type'];
  106. 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);
  107. switch($type){
  108. case 1:
  109. 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);
  110. $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
  111. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  112. break;
  113. case 2:
  114. 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);
  115. $oLP = new scorm(api_get_course_id(),$lp_id,api_get_user_id());
  116. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  117. break;
  118. case 3:
  119. 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);
  120. $oLP = new aicc(api_get_course_id(),$lp_id,api_get_user_id());
  121. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  122. break;
  123. default:
  124. 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);
  125. $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
  126. if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
  127. break;
  128. }
  129. }
  130. } else {
  131. if($debug>0) error_log('New LP - Request[lp_id] is not numeric',0);
  132. }
  133. } else {
  134. if($debug>0) error_log('New LP - Request[lp_id] and refresh_id were empty',0);
  135. }
  136. if($lp_found) {
  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. if(isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true')
  147. {
  148. if($_REQUEST['action'] != 'list' AND $_REQUEST['action'] != 'view')
  149. {
  150. if(!empty($_REQUEST['lp_id']))
  151. {
  152. $_REQUEST['action'] = 'view';
  153. }
  154. else
  155. {
  156. $_REQUEST['action'] = 'list';
  157. }
  158. }
  159. }
  160. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  161. $action = (!empty($_REQUEST['action'])?$_REQUEST['action']:'');
  162. switch($action)
  163. {
  164. case 'add_item':
  165. if(!$is_allowed_to_edit){
  166. api_not_allowed(true);
  167. }
  168. if($debug > 0) error_log('New LP - add item action triggered', 0);
  169. if(!$lp_found){
  170. //check if the learnpath ID was defined, otherwise send back to list
  171. error_log('New LP - No learnpath given for add item', 0);
  172. require('lp_list.php');
  173. } else {
  174. $_SESSION['refresh'] = 1;
  175. if(isset($_POST['submit_button']) && !empty($_POST['title'])) {
  176. //if a title was sumbitted
  177. if(isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
  178. //check post_time to ensure ??? (counter-hacking measure?)
  179. require('lp_add_item.php');
  180. } else {
  181. $_SESSION['post_time'] = $_POST['post_time'];
  182. if($_POST['type'] == TOOL_DOCUMENT) {
  183. if(isset($_POST['path']) && $_GET['edit'] != 'true') {
  184. $document_id = $_POST['path'];
  185. } else {
  186. $document_id = $_SESSION['oLP']->create_document($_course);
  187. }
  188. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $document_id, $_POST['title'], $_POST['description'], $_POST['prerequisites']);
  189. } else {
  190. //for all other item types than documents, load the item using the item type and path rather than its ID
  191. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $_POST['path'], $_POST['title'], $_POST['description'], $_POST['prerequisites'],$_POST['maxTimeAllowed']);
  192. }
  193. //display
  194. require('lp_add_item.php');
  195. }
  196. } else {
  197. require('lp_add_item.php');
  198. }
  199. }
  200. break;
  201. case 'add_lp':
  202. if(!$is_allowed_to_edit){
  203. api_not_allowed(true);
  204. }
  205. if($debug > 0) error_log('New LP - add_lp action triggered', 0);
  206. $_REQUEST['learnpath_name'] = trim($_REQUEST['learnpath_name']);
  207. if(!empty($_REQUEST['learnpath_name']))
  208. {
  209. $_SESSION['refresh'] = 1;
  210. if(isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time'])
  211. {
  212. require('lp_add.php');
  213. }
  214. else
  215. {
  216. $_SESSION['post_time'] = $_REQUEST['post_time'];
  217. //Kevin Van Den Haute: changed $_REQUEST['learnpath_description'] by '' because it's not used
  218. //old->$new_lp_id = learnpath::add_lp(api_get_course_id(), $_REQUEST['learnpath_name'], $_REQUEST['learnpath_description'], 'dokeos', 'manual', '');
  219. $new_lp_id = learnpath::add_lp(api_get_course_id(), Security::remove_XSS($_REQUEST['learnpath_name']), '', 'dokeos', 'manual', '');
  220. //learnpath::toggle_visibility($new_lp_id,'v');
  221. //Kevin Van Den Haute: only go further if learnpath::add_lp has returned an id
  222. if(is_numeric($new_lp_id))
  223. {
  224. //TODO maybe create a first module directly to avoid bugging the user with useless queries
  225. $_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
  226. //$_SESSION['oLP']->add_item(0,-1,'dokeos_chapter',$_REQUEST['path'],'Default');
  227. require('lp_build.php');
  228. }
  229. }
  230. }
  231. else
  232. require('lp_add.php');
  233. break;
  234. case 'admin_view':
  235. if(!$is_allowed_to_edit){
  236. api_not_allowed(true);
  237. }
  238. if($debug>0) error_log('New LP - admin_view action triggered',0);
  239. if(!$lp_found){ error_log('New LP - No learnpath given for admin_view', 0); require('lp_list.php'); }
  240. else
  241. {
  242. $_SESSION['refresh'] = 1;
  243. require('lp_admin_view.php');
  244. }
  245. break;
  246. case 'build':
  247. if(!$is_allowed_to_edit){
  248. api_not_allowed(true);
  249. }
  250. if($debug > 0) error_log('New LP - build action triggered', 0);
  251. if(!$lp_found){ error_log('New LP - No learnpath given for build', 0); require('lp_list.php'); }
  252. else
  253. {
  254. $_SESSION['refresh'] = 1;
  255. require('lp_build.php');
  256. }
  257. break;
  258. case 'delete_item':
  259. if(!$is_allowed_to_edit){
  260. api_not_allowed(true);
  261. }
  262. if($debug > 0) error_log('New LP - delete item action triggered', 0);
  263. if(!$lp_found){ error_log('New LP - No learnpath given for delete item', 0); require('lp_list.php'); }
  264. else
  265. {
  266. $_SESSION['refresh'] = 1;
  267. if(is_numeric($_GET['id']))
  268. {
  269. $_SESSION['oLP']->delete_item($_GET['id']);
  270. $is_success = true;
  271. }
  272. if(isset($_GET['view']) && $_GET['view'] == 'build')
  273. {
  274. require('lp_build.php');
  275. }
  276. else
  277. {
  278. require('lp_admin_view.php');
  279. }
  280. }
  281. break;
  282. case 'edit_item':
  283. if(!$is_allowed_to_edit){
  284. api_not_allowed(true);
  285. }
  286. if($debug > 0) error_log('New LP - edit item action triggered', 0);
  287. if(!$lp_found){ error_log('New LP - No learnpath given for edit item', 0); require('lp_list.php'); }
  288. else
  289. {
  290. $_SESSION['refresh'] = 1;
  291. if(isset($_POST['submit_button']) && !empty($_POST['title'])) {
  292. //$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
  293. //todo mp3 edit
  294. $audio = array();
  295. if (isset($_FILES['mp3'])) $audio = $_FILES['mp3'];
  296. $_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites'],$audio, $_POST['maxTimeAllowed']);
  297. if(isset($_POST['content_lp'])) {
  298. $_SESSION['oLP']->edit_document($_course);
  299. }
  300. $is_success = true;
  301. }
  302. if(isset($_GET['view']) && $_GET['view'] == 'build')
  303. {
  304. require('lp_edit_item.php');
  305. }
  306. else
  307. {
  308. require('lp_admin_view.php');
  309. }
  310. }
  311. break;
  312. case 'edit_item_prereq':
  313. if(!$is_allowed_to_edit){
  314. api_not_allowed(true);
  315. }
  316. if($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  317. if(!$lp_found){ error_log('New LP - No learnpath given for edit item prereq', 0); require('lp_list.php'); }
  318. else
  319. {
  320. if(isset($_POST['submit_button']))
  321. {
  322. $_SESSION['refresh'] = 1;
  323. $_SESSION['oLP']->edit_item_prereq($_GET['id'], $_POST['prerequisites'], $_POST['min_' . $_POST['prerequisites']], $_POST['max_' . $_POST['prerequisites']]);
  324. }
  325. require('lp_edit_item_prereq.php');
  326. }
  327. break;
  328. case 'move_item':
  329. if(!$is_allowed_to_edit){
  330. api_not_allowed(true);
  331. }
  332. if($debug > 0) error_log('New LP - move item action triggered', 0);
  333. if(!$lp_found){ error_log('New LP - No learnpath given for move item', 0); require('lp_list.php'); }
  334. else
  335. {
  336. $_SESSION['refresh'] = 1;
  337. if(isset($_POST['submit_button']))
  338. {
  339. $_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], Security::remove_XSS($_POST['title']), $_POST['description']);
  340. $is_success = true;
  341. }
  342. if(isset($_GET['view']) && $_GET['view'] == 'build')
  343. {
  344. require('lp_move_item.php');
  345. }
  346. else
  347. {
  348. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  349. require('lp_admin_view.php');
  350. }
  351. }
  352. break;
  353. case 'view_item':
  354. if(!$is_allowed_to_edit){
  355. api_not_allowed(true);
  356. }
  357. if($debug>0) error_log('New LP - view_item action triggered', 0);
  358. if(!$lp_found){
  359. error_log('New LP - No learnpath given for view item', 0); require('lp_list.php');
  360. } else {
  361. $_SESSION['refresh'] = 1;
  362. require('lp_view_item.php');
  363. }
  364. break;
  365. case 'upload':
  366. if(!$is_allowed_to_edit){
  367. api_not_allowed(true);
  368. }
  369. if($debug>0) error_log('New LP - upload action triggered',0);
  370. $cwdir = getcwd();
  371. require('lp_upload.php');
  372. //reinit current working directory as many functions in upload change it
  373. chdir($cwdir);
  374. require('lp_list.php');
  375. break;
  376. case 'export':
  377. if(!$is_allowed_to_edit){
  378. api_not_allowed(true);
  379. }
  380. if($debug>0) error_log('New LP - export action triggered',0);
  381. if(!$lp_found){ error_log('New LP - No learnpath given for export',0); require('lp_list.php'); }
  382. else{
  383. $_SESSION['oLP']->scorm_export();
  384. exit();
  385. //require('lp_list.php');
  386. }
  387. break;
  388. case 'delete':
  389. if(!$is_allowed_to_edit){
  390. api_not_allowed(true);
  391. }
  392. if($debug>0) error_log('New LP - delete action triggered',0);
  393. if(!$lp_found){ error_log('New LP - No learnpath given for delete',0); require('lp_list.php'); }
  394. else{
  395. $_SESSION['refresh'] = 1;
  396. //remove lp from homepage if it is there
  397. //$_SESSION['oLP']->toggle_visibility((int)$_GET['lp_id'],'i');
  398. $_SESSION['oLP']->delete(null,(int)$_GET['lp_id'],'remove');
  399. api_session_unregister('oLP');
  400. require('lp_list.php');
  401. }
  402. break;
  403. case 'toggle_visible': //change lp visibility (inside lp tool)
  404. if(!$is_allowed_to_edit){
  405. api_not_allowed(true);
  406. }
  407. if($debug>0) error_log('New LP - visibility action triggered',0);
  408. if(!$lp_found){ error_log('New LP - No learnpath given for visibility',0); require('lp_list.php'); }
  409. else{
  410. learnpath::toggle_visibility($_REQUEST['lp_id'],$_REQUEST['new_status']);
  411. require('lp_list.php');
  412. }
  413. break;
  414. case 'toggle_publish': //change lp published status (visibility on homepage)
  415. if(!$is_allowed_to_edit){
  416. api_not_allowed(true);
  417. }
  418. if($debug>0) error_log('New LP - publish action triggered',0);
  419. if(!$lp_found){ error_log('New LP - No learnpath given for publish',0); require('lp_list.php'); }
  420. else{
  421. learnpath::toggle_publish($_REQUEST['lp_id'],$_REQUEST['new_status']);
  422. require('lp_list.php');
  423. }
  424. break;
  425. case 'move_lp_up': //change lp published status (visibility on homepage)
  426. if(!$is_allowed_to_edit){
  427. api_not_allowed(true);
  428. }
  429. if($debug>0) error_log('New LP - publish action triggered',0);
  430. if(!$lp_found)
  431. {
  432. error_log('New LP - No learnpath given for publish',0);
  433. require('lp_list.php');
  434. }
  435. else
  436. {
  437. learnpath::move_up($_REQUEST['lp_id']);
  438. require('lp_list.php');
  439. }
  440. break;
  441. case 'move_lp_down': //change lp published status (visibility on homepage)
  442. if(!$is_allowed_to_edit){
  443. api_not_allowed(true);
  444. }
  445. if($debug>0) error_log('New LP - publish action triggered',0);
  446. if(!$lp_found){
  447. error_log('New LP - No learnpath given for publish',0);
  448. require('lp_list.php');
  449. }
  450. else
  451. {
  452. learnpath::move_down($_REQUEST['lp_id']);
  453. require('lp_list.php');
  454. }
  455. break;
  456. case 'edit':
  457. if(!$is_allowed_to_edit)
  458. {
  459. api_not_allowed(true);
  460. }
  461. if($debug>0) error_log('New LP - edit action triggered',0);
  462. if(!$lp_found){ error_log('New LP - No learnpath given for edit',0); require('lp_list.php'); }
  463. else{
  464. $_SESSION['refresh'] = 1;
  465. require('lp_edit.php');
  466. }
  467. break;
  468. case 'update_lp':
  469. if(!$is_allowed_to_edit){
  470. api_not_allowed(true);
  471. }
  472. if($debug>0) error_log('New LP - update_lp action triggered',0);
  473. if(!$lp_found){ error_log('New LP - No learnpath given for edit',0); require('lp_list.php'); }
  474. else{
  475. $_SESSION['refresh'] = 1;
  476. $lp_name=Security::remove_XSS($_REQUEST['lp_name']);
  477. $_SESSION['oLP']->set_name($lp_name);
  478. $author=$_REQUEST['lp_author'];
  479. //fixing the author name (no body or html tags)
  480. $auth_init = stripos($author,'<p>');
  481. if ( $auth_init === false ) {
  482. $auth_init = stripos($author,'<body>');
  483. $auth_end = $auth_init + stripos(substr($author,$auth_init+6),'</body>') + 7;
  484. $len = $auth_end - $auth_init +6;
  485. } else {
  486. $auth_end = strripos($author,'</p>');
  487. $len = $auth_end - $auth_init + 4;
  488. }
  489. $author_fixed=substr($author,$auth_init, $len);
  490. //$author_fixed = $author;
  491. $_SESSION['oLP']->set_author($author_fixed);
  492. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  493. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  494. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  495. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  496. if ($_REQUEST['remove_picture'])
  497. {
  498. $_SESSION['oLP']->delete_lp_image();
  499. }
  500. if ($_FILES['lp_preview_image']['size']>0)
  501. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  502. if (api_get_setting('search_enabled') === 'true')
  503. {
  504. require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
  505. $specific_fields = get_specific_field_list();
  506. foreach ($specific_fields as $specific_field) {
  507. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  508. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  509. if ( !empty($new_values) ) {
  510. array_walk($new_values, 'trim');
  511. delete_all_specific_field_value(api_get_course_id(), $specific_field['id'], TOOL_LEARNPATH, $_SESSION['oLP']->lp_id);
  512. foreach ($new_values as $value)
  513. {
  514. if ( !empty($value) ) {
  515. add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $_SESSION['oLP']->lp_id, $value);
  516. }
  517. }
  518. }
  519. }
  520. }
  521. require('lp_list.php');
  522. }
  523. break;
  524. case 'add_sub_item': //add an item inside a chapter
  525. if(!$is_allowed_to_edit){
  526. api_not_allowed(true);
  527. }
  528. if($debug>0) error_log('New LP - add sub item action triggered',0);
  529. if(!$lp_found){ error_log('New LP - No learnpath given for add sub item',0); require('lp_list.php'); }
  530. else{
  531. $_SESSION['refresh'] = 1;
  532. if(!empty($_REQUEST['parent_item_id'])){
  533. $_SESSION['from_learnpath']='yes';
  534. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.Security::remove_XSS($_REQUEST['lp_id']);
  535. require('resourcelinker.php');
  536. //$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'],$_REQUEST['previous'],$_REQUEST['type'],$_REQUEST['path'],$_REQUEST['title']);
  537. }else{
  538. require('lp_admin_view.php');
  539. }
  540. }
  541. break;
  542. case 'deleteitem':
  543. case 'delete_item':
  544. if(!$is_allowed_to_edit){
  545. api_not_allowed(true);
  546. }
  547. if($debug>0) error_log('New LP - delete item action triggered',0);
  548. if(!$lp_found){ error_log('New LP - No learnpath given for delete item',0); require('lp_list.php'); }
  549. else{
  550. $_SESSION['refresh'] = 1;
  551. if(!empty($_REQUEST['id'])){
  552. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  553. }
  554. require('lp_admin_view.php');
  555. }
  556. break;
  557. case 'edititemprereq':
  558. case 'edit_item_prereq':
  559. if(!$is_allowed_to_edit){
  560. api_not_allowed(true);
  561. }
  562. if($debug>0) error_log('New LP - edit item prereq action triggered',0);
  563. if(!$lp_found){ error_log('New LP - No learnpath given for edit item prereq',0); require('lp_list.php'); }
  564. else{
  565. if(!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])){
  566. $_SESSION['refresh'] = 1;
  567. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'],$_REQUEST['prereq']);
  568. }
  569. require('lp_admin_view.php');
  570. }
  571. break;
  572. case 'restart':
  573. if($debug>0) error_log('New LP - restart action triggered',0);
  574. if(!$lp_found){ error_log('New LP - No learnpath given for restart',0); require('lp_list.php'); }
  575. else{
  576. $_SESSION['oLP']->restart();
  577. require('lp_view.php');
  578. }
  579. break;
  580. case 'last':
  581. if($debug>0) error_log('New LP - last action triggered',0);
  582. if(!$lp_found){ error_log('New LP - No learnpath given for last',0); require('lp_list.php'); }
  583. else{
  584. $_SESSION['oLP']->last();
  585. require('lp_view.php');
  586. }
  587. break;
  588. case 'first':
  589. if($debug>0) error_log('New LP - first action triggered',0);
  590. if(!$lp_found){ error_log('New LP - No learnpath given for first',0); require('lp_list.php'); }
  591. else{
  592. $_SESSION['oLP']->first();
  593. require('lp_view.php');
  594. }
  595. break;
  596. case 'next':
  597. if($debug>0) error_log('New LP - next action triggered',0);
  598. if(!$lp_found){ error_log('New LP - No learnpath given for next',0); require('lp_list.php'); }
  599. else{
  600. $_SESSION['oLP']->next();
  601. require('lp_view.php');
  602. }
  603. break;
  604. case 'previous':
  605. if($debug>0) error_log('New LP - previous action triggered',0);
  606. if(!$lp_found){ error_log('New LP - No learnpath given for previous',0); require('lp_list.php'); }
  607. else{
  608. $_SESSION['oLP']->previous();
  609. require('lp_view.php');
  610. }
  611. break;
  612. case 'content':
  613. if($debug>0) error_log('New LP - content action triggered',0);
  614. if($debug>0) error_log('New LP - Item id is '.$_GET['item_id'],0);
  615. if(!$lp_found){ error_log('New LP - No learnpath given for content',0); require('lp_list.php'); }
  616. else{
  617. $_SESSION['oLP']->save_last();
  618. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  619. $_SESSION['oLP']->start_current_item();
  620. require('lp_content.php');
  621. }
  622. break;
  623. case 'view':
  624. if($debug > 0)
  625. error_log('New LP - view action triggered', 0);
  626. if(!$lp_found)
  627. {
  628. error_log('New LP - No learnpath given for view', 0);
  629. require('lp_list.php');
  630. }
  631. else
  632. {
  633. if($debug > 0){error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0);}
  634. if ( !empty($_REQUEST['item_id']) )
  635. {
  636. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  637. }
  638. require('lp_view.php');
  639. }
  640. break;
  641. case 'save':
  642. if($debug>0) error_log('New LP - save action triggered',0);
  643. if(!$lp_found){ error_log('New LP - No learnpath given for save',0); require('lp_list.php'); }
  644. else{
  645. $_SESSION['oLP']->save_item();
  646. require('lp_save.php');
  647. }
  648. break;
  649. case 'stats':
  650. if($debug>0) error_log('New LP - stats action triggered',0);
  651. if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require('lp_list.php'); }
  652. else{
  653. $_SESSION['oLP']->save_current();
  654. $_SESSION['oLP']->save_last();
  655. //declare variables to be used in lp_stats.php
  656. $lp_id = $_SESSION['oLP']->get_id();
  657. $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  658. $user_id = api_get_user_id();
  659. $stats_charset = $_SESSION['oLP']->encoding;
  660. require('lp_stats.php');
  661. }
  662. break;
  663. case 'list':
  664. if($debug>0) error_log('New LP - list action triggered',0);
  665. if($lp_found){
  666. $_SESSION['refresh'] = 1;
  667. $_SESSION['oLP']->save_last();
  668. }
  669. require('lp_list.php');
  670. break;
  671. case 'mode':
  672. //switch between fullscreen and embedded mode
  673. if($debug>0) error_log('New LP - mode change triggered',0);
  674. $mode = $_REQUEST['mode'];
  675. if($mode == 'fullscreen'){
  676. $_SESSION['oLP']->mode = 'fullscreen';
  677. }else{
  678. $_SESSION['oLP']->mode = 'embedded';
  679. }
  680. require('lp_view.php');
  681. break;
  682. case 'switch_view_mode':
  683. if($debug>0) error_log('New LP - switch_view_mode action triggered',0);
  684. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  685. $_SESSION['refresh'] = 1;
  686. $_SESSION['oLP']->update_default_view_mode();
  687. require('lp_list.php');
  688. break;
  689. case 'switch_force_commit':
  690. if($debug>0) error_log('New LP - switch_force_commit action triggered',0);
  691. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  692. $_SESSION['refresh'] = 1;
  693. $_SESSION['oLP']->update_default_scorm_commit();
  694. require('lp_list.php');
  695. break;
  696. case 'switch_reinit':
  697. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  698. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  699. $_SESSION['refresh'] = 1;
  700. $_SESSION['oLP']->update_reinit();
  701. require('lp_list.php');
  702. break;
  703. case 'switch_scorm_debug':
  704. if($debug>0) error_log('New LP - switch_scorm_debug action triggered',0);
  705. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require('lp_list.php'); }
  706. $_SESSION['refresh'] = 1;
  707. $_SESSION['oLP']->update_scorm_debug();
  708. require('lp_list.php');
  709. break;
  710. case 'intro_cmdAdd':
  711. if($debug>0) error_log('New LP - intro_cmdAdd action triggered',0);
  712. //add introduction section page
  713. break;
  714. case 'js_api_refresh':
  715. if($debug>0) error_log('New LP - js_api_refresh action triggered',0);
  716. if(!$lp_found){ error_log('New LP - No learnpath given for js_api_refresh',0); require('lp_message.php'); }
  717. if(isset($_REQUEST['item_id'])){
  718. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  719. }
  720. require('lp_message.php');
  721. break;
  722. case 'return_to_course_homepage':
  723. if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require('lp_list.php'); }
  724. else{
  725. $_SESSION['oLP']->save_current();
  726. $_SESSION['oLP']->save_last();
  727. //declare variables to be used in lp_stats.php
  728. $lp_id = $_SESSION['oLP']->get_id();
  729. $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  730. $user_id = api_get_user_id();
  731. $stats_charset = $_SESSION['oLP']->encoding;
  732. //header('location: ../course_home/course_home.php?'.api_get_cidreq()); // This is not the preferable way to go to the homepage.
  733. header('location: '.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php');
  734. }
  735. break;
  736. case 'search':
  737. /* Include the search script, it's smart enough to know when we are
  738. * searching or not
  739. */
  740. require 'lp_list_search.php';
  741. break;
  742. default:
  743. if($debug>0) error_log('New LP - default action triggered',0);
  744. //$_SESSION['refresh'] = 1;
  745. require('lp_list.php');
  746. break;
  747. }
  748. if(!empty($_SESSION['oLP'])){
  749. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  750. if($debug>0) error_log('New LP - lpobject is serialized in session',0);
  751. }
  752. ?>