Passed
Push — 1.11.x ( bce6cd...c146d9 )
by Angel Fernando Quiroz
12:25
created

main/admin/configure_homepage.php (2 issues)

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Configure the portal homepage (manages multi-urls and languages).
6
 *
7
 * @package chamilo.admin
8
 */
9
10
/**
11
 * Creates menu tabs for logged and anonymous users.
12
 *
13
 * This function copies the file containing private a public tabs (home_tabs_logged_in_$language.html)
14
 * in to the public tab template (home_tabs_$language.html) but without the private tabs.
15
 * Private tabs are the ones including "?private" string in the end of the url, ex: http://google.com/?private
16
 *
17
 * @param  string Name of the file been updated by the administration, ex: home_tabs_logged_in_($language).html
18
 */
19
function home_tabs($file_logged_in)
20
{
21
    $post = strpos($file_logged_in, "_logged_in");
22
    if ($post !== false) {
23
        $file_logged_out = str_replace('_logged_in', '', $file_logged_in);
24
        //variables initialization
25
        $data_logged_out = [];
26
        $data_logged_in = [];
27
28
        //we read the file with all links
29
        $file = file($file_logged_in);
30
        foreach ($file as $line) {
31
            $line = str_replace("\n", '', $line);
32
            //not logged user only sees public links
33
            if (!preg_match('/::private/', $line)) {
34
                $data_logged_out[] = $line;
35
            }
36
            //logged user only sees all links
37
            $data_logged_in[] = $line;
38
        }
39
        //tabs file for logged out users
40
        if (file_exists($file_logged_out)) {
41
            $fp = fopen($file_logged_out, 'w');
42
            fputs($fp, implode("\n", $data_logged_out));
43
            fclose($fp);
44
        }
45
        //tabs file for logged in users
46
        $fp = fopen($file_logged_in, 'w');
47
        fputs($fp, implode("\n", $data_logged_in));
48
        fclose($fp);
49
    }
50
}
51
52
$cidReset = true;
53
require_once __DIR__.'/../inc/global.inc.php';
54
55
$this_section = SECTION_PLATFORM_ADMIN;
56
$_SESSION['this_section'] = $this_section;
57
$this_page = '';
58
59
api_protect_admin_script();
60
61
$htmlHeadXtra[] = '<script>
62
$(function() {
63
    $("#all_langs").change(function() {
64
        if ($("#all_langs[type=checkbox]").is(":checked")) {
65
            $("#table_langs [type=checkbox]").prop("checked", true);
66
        } else {
67
            $("#table_langs [type=checkbox]").prop("checked", false);
68
        }
69
    });
70
});
71
</script>';
72
73
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
74
$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
75
$tool_name = get_lang('ConfigureHomePage');
76
$_languages = api_get_languages();
77
$selfUrl = api_get_self();
78
$interbreadcrumb[] = [
79
    'url' => 'index.php',
80
    'name' => get_lang('PlatformAdmin'),
81
];
82
83
if (!empty($action)) {
84
    $interbreadcrumb[] = [
85
        'url' => 'configure_homepage.php',
86
        'name' => get_lang('ConfigureHomePage'),
87
    ];
88
89
    switch ($action) {
90
        case 'edit_top':
91
            $tool_name = get_lang('EditHomePage');
92
            break;
93
        case 'edit_news':
94
            $tool_name = get_lang('EditNews');
95
            break;
96
        case 'edit_notice':
97
            $tool_name = get_lang('EditNotice');
98
            break;
99
        case 'insert_link':
100
            $tool_name = get_lang('InsertLink');
101
            break;
102
        case 'edit_link':
103
            $tool_name = get_lang('EditLink');
104
            break;
105
        case 'insert_tabs':
106
            $tool_name = get_lang('InsertTabs');
107
            break;
108
        case 'edit_tabs':
109
            $tool_name = get_lang('EditTabs');
110
            break;
111
    }
112
}
113
114
// The global logic for language priorities should be:
115
// - take language selected when connecting ($_SESSION['user_language_choice'])
116
//   or last language selected (taken from select box into SESSION by global.inc.php)
117
//   or, if unavailable;
118
// - take default user language ($_SESSION['_user']['language']) - which is taken from
119
//   the database in local.inc.php or, if unavailable;
120
// - take platform language (taken from the database campus setting 'platformLanguage')
121
// Then if a language file doesn't exist, it should be created.
122
// The default language for the homepage should use the default platform language
123
// (if nothing else is selected), which means the 'no-language' file should be taken
124
// to fill a new 'language-specified' language file, and then only the latter should be
125
// modified. The original 'no-language' files should never be modified.
126
127
// ----- Language selection -----
128
// The final language selected and used everywhere in this script follows the rules
129
// described above and is put into "$lang". Because this script includes
130
// global.inc.php, the variables used for language purposes below are considered safe.
131
132
$lang = ''; //el for "Edit Language"
133
if (!empty($_SESSION['user_language_choice'])) {
134
    $lang = $_SESSION['user_language_choice'];
135
} elseif (!empty($_SESSION['_user']['language'])) {
136
    $lang = $_SESSION['_user']['language'];
137
} else {
138
    $lang = api_get_setting('platformLanguage');
139
}
140
141
$languageGet = isset($_GET['language']) ? Security::remove_XSS($_GET['language']) : $lang;
142
143
// Ensuring availability of main files in the corresponding language
144
$homePath = api_get_path(SYS_HOME_PATH);
145
146
if (api_is_multiple_url_enabled()) {
147
    $access_url_id = api_get_current_access_url_id();
148
    if ($access_url_id != -1) {
149
        $url_info = api_get_access_url($access_url_id);
150
        $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
151
        $clean_url = api_replace_dangerous_char($url);
152
        $clean_url = str_replace('/', '-', $clean_url);
153
        $clean_url .= '/';
154
155
        $homep = $homePath; //homep for Home Path
156
        $homep_new = $homePath.$clean_url; //homep for Home Path added the url
157
        $new_url_dir = $homePath.$clean_url;
158
        //we create the new dir for the new sites
159
        if (!is_dir($new_url_dir)) {
160
            mkdir($new_url_dir, api_get_permissions_for_new_directories());
161
        }
162
    }
163
} else {
164
    $homep_new = '';
165
    $homep = $homePath; //homep for Home Path
166
}
167
168
$menuf = 'home_menu'; //menuf for Menu File
169
$newsf = 'home_news'; //newsf for News File
170
$topf = 'home_top'; //topf for Top File
171
$noticef = 'home_notice'; //noticef for Notice File
172
$menutabs = 'home_tabs'; //menutabs for tabs Menu
173
$mtloggedin = 'home_tabs_logged_in'; //menutabs for tabs Menu
174
$ext = '.html'; //ext for HTML Extension - when used frequently, variables are
175
// faster than hardcoded strings
176
$homef = [$menuf, $newsf, $topf, $noticef, $menutabs, $mtloggedin];
177
178
// If language-specific file does not exist, create it by copying default file
179
foreach ($homef as $my_file) {
180
    if (api_is_multiple_url_enabled()) {
181
        if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
182
            if (!file_exists($homep.$my_file.$ext)) {
183
                touch($homep.$my_file.$ext);
184
            }
185
            @copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for copy(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

185
            /** @scrutinizer ignore-unhandled */ @copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
186
        }
187
    } else {
188
        if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
189
            if (!file_exists($homep.$my_file.$ext)) {
190
                touch($homep.$my_file.$ext);
191
            }
192
            @copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext);
193
        }
