Test Setup Failed
Push — master ( 4e700f...c7183e )
by Julito
63:12
created

banner.lib.php ➔ getCustomTabs()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 14
nc 7
nop 0
dl 0
loc 25
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
5
use ChamiloSession as Session;
6
7
/**
8
 * @deprecated
9
 *
10
 */
11
12
/**
13
 * Determines the possible tabs (=sections) that are available.
14
 * This function is used when creating the tabs in the third header line and
15
 * all the sections that do not appear there (as determined by the
16
 * platform admin on the Dokeos configuration settings page)
17
 * will appear in the right hand menu that appears on several other pages
18
 * @return array containing all the possible tabs
19
 * @author Patrick Cool <[email protected]>, Ghent University
20
 */
21
function get_tabs($courseId = null)
22
{
23
    $_course = api_get_course_info($courseId);
24
25
    $navigation = array();
26
27
    // Campus Homepage
28
    $navigation[SECTION_CAMPUS]['url'] = api_get_path(WEB_PATH).'index.php';
29
    $navigation[SECTION_CAMPUS]['title'] = get_lang('CampusHomepage');
30
    $navigation[SECTION_CAMPUS]['key'] = 'homepage';
31
    $navigation[SECTION_CAMPUS]['icon'] = 'homepage.png';
32
33
    $navigation[SECTION_CATALOG]['url'] = api_get_path(WEB_PATH).'main/auth/courses.php';
34
    $navigation[SECTION_CATALOG]['title'] = get_lang('Courses');
35
    $navigation[SECTION_CATALOG]['key'] = 'catalog';
36
    $navigation[SECTION_CATALOG]['icon'] = 'catalog.png';
37
38
    // My Courses
39
    if (api_is_allowed_to_create_course()) {
40
        // Link to my courses for teachers
41
        $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php?nosession=true';
42
    } else {
43
        // Link to my courses for students
44
        $navigation['mycourses']['url'] = api_get_path(WEB_PATH).'user_portal.php';
45
    }
46
    $navigation['mycourses']['title'] = get_lang('MyCourses');
47
    $navigation['mycourses']['key'] = 'my-course';
48
    $navigation['mycourses']['icon'] = 'my-course.png';
49
50
    // My Profile
51
    $navigation['myprofile']['url'] = api_get_path(WEB_CODE_PATH)
52
        .'auth/profile.php'
53
        .(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
54
    $navigation['myprofile']['title'] = get_lang('ModifyProfile');
55
    $navigation['myprofile']['key'] = 'profile';
56
    $navigation['myprofile']['icon'] = 'profile.png';
57
    // Link to my agenda
58
    $navigation['myagenda']['url'] = api_get_path(WEB_CODE_PATH).'calendar/agenda_js.php?type=personal';
59
    $navigation['myagenda']['title'] = get_lang('MyAgenda');
60
    $navigation['myagenda']['key'] = 'agenda';
61
    $navigation['myagenda']['icon'] = 'agenda.png';
62
63
    // Gradebook
64
    if (api_get_setting('gradebook_enable') == 'true') {
65
        $navigation['mygradebook']['url'] = api_get_path(WEB_CODE_PATH)
66
            .'gradebook/gradebook.php'
67
            .(!empty($_course['path']) ? '?coursePath='.$_course['path'].'&amp;courseCode='.$_course['official_code'] : '');
68
        $navigation['mygradebook']['title'] = get_lang('MyGradebook');
69
        $navigation['mygradebook']['key'] = 'gradebook';
70
        $navigation['mygradebook']['icon'] = 'gradebook.png';
71
    }
72
73
    // Reporting
74
    if (api_is_teacher() || api_is_drh() || api_is_session_admin()) {
75
        // Link to my space
76
        $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/'
77
            .(api_is_drh() ? 'session.php' : '');
78
        $navigation['session_my_space']['title'] = get_lang('MySpace');
79
        $navigation['session_my_space']['key'] = 'my-space';
80
        $navigation['session_my_space']['icon'] = 'my-space.png';
81
    } else {
82
        if (api_is_student_boss()) {
83
            $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/student.php';
84
            $navigation['session_my_space']['title'] = get_lang('MySpace');
85
            $navigation['session_my_space']['key'] = 'my-space';
86
            $navigation['session_my_space']['icon'] = 'my-space.png';
87
        } else {
88
            $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH);
89
            // Link to my progress
90
            switch (api_get_setting('gamification_mode')) {
91
                case 1:
92
                    $navigation['session_my_progress']['url'] .= 'gamification/my_progress.php';
93
                    break;
94
                default:
95
                    $navigation['session_my_progress']['url'] .= 'auth/my_progress.php';
96
            }
97
98
            $navigation['session_my_progress']['title'] = get_lang('MyProgress');
99
            $navigation['session_my_progress']['key'] = 'my-progress';
100
            $navigation['session_my_progress']['icon'] = 'my-progress.png';
101
        }
102
    }
103
104
    // Social
105 View Code Duplication
    if (api_get_setting('allow_social_tool') == 'true') {
106
        $navigation['social']['url'] = api_get_path(WEB_CODE_PATH).'social/home.php';
107
        $navigation['social']['title'] = get_lang('SocialNetwork');
108
        $navigation['social']['key'] = 'social-network';
109
        $navigation['social']['icon'] = 'social-network.png';
110
    }
111
112
    // Dashboard
113
    if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
114
        $navigation['dashboard']['url'] = api_get_path(WEB_CODE_PATH).'dashboard/index.php';
115
        $navigation['dashboard']['title'] = get_lang('Dashboard');
116
        $navigation['dashboard']['key'] = 'dashboard';
117
        $navigation['dashboard']['icon'] = 'dashboard.png';
118
    }
