Completed
Push — master ( 5da9ea...eef579 )
by Angel Fernando Quiroz
50:18 queued 17:36
created
main/lp/storageapi.php 1 patch
Switch Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -15,52 +15,52 @@
 block discarded – undo
15 15
 }
16 16
 
17 17
 switch ($_REQUEST['action']) {
18
-    case "get":
19
-        print storage_get($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
20
-        break;
21
-    case "set":
22
-        if (storage_can_set($_REQUEST['svuser'])) {
23
-            print storage_set($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svvalue']);
24
-        }
25
-        break;
26
-    case "getall":
27
-        print storage_getall($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco']);
28
-        break;
29
-    case "stackpush":
30
-        if (storage_can_set($_REQUEST['svuser'])) {
31
-            print storage_stack_push($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svvalue']);
32
-        }
33
-        break;
34
-    case "stackpop":
35
-        if (storage_can_set($_REQUEST['svuser'])) {
36
-            print storage_stack_pop($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
37
-        }
38
-        break;
39
-    case "stacklength":
40
-        print storage_stack_length($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
41
-        break;
42
-    case "stackclear":
43
-        if (storage_can_set($_REQUEST['svuser'])) {
44
-            print storage_stack_clear($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
45
-        }
46
-        break;
47
-    case "stackgetall":
48
-        if (storage_can_set($_REQUEST['svuser']))
49
-            print storage_stack_getall($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
50
-        break;
51
-    case "getposition":
52
-        print storage_get_position($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svasc']);
53
-        break;
54
-    case "getleaders":
55
-        print storage_get_leaders($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svasc'], $_REQUEST['svlength']);
56
-        break;
57
-    case "usersgetall":
58
-// security issue
59
-        print "NOT allowed, security issue, see sources";
60
-//		print storage_get_all_users();
61
-        break;
62
-    default:
63
-        // Do nothing
18
+        case "get":
19
+            print storage_get($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
20
+            break;
21
+        case "set":
22
+            if (storage_can_set($_REQUEST['svuser'])) {
23
+                print storage_set($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svvalue']);
24
+            }
25
+            break;
26
+        case "getall":
27
+            print storage_getall($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco']);
28
+            break;
29
+        case "stackpush":
30
+            if (storage_can_set($_REQUEST['svuser'])) {
31
+                print storage_stack_push($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svvalue']);
32
+            }
33
+            break;
34
+        case "stackpop":
35
+            if (storage_can_set($_REQUEST['svuser'])) {
36
+                print storage_stack_pop($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
37
+            }
38
+            break;
39
+        case "stacklength":
40
+            print storage_stack_length($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
41
+            break;
42
+        case "stackclear":
43
+            if (storage_can_set($_REQUEST['svuser'])) {
44
+                print storage_stack_clear($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
45
+            }
46
+            break;
47
+        case "stackgetall":
48
+            if (storage_can_set($_REQUEST['svuser']))
49
+                print storage_stack_getall($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey']);
50
+            break;
51
+        case "getposition":
52
+            print storage_get_position($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svasc']);
53
+            break;
54
+        case "getleaders":
55
+            print storage_get_leaders($_REQUEST['svuser'], $_REQUEST['svcourse'], $_REQUEST['svsco'], $_REQUEST['svkey'], $_REQUEST['svasc'], $_REQUEST['svlength']);
56
+            break;
57
+        case "usersgetall":
58
+    // security issue
59
+            print "NOT allowed, security issue, see sources";
60
+    //		print storage_get_all_users();
61
+            break;
62
+        default:
63
+            // Do nothing
64 64
 }
65 65
 
66 66
 function storage_can_set($sv_user) {
Please login to merge, or discard this patch.
main/upload/upload.php 1 patch
Switch Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -31,14 +31,14 @@
 block discarded – undo
31 31
  * Redirect to the correct script to handle this type of upload
32 32
  */
33 33
 switch ($toolFromSession) {
34
-    case TOOL_LEARNPATH:
35
-        require 'upload.scorm.php';
36
-        break;
37
-    //the following cases need to be distinguished later on
38
-    case TOOL_DROPBOX:
39
-    case TOOL_STUDENTPUBLICATION:
40
-    case TOOL_DOCUMENT:
41
-    default:
42
-        require 'upload.document.php';
43
-        break;
34
+        case TOOL_LEARNPATH:
35
+            require 'upload.scorm.php';
36
+            break;
37
+        //the following cases need to be distinguished later on
38
+        case TOOL_DROPBOX:
39
+        case TOOL_STUDENTPUBLICATION:
40
+        case TOOL_DOCUMENT:
41
+        default:
42
+            require 'upload.document.php';
43
+            break;
44 44
 }
Please login to merge, or discard this patch.
main/user/user_export.php 1 patch
Switch Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -149,15 +149,15 @@
 block discarded – undo
149 149
 }
150 150
 
151 151
 switch ($file_type) {
152
-    case 'xml':
153
-        Export::arrayToXml($data, $filename, 'Contact', 'Contacts');
154
-        exit;
155
-        break;
156
-    case 'csv':
157
-        Export::arrayToCsv($data, $filename);
158
-        exit;
159
-    case 'xls':
160
-        Export::arrayToXls($data, $filename);
161
-        exit;
162
-        break;
152
+        case 'xml':
153
+            Export::arrayToXml($data, $filename, 'Contact', 'Contacts');
154
+            exit;
155
+            break;
156
+        case 'csv':
157
+            Export::arrayToCsv($data, $filename);
158
+            exit;
159
+        case 'xls':
160
+            Export::arrayToXls($data, $filename);
161
+            exit;
162
+            break;
163 163
 }
164 164
\ No newline at end of file
Please login to merge, or discard this patch.
main/ticket/tickets.php 1 patch
Switch Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -72,48 +72,48 @@
 block discarded – undo
72 72
 }
73 73
 
74 74
 switch ($action) {
75
-    case 'alert':
76
-        if (!$isAdmin && isset($_GET['ticket_id'])) {
77
-            TicketManager::send_alert($_GET['ticket_id'], $user_id);
78
-        }
79
-        break;
80
-    case 'export':
81
-        $data = array(
82
-            array(
83
-                '#',
84
-                get_lang('Date'),
85
-                get_lang('LastUpdate'),
86
-                get_lang('Category'),
87
-                get_lang('User'),
88
-                get_lang('Program'),
89
-                get_lang('AssignedTo'),
90
-                get_lang('Status'),
91
-                get_lang('Description')
92
-            )
93
-        );
94
-        $datos = $table->get_clean_html();
95
-        foreach ($datos as $ticket) {
96
-            $ticket[0] = substr(strip_tags($ticket[0]), 0, 12);
97
-            $ticket_rem = array(
98
-                utf8_decode(strip_tags($ticket[0])),
99
-                utf8_decode(api_html_entity_decode($ticket[1])),
100
-                utf8_decode(strip_tags($ticket[2])),
101
-                utf8_decode(strip_tags($ticket[3])),
102
-                utf8_decode(strip_tags($ticket[4])),
103
-                utf8_decode(strip_tags($ticket[5])),
104
-                utf8_decode(strip_tags($ticket[6])),
105
-                utf8_decode(strip_tags($ticket[7]))
75
+        case 'alert':
76
+            if (!$isAdmin && isset($_GET['ticket_id'])) {
77
+                TicketManager::send_alert($_GET['ticket_id'], $user_id);
78
+            }
79
+            break;
80
+        case 'export':
81
+            $data = array(
82
+                array(
83
+                    '#',
84
+                    get_lang('Date'),
85
+                    get_lang('LastUpdate'),
86
+                    get_lang('Category'),
87
+                    get_lang('User'),
88
+                    get_lang('Program'),
89
+                    get_lang('AssignedTo'),
90
+                    get_lang('Status'),
91
+                    get_lang('Description')
92
+                )
106 93
             );
107
-            $data[] = $ticket_rem;
108
-        }
109
-        Export::arrayToXls($data, get_lang('Tickets'));
110
-        exit;
111
-        break;
112
-    case 'close_tickets':
113
-        TicketManager::close_old_tickets();
114
-        break;
115
-    default:
116
-        break;
94
+            $datos = $table->get_clean_html();
95
+            foreach ($datos as $ticket) {
96
+                $ticket[0] = substr(strip_tags($ticket[0]), 0, 12);
97
+                $ticket_rem = array(
98
+                    utf8_decode(strip_tags($ticket[0])),
99
+                    utf8_decode(api_html_entity_decode($ticket[1])),
100
+                    utf8_decode(strip_tags($ticket[2])),
101
+                    utf8_decode(strip_tags($ticket[3])),
102
+                    utf8_decode(strip_tags($ticket[4])),
103
+                    utf8_decode(strip_tags($ticket[5])),
104
+                    utf8_decode(strip_tags($ticket[6])),
105
+                    utf8_decode(strip_tags($ticket[7]))
106
+                );
107
+                $data[] = $ticket_rem;
108
+            }
109
+            Export::arrayToXls($data, get_lang('Tickets'));
110
+            exit;
111
+            break;
112
+        case 'close_tickets':
113
+            TicketManager::close_old_tickets();
114
+            break;
115
+        default:
116
+            break;
117 117
 }
118 118
 
119 119
 if (empty($projectId)) {
Please login to merge, or discard this patch.
main/auth/courses.php 1 patch
Switch Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -175,29 +175,29 @@  discard block
 block discarded – undo
175 175
 }
176 176
 
177 177
 switch ($action) {
178
-    case 'subscribe_user_with_password':
179
-        $courses_controller->subscribe_user(
180
-            isset($_POST['subscribe_user_with_password']) ? $_POST['subscribe_user_with_password'] : '',
181
-            isset($_POST['search_term']) ? $_POST['search_term'] : '',
182
-            isset($_POST['category_code']) ? $_POST['category_code'] : ''
183
-        );
184
-        break;
185
-    case 'createcoursecategory':
186
-        $courses_controller->categories_list($action);
187
-        break;
188
-    case 'deletecoursecategory':
189
-        $courses_controller->courses_list($action);
190
-        break;
191
-    case 'sortmycourses':
192
-        $courses_controller->courses_list($action);
193
-        break;
194
-    case 'subscribe':
195
-        if (!$user_can_view_page) {
196
-            api_not_allowed(true);
197
-        }
198
-        header('Location: '.api_get_self());
199
-        exit;
200
-        /* if (!CoursesAndSessionsCatalog::is(CATALOG_SESSIONS)) {
178
+        case 'subscribe_user_with_password':
179
+            $courses_controller->subscribe_user(
180
+                isset($_POST['subscribe_user_with_password']) ? $_POST['subscribe_user_with_password'] : '',
181
+                isset($_POST['search_term']) ? $_POST['search_term'] : '',
182
+                isset($_POST['category_code']) ? $_POST['category_code'] : ''
183
+            );
184
+            break;
185
+        case 'createcoursecategory':
186
+            $courses_controller->categories_list($action);
187
+            break;
188
+        case 'deletecoursecategory':
189
+            $courses_controller->courses_list($action);
190
+            break;
191
+        case 'sortmycourses':
192
+            $courses_controller->courses_list($action);
193
+            break;
194
+        case 'subscribe':
195
+            if (!$user_can_view_page) {
196
+                api_not_allowed(true);
197
+            }
198
+            header('Location: '.api_get_self());
199
+            exit;
200
+            /* if (!CoursesAndSessionsCatalog::is(CATALOG_SESSIONS)) {
201 201
             $courses_controller->courses_categories(
202 202
                 $action,
203 203
                 $categoryCode,
@@ -210,123 +210,123 @@  discard block
 block discarded – undo
210 210
             header('Location: ' . api_get_self());
211 211
             exit;
212 212
         }*/
213
-        break;
214
-    case 'display_random_courses':
215
-        if (!$user_can_view_page) {
216
-            api_not_allowed(true);
217
-        }
218
-
219
-        $courses_controller->courses_categories($action);
220
-        break;
221
-    case 'display_courses':
222
-        if (!$user_can_view_page) {
223
-            api_not_allowed(true);
224
-        }
225
-
226
-        $courses_controller->courses_categories(
227
-            $action,
228
-            $categoryCode,
229
-            null,
230
-            null,
231
-            null,
232
-            $limit
233
-        );
234
-        break;
235
-    case 'display_sessions':
236
-        if (!$user_can_view_page) {
237
-            api_not_allowed(true);
238
-        }
239
-
240
-        $courses_controller->sessionsList($action, $nameTools, $limit);
241
-        break;
242
-    case 'subscribe_to_session':
243
-        if (!$user_can_view_page) {
244
-            api_not_allowed(true);
245
-        }
246
-
247
-        $userId = api_get_user_id();
248
-        $confirmed = isset($_GET['confirm']);
249
-        $sessionId = intval($_GET['session_id']);
250
-
251
-        if (empty($userId)) {
252
-            api_not_allowed();
253
-            exit;
254
-        }
213
+            break;
214
+        case 'display_random_courses':
215
+            if (!$user_can_view_page) {
216
+                api_not_allowed(true);
217
+            }
218
+
219
+            $courses_controller->courses_categories($action);
220
+            break;
221
+        case 'display_courses':
222
+            if (!$user_can_view_page) {
223
+                api_not_allowed(true);
224
+            }
225
+
226
+            $courses_controller->courses_categories(
227
+                $action,
228
+                $categoryCode,
229
+                null,
230
+                null,
231
+                null,
232
+                $limit
233
+            );
234
+            break;
235
+        case 'display_sessions':
236
+            if (!$user_can_view_page) {
237
+                api_not_allowed(true);
238
+            }
255 239
 
256
-        if (!$confirmed) {
257
-            $template = new Template(null, false, false, false, false, false);
258
-            $template->assign('session_id', $sessionId);
240
+            $courses_controller->sessionsList($action, $nameTools, $limit);
241
+            break;
242
+        case 'subscribe_to_session':
243
+            if (!$user_can_view_page) {
244
+                api_not_allowed(true);
245
+            }
259 246
 
260
-            $layout = $template->get_template('auth/confirm_session_subscription.tpl');
247
+            $userId = api_get_user_id();
248
+            $confirmed = isset($_GET['confirm']);
249
+            $sessionId = intval($_GET['session_id']);
261 250
 
262
-            echo $template->fetch($layout);
263
-            exit;
264
-        }
251
+            if (empty($userId)) {
252
+                api_not_allowed();
253
+                exit;
254
+            }
265 255
 
266
-        $registrationAllowed = api_get_setting('catalog_allow_session_auto_subscription');
267
-        if ($registrationAllowed === 'true') {
268
-            $entityManager = Database::getManager();
269
-            $repository = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource');
256
+            if (!$confirmed) {
257
+                $template = new Template(null, false, false, false, false, false);
258
+                $template->assign('session_id', $sessionId);
270 259
 
271
-            $sequences = $repository->getRequirements(
272
-                $sessionId,
273
-                SequenceResource::SESSION_TYPE
274
-            );
260
+                $layout = $template->get_template('auth/confirm_session_subscription.tpl');
261
+
262
+                echo $template->fetch($layout);
263
+                exit;
264
+            }
265
+
266
+            $registrationAllowed = api_get_setting('catalog_allow_session_auto_subscription');
267
+            if ($registrationAllowed === 'true') {
268
+                $entityManager = Database::getManager();
269
+                $repository = $entityManager->getRepository('ChamiloCoreBundle:SequenceResource');
275 270
 
276
-            if (count($sequences) > 0) {
277
-                $requirementsData = SequenceResourceManager::checkRequirementsForUser(
278
-                    $sequences,
279
-                    SequenceResource::SESSION_TYPE,
280
-                    $userId
271
+                $sequences = $repository->getRequirements(
272
+                    $sessionId,
273
+                    SequenceResource::SESSION_TYPE
281 274
                 );
282 275
 
283
-                $continueWithSubscription = SequenceResourceManager::checkSequenceAreCompleted($requirementsData);
276
+                if (count($sequences) > 0) {
277
+                    $requirementsData = SequenceResourceManager::checkRequirementsForUser(
278
+                        $sequences,
279
+                        SequenceResource::SESSION_TYPE,
280
+                        $userId
281
+                    );
284 282
 
285
-                if (!$continueWithSubscription) {
286
-                    header('Location: '.api_get_path(WEB_CODE_PATH).'auth/courses.php');
287
-                    exit;
283
+                    $continueWithSubscription = SequenceResourceManager::checkSequenceAreCompleted($requirementsData);
284
+
285
+                    if (!$continueWithSubscription) {
286
+                        header('Location: '.api_get_path(WEB_CODE_PATH).'auth/courses.php');
287
+                        exit;
288
+                    }
288 289
                 }
289
-            }
290 290
 
291
-            SessionManager::subscribe_users_to_session(
292
-                $_GET['session_id'],
293
-                array($userId),
294
-                SESSION_VISIBLE_READ_ONLY,
295
-                false
296
-            );
291
+                SessionManager::subscribe_users_to_session(
292
+                    $_GET['session_id'],
293
+                    array($userId),
294
+                    SESSION_VISIBLE_READ_ONLY,
295
+                    false
296
+                );
297 297
 
298
-            $coursesList = SessionManager::get_course_list_by_session_id($_GET['session_id']);
299
-            $count = count($coursesList);
300
-            $url = '';
301
-
302
-            if ($count <= 0) {
303
-                // no course in session -> return to catalog
304
-                $url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
305
-            } elseif ($count == 1) {
306
-                // only one course, so redirect directly to this course
307
-                foreach ($coursesList as $course) {
308
-                    $url = api_get_path(WEB_COURSE_PATH).$course['directory'].'/index.php?id_session='.intval($_GET['session_id']);
298
+                $coursesList = SessionManager::get_course_list_by_session_id($_GET['session_id']);
299
+                $count = count($coursesList);
300
+                $url = '';
301
+
302
+                if ($count <= 0) {
303
+                    // no course in session -> return to catalog
304
+                    $url = api_get_path(WEB_CODE_PATH).'auth/courses.php';
305
+                } elseif ($count == 1) {
306
+                    // only one course, so redirect directly to this course
307
+                    foreach ($coursesList as $course) {
308
+                        $url = api_get_path(WEB_COURSE_PATH).$course['directory'].'/index.php?id_session='.intval($_GET['session_id']);
309
+                    }
310
+                } else {
311
+                    $url = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.intval($_GET['session_id']);
309 312
                 }
310
-            } else {
311
-                $url = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.intval($_GET['session_id']);
313
+                header('Location: '.$url);
314
+                exit;
312 315
             }
313
-            header('Location: '.$url);
314
-            exit;
315
-        }
316
-        //else show error message?
317
-        break;
318
-    case 'search_tag':
319
-        if (!$user_can_view_page) {
320
-            api_not_allowed(true);
321
-        }
322
-
323
-        $courses_controller->sessionsListByCoursesTag($limit);
324
-        break;
325
-    case 'search_session':
326
-        if (!$user_can_view_page) {
327
-            api_not_allowed(true);
328
-        }
329
-
330
-        $courses_controller->sessionListBySearch($limit);
331
-        break;
316
+            //else show error message?
317
+            break;
318
+        case 'search_tag':
319
+            if (!$user_can_view_page) {
320
+                api_not_allowed(true);
321
+            }
322
+
323
+            $courses_controller->sessionsListByCoursesTag($limit);
324
+            break;
325
+        case 'search_session':
326
+            if (!$user_can_view_page) {
327
+                api_not_allowed(true);
328
+            }
329
+
330
+            $courses_controller->sessionListBySearch($limit);
331
+            break;
332 332
 }
Please login to merge, or discard this patch.
main/lp/lp_controller.php 1 patch
Switch Indentation   +927 added lines, -927 removed lines patch added patch discarded remove patch
@@ -366,857 +366,857 @@  discard block
 block discarded – undo
366 366
 }
367 367
 
368 368
 switch ($action) {
369
-    case 'add_item':
370
-        if (!$is_allowed_to_edit) {
371
-            api_not_allowed(true);
372
-        }
373
-        if (!$lp_found) {
374
-            //check if the learnpath ID was defined, otherwise send back to list
375
-            if ($debug > 0) {
376
-                error_log('New LP - No learnpath given for add item', 0);
369
+        case 'add_item':
370
+            if (!$is_allowed_to_edit) {
371
+                api_not_allowed(true);
377 372
             }
378
-            require 'lp_list.php';
379
-        } else {
380
-            $_SESSION['refresh'] = 1;
373
+            if (!$lp_found) {
374
+                //check if the learnpath ID was defined, otherwise send back to list
375
+                if ($debug > 0) {
376
+                    error_log('New LP - No learnpath given for add item', 0);
377
+                }
378
+                require 'lp_list.php';
379
+            } else {
380
+                $_SESSION['refresh'] = 1;
381 381
 
382
-            if (isset($_POST['submit_button']) && !empty($post_title)) {
383
-                // If a title was submitted:
382
+                if (isset($_POST['submit_button']) && !empty($post_title)) {
383
+                    // If a title was submitted:
384 384
 
385
-                //Updating the lp.modified_on
386
-                $_SESSION['oLP']->set_modified_on();
385
+                    //Updating the lp.modified_on
386
+                    $_SESSION['oLP']->set_modified_on();
387 387
 
388
-                if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
389
-                    // Check post_time to ensure ??? (counter-hacking measure?)
390
-                    require 'lp_add_item.php';
391
-                } else {
392
-                    $_SESSION['post_time'] = $_POST['post_time'];
393
-                    $directoryParentId = isset($_POST['directory_parent_id']) ? $_POST['directory_parent_id'] : 0;
394
-                    $courseInfo = api_get_course_info();
395
-                    if (empty($directoryParentId)) {
396
-                        $_SESSION['oLP']->generate_lp_folder($courseInfo);
397
-                    }
388
+                    if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
389
+                        // Check post_time to ensure ??? (counter-hacking measure?)
390
+                        require 'lp_add_item.php';
391
+                    } else {
392
+                        $_SESSION['post_time'] = $_POST['post_time'];
393
+                        $directoryParentId = isset($_POST['directory_parent_id']) ? $_POST['directory_parent_id'] : 0;
394
+                        $courseInfo = api_get_course_info();
395
+                        if (empty($directoryParentId)) {
396
+                            $_SESSION['oLP']->generate_lp_folder($courseInfo);
397
+                        }
398 398
 
399
-                    $parent = isset($_POST['parent']) ? $_POST['parent'] : '';
400
-                    $previous = isset($_POST['previous']) ? $_POST['previous'] : '';
401
-                    $type = isset($_POST['type']) ? $_POST['type'] : '';
402
-                    $path = isset($_POST['path']) ? $_POST['path'] : '';
403
-                    $description = isset($_POST['description']) ? $_POST['description'] : '';
404
-                    $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
405
-                    $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
399
+                        $parent = isset($_POST['parent']) ? $_POST['parent'] : '';
400
+                        $previous = isset($_POST['previous']) ? $_POST['previous'] : '';
401
+                        $type = isset($_POST['type']) ? $_POST['type'] : '';
402
+                        $path = isset($_POST['path']) ? $_POST['path'] : '';
403
+                        $description = isset($_POST['description']) ? $_POST['description'] : '';
404
+                        $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
405
+                        $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
406
+
407
+                        if ($_POST['type'] == TOOL_DOCUMENT) {
408
+                            if (isset($_POST['path']) && $_GET['edit'] != 'true') {
409
+                                $document_id = $_POST['path'];
410
+                            } else {
411
+                                if ($_POST['content_lp']) {
412
+                                    $document_id = $_SESSION['oLP']->create_document(
413
+                                        $_course,
414
+                                        $_POST['content_lp'],
415
+                                        $_POST['title'],
416
+                                        'html',
417
+                                        $directoryParentId
418
+                                    );
419
+                                }
420
+                            }
406 421
 
407
-                    if ($_POST['type'] == TOOL_DOCUMENT) {
408
-                        if (isset($_POST['path']) && $_GET['edit'] != 'true') {
409
-                            $document_id = $_POST['path'];
422
+                            $new_item_id = $_SESSION['oLP']->add_item(
423
+                                $parent,
424
+                                $previous,
425
+                                $type,
426
+                                $document_id,
427
+                                $post_title,
428
+                                $description,
429
+                                $prerequisites
430
+                            );
410 431
                         } else {
411
-                            if ($_POST['content_lp']) {
412
-                                $document_id = $_SESSION['oLP']->create_document(
413
-                                    $_course,
414
-                                    $_POST['content_lp'],
415
-                                    $_POST['title'],
416
-                                    'html',
417
-                                    $directoryParentId
418
-                                );
419
-                            }
432
+                            // For all other item types than documents, load the item using the item type and path rather than its ID.
433
+                            $new_item_id = $_SESSION['oLP']->add_item(
434
+                                $parent,
435
+                                $previous,
436
+                                $type,
437
+                                $path,
438
+                                $post_title,
439
+                                $description,
440
+                                $prerequisites,
441
+                                $maxTimeAllowed
442
+                            );
420 443
                         }
421
-
422
-                        $new_item_id = $_SESSION['oLP']->add_item(
423
-                            $parent,
424
-                            $previous,
425
-                            $type,
426
-                            $document_id,
427
-                            $post_title,
428
-                            $description,
429
-                            $prerequisites
430
-                        );
431
-                    } else {
432
-                        // For all other item types than documents, load the item using the item type and path rather than its ID.
433
-                        $new_item_id = $_SESSION['oLP']->add_item(
434
-                            $parent,
435
-                            $previous,
436
-                            $type,
437
-                            $path,
438
-                            $post_title,
439
-                            $description,
440
-                            $prerequisites,
441
-                            $maxTimeAllowed
442
-                        );
444
+                        $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
445
+                        header('Location: '.$url);
446
+                        exit;
443 447
                     }
444
-                    $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
445
-                    header('Location: '.$url);
446
-                    exit;
448
+                } else {
449
+                    require 'lp_add_item.php';
447 450
                 }
448
-            } else {
449
-                require 'lp_add_item.php';
450 451
             }
451
-        }
452
-        break;
453
-    case 'add_users_to_category':
454
-        if (!$is_allowed_to_edit) {
455
-            api_not_allowed(true);
456
-        }
457
-        require 'lp_subscribe_users_to_category.php';
458
-        break;
459
-    case 'add_audio':
460
-        if (!$is_allowed_to_edit) {
461
-            api_not_allowed(true);
462
-        }
463
-        if (!$lp_found) {
464
-            //check if the learnpath ID was defined, otherwise send back to list
465
-            if ($debug > 0) {
466
-                error_log('New LP - No learnpath given for add audio', 0);
452
+            break;
453
+        case 'add_users_to_category':
454
+            if (!$is_allowed_to_edit) {
455
+                api_not_allowed(true);
467 456
             }
468
-            require 'lp_list.php';
469
-        } else {
470
-            $_SESSION['refresh'] = 1;
471
-
472
-            if (isset($_REQUEST['id'])) {
473
-                $lp_item_obj = new learnpathItem($_REQUEST['id']);
474
-
475
-                // Remove audio
476
-                if (isset($_GET['delete_file']) && $_GET['delete_file'] == 1) {
477
-                    $lp_item_obj->remove_audio();
478
-
479
-                    $url = api_get_self().'?action=add_audio&lp_id='.intval($_SESSION['oLP']->lp_id).'&id='.$lp_item_obj->get_id().'&'.api_get_cidreq();
480
-                    header('Location: '.$url);
481
-                    exit;
457
+            require 'lp_subscribe_users_to_category.php';
458
+            break;
459
+        case 'add_audio':
460
+            if (!$is_allowed_to_edit) {
461
+                api_not_allowed(true);
462
+            }
463
+            if (!$lp_found) {
464
+                //check if the learnpath ID was defined, otherwise send back to list
465
+                if ($debug > 0) {
466
+                    error_log('New LP - No learnpath given for add audio', 0);
482 467
                 }
468
+                require 'lp_list.php';
469
+            } else {
470
+                $_SESSION['refresh'] = 1;
483 471
 
484
-                // Upload audio
485
-                if (isset($_FILES['file']) && !empty($_FILES['file'])) {
486
-                    // Updating the lp.modified_on
487
-                    $_SESSION['oLP']->set_modified_on();
488
-                    $lp_item_obj->add_audio();
489
-                }
472
+                if (isset($_REQUEST['id'])) {
473
+                    $lp_item_obj = new learnpathItem($_REQUEST['id']);
490 474
 
491
-                //Add audio file from documents
492
-                if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
493
-                    $_SESSION['oLP']->set_modified_on();
494
-                    $lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
495
-                }
475
+                    // Remove audio
476
+                    if (isset($_GET['delete_file']) && $_GET['delete_file'] == 1) {
477
+                        $lp_item_obj->remove_audio();
496 478
 
497
-                // Display.
498
-                require 'lp_add_audio.php';
499
-            } else {
500
-                require 'lp_add_audio.php';
501
-            }
502
-        }
503
-        break;
504
-    case 'add_lp_category':
505
-        if (!$is_allowed_to_edit) {
506
-            api_not_allowed(true);
507
-        }
508
-        require 'lp_add_category.php';
509
-        break;
510
-    case 'move_up_category':
511
-        if (!$is_allowed_to_edit) {
512
-            api_not_allowed(true);
513
-        }
514
-        if (isset($_REQUEST['id'])) {
515
-            learnpath::moveUpCategory($_REQUEST['id']);
516
-        }
517
-        require 'lp_list.php';
518
-        break;
519
-    case 'move_down_category':
520
-        if (!$is_allowed_to_edit) {
521
-            api_not_allowed(true);
522
-        }
523
-        if (isset($_REQUEST['id'])) {
524
-            learnpath::moveDownCategory($_REQUEST['id']);
525
-        }
526
-        require 'lp_list.php';
527
-        break;
528
-    case 'delete_lp_category':
529
-        if (!$is_allowed_to_edit) {
530
-            api_not_allowed(true);
531
-        }
532
-        if (isset($_REQUEST['id'])) {
533
-            learnpath::deleteCategory($_REQUEST['id']);
534
-        }
535
-        require 'lp_list.php';
536
-        break;
537
-    case 'add_lp':
538
-        if (!$is_allowed_to_edit) {
539
-            api_not_allowed(true);
540
-        }
541
-        if (isset($_REQUEST['lp_name']) && !empty($_REQUEST['lp_name'])) {
542
-            $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
543
-            $_SESSION['refresh'] = 1;
479
+                        $url = api_get_self().'?action=add_audio&lp_id='.intval($_SESSION['oLP']->lp_id).'&id='.$lp_item_obj->get_id().'&'.api_get_cidreq();
480
+                        header('Location: '.$url);
481
+                        exit;
482
+                    }
544 483
 
545
-            if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
546
-                require 'lp_add.php';
547
-            } else {
548
-                $_SESSION['post_time'] = $_REQUEST['post_time'];
484
+                    // Upload audio
485
+                    if (isset($_FILES['file']) && !empty($_FILES['file'])) {
486
+                        // Updating the lp.modified_on
487
+                        $_SESSION['oLP']->set_modified_on();
488
+                        $lp_item_obj->add_audio();
489
+                    }
549 490
 
550
-                if (isset($_REQUEST['activate_start_date_check']) &&
551
-                    $_REQUEST['activate_start_date_check'] == 1
552
-                ) {
553
-                    $publicated_on = $_REQUEST['publicated_on'];
491
+                    //Add audio file from documents
492
+                    if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
493
+                        $_SESSION['oLP']->set_modified_on();
494
+                        $lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
495
+                    }
496
+
497
+                    // Display.
498
+                    require 'lp_add_audio.php';
554 499
                 } else {
555
-                    $publicated_on = null;
500
+                    require 'lp_add_audio.php';
556 501
                 }
502
+            }
503
+            break;
504
+        case 'add_lp_category':
505
+            if (!$is_allowed_to_edit) {
506
+                api_not_allowed(true);
507
+            }
508
+            require 'lp_add_category.php';
509
+            break;
510
+        case 'move_up_category':
511
+            if (!$is_allowed_to_edit) {
512
+                api_not_allowed(true);
513
+            }
514
+            if (isset($_REQUEST['id'])) {
515
+                learnpath::moveUpCategory($_REQUEST['id']);
516
+            }
517
+            require 'lp_list.php';
518
+            break;
519
+        case 'move_down_category':
520
+            if (!$is_allowed_to_edit) {
521
+                api_not_allowed(true);
522
+            }
523
+            if (isset($_REQUEST['id'])) {
524
+                learnpath::moveDownCategory($_REQUEST['id']);
525
+            }
526
+            require 'lp_list.php';
527
+            break;
528
+        case 'delete_lp_category':
529
+            if (!$is_allowed_to_edit) {
530
+                api_not_allowed(true);
531
+            }
532
+            if (isset($_REQUEST['id'])) {
533
+                learnpath::deleteCategory($_REQUEST['id']);
534
+            }
535
+            require 'lp_list.php';
536
+            break;
537
+        case 'add_lp':
538
+            if (!$is_allowed_to_edit) {
539
+                api_not_allowed(true);
540
+            }
541
+            if (isset($_REQUEST['lp_name']) && !empty($_REQUEST['lp_name'])) {
542
+                $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
543
+                $_SESSION['refresh'] = 1;
557 544
 
558
-                if (isset($_REQUEST['activate_end_date_check']) &&
559
-                    $_REQUEST['activate_end_date_check'] == 1
560
-                ) {
561
-                    $expired_on = $_REQUEST['expired_on'];
545
+                if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
546
+                    require 'lp_add.php';
562 547
                 } else {
563
-                    $expired_on = null;
564
-                }
548
+                    $_SESSION['post_time'] = $_REQUEST['post_time'];
565 549
 
566
-                $new_lp_id = learnpath::add_lp(
567
-                    api_get_course_id(),
568
-                    Security::remove_XSS($_REQUEST['lp_name']),
569
-                    '',
570
-                    'chamilo',
571
-                    'manual',
572
-                    '',
573
-                    $publicated_on,
574
-                    $expired_on,
575
-                    $_REQUEST['category_id']
576
-                );
550
+                    if (isset($_REQUEST['activate_start_date_check']) &&
551
+                        $_REQUEST['activate_start_date_check'] == 1
552
+                    ) {
553
+                        $publicated_on = $_REQUEST['publicated_on'];
554
+                    } else {
555
+                        $publicated_on = null;
556
+                    }
577 557
 
578
-                if (is_numeric($new_lp_id)) {
579
-                    // TODO: Maybe create a first directory directly to avoid bugging the user with useless queries
580
-                    $_SESSION['oLP'] = new learnpath(
558
+                    if (isset($_REQUEST['activate_end_date_check']) &&
559
+                        $_REQUEST['activate_end_date_check'] == 1
560
+                    ) {
561
+                        $expired_on = $_REQUEST['expired_on'];
562
+                    } else {
563
+                        $expired_on = null;
564
+                    }
565
+
566
+                    $new_lp_id = learnpath::add_lp(
581 567
                         api_get_course_id(),
582
-                        $new_lp_id,
583
-                        api_get_user_id()
568
+                        Security::remove_XSS($_REQUEST['lp_name']),
569
+                        '',
570
+                        'chamilo',
571
+                        'manual',
572
+                        '',
573
+                        $publicated_on,
574
+                        $expired_on,
575
+                        $_REQUEST['category_id']
584 576
                     );
585 577
 
586
-                    $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
587
-                    $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
578
+                    if (is_numeric($new_lp_id)) {
579
+                        // TODO: Maybe create a first directory directly to avoid bugging the user with useless queries
580
+                        $_SESSION['oLP'] = new learnpath(
581
+                            api_get_course_id(),
582
+                            $new_lp_id,
583
+                            api_get_user_id()
584
+                        );
588 585
 
589
-                    $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
590
-                    header("Location: $url&isStudentView=false");
591
-                    exit;
586
+                        $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
587
+                        $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
588
+
589
+                        $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
590
+                        header("Location: $url&isStudentView=false");
591
+                        exit;
592
+                    }
592 593
                 }
594
+            } else {
595
+                require 'lp_add.php';
593 596
             }
594
-        } else {
595
-            require 'lp_add.php';
596
-        }
597
-        break;
598
-    case 'admin_view':
599
-        if (!$is_allowed_to_edit) {
600
-            api_not_allowed(true);
601
-        }
602
-        if (!$lp_found) {
603
-            error_log('New LP - No learnpath given for admin_view', 0);
604
-            require 'lp_list.php';
605
-        } else {
606
-            $_SESSION['refresh'] = 1;
607
-            require 'lp_admin_view.php';
608
-        }
609
-        break;
610
-    case 'auto_launch':
611
-        if (api_get_course_setting('enable_lp_auto_launch') == 1) { //Redirect to a specific LP
597
+            break;
598
+        case 'admin_view':
612 599
             if (!$is_allowed_to_edit) {
613 600
                 api_not_allowed(true);
614 601
             }
615 602
             if (!$lp_found) {
616
-                error_log('New LP - No learnpath given for set_autolaunch', 0);
603
+                error_log('New LP - No learnpath given for admin_view', 0);
617 604
                 require 'lp_list.php';
605
+            } else {
606
+                $_SESSION['refresh'] = 1;
607
+                require 'lp_admin_view.php';
618 608
             }
619
-            else {
620
-                $_SESSION['oLP']->set_autolaunch($_GET['lp_id'], $_GET['status']);
609
+            break;
610
+        case 'auto_launch':
611
+            if (api_get_course_setting('enable_lp_auto_launch') == 1) { //Redirect to a specific LP
612
+                if (!$is_allowed_to_edit) {
613
+                    api_not_allowed(true);
614
+                }
615
+                if (!$lp_found) {
616
+                    error_log('New LP - No learnpath given for set_autolaunch', 0);
617
+                    require 'lp_list.php';
618
+                }
619
+                else {
620
+                    $_SESSION['oLP']->set_autolaunch($_GET['lp_id'], $_GET['status']);
621
+                    require 'lp_list.php';
622
+                    exit;
623
+                }
624
+            }
625
+            break;
626
+        case 'build':
627
+            if (!$is_allowed_to_edit) {
628
+                api_not_allowed(true);
629
+            }
630
+            if (!$lp_found) {
631
+                error_log('New LP - No learnpath given for build', 0);
621 632
                 require 'lp_list.php';
633
+            } else {
634
+                $_SESSION['refresh'] = 1;
635
+                //require 'lp_build.php';
636
+                $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
637
+                header('Location: '.$url);
622 638
                 exit;
623 639
             }
624
-        }
625
-        break;
626
-    case 'build':
627
-        if (!$is_allowed_to_edit) {
628
-            api_not_allowed(true);
629
-        }
630
-        if (!$lp_found) {
631
-            error_log('New LP - No learnpath given for build', 0);
632
-            require 'lp_list.php';
633
-        } else {
634
-            $_SESSION['refresh'] = 1;
635
-            //require 'lp_build.php';
636
-            $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
637
-            header('Location: '.$url);
638
-            exit;
639
-        }
640
-        break;
641
-    case 'edit_item':
642
-        if (!$is_allowed_to_edit) {
643
-            api_not_allowed(true);
644
-        }
645
-        if (!$lp_found) {
646
-            error_log('New LP - No learnpath given for edit item', 0);
647
-            require 'lp_list.php';
648
-        } else {
649
-            $_SESSION['refresh'] = 1;
650
-            if (isset($_POST['submit_button']) && !empty($post_title)) {
651
-                //Updating the lp.modified_on
652
-                $_SESSION['oLP']->set_modified_on();
640
+            break;
641
+        case 'edit_item':
642
+            if (!$is_allowed_to_edit) {
643
+                api_not_allowed(true);
644
+            }
645
+            if (!$lp_found) {
646
+                error_log('New LP - No learnpath given for edit item', 0);
647
+                require 'lp_list.php';
648
+            } else {
649
+                $_SESSION['refresh'] = 1;
650
+                if (isset($_POST['submit_button']) && !empty($post_title)) {
651
+                    //Updating the lp.modified_on
652
+                    $_SESSION['oLP']->set_modified_on();
653 653
 
654
-                // TODO: mp3 edit
655
-                $audio = array();
656
-                if (isset($_FILES['mp3'])) {
657
-                    $audio = $_FILES['mp3'];
658
-                }
654
+                    // TODO: mp3 edit
655
+                    $audio = array();
656
+                    if (isset($_FILES['mp3'])) {
657
+                        $audio = $_FILES['mp3'];
658
+                    }
659 659
 
660
-                $description = isset($_POST['description']) ? $_POST['description'] : '';
661
-                $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
662
-                $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
663
-                $url = isset($_POST['url']) ? $_POST['url'] : '';
664
-
665
-                $_SESSION['oLP']->edit_item(
666
-                    $_REQUEST['id'],
667
-                    $_POST['parent'],
668
-                    $_POST['previous'],
669
-                    $post_title,
670
-                    $description,
671
-                    $prerequisites,
672
-                    $audio,
673
-                    $maxTimeAllowed,
674
-                    $url
675
-                );
660
+                    $description = isset($_POST['description']) ? $_POST['description'] : '';
661
+                    $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
662
+                    $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
663
+                    $url = isset($_POST['url']) ? $_POST['url'] : '';
664
+
665
+                    $_SESSION['oLP']->edit_item(
666
+                        $_REQUEST['id'],
667
+                        $_POST['parent'],
668
+                        $_POST['previous'],
669
+                        $post_title,
670
+                        $description,
671
+                        $prerequisites,
672
+                        $audio,
673
+                        $maxTimeAllowed,
674
+                        $url
675
+                    );
676 676
 
677
-                if (isset($_POST['content_lp'])) {
678
-                    $_SESSION['oLP']->edit_document($_course);
679
-                }
680
-                $is_success = true;
677
+                    if (isset($_POST['content_lp'])) {
678
+                        $_SESSION['oLP']->edit_document($_course);
679
+                    }
680
+                    $is_success = true;
681 681
 
682
-                Display::addFlash(Display::return_message(get_lang('Updated')));
682
+                    Display::addFlash(Display::return_message(get_lang('Updated')));
683 683
 
684
-                $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
685
-                header('Location: '.$url);
686
-                exit;
684
+                    $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
685
+                    header('Location: '.$url);
686
+                    exit;
687
+                }
688
+                if (isset($_GET['view']) && $_GET['view'] == 'build') {
689
+                    require 'lp_edit_item.php';
690
+                } else {
691
+                    require 'lp_admin_view.php';
692
+                }
693
+            }
694
+            break;
695
+        case 'edit_item_prereq':
696
+            if (!$is_allowed_to_edit) {
697
+                api_not_allowed(true);
687 698
             }
688
-            if (isset($_GET['view']) && $_GET['view'] == 'build') {
689
-                require 'lp_edit_item.php';
699
+            if (!$lp_found) {
700
+                error_log('New LP - No learnpath given for edit item prereq', 0);
701
+                require 'lp_list.php';
690 702
             } else {
691
-                require 'lp_admin_view.php';
703
+                if (isset($_POST['submit_button'])) {
704
+                    //Updating the lp.modified_on
705
+                    $_SESSION['oLP']->set_modified_on();
706
+                    $_SESSION['refresh'] = 1;
707
+                    $editPrerequisite = $_SESSION['oLP']->edit_item_prereq(
708
+                        $_GET['id'],
709
+                        $_POST['prerequisites'],
710
+                        $_POST['min_' . $_POST['prerequisites']],
711
+                        $_POST['max_' . $_POST['prerequisites']]
712
+                    );
713
+
714
+                    if ($editPrerequisite) {
715
+                        $is_success = true;
716
+                    }
717
+
718
+                    $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
719
+                    header('Location: '.$url);
720
+                    exit;
721
+                } else {
722
+                    require 'lp_edit_item_prereq.php';
723
+                }
724
+            }
725
+            break;
726
+        case 'move_item':
727
+            if (!$is_allowed_to_edit) {
728
+                api_not_allowed(true);
692 729
             }
693
-        }
694
-        break;
695
-    case 'edit_item_prereq':
696
-        if (!$is_allowed_to_edit) {
697
-            api_not_allowed(true);
698
-        }
699
-        if (!$lp_found) {
700
-            error_log('New LP - No learnpath given for edit item prereq', 0);
701
-            require 'lp_list.php';
702
-        } else {
703
-            if (isset($_POST['submit_button'])) {
704
-                //Updating the lp.modified_on
705
-                $_SESSION['oLP']->set_modified_on();
706
-                $_SESSION['refresh'] = 1;
707
-                $editPrerequisite = $_SESSION['oLP']->edit_item_prereq(
708
-                    $_GET['id'],
709
-                    $_POST['prerequisites'],
710
-                    $_POST['min_' . $_POST['prerequisites']],
711
-                    $_POST['max_' . $_POST['prerequisites']]
712
-                );
713 730
 
714
-                if ($editPrerequisite) {
731
+            if (!$lp_found) {
732
+                error_log('New LP - No learnpath given for move item', 0);
733
+                require 'lp_list.php';
734
+            } else {
735
+                $_SESSION['refresh'] = 1;
736
+                if (isset($_POST['submit_button'])) {
737
+                    //Updating the lp.modified_on
738
+                    $_SESSION['oLP']->set_modified_on();
739
+                    $_SESSION['oLP']->edit_item(
740
+                        $_GET['id'],
741
+                        $_POST['parent'],
742
+                        $_POST['previous'],
743
+                        $post_title,
744
+                        $_POST['description']
745
+                    );
715 746
                     $is_success = true;
747
+                    $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
748
+                    header('Location: '.$url);
716 749
                 }
717
-
718
-                $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
719
-                header('Location: '.$url);
720
-                exit;
750
+                if (isset($_GET['view']) && $_GET['view'] == 'build') {
751
+                    require 'lp_move_item.php';
752
+                } else {
753
+                    // Avoids weird behaviours see CT#967.
754
+                    $check = Security::check_token('get');
755
+                    if ($check) {
756
+                        $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
757
+                    }
758
+                    Security::clear_token();
759
+                    require 'lp_admin_view.php';
760
+                }
761
+            }
762
+            break;
763
+        case 'view_item':
764
+            if (!$is_allowed_to_edit) {
765
+                api_not_allowed(true);
766
+            }
767
+            if (!$lp_found) {
768
+                error_log('New LP - No learnpath given for view item', 0); require 'lp_list.php';
721 769
             } else {
722
-                require 'lp_edit_item_prereq.php';
770
+                $_SESSION['refresh'] = 1;
771
+                require 'lp_view_item.php';
772
+            }
773
+            break;
774
+        case 'upload':
775
+            if (!$is_allowed_to_edit) {
776
+                api_not_allowed(true);
777
+            }
778
+            $cwdir = getcwd();
779
+            require 'lp_upload.php';
780
+            // Reinit current working directory as many functions in upload change it.
781
+            chdir($cwdir);
782
+            require 'lp_list.php';
783
+            break;
784
+        case 'copy':
785
+            if (!$is_allowed_to_edit) {
786
+                api_not_allowed(true);
787
+            }
788
+
789
+            $hideScormCopyLink = api_get_setting('hide_scorm_copy_link');
790
+            if ($hideScormCopyLink === 'true') {
791
+                api_not_allowed(true);
723 792
             }
724
-        }
725
-        break;
726
-    case 'move_item':
727
-        if (!$is_allowed_to_edit) {
728
-            api_not_allowed(true);
729
-        }
730 793
 
731
-        if (!$lp_found) {
732
-            error_log('New LP - No learnpath given for move item', 0);
794
+            if (!$lp_found) {
795
+                error_log('New LP - No learnpath given for copy', 0);
796
+                require 'lp_list.php';
797
+            } else {
798
+                $_SESSION['oLP']->copy();
799
+            }
733 800
             require 'lp_list.php';
734
-        } else {
735
-            $_SESSION['refresh'] = 1;
736
-            if (isset($_POST['submit_button'])) {
737
-                //Updating the lp.modified_on
738
-                $_SESSION['oLP']->set_modified_on();
739
-                $_SESSION['oLP']->edit_item(
740
-                    $_GET['id'],
741
-                    $_POST['parent'],
742
-                    $_POST['previous'],
743
-                    $post_title,
744
-                    $_POST['description']
745
-                );
746
-                $is_success = true;
747
-                $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
748
-                header('Location: '.$url);
801
+            break;
802
+        case 'export':
803
+            if (!$is_allowed_to_edit) {
804
+                api_not_allowed(true);
805
+            }
806
+            $hideScormExportLink = api_get_setting('hide_scorm_export_link');
807
+            if ($hideScormExportLink === 'true') {
808
+                api_not_allowed(true);
749 809
             }
750
-            if (isset($_GET['view']) && $_GET['view'] == 'build') {
751
-                require 'lp_move_item.php';
810
+            if (!$lp_found) {
811
+                error_log('New LP - No learnpath given for export', 0);
812
+                require 'lp_list.php';
752 813
             } else {
753
-                // Avoids weird behaviours see CT#967.
754
-                $check = Security::check_token('get');
755
-                if ($check) {
756
-                    $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
757
-                }
758
-                Security::clear_token();
759
-                require 'lp_admin_view.php';
814
+                $_SESSION['oLP']->scorm_export();
815
+                exit();
816
+            }
817
+            break;
818
+        case 'export_to_pdf':
819
+            if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
820
+                api_not_allowed();
821
+            }
822
+            $hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
823
+            if ($hideScormPdfLink === 'true') {
824
+                api_not_allowed(true);
760 825
             }
761
-        }
762
-        break;
763
-    case 'view_item':
764
-        if (!$is_allowed_to_edit) {
765
-            api_not_allowed(true);
766
-        }
767
-        if (!$lp_found) {
768
-            error_log('New LP - No learnpath given for view item', 0); require 'lp_list.php';
769
-        } else {
770
-            $_SESSION['refresh'] = 1;
771
-            require 'lp_view_item.php';
772
-        }
773
-        break;
774
-    case 'upload':
775
-        if (!$is_allowed_to_edit) {
776
-            api_not_allowed(true);
777
-        }
778
-        $cwdir = getcwd();
779
-        require 'lp_upload.php';
780
-        // Reinit current working directory as many functions in upload change it.
781
-        chdir($cwdir);
782
-        require 'lp_list.php';
783
-        break;
784
-    case 'copy':
785
-        if (!$is_allowed_to_edit) {
786
-            api_not_allowed(true);
787
-        }
788 826
 
789
-        $hideScormCopyLink = api_get_setting('hide_scorm_copy_link');
790
-        if ($hideScormCopyLink === 'true') {
791
-            api_not_allowed(true);
792
-        }
827
+            if (!$lp_found) {
828
+                error_log('New LP - No learnpath given for export_to_pdf', 0);
829
+                require 'lp_list.php';
830
+            } else {
831
+                $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
832
+                if (!$result) {
833
+                    require 'lp_list.php';
834
+                }
835
+                exit;
836
+            }
837
+            break;
838
+        case 'delete':
839
+            if (!$is_allowed_to_edit) {
840
+                api_not_allowed(true);
841
+            }
842
+            if (!$lp_found) {
843
+                error_log('New LP - No learnpath given for delete', 0);
844
+                require 'lp_list.php';
845
+            } else {
846
+                $_SESSION['refresh'] = 1;
847
+                $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
848
+                Display::addFlash(Display::return_message(get_lang('Deleted')));
849
+                Session::erase('oLP');
850
+                require 'lp_list.php';
851
+            }
852
+            break;
853
+        case 'toggle_visible':
854
+            // Change lp visibility (inside lp tool).
855
+            if (!$is_allowed_to_edit) {
856
+                api_not_allowed(true);
857
+            }
793 858
 
794
-        if (!$lp_found) {
795
-            error_log('New LP - No learnpath given for copy', 0);
796
-            require 'lp_list.php';
797
-        } else {
798
-            $_SESSION['oLP']->copy();
799
-        }
800
-        require 'lp_list.php';
801
-        break;
802
-    case 'export':
803
-        if (!$is_allowed_to_edit) {
804
-            api_not_allowed(true);
805
-        }
806
-        $hideScormExportLink = api_get_setting('hide_scorm_export_link');
807
-        if ($hideScormExportLink === 'true') {
808
-            api_not_allowed(true);
809
-        }
810
-        if (!$lp_found) {
811
-            error_log('New LP - No learnpath given for export', 0);
812
-            require 'lp_list.php';
813
-        } else {
814
-            $_SESSION['oLP']->scorm_export();
815
-            exit();
816
-        }
817
-        break;
818
-    case 'export_to_pdf':
819
-        if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
820
-            api_not_allowed();
821
-        }
822
-        $hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
823
-        if ($hideScormPdfLink === 'true') {
824
-            api_not_allowed(true);
825
-        }
859
+            if (!$lp_found) {
860
+                error_log('New LP - No learnpath given for visibility', 0);
861
+                require 'lp_list.php';
862
+            } else {
863
+                learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
864
+                require 'lp_list.php';
865
+            }
866
+            break;
867
+        case 'toggle_publish':
868
+            // Change lp published status (visibility on homepage).
869
+            if (!$is_allowed_to_edit) {
870
+                api_not_allowed(true);
871
+            }
872
+            if (!$lp_found) {
873
+                error_log('New LP - No learnpath given for publish', 0);
874
+                require 'lp_list.php';
875
+            } else {
876
+                learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
877
+                require 'lp_list.php';
878
+            }
879
+            break;
880
+        case 'move_lp_up':
881
+            // Change lp published status (visibility on homepage)
882
+            if (!$is_allowed_to_edit) {
883
+                api_not_allowed(true);
884
+            }
885
+            if (!$lp_found) {
886
+                error_log('New LP - No learnpath given for publish', 0);
887
+                require 'lp_list.php';
888
+            } else {
889
+                learnpath::move_up($_REQUEST['lp_id']);
890
+                require 'lp_list.php';
891
+            }
892
+            break;
893
+        case 'move_lp_down':
894
+            // Change lp published status (visibility on homepage)
895
+            if (!$is_allowed_to_edit) {
896
+                api_not_allowed(true);
897
+            }
898
+            if (!$lp_found) {
899
+                error_log('New LP - No learnpath given for publish', 0);
900
+                require 'lp_list.php';
901
+            } else {
902
+                learnpath::move_down($_REQUEST['lp_id']);
903
+                require 'lp_list.php';
904
+            }
905
+            break;
906
+        case 'edit':
907
+            if (!$is_allowed_to_edit) {
908
+                api_not_allowed(true);
909
+            }
826 910
 
827
-        if (!$lp_found) {
828
-            error_log('New LP - No learnpath given for export_to_pdf', 0);
829
-            require 'lp_list.php';
830
-        } else {
831
-            $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
832
-            if (!$result) {
911
+            if (!$lp_found) {
912
+                error_log('New LP - No learnpath given for edit', 0);
833 913
                 require 'lp_list.php';
914
+            } else {
915
+                $_SESSION['refresh'] = 1;
916
+                require 'lp_edit.php';
834 917
             }
835
-            exit;
836
-        }
837
-        break;
838
-    case 'delete':
839
-        if (!$is_allowed_to_edit) {
840
-            api_not_allowed(true);
841
-        }
842
-        if (!$lp_found) {
843
-            error_log('New LP - No learnpath given for delete', 0);
844
-            require 'lp_list.php';
845
-        } else {
846
-            $_SESSION['refresh'] = 1;
847
-            $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
848
-            Display::addFlash(Display::return_message(get_lang('Deleted')));
849
-            Session::erase('oLP');
850
-            require 'lp_list.php';
851
-        }
852
-        break;
853
-    case 'toggle_visible':
854
-        // Change lp visibility (inside lp tool).
855
-        if (!$is_allowed_to_edit) {
856
-            api_not_allowed(true);
857
-        }
918
+            break;
919
+        case 'update_lp':
920
+            if (!$is_allowed_to_edit) {
921
+                api_not_allowed(true);
922
+            }
923
+            if (!$lp_found) {
924
+                error_log('New LP - No learnpath given for edit', 0);
925
+                require 'lp_list.php';
926
+            } else {
927
+                $_SESSION['refresh'] = 1;
928
+                $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
929
+                $_SESSION['oLP']->set_name($lp_name);
930
+                $author = $_REQUEST['lp_author'];
931
+                // Fixing the author name (no body or html tags).
932
+                $auth_init = stripos($author, '<p>');
933
+                if ($auth_init === false) {
934
+                    $auth_init = stripos($author, '<body>');
935
+                    $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
936
+                    $len = $auth_end - $auth_init + 6;
937
+                } else {
938
+                    $auth_end = strripos($author, '</p>');
939
+                    $len = $auth_end - $auth_init + 4;
940
+                }
858 941
 
859
-        if (!$lp_found) {
860
-            error_log('New LP - No learnpath given for visibility', 0);
861
-            require 'lp_list.php';
862
-        } else {
863
-            learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
864
-            require 'lp_list.php';
865
-        }
866
-        break;
867
-    case 'toggle_publish':
868
-        // Change lp published status (visibility on homepage).
869
-        if (!$is_allowed_to_edit) {
870
-            api_not_allowed(true);
871
-        }
872
-        if (!$lp_found) {
873
-            error_log('New LP - No learnpath given for publish', 0);
874
-            require 'lp_list.php';
875
-        } else {
876
-            learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
877
-            require 'lp_list.php';
878
-        }
879
-        break;
880
-    case 'move_lp_up':
881
-        // Change lp published status (visibility on homepage)
882
-        if (!$is_allowed_to_edit) {
883
-            api_not_allowed(true);
884
-        }
885
-        if (!$lp_found) {
886
-            error_log('New LP - No learnpath given for publish', 0);
887
-            require 'lp_list.php';
888
-        } else {
889
-            learnpath::move_up($_REQUEST['lp_id']);
890
-            require 'lp_list.php';
891
-        }
892
-        break;
893
-    case 'move_lp_down':
894
-        // Change lp published status (visibility on homepage)
895
-        if (!$is_allowed_to_edit) {
896
-            api_not_allowed(true);
897
-        }
898
-        if (!$lp_found) {
899
-            error_log('New LP - No learnpath given for publish', 0);
900
-            require 'lp_list.php';
901
-        } else {
902
-            learnpath::move_down($_REQUEST['lp_id']);
903
-            require 'lp_list.php';
904
-        }
905
-        break;
906
-    case 'edit':
907
-        if (!$is_allowed_to_edit) {
908
-            api_not_allowed(true);
909
-        }
942
+                $author_fixed = substr($author, $auth_init, $len);
943
+                $_SESSION['oLP']->set_author($author_fixed);
944
+                // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
945
+                $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
910 946
 
911
-        if (!$lp_found) {
912
-            error_log('New LP - No learnpath given for edit', 0);
913
-            require 'lp_list.php';
914
-        } else {
915
-            $_SESSION['refresh'] = 1;
916
-            require 'lp_edit.php';
917
-        }
918
-        break;
919
-    case 'update_lp':
920
-        if (!$is_allowed_to_edit) {
921
-            api_not_allowed(true);
922
-        }
923
-        if (!$lp_found) {
924
-            error_log('New LP - No learnpath given for edit', 0);
925
-            require 'lp_list.php';
926
-        } else {
927
-            $_SESSION['refresh'] = 1;
928
-            $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
929
-            $_SESSION['oLP']->set_name($lp_name);
930
-            $author = $_REQUEST['lp_author'];
931
-            // Fixing the author name (no body or html tags).
932
-            $auth_init = stripos($author, '<p>');
933
-            if ($auth_init === false) {
934
-                $auth_init = stripos($author, '<body>');
935
-                $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
936
-                $len = $auth_end - $auth_init + 6;
947
+                if (isset($_REQUEST['lp_maker'])) {
948
+                    $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
949
+                }
950
+                if (isset($_REQUEST['lp_proximity'])) {
951
+                    $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
952
+                }
953
+                $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
954
+
955
+                if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
956
+                    $hide_toc_frame = $_REQUEST['hide_toc_frame'];
957
+                } else {
958
+                    $hide_toc_frame = null;
959
+                }
960
+                $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
961
+                $_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
962
+                $_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
963
+
964
+                $subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
965
+                $_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
966
+
967
+                $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
968
+                $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
969
+
970
+                if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
971
+            	    $publicated_on  = $_REQUEST['publicated_on'];
972
+                } else {
973
+            	    $publicated_on = null;
974
+                }
975
+
976
+                if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
977
+                    $expired_on = $_REQUEST['expired_on'];
978
+                } else {
979
+                    $expired_on = null;
980
+                }
981
+                $_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
982
+                $_SESSION['oLP']->set_modified_on();
983
+                $_SESSION['oLP']->set_publicated_on($publicated_on);
984
+                $_SESSION['oLP']->set_expired_on($expired_on);
985
+
986
+                if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
987
+                    $_SESSION['oLP']->delete_lp_image();
988
+                }
989
+
990
+                $extraFieldValue = new ExtraFieldValue('lp');
991
+                $params = array(
992
+                    'lp_id' => $_SESSION['oLP']->id
993
+                );
994
+                $extraFieldValue->saveFieldValues($_REQUEST);
995
+
996
+                if ($_FILES['lp_preview_image']['size'] > 0) {
997
+                    $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
998
+                }
999
+
1000
+                if (api_get_setting('search_enabled') === 'true') {
1001
+                    require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
1002
+                    $specific_fields = get_specific_field_list();
1003
+                    foreach ($specific_fields as $specific_field) {
1004
+                        $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
1005
+                        $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
1006
+                        if (!empty($new_values)) {
1007
+                            array_walk($new_values, 'trim');
1008
+                            delete_all_specific_field_value(
1009
+                                api_get_course_id(),
1010
+                                $specific_field['id'],
1011
+                                TOOL_LEARNPATH,
1012
+                                $_SESSION['oLP']->lp_id
1013
+                            );
1014
+
1015
+                            foreach ($new_values as $value) {
1016
+                                if (!empty($value)) {
1017
+                                    add_specific_field_value(
1018
+                                        $specific_field['id'],
1019
+                                        api_get_course_id(),
1020
+                                        TOOL_LEARNPATH,
1021
+                                        $_SESSION['oLP']->lp_id,
1022
+                                        $value
1023
+                                    );
1024
+                                }
1025
+                            }
1026
+                        }
1027
+                    }
1028
+                }
1029
+                Display::addFlash(Display::return_message(get_lang('Updated')));
1030
+                $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
1031
+                header('Location: '.$url);
1032
+                exit;
1033
+            }
1034
+            break;
1035
+        case 'add_sub_item': // Add an item inside a dir/chapter.
1036
+            // @todo check if this is @deprecated
1037
+            if (!$is_allowed_to_edit) {
1038
+                api_not_allowed(true);
1039
+            }
1040
+            if (!$lp_found) {
1041
+                error_log('New LP - No learnpath given for add sub item', 0);
1042
+                require 'lp_list.php';
1043
+            } else {
1044
+                $_SESSION['refresh'] = 1;
1045
+                if (!empty($_REQUEST['parent_item_id'])) {
1046
+                    $_SESSION['from_learnpath'] = 'yes';
1047
+                    $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.intval($_REQUEST['lp_id']);
1048
+                } else {
1049
+                    require 'lp_admin_view.php';
1050
+                }
1051
+            }
1052
+            break;
1053
+        case 'deleteitem':
1054
+        case 'delete_item':
1055
+            if (!$is_allowed_to_edit) {
1056
+                api_not_allowed(true);
1057
+            }
1058
+            if (!$lp_found) {
1059
+                error_log('New LP - No learnpath given for delete item', 0);
1060
+                require 'lp_list.php';
937 1061
             } else {
938
-                $auth_end = strripos($author, '</p>');
939
-                $len = $auth_end - $auth_init + 4;
1062
+                if (!empty($_REQUEST['id'])) {
1063
+                    $_SESSION['oLP']->delete_item($_REQUEST['id']);
1064
+                }
1065
+                $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']).'&'.api_get_cidreq();
1066
+                header('Location: '.$url);
1067
+                exit;
940 1068
             }
941
-
942
-            $author_fixed = substr($author, $auth_init, $len);
943
-            $_SESSION['oLP']->set_author($author_fixed);
944
-            // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
945
-            $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
946
-
947
-            if (isset($_REQUEST['lp_maker'])) {
948
-                $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
1069
+            break;
1070
+        case 'edititemprereq':
1071
+        case 'edit_item_prereq':
1072
+            if (!$is_allowed_to_edit) {
1073
+                api_not_allowed(true);
949 1074
             }
950
-            if (isset($_REQUEST['lp_proximity'])) {
951
-                $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
1075
+            if (!$lp_found) {
1076
+                error_log('New LP - No learnpath given for edit item prereq', 0);
1077
+                require 'lp_list.php';
1078
+            } else {
1079
+                if (!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])) {
1080
+                    $_SESSION['refresh'] = 1;
1081
+                    $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'], $_REQUEST['prereq']);
1082
+                }
1083
+                require 'lp_admin_view.php';
952 1084
             }
953
-            $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
954
-
955
-            if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
956
-                $hide_toc_frame = $_REQUEST['hide_toc_frame'];
1085
+            break;
1086
+        case 'restart':
1087
+            if (!$lp_found) {
1088
+                error_log('New LP - No learnpath given for restart', 0);
1089
+                require 'lp_list.php';
957 1090
             } else {
958
-                $hide_toc_frame = null;
1091
+                $_SESSION['oLP']->restart();
1092
+                require 'lp_view.php';
959 1093
             }
960
-            $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
961
-            $_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
962
-            $_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
963
-
964
-            $subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
965
-            $_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
966
-
967
-            $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
968
-            $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
969
-
970
-            if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
971
-            	$publicated_on  = $_REQUEST['publicated_on'];
1094
+            break;
1095
+        case 'last':
1096
+            if (!$lp_found) {
1097
+                error_log('New LP - No learnpath given for last', 0);
1098
+                require 'lp_list.php';
972 1099
             } else {
973
-            	$publicated_on = null;
1100
+                $_SESSION['oLP']->last();
1101
+                require 'lp_view.php';
974 1102
             }
975
-
976
-            if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
977
-                $expired_on = $_REQUEST['expired_on'];
1103
+            break;
1104
+        case 'first':
1105
+            if (!$lp_found) {
1106
+                error_log('New LP - No learnpath given for first', 0);
1107
+                require 'lp_list.php';
978 1108
             } else {
979
-                $expired_on = null;
1109
+                $_SESSION['oLP']->first();
1110
+                require 'lp_view.php';
980 1111
             }
981
-            $_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
982
-            $_SESSION['oLP']->set_modified_on();
983
-            $_SESSION['oLP']->set_publicated_on($publicated_on);
984
-            $_SESSION['oLP']->set_expired_on($expired_on);
985
-
986
-            if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
987
-                $_SESSION['oLP']->delete_lp_image();
1112
+            break;
1113
+        case 'next':
1114
+            if (!$lp_found) {
1115
+                error_log('New LP - No learnpath given for next', 0);
1116
+                require 'lp_list.php';
1117
+            } else {
1118
+                $_SESSION['oLP']->next();
1119
+                require 'lp_view.php';
988 1120
             }
989
-
990
-            $extraFieldValue = new ExtraFieldValue('lp');
991
-            $params = array(
992
-                'lp_id' => $_SESSION['oLP']->id
993
-            );
994
-            $extraFieldValue->saveFieldValues($_REQUEST);
995
-
996
-            if ($_FILES['lp_preview_image']['size'] > 0) {
997
-                $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
1121
+            break;
1122
+        case 'previous':
1123
+            if (!$lp_found) {
1124
+                error_log('New LP - No learnpath given for previous', 0);
1125
+                require 'lp_list.php';
1126
+            } else {
1127
+                $_SESSION['oLP']->previous();
1128
+                require 'lp_view.php';
998 1129
             }
999
-
1000
-            if (api_get_setting('search_enabled') === 'true') {
1001
-                require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
1002
-                $specific_fields = get_specific_field_list();
1003
-                foreach ($specific_fields as $specific_field) {
1004
-                    $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
1005
-                    $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
1006
-                    if (!empty($new_values)) {
1007
-                        array_walk($new_values, 'trim');
1008
-                        delete_all_specific_field_value(
1009
-                            api_get_course_id(),
1010
-                            $specific_field['id'],
1011
-                            TOOL_LEARNPATH,
1012
-                            $_SESSION['oLP']->lp_id
1013
-                        );
1014
-
1015
-                        foreach ($new_values as $value) {
1016
-                            if (!empty($value)) {
1017
-                                add_specific_field_value(
1018
-                                    $specific_field['id'],
1019
-                                    api_get_course_id(),
1020
-                                    TOOL_LEARNPATH,
1021
-                                    $_SESSION['oLP']->lp_id,
1022
-                                    $value
1023
-                                );
1024
-                            }
1025
-                        }
1026
-                    }
1130
+            break;
1131
+        case 'content':
1132
+            if ($debug > 0) error_log('New LP - Item id is '.intval($_GET['item_id']), 0);
1133
+            if (!$lp_found) {
1134
+                error_log('New LP - No learnpath given for content', 0);
1135
+                require 'lp_list.php';
1136
+            } else {
1137
+                if ($debug > 0) error_log('New LP - save_last()', 0);
1138
+                $_SESSION['oLP']->save_last();
1139
+                if ($debug > 0) error_log('New LP - set_current_item()', 0);
1140
+                $_SESSION['oLP']->set_current_item($_GET['item_id']);
1141
+                if ($debug > 0) error_log('New LP - start_current_item()', 0);
1142
+                $_SESSION['oLP']->start_current_item();
1143
+                require 'lp_content.php';
1144
+            }
1145
+            break;
1146
+        case 'view':
1147
+            if (!$lp_found) {
1148
+                error_log('New LP - No learnpath given for view', 0);
1149
+                require 'lp_list.php';
1150
+            } else {
1151
+                if ($debug > 0) {error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0); }
1152
+                if ( !empty($_REQUEST['item_id']) ) {
1153
+                    $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
1027 1154
                 }
1155
+                require 'lp_view.php';
1028 1156
             }
1029
-            Display::addFlash(Display::return_message(get_lang('Updated')));
1030
-            $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
1031
-            header('Location: '.$url);
1032
-            exit;
1033
-        }
1034
-        break;
1035
-    case 'add_sub_item': // Add an item inside a dir/chapter.
1036
-        // @todo check if this is @deprecated
1037
-        if (!$is_allowed_to_edit) {
1038
-            api_not_allowed(true);
1039
-        }
1040
-        if (!$lp_found) {
1041
-            error_log('New LP - No learnpath given for add sub item', 0);
1042
-            require 'lp_list.php';
1043
-        } else {
1044
-            $_SESSION['refresh'] = 1;
1045
-            if (!empty($_REQUEST['parent_item_id'])) {
1046
-                $_SESSION['from_learnpath'] = 'yes';
1047
-                $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.intval($_REQUEST['lp_id']);
1157
+            break;
1158
+        case 'save':
1159
+            if (!$lp_found) {
1160
+                error_log('New LP - No learnpath given for save', 0);
1161
+                require 'lp_list.php';
1048 1162
             } else {
1049
-                require 'lp_admin_view.php';
1163
+                $_SESSION['oLP']->save_item();
1164
+                require 'lp_save.php';
1050 1165
             }
1051
-        }
1052
-        break;
1053
-    case 'deleteitem':
1054
-    case 'delete_item':
1055
-        if (!$is_allowed_to_edit) {
1056
-            api_not_allowed(true);
1057
-        }
1058
-        if (!$lp_found) {
1059
-            error_log('New LP - No learnpath given for delete item', 0);
1060
-            require 'lp_list.php';
1061
-        } else {
1062
-            if (!empty($_REQUEST['id'])) {
1063
-                $_SESSION['oLP']->delete_item($_REQUEST['id']);
1166
+            break;
1167
+        case 'stats':
1168
+            if (!$lp_found) {
1169
+                error_log('New LP - No learnpath given for stats', 0);
1170
+                require 'lp_list.php';
1171
+            } else {
1172
+                $_SESSION['oLP']->save_current();
1173
+                $_SESSION['oLP']->save_last();
1174
+                $output = require 'lp_stats.php';
1175
+                echo $output;
1064 1176
             }
1065
-            $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']).'&'.api_get_cidreq();
1066
-            header('Location: '.$url);
1067
-            exit;
1068
-        }
1069
-        break;
1070
-    case 'edititemprereq':
1071
-    case 'edit_item_prereq':
1072
-        if (!$is_allowed_to_edit) {
1073
-            api_not_allowed(true);
1074
-        }
1075
-        if (!$lp_found) {
1076
-            error_log('New LP - No learnpath given for edit item prereq', 0);
1077
-            require 'lp_list.php';
1078
-        } else {
1079
-            if (!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])) {
1177
+            break;
1178
+        case 'list':
1179
+            if ($lp_found) {
1080 1180
                 $_SESSION['refresh'] = 1;
1081
-                $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'], $_REQUEST['prereq']);
1181
+                $_SESSION['oLP']->save_last();
1082 1182
             }
1083
-            require 'lp_admin_view.php';
1084
-        }
1085
-        break;
1086
-    case 'restart':
1087
-        if (!$lp_found) {
1088
-            error_log('New LP - No learnpath given for restart', 0);
1089
-            require 'lp_list.php';
1090
-        } else {
1091
-            $_SESSION['oLP']->restart();
1092
-            require 'lp_view.php';
1093
-        }
1094
-        break;
1095
-    case 'last':
1096
-        if (!$lp_found) {
1097
-            error_log('New LP - No learnpath given for last', 0);
1098
-            require 'lp_list.php';
1099
-        } else {
1100
-            $_SESSION['oLP']->last();
1101
-            require 'lp_view.php';
1102
-        }
1103
-        break;
1104
-    case 'first':
1105
-        if (!$lp_found) {
1106
-            error_log('New LP - No learnpath given for first', 0);
1107
-            require 'lp_list.php';
1108
-        } else {
1109
-            $_SESSION['oLP']->first();
1110
-            require 'lp_view.php';
1111
-        }
1112
-        break;
1113
-    case 'next':
1114
-        if (!$lp_found) {
1115
-            error_log('New LP - No learnpath given for next', 0);
1116
-            require 'lp_list.php';
1117
-        } else {
1118
-            $_SESSION['oLP']->next();
1119
-            require 'lp_view.php';
1120
-        }
1121
-        break;
1122
-    case 'previous':
1123
-        if (!$lp_found) {
1124
-            error_log('New LP - No learnpath given for previous', 0);
1125
-            require 'lp_list.php';
1126
-        } else {
1127
-            $_SESSION['oLP']->previous();
1128
-            require 'lp_view.php';
1129
-        }
1130
-        break;
1131
-    case 'content':
1132
-        if ($debug > 0) error_log('New LP - Item id is '.intval($_GET['item_id']), 0);
1133
-        if (!$lp_found) {
1134
-            error_log('New LP - No learnpath given for content', 0);
1135
-            require 'lp_list.php';
1136
-        } else {
1137
-            if ($debug > 0) error_log('New LP - save_last()', 0);
1138
-            $_SESSION['oLP']->save_last();
1139
-            if ($debug > 0) error_log('New LP - set_current_item()', 0);
1140
-            $_SESSION['oLP']->set_current_item($_GET['item_id']);
1141
-            if ($debug > 0) error_log('New LP - start_current_item()', 0);
1142
-            $_SESSION['oLP']->start_current_item();
1143
-            require 'lp_content.php';
1144
-        }
1145
-        break;
1146
-    case 'view':
1147
-        if (!$lp_found) {
1148
-            error_log('New LP - No learnpath given for view', 0);
1149 1183
             require 'lp_list.php';
1150
-        } else {
1151
-            if ($debug > 0) {error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0); }
1152
-            if ( !empty($_REQUEST['item_id']) ) {
1153
-                $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
1184
+            break;
1185
+        case 'mode':
1186
+            // Switch between fullscreen and embedded mode.
1187
+            $mode = $_REQUEST['mode'];
1188
+            if ($mode == 'fullscreen') {
1189
+                $_SESSION['oLP']->mode = 'fullscreen';
1190
+            } elseif ($mode == 'embedded') {
1191
+                $_SESSION['oLP']->mode = 'embedded';
1192
+            } elseif ($mode == 'embedframe') {
1193
+        	    $_SESSION['oLP']->mode = 'embedframe';
1194
+            } elseif ($mode == 'impress') {
1195
+                $_SESSION['oLP']->mode = 'impress';
1154 1196
             }
1155 1197
             require 'lp_view.php';
1156
-        }
1157
-        break;
1158
-    case 'save':
1159
-        if (!$lp_found) {
1160
-            error_log('New LP - No learnpath given for save', 0);
1161
-            require 'lp_list.php';
1162
-        } else {
1163
-            $_SESSION['oLP']->save_item();
1164
-            require 'lp_save.php';
1165
-        }
1166
-        break;
1167
-    case 'stats':
1168
-        if (!$lp_found) {
1169
-            error_log('New LP - No learnpath given for stats', 0);
1170
-            require 'lp_list.php';
1171
-        } else {
1172
-            $_SESSION['oLP']->save_current();
1173
-            $_SESSION['oLP']->save_last();
1174
-            $output = require 'lp_stats.php';
1175
-            echo $output;
1176
-        }
1177
-        break;
1178
-    case 'list':
1179
-        if ($lp_found) {
1180
-            $_SESSION['refresh'] = 1;
1181
-            $_SESSION['oLP']->save_last();
1182
-        }
1183
-        require 'lp_list.php';
1184
-        break;
1185
-    case 'mode':
1186
-        // Switch between fullscreen and embedded mode.
1187
-        $mode = $_REQUEST['mode'];
1188
-        if ($mode == 'fullscreen') {
1189
-            $_SESSION['oLP']->mode = 'fullscreen';
1190
-        } elseif ($mode == 'embedded') {
1191
-            $_SESSION['oLP']->mode = 'embedded';
1192
-        } elseif ($mode == 'embedframe') {
1193
-        	$_SESSION['oLP']->mode = 'embedframe';
1194
-        } elseif ($mode == 'impress') {
1195
-            $_SESSION['oLP']->mode = 'impress';
1196
-        }
1197
-        require 'lp_view.php';
1198
-        break;
1199
-    case 'switch_view_mode':
1200
-        if (!$lp_found) {
1201
-            error_log('New LP - No learnpath given for switch', 0);
1198
+            break;
1199
+        case 'switch_view_mode':
1200
+            if (!$lp_found) {
1201
+                error_log('New LP - No learnpath given for switch', 0);
1202
+                require 'lp_list.php';
1203
+            }
1204
+            if (Security::check_token('get')) {
1205
+                $_SESSION['refresh'] = 1;
1206
+                $_SESSION['oLP']->update_default_view_mode();
1207
+            }
1202 1208
             require 'lp_list.php';
1203
-        }
1204
-        if (Security::check_token('get')) {
1209
+            break;
1210
+        case 'switch_force_commit':
1211
+            if (!$lp_found) {
1212
+                error_log('New LP - No learnpath given for switch', 0);
1213
+                require 'lp_list.php';
1214
+            }
1205 1215
             $_SESSION['refresh'] = 1;
1206
-            $_SESSION['oLP']->update_default_view_mode();
1207
-        }
1208
-        require 'lp_list.php';
1209
-        break;
1210
-    case 'switch_force_commit':
1211
-        if (!$lp_found) {
1212
-            error_log('New LP - No learnpath given for switch', 0);
1216
+            $_SESSION['oLP']->update_default_scorm_commit();
1213 1217
             require 'lp_list.php';
1214
-        }
1215
-        $_SESSION['refresh'] = 1;
1216
-        $_SESSION['oLP']->update_default_scorm_commit();
1217
-        require 'lp_list.php';
1218
-        break;
1219
-    /* Those 2 switches have been replaced by switc_attempt_mode switch
1218
+            break;
1219
+        /* Those 2 switches have been replaced by switc_attempt_mode switch
1220 1220
     case 'switch_reinit':
1221 1221
         if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
1222 1222
         $_SESSION['refresh'] = 1;
@@ -1236,208 +1236,208 @@  discard block
 block discarded – undo
1236 1236
 		$_SESSION['oLP']->switch_attempt_mode();
1237 1237
         require 'lp_list.php';
1238 1238
         break;
1239
-    case 'switch_scorm_debug':
1240
-        if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
1241
-        $_SESSION['refresh'] = 1;
1242
-        $_SESSION['oLP']->update_scorm_debug();
1243
-        require 'lp_list.php';
1244
-        break;
1245
-    case 'intro_cmdAdd':
1246
-        // Add introduction section page.
1247
-        break;
1248
-    case 'js_api_refresh':
1249
-        if (!$lp_found) { error_log('New LP - No learnpath given for js_api_refresh', 0); require 'lp_message.php'; }
1250
-        if (isset($_REQUEST['item_id'])) {
1251
-            $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
1252
-        }
1253
-        require 'lp_message.php';
1254
-        break;
1255
-    case 'return_to_course_homepage':
1256
-        if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
1257
-        else {
1258
-            $_SESSION['oLP']->save_current();
1259
-            $_SESSION['oLP']->save_last();
1260
-            $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
1261
-            if (isset($_GET['redirectTo']) && $_GET['redirectTo'] == 'lp_list') {
1262
-                $url = 'lp_controller.php?'.api_get_cidreq();
1263
-            }
1264
-            header('location: '.$url);
1265
-            exit;
1266
-        }
1267
-        break;
1268
-    case 'search':
1269
-        /* Include the search script, it's smart enough to know when we are
1239
+        case 'switch_scorm_debug':
1240
+            if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
1241
+            $_SESSION['refresh'] = 1;
1242
+            $_SESSION['oLP']->update_scorm_debug();
1243
+            require 'lp_list.php';
1244
+            break;
1245
+        case 'intro_cmdAdd':
1246
+            // Add introduction section page.
1247
+            break;
1248
+        case 'js_api_refresh':
1249
+            if (!$lp_found) { error_log('New LP - No learnpath given for js_api_refresh', 0); require 'lp_message.php'; }
1250
+            if (isset($_REQUEST['item_id'])) {
1251
+                $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
1252
+            }
1253
+            require 'lp_message.php';
1254
+            break;
1255
+        case 'return_to_course_homepage':
1256
+            if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
1257
+            else {
1258
+                $_SESSION['oLP']->save_current();
1259
+                $_SESSION['oLP']->save_last();
1260
+                $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
1261
+                if (isset($_GET['redirectTo']) && $_GET['redirectTo'] == 'lp_list') {
1262
+                    $url = 'lp_controller.php?'.api_get_cidreq();
1263
+                }
1264
+                header('location: '.$url);
1265
+                exit;
1266
+            }
1267
+            break;
1268
+        case 'search':
1269
+            /* Include the search script, it's smart enough to know when we are
1270 1270
          * searching or not.
1271 1271
          */
1272
-        require 'lp_list_search.php';
1273
-        break;
1274
-    case 'impress':
1275
-        if (!$lp_found) {
1276
-            error_log('New LP - No learnpath given for view', 0);
1277
-            require 'lp_list.php';
1278
-        } else {
1279
-            if ($debug > 0) {error_log('New LP - Trying to impress this LP item to ' . $_REQUEST['item_id'], 0); }
1280
-            if (!empty($_REQUEST['item_id']) ) {
1281
-                $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
1272
+            require 'lp_list_search.php';
1273
+            break;
1274
+        case 'impress':
1275
+            if (!$lp_found) {
1276
+                error_log('New LP - No learnpath given for view', 0);
1277
+                require 'lp_list.php';
1278
+            } else {
1279
+                if ($debug > 0) {error_log('New LP - Trying to impress this LP item to ' . $_REQUEST['item_id'], 0); }
1280
+                if (!empty($_REQUEST['item_id']) ) {
1281
+                    $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
1282
+                }
1283
+                require 'lp_impress.php';
1284
+            }
1285
+            break;
1286
+        case 'set_previous_step_as_prerequisite':
1287
+            $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
1288
+            $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
1289
+            Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
1290
+            header('Location: '.$url);
1291
+            break;
1292
+        case 'clear_prerequisites':
1293
+            $_SESSION['oLP']->clear_prerequisites();
1294
+            $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
1295
+            Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
1296
+            header('Location: '.$url);
1297
+            break;
1298
+        case 'toggle_seriousgame': //activate/deactive seriousgame_mode
1299
+            if (!$is_allowed_to_edit) {
1300
+                api_not_allowed(true);
1282 1301
             }
1283
-            require 'lp_impress.php';
1284
-        }
1285
-        break;
1286
-    case 'set_previous_step_as_prerequisite':
1287
-        $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
1288
-        $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
1289
-        Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
1290
-        header('Location: '.$url);
1291
-        break;
1292
-    case 'clear_prerequisites':
1293
-        $_SESSION['oLP']->clear_prerequisites();
1294
-        $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
1295
-        Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
1296
-        header('Location: '.$url);
1297
-        break;
1298
-    case 'toggle_seriousgame': //activate/deactive seriousgame_mode
1299
-        if (!$is_allowed_to_edit) {
1300
-            api_not_allowed(true);
1301
-        }
1302 1302
 
1303
-        if (!$lp_found) {
1304
-            error_log('New LP - No learnpath given for visibility');
1303
+            if (!$lp_found) {
1304
+                error_log('New LP - No learnpath given for visibility');
1305 1305
 
1306
-            require 'lp_list.php';
1307
-        }
1306
+                require 'lp_list.php';
1307
+            }
1308 1308
 
1309
-        $_SESSION['refresh'] = 1;
1310
-        $_SESSION['oLP']->set_seriousgame_mode();
1311
-        require 'lp_list.php';
1312
-        break;
1313
-    case 'create_forum':
1314
-        if (!isset($_GET['id'])) {
1309
+            $_SESSION['refresh'] = 1;
1310
+            $_SESSION['oLP']->set_seriousgame_mode();
1311
+            require 'lp_list.php';
1315 1312
             break;
1316
-        }
1317
-
1318
-        $selectedItem = null;
1319
-        foreach ($_SESSION['oLP']->items as $item) {
1320
-            if ($item->db_id == $_GET['id']) {
1321
-                $selectedItem = $item;
1313
+        case 'create_forum':
1314
+            if (!isset($_GET['id'])) {
1315
+                break;
1322 1316
             }
1323
-        }
1324
-
1325
-        if (!empty($selectedItem)) {
1326
-            $forumThread = $selectedItem->getForumThread(
1327
-                $_SESSION['oLP']->course_int_id,
1328
-                $_SESSION['oLP']->lp_session_id
1329
-            );
1330 1317
 
1331
-            if (empty($forumThread)) {
1332
-                require '../forum/forumfunction.inc.php';
1318
+            $selectedItem = null;
1319
+            foreach ($_SESSION['oLP']->items as $item) {
1320
+                if ($item->db_id == $_GET['id']) {
1321
+                    $selectedItem = $item;
1322
+                }
1323
+            }
1333 1324
 
1334
-                $forumCategory = getForumCategoryByTitle(
1335
-                    get_lang('LearningPaths'),
1325
+            if (!empty($selectedItem)) {
1326
+                $forumThread = $selectedItem->getForumThread(
1336 1327
                     $_SESSION['oLP']->course_int_id,
1337 1328
                     $_SESSION['oLP']->lp_session_id
1338 1329
                 );
1339 1330
 
1340
-                $forumCategoryId = !empty($forumCategory) ? $forumCategory['cat_id']: 0;
1341
-
1342
-                if (empty($forumCategoryId)) {
1343
-                    $forumCategoryId = store_forumcategory(
1344
-                        [
1345
-                            'lp_id' => 0,
1346
-                            'forum_category_title' => get_lang('LearningPaths'),
1347
-                            'forum_category_comment' => null
1348
-                        ],
1349
-                        [],
1350
-                        false
1351
-                    );
1352
-                }
1331
+                if (empty($forumThread)) {
1332
+                    require '../forum/forumfunction.inc.php';
1353 1333
 
1354
-                if (!empty($forumCategoryId)) {
1355
-                    $forum = $_SESSION['oLP']->getForum(
1334
+                    $forumCategory = getForumCategoryByTitle(
1335
+                        get_lang('LearningPaths'),
1336
+                        $_SESSION['oLP']->course_int_id,
1356 1337
                         $_SESSION['oLP']->lp_session_id
1357 1338
                     );
1358 1339
 
1359
-                    $forumId = !empty($forum) ? $forum['forum_id'] : 0;
1360
-
1361
-                    if (empty($forumId)) {
1362
-                        $forumId = $_SESSION['oLP']->createForum($forumCategoryId);
1340
+                    $forumCategoryId = !empty($forumCategory) ? $forumCategory['cat_id']: 0;
1341
+
1342
+                    if (empty($forumCategoryId)) {
1343
+                        $forumCategoryId = store_forumcategory(
1344
+                            [
1345
+                                'lp_id' => 0,
1346
+                                'forum_category_title' => get_lang('LearningPaths'),
1347
+                                'forum_category_comment' => null
1348
+                            ],
1349
+                            [],
1350
+                            false
1351
+                        );
1363 1352
                     }
1364 1353
 
1365
-                    if (!empty($forumId)) {
1366
-                        $selectedItem->createForumThread($forumId);
1354
+                    if (!empty($forumCategoryId)) {
1355
+                        $forum = $_SESSION['oLP']->getForum(
1356
+                            $_SESSION['oLP']->lp_session_id
1357
+                        );
1358
+
1359
+                        $forumId = !empty($forum) ? $forum['forum_id'] : 0;
1360
+
1361
+                        if (empty($forumId)) {
1362
+                            $forumId = $_SESSION['oLP']->createForum($forumCategoryId);
1363
+                        }
1364
+
1365
+                        if (!empty($forumId)) {
1366
+                            $selectedItem->createForumThread($forumId);
1367
+                        }
1367 1368
                     }
1368 1369
                 }
1369 1370
             }
1370
-        }
1371 1371
 
1372
-        header('Location:' . api_get_self() . '?' . http_build_query([
1373
-            'action' => 'add_item',
1374
-            'type' => 'step',
1375
-            'lp_id' => $_SESSION['oLP']->lp_id
1376
-        ]));
1372
+            header('Location:' . api_get_self() . '?' . http_build_query([
1373
+                'action' => 'add_item',
1374
+                'type' => 'step',
1375
+                'lp_id' => $_SESSION['oLP']->lp_id
1376
+            ]));
1377 1377
 
1378
-        break;
1379
-    case 'report':
1380
-        require 'lp_report.php';
1381
-        break;
1382
-    case 'dissociate_forum':
1383
-        if (!isset($_GET['id'])) {
1384 1378
             break;
1385
-        }
1379
+        case 'report':
1380
+            require 'lp_report.php';
1381
+            break;
1382
+        case 'dissociate_forum':
1383
+            if (!isset($_GET['id'])) {
1384
+                break;
1385
+            }
1386 1386
 
1387
-        $selectedItem = null;
1388
-        foreach ($_SESSION['oLP']->items as $item) {
1389
-            if ($item->db_id != $_GET['id']) {
1390
-                continue;
1387
+            $selectedItem = null;
1388
+            foreach ($_SESSION['oLP']->items as $item) {
1389
+                if ($item->db_id != $_GET['id']) {
1390
+                    continue;
1391
+                }
1392
+                $selectedItem = $item;
1391 1393
             }
1392
-            $selectedItem = $item;
1393
-        }
1394 1394
 
1395
-        if (!empty($selectedItem)) {
1396
-            $forumThread = $selectedItem->getForumThread(
1397
-                $_SESSION['oLP']->course_int_id,
1398
-                $_SESSION['oLP']->lp_session_id
1399
-            );
1395
+            if (!empty($selectedItem)) {
1396
+                $forumThread = $selectedItem->getForumThread(
1397
+                    $_SESSION['oLP']->course_int_id,
1398
+                    $_SESSION['oLP']->lp_session_id
1399
+                );
1400 1400
 
1401
-            if (!empty($forumThread)) {
1402
-                $dissociated = $selectedItem->dissociateForumThread($forumThread['iid']);
1401
+                if (!empty($forumThread)) {
1402
+                    $dissociated = $selectedItem->dissociateForumThread($forumThread['iid']);
1403 1403
 
1404
-                if ($dissociated) {
1405
-                    Display::addFlash(
1406
-                        Display::return_message(get_lang('ForumDissociate'), 'success')
1407
-                    );
1404
+                    if ($dissociated) {
1405
+                        Display::addFlash(
1406
+                            Display::return_message(get_lang('ForumDissociate'), 'success')
1407
+                        );
1408
+                    }
1408 1409
                 }
1409 1410
             }
1410
-        }
1411 1411
 
1412
-        header('Location:' . api_get_self() . '?' . http_build_query([
1413
-            'action' => 'add_item',
1414
-            'type' => 'step',
1415
-            'lp_id' => $_SESSION['oLP']->lp_id
1416
-        ]));
1417
-        break;
1418
-    case 'add_final_item':
1419
-        if (!$lp_found) {
1420
-            Display::addFlash(
1421
-                Display::return_message(get_lang('NoLPFound'), 'error')
1422
-            );
1412
+            header('Location:' . api_get_self() . '?' . http_build_query([
1413
+                'action' => 'add_item',
1414
+                'type' => 'step',
1415
+                'lp_id' => $_SESSION['oLP']->lp_id
1416
+            ]));
1423 1417
             break;
1424
-        }
1418
+        case 'add_final_item':
1419
+            if (!$lp_found) {
1420
+                Display::addFlash(
1421
+                    Display::return_message(get_lang('NoLPFound'), 'error')
1422
+                );
1423
+                break;
1424
+            }
1425 1425
 
1426
-        $_SESSION['refresh'] = 1;
1427
-        if (!isset($_POST['submit']) || empty($post_title)) {
1428
-            break;
1429
-        }
1426
+            $_SESSION['refresh'] = 1;
1427
+            if (!isset($_POST['submit']) || empty($post_title)) {
1428
+                break;
1429
+            }
1430 1430
 
1431
-        $_SESSION['oLP']->getFinalItemForm();
1432
-        $redirectTo = api_get_self() . '?' . api_get_cidreq().'&'.http_build_query([
1433
-            'action' => 'add_item',
1434
-            'type' => 'step',
1435
-            'lp_id' => intval($_SESSION['oLP']->lp_id)
1436
-        ]);
1437
-        break;
1438
-    default:
1439
-        require 'lp_list.php';
1440
-        break;
1431
+            $_SESSION['oLP']->getFinalItemForm();
1432
+            $redirectTo = api_get_self() . '?' . api_get_cidreq().'&'.http_build_query([
1433
+                'action' => 'add_item',
1434
+                'type' => 'step',
1435
+                'lp_id' => intval($_SESSION['oLP']->lp_id)
1436
+            ]);
1437
+            break;
1438
+        default:
1439
+            require 'lp_list.php';
1440
+            break;
1441 1441
 }
1442 1442
 
1443 1443
 if (!empty($_SESSION['oLP'])) {
Please login to merge, or discard this patch.
main/session/session_course_user_list.php 1 patch
Switch Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -55,28 +55,28 @@
 block discarded – undo
55 55
 }
56 56
 
57 57
 switch ($action) {
58
-    case 'delete':
59
-        if (is_array($idChecked) && count($idChecked) > 0) {
60
-            array_map('intval', $idChecked);
61
-            $idChecked = implode(',', $idChecked);
62
-        }
63
-        if (!empty($idChecked)) {
64
-            $sql = "DELETE FROM $tbl_session_rel_course_rel_user
58
+        case 'delete':
59
+            if (is_array($idChecked) && count($idChecked) > 0) {
60
+                array_map('intval', $idChecked);
61
+                $idChecked = implode(',', $idChecked);
62
+            }
63
+            if (!empty($idChecked)) {
64
+                $sql = "DELETE FROM $tbl_session_rel_course_rel_user
65 65
                     WHERE session_id='$id_session' AND c_id='".$courseId."' AND user_id IN($idChecked)";
66
-            $result = Database::query($sql);
67
-            $nbr_affected_rows = Database::affected_rows($result);
68
-            $sql = "UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows
66
+                $result = Database::query($sql);
67
+                $nbr_affected_rows = Database::affected_rows($result);
68
+                $sql = "UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows
69 69
                     WHERE session_id='$id_session' AND c_id='".$courseId."'";
70
-            Database::query($sql);
71
-        }
72
-        header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
73
-        exit();
74
-        break;
75
-    case 'add':
76
-        SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $course_code);
77
-        header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
78
-        exit;
79
-        break;
70
+                Database::query($sql);
71
+            }
72
+            header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
73
+            exit();
74
+            break;
75
+        case 'add':
76
+            SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $course_code);
77
+            header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort);
78
+            exit;
79
+            break;
80 80
 }
81 81
 
82 82
 
Please login to merge, or discard this patch.
main/inc/ajax/chat.ajax.php 1 patch
Switch Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -47,56 +47,56 @@
 block discarded – undo
47 47
 }
48 48
 
49 49
 switch ($action) {
50
-    case 'chatheartbeat':
51
-        $chat->heartbeat();
52
-        break;
53
-    case 'closechat':
54
-        $chat->close();
55
-        break;
56
-    case 'sendchat':
57
-        $chat->send(api_get_user_id(), $to_user_id, $message);
58
-        break;
59
-    case 'startchatsession':
60
-        $chat->startSession();
61
-        break;
62
-    case 'set_status':
63
-        $status = isset($_REQUEST['status']) ? intval($_REQUEST['status']) : 0;
64
-        $chat->setUserStatus($status);
65
-        break;
66
-    case 'create_room':
67
-        $room = VideoChat::getChatRoomByUsers(api_get_user_id(), $to_user_id);
68
-
69
-        if ($room === false) {
70
-            $createdRoom = VideoChat::createRoom(api_get_user_id(), $to_user_id);
71
-
72
-            if ($createdRoom === false) {
73
-                echo Display::return_message(get_lang('ChatRoomNotCreated'), 'error');
74
-                break;
50
+        case 'chatheartbeat':
51
+            $chat->heartbeat();
52
+            break;
53
+        case 'closechat':
54
+            $chat->close();
55
+            break;
56
+        case 'sendchat':
57
+            $chat->send(api_get_user_id(), $to_user_id, $message);
58
+            break;
59
+        case 'startchatsession':
60
+            $chat->startSession();
61
+            break;
62
+        case 'set_status':
63
+            $status = isset($_REQUEST['status']) ? intval($_REQUEST['status']) : 0;
64
+            $chat->setUserStatus($status);
65
+            break;
66
+        case 'create_room':
67
+            $room = VideoChat::getChatRoomByUsers(api_get_user_id(), $to_user_id);
68
+
69
+            if ($room === false) {
70
+                $createdRoom = VideoChat::createRoom(api_get_user_id(), $to_user_id);
71
+
72
+                if ($createdRoom === false) {
73
+                    echo Display::return_message(get_lang('ChatRoomNotCreated'), 'error');
74
+                    break;
75
+                }
76
+
77
+                $room = VideoChat::getChatRoomByUsers(api_get_user_id(), $to_user_id);
75 78
             }
76 79
 
77
-            $room = VideoChat::getChatRoomByUsers(api_get_user_id(), $to_user_id);
78
-        }
79
-
80
-        $videoChatUrl = api_get_path(WEB_CODE_PATH) . "chat/video.php?room={$room['id']}";
81
-        $videoChatLink = Display::url(
82
-            Display::returnFontAwesomeIcon('video-camera').get_lang('StartVideoChat'),
83
-            $videoChatUrl
84
-        );
85
-
86
-        $chat->send(
87
-            api_get_user_id(),
88
-            $to_user_id,
89
-            $videoChatLink,
90
-            false,
91
-            false
92
-        );
93
-
94
-        echo Display::tag('p', $videoChatLink, ['class' => 'lead']);
95
-        break;
96
-    case 'notify_not_support':
97
-        $chat->send(api_get_user_id(), $to_user_id, get_lang('TheXUserBrowserDoesNotSupportWebRTC'));
98
-        break;
99
-    default:
100
-        echo '';
80
+            $videoChatUrl = api_get_path(WEB_CODE_PATH) . "chat/video.php?room={$room['id']}";
81
+            $videoChatLink = Display::url(
82
+                Display::returnFontAwesomeIcon('video-camera').get_lang('StartVideoChat'),
83
+                $videoChatUrl
84
+            );
85
+
86
+            $chat->send(
87
+                api_get_user_id(),
88
+                $to_user_id,
89
+                $videoChatLink,
90
+                false,
91
+                false
92
+            );
93
+
94
+            echo Display::tag('p', $videoChatLink, ['class' => 'lead']);
95
+            break;
96
+        case 'notify_not_support':
97
+            $chat->send(api_get_user_id(), $to_user_id, get_lang('TheXUserBrowserDoesNotSupportWebRTC'));
98
+            break;
99
+        default:
100
+            echo '';
101 101
 }
102 102
 exit;
Please login to merge, or discard this patch.