194
    }
195
}
196
197
if (api_is_multiple_url_enabled()) {
198
    $homep = $homep_new;
199
}
200
201
// Check WCAG settings and prepare edition using WCAG
202
$errorMsg = '';
203
204
// Filter link param
205
$link = '';
206
if (!empty($_GET['link'])) {
207
    $link = $_GET['link'];
208
    // If the link parameter is suspicious, empty it
209
    if (strstr($link, '/') || !strstr($link, '.html') || strstr($link, '\\')) {
210
        $link = '';
211
        $action = '';
212
    }
213
}
214
215
// Start analysing requested actions
216
if (!empty($action)) {
217
    if (!empty($_POST['formSent'])) {
218
        // Variables used are $homep for home path, $menuf for menu file, $newsf
219
        // for news file, $topf for top file, $noticef for noticefile,
220
        // $ext for '.html'
221
        switch ($action) {
222
            case 'edit_top':
223
                // Filter
224
                $home_top = trim(stripslashes($_POST['home_top']));
225
226
                // Write
227
                if (is_writable($homep)) {
228
                    // Default
229
                    if (is_writable($homep.$topf.'_'.$lang.$ext)) {
230
                        $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
231
                        fputs($fp, $home_top);
232
                        fclose($fp);
233
234
                        // Language
235
                        foreach ($_languages['name'] as $key => $value) {
236
                            $lang_name = $_languages['folder'][$key];
237
                            if (isset($_POST[$lang_name])) {
238
                                $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
239
                                fputs($fp, $home_top);
240
                                fclose($fp);
241
                            }
242
                        }
243
                    } else {
244
                        $errorMsg = get_lang('HomePageFilesNotWritable');
245
                    }
246
                } else {
247
                    //File does not exist
248
                    $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
249
                    fputs($fp, $home_top);
250
                    fclose($fp);
251
252
                    foreach ($_languages['name'] as $key => $value) {
253
                        $lang_name = $_languages['folder'][$key];
254
                        if (isset($_POST[$lang_name])) {
255
                            if (file_exists($homep.$topf.'_'.$lang_name.$ext)) {
256
                                $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
257
                                fputs($fp, $home_top);
258
                                fclose($fp);
259
                            }
260
                        }
261
                    }
262
                }
263
264
                if (EventsMail::check_if_using_class('portal_homepage_edited')) {
265
                    EventsDispatcher::events('portal_homepage_edited', ['about_user' => api_get_user_id()]);
266
                }
267
                Event::addEvent(
268
                    LOG_HOMEPAGE_CHANGED,
269
                    'edit_top',
270
                    cut(strip_tags($home_top), 254),
271
                    api_get_utc_datetime(),
272
                    api_get_user_id()
273
                );
274
                break;
275
            case 'edit_notice':
276
                // Filter
277
                $notice_title = trim(strip_tags(stripslashes($_POST['notice_title'])));
278
                $notice_text = trim(str_replace(["\r", "\n"], ['', '<br />'], strip_tags(stripslashes($_POST['notice_text']), '<a>')));
279
                if (empty($notice_title) || empty($notice_text)) {
280
                    $errorMsg = get_lang('NoticeWillBeNotDisplayed');
281
                }
282
                // Write
283
                if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
284
                    if (is_writable($homep.$noticef.'_'.$lang.$ext)) {
285
                        $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
286
                        if ($errorMsg == '') {
287
                            fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
288
289
                            foreach ($_languages['name'] as $key => $value) {
290
                                $lang_name = $_languages['folder'][$key];
291
                                if (isset($_POST[$lang_name])) {
292
                                    if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
293
                                        if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) {
294
                                            $fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
295
                                            fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
296
                                            fclose($fp);
297
                                        }
298
                                    }
299
                                }
300
                            }
301
                        } else {
302
                            fputs($fp, '');
303
304
                            foreach ($_languages['name'] as $key => $value) {
305
                                $lang_name = $_languages['folder'][$key];
306
                                if (isset($_POST[$lang_name])) {
307
                                    if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
308
                                        $fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
309
                                        fputs($fp1, '');
310
                                        fclose($fp1);
311
                                    }
312
                                }
313
                            }
314
                        }
315
                        fclose($fp);
316
                    } else {
317
                        $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable');
318
                    }
319
                } else {
320
                    //File does not exist
321
                    $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
322
                    fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
323
                    fclose($fp);
324
                }
325
                Event::addEvent(
326
                    LOG_HOMEPAGE_CHANGED,
327
                    'edit_notice',
328
                    cut(strip_tags($notice_title), 254),
329
                    api_get_utc_datetime(),
330
                    api_get_user_id()
331
                );
332
                break;
333
            case 'edit_news':
334
                //Filter
335
                $home_news = trim(stripslashes($_POST['home_news']));
336
337
                //Write