119
120
    // Reports
121
    /*
122
	if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
123
        $navigation['reports']['url'] = api_get_path(WEB_CODE_PATH).'reports/index.php';
124
        $navigation['reports']['title'] = get_lang('Reports');
125
	}*/
126
127
    // Custom Tabs See BT#7180
128
    $customTabs = getCustomTabs();
129
    if (!empty($customTabs)) {
130
        foreach ($customTabs as $tab) {
131
            if (api_get_setting($tab['variable'], $tab['subkey']) == 'true') {
132
                if (!empty($tab['comment']) && $tab['comment'] !== 'ShowTabsComment') {
133
                    $navigation[$tab['subkey']]['url'] = $tab['comment'];
134
                    // $tab['title'] value must be included in trad4all.inc.php
135
                    $navigation[$tab['subkey']]['title'] = get_lang($tab['title']);
136
                    $navigation[$tab['subkey']]['key'] = $tab['subkey'];
137
                }
138
            }
139
        }
140
    }
141
    // End Custom Tabs
142
143
    // Platform administration
144 View Code Duplication
    if (api_is_platform_admin(true)) {
145
        $navigation['platform_admin']['url'] = api_get_path(WEB_CODE_PATH).'admin/';
146
        $navigation['platform_admin']['title'] = get_lang('PlatformAdmin');
147
        $navigation['platform_admin']['key'] = 'admin';
148
        $navigation['platform_admin']['icon'] = 'admin.png';
149
    }
150
151
    return $navigation;
152
}
153
154
/**
155
 * This function returns the custom tabs
156
 *
157
 * @return array
158
 */
159
function getCustomTabs()
160
{
161
    $tableSettingsCurrent = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
162
    $sql = "SELECT * FROM $tableSettingsCurrent
163
            WHERE 
164
                variable = 'show_tabs' AND
165
                subkey like 'custom_tab_%'";
166
    $result = Database::query($sql);
167
    $customTabs = array();
168
    while ($row = Database::fetch_assoc($result)) {
169
        $shouldAdd = true;
170
171
        if (strpos($row['subkey'], Plugin::TAB_FILTER_NO_STUDENT) !== false && api_is_student()) {
172
            $shouldAdd = false;
173
        } elseif (strpos($row['subkey'], Plugin::TAB_FILTER_ONLY_STUDENT) !== false && !api_is_student()) {
174
            $shouldAdd = false;
175
        }
176
177
        if ($shouldAdd) {
178
            $customTabs[] = $row;
179
        }
180
    }
181
182
    return $customTabs;
183
}
184
185
/**
186
 * Return the active logo of the portal, based on a series of settings
187
 * @param string $theme The name of the theme folder from web/css/themes/
188
 * @return string HTML string with logo as an HTML element
189
 */
190
function return_logo($theme = '')
191
{
192
    $siteName = api_get_setting('siteName');
193
194
    return ChamiloApi::getPlatformLogo(
195
        $theme,
196
        [
197
            'title' => $siteName,
198
            'class' => 'img-responsive',
199
            'id' => 'header-logo',
200
        ]
201
    );
202
}
203
204
/**
205
 * Return HTML string of a list as <li> items
206
 * @return string
207
 */
