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