lp_controller.php 37 KB

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