338
                if ($s_languages_news != 'all') {
339
                    if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) {
340
                        if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) {
341
                            $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
342
                            fputs($fp, $home_news);
343
                            fclose($fp);
344
                        } else {
345
                            $errorMsg = get_lang('HomePageFilesNotWritable');
346
                        }
347
                    } else {
348
                        // File does not exist
349
                        $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
350
                        fputs($fp, $home_news);
351
                        fclose($fp);
352
                    }
353
                } else {
354
                    // We update all the news file
355
                    foreach ($_languages['name'] as $key => $value) {
356
                        $english_name = $_languages['folder'][$key];
357
                        if (file_exists($homep.$newsf.'_'.$english_name.$ext)) {
358
                            if (is_writable($homep.$newsf.'_'.$english_name.$ext)) {
359
                                $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
360
                                fputs($fp, $home_news);
361
                                fclose($fp);
362
                            } else {
363
                                $errorMsg = get_lang('HomePageFilesNotWritable');
364
                            }
365
                        } else {
366
                            // File does not exist
367
                            $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
368
                            fputs($fp, $home_news);
369
                            fclose($fp);
370
                        }
371
                    }
372
                }
373
                Event::addEvent(
374
                    LOG_HOMEPAGE_CHANGED,
375
                    'edit_news',
376
                    strip_tags(cut($home_news, 254)),
377
                    api_get_utc_datetime(),
378
                    api_get_user_id()
379
                );
380
                break;
381
            case 'insert_tabs':
382
            case 'edit_tabs':
383
            case 'insert_link':
384
            case 'edit_link':
385
                $link_index = (isset($_POST['link_index']) ? intval($_POST['link_index']) : 0);
386
                $insert_where = (isset($_POST['insert_where']) ? intval($_POST['insert_where']) : 0);
387
                $link_name = trim(stripslashes($_POST['link_name']));
388
                $link_url = trim(stripslashes($_POST['link_url']));
389
                $add_in_tab = (isset($_POST['add_in_tab']) ? intval($_POST['add_in_tab']) : 0);
390
                $link_html = trim(stripslashes($_POST['link_html']));
391
                $filename = trim(stripslashes($_POST['filename']));
392
                $target_blank = isset($_POST['target_blank']);
393
394
                if ($link_url == 'http://' || $link_url == 'https://') {
395
                    $link_url = '';
396
                } elseif (!empty($link_url) && !strstr($link_url, '://')) {
397
                    $link_url = 'http://'.$link_url;
398
                }
399
                $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
400
401
                if (!is_writable($homep.$menuf.'_'.$lang.$ext)) {
402
                    $errorMsg = get_lang('HomePageFilesNotWritable');
403
                } elseif (empty($link_name)) {
404
                    $errorMsg = get_lang('PleaseEnterLinkName');
405
                } else {
406
                    // New links are added as new files in the home/ directory
407
                    if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) {
408
                        $filename = api_replace_dangerous_char($link_name).'.html';
409
                    }
410
411
                    // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files)
412
                    if (!empty($filename)) {
413
                        $filename = str_replace('home_', 'user_', $filename);
414
                    }
415
                    // If the typical language suffix is not found in the file name,
416
                    // replace the ".html" suffix by "_en.html" or the active menu language
417
                    if (!strstr($filename, '_'.$lang.$ext)) {
418
                        $filename = str_replace($ext, '_'.$lang.$ext, $filename);
419
                    }
420
                    // Get the contents of home_menu_en.html (or active menu language
421
                    // version) into $home_menu as an array of one entry per line
422
                    $home_menu = file($homep.$menuf.'_'.$lang.$ext);
423
                    $home_menu = implode("\n", $home_menu);
424
                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
425
                    $home_menu = explode("\n", $home_menu);
426
                    $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
427
                    // Prepare place to insert the new link into (default is end of file)
428
                    if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) {
429
                        $insert_where = sizeof($home_menu) - 1;
430
                    }
431
                    //
432
                    // For each line of the file, remove trailing spaces and special chars
433
                    //foreach ($home_menu as $key => $enreg) {
434
                    //	$home_menu[$key] = trim($enreg);
435
                    //}
436
                    //
437
                    // If the given link url is empty, then replace the link url by a link to the link file created
438
439
                    if (empty($link_url) || $link_url == 'http://' || $link_url == 'https://') {
440
                        $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
441
                        // If the file doesn't exist, then create it and
442
                        // fill it with default text
443
444
                        $fp = @fopen($homep.$filename, 'w');
445
                        if ($fp) {
446
                            if (empty($link_html)) {
447
                                fputs($fp, get_lang('MyTextHere'));
448
                                home_tabs($homep.$filename);
449
                            } else {
450
                                fputs($fp, $link_html);
451
                                home_tabs($homep.$filename);
452
                            }
453
                            fclose($fp);
454
                        }
455
                    }
456
                    // If the requested action is to edit a link, open the file and
457
                    // write to it (if the file doesn't exist, create it)
458
                    if (in_array($action, ['edit_link']) && !empty($link_html)) {
459
                        $fp = @fopen($homep.$filename, 'w');
460
                        if ($fp) {
461
                            fputs($fp, $link_html);
462
                            home_tabs($homep.$filename);
463
                            fclose($fp);
464
                        }
465
                    }
466
467
                    $class_add_in_tab = 'class="show_menu"';
468
469
                    if (!$add_in_tab) {
470
                        $class_add_in_tab = 'class="hide_menu"';
471
                    }
472
473
                    // If the requested action is to create a link, make some room
474
                    // for the new link in the home_menu array at the requested place
475
                    // and insert the new link there
476
477
                    if ($action == 'insert_link' || $action == 'insert_tabs') {
478
                        for ($i = sizeof($home_menu); $i; $i--) {
479
                            if ($i > $insert_where) {
480
                                $home_menu[$i] = $home_menu[$i - 1];
481
                            } else {
482
                                break;
483
                            }
484
                        }
485
                        $home_menu[$insert_where + 1] = '<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'.$link_name.'</a></li>';
486
                    } else {
487
                        // If the request is about a link edition, change the link
488
                        $home_menu[$link_index] = '<li '.$class_add_in_tab.'><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'.$link_name.'</a></li>';
489
                    }