208
function returnNotificationMenu()
209
{
210
    $_course = api_get_course_info();
211
    $course_id = 0;
212
    if (!empty($_course)) {
213
        $course_id = $_course['code'];
214
    }
215
216
    $user_id = api_get_user_id();
217
218
    $html = '';
219
220
    if ((api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
221
        (api_get_setting('showonline', 'users') == 'true' && $user_id) ||
222
        (api_get_setting('showonline', 'course') == 'true' && $user_id && $course_id)
223
    ) {
224
        $number = getOnlineUsersCount();
225
        $number_online_in_course = getOnlineUsersInCourseCount($user_id, $_course);
226
227
        // Display the who's online of the platform
228
        if ($number &&
229
            (api_get_setting('showonline', 'world') == 'true' && !$user_id) ||
230
            (api_get_setting('showonline', 'users') == 'true' && $user_id)
231
        ) {
232
            $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php" target="_self" title="'
233
                .get_lang('UsersOnline').'" >'
234
                .Display::return_icon('user.png', get_lang('UsersOnline'), array(), ICON_SIZE_TINY)
235
                .' '.$number.'</a></li>';
236
        }
237
238
        // Display the who's online for the course
239
        if (
240
            $number_online_in_course &&
241
            (
242
                is_array($_course) &&
243
                api_get_setting('showonline', 'course') == 'true' && isset($_course['sysCode'])
244
            )
245
        ) {
246
            $html .= '<li><a href="'.api_get_path(WEB_PATH).'whoisonline.php?cidReq='.$_course['sysCode']
247
                .'" target="_self">'
248
                .Display::return_icon('course.png', get_lang('UsersOnline').' '.get_lang('InThisCourse'), array(), ICON_SIZE_TINY)
249
                .' '.$number_online_in_course.' </a></li>';
250
        }
251
252 View Code Duplication
        if (isset($user_id) && api_get_session_id() != 0) {
253
            $html .= '<li><a href="'.api_get_path(WEB_PATH)
254
                .'whoisonlinesession.php?id_coach='.$user_id.'&amp;referer='.urlencode($_SERVER['REQUEST_URI'])
255
                .'" target="_self">'
256
                .Display::return_icon('session.png', get_lang('UsersConnectedToMySessions'), array(), ICON_SIZE_TINY)
257
                .'</a></li>';
258
        }
259
    }
260
261
    return $html;
262
}
263
264
/**
265
 * Return an array with different navigation menu elements
266
 * @deprecated Check src/Chamilo/CoreBundle/Menu/NavBuilder.php to handle
267
 * Chamilo menus
268
 * @return array [menu_navigation[], navigation[], possible_tabs[]]
269
 */
270
function return_navigation_array()
271
{
272
    return ;
273
    $navigation = array();
0 ignored issues
show
Unused Code introduced by
$navigation = array(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
274
    $menu_navigation = array();
275
    $possible_tabs = get_tabs();
276
277
    // Campus Homepage
278
    if (api_get_setting('show_tabs', 'campus_homepage') == 'true') {
279
        $navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
280
    } else {
281
        $menu_navigation[SECTION_CAMPUS] = $possible_tabs[SECTION_CAMPUS];
282
    }
283
284
    if (api_get_setting('course_catalog_published') == 'true' && api_is_anonymous()) {
285
        $navigation[SECTION_CATALOG] = $possible_tabs[SECTION_CATALOG];
286
    }
287
288
    if (api_get_user_id() && !api_is_anonymous()) {
289
        // My Courses
290 View Code Duplication
        if (api_get_setting('show_tabs', 'my_courses') == 'true') {
291
            $navigation['mycourses'] = $possible_tabs['mycourses'];
292
        } else {
293
            $menu_navigation['mycourses'] = $possible_tabs['mycourses'];
294
        }
295
296
        // My Profile
297
        if (api_get_setting('show_tabs', 'my_profile') == 'true' &&
298
            api_get_setting('allow_social_tool') != 'true'
299
        ) {
300
            $navigation['myprofile'] = $possible_tabs['myprofile'];
301
        } else {
302
            $menu_navigation['myprofile'] = $possible_tabs['myprofile'];
303
        }
304
305
        // My Agenda
306 View Code Duplication
        if (api_get_setting('show_tabs', 'my_agenda') == 'true') {
307
            $navigation['myagenda'] = $possible_tabs['myagenda'];
308
        } else {
309
            $menu_navigation['myagenda'] = $possible_tabs['myagenda'];
310
        }
311
312
        // Gradebook
313
        if (api_get_setting('gradebook_enable') == 'true') {
314 View Code Duplication
            if (api_get_setting('show_tabs', 'my_gradebook') == 'true') {
315
                $navigation['mygradebook'] = $possible_tabs['mygradebook'];
316
            } else {
317
                $menu_navigation['mygradebook'] = $possible_tabs['mygradebook'];
318
            }
319
        }
320
321
        // Reporting
322
        if (api_get_setting('show_tabs', 'reporting') == 'true') {
323 View Code Duplication
            if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
324
                $navigation['session_my_space'] = $possible_tabs['session_my_space'];
325
            } else {
326
                $navigation['session_my_space'] = $possible_tabs['session_my_progress'];
327
            }
328 View Code Duplication
        } else {
329
            if (api_is_teacher() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) {
330
                $menu_navigation['session_my_space'] = $possible_tabs['session_my_space'];
331
            } else {
332
                $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress'];
333
            }
334
        }
335
336
        // Social Networking
337
        if (api_get_setting('show_tabs', 'social') == 'true') {
338
            if (api_get_setting('allow_social_tool') == 'true') {
339
                $navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
340
            }
341
        } else {
342
            $menu_navigation['social'] = isset($possible_tabs['social']) ? $possible_tabs['social'] : null;
343
        }
344
345
        // Dashboard
346
        if (api_get_setting('show_tabs', 'dashboard') == 'true') {
347
            if (api_is_platform_admin() || api_is_drh() || api_is_session_admin()) {
348
                $navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
349
            }
350
        } else {
351
            $menu_navigation['dashboard'] = isset($possible_tabs['dashboard']) ? $possible_tabs['dashboard'] : null;
352
        }
353
354
        ///if (api_is_student()) {
355
        if (true) {
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
356
            $params = array('variable = ? AND subkey = ?' => ['status', 'studentfollowup']);
357
            $result = api_get_settings_params_simple($params);
358
            $plugin = StudentFollowUpPlugin::create();
359
            if (!empty($result) && $result['selected_value'] === 'installed') {
360
                // Students
361
                $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php';
362
363
                if (api_is_platform_admin() || api_is_drh() || api_is_teacher()) {
364
                    $url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/my_students.php';
365
                }
366
                $navigation['follow_up']['url'] = $url;
367
                $navigation['follow_up']['title'] = $plugin->get_lang('CareDetailView');
368
                $navigation['follow_up']['key'] = 'homepage';
369
                $navigation['follow_up']['icon'] = 'homepage.png';
370
            }
371
        }
372
373
        // Administration
374
        if (api_is_platform_admin(true)) {
375 View Code Duplication
            if (api_get_setting('show_tabs', 'platform_administration') == 'true') {
376
                $navigation['platform_admin'] = $possible_tabs['platform_admin'];
377
            } else {
378
                $menu_navigation['platform_admin'] = $possible_tabs['platform_admin'];
379
            }
380
        }
381
382
        // Reports
383
        if (!empty($possible_tabs['reports'])) {
384
            if (api_get_setting('show_tabs', 'reports') == 'true') {
385
                if ((api_is_platform_admin() || api_is_drh() || api_is_session_admin())
386
                        && Rights::hasRight('show_tabs:reports')
387
                ) {
388
                    $navigation['reports'] = $possible_tabs['reports'];
389
                }
390
            } else {
391
                $menu_navigation['reports'] = $possible_tabs['reports'];
392
            }
393
        }
394
395
        // Custom tabs
396
        $customTabs = getCustomTabs();
397
398
        if (!empty($customTabs)) {
399
            foreach ($customTabs as $tab) {
400
                if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
401
                    isset($possible_tabs[$tab['subkey']])
402
                ) {
403
                    $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH)
404
                        .$possible_tabs[$tab['subkey']]['url'];
405
                    $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
406 View Code Duplication
                } else {
407
                    if (isset($possible_tabs[$tab['subkey']])) {
408
                        $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH)
409
                            .$possible_tabs[$tab['subkey']]['url'];
410
                        $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
411
                    }
412
                }
413
            }
414
        }
