lp_controller.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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 '../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. 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. if (isset($_SESSION['oLP'])) {
  178. $_SESSION['oLP']->update_queue = array(); // Reinitialises array used by javascript to update items in the TOC.
  179. $_SESSION['oLP']->message = ''; // Should use ->clear_message() method but doesn't work.
  180. }
  181. if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
  182. if ($_REQUEST['action'] != 'list' AND $_REQUEST['action'] != 'view') {
  183. if (!empty($_REQUEST['lp_id'])) {
  184. $_REQUEST['action'] = 'view';
  185. } else {
  186. $_REQUEST['action'] = 'list';
  187. }
  188. }
  189. } else {
  190. if ($is_allowed_to_edit) {
  191. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'view' && !isset($_REQUEST['exeId'])) {
  192. $_REQUEST['action'] = 'build';
  193. }
  194. $_SESSION['studentview'] = null;
  195. }
  196. }
  197. $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : '');
  198. switch ($action) {
  199. case 'add_item':
  200. if (!$is_allowed_to_edit) {
  201. api_not_allowed(true);
  202. }
  203. if ($debug > 0) error_log('New LP - add item action triggered', 0);
  204. if (!$lp_found) {
  205. //check if the learnpath ID was defined, otherwise send back to list
  206. if ($debug > 0) error_log('New LP - No learnpath given for add item', 0);
  207. require 'lp_list.php';
  208. } else {
  209. $_SESSION['refresh'] = 1;
  210. if (isset($_POST['submit_button']) && !empty($_POST['title'])) {
  211. // If a title was sumbitted:
  212. //Updating the lp.modified_on
  213. $_SESSION['oLP']->set_modified_on();
  214. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
  215. // Check post_time to ensure ??? (counter-hacking measure?)
  216. require 'lp_add_item.php';
  217. } else {
  218. $_SESSION['post_time'] = $_POST['post_time'];
  219. if ($_POST['type'] == TOOL_DOCUMENT) {
  220. if (isset($_POST['path']) && $_GET['edit'] != 'true') {
  221. $document_id = $_POST['path'];
  222. } else {
  223. $document_id = $_SESSION['oLP']->create_document($_course);
  224. }
  225. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $document_id, $_POST['title'], $_POST['description'], $_POST['prerequisites']);
  226. } else {
  227. // For all other item types than documents, load the item using the item type and path rather than its ID.
  228. $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $_POST['path'], $_POST['title'], $_POST['description'], $_POST['prerequisites'], $_POST['maxTimeAllowed']);
  229. }
  230. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  231. header('Location: '.$url);
  232. exit;
  233. }
  234. } else {
  235. require 'lp_add_item.php';
  236. }
  237. }
  238. break;
  239. case 'add_audio':
  240. if (!$is_allowed_to_edit) {
  241. api_not_allowed(true);
  242. }
  243. if ($debug > 0) error_log('New LP - add audio action triggered', 0);
  244. if (!$lp_found) {
  245. //check if the learnpath ID was defined, otherwise send back to list
  246. if ($debug > 0) error_log('New LP - No learnpath given for add audio', 0);
  247. require 'lp_list.php';
  248. } else {
  249. $_SESSION['refresh'] = 1;
  250. if (isset($_REQUEST['id'])) {
  251. $lp_item_obj = new learnpathItem($_REQUEST['id']);
  252. //Remove audio
  253. if (isset($_POST['delete_file']) && $_POST['delete_file'] == 1) {
  254. $lp_item_obj->remove_audio();
  255. }
  256. //Upload audio
  257. if (isset($_FILES['file']) && !empty($_FILES['file'])) {
  258. //Updating the lp.modified_on
  259. $_SESSION['oLP']->set_modified_on();
  260. $lp_item_obj->add_audio();
  261. }
  262. //Add audio file from documents
  263. if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
  264. $_SESSION['oLP']->set_modified_on();
  265. $lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
  266. }
  267. // Display.
  268. require 'lp_add_audio.php';
  269. } else {
  270. require 'lp_add_audio.php';
  271. }
  272. }
  273. break;
  274. case 'add_lp_category':
  275. if (!$is_allowed_to_edit) {
  276. api_not_allowed(true);
  277. }
  278. require 'lp_add_category.php';
  279. break;
  280. case 'move_up_category':
  281. if (!$is_allowed_to_edit) {
  282. api_not_allowed(true);
  283. }
  284. if (isset($_REQUEST['id'])) {
  285. learnpath::move_up_category($_REQUEST['id']);
  286. }
  287. require 'lp_list.php';
  288. break;
  289. case 'move_down_category':
  290. if (!$is_allowed_to_edit) {
  291. api_not_allowed(true);
  292. }
  293. if (isset($_REQUEST['id'])) {
  294. learnpath::move_down_category($_REQUEST['id']);
  295. }
  296. require 'lp_list.php';
  297. break;
  298. case 'delete_lp_category':
  299. if (!$is_allowed_to_edit) {
  300. api_not_allowed(true);
  301. }
  302. if (isset($_REQUEST['id'])) {
  303. learnpath::delete_category($_REQUEST['id']);
  304. }
  305. require 'lp_list.php';
  306. break;
  307. case 'add_lp':
  308. if (!$is_allowed_to_edit) {
  309. api_not_allowed(true);
  310. }
  311. if ($debug > 0) error_log('New LP - add_lp action triggered', 0);
  312. if (isset($_REQUEST['lp_name']) && !empty($_REQUEST['lp_name'])) {
  313. $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
  314. $_SESSION['refresh'] = 1;
  315. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
  316. require 'lp_add.php';
  317. } else {
  318. $_SESSION['post_time'] = $_REQUEST['post_time'];
  319. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  320. $publicated_on = $_REQUEST['publicated_on'];
  321. $publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
  322. } else {
  323. $publicated_on = null;
  324. }
  325. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  326. $expired_on = $_REQUEST['expired_on'];
  327. $expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
  328. } else {
  329. $expired_on = null;
  330. }
  331. $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']);
  332. if (is_numeric($new_lp_id)) {
  333. // TODO: Maybe create a first module directly to avoid bugging the user with useless queries
  334. $_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
  335. //require 'lp_build.php';
  336. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id);
  337. header('Location: '.$url);
  338. exit;
  339. }
  340. }
  341. } else {
  342. require 'lp_add.php';
  343. }
  344. break;
  345. case 'admin_view':
  346. if (!$is_allowed_to_edit) {
  347. api_not_allowed(true);
  348. }
  349. if ($debug > 0) error_log('New LP - admin_view action triggered', 0);
  350. if (!$lp_found) { error_log('New LP - No learnpath given for admin_view', 0); require 'lp_list.php'; }
  351. else {
  352. $_SESSION['refresh'] = 1;
  353. require 'lp_admin_view.php';
  354. }
  355. break;
  356. case 'auto_launch':
  357. if (api_get_course_setting('enable_lp_auto_launch') == 1) { //Redirect to a specific LP
  358. if (!$is_allowed_to_edit) {
  359. api_not_allowed(true);
  360. }
  361. if ($debug > 0) error_log('New LP - auto_launch action triggered', 0);
  362. if (!$lp_found) { error_log('New LP - No learnpath given for set_autolunch', 0); require 'lp_list.php'; }
  363. else {
  364. $_SESSION['oLP']->set_autolunch($_GET['lp_id'], $_GET['status']);
  365. require 'lp_list.php';
  366. exit;
  367. }
  368. }
  369. break;
  370. case 'build':
  371. if (!$is_allowed_to_edit) {
  372. api_not_allowed(true);
  373. }
  374. if ($debug > 0) error_log('New LP - build action triggered', 0);
  375. if (!$lp_found) { error_log('New LP - No learnpath given for build', 0); require 'lp_list.php'; }
  376. else {
  377. $_SESSION['refresh'] = 1;
  378. //require 'lp_build.php';
  379. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  380. header('Location: '.$url);
  381. exit;
  382. }
  383. break;
  384. case 'edit_item':
  385. if (!$is_allowed_to_edit) {
  386. api_not_allowed(true);
  387. }
  388. if ($debug > 0) error_log('New LP - edit item action triggered', 0);
  389. if (!$lp_found) { error_log('New LP - No learnpath given for edit item', 0); require 'lp_list.php'; }
  390. else {
  391. $_SESSION['refresh'] = 1;
  392. if (isset($_POST['submit_button']) && !empty($_POST['title'])) {
  393. //Updating the lp.modified_on
  394. $_SESSION['oLP']->set_modified_on();
  395. // TODO: mp3 edit
  396. $audio = array();
  397. if (isset($_FILES['mp3'])) {
  398. $audio = $_FILES['mp3'];
  399. }
  400. $_SESSION['oLP']->edit_item($_REQUEST['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites'], $audio, $_POST['maxTimeAllowed']);
  401. if (isset($_POST['content_lp'])) {
  402. $_SESSION['oLP']->edit_document($_course);
  403. }
  404. $is_success = true;
  405. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  406. header('Location: '.$url);
  407. exit;
  408. }
  409. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  410. require 'lp_edit_item.php';
  411. } else {
  412. require 'lp_admin_view.php';
  413. }
  414. }
  415. break;
  416. case 'edit_item_prereq':
  417. if (!$is_allowed_to_edit) {
  418. api_not_allowed(true);
  419. }
  420. if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  421. if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
  422. else {
  423. if (isset($_POST['submit_button'])) {
  424. //Updating the lp.modified_on
  425. $_SESSION['oLP']->set_modified_on();
  426. $_SESSION['refresh'] = 1;
  427. if ($_SESSION['oLP']->edit_item_prereq($_GET['id'], $_POST['prerequisites'], $_POST['min_' . $_POST['prerequisites']], $_POST['max_' . $_POST['prerequisites']])) {
  428. $is_success = true;
  429. }
  430. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  431. header('Location: '.$url);
  432. exit;
  433. } else {
  434. require 'lp_edit_item_prereq.php';
  435. }
  436. }
  437. break;
  438. case 'move_item':
  439. if (!$is_allowed_to_edit) {
  440. api_not_allowed(true);
  441. }
  442. if ($debug > 0) error_log('New LP - move item action triggered', 0);
  443. if (!$lp_found) { error_log('New LP - No learnpath given for move item', 0); require 'lp_list.php'; }
  444. else {
  445. $_SESSION['refresh'] = 1;
  446. if (isset($_POST['submit_button'])) {
  447. //Updating the lp.modified_on
  448. $_SESSION['oLP']->set_modified_on();
  449. $_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description']);
  450. $is_success = true;
  451. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  452. header('Location: '.$url);
  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().'/?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. break;
  942. case 'clear_prerequisites':
  943. $_SESSION['oLP']->clear_prerequisites();
  944. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated";
  945. header('Location: '.$url);
  946. break;
  947. default:
  948. if ($debug > 0) error_log('New LP - default action triggered', 0);
  949. require 'lp_list.php';
  950. break;
  951. }
  952. if (!empty($_SESSION['oLP'])) {
  953. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  954. if ($debug > 0) error_log('New LP - lpobject is serialized in session', 0);
  955. }