490
                    // Re-build the file from the home_menu array
491
                    $home_menu = implode("\n", $home_menu);
492
                    // Write
493
                    if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
494
                        if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
495
                            $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
496
                            fputs($fp, $home_menu);
497
                            home_tabs($homep.$menuf.'_'.$lang.$ext);
498
                            fclose($fp);
499
500
                            foreach ($_languages['name'] as $key => $value) {
501
                                $lang_name = $_languages['folder'][$key];
502
                                if (isset($_POST[$lang_name])) {
503
                                    $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
504
                                    fputs($fp, $home_menu);
505
                                    home_tabs($homep.$menuf.'_'.$lang_name.$ext);
506
                                    fclose($fp);
507
                                }
508
                            }
509
510
                            if (file_exists($homep.$menuf.$ext)) {
511
                                if (is_writable($homep.$menuf.$ext)) {
512
                                    $fpo = fopen($homep.$menuf.$ext, 'w');
513
                                    fputs($fpo, $home_menu);
514
                                    home_tabs($homep.$menuf.$ext);
515
                                    fclose($fpo);
516
                                }
517
                            }
518
                        } else {
519
                            $errorMsg = get_lang('HomePageFilesNotWritable');
520
                        }
521
                    } else {
522
                        //File does not exist
523
                        $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
524
                        fputs($fp, $home_menu);
525
                        home_tabs($homep.$menuf.'_'.$lang.$ext);
526
                        fclose($fp);
527
528
                        foreach ($_languages['name'] as $key => $value) {
529
                            $lang_name = $_languages['folder'][$key];
530
                            if (isset($_POST[$lang_name])) {
531
                                $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
532
                                fputs($fp, $home_menu);
533
                                home_tabs($homep.$menuf.'_'.$lang_name.$ext);
534
                                fclose($fp);
535
                            }
536
                        }
537
                    }
538
                }
539
                Event::addEvent(
540
                    LOG_HOMEPAGE_CHANGED,
541
                    $action,
542
                    cut($link_name.':'.$link_url, 254),
543
                    api_get_utc_datetime(),
544
                    api_get_user_id()
545
                );
546
                break;
547
        } //end of switch($action)
548
549
        if (empty($errorMsg)) {
550
            header('Location: '.$selfUrl.'?language='.$languageGet);
551
            exit();
552
        }
553
    } else {
554
        //if POST[formSent] is not set
555
        switch ($action) {
556
            case 'delete_all':
557
                foreach ($_languages['name'] as $key => $value) {
558
                    $lang = $_languages['folder'][$key];
559
                    $link_index = intval($_GET['link_index']);
560
                    $menuf = $mtloggedin;
561
                    $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
562
                    if (empty($home_menu)) {
563
                        $home_menu = [];
564
                    }
565
                    foreach ($home_menu as $key => $enreg) {
0 ignored issues
show
Comprehensibility Bug introduced by
$key is overwriting a variable from outer foreach loop.
Loading history...
566
                        if ($key == $link_index) {
567
                            unset($home_menu[$key]);
568
                        } else {
569
                            $home_menu[$key] = trim($enreg);
570
                        }
571
                    }
572
                    $home_menu = implode("\n", $home_menu);
573
                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
574
575
                    $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
576
                    fputs($fp, $home_menu);
577
                    home_tabs($homep.$menuf.'_'.$lang.$ext);
578
                    fclose($fp);
579
                    if (file_exists($homep.$menuf.$ext)) {
580
                        if (is_writable($homep.$menuf.$ext)) {
581
                            $fpo = fopen($homep.$menuf.$ext, 'w');
582
                            fputs($fpo, $home_menu);
583
                            home_tabs($homep.$menuf.$ext);
584
                            fclose($fpo);
585
                        }
586
                    }
587
                    header('Location: '.$selfUrl);
588
                }
589
                exit();
590
                break;
591
            case 'open_link':
592
                // Previously, filtering of GET['link'] was done here but it left
593
                // a security threat. Filtering has now been moved outside conditions
594
                break;
595
            case 'delete_tabs':
596
            case 'delete_link':
597
                // A link is deleted by getting the file into an array, removing the
598
                // link and re-writing the array to the file
599
                $link_index = intval($_GET['link_index']);
600
                $menuf = ($action == 'delete_tabs') ? $mtloggedin : $menuf;
601
                $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
602
                if (empty($home_menu)) {
603
                    $home_menu = [];
604
                }
605
                foreach ($home_menu as $key => $enreg) {
606
                    if ($key == $link_index) {
607
                        unset($home_menu[$key]);
608
                    } else {
609
                        $home_menu[$key] = trim($enreg);
610
                    }
611
                }
612
                $home_menu = implode("\n", $home_menu);
613
                $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
614
615
                $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
616
                fputs($fp, $home_menu);
617
                home_tabs($homep.$menuf.'_'.$lang.$ext);
618
                fclose($fp);
619
                if (file_exists($homep.$menuf.$ext)) {
620
                    if (is_writable($homep.$menuf.$ext)) {
621
                        $fpo = fopen($homep.$menuf.$ext, 'w');
622
                        fputs($fpo, $home_menu);
623
                        home_tabs($homep.$menuf.$ext);
624
                        fclose($fpo);
625
                    }
626
                }
627
                header('Location: '.$selfUrl);
628
                exit();
629
                break;
630
            case 'edit_top':
631
                // This request is only the preparation for the update of the home_top
632
                $home_top = '';
633
                if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
634
                    $home_top = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
635
                } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
636
                    $home_top = @(string) file_get_contents($homep.$topf.$lang.$ext);
637
                } else {
638
                    $errorMsg = get_lang('HomePageFilesNotReadable');
639
                }
640
                $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
641
                break;
642
            case 'edit_notice':
643
                // This request is only the preparation for the update of the home_notice
644
                $home_notice = '';
645
                if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) {
646
                    $home_notice = @file($homep.$noticef.'_'.$lang.$ext);
647
                } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) {
648
                    $home_notice = @file($homep.$noticef.$lang.$ext);
649
                } else {
650
                    $errorMsg = get_lang('HomePageFilesNotReadable');
651
                }
652
                if (empty($home_notice)) {
653
                    $home_notice = [];
654
                }