415
    } else {
416
        // Show custom tabs that are specifically marked as public
417
        $customTabs = getCustomTabs();
418
        if (!empty($customTabs)) {
419
            foreach ($customTabs as $tab) {
420
                if (api_get_setting($tab['variable'], $tab['subkey']) == 'true' &&
421
                    isset($possible_tabs[$tab['subkey']]) &&
422
                    api_get_plugin_setting(strtolower(str_replace('Tabs', '', $tab['subkeytext'])), 'public_main_menu_tab') == 'true'
423
                ) {
424
                    $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
425
                    $navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
426 View Code Duplication
                } else {
427
                    if (isset($possible_tabs[$tab['subkey']])) {
428
                        $possible_tabs[$tab['subkey']]['url'] = api_get_path(WEB_PATH).$possible_tabs[$tab['subkey']]['url'];
429
                        $menu_navigation[$tab['subkey']] = $possible_tabs[$tab['subkey']];
430
                    }
431
                }
432
            }
433
        }
434
    }
435
436
    return array(
437
        'menu_navigation' => $menu_navigation,
438
        'navigation' => $navigation,
439
        'possible_tabs' => $possible_tabs,
440
    );
441
}
442
443
/**
444
 * Return the navigation menu elements as a flat array
445
 * @return array
446
 */
