Passed
Push — master ( fb9bbb...88f99d )
by Julito
06:51
created

CourseController::welcome()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Controller;
8
9
use Chamilo\CoreBundle\Entity\Course;
10
use Chamilo\CoreBundle\Entity\ExtraField;
11
use Chamilo\CoreBundle\Entity\ExtraFieldRelTag;
12
use Chamilo\CoreBundle\Framework\Container;
13
use Chamilo\CoreBundle\Repository\ExtraFieldRelTagRepository;
14
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
15
use Chamilo\CoreBundle\Security\Authorization\Voter\CourseVoter;
16
use Chamilo\CoreBundle\Tool\ToolChain;
17
use Chamilo\CourseBundle\Controller\ToolBaseController;
18
use Chamilo\CourseBundle\Entity\CCourseDescription;
19
use Chamilo\CourseBundle\Entity\CTool;
20
use Chamilo\CourseBundle\Repository\CCourseDescriptionRepository;
21
use Chamilo\CourseBundle\Repository\CShortcutRepository;
22
use Chamilo\CourseBundle\Repository\CToolRepository;
23
use Chamilo\CourseBundle\Settings\SettingsCourseManager;
24
use Chamilo\CourseBundle\Settings\SettingsFormFactory;
25
use CourseManager;
26
use Database;
27
use Display;
28
use Doctrine\ORM\EntityRepository;
29
use Event;
30
use Exercise;
31
use ExtraFieldValue;
32
use Fhaculty\Graph\Graph;
33
use Security;
34
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
35
use Symfony\Component\HttpFoundation\RedirectResponse;
36
use Symfony\Component\HttpFoundation\Request;
37
use Symfony\Component\HttpFoundation\Response;
38
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
39
use Symfony\Component\Routing\Annotation\Route;
40
use Symfony\Component\Validator\Exception\ValidatorException;
41
use UnserializeApi;
42
use UserManager;
43
44
/**
45
 * @author Julio Montoya <[email protected]>
46
 */