655
                $notice_title = strip_tags($home_notice[0]);
656
                $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title));
657
                $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>');
658
                $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text)));
659
                break;
660
            case 'edit_news':
661
                // This request is the preparation for the update of the home_news page
662
                $home_news = '';
663
                if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
664
                    $home_news = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
665
                } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
666
                    $home_news = @(string) file_get_contents($homep.$newsf.$lang.$ext);
667
                } else {
668
                    $errorMsg = get_lang('HomePageFilesNotReadable');
669
                }
670
                $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news)));
671
                break;
672
            case 'insert_link':
673
                // This request is the preparation for the addition of an item in home_menu
674
                $home_menu = '';
675
                $menuf = ($action == 'edit_tabs') ? $mtloggedin : $menuf;
676
                if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
677
                    $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
678
                } elseif (is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
679
                    $home_menu = @file($homep.$menuf.$lang.$ext);
680
                } else {
681
                    $errorMsg = get_lang('HomePageFilesNotReadable');
682
                }
683
                if (empty($home_menu)) {
684
                    $home_menu = [];
685
                }
686
                if (!empty($home_menu)) {
687
                    $home_menu = implode("\n", $home_menu);
688
                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
689
                    $home_menu = explode("\n", $home_menu);
690
                }
691
                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
692
                break;
693
            case 'insert_tabs':
694
                // This request is the preparation for the addition of an item in home_menu
695
                $home_menu = '';
696
                if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
697
                    $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
698
                } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
699
                    $home_menu = @file($homep.$mtloggedin.$lang.$ext);
700
                } elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) {
701
                    $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
702
                } else {
703
                    $errorMsg = get_lang('HomePageFilesNotReadable');
704
                }
705
                if (empty($home_menu)) {
706
                    $home_menu = [];
707
                }
708
                if (!empty($home_menu)) {
709
                    $home_menu = implode("\n", $home_menu);
710
                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
711
                    $home_menu = explode("\n", $home_menu);
712
                }
713
                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
714
                break;
715
            case 'edit_tabs':
716
            case 'edit_link':
717
                // This request is the preparation for the edition of the links array
718
                $home_menu = '';
719
                $menuf = ($action == 'edit_tabs') ? $mtloggedin : $menuf;
720
                if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
721
                    $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
722
                } elseif (is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
723
                    $home_menu = @file($homep.$menuf.$lang.$ext);
724
                } else {
725
                    $errorMsg = get_lang('HomePageFilesNotReadable');
726
                }
727
728
                if (empty($home_menu)) {
729
                    if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
730
                        $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
731
                    }
732
                }
733
734
                if (empty($home_menu)) {
735
                    $home_menu = [];
736
                }
737
                if (!empty($home_menu)) {
738
                    $home_menu = implode("\n", $home_menu);
739
                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
740
                    $home_menu = explode("\n", $home_menu);
741
                }
742
743
                $link_index = intval($_GET['link_index']);
744
745
                $target_blank = false;
746
                $link_name = '';
747
                $link_url = '';
748
749
                //$home_menu_new = array();
750
                //
751
                //Cleaning array
752
                //foreach ($home_menu as $item) {
753
                //	if(!empty($item)) {
754
                //		$home_menu_new[] = $item;
755
                //	}
756
                //}
757
                //$home_menu = $home_menu_new;
758
759
                // Cleaning the array
760
                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
761
762
                // For each line of the home_menu file
763
                foreach ($home_menu as $key => $enreg) {
764
                    // Check if the current item is the one we want to update
765
                    if ($key == $link_index) {
766
                        // This is the link we want to update
767
                        // Check if the target should be "_blank"
768
                        if (strstr($enreg, 'target="_blank"')) {
769
                            $target_blank = true;
770
                        }
771
772
                        if (strstr($enreg, 'hide_menu')) {
773
                            $add_in_tab = false;
774
                        } else {
775
                            $add_in_tab = true;
776
                        }
777
778
                        // Remove dangerous HTML tags from the link itself (this is an
779
                        // additional measure in case a link previously contained
780
                        // unsecure tags)
781
                        $link_name = strip_tags($enreg);
782
783
                        // Get the contents of "href" attribute in $link_url
784
                        $enreg = explode('href="', $enreg);
785
                        list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
786
787
                        // If the link contains the web root of this portal, then strip
788
                        // it off and keep only the name of the file that needs edition
789
                        if (strstr($link_url, '?include=')) {
790
                            $link_url = explode('?include=', $link_url);
791
792
                            $filename = $link_url[sizeof($link_url) - 1];
793
794
                            if (!strstr($filename, '/') && strstr($filename, '.html')) {
795
                                // Get oonly the contents of the link file
796
                                $link_html = @file($homep.$filename);
797
                                $link_html = implode('', $link_html);
798
                                $link_url = '';
799
                            } else {
800
                                $filename = '';
801
                            }
802
                        }
803
                        break;
804
                    }
805
                }
806
                break;
807
        }//end of second switch($action) (when POST['formSent'] was not set, yet)
808
    }// end of "else" in if($_POST['formSent']) condition