447
function menuArray()
448
{
449
    $mainNavigation = return_navigation_array();
450
    unset($mainNavigation['possible_tabs']);
451
    unset($mainNavigation['menu_navigation']);
452
    //$navigation = $navigation['navigation'];
453
    // Get active language
454
    $lang = api_get_setting('platformLanguage');
455 View Code Duplication
    if (!empty($_SESSION['user_language_choice'])) {
456
        $lang = $_SESSION['user_language_choice'];
457
458
    } elseif (!empty($_SESSION['_user']['language'])) {
459
        $lang = $_SESSION['_user']['language'];
460
    }
461
462
    // Preparing home folder for multiple urls
463
    if (api_get_multiple_access_url()) {
464
        $access_url_id = api_get_current_access_url_id();
465
        if ($access_url_id != -1) {
466
            // If not a dead URL
467
            $urlInfo = api_get_access_url($access_url_id);
468
            $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
469
            $cleanUrl = api_replace_dangerous_char($url);
470
            $cleanUrl = str_replace('/', '-', $cleanUrl);
471
            $cleanUrl .= '/';
472
            $homepath = api_get_path(SYS_HOME_PATH).$cleanUrl; //homep for Home Path
473
474
            //we create the new dir for the new sites
475
            if (!is_dir($homepath)) {
476
                mkdir($homepath, api_get_permissions_for_new_directories());
477
            }
478
        }
479
    } else {
480
        $homepath = api_get_path(SYS_HOME_PATH);
481
    }
482
    $ext = '.html';
483
    $menuTabs = 'home_tabs';
484
    $menuTabsLoggedIn = 'home_tabs_logged_in';
485
    $pageContent = '';
486
    // Get the extra page content, containing the links to add to the tabs
487
    if (is_file($homepath.$menuTabs.'_'.$lang.$ext) && is_readable($homepath.$menuTabs.'_'.$lang.$ext)) {
488
        $pageContent = @(string) file_get_contents($homepath.$menuTabs.'_'.$lang.$ext);
489
    } elseif (is_file($homepath.$menuTabs.$lang.$ext) && is_readable($homepath.$menuTabs.$lang.$ext)) {
490
        $pageContent = @(string) file_get_contents($homepath.$menuTabs.$lang.$ext);
491
    }
492
    // Sanitize page content
493
    $pageContent = api_to_system_encoding($pageContent, api_detect_encoding(strip_tags($pageContent)));
494
    $open = str_replace('{rel_path}', api_get_path(REL_PATH), $pageContent);
495
    $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
496
    // Get the extra page content, containing the links to add to the tabs
497
    //  that are only for users already logged in
498
    $openMenuTabsLoggedIn = '';
499
    if (api_get_user_id() && !api_is_anonymous()) {
500
        if (is_file($homepath.$menuTabsLoggedIn.'_'.$lang.$ext) && is_readable(
501
                $homepath.$menuTabsLoggedIn.'_'.$lang.$ext
502
            )
503
        ) {
504
            $pageContent = @(string) file_get_contents($homepath.$menuTabsLoggedIn.'_'.$lang.$ext);
505
            $pageContent = str_replace('::private', '', $pageContent);
506
        } elseif (is_file($homepath.$menuTabsLoggedIn.$lang.$ext) && is_readable(
507
                $homepath.$menuTabsLoggedIn.$lang.$ext
508
            )
509
        ) {
510
            $pageContent = @(string) file_get_contents($homepath.$menuTabsLoggedIn.$lang.$ext);
511
            $pageContent = str_replace('::private', '', $pageContent);
512
        }
513
514
        $pageContent = api_to_system_encoding($pageContent, api_detect_encoding(strip_tags($pageContent)));
515
        $openMenuTabsLoggedIn = str_replace('{rel_path}', api_get_path(REL_PATH), $pageContent);
516
        $openMenuTabsLoggedIn = api_to_system_encoding(
517
            $openMenuTabsLoggedIn,
518
            api_detect_encoding(strip_tags($openMenuTabsLoggedIn))
519
        );
520
    }
521
    if (!empty($open) || !empty($openMenuTabsLoggedIn)) {
522
        if (strpos($open.$openMenuTabsLoggedIn, 'show_menu') === false) {
523
            if (api_is_anonymous()) {
524
                $mainNavigation['navigation'][SECTION_CAMPUS] = null;
525
            }
526
        } else {
527
            $list = explode("\n", api_get_user_id() && !api_is_anonymous() ? $openMenuTabsLoggedIn : $open);
528
529
            foreach ($list as $link) {
530
                if (strpos($link, 'class="hide_menu"') !== false) {
531
                    continue;
532
                }
533
534
                $matches = array();
535
                $match = preg_match('$href="([^"]*)" target="([^"]*)">([^<]*)</a>$', $link, $matches);
536
537
                if (!$match) {
538
                    continue;
539
                }
540
541
                $mainNavigation['navigation'][$matches[3]] = array(
542
                    'url' => $matches[1],
543
                    'target' => $matches[2],
544
                    'title' => $matches[3],
545
                    'key' => 'page-'.str_replace(' ', '-', strtolower($matches[3])),
546
                );
547
            }
548
        }
549
    }
550
551
    if (count($mainNavigation['navigation']) > 0) {
552
        //$pre_lis = '';
553
        $activeSection = '';
554
        foreach ($mainNavigation['navigation'] as $section => $navigation_info) {
555
            $key = (!empty($navigation_info['key']) ? 'tab-'.$navigation_info['key'] : '');
556
557
            if (isset($GLOBALS['this_section'])) {
558
                $tempSection = $section;
559
                if ($section == 'social') {
560
                    $tempSection = 'social-network';
561
                }
562
                if ($tempSection == $GLOBALS['this_section']) {
563
                    $activeSection = $section;
564
                }
565
                // If we're on the index page and a specific extra link has been
566
                // loaded
567
                if ($GLOBALS['this_section'] == SECTION_CAMPUS) {
568
                    if (!empty($_GET['include'])) {
569
                        $name = str_replace(' ', '-', strtolower($navigation_info['title'])).'_'.$lang.$ext;
570
                        if (strtolower($_GET['include']) == $name) {
571
                            $activeSection = $section;
572
                        }
573
                    }
574
                }
575
            } else {
576
                $current = '';
577
            }
578
            $mainNavigation['navigation'][$section]['current'] = '';
579
        }
580
        if (!empty($activeSection)) {
581
            $mainNavigation['navigation'][$activeSection]['current'] = 'active';
582
        }
583
584
    }
585
    unset($mainNavigation['navigation']['myprofile']);
586
587
    return $mainNavigation['navigation'];
588
}
589
590
/**
591
 * Return the breadcrumb menu elements as an array of <li> items
592
 * @param array $interbreadcrumb The elements to add to the breadcrumb
593
 * @param string $language_file Deprecated
594
 * @param string $nameTools The name of the current tool (not linked)
595
 * @return string HTML string of <li> items
596
 */
