lp_controller.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  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>
  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>
  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. $is_allowed_to_edit = api_is_allowed_to_edit(false, true, false, false);
  177. /**
  178. * Actions switching
  179. */
  180. if (isset($_SESSION['oLP'])) {
  181. $_SESSION['oLP']->update_queue = array(); // Reinitialises array used by javascript to update items in the TOC.
  182. $_SESSION['oLP']->message = ''; // Should use ->clear_message() method but doesn't work.
  183. }
  184. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
  185. if ($_REQUEST['action'] != 'list' AND $_REQUEST['action'] != 'view') {
  186. if (!empty($_REQUEST['lp_id'])) {
  187. $_REQUEST['action'] = 'view';
  188. } else {
  189. $_REQUEST['action'] = 'list';
  190. }
  191. }
  192. } else {
  193. if ($is_allowed_to_edit) {
  194. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'view') {
  195. $_REQUEST['action'] = 'build';
  196. }
  197. }
  198. }
  199. $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : '');
  200. switch ($action) {
  201. case 'add_item':
  202. if (!$is_allowed_to_edit) {
  203. api_not_allowed(true);
  204. }
  205. if ($debug > 0) error_log('New LP - add item action triggered', 0);
  206. if (!$lp_found) {
  207. //check if the learnpath ID was defined, otherwise send back to list
  208. if ($debug > 0) error_log('New LP - No learnpath given for add item', 0);
  209. require 'lp_list.php';
  210. } else {
  211. $_SESSION['refresh'] = 1;
  212. if (isset($_POST['submit_button']) && !empty($_POST['title'])) {
  213. // If a title was sumbitted:
  214. //Updating the lp.modified_on
  215. $_SESSION['oLP']->set_modified_on();
  216. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
  217. // Check post_time to ensure ??? (counter-hacking measure?)
  218. require 'lp_add_item.php';
  219. } else {
  220. $_SESSION['post_time'] = $_POST['post_time'];
  221. if ($_POST['type'] == TOOL_DOCUMENT) {
  222. if (isset($_POST['path']) && $_GET['edit'] != 'true') {
  223. $document_id = $_POST['path'];
  224. } else {
  225. $document_id = $_SESSION['oLP']->create_document($_course);
  226. }
  227. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $document_id, $_POST['title'], $_POST['description'], $_POST['prerequisites']);
  228. } else {
  229. // For all other item types than documents, load the item using the item type and path rather than its ID.
  230. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $_POST['path'], $_POST['title'], $_POST['description'], $_POST['prerequisites'], $_POST['maxTimeAllowed']);
  231. }
  232. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  233. header('Location: '.$url);
  234. exit;
  235. }
  236. } else {
  237. require 'lp_add_item.php';
  238. }
  239. }
  240. break;
  241. case 'add_audio':
  242. if (!$is_allowed_to_edit) {
  243. api_not_allowed(true);
  244. }
  245. if ($debug > 0) error_log('New LP - add audio action triggered', 0);
  246. if (!$lp_found) {
  247. //check if the learnpath ID was defined, otherwise send back to list
  248. if ($debug > 0) error_log('New LP - No learnpath given for add audio', 0);
  249. require 'lp_list.php';
  250. } else {
  251. $_SESSION['refresh'] = 1;
  252. if (isset($_REQUEST['id'])) {
  253. $lp_item_obj = new learnpathItem($_REQUEST['id']);
  254. //Remove audio
  255. if (isset($_POST['delete_file']) && $_POST['delete_file'] == 1) {
  256. $lp_item_obj->remove_audio();
  257. }
  258. //Upload audio
  259. if (isset($_FILES['file']) && !empty($_FILES['file'])) {
  260. //Updating the lp.modified_on
  261. $_SESSION['oLP']->set_modified_on();
  262. $lp_item_obj->add_audio();
  263. }
  264. //Add audio file from documents
  265. if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
  266. $_SESSION['oLP']->set_modified_on();
  267. $lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
  268. }
  269. // Display.
  270. require 'lp_add_audio.php';
  271. } else {
  272. require 'lp_add_audio.php';
  273. }
  274. }
  275. break;
  276. case 'add_lp':
  277. if (!$is_allowed_to_edit) {
  278. api_not_allowed(true);
  279. }
  280. if ($debug > 0) error_log('New LP - add_lp action triggered', 0);
  281. $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
  282. if (!empty($_REQUEST['lp_name'])) {
  283. $_SESSION['refresh'] = 1;
  284. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
  285. require 'lp_add.php';
  286. } else {
  287. $_SESSION['post_time'] = $_REQUEST['post_time'];
  288. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  289. $publicated_on = $_REQUEST['publicated_on'];
  290. $publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
  291. } else {
  292. $publicated_on = null;
  293. }
  294. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  295. $expired_on = $_REQUEST['expired_on'];
  296. $expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
  297. } else {
  298. $expired_on = null;
  299. }
  300. $new_lp_id = learnpath::add_lp(api_get_course_id(), Security::remove_XSS($_REQUEST['lp_name']), '', 'chamilo', 'manual', '', $publicated_on, $expired_on);
  301. if (is_numeric($new_lp_id)) {
  302. // TODO: Maybe create a first module directly to avoid bugging the user with useless queries
  303. $_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
  304. //require 'lp_build.php';
  305. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id);
  306. header('Location: '.$url);
  307. exit;
  308. }
  309. }
  310. } else {
  311. require 'lp_add.php';
  312. }
  313. break;
  314. case 'admin_view':
  315. if (!$is_allowed_to_edit) {
  316. api_not_allowed(true);
  317. }
  318. if ($debug > 0) error_log('New LP - admin_view action triggered', 0);
  319. if (!$lp_found) { error_log('New LP - No learnpath given for admin_view', 0); require 'lp_list.php'; }
  320. else {
  321. $_SESSION['refresh'] = 1;
  322. require 'lp_admin_view.php';
  323. }
  324. break;
  325. case 'auto_launch':
  326. if (api_get_course_setting('enable_lp_auto_launch') == 1) { //Redirect to a specific LP
  327. if (!$is_allowed_to_edit) {
  328. api_not_allowed(true);
  329. }
  330. if ($debug > 0) error_log('New LP - auto_launch action triggered', 0);
  331. if (!$lp_found) { error_log('New LP - No learnpath given for set_autolunch', 0); require 'lp_list.php'; }
  332. else {
  333. $_SESSION['oLP']->set_autolunch($_GET['lp_id'], $_GET['status']);
  334. require 'lp_list.php';
  335. exit;
  336. }
  337. }
  338. break;
  339. case 'build':
  340. if (!$is_allowed_to_edit) {
  341. api_not_allowed(true);
  342. }
  343. if ($debug > 0) error_log('New LP - build action triggered', 0);
  344. if (!$lp_found) { error_log('New LP - No learnpath given for build', 0); require 'lp_list.php'; }
  345. else {
  346. $_SESSION['refresh'] = 1;
  347. //require 'lp_build.php';
  348. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  349. header('Location: '.$url);
  350. exit;
  351. }
  352. break;
  353. case 'edit_item':
  354. if (!$is_allowed_to_edit) {
  355. api_not_allowed(true);
  356. }
  357. if ($debug > 0) error_log('New LP - edit item action triggered', 0);
  358. if (!$lp_found) { error_log('New LP - No learnpath given for edit item', 0); require 'lp_list.php'; }
  359. else {
  360. $_SESSION['refresh'] = 1;
  361. if (isset($_POST['submit_button']) && !empty($_POST['title'])) {
  362. //Updating the lp.modified_on
  363. $_SESSION['oLP']->set_modified_on();
  364. // TODO: mp3 edit
  365. $audio = array();
  366. if (isset($_FILES['mp3'])) {
  367. $audio = $_FILES['mp3'];
  368. }
  369. $_SESSION['oLP']->edit_item($_REQUEST['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites'], $audio, $_POST['maxTimeAllowed']);
  370. if (isset($_POST['content_lp'])) {
  371. $_SESSION['oLP']->edit_document($_course);
  372. }
  373. $is_success = true;
  374. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  375. header('Location: '.$url);
  376. exit;
  377. }
  378. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  379. require 'lp_edit_item.php';
  380. } else {
  381. require 'lp_admin_view.php';
  382. }
  383. }
  384. break;
  385. case 'edit_item_prereq':
  386. if (!$is_allowed_to_edit) {
  387. api_not_allowed(true);
  388. }
  389. if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  390. if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
  391. else {
  392. if (isset($_POST['submit_button'])) {
  393. //Updating the lp.modified_on
  394. $_SESSION['oLP']->set_modified_on();
  395. $_SESSION['refresh'] = 1;
  396. if ($_SESSION['oLP']->edit_item_prereq($_GET['id'], $_POST['prerequisites'], $_POST['min_' . $_POST['prerequisites']], $_POST['max_' . $_POST['prerequisites']])) {
  397. $is_success = true;
  398. }
  399. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  400. header('Location: '.$url);
  401. exit;
  402. } else {
  403. require 'lp_edit_item_prereq.php';
  404. }
  405. }
  406. break;
  407. case 'move_item':
  408. if (!$is_allowed_to_edit) {
  409. api_not_allowed(true);
  410. }
  411. if ($debug > 0) error_log('New LP - move item action triggered', 0);
  412. if (!$lp_found) { error_log('New LP - No learnpath given for move item', 0); require 'lp_list.php'; }
  413. else {
  414. $_SESSION['refresh'] = 1;
  415. if (isset($_POST['submit_button'])) {
  416. //Updating the lp.modified_on
  417. $_SESSION['oLP']->set_modified_on();
  418. $_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description']);
  419. $is_success = true;
  420. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  421. header('Location: '.$url);
  422. }
  423. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  424. require 'lp_move_item.php';
  425. } else {
  426. // Avoids weird behaviours see CT#967.
  427. $check = Security::check_token('get');
  428. if ($check) {
  429. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  430. }
  431. Security::clear_token();
  432. require 'lp_admin_view.php';
  433. }
  434. }
  435. break;
  436. case 'view_item':
  437. if (!$is_allowed_to_edit) {
  438. api_not_allowed(true);
  439. }
  440. if ($debug > 0) error_log('New LP - view_item action triggered', 0);
  441. if (!$lp_found) {
  442. error_log('New LP - No learnpath given for view item', 0); require 'lp_list.php';
  443. } else {
  444. $_SESSION['refresh'] = 1;
  445. require 'lp_view_item.php';
  446. }
  447. break;
  448. case 'upload':
  449. if (!$is_allowed_to_edit) {
  450. api_not_allowed(true);
  451. }
  452. if ($debug > 0) error_log('New LP - upload action triggered', 0);
  453. $cwdir = getcwd();
  454. require 'lp_upload.php';
  455. // Reinit current working directory as many functions in upload change it.
  456. chdir($cwdir);
  457. require 'lp_list.php';
  458. break;
  459. case 'copy':
  460. if (!$is_allowed_to_edit) {
  461. api_not_allowed(true);
  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 copy', 0); require 'lp_list.php'; }
  465. else {
  466. $_SESSION['oLP']->copy();
  467. }
  468. require 'lp_list.php';
  469. break;
  470. case 'export':
  471. if (!$is_allowed_to_edit) {
  472. api_not_allowed(true);
  473. }
  474. if ($debug > 0) error_log('New LP - export action triggered', 0);
  475. if (!$lp_found) { error_log('New LP - No learnpath given for export', 0); require 'lp_list.php'; }
  476. else {
  477. $_SESSION['oLP']->scorm_export();
  478. exit();
  479. //require 'lp_list.php';
  480. }
  481. break;
  482. case 'export_to_pdf':
  483. if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
  484. api_not_allowed();
  485. }
  486. if ($debug > 0) error_log('New LP - export action triggered', 0);
  487. if (!$lp_found) { error_log('New LP - No learnpath given for export_to_pdf', 0); require 'lp_list.php';
  488. } else {
  489. $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
  490. if (!$result) {
  491. require 'lp_list.php';
  492. }
  493. exit;
  494. }
  495. break;
  496. case 'delete':
  497. if (!$is_allowed_to_edit) {
  498. api_not_allowed(true);
  499. }
  500. if ($debug > 0) error_log('New LP - delete action triggered', 0);
  501. if (!$lp_found) { error_log('New LP - No learnpath given for delete', 0); require 'lp_list.php'; }
  502. else {
  503. $_SESSION['refresh'] = 1;
  504. // Remove lp from homepage if it is there.
  505. //$_SESSION['oLP']->toggle_visibility((int)$_GET['lp_id'],'i');
  506. $_SESSION['oLP']->delete(null,(int)$_GET['lp_id'],'remove');
  507. Session::erase('oLP');
  508. require 'lp_list.php';
  509. }
  510. break;
  511. case 'toggle_visible': // Change lp visibility (inside lp tool).
  512. if (!$is_allowed_to_edit) {
  513. api_not_allowed(true);
  514. }
  515. if ($debug > 0) error_log('New LP - visibility action triggered', 0);
  516. if (!$lp_found) { error_log('New LP - No learnpath given for visibility', 0); require 'lp_list.php'; }
  517. else {
  518. learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
  519. require 'lp_list.php';
  520. }
  521. break;
  522. case 'toggle_publish': // Change lp published status (visibility on homepage).
  523. if (!$is_allowed_to_edit) {
  524. api_not_allowed(true);
  525. }
  526. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  527. if (!$lp_found) { error_log('New LP - No learnpath given for publish', 0); require 'lp_list.php'; }
  528. else {
  529. learnpath::toggle_publish($_REQUEST['lp_id'],$_REQUEST['new_status']);
  530. require 'lp_list.php';
  531. }
  532. break;
  533. case 'move_lp_up': // Change lp published status (visibility on homepage)
  534. if (!$is_allowed_to_edit) {
  535. api_not_allowed(true);
  536. }
  537. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  538. if (!$lp_found) {
  539. error_log('New LP - No learnpath given for publish', 0);
  540. require 'lp_list.php';
  541. } else {
  542. learnpath::move_up($_REQUEST['lp_id']);
  543. require 'lp_list.php';
  544. }
  545. break;
  546. case 'move_lp_down': //change lp published status (visibility on homepage)
  547. if (!$is_allowed_to_edit) {
  548. api_not_allowed(true);
  549. }
  550. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  551. if (!$lp_found) {
  552. error_log('New LP - No learnpath given for publish', 0);
  553. require 'lp_list.php';
  554. } else {
  555. learnpath::move_down($_REQUEST['lp_id']);
  556. require 'lp_list.php';
  557. }
  558. break;
  559. case 'edit':
  560. if (!$is_allowed_to_edit) {
  561. api_not_allowed(true);
  562. }
  563. if ($debug > 0) error_log('New LP - edit action triggered', 0);
  564. if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
  565. else {
  566. $_SESSION['refresh'] = 1;
  567. require 'lp_edit.php';
  568. }
  569. break;
  570. case 'update_lp':
  571. if (!$is_allowed_to_edit) {
  572. api_not_allowed(true);
  573. }
  574. if ($debug > 0) error_log('New LP - update_lp action triggered', 0);
  575. if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
  576. else {
  577. $_SESSION['refresh'] = 1;
  578. $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
  579. $_SESSION['oLP']->set_name($lp_name);
  580. $author = $_REQUEST['lp_author'];
  581. // Fixing the author name (no body or html tags).
  582. $auth_init = stripos($author, '<p>');
  583. if ($auth_init === false) {
  584. $auth_init = stripos($author, '<body>');
  585. $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
  586. $len = $auth_end - $auth_init + 6;
  587. } else {
  588. $auth_end = strripos($author, '</p>');
  589. $len = $auth_end - $auth_init + 4;
  590. }
  591. $author_fixed = substr($author, $auth_init, $len);
  592. //$author_fixed = $author;
  593. $_SESSION['oLP']->set_author($author_fixed);
  594. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']); // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
  595. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  596. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  597. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  598. $_SESSION['oLP']->set_hide_toc_frame($_REQUEST['hide_toc_frame']);
  599. $_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
  600. $_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
  601. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  602. $publicated_on = $_REQUEST['publicated_on'];
  603. $publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
  604. } else {
  605. $publicated_on = null;
  606. }
  607. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  608. $expired_on = $_REQUEST['expired_on'];
  609. $expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
  610. } else {
  611. $expired_on = null;
  612. }
  613. $_SESSION['oLP']->set_modified_on();
  614. $_SESSION['oLP']->set_publicated_on($publicated_on);
  615. $_SESSION['oLP']->set_expired_on($expired_on);
  616. if ($_REQUEST['remove_picture']) {
  617. $_SESSION['oLP']->delete_lp_image();
  618. }
  619. if ($_FILES['lp_preview_image']['size'] > 0)
  620. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  621. if (api_get_setting('search_enabled') === 'true') {
  622. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  623. $specific_fields = get_specific_field_list();
  624. foreach ($specific_fields as $specific_field) {
  625. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  626. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  627. if (!empty($new_values)) {
  628. array_walk($new_values, 'trim');
  629. delete_all_specific_field_value(api_get_course_id(), $specific_field['id'], TOOL_LEARNPATH, $_SESSION['oLP']->lp_id);
  630. foreach ($new_values as $value) {
  631. if (!empty($value)) {
  632. add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $_SESSION['oLP']->lp_id, $value);
  633. }
  634. }
  635. }
  636. }
  637. }
  638. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  639. header('Location: '.$url);
  640. exit;
  641. }
  642. break;
  643. case 'add_sub_item': // Add an item inside a chapter.
  644. if (!$is_allowed_to_edit) {
  645. api_not_allowed(true);
  646. }
  647. if ($debug > 0) error_log('New LP - add sub item action triggered', 0);
  648. if (!$lp_found) { error_log('New LP - No learnpath given for add sub item', 0); require 'lp_list.php'; }
  649. else {
  650. $_SESSION['refresh'] = 1;
  651. if (!empty($_REQUEST['parent_item_id'])) {
  652. $_SESSION['from_learnpath']='yes';
  653. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.Security::remove_XSS($_REQUEST['lp_id']);
  654. require 'resourcelinker.php';
  655. //$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'], $_REQUEST['previous'], $_REQUEST['type'], $_REQUEST['path'], $_REQUEST['title']);
  656. } else {
  657. require 'lp_admin_view.php';
  658. }
  659. }
  660. break;
  661. case 'deleteitem':
  662. case 'delete_item':
  663. if (!$is_allowed_to_edit) {
  664. api_not_allowed(true);
  665. }
  666. if ($debug > 0) error_log('New LP - delete item action triggered', 0);
  667. if (!$lp_found) { error_log('New LP - No learnpath given for delete item', 0); require 'lp_list.php'; }
  668. else {
  669. //$_SESSION['refresh'] = 1;
  670. if (!empty($_REQUEST['id'])) {
  671. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  672. }
  673. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']);
  674. header('Location: '.$url);
  675. exit;
  676. }
  677. break;
  678. case 'edititemprereq':
  679. case 'edit_item_prereq':
  680. if (!$is_allowed_to_edit) {
  681. api_not_allowed(true);
  682. }
  683. if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  684. if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
  685. else {
  686. if (!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])) {
  687. $_SESSION['refresh'] = 1;
  688. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'], $_REQUEST['prereq']);
  689. }
  690. require 'lp_admin_view.php';
  691. }
  692. break;
  693. case 'restart':
  694. if ($debug > 0) error_log('New LP - restart action triggered', 0);
  695. if (!$lp_found) { error_log('New LP - No learnpath given for restart', 0); require 'lp_list.php'; }
  696. else {
  697. $_SESSION['oLP']->restart();
  698. require 'lp_view.php';
  699. }
  700. break;
  701. case 'last':
  702. if ($debug > 0) error_log('New LP - last action triggered', 0);
  703. if (!$lp_found) { error_log('New LP - No learnpath given for last', 0); require 'lp_list.php'; }
  704. else {
  705. $_SESSION['oLP']->last();
  706. require 'lp_view.php';
  707. }
  708. break;
  709. case 'first':
  710. if ($debug > 0) error_log('New LP - first action triggered', 0);
  711. if (!$lp_found) { error_log('New LP - No learnpath given for first', 0); require 'lp_list.php'; }
  712. else {
  713. $_SESSION['oLP']->first();
  714. require 'lp_view.php';
  715. }
  716. break;
  717. case 'next':
  718. if ($debug > 0) error_log('New LP - next action triggered', 0);
  719. if (!$lp_found) { error_log('New LP - No learnpath given for next', 0); require 'lp_list.php'; }
  720. else {
  721. $_SESSION['oLP']->next();
  722. require 'lp_view.php';
  723. }
  724. break;
  725. case 'previous':
  726. if ($debug > 0) error_log('New LP - previous action triggered', 0);
  727. if (!$lp_found) { error_log('New LP - No learnpath given for previous', 0); require 'lp_list.php'; }
  728. else {
  729. $_SESSION['oLP']->previous();
  730. require 'lp_view.php';
  731. }
  732. break;
  733. case 'content':
  734. if ($debug > 0) error_log('New LP - content action triggered', 0);
  735. if ($debug > 0) error_log('New LP - Item id is '.$_GET['item_id'], 0);
  736. if (!$lp_found) { error_log('New LP - No learnpath given for content', 0); require 'lp_list.php'; }
  737. else {
  738. $_SESSION['oLP']->save_last();
  739. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  740. $_SESSION['oLP']->start_current_item();
  741. require 'lp_content.php';
  742. }
  743. break;
  744. case 'view':
  745. if ($debug > 0)
  746. error_log('New LP - view action triggered', 0);
  747. if (!$lp_found) {
  748. error_log('New LP - No learnpath given for view', 0);
  749. require 'lp_list.php';
  750. } else {
  751. if ($debug > 0) {error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0); }
  752. if ( !empty($_REQUEST['item_id']) ) {
  753. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  754. }
  755. require 'lp_view.php';
  756. }
  757. break;
  758. case 'save':
  759. if ($debug > 0) error_log('New LP - save action triggered', 0);
  760. if (!$lp_found) { error_log('New LP - No learnpath given for save', 0); require 'lp_list.php'; }
  761. else {
  762. $_SESSION['oLP']->save_item();
  763. require 'lp_save.php';
  764. }
  765. break;
  766. case 'stats':
  767. if ($debug > 0) error_log('New LP - stats action triggered', 0);
  768. if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
  769. else {
  770. $_SESSION['oLP']->save_current();
  771. $_SESSION['oLP']->save_last();
  772. require 'lp_stats.php';
  773. }
  774. break;
  775. case 'list':
  776. if ($debug > 0) error_log('New LP - list action triggered', 0);
  777. if ($lp_found) {
  778. $_SESSION['refresh'] = 1;
  779. $_SESSION['oLP']->save_last();
  780. }
  781. require 'lp_list.php';
  782. break;
  783. case 'mode':
  784. // Switch between fullscreen and embedded mode.
  785. if ($debug > 0) error_log('New LP - mode change triggered', 0);
  786. $mode = $_REQUEST['mode'];
  787. if ($mode == 'fullscreen') {
  788. $_SESSION['oLP']->mode = 'fullscreen';
  789. } elseif ($mode == 'embedded') {
  790. $_SESSION['oLP']->mode = 'embedded';
  791. } elseif ($mode == 'embedframe') {
  792. $_SESSION['oLP']->mode = 'embedframe';
  793. }
  794. require 'lp_view.php';
  795. break;
  796. case 'switch_view_mode':
  797. if ($debug > 0) error_log('New LP - switch_view_mode action triggered', 0);
  798. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  799. $_SESSION['refresh'] = 1;
  800. $_SESSION['oLP']->update_default_view_mode();
  801. require 'lp_list.php';
  802. break;
  803. case 'switch_force_commit':
  804. if ($debug > 0) error_log('New LP - switch_force_commit action triggered', 0);
  805. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  806. $_SESSION['refresh'] = 1;
  807. $_SESSION['oLP']->update_default_scorm_commit();
  808. require 'lp_list.php';
  809. break;
  810. /* Those 2 switches have been replaced by switc_attempt_mode switch
  811. case 'switch_reinit':
  812. if ($debug > 0) error_log('New LP - switch_reinit action triggered', 0);
  813. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  814. $_SESSION['refresh'] = 1;
  815. $_SESSION['oLP']->update_reinit();
  816. require 'lp_list.php';
  817. break;
  818. case 'switch_seriousgame_mode':
  819. if($debug>0) error_log('New LP - switch_seriousgame_mode action triggered',0);
  820. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
  821. $_SESSION['refresh'] = 1;
  822. $_SESSION['oLP']->set_seriousgame_mode();
  823. require 'lp_list.php';
  824. break;
  825. */
  826. case 'switch_attempt_mode':
  827. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  828. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
  829. $_SESSION['refresh'] = 1;
  830. $_SESSION['oLP']->switch_attempt_mode();
  831. require 'lp_list.php';
  832. break;
  833. case 'switch_scorm_debug':
  834. if ($debug > 0) error_log('New LP - switch_scorm_debug action triggered', 0);
  835. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  836. $_SESSION['refresh'] = 1;
  837. $_SESSION['oLP']->update_scorm_debug();
  838. require 'lp_list.php';
  839. break;
  840. case 'intro_cmdAdd':
  841. if ($debug > 0) error_log('New LP - intro_cmdAdd action triggered', 0);
  842. // Add introduction section page.
  843. break;
  844. case 'js_api_refresh':
  845. if ($debug > 0) error_log('New LP - js_api_refresh action triggered', 0);
  846. if (!$lp_found) { error_log('New LP - No learnpath given for js_api_refresh', 0); require 'lp_message.php'; }
  847. if (isset($_REQUEST['item_id'])) {
  848. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  849. }
  850. require 'lp_message.php';
  851. break;
  852. case 'return_to_course_homepage':
  853. if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
  854. else {
  855. $_SESSION['oLP']->save_current();
  856. $_SESSION['oLP']->save_last();
  857. header('location: '.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/?id_session='.api_get_session_id());
  858. exit;
  859. }
  860. break;
  861. case 'search':
  862. /* Include the search script, it's smart enough to know when we are
  863. * searching or not.
  864. */
  865. require 'lp_list_search.php';
  866. break;
  867. case 'impress':
  868. if ($debug > 0)
  869. error_log('New LP - view action triggered', 0);
  870. if (!$lp_found) {
  871. error_log('New LP - No learnpath given for view', 0);
  872. require 'lp_list.php';
  873. } else {
  874. if ($debug > 0) {error_log('New LP - Trying to impress this LP item to ' . $_REQUEST['item_id'], 0); }
  875. if ( !empty($_REQUEST['item_id']) ) {
  876. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  877. }
  878. require 'lp_impress.php';
  879. }
  880. break;
  881. default:
  882. if ($debug > 0) error_log('New LP - default action triggered', 0);
  883. //$_SESSION['refresh'] = 1;
  884. require 'lp_list.php';
  885. break;
  886. }
  887. if (!empty($_SESSION['oLP'])) {
  888. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  889. if ($debug > 0) error_log('New LP - lpobject is serialized in session', 0);
  890. }