lp_controller.php 27 KB

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