597
function return_breadcrumb($interbreadcrumb, $language_file, $nameTools)
598
{
599
    /** @var \Chamilo\CoreBundle\Entity\Session $session */
600
    $session = Database::getManager()
601
        ->find('ChamiloCoreBundle:Session', api_get_session_id());
602
    $_course = api_get_course_info();
603
    $user_id = api_get_user_id();
604
    $course_id = 0;
605
    if (!empty($_course)) {
606
        $course_id = $_course['real_id'];
607
    }
608
609
    $additonalBlocks = '';
610
611
    /*  Plugins for banner section */
612
    $web_course_path = api_get_path(WEB_COURSE_PATH);
613
614
    /* If the user is a coach he can see the users who are logged in its session */
615
    $navigation = array();
616
617
    // part 1: Course Homepage. If we are in a course then the first breadcrumb is a link to the course homepage
618
    // hide_course_breadcrumb the parameter has been added to hide the name of the course, that appeared in the default $interbreadcrumb
619
    $my_session_name = $session ? ' ('.cut($session->getName(), MAX_LENGTH_BREADCRUMB).')' : null;
620
621
    if (!empty($_course) && !isset($_GET['hide_course_breadcrumb'])) {
622
        $_course['name'] = api_htmlentities($_course['name']);
623
        $course_title = cut($_course['name'], MAX_LENGTH_BREADCRUMB);
624
625
        switch (api_get_setting('breadcrumbs_course_homepage')) {
626
            case 'get_lang':
627
                $itemTitle = Display::return_icon('home.png', get_lang('CourseHomepageLink'), [], ICON_SIZE_TINY);
628
                break;
629
            case 'course_code':
630
                $itemTitle = Display::return_icon('home.png', $_course['official_code'], [], ICON_SIZE_TINY)
631
                    .' '.$_course['official_code'];
632
                break;
633
            case 'session_name_and_course_title':
634
                //no break
635
            default:
636
                $itemTitle = Display::return_icon('home.png', $_course['name'].$my_session_name, [], ICON_SIZE_TINY)
637
                    .' '.$course_title.$my_session_name;
638
639
                if (
640
                    $session && ($session->getDuration() && !api_is_allowed_to_edit())
641
                ) {
642
                    $daysLeft = SessionManager::getDayLeftInSession(
643
                        ['id' => $session->getId(), 'duration' => $session->getDuration()],
644
                        $user_id
645
                    );
646
647 View Code Duplication
                    if ($daysLeft >= 0) {
648
                        $additonalBlocks .= Display::return_message(
649
                            sprintf(get_lang('SessionDurationXDaysLeft'), $daysLeft),
650
                            'information'
651
                        );
652
                    } else {
653
                        $additonalBlocks .= Display::return_message(
654
                            get_lang('YourSessionTimeHasExpired'),
655
                            'warning'
656
                        );
657
                    }
658
                }
659
                break;
660
        }
661
662
        /**
663
         * @todo could be useful adding the My courses in the breadcrumb
664
         * $navigation_item_my_courses['title'] = get_lang('MyCourses');
665
         * $navigation_item_my_courses['url'] = api_get_path(WEB_PATH).'user_portal.php';
666
         * $navigation[] = $navigation_item_my_courses;
667
         */
668
        $navigation[] = [
669
            'url' => $web_course_path.$_course['path'].'/index.php'.($session ? '?id_session='.$session->getId() : ''),
670
            'title' => $itemTitle
671
        ];
672
    }
673
674
    /* part 2: Interbreadcrumbs. If there is an array $interbreadcrumb
675
    defined then these have to appear before the last breadcrumb
676
    (which is the tool itself)*/
677
    if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
678
        foreach ($interbreadcrumb as $breadcrumb_step) {
679
            if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
680
                continue;
681
            }
682
            if ($breadcrumb_step['url'] != '#') {
683
                $sep = strrchr($breadcrumb_step['url'], '?') ? '&' : '?';
684
                $courseParams = strpos($breadcrumb_step['url'], 'cidReq') === false ? api_get_cidreq() : '';
685
                $navigation_item['url'] = $breadcrumb_step['url'].$sep.$courseParams;
686
            } else {
687
                $navigation_item['url'] = '#';
688
            }
689
            $navigation_item['title'] = $breadcrumb_step['name'];
690
            // titles for shared folders
691
            if ($breadcrumb_step['name'] == 'shared_folder') {
692
                $navigation_item['title'] = get_lang('UserFolders');
693
            } elseif (strstr($breadcrumb_step['name'], 'shared_folder_session_')) {
694
                $navigation_item['title'] = get_lang('UserFolders');
695
            } elseif (strstr($breadcrumb_step['name'], 'sf_user_')) {
696
                $userinfo = api_get_user_info(substr($breadcrumb_step['name'], 8));
697
                $navigation_item['title'] = $userinfo['complete_name'];
698
            } elseif ($breadcrumb_step['name'] == 'chat_files') {
699
                $navigation_item['title'] = get_lang('ChatFiles');
700
            } elseif ($breadcrumb_step['name'] == 'images') {
701
                $navigation_item['title'] = get_lang('Images');
702
            } elseif ($breadcrumb_step['name'] == 'video') {
703
                $navigation_item['title'] = get_lang('Video');
704
            } elseif ($breadcrumb_step['name'] == 'audio') {
705
                $navigation_item['title'] = get_lang('Audio');
706
            } elseif ($breadcrumb_step['name'] == 'flash') {
707
                $navigation_item['title'] = get_lang('Flash');
708
            } elseif ($breadcrumb_step['name'] == 'gallery') {
709
                $navigation_item['title'] = get_lang('Gallery');
710
            }
711
            // Fixes breadcrumb title now we applied the Security::remove_XSS and
712
            // we cut the string depending of the MAX_LENGTH_BREADCRUMB value
713
            $navigation_item['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
714
            $navigation_item['title'] = Security::remove_XSS($navigation_item['title']);
715
716
            $navigation[] = $navigation_item;
717
        }
718
    }