809
} else {
810
    //if $action is empty, then prepare a list of the course categories to display (?)
811
    $Categories = CourseCategory::getCategoriesToDisplayInHomePage();
812
}
813
814
// Display section
815
816
Display::display_header($tool_name);
817
818
switch ($action) {
819
    case 'open_link':
820
        if (!empty($link)) {
821
            // $link is only set in case of action=open_link and is filtered
822
            $open = @(string) file_get_contents($homep.$link);
823
            $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
824
            echo $open;
825
        }
826
        break;
827
    case 'edit_notice':
828
        // Display for edit_notice case
829
        ?>
830
        <form action="<?php echo $selfUrl; ?>?action=<?php echo $action; ?>" method="post" class="form-horizontal">
831
            <legend><?php echo $tool_name; ?></legend>
832
            <input type="hidden" name="formSent" value="1"/>
833
            <?php
834
            if (!empty($errorMsg)) {
835
                echo Display::return_message($errorMsg, 'normal');
836
            }
837
            ?>
838
            <div class="row">
839
                <div class="col-md-12">
840
                    <p><?php echo get_lang('LetThoseFieldsEmptyToHideTheNotice'); ?></p>
841
                    <div class="form-group">
842
                        <label class="col-sm-3 control-label"> <?php echo get_lang('NoticeTitle'); ?> </label>
843
                        <div class="col-sm-6">
844
                            <input type="text" name="notice_title" size="30" maxlength="50"
845
                                   value="<?php echo $notice_title; ?>" class="form-control"/>
846
                        </div>
847
                        <div class="col-sm-3"></div>
848
                    </div>
849
                    <div class="form-group">
850
                        <label class="col-sm-3 control-label"><?php echo get_lang('NoticeText'); ?></label>
851
                        <div class="col-sm-6">
852
                            <textarea name="notice_text" cols="30" rows="5" wrap="virtual"
853
                                      class="form-control"><?php echo $notice_text; ?></textarea>
854
                        </div>
855
                        <div class="col-sm-3"></div>
856
                    </div>
857
                    <div class="form-group">
858
                        <div class="col-sm-3"></div>
859
                        <div class="col-sm-6">
860
                            <div class="checkbox">
861
                                <label>
862
                                    <input type="checkbox" name="all_langs"
863
                                           value="<?php echo get_lang('ApplyAllLanguages'); ?>"/> <?php echo get_lang('ApplyAllLanguages'); ?>
864
                                </label>
865
                            </div>
866
                        </div>
867
                        <div class="col-sm-3"></div>
868
                    </div>
869
                    <div class="form-group">
870
                        <div class="col-sm-offset-3 col-sm-9">
871
                            <button class="btn btn-primary" type="submit"
872
                                    value="<?php echo get_lang('Ok'); ?>"><?php echo get_lang('Ok'); ?></button>
873
                        </div>
874
                    </div>
875
                </div>
876
            </div>
877
        </form>
878
        <?php
879
        break;
880
    case 'insert_tabs':
881
    case 'edit_tabs':
882
    case 'insert_link':
883
    case 'edit_link':
884
        $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
885
        if (!empty($errorMsg)) {
886
            echo Display::return_message($errorMsg, 'normal');
887
        }
888
        $default = [];
889
        $form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', ['style' => 'margin: 0px;']);
890
        $renderer = &$form->defaultRenderer();
891
892
        $form->addElement('header', '', $tool_name);
893
        $form->addElement('hidden', 'formSent', '1');
894
        $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
895
        $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : '');
896
897
        $form->addElement('text', 'link_name', get_lang('LinkName'), ['size' => '30', 'maxlength' => '50']);
898
        if (!empty($link_name)) {
899
            $default['link_name'] = $link_name;
900
        }
901
        $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
902
        $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : '';
903
        $form->addElement('text', 'link_url', [get_lang('LinkURL'), $linkUrlComment], ['size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;']);
904
905
        $options = ['-1' => get_lang('FirstPlace')];
906
907
        $selected = '';
908
909
        if ($action == 'insert_link' || $action == 'insert_tabs') {
910
            $add_in_tab = 1;
911
            if (is_array($home_menu)) {
912
                foreach ($home_menu as $key => $enreg) {
913
                    if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
914
                        $options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
915
                        $formSentCheck = (!empty($_POST['formSent']) ? true : false);
916
                        $selected = $formSentCheck && $insert_where == $key ? $key : '';
917
                    }
918
                }
919
            }
920
            $default['insert_link'] = $selected;
921
            $form->addElement('select', 'insert_where', get_lang('InsertThisLink'), $options);
922
        }
923
924
        $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
925
926
        if ($action == 'insert_tabs' || $action == 'edit_tabs') {
927
            $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1);
928
            $default['add_in_tab'] = $add_in_tab;
929
        }
930
931
        if (!empty($target_blank)) {
932
            $target_blank_checkbox->setChecked(true);
933
        }
934
935
        if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) {
936
            $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
937
            $form->addHtmlEditor('link_html', get_lang('Content'), false, false, ['ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400']);
938
            $form->addButtonSave(get_lang('Save'), 'submit');
939
        } else {
940
            if (in_array($action, ['edit_tabs', 'insert_tabs'])) {
941
                $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : '');
942
                $form->addHtmlEditor('link_html', get_lang('Content'), false, false, ['ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400']);
943
            }
944
            $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), ['id' => 'all_langs']);
945
            $form->addElement('html', '<table id="table_langs" style="margin-left:159px;"><tr>');
946
            $i = 0;
947
            foreach ($_languages['name'] as $key => $value) {
948
                $i++;
949
                $lang_name = $_languages['folder'][$key];
950
                $html_langs = '<td width="300">';
951
                $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
952
                $html_langs .= '</td>';
953
                if ($i % 5 == 0) {
954
                    $html_langs .= '</tr><tr>';
955
                }
956
                $form->addElement('html', $html_langs);
957
            }
958
            $form->addElement('html', '</tr></table><br/>');
959
            $form->addButtonSave(get_lang('Save'), 'submit');
960
        }
961
962
        $form->setDefaults($default);
963
        $form->display();
964
965
        break;
966
    case 'edit_top':
967
    case 'edit_news':
968
        if ($action == 'edit_top') {
969
            $name = $topf;
970
            $open = $home_top;
971
        } else {
972
            $name = $newsf;
973
            $open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
974
        }
975
        $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
976
977
        if (!empty($errorMsg)) {
978
            echo Display::return_message($errorMsg, 'normal'); //main API
979
        }
980
981
        $default = [];
982
        $form = new FormValidator(
983
            'configure_homepage_'.$action,
984
            'post',
985
            $selfUrl.'?action='.$action,
986
            '',
987
            ['style' => 'margin: 0px;']
988
        );
989
        $renderer = &$form->defaultRenderer();
990
        $renderer->setHeaderTemplate('');
991
        $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
992
        $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
993
        $renderer->setRequiredNoteTemplate('');
994
        $form->addElement('hidden', 'formSent', '1');
