lp_controller.php 27 KB

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