47
#[Route('/course')]
48
class CourseController extends ToolBaseController
49
{
50
    #[Route('/{cid}/home.json', name: 'chamilo_core_course_home_json')]
51
    #[Entity('course', expr: 'repository.find(cid)')]
52
    public function indexJsonAction(Request $request, CToolRepository $toolRepository, CShortcutRepository $shortcutRepository, ToolChain $toolChain): Response
53
    {
54
        $course = $this->getCourse();
55
56
        if (null === $course) {
57
            throw $this->createAccessDeniedException();
58
        }
59
60
        $this->denyAccessUnlessGranted(CourseVoter::VIEW, $course);
61
62
        $session = $request->getSession();
63
64
        $userId = 0;
65
        $user = $this->getUser();
66
        if (null !== $user) {
67
            $userId = $user->getId();
68
        }
69
70
        $courseCode = $course->getCode();
71
        $courseId = $course->getId();
72
        $sessionId = $this->getSessionId();
73
74
        if ($user && $user->hasRole('ROLE_INVITEE')) {
75
            $isInASession = $sessionId > 0;
76
            $isSubscribed = CourseManager::is_user_subscribed_in_course(
77
                $userId,
78
                $courseCode,
79
                $isInASession,
80
                $sessionId
81
            );
82
83
            if (!$isSubscribed) {
84
                throw $this->createAccessDeniedException();
85
            }
86
        }
87
88
        $isSpecialCourse = CourseManager::isSpecialCourse($courseId);
89
90
        if ($user && $isSpecialCourse && (isset($_GET['autoreg']) && 1 === (int) $_GET['autoreg']) &&
91
            CourseManager::subscribeUser($userId, $courseId, STUDENT)
92
        ) {
93
            $session->set('is_allowed_in_course', true);
94
        }
95
96
        /*$action = empty($_GET['action']) ? '' : Security::remove_XSS($_GET['action']);
97
        if ('subscribe' === $action && Security::check_token('get')) {
98
            Security::clear_token();
99
            $result = CourseManager::autoSubscribeToCourse($courseCode);
100
            if ($result && CourseManager::is_user_subscribed_in_course($userId, $courseCode)) {
101
                $session->set('is_allowed_in_course', true);
102
            }
103
            header('Location: '.api_get_self());
104
            exit;
105
        }
106
107
        $logInfo = [
108
            'tool' => 'course-main',
109
            'action' => $action,
110
        ];
111
        Event::registerLog($logInfo);*/
112
        $logInfo = [
113
            'tool' => 'course-main',
114
        ];
115
        Event::registerLog($logInfo);
116
117
        $qb = $toolRepository->getResourcesByCourse($course, $this->getSession());
118
119
        $qb->addSelect('tool');
120
        $qb->innerJoin('resource.tool', 'tool');
121
122
        $result = $qb->getQuery()->getResult();
123
        $tools = [];
124
        $isCourseTeacher = $this->isGranted('ROLE_CURRENT_COURSE_TEACHER');
125
126
        $skipTools = ['course_tool', 'chat', 'notebook', 'wiki'];
127
128
        /** @var CTool $item */
129
        foreach ($result as $item) {
130
            if (\in_array($item->getName(), $skipTools, true)) {
131
                continue;
132
            }
133
            $toolModel = $toolChain->getToolFromName($item->getTool()->getName());
134
135
            if (!$isCourseTeacher && 'admin' === $toolModel->getCategory()) {
136
                continue;
137
            }
138
139
            $tools[$toolModel->getCategory()][] = [
140
                'ctool' => $item,
141
                'tool' => $toolModel,
142
            ];
143
        }
144
145
        // Get session-career diagram
146
        $diagram = '';
147
        /*$allow = api_get_configuration_value('allow_career_diagram');
148
        if (true === $allow) {
149
            $htmlHeadXtra[] = api_get_js('jsplumb2.js');
150
            $extra = new ExtraFieldValue('session');
151
            $value = $extra->get_values_by_handler_and_field_variable(
152
                api_get_session_id(),
153
                'external_career_id'
154
            );
155
156
            if (!empty($value) && isset($value['value'])) {
157
                $careerId = $value['value'];
158
                $extraFieldValue = new ExtraFieldValue('career');
159
                $item = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
160
                    'external_career_id',
161
                    $careerId,
162
                    false,
163
                    false,
164
                    false
165
                );
166
167
                if (!empty($item) && isset($item['item_id'])) {
168
                    $careerId = $item['item_id'];
169
                    $career = new Career();
170
                    $careerInfo = $career->get($careerId);
171
                    if (!empty($careerInfo)) {
172
                        $extraFieldValue = new ExtraFieldValue('career');
173
                        $item = $extraFieldValue->get_values_by_handler_and_field_variable(
174
                            $careerId,
175
                            'career_diagram',
176
                            false,
177
                            false,
178
                            0
179
                        );
180
181
                        if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
182
                            // @var Graph $graph
183
                            $graph = UnserializeApi::unserialize('career', $item['value']);
184
                            $diagram = Career::renderDiagram($careerInfo, $graph);
185
                        }
186
                    }
187
                }
188
            }
189
        }*/
190
191
        // Deleting the objects
192
        $session->remove('toolgroup');
193
        $session->remove('_gid');
194
        $session->remove('oLP');
195
        $session->remove('lpobject');
196
197
        api_remove_in_gradebook();
198
        Exercise::cleanSessionVariables();
199
200
        $shortcuts = [];
201
        if (null !== $user) {
202
            $shortcutQuery = $shortcutRepository->getResources($course->getResourceNode());
203
            $shortcuts = $shortcutQuery->getQuery()->getResult();
204
        }
205
        $responseData = [
206
            'course' => $course,
207
            'shortcuts' => $shortcuts,
208
            'diagram' => $diagram,
209
            'tools' => $tools,
210
        ];
211
212
        $json = $this->get('serializer')->serialize(
213
            $responseData,
214
            'json',
215
            [
216
                'groups' => ['course:read', 'ctool:read', 'tool:read', 'cshortcut:read'],
217
            ]
218
        );
219
220
        return new Response(
221
            $json,
222
            Response::HTTP_OK,
223
            [
224
                'Content-type' => 'application/json',
225
            ]
226
        );
227
        /*return $this->render(
228
            '@ChamiloCore/Course/home.html.twig',
229
            [
230
                'course' => $course,
231
                'shortcuts' => $shortcuts,
232
                'diagram' => $diagram,
233
                'tools' => $tools,
234
            ]
235
        );*/
236
    }
237
238
    /**
239
     * Redirects the page to a tool, following the tools.yml settings.
240
     */
241
    #[Route('/{cid}/tool/{toolName}', name: 'chamilo_core_course_redirect_tool')]
242
    public function redirectTool(string $toolName, CToolRepository $repo, ToolChain $toolChain): RedirectResponse
243
    {
244
        /** @var CTool|null $tool */
245
        $tool = $repo->findOneBy([
246
            'name' => $toolName,
247
        ]);
248
249
        if (null === $tool) {
250
            throw new NotFoundHttpException($this->trans('Tool not found'));
251
        }
252
253
        $tool = $toolChain->getToolFromName($tool->getTool()->getName());
254
        $link = $tool->getLink();
255
256
        if (null === $this->getCourse()) {
257
            throw new NotFoundHttpException($this->trans('Course not found'));
258
        }
259
260
        if (strpos($link, 'nodeId')) {
261
            $nodeId = (string) $this->getCourse()->getResourceNode()->getId();
262
            $link = str_replace(':nodeId', $nodeId, $link);
263
        }
264
265
        $url = $link.'?'.$this->getCourseUrlQuery();
266
267
        return $this->redirect($url);
268
    }
269
270
    public function redirectToShortCut(string $toolName, CToolRepository $repo, ToolChain $toolChain): RedirectResponse
271
    {
272
        /** @var CTool|null $tool */
273
        $tool = $repo->findOneBy([
274
            'name' => $toolName,
275
        ]);
276
277
        if (null === $tool) {
278
            throw new NotFoundHttpException($this->trans('Tool not found'));
279
        }
280
281
        $tool = $toolChain->getToolFromName($tool->getTool()->getName());
282
        $link = $tool->getLink();
283
284
        if (strpos($link, 'nodeId')) {
285
            $nodeId = (string) $this->getCourse()->getResourceNode()->getId();
286
            $link = str_replace(':nodeId', $nodeId, $link);
287
        }
288
289
        $url = $link.'?'.$this->getCourseUrlQuery();
290
291
        return $this->redirect($url);
292
    }
293
294
    /**
295
     * Edit configuration with given namespace.
296
     */
297
    #[Route('/{cid}/settings/{namespace}', name: 'chamilo_core_course_settings')]
298
    #[Entity('course', expr: 'repository.find(cid)')]
299
    public function updateSettings(Request $request, Course $course, string $namespace, SettingsCourseManager $manager, SettingsFormFactory $formFactory): Response
300
    {
301
        $this->denyAccessUnlessGranted(CourseVoter::VIEW, $course);
302
303
        $schemaAlias = $manager->convertNameSpaceToService($namespace);
304
        $settings = $manager->load($namespace);
305
306
        $form = $formFactory->create($schemaAlias);
307
308
        $form->setData($settings);
309
        $form->handleRequest($request);
310
311
        if ($form->isSubmitted() && $form->isValid()) {
312
            $messageType = 'success';
313
314
            try {
315
                $manager->setCourse($course);
316
                $manager->save($form->getData());
317
                $message = $this->trans('Update');
318
            } catch (ValidatorException $validatorException) {
319
                $message = $this->trans($validatorException->getMessage());
320
                $messageType = 'error';
321
            }
322
            $this->addFlash($messageType, $message);
323
324
            if ($request->headers->has('referer')) {
325
                return $this->redirect($request->headers->get('referer'));
326
            }
327
        }
328
329
        $schemas = $manager->getSchemas();
330
331
        return $this->render(
332
            '@ChamiloCore/Course/settings.html.twig',
333
            [
334
                'course' => $course,
335
                'schemas' => $schemas,
336
                'settings' => $settings,
337
                'form' => $form->createView(),
338
            ]
339
        );
340
    }
341
342
    #[Route('/{id}/about', name: 'chamilo_core_course_about')]
343
    public function about(Course $course, IllustrationRepository $illustrationRepository, CCourseDescriptionRepository $courseDescriptionRepository): Response
344
    {
345
        $courseId = $course->getId();
346
        $userId = $this->getUser()->getId();
347
        $em = $this->getDoctrine()->getManager();
348
349
        /** @var EntityRepository $fieldsRepo */
350
        $fieldsRepo = $em->getRepository(ExtraField::class);
351
        /** @var ExtraFieldRelTagRepository $fieldTagsRepo */
352
        $fieldTagsRepo = $em->getRepository(ExtraFieldRelTag::class);
353
354
        $courseDescriptions = $courseDescriptionRepository->getResourcesByCourse($course)->getQuery()->getResult();
355
356
        $courseValues = new ExtraFieldValue('course');
357
358
        $urlCourse = api_get_path(WEB_PATH).sprintf('course/%s/about', $courseId);
359
        $courseTeachers = $course->getTeachers();
360
        $teachersData = [];
361
362
        foreach ($courseTeachers as $teacherSubscription) {
363
            $teacher = $teacherSubscription->getUser();
364
            $userData = [
365
                'complete_name' => UserManager::formatUserFullName($teacher),
366
                'image' => $illustrationRepository->getIllustrationUrl($teacher),
367
                'diploma' => $teacher->getDiplomas(),
368
                'openarea' => $teacher->getOpenarea(),
369
            ];
370
371
            $teachersData[] = $userData;
372
        }
373
        /** @var ExtraField $tagField */
374
        $tagField = $fieldsRepo->findOneBy([
375
            'extraFieldType' => ExtraField::COURSE_FIELD_TYPE,
376
            'variable' => 'tags',
377
        ]);
378
379
        $courseTags = [];
380
        if (null !== $tagField) {
381
            $courseTags = $fieldTagsRepo->getTags($tagField, $courseId);
382
        }
383
384
        $courseDescription = $courseObjectives = $courseTopics = $courseMethodology = '';
385
        $courseMaterial = $courseResources = $courseAssessment = '';
386
        $courseCustom = [];
387
        foreach ($courseDescriptions as $descriptionTool) {
388
            switch ($descriptionTool->getDescriptionType()) {
389
                case CCourseDescription::TYPE_DESCRIPTION:
390
                    $courseDescription = $descriptionTool->getContent();
391
392
                    break;
393
                case CCourseDescription::TYPE_OBJECTIVES:
394
                    $courseObjectives = $descriptionTool;
395
396
                    break;
397
                case CCourseDescription::TYPE_TOPICS:
398
                    $courseTopics = $descriptionTool;
399
400
                    break;
401
                case CCourseDescription::TYPE_METHODOLOGY:
402
                    $courseMethodology = $descriptionTool;
403
404
                    break;
405
                case CCourseDescription::TYPE_COURSE_MATERIAL:
406
                    $courseMaterial = $descriptionTool;
407
408
                    break;
409
                case CCourseDescription::TYPE_RESOURCES:
410
                    $courseResources = $descriptionTool;
411
412
                    break;
413
                case CCourseDescription::TYPE_ASSESSMENT:
414
                    $courseAssessment = $descriptionTool;
415
416
                    break;
417
                case CCourseDescription::TYPE_CUSTOM:
418
                    $courseCustom[] = $descriptionTool;
419
420
                    break;
421
            }
422
        }
423
424
        $topics = [
425
            'objectives' => $courseObjectives,
426
            'topics' => $courseTopics,
427
            'methodology' => $courseMethodology,
428
            'material' => $courseMaterial,
429
            'resources' => $courseResources,
430
            'assessment' => $courseAssessment,
431
            'custom' => array_reverse($courseCustom),
432
        ];
433
434
        $subscriptionUser = CourseManager::is_user_subscribed_in_course($userId, $course->getCode());
435
436
        /*$allowSubscribe = false;
437
        if ($course->getSubscribe() || api_is_platform_admin()) {
438
            $allowSubscribe = true;
439
        }
440
        $plugin = \BuyCoursesPlugin::create();
441
        $checker = $plugin->isEnabled();
442
        $courseIsPremium = null;
443
        if ($checker) {
444
            $courseIsPremium = $plugin->getItemByProduct(
445
                $courseId,
446
                \BuyCoursesPlugin::PRODUCT_TYPE_COURSE
447
            );
448
        }*/
449
450
        $image = Container::getIllustrationRepository()->getIllustrationUrl($course, 'course_picture_medium');
451
452
        $params = [
453
            'course' => $course,
454
            'description' => $courseDescription,
455
            'image' => $image,
456
            'syllabus' => $topics,
457
            'tags' => $courseTags,
458
            'teachers' => $teachersData,
459
            'extra_fields' => $courseValues->getAllValuesForAnItem(
460
                $course->getId(),
461
                null,
462
                true
463
            ),
464
            'subscription' => $subscriptionUser,
465
            'url' => '',
466
            'is_premium' => '',
467
            'token' => '',
468
        ];
469
470
        $metaInfo = '<meta property="og:url" content="'.$urlCourse.'" />';
471
        $metaInfo .= '<meta property="og:type" content="website" />';
472
        $metaInfo .= '<meta property="og:title" content="'.$course->getTitle().'" />';
473
        $metaInfo .= '<meta property="og:description" content="'.strip_tags($courseDescription).'" />';
474
        $metaInfo .= '<meta property="og:image" content="'.$image.'" />';
475
476
        $htmlHeadXtra[] = $metaInfo;
477
        $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js');
478
479
        return $this->render('@ChamiloCore/Course/about.html.twig', $params);
480
    }
481
482
    #[Route('/{id}/welcome', name: 'chamilo_core_course_welcome')]
483
    public function welcome(Course $course): Response
484
    {
485
        return $this->render('@ChamiloCore/Course/welcome.html.twig', [
486
            'course' => $course,
487
        ]);
488
    }
489
490
    private function autoLaunch(): void
491
    {
492
        $autoLaunchWarning = '';
493
        $showAutoLaunchLpWarning = false;
494
        $course_id = api_get_course_int_id();
495
        $lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch');
496
        $session_id = api_get_session_id();
497
        $allowAutoLaunchForCourseAdmins =
498
            api_is_platform_admin() ||
499
            api_is_allowed_to_edit(true, true) ||
500
            api_is_coach();
501
502
        if (!empty($lpAutoLaunch)) {
503
            if (2 === $lpAutoLaunch) {
504
                // LP list
505
                if ($allowAutoLaunchForCourseAdmins) {
506
                    $showAutoLaunchLpWarning = true;
507
                } else {
508
                    $session_key = 'lp_autolaunch_'.$session_id.'_'.$course_id.'_'.api_get_user_id();
509
                    if (!isset($_SESSION[$session_key])) {
510
                        // Redirecting to the LP
511
                        $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq();
512
                        $_SESSION[$session_key] = true;
513
                        header(sprintf('Location: %s', $url));
514
                        exit;
515
                    }
516
                }
517
            } else {
518
                $lp_table = Database::get_course_table(TABLE_LP_MAIN);
519
                $condition = '';
520
                if (!empty($session_id)) {
521
                    $condition = api_get_session_condition($session_id);
522
                    $sql = "SELECT id FROM {$lp_table}
523
                            WHERE c_id = {$course_id} AND autolaunch = 1 {$condition}
524
                            LIMIT 1";
525
                    $result = Database::query($sql);
526
                    // If we found nothing in the session we just called the session_id =  0 autolaunch
527
                    if (0 === Database::num_rows($result)) {
528
                        $condition = '';
529
                    }
530
                }
531
532
                $sql = "SELECT iid FROM {$lp_table}
533
                        WHERE c_id = {$course_id} AND autolaunch = 1 {$condition}
534
                        LIMIT 1";
535
                $result = Database::query($sql);
536
                if (Database::num_rows($result) > 0) {
537
                    $lp_data = Database::fetch_array($result, 'ASSOC');
538
                    if (!empty($lp_data['iid'])) {
539
                        if ($allowAutoLaunchForCourseAdmins) {
540
                            $showAutoLaunchLpWarning = true;
541
                        } else {
542
                            $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
543
                            if (!isset($_SESSION[$session_key])) {
544
                                // Redirecting to the LP
545
                                $url = api_get_path(WEB_CODE_PATH).
546
                                    'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['iid'];
547
548
                                $_SESSION[$session_key] = true;
549
                                header(sprintf('Location: %s', $url));
550
                                exit;
551
                            }
552
                        }
553
                    }
554
                }
555
            }
556
        }
557
558
        if ($showAutoLaunchLpWarning) {
559
            $autoLaunchWarning = get_lang(
560
                'The learning path auto-launch setting is ON. When learners enter this course, they will be automatically redirected to the learning path marked as auto-launch.'
561
            );
562
        }
563
564
        $forumAutoLaunch = (int) api_get_course_setting('enable_forum_auto_launch');
565
        if (1 === $forumAutoLaunch) {
566
            if ($allowAutoLaunchForCourseAdmins) {
567
                if (empty($autoLaunchWarning)) {
568
                    $autoLaunchWarning = get_lang(
569
                        "The forum's auto-launch setting is on. Students will be redirected to the forum tool when entering this course."
570
                    );
571
                }
572
            } else {
573
                $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq();
574
                header(sprintf('Location: %s', $url));
575
                exit;
576
            }
577
        }
578
579
        if (api_get_configuration_value('allow_exercise_auto_launch')) {
580
            $exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch');
581
            if (2 === $exerciseAutoLaunch) {
582
                if ($allowAutoLaunchForCourseAdmins) {
583
                    if (empty($autoLaunchWarning)) {
584
                        $autoLaunchWarning = get_lang(
585
                            'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList'
586
                        );
587
                    }
588
                } else {
589
                    // Redirecting to the document
590
                    $url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq();
591
                    header(sprintf('Location: %s', $url));
592
                    exit;
593
                }
594
            } elseif (1 === $exerciseAutoLaunch) {
595
                if ($allowAutoLaunchForCourseAdmins) {
596
                    if (empty($autoLaunchWarning)) {
597
                        $autoLaunchWarning = get_lang(
598
                            'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'
599
                        );
600
                    }
601
                } else {
602
                    // Redirecting to an exercise
603
                    $table = Database::get_course_table(TABLE_QUIZ_TEST);
604
                    $condition = '';
605
                    if (!empty($session_id)) {
606
                        $condition = api_get_session_condition($session_id);
607
                        $sql = "SELECT iid FROM {$table}
608
                                WHERE c_id = {$course_id} AND autolaunch = 1 {$condition}
609
                                LIMIT 1";
610
                        $result = Database::query($sql);
611
                        // If we found nothing in the session we just called the session_id = 0 autolaunch
612
                        if (0 === Database::num_rows($result)) {
613
                            $condition = '';
614
                        }
615
                    }
616
617
                    $sql = "SELECT iid FROM {$table}
618
                            WHERE c_id = {$course_id} AND autolaunch = 1 {$condition}
619
                            LIMIT 1";
620
                    $result = Database::query($sql);
621
                    if (Database::num_rows($result) > 0) {
622
                        $row = Database::fetch_array($result, 'ASSOC');
623
                        $exerciseId = $row['iid'];
624
                        $url = api_get_path(WEB_CODE_PATH).
625
                            'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq();
626
                        header(sprintf('Location: %s', $url));
627
                        exit;
628
                    }
629
                }
630
            }
631
        }
632
633
        $documentAutoLaunch = (int) api_get_course_setting('enable_document_auto_launch');
634
        if (1 === $documentAutoLaunch) {
635
            if ($allowAutoLaunchForCourseAdmins) {
636
                if (empty($autoLaunchWarning)) {
637
                    $autoLaunchWarning = get_lang(
638
                        'The document auto-launch feature configuration is enabled. Learners will be automatically redirected to document tool.'
639
                    );
640
                }
641
            } else {
642
                // Redirecting to the document
643
                $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq();
644
                header("Location: $url");
645
                exit;
646
            }
647
        }
648
649
        /*	SWITCH TO A DIFFERENT HOMEPAGE VIEW
650
         the setting homepage_view is adjustable through
651
         the platform administration section */
652
        if (!empty($autoLaunchWarning)) {
653
            $this->addFlash(
654
                'warning',
655
                Display::return_message(
656
                    $autoLaunchWarning,
657
                    'warning'
658
                )
659
            );
660
        }
661
    }
662
}
663