lp_controller.php 39 KB

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