Issues (2126)

main/lp/lp_view.php (1 issue)

Severity
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CourseBundle\Entity\CLpCategory;
6
use ChamiloSession as Session;
7
8
/**
9
 * This file was originally the copy of document.php, but many modifications happened since then ;
10
 * the direct file view is not needed anymore, if the user uploads a scorm zip file, a directory
11
 * will be automatically created for it, and the files will be uncompressed there for example ;.
12
 *
13
 * @author Yannick Warnier <[email protected]> - redesign
14
 * @author Denes Nagy, principal author
15
 * @author Isthvan Mandak, several new features
16
 * @author Roan Embrechts, code improvements and refactoring
17
 */
18
$use_anonymous = true;
19
$this_section = SECTION_COURSES;
20
21
if ($lp_controller_touched != 1) {
22
    header('Location: lp_controller.php?action=view&item_id='.intval($_REQUEST['item_id']));
23
    exit;
24
}
25
26
require_once __DIR__.'/../inc/global.inc.php';
27
28
api_protect_course_script();
29
30
if (isset($_REQUEST['origin']) && $_REQUEST['origin'] === 'learnpath') {
31
    $_REQUEST['origin'] = '';
32
}
33
34
// To prevent the template class
35
$lp_id = !empty($_GET['lp_id']) ? (int) $_GET['lp_id'] : 0;
36
$sessionId = api_get_session_id();
37
$course_code = api_get_course_id();
38
$course_id = api_get_course_int_id();
39
$user_id = api_get_user_id();
40
41
// Check if the learning path is visible for student - (LP requisites)
42
if (!api_is_platform_admin()) {
43
    if (!api_is_allowed_to_edit(null, true, false, false) &&
44
        !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())
45
    ) {
46
        api_not_allowed(true);
47
    }