719
720
    $navigation_right = array();
721
722
    if (isset($interbreadcrumb) && is_array($interbreadcrumb)) {
723
        foreach ($interbreadcrumb as $breadcrumb_step) {
724
            if (isset($breadcrumb_step['type']) && $breadcrumb_step['type'] == 'right') {
725
                if ($breadcrumb_step['url'] != '#') {
726
                    $sep = (strrchr($breadcrumb_step['url'], '?') ? '&amp;' : '?');
727
                    $navigation_item['url'] = $breadcrumb_step['url'].$sep.api_get_cidreq();
728
                } else {
729
                    $navigation_item['url'] = '#';
730
                }
731
                $breadcrumb_step['title'] = cut($navigation_item['title'], MAX_LENGTH_BREADCRUMB);
732
                $breadcrumb_step['title'] = Security::remove_XSS($navigation_item['title']);
733
                $navigation_right[] = $breadcrumb_step;
734
            }
735
        }
736
    }
737
738
    // part 3: The tool itself. If we are on the course homepage we do not want
739
    // to display the title of the course because this
740
    // is the same as the first part of the breadcrumbs (see part 1)
741
    if (isset($nameTools)) {
742
        $navigation_item['url'] = '#';
743
        $navigation_item['title'] = $nameTools;
744
        $navigation[] = $navigation_item;
745
    }
746
747
    $final_navigation = array();
748
    $counter = 0;
749
    foreach ($navigation as $index => $navigation_info) {
750
        if (!empty($navigation_info['title'])) {
751
            if ($navigation_info['url'] == '#') {
752
                $final_navigation[$index] = $navigation_info['title'];
753
            } else {
754
                $final_navigation[$index] = '<a href="'.$navigation_info['url'].'" target="_self">'.$navigation_info['title'].'</a>';
755
            }
756
            $counter++;
757
        }
758
    }
