lp_controller.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  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. exit;
  454. }
  455. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  456. require 'lp_move_item.php';
  457. } else {
  458. // Avoids weird behaviours see CT#967.
  459. $check = Security::check_token('get');
  460. if ($check) {
  461. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  462. }
  463. Security::clear_token();
  464. require 'lp_admin_view.php';
  465. }
  466. }
  467. break;
  468. case 'view_item':
  469. if (!$is_allowed_to_edit) {
  470. api_not_allowed(true);
  471. }
  472. if ($debug > 0) error_log('New LP - view_item action triggered', 0);
  473. if (!$lp_found) {
  474. error_log('New LP - No learnpath given for view item', 0); require 'lp_list.php';
  475. } else {
  476. $_SESSION['refresh'] = 1;
  477. require 'lp_view_item.php';
  478. }
  479. break;
  480. case 'upload':
  481. if (!$is_allowed_to_edit) {
  482. api_not_allowed(true);
  483. }
  484. if ($debug > 0) error_log('New LP - upload action triggered', 0);
  485. $cwdir = getcwd();
  486. require 'lp_upload.php';
  487. // Reinit current working directory as many functions in upload change it.
  488. chdir($cwdir);
  489. require 'lp_list.php';
  490. break;
  491. case 'copy':
  492. if (!$is_allowed_to_edit) {
  493. api_not_allowed(true);
  494. }
  495. if ($debug > 0) error_log('New LP - export action triggered', 0);
  496. if (!$lp_found) { error_log('New LP - No learnpath given for copy', 0); require 'lp_list.php'; }
  497. else {
  498. $_SESSION['oLP']->copy();
  499. }
  500. require 'lp_list.php';
  501. break;
  502. case 'export':
  503. if (!$is_allowed_to_edit) {
  504. api_not_allowed(true);
  505. }
  506. if ($debug > 0) error_log('New LP - export action triggered', 0);
  507. if (!$lp_found) { error_log('New LP - No learnpath given for export', 0); require 'lp_list.php'; }
  508. else {
  509. $_SESSION['oLP']->scorm_export();
  510. exit();
  511. //require 'lp_list.php';
  512. }
  513. break;
  514. case 'export_to_pdf':
  515. if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
  516. api_not_allowed();
  517. }
  518. if ($debug > 0) error_log('New LP - export action triggered', 0);
  519. if (!$lp_found) { error_log('New LP - No learnpath given for export_to_pdf', 0); require 'lp_list.php';
  520. } else {
  521. $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
  522. if (!$result) {
  523. require 'lp_list.php';
  524. }
  525. exit;
  526. }
  527. break;
  528. case 'delete':
  529. if (!$is_allowed_to_edit) {
  530. api_not_allowed(true);
  531. }
  532. if ($debug > 0) error_log('New LP - delete action triggered', 0);
  533. if (!$lp_found) { error_log('New LP - No learnpath given for delete', 0); require 'lp_list.php'; }
  534. else {
  535. $_SESSION['refresh'] = 1;
  536. // Remove lp from homepage if it is there.
  537. //$_SESSION['oLP']->toggle_visibility((int)$_GET['lp_id'],'i');
  538. $_SESSION['oLP']->delete(null,(int)$_GET['lp_id'],'remove');
  539. Session::erase('oLP');
  540. require 'lp_list.php';
  541. }
  542. break;
  543. case 'toggle_visible': // Change lp visibility (inside lp tool).
  544. if (!$is_allowed_to_edit) {
  545. api_not_allowed(true);
  546. }
  547. if ($debug > 0) error_log('New LP - visibility action triggered', 0);
  548. if (!$lp_found) { error_log('New LP - No learnpath given for visibility', 0); require 'lp_list.php'; }
  549. else {
  550. learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
  551. require 'lp_list.php';
  552. }
  553. break;
  554. case 'toggle_publish': // Change lp published status (visibility on homepage).
  555. if (!$is_allowed_to_edit) {
  556. api_not_allowed(true);
  557. }
  558. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  559. if (!$lp_found) { error_log('New LP - No learnpath given for publish', 0); require 'lp_list.php'; }
  560. else {
  561. learnpath::toggle_publish($_REQUEST['lp_id'],$_REQUEST['new_status']);
  562. require 'lp_list.php';
  563. }
  564. break;
  565. case 'move_lp_up': // Change lp published status (visibility on homepage)
  566. if (!$is_allowed_to_edit) {
  567. api_not_allowed(true);
  568. }
  569. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  570. if (!$lp_found) {
  571. error_log('New LP - No learnpath given for publish', 0);
  572. require 'lp_list.php';
  573. } else {
  574. learnpath::move_up($_REQUEST['lp_id']);
  575. require 'lp_list.php';
  576. }
  577. break;
  578. case 'move_lp_down': //change lp published status (visibility on homepage)
  579. if (!$is_allowed_to_edit) {
  580. api_not_allowed(true);
  581. }
  582. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  583. if (!$lp_found) {
  584. error_log('New LP - No learnpath given for publish', 0);
  585. require 'lp_list.php';
  586. } else {
  587. learnpath::move_down($_REQUEST['lp_id']);
  588. require 'lp_list.php';
  589. }
  590. break;
  591. case 'edit':
  592. if (!$is_allowed_to_edit) {
  593. api_not_allowed(true);
  594. }
  595. if ($debug > 0) error_log('New LP - edit action triggered', 0);
  596. if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
  597. else {
  598. $_SESSION['refresh'] = 1;
  599. require 'lp_edit.php';
  600. }
  601. break;
  602. case 'update_lp':
  603. if (!$is_allowed_to_edit) {
  604. api_not_allowed(true);
  605. }
  606. if ($debug > 0) error_log('New LP - update_lp action triggered', 0);
  607. if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
  608. else {
  609. $_SESSION['refresh'] = 1;
  610. $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
  611. $_SESSION['oLP']->set_name($lp_name);
  612. $author = $_REQUEST['lp_author'];
  613. // Fixing the author name (no body or html tags).
  614. $auth_init = stripos($author, '<p>');
  615. if ($auth_init === false) {
  616. $auth_init = stripos($author, '<body>');
  617. $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
  618. $len = $auth_end - $auth_init + 6;
  619. } else {
  620. $auth_end = strripos($author, '</p>');
  621. $len = $auth_end - $auth_init + 4;
  622. }
  623. $author_fixed = substr($author, $auth_init, $len);
  624. //$author_fixed = $author;
  625. $_SESSION['oLP']->set_author($author_fixed);
  626. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']); // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
  627. if (isset($_REQUEST['lp_maker'])) {
  628. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  629. }
  630. if (isset($_REQUEST['lp_proximity'])) {
  631. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  632. }
  633. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  634. if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
  635. $hide_toc_frame = $_REQUEST['hide_toc_frame'];
  636. } else {
  637. $hide_toc_frame = null;
  638. }
  639. $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
  640. $_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
  641. $_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
  642. $_SESSION['oLP']->set_subscribe_users($_REQUEST['subscribe_users']);
  643. $_SESSION['oLP']->set_max_attempts($_REQUEST['max_attempts']);
  644. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  645. $publicated_on = $_REQUEST['publicated_on'];
  646. $publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
  647. } else {
  648. $publicated_on = null;
  649. }
  650. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  651. $expired_on = $_REQUEST['expired_on'];
  652. $expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
  653. } else {
  654. $expired_on = null;
  655. }
  656. $_SESSION['oLP']->set_category_id($_REQUEST['category_id']);
  657. $_SESSION['oLP']->set_modified_on();
  658. $_SESSION['oLP']->set_publicated_on($publicated_on);
  659. $_SESSION['oLP']->set_expired_on($expired_on);
  660. if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
  661. $_SESSION['oLP']->delete_lp_image();
  662. }
  663. if ($_FILES['lp_preview_image']['size'] > 0)
  664. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  665. if (api_get_setting('search_enabled') === 'true') {
  666. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  667. $specific_fields = get_specific_field_list();
  668. foreach ($specific_fields as $specific_field) {
  669. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  670. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  671. if (!empty($new_values)) {
  672. array_walk($new_values, 'trim');
  673. delete_all_specific_field_value(api_get_course_id(), $specific_field['id'], TOOL_LEARNPATH, $_SESSION['oLP']->lp_id);
  674. foreach ($new_values as $value) {
  675. if (!empty($value)) {
  676. add_specific_field_value($specific_field['id'], api_get_course_id(), TOOL_LEARNPATH, $_SESSION['oLP']->lp_id, $value);
  677. }
  678. }
  679. }
  680. }
  681. }
  682. $referer = isset($_REQUEST['referer']) ? $_REQUEST['referer'] : 'add_item';
  683. switch ($referer) {
  684. case 'lplist':
  685. $url = api_get_self().'?action=list&'.api_get_cidreq();
  686. break;
  687. default:
  688. case 'add_item':
  689. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  690. break;
  691. }
  692. header('Location: '.$url);
  693. exit;
  694. }
  695. break;
  696. case 'add_sub_item': // Add an item inside a chapter.
  697. if (!$is_allowed_to_edit) {
  698. api_not_allowed(true);
  699. }
  700. if ($debug > 0) error_log('New LP - add sub item action triggered', 0);
  701. if (!$lp_found) { error_log('New LP - No learnpath given for add sub item', 0); require 'lp_list.php'; }
  702. else {
  703. $_SESSION['refresh'] = 1;
  704. if (!empty($_REQUEST['parent_item_id'])) {
  705. $_SESSION['from_learnpath']='yes';
  706. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.Security::remove_XSS($_REQUEST['lp_id']);
  707. require 'resourcelinker.php';
  708. //$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'], $_REQUEST['previous'], $_REQUEST['type'], $_REQUEST['path'], $_REQUEST['title']);
  709. } else {
  710. require 'lp_admin_view.php';
  711. }
  712. }
  713. break;
  714. case 'deleteitem':
  715. case 'delete_item':
  716. if (!$is_allowed_to_edit) {
  717. api_not_allowed(true);
  718. }
  719. if ($debug > 0) error_log('New LP - delete item action triggered', 0);
  720. if (!$lp_found) { error_log('New LP - No learnpath given for delete item', 0); require 'lp_list.php'; }
  721. else {
  722. //$_SESSION['refresh'] = 1;
  723. if (!empty($_REQUEST['id'])) {
  724. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  725. }
  726. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']);
  727. header('Location: '.$url);
  728. exit;
  729. }
  730. break;
  731. case 'edititemprereq':
  732. case 'edit_item_prereq':
  733. if (!$is_allowed_to_edit) {
  734. api_not_allowed(true);
  735. }
  736. if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  737. if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
  738. else {
  739. if (!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])) {
  740. $_SESSION['refresh'] = 1;
  741. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'], $_REQUEST['prereq']);
  742. }
  743. require 'lp_admin_view.php';
  744. }
  745. break;
  746. case 'restart':
  747. if ($debug > 0) error_log('New LP - restart action triggered', 0);
  748. if (!$lp_found) { error_log('New LP - No learnpath given for restart', 0); require 'lp_list.php'; }
  749. else {
  750. $_SESSION['oLP']->restart();
  751. require 'lp_view.php';
  752. }
  753. break;
  754. case 'last':
  755. if ($debug > 0) error_log('New LP - last action triggered', 0);
  756. if (!$lp_found) { error_log('New LP - No learnpath given for last', 0); require 'lp_list.php'; }
  757. else {
  758. $_SESSION['oLP']->last();
  759. require 'lp_view.php';
  760. }
  761. break;
  762. case 'first':
  763. if ($debug > 0) error_log('New LP - first action triggered', 0);
  764. if (!$lp_found) { error_log('New LP - No learnpath given for first', 0); require 'lp_list.php'; }
  765. else {
  766. $_SESSION['oLP']->first();
  767. require 'lp_view.php';
  768. }
  769. break;
  770. case 'next':
  771. if ($debug > 0) error_log('New LP - next action triggered', 0);
  772. if (!$lp_found) { error_log('New LP - No learnpath given for next', 0); require 'lp_list.php'; }
  773. else {
  774. $_SESSION['oLP']->next();
  775. require 'lp_view.php';
  776. }
  777. break;
  778. case 'previous':
  779. if ($debug > 0) error_log('New LP - previous action triggered', 0);
  780. if (!$lp_found) { error_log('New LP - No learnpath given for previous', 0); require 'lp_list.php'; }
  781. else {
  782. $_SESSION['oLP']->previous();
  783. require 'lp_view.php';
  784. }
  785. break;
  786. case 'content':
  787. if ($debug > 0) error_log('New LP - content action triggered', 0);
  788. if ($debug > 0) error_log('New LP - Item id is '.$_GET['item_id'], 0);
  789. if (!$lp_found) { error_log('New LP - No learnpath given for content', 0); require 'lp_list.php'; }
  790. else {
  791. $_SESSION['oLP']->save_last();
  792. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  793. $_SESSION['oLP']->start_current_item();
  794. require 'lp_content.php';
  795. }
  796. break;
  797. case 'view':
  798. if ($debug > 0)
  799. error_log('New LP - view action triggered', 0);
  800. if (!$lp_found) {
  801. error_log('New LP - No learnpath given for view', 0);
  802. require 'lp_list.php';
  803. } else {
  804. if ($debug > 0) {error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0); }
  805. if ( !empty($_REQUEST['item_id']) ) {
  806. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  807. }
  808. require 'lp_view.php';
  809. }
  810. break;
  811. case 'save':
  812. if ($debug > 0) error_log('New LP - save action triggered', 0);
  813. if (!$lp_found) { error_log('New LP - No learnpath given for save', 0); require 'lp_list.php'; }
  814. else {
  815. $_SESSION['oLP']->save_item();
  816. require 'lp_save.php';
  817. }
  818. break;
  819. case 'stats':
  820. if ($debug > 0) error_log('New LP - stats action triggered', 0);
  821. if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
  822. else {
  823. $_SESSION['oLP']->save_current();
  824. $_SESSION['oLP']->save_last();
  825. require 'lp_stats.php';
  826. }
  827. break;
  828. case 'list':
  829. if ($debug > 0) error_log('New LP - list action triggered', 0);
  830. if ($lp_found) {
  831. $_SESSION['refresh'] = 1;
  832. $_SESSION['oLP']->save_last();
  833. }
  834. require 'lp_list.php';
  835. break;
  836. case 'mode':
  837. // Switch between fullscreen and embedded mode.
  838. if ($debug > 0) error_log('New LP - mode change triggered', 0);
  839. $mode = $_REQUEST['mode'];
  840. if ($mode == 'fullscreen') {
  841. $_SESSION['oLP']->mode = 'fullscreen';
  842. } elseif ($mode == 'embedded') {
  843. $_SESSION['oLP']->mode = 'embedded';
  844. } elseif ($mode == 'embedframe') {
  845. $_SESSION['oLP']->mode = 'embedframe';
  846. } elseif ($mode == 'impress') {
  847. $_SESSION['oLP']->mode = 'impress';
  848. }
  849. require 'lp_view.php';
  850. break;
  851. case 'switch_view_mode':
  852. if ($debug > 0) error_log('New LP - switch_view_mode action triggered', 0);
  853. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  854. if (Security::check_token('get')) {
  855. $_SESSION['refresh'] = 1;
  856. $_SESSION['oLP']->update_default_view_mode();
  857. }
  858. require 'lp_list.php';
  859. break;
  860. case 'switch_force_commit':
  861. if ($debug > 0) error_log('New LP - switch_force_commit action triggered', 0);
  862. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  863. $_SESSION['refresh'] = 1;
  864. $_SESSION['oLP']->update_default_scorm_commit();
  865. require 'lp_list.php';
  866. break;
  867. /* Those 2 switches have been replaced by switc_attempt_mode switch
  868. case 'switch_reinit':
  869. if ($debug > 0) error_log('New LP - switch_reinit action triggered', 0);
  870. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  871. $_SESSION['refresh'] = 1;
  872. $_SESSION['oLP']->update_reinit();
  873. require 'lp_list.php';
  874. break;
  875. case 'switch_seriousgame_mode':
  876. if($debug>0) error_log('New LP - switch_seriousgame_mode action triggered',0);
  877. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
  878. $_SESSION['refresh'] = 1;
  879. $_SESSION['oLP']->set_seriousgame_mode();
  880. require 'lp_list.php';
  881. break;
  882. */
  883. case 'switch_attempt_mode':
  884. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  885. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
  886. $_SESSION['refresh'] = 1;
  887. $_SESSION['oLP']->switch_attempt_mode();
  888. require 'lp_list.php';
  889. break;
  890. case 'switch_scorm_debug':
  891. if ($debug > 0) error_log('New LP - switch_scorm_debug action triggered', 0);
  892. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  893. $_SESSION['refresh'] = 1;
  894. $_SESSION['oLP']->update_scorm_debug();
  895. require 'lp_list.php';
  896. break;
  897. case 'intro_cmdAdd':
  898. if ($debug > 0) error_log('New LP - intro_cmdAdd action triggered', 0);
  899. // Add introduction section page.
  900. break;
  901. case 'js_api_refresh':
  902. if ($debug > 0) error_log('New LP - js_api_refresh action triggered', 0);
  903. if (!$lp_found) { error_log('New LP - No learnpath given for js_api_refresh', 0); require 'lp_message.php'; }
  904. if (isset($_REQUEST['item_id'])) {
  905. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  906. }
  907. require 'lp_message.php';
  908. break;
  909. case 'return_to_course_homepage':
  910. if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
  911. else {
  912. $_SESSION['oLP']->save_current();
  913. $_SESSION['oLP']->save_last();
  914. header('location: '.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id());
  915. exit;
  916. }
  917. break;
  918. case 'search':
  919. /* Include the search script, it's smart enough to know when we are
  920. * searching or not.
  921. */
  922. require 'lp_list_search.php';
  923. break;
  924. case 'impress':
  925. if ($debug > 0)
  926. error_log('New LP - view action triggered', 0);
  927. if (!$lp_found) {
  928. error_log('New LP - No learnpath given for view', 0);
  929. require 'lp_list.php';
  930. } else {
  931. if ($debug > 0) {error_log('New LP - Trying to impress this LP item to ' . $_REQUEST['item_id'], 0); }
  932. if (!empty($_REQUEST['item_id']) ) {
  933. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  934. }
  935. require 'lp_impress.php';
  936. }
  937. break;
  938. case 'set_previous_step_as_prerequisite':
  939. $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
  940. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated";
  941. header('Location: '.$url);
  942. exit;
  943. break;
  944. case 'clear_prerequisites':
  945. $_SESSION['oLP']->clear_prerequisites();
  946. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated";
  947. header('Location: '.$url);
  948. exit;
  949. break;
  950. default:
  951. if ($debug > 0) error_log('New LP - default action triggered', 0);
  952. require 'lp_list.php';
  953. break;
  954. }
  955. if (!empty($_SESSION['oLP'])) {
  956. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  957. if ($debug > 0) error_log('New LP - lpobject is serialized in session', 0);
  958. }