lp_controller.php 42 KB

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