759
760
    $html = '';
761
762
    /* Part 4 . Show the teacher view/student view button at the right of the breadcrumb */
763
    $view_as_student_link = null;
764
    if ($user_id && isset($course_id)) {
765
        if ((
766
                api_is_course_admin() ||
767
                api_is_platform_admin() ||
768
                api_is_coach(null, null, false)
769
            ) &&
770
            api_get_setting('student_view_enabled') === 'true' && api_get_course_info()
771
        ) {
772
            $view_as_student_link = api_display_tool_view_option();
773
774
            // Only show link if LP can be editable
775
            /** @var learnpath $learnPath */
776
            $learnPath = Session::read('oLP');
777
            if (!empty($learnPath) && !empty($view_as_student_link)) {
778
                if ((int) $learnPath->get_lp_session_id() != (int) api_get_session_id()) {
779
                    $view_as_student_link = '';
780
                }
781
            }
782
        }
783
    }
784
785
    if (!empty($final_navigation)) {
786
        $lis = '';
787
        $i = 0;
788
        $final_navigation_count = count($final_navigation);
789
        if (!empty($final_navigation)) {
790
            // $home_link.= '<span class="divider">/</span>';
791
            if (!empty($home_link)) {
0 ignored issues
show
Bug introduced by
The variable $home_link seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
792
                $lis .= Display::tag('li', $home_link);
793
            }
794
795
            foreach ($final_navigation as $bread) {
796
                $bread_check = trim(strip_tags($bread));
797
                if (!empty($bread_check)) {
798
                    if ($final_navigation_count - 1 > $i) {
799
                        $bread .= '';
800
                    }
801
                    $lis .= Display::tag('li', $bread, array('class' => 'active'));
802
                    $i++;
803
                }
804
            }
805
        } else {
806
            if (!empty($home_link)) {
807
                $lis .= Display::tag('li', $home_link);
808
            }
809
        }
810
811
        // View as student/teacher link
812
        if (!empty($view_as_student_link)) {
813
            $html .= Display::tag('div', $view_as_student_link, array('id' => 'view_as_link', 'class' => 'pull-right'));
814
        }
815
816
        if (!empty($navigation_right)) {
817
            foreach ($navigation_right as $item) {
818
                $extra_class = isset($item['class']) ? $item['class'] : null;
819
                $lis .= Display::tag('li', $item['title'], array('class' => $extra_class.' pull-right'));
820
            }
821
        }
822
823
        if (!empty($lis)) {
824
            $html .= Display::tag('ul', $lis, array('class' => 'breadcrumb'));
825
        }
826
    }
827
828
    return $html.$additonalBlocks;
829
}
830
831
/**
832
 * Helper function to get the number of users online, using cache if available
833
 * @return  int     The number of users currently online
834
 */
835
function getOnlineUsersCount()
836
{
837
    $number = 0;
838
    $cacheAvailable = api_get_configuration_value('apc');
839
    if ($cacheAvailable === true) {
840
        $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple';
841 View Code Duplication
        if (apcu_exists($apcVar)) {
842
            $number = apcu_fetch($apcVar);
843
        } else {
844
            $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
845
            apcu_store($apcVar, $number, 15);
846
        }
847
    } else {
848
        $number = who_is_online_count(api_get_setting('time_limit_whosonline'));
849
    }
850
851
    return $number;
852
}
853
854
/**
855
 * Helper function to get the number of users online in a course, using cache if available
856
 * @param   int $userId The user ID
857
 * @param   array $_course The course details
858
 * @return  int     The number of users currently online
859
 */
860
function getOnlineUsersInCourseCount($userId, $_course)
861
{
862
    $cacheAvailable = api_get_configuration_value('apc');
863
    $numberOnlineInCourse = 0;
864
    if (!empty($_course['id'])) {
865
        if ($cacheAvailable === true) {
866
            $apcVar = api_get_configuration_value('apc_prefix').'my_campus_whoisonline_count_simple_'.$_course['id'];
867 View Code Duplication
            if (apcu_exists($apcVar)) {
868
                $numberOnlineInCourse = apcu_fetch($apcVar);
869
            } else {
870
                $numberOnlineInCourse = who_is_online_in_this_course_count(
871
                    $userId,
872
                    api_get_setting('time_limit_whosonline'),
873
                    $_course['id']
874
                );
875
                apcu_store(
876
                    $apcVar,
877
                    $numberOnlineInCourse,
878
                    15
879
                );
880
            }
881
        } else {
882
            $numberOnlineInCourse = who_is_online_in_this_course_count(
883
                $userId,
884
                api_get_setting('time_limit_whosonline'),
885
                $_course['id']
886
            );
887
        }
888
    }
889
890
    return $numberOnlineInCourse;
891
}
892