48
}
49
50
// Checking visibility (eye icon)
51
$visibility = api_get_item_visibility(
52
    api_get_course_info(),
53
    TOOL_LEARNPATH,
54
    $lp_id,
55
    $action,
56
    api_get_user_id(),
57
    $sessionId
58
);
59
60
if ($visibility === 0 &&
61
    !api_is_allowed_to_edit(false, true, false, false)
62
) {
63
    api_not_allowed(true);
64
}
65
66
/** @var learnpath $lp */
67
$lp = Session::read('oLP');
68
69
if (empty($lp)) {
70
    api_not_allowed(true);
71
}
72
73
$debug = 0;
74
if ($debug) {
75
    error_log('------ Entering lp_view.php -------');
76
}
77
78
$lp_item_id = $lp->get_current_item_id();
79
$lpType = $lp->get_type();
80
81
if (!$is_allowed_to_edit) {
82
    $categoryId = $lp->getCategoryId();
83
    $em = Database::getManager();
84
    if (!empty($categoryId)) {
85
        /** @var CLpCategory $category */
86
        $category = $em->getRepository('ChamiloCourseBundle:CLpCategory')->find($categoryId);
87
        $block = false;
88
        if ($category) {
0 ignored issues
show
$category is of type CLpCategory, thus it always evaluated to true.
Loading history...
89
            $user = UserManager::getRepository()->find($user_id);
90
            $users = $category->getUsers();
91
            if (!empty($users) && $users->count() > 0) {
92
                if ($user && !$category->hasUserAdded($user)) {
93
                    $block = true;
94
                }
95
            }
96
97
            $isVisible = learnpath::categoryIsVisibleForStudent(
98
                $category,
99
                $user
100
            );
101
102
            if ($isVisible) {
103
                $block = false;
104
            }
105
106
            if ($block) {
107
                api_not_allowed(true);
108
            }
109
        }
110
    }
111
}
112
113
$platform_theme = api_get_setting('stylesheets');
114
$my_style = $platform_theme;
115
$extraParams = '';
116
if (isset($_REQUEST['lti_launch_id'])) {
117
    $extraParams .= '&lti_launch_id='.Security::remove_XSS($_REQUEST['lti_launch_id']);
118
}
119
$ajaxUrl = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?a=get_item_prerequisites&'.api_get_cidreq().$extraParams;
120
$htmlHeadXtra[] = '<script>
121
<!--
122
var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
123
-->
124
</script>';
125
126
$htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css');
127
$htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js');
128
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
129
$htmlHeadXtra[] = '<script>
130
$(function() {
131
    $("div#log_content_cleaner").bind("click", function() {
132
        $("div#log_content").empty();
133
    });
134
});
135
var chamilo_xajax_handler = window.oxajax;
136
</script>';
137
if (!empty($lp->lti_launch_id)) {
138
    if (isset($_REQUEST['from']) && 'lti_provider' == $_REQUEST['from']) {
139
        $logout = api_get_path(WEB_PATH).'plugin/lti_provider/tool/logout.php?uid='.api_get_user_id();
140
        $htmlHeadXtra[] = '<script>
141
            $(function() {
142
              if ($("#btn-menu-float").length > 0) {
143
                $("#btn-menu-float").find("#home-course").show();
144
                $("#btn-menu-float").find("#home-course").attr("href", "'.$logout.'");
145
              }
146
            });
147
        </script>';
148
    } else {
149
        $htmlHeadXtra[] = '<script>
150
                $(function() {
151
                  if ($("#btn-menu-float").length > 0) {
152
                    $("#btn-menu-float").find("#home-course").hide();
153
                  }
154
                });
155
        </script>';
156
    }
157
}
158
159
$zoomOptions = api_get_configuration_value('quiz_image_zoom');
160
if (isset($zoomOptions['options']) && !in_array($origin, ['embeddable', 'noheader'])) {
161
    $options = $zoomOptions['options'];
162
    $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'jquery.elevatezoom.js"></script>';
163
    $htmlHeadXtra[] = '<script>
164
        $(function() {
165
            $("img").each(function() {
166
                var attr = $(this).attr("data-zoom-image");
167
                // For some browsers, `attr` is undefined; for others,
168
                // `attr` is false.  Check for both.
169
                if (typeof attr !== typeof undefined && attr !== false) {
170
                    $(this).elevateZoom({
171
                        scrollZoom : true,
172
                        cursor: "crosshair",
173
                        tint:true,
174
                        tintColour:\'#CCC\',
175
                        tintOpacity:0.5,
176
                        zoomWindowWidth:'.$options['zoomWindowWidth'].',
177
                        zoomWindowHeight:'.$options['zoomWindowHeight'].'
178
                    });
179
                }
180
            });
181
        });
182
    </script>';
183
}
184
185
$allowLpItemTip = api_get_configuration_value('hide_accessibility_label_on_lp_item') === false;
186
if ($allowLpItemTip) {
187
    $htmlHeadXtra[] = '<script>
188
    $(function() {
189
         $(".scorm_item_normal").qtip({
190
            content: {
191
                text: function(event, api) {
192
                    var item = $(this);
193
                    var itemId = $(this).attr("id");
194
                    itemId = itemId.replace("toc_", "");
195
                    var textToShow = "";
196
                    $.ajax({
197
                        type: "GET",
198
                        url: "'.$ajaxUrl.'&item_id="+ itemId,
199
                        async: false
200
                    })
201
                    .then(function(content) {
202
                        if (content == 1) {
203
                            textToShow = "'.addslashes(get_lang('LPItemCanBeAccessed')).'";
204
                            api.set("style.classes", "qtip-green qtip-shadow");
205
                        } else {
206
                            textToShow = content;
207
                            api.set("style.classes", "qtip-red qtip-shadow");
208
                        }
209
210
                        return textToShow;
211
                    });
212
                    return textToShow;
213
                }
214
            }
215
        });
216
    });
217
    </script>';
218
}
219
220
// Impress js
221
if ($lp->mode === 'impress') {
222
    $lp_id = $lp->get_id();
223
    $url = api_get_path(WEB_CODE_PATH)."lp/lp_impress.php?lp_id=$lp_id&".api_get_cidreq();
224
    header("Location: $url");
225
    exit;
226
}
227
228
// Prepare variables for the test tool (just in case) - honestly, this should disappear later on.
229
Session::write('scorm_view_id', $lp->get_view_id());
230
Session::write('scorm_item_id', $lp_item_id);
231
232
// Reinit exercises variables to avoid spacename clashes (see exercise tool)
233
if (isset($exerciseResult) || isset($_SESSION['exerciseResult'])) {
234
    Session::erase('exerciseResult');
235
    Session::erase('objExercise');
236
    Session::erase('questionList');
237
    Session::erase('duration_time_previous');
238
    Session::erase('duration_time');
239
}
240
241
// additional APIs
242
$htmlHeadXtra[] = '<script>
243
chamilo_courseCode = "'.$course_code.'";
244
</script>';
245
// Document API
246
$htmlHeadXtra[] = '<script src="js/documentapi.js" type="text/javascript" language="javascript"></script>';
247
// Storage API
248
$htmlHeadXtra[] = '<script>
249
var sv_user = \''.api_get_user_id().'\';
250
var sv_course = chamilo_courseCode;
251
var sv_sco = \''.$lp_id.'\';
252
</script>'; // FIXME fetch sco and userid from a more reliable source directly in storageapi.js
253
$htmlHeadXtra[] = '<script type="text/javascript" src="js/storageapi.js"></script>';
254
255
/**
256
 * Get a link to the corresponding document.
257
 */