995
996
        if ($action == 'edit_news') {
997
            $_languages = api_get_languages();
998
            $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
999
            $html .= '<select name="news_languages">';
1000
            $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>';
1001
            foreach ($_languages['name'] as $key => $value) {
1002
                $english_name = $_languages['folder'][$key];
1003
                if ($language == $english_name) {
1004
                    $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
1005
                } else {
1006
                    $html .= '<option value="'.$english_name.'">'.$value.'</option>';
1007
                }
1008
            }
1009
            $html .= '</select></td></tr>';
1010
            $form->addElement('html', $html);
1011
        }
1012
1013
        $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
1014
        $form->addHtmlEditor($name, '', true, false, ['ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400']);
1015
        $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), ['id' => 'all_langs']);
1016
        $form->addElement('html', '<table id="table_langs" style="margin-left:5px;"><tr>');
1017
1018
        $currentLanguage = api_get_interface_language();
1019
        $i = 0;
1020
        foreach ($_languages['name'] as $key => $value) {
1021
            $lang_name = $_languages['folder'][$key];
1022
            $i++;
1023
1024
            $checked = null;
1025
            if ($languageGet == $lang_name) {
1026
                $checked = "checked";
1027
            }
1028
            $html_langs = '<td width="300">';
1029
            $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" />&nbsp;'.$value.'<label/>';
1030
            $html_langs .= '</td>';
1031
            if ($i % 5 == 0) {
1032
                $html_langs .= '</tr><tr>';
1033
            }
1034
            $form->addElement('html', $html_langs);
1035
        }
1036
        $form->addElement('html', '</tr></table><br/>');
1037
        $form->addButtonSave(get_lang('Save'));
1038
        $form->setDefaults($default);
1039
        $form->display();
1040
1041
        break;
1042
    default: // When no action applies, default page to update campus homepage
1043
        ?>
1044
1045
        <section id="page-home">
1046
            <div class="row">
1047
                <div class="col-md-3">
1048
1049
                    <!-- login block -->
1050
                    <div id="login-block" class="panel panel-default">
1051
                        <div class="panel-body">
1052
                            <?php echo api_display_language_form(false, true); ?>
1053
                            <form id="formLogin" class="form-horizontal">
1054
                                <div class="input-group">
1055
                                    <div class="input-group-addon"><em class="fa fa-user"></em></div>
1056
                                    <input class="form-control" type="text" id="login" value="" disabled="disabled"/>
1057
                                </div>
1058
                                <div class="input-group">
1059
                                    <div class="input-group-addon"><em class="fa fa-lock"></em></div>
1060
                                    <input type="password" id="password" class="form-control" value=""
1061
                                           disabled="disabled"/>
1062
                                </div>
1063
                                <button class="btn btn-primary btn-block" type="button" name="submitAuth"
1064
                                        value="<?php echo get_lang('LoginEnter'); ?>"
1065
                                        disabled="disabled"><?php echo get_lang('LoginEnter'); ?></button>
1066
                            </form>
1067
                            <ul class="nav nav-pills nav-stacked">
1068
                                <li><?php echo api_ucfirst(get_lang('SignUp')); ?></li>
1069
                                <li><?php echo api_ucfirst(get_lang('LostPassword')); ?></li>
1070
                            </ul>
1071
                        </div>
1072
                    </div>
1073
1074
                    <!-- notice block -->
1075
1076
1077
                    <div class="panel-group" id="notice-block" role="tablist" aria-multiselectable="true">
1078
                        <div class="panel panel-default">
1079
                            <div class="panel-heading" role="tab" id="headingOne">
1080
                                <h4 class="panel-title">
1081
                                    <a role="button" data-toggle="collapse" data-parent="#notice-block"
1082
                                       href="#notice-list" aria-expanded="true" aria-controls="notice-list">
1083
                                        <?php echo get_lang('Notice'); ?>
1084
                                        <a class="pull-right"
1085
                                           href="<?php echo $selfUrl; ?>?action=edit_notice"><?php Display::display_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL); ?></a>
1086
                                    </a>
1087
                                </h4>
1088
                            </div>
1089
                            <div id="notice-list" class="panel-collapse collapse in" role="tabpanel"
1090
                                 aria-labelledby="headingOne">
1091
                                <div class="panel-body">
1092
                                    <?php
1093
                                    $home_notice = '';
1094
                                    if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
1095
                                        $home_notice = @(string) file_get_contents($homep.$noticef.'_'.$lang.$ext);
1096
                                    } else {
1097
                                        $home_notice = @(string) file_get_contents($homep.$noticef.$ext);
1098
                                    }
1099
                                    $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
1100
                                    echo '<div class="homepage_notice">';
1101
                                    echo $home_notice;
1102
                                    echo '</div>';
1103
                                    ?>
1104
                                </div>
1105
                            </div>
1106
                        </div>
1107
                    </div>
1108
                    <!-- insert link block -->
1109
1110
                    <div class="panel-group" id="links-block" role="tablist" aria-multiselectable="true">
1111
                        <div class="panel panel-default">
1112
                            <div class="panel-heading" role="tab" id="headingOne">
1113
                                <h4 class="panel-title">
1114
                                    <a role="button" data-toggle="collapse" data-parent="#links-block"
1115
                                       href="#links-list" aria-expanded="true" aria-controls="links-list">
1116
                                        <?php echo api_ucfirst(get_lang('MenuGeneral')); ?>
1117
                                    </a>
1118
                                </h4>
1119
                            </div>
1120
                            <div id="links-list" class="panel-collapse collapse in" role="tabpanel"
1121
                                 aria-labelledby="headingOne">
1122
                                <div class="panel-body">
1123
                                    <a href="<?php echo $selfUrl; ?>?action=insert_link"><?php echo Display::return_icon('add.png', get_lang('InsertLink')).'&nbsp;'.get_lang('InsertLink'); ?>
1124
                                    </a>
1125
                                    <ul class="menulist">
1126
                                        <?php
1127
                                        $home_menu = '';
1128
                                        if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
1129
                                            $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
1130
                                        } else {
1131
                                            $home_menu = @file($homep.$menuf.$ext);
1132
                                        }
1133
                                        if (empty($home_menu)) {
1134
                                            $home_menu = [];
1135
                                        }
1136
                                        if (!empty($home_menu)) {
1137
                                            $home_menu = implode("\n", $home_menu);
1138
                                            $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
1139
                                            $home_menu = explode("\n", $home_menu);
1140
                                        }
