lp_controller.php 27 KB

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