258
if ($debug) {
259
    error_log(" src: $src ");
260
    error_log(" lp_type: $lpType ");
261
}
262
263
$get_toc_list = $lp->get_toc();
264
$get_teacher_buttons = $lp->get_teacher_toc_buttons();
265
$flowButtons = $lp->getFlowLpbuttons();
266
$itemType = '';
267
foreach ($get_toc_list as $toc) {
268
    if ($toc['id'] == $lp_item_id) {
269
        $itemType = $toc['type'];
270
    }
271
}
272
273
if (!isset($src)) {
274
    $src = null;
275
    switch ($lpType) {
276
        case 1:
277
            $lp->stop_previous_item();
278
            $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
279
            $preReqCheck = $lp->prerequisites_match($lp_item_id);
280
281
            if ($preReqCheck === true) {
282
                $src = $lp->get_link(
283
                    'http',
284
                    $lp_item_id,
285
                    $get_toc_list
286
                );
287
288
                if (empty($src)) {
289
                    $src = 'blank.php?'.api_get_cidreq().'&error=document_protected';
290
                    break;
291
                }
292
293
                // Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
294
                $file_info = parse_url($src);
295
                if (isset($file_info['path'])) {
296
                    $file_info = pathinfo($file_info['path']);
297
                }
298
299
                if (isset($file_info['extension']) &&
300
                    api_strtolower(substr($file_info['extension'], 0, 3)) == 'pdf'
301
                ) {
302
                    $src = api_get_path(WEB_CODE_PATH).'lp/lp_view_item.php?lp_item_id='.$lp_item_id.'&'.api_get_cidreq();
303
                }
304
305
                $src = $lp->fixBlockedLinks($src);
306
307
                if (WhispeakAuthPlugin::isLpItemMarked($lp_item_id)) {
308
                    ChamiloSession::write(
309
                        WhispeakAuthPlugin::SESSION_LP_ITEM,
310
                        ['lp' => $lp->lp_id, 'lp_item' => $lp_item_id, 'src' => $src]
311
                    );
312
313
                    $src = api_get_path(WEB_PLUGIN_PATH).'whispeakauth/authentify.php';
314
                    break;
315
                }
316
317
                // This change the status to complete in Chamilo LP.
318
                $lp->start_current_item(); // starts time counter manually if asset
319
            } else {
320
                $src = 'blank.php?error=prerequisites';
321
            }
322
            break;
323
        case 2:
324
            // save old if asset
325
            $lp->stop_previous_item(); // save status manually if asset
326
            $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
327
            $preReqCheck = $lp->prerequisites_match($lp_item_id);
328
            if ($preReqCheck === true) {
329
                $src = $lp->get_link('http', $lp_item_id, $get_toc_list);
330
                $lp->start_current_item(); // starts time counter manually if asset
331
            } else {
332
                $src = 'blank.php?error=prerequisites';
333
            }
334
            break;
335
        case 3:
336
            // aicc
337
            $lp->stop_previous_item(); // save status manually if asset
338
            $htmlHeadXtra[] = '<script src="'.$lp->get_js_lib().'" type="text/javascript" language="javascript"></script>';
339
            $preReqCheck = $lp->prerequisites_match($lp_item_id);
340
            if ($preReqCheck === true) {
341
                $src = $lp->get_link(
342
                    'http',
343
                    $lp_item_id,
344
                    $get_toc_list
345
                );
346
                $lp->start_current_item(); // starts time counter manually if asset
347
            } else {
348
                $src = 'blank.php';
349
            }
350
            break;
351
        case 4:
352
            break;
353
    }
354
}
355
356
$autostart = 'true';
357
// Update status, total_time from lp_item_view table when you finish the exercises in learning path.
358
359
if ($debug) {
360
    error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId']));
361
    error_log('$lp_id: '.$lp_id);
362
    error_log('$_REQUEST[lp_item_id]: '.intval($_REQUEST['lp_item_id']));
363
}
364
365
if (!empty($_REQUEST['exeId']) &&
366
    isset($lp_id) &&
367
    isset($_REQUEST['lp_item_id'])
368
) {
369
    global $src;
370
    $lp->items[$lp->current]->write_to_db();
371
372
    $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
373
    $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
374
    $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
375
    $safe_item_id = (int) $_REQUEST['lp_item_id'];
376
    $safe_id = $lp_id;
377
    $safe_exe_id = (int) $_REQUEST['exeId'];
378
379
    if (!empty($safe_id) && !empty($safe_item_id)) {
380
        Exercise::saveExerciseInLp($safe_item_id, $safe_exe_id);
381
    }
382
    /*if (intval($_GET['fb_type']) != EXERCISE_FEEDBACK_TYPE_END) {
383
       $src = 'blank.php?msg=exerciseFinished&'.api_get_cidreq(true, true, 'learnpath');
384
    } else {*/
385
    $src = api_get_path(WEB_CODE_PATH).'exercise/result.php?id='.$safe_exe_id.'&'.api_get_cidreq(true, true, 'learnpath');
386
    if ($debug) {
387
        error_log('Calling URL: '.$src);
388
    }
389
    $autostart = 'false';
390
}
391
392
$lp->set_previous_item($lp_item_id);
393
$nameTools = Security::remove_XSS($lp->get_name());
394
395
$save_setting = api_get_setting('show_navigation_menu');
396
global $_setting;
397
$_setting['show_navigation_menu'] = 'false';
398
$scorm_css_header = true;
399
$lp_theme_css = $lp->get_theme();
400
// Sets the css theme of the LP this call is also use at the frames (toc, nav, message).
401
if ($lp->mode === 'fullscreen') {
402
    $htmlHeadXtra[] = "<script>
403
        window.open('$src','content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1');
404
    </script>";
405
}
406
// Set flag to ensure lp_header.php is loaded by this script (flag is unset in lp_header.php).
407
Session::write('loaded_lp_view', true);
408
$display_none = '';
409
$margin_left = '340px';
410
411
// Media player code
412
$display_mode = $lp->mode;
413
$scorm_css_header = true;
414
$lp_theme_css = $lp->get_theme();
415
416
// Setting up the CSS theme if exists.
417
if (!empty($lp_theme_css) && !empty($mycourselptheme) && $mycourselptheme != -1 && $mycourselptheme == 1) {
418
    global $lp_theme_css;
419
} else {
420
    $lp_theme_css = $my_style;
421
}
422
423
$progress_bar = '';
424
if (!api_is_invitee()) {
425
    $progress_bar = $lp->getProgressBar();
426
}
427
$navigation_bar = $lp->get_navigation_bar();
428
$navigation_bar_bottom = $lp->get_navigation_bar('control-bottom');
429
$mediaplayer = $lp->get_mediaplayer($lp->current, $autostart);
430
431
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
432
// Getting all the information about the item.
433
$sql = "SELECT audio FROM $tbl_lp_item
434
        WHERE c_id = $course_id AND lp_id = ".$lp->lp_id;
435
$res_media = Database::query($sql);
436
437
$show_audioplayer = false;
438
if (Database::num_rows($res_media) > 0) {
439
    while ($row_media = Database::fetch_array($res_media)) {
440
        if (!empty($row_media['audio'])) {
441
            $show_audioplayer = true;
442
            break;
443
        }
444
    }
445
}
446
447
$is_allowed_to_edit = api_is_allowed_to_edit(false, true, true, false);
448
449
global $interbreadcrumb;
450
if ($is_allowed_to_edit) {
451
    $interbreadcrumb[] = [
452
        'url' => api_get_self().'?action=list&isStudentView=false&'.api_get_cidreq(true, true, 'course'),
453
        'name' => get_lang('LearningPaths'),
454
    ];
455
    $interbreadcrumb[] = [
456
        'url' => api_get_self()."?action=add_item&type=step&lp_id={$lp->lp_id}&isStudentView=false&".api_get_cidreq(true, true, 'course'),
457
        'name' => $lp->getNameNoTags(),
458
    ];
459
460
    $interbreadcrumb[] = [
461
        'url' => '#',
462
        'name' => get_lang('Preview'),
463
    ];
464
    $buttonHomeUrl = 'lp_controller.php?'.api_get_cidreq(true, true, 'course').'&'.http_build_query([
465
        'isStudentView' => 'false',
466
        'action' => 'return_to_course_homepage',
467
    ]);
468
} else {
469
    $buttonHomeUrl = 'lp_controller.php?'.api_get_cidreq(true, true, 'course').'&'.http_build_query([
470
        'action' => 'return_to_course_homepage',
471
    ]);
472
}
473
474
$buttonHomeText = get_lang('CourseHomepageLink');
475
$returnLink = api_get_course_setting('lp_return_link');
476
switch ($returnLink) {
477
    case 1: // lp list
478
        $buttonHomeUrl .= '&redirectTo=lp_list';
479
        $buttonHomeText = get_lang('LearningPathList');
480
        break;
481
    case 2: // Course home
482
        $buttonHomeUrl .= '&redirectTo=my_courses';
483
        $buttonHomeText = get_lang('MyCourses');
484
        break;
485
    case 3: // Portal home
486
        $buttonHomeUrl .= '&redirectTo=portal_home';
487
        $buttonHomeText = get_lang('Home');
488
        break;
489
}
490
491
$lpPreviewImagePath = Display::returnIconPath('unknown.png', ICON_SIZE_BIG);
492
if ($lp->get_preview_image()) {
493
    $lpPreviewImagePath = $lp->get_preview_image_path();
494
}
495
496
if ($lp->current == $lp->get_last()) {
497
    $categories = Category::load(
498
        null,
499
        null,
500
        $course_code,
501
        null,
502
        null,
503
        $sessionId
504
    );
505
506
    if (!empty($categories)) {
507
        $gradebookEvaluations = $categories[0]->get_evaluations();
508
        $gradebookLinks = $categories[0]->get_links();
509
510
        if (count($gradebookEvaluations) === 0 &&
511
            count($gradebookLinks) === 1 &&
512
            $gradebookLinks[0]->get_type() == LINK_LEARNPATH &&
513
            $gradebookLinks[0]->get_ref_id() == $lp->lp_id
514
        ) {
515
            $gradebookMinScore = $categories[0]->getCertificateMinScore();
516
            $userScore = $gradebookLinks[0]->calc_score($user_id, 'best');
517
518
            if ($userScore[0] >= $gradebookMinScore) {
519
                Category::generateUserCertificate($categories[0]->get_id(), $user_id);
520
            }
521
        }
522
    }
523
}
524
525
$template = new Template('', false, false, true, true, false);
526
$fixLinkSetting = api_get_configuration_value('lp_fix_embed_content');
527
$fixLink = '';
528
if ($fixLinkSetting) {
529
    $fixLink = '{type:"script", id:"_fr10", src:"'.api_get_path(WEB_LIBRARY_PATH).'fixlinks.js"}';
530
}
531
532
$template->assign('fix_link', $fixLink);
533
$template->assign('glossary_tool_available_list', ['true', 'lp', 'exercise_and_lp']);
534
535
// If the global gamification mode is enabled...
536
$gamificationMode = api_get_setting('gamification_mode');
537
// ...AND this learning path is set in gamification mode, then change the display
538
$gamificationMode = $gamificationMode && $lp->seriousgame_mode;
539
540
$template->assign('gamification_mode', $gamificationMode);
541
$template->assign('glossary_extra_tools', api_get_setting('show_glossary_in_extra_tools'));
542
$template->assign('show_glossary_in_documents', api_get_setting('show_glossary_in_documents'));
543
$template->assign('jquery_web_path', api_get_jquery_web_path());
544
$template->assign('jquery_ui_js_web_path', api_get_jquery_ui_js_web_path());
545
$template->assign('jquery_ui_css_web_path', api_get_jquery_ui_css_web_path());
546
$template->assign('is_allowed_to_edit', $is_allowed_to_edit);
547
$template->assign('button_home_url', $buttonHomeUrl);
548
$template->assign('button_home_text', $buttonHomeText);
549
$template->assign('navigation_bar', $navigation_bar);
550
$template->assign('progress_bar', $progress_bar);
551
$template->assign('show_audio_player', $show_audioplayer);
552
$template->assign('media_player', $mediaplayer);
553
$template->assign('toc_list', $get_toc_list);
554
$template->assign('teacher_toc_buttons', $get_teacher_buttons);
555
$template->assign('flow_buttons', $flowButtons);
556
$template->assign('iframe_src', $src);
557
$template->assign('navigation_bar_bottom', $navigation_bar_bottom);
558
$template->assign('show_left_column', $lp->getHideTableOfContents() == 0);
559
560
$showMenu = 0;
561
$settings = api_get_configuration_value('lp_view_settings');
562
$display = isset($settings['display']) ? $settings['display'] : false;
563
$navigationInTheMiddle = false;
564
$addExtraQuitToHomeIcon = false;
565
if (!empty($display)) {
566
    $showMenu = isset($display['show_toolbar_by_default']) && $display['show_toolbar_by_default'] ? 1 : 0;
567
    $navigationInTheMiddle = isset($display['navigation_in_the_middle']) && $display['navigation_in_the_middle'] ? 1 : 0;
568
    $addExtraQuitToHomeIcon = $display['add_extra_quit_to_home_icon'] ?? false;
569
570
    $value = (new ExtraFieldValue('lp'))->get_values_by_handler_and_field_variable($lp_id, 'add_extra_quit_button');
571
572
    if (is_array($value)) {
573
        $addExtraQuitToHomeIcon = $value['value'] !== '0';
574
    }
575
}
576
577
$template->assign('show_toolbar_by_default', $showMenu);
578
$template->assign('navigation_in_the_middle', $navigationInTheMiddle);
579
$template->assign('add_extra_quit_to_home_icon', $addExtraQuitToHomeIcon);
580
581
if ($gamificationMode == 1) {
582
    $template->assign('gamification_stars', $lp->getCalculateStars($sessionId));
583
    $template->assign('gamification_points', $lp->getCalculateScore($sessionId));
584
}
585
586
$template->assign('lp_author', $lp->get_author());
587
588
$lpMinTime = '';
589
if (Tracking::minimumTimeAvailable(api_get_session_id(), api_get_course_int_id())) {
590
    // Calulate minimum and accumulated time
591
    $timeLp = $_SESSION['oLP']->getAccumulateWorkTime();
592
    $timeTotalCourse = $_SESSION['oLP']->getAccumulateWorkTimeTotalCourse();
593
    // Minimum connection percentage
594
    $perc = 100;
595
    // Time from the course
596
    $tc = $timeTotalCourse;
597
    // Percentage of the learning paths
598
    $pl = 0;
599
    if (!empty($timeTotalCourse)) {
600
        $pl = $timeLp / $timeTotalCourse;
601
    }
602
603
    // Minimum time for each learning path
604
    $time_min = (int) ($pl * $tc * $perc / 100);
605
606
    if ($_SESSION['oLP']->getAccumulateWorkTime() > 0) {
607
        $lpMinTime = '('.$time_min.' min)';
608
    }
609
610
    $lpTimeList = Tracking::getCalculateTime($user_id, api_get_course_int_id(), api_get_session_id());
611
    $lpTime = isset($lpTimeList[TOOL_LEARNPATH][$lp_id]) ? (int) $lpTimeList[TOOL_LEARNPATH][$lp_id] : 0;
612
613
    if ($lpTime >= ($time_min * 60)) {
614
        $time_progress_perc = '100%';
615
        $time_progress_value = 100;
616
    } else {
617
        $time_progress_value = intval(($lpTime * 100) / ($time_min * 60));
618
        $time_progress_perc = $time_progress_value.'%';
619
    }
620
621
    $template->assign('time_progress_perc', $time_progress_perc);
622
    $template->assign('time_progress_value', $time_progress_value);
623
    // Cronometro
624
    $hour = (intval($lpTime / 3600)) < 10 ? '0'.intval($lpTime / 3600) : intval($lpTime / 3600);
625
    $template->assign('hour', $hour);
626
    $template->assign('minute', date('i', $lpTime));
627
    $template->assign('second', date('s', $lpTime));
628
    $template->assign('hour_min', api_time_to_hms($timeLp * 60, '</div><div class="divider">:</div><div>'));
629
}
630
631
$template->assign('lp_accumulate_work_time', $lpMinTime);
632
633
$template->assign('lp_mode', $lp->mode);
634
$template->assign('lp_title_scorm', $lp->get_name());
635
if (api_get_configuration_value('lp_view_accordion') === true && $lpType == 1) {
636
    $template->assign('data_panel', $lp->getTOCTree());
637
} else {
638
    $template->assign('data_list', $lp->getListArrayToc($get_toc_list));
639
}
640
$template->assign('lp_id', $lp->lp_id);
641
$template->assign('lp_current_item_id', $lp->get_current_item_id());
642
643
$menuLocation = 'left';
644
if (!empty(api_get_configuration_value('lp_menu_location'))) {
645
    $menuLocation = api_get_configuration_value('lp_menu_location');
646
}
647
$template->assign('menu_location', $menuLocation);
648
$template->assign('disable_js_in_lp_view', (int) api_get_configuration_value('disable_js_in_lp_view'));
649
$template->assign(
650
    'lp_preview_image',
651
    Display::img(
652
        $lpPreviewImagePath,
653
        $lp->getNameNoTags(),
654
        [],
655
        ICON_SIZE_BIG
656
    )
657
);
658
659
// Check if the 'Open in new window' button for IOs hosts must be hidden
660
$iosHideOpenInNewWindow = false;
661
if (api_get_configuration_value('lp_ios_hide_open_in_new_window_button') === true) {
662
    $iosHideOpenInNewWindow = api_get_configuration_value('lp_ios_hide_open_in_new_window_button');
663
}
664
$template->assign('ios_hide_open_in_new_window', $iosHideOpenInNewWindow);
665
666
$frameReady = Display::getFrameReadyBlock(
667
    '#content_id, #content_id_blank',
668
    $itemType,
669
    'function () {
670
        var arr = ["link", "sco", "xapi", "quiz", "h5p"];
671
672
        return $.inArray(olms.lms_item_type, arr) !== -1;
673
    }'
674
);
675
$template->assign('frame_ready', $frameReady);
676
677
$view = $template->get_template('learnpath/view.tpl');
678
$content = $template->fetch($view);
679
680
$template->assign('content', $content);
681
$template->display_no_layout_template();
682
683
// Restore a global setting.
684
$_setting['show_navigation_menu'] = $save_setting;
685
686
Session::write('oLP', $lp);
687
688
if ($debug) {
689
    error_log(' ------- end lp_view.php ------');
690
}
691