1141
                                        $i = 0;
1142
                                        foreach ($home_menu as $enreg) {
1143
                                            $enreg = trim($enreg);
1144
                                            if (!empty($enreg)) {
1145
                                                $edit_link = '<a href="'.$selfUrl.'?action=edit_link&amp;link_index='.$i.'">'.Display::return_icon('edit.png', get_lang('Edit')).'</a>';
1146
                                                $delete_link = '<a href="'.$selfUrl.'?action=delete_link&amp;link_index='.$i.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete')).'</a>';
1147
                                                echo str_replace(['href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'], ['href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=', $edit_link.' '.$delete_link.'</li>'], $enreg);
1148
                                                $i++;
1149
                                            }
1150
                                        }
1151
                                        ?>
1152
                                    </ul>
1153
                                </div>
1154
                            </div>
1155
                        </div>
1156
                    </div>
1157
1158
                </div>
1159
                <div class="col-md-9">
1160
                    <div class="actions">
1161
                        <a href="<?php echo $selfUrl; ?>?action=edit_top&language=<?php echo $languageGet; ?>">
1162
                            <?php echo Display::return_icon('edit.png', get_lang('EditHomePage'), null, ICON_SIZE_SMALL).'&nbsp;'.get_lang('EditHomePage'); ?>
1163
                        </a>
1164
                    </div>
1165
                    <section id="homepage-home">
1166
                        <?php
1167
                        //print home_top contents
1168
                        if (file_exists($homep.$topf.'_'.$lang.$ext)) {
1169
                            $home_top_temp = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
1170
                        } else {
1171
                            $home_top_temp = @(string) file_get_contents($homep.$topf.$ext);
1172
                        }
1173
                        $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
1174
                        $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1175
                        echo $open;
1176
                        ?>
1177
                    </section>
1178
1179
                    <?php
1180
                    $access_url_id = 1;
1181
                    // we only show the category options for the main chamilo installation
1182
                    if (api_is_multiple_url_enabled()) {
1183
                        $access_url_id = api_get_current_access_url_id();
1184
                    }
1185
1186
                    if ($access_url_id == 1) {
1187
                        echo '<div class="actions">';
1188
                        echo '<a href="course_category.php">'.Display::return_icon('edit.png', get_lang('Edit')).'&nbsp;'.get_lang('EditCategories').'</a>';
1189
                        echo '</div>';
1190
                        echo '<ul class="list-group">';
1191
1192
                        if (count($Categories)) {
1193
                            foreach ($Categories as $enreg) {
1194
                                echo '<li class="list-group-item">'
1195
                                    .Display::return_icon('folder.png', get_lang('CourseCategory')).' '.$enreg['name']
1196
                                    .'</li>';
1197
                            }
1198
                            unset($Categories);
1199
                        } else {
1200
                            echo '<li class="list-group-item">'.get_lang('NoCategories').'</li>';
1201
                        }
1202
1203
                        echo '</ul>';
1204
                    }
1205
                    ?>
1206
1207
                    <?php
1208
                    if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
1209
                        $open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
1210
                        $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1211
                        echo $open;
1212
                    } else {
1213
                        $open = @(string) file_get_contents($homep.$newsf.$ext);
1214
                        $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1215
                        echo $open;
1216
                    }
1217
                    ?>
1218
1219
                    <?php
1220
                    // Add new page
1221
                    $home_menu = '';
1222
                    if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) {
1223
                        $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
1224
                    } else {
1225
                        $home_menu = @file($homep.$mtloggedin.$ext);
1226
                    }
1227
                    if (empty($home_menu)) {
1228
                        if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
1229
                            $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
1230
                        }
1231
                    }
1232
                    if (empty($home_menu)) {
1233
                        $home_menu = [];
1234
                    }
1235
                    if (!empty($home_menu)) {
1236
                        $home_menu = implode("\n", $home_menu);
1237
                        $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
1238
                        $home_menu = explode("\n", $home_menu);
1239
                    }
1240
                    $link_list = '';
1241
                    $tab_counter = 0;
1242
                    foreach ($home_menu as $enreg) {
1243
                        $enreg = trim($enreg);
1244
                        if (!empty($enreg)) {
1245
                            $edit_link = ' <a href="'.$selfUrl.'?action=edit_tabs&amp;link_index='.$tab_counter.'" ><span>'.Display::return_icon('edit.png', get_lang('Edit')).'</span></a>';
1246
                            $delete_link = ' <a href="'.$selfUrl.'?action=delete_tabs&amp;link_index='.$tab_counter.'"  onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;"><span>'.Display::return_icon('delete.png', get_lang('Delete')).'</span></a>';
1247
                            $delete_all = ' <a href="'.$selfUrl.'?action=delete_all&amp;link_index='.$tab_counter.'"
1248
                                            onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\'))
1249
                                            return false;"><span>'.Display::return_icon('closed-circle.png', get_lang('DeleteInAllLanguages')).'</span></a>';
1250
                            $tab_string = str_replace(
1251
                                ['href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'],
1252
                                ['href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=',
1253
                                        $edit_link.$delete_link.$delete_all.'</li>', ],
1254
                                $enreg
1255
                            );
1256
                            $tab_string = str_replace([' class="hide_menu"', ' class="show_menu"'], '', $tab_string);
1257
                            $tab_string = str_replace(['<li>', '</li>'], '', $tab_string);
1258
                            $link_list .= Display::tag('li', $tab_string, ['class' => 'list-group-item']);
1259
                            $tab_counter++;
1260
                        }
1261
                    }
1262
                    ?>
1263
                    <div class="actions">
1264
                        <a href="<?php echo $selfUrl; ?>?action=insert_tabs">
1265
                            <?php echo Display::return_icon('add.png', get_lang('InsertLink')).'&nbsp;'.get_lang('InsertLink'); ?>
1266
                        </a>
1267
                    </div>
1268
                    <?php
1269
                    echo '<ul id="list-hiperlink" class="list-group">';
1270
                    echo $link_list;
1271
                    echo '</ul>';
1272
                    ?>
1273
                </div>
1274
            </div>
1275
        </section>
1276
        <?php
1277
        break;
1278
}
1279
Display::display_footer();
1280