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

main/inc/global.inc.php (1 issue)

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
6
7
/**
8
 * It is recommended that ALL Chamilo scripts include this important file.
9
 * This script manages
10
 * - include of /app/config/configuration.php;
11
 * - include of several libraries: api, database, display, text, security;
12
 * - selecting the main database;
13
 * - include of language files.
14
 *
15
 * @package chamilo.include
16
 *
17
 * @todo remove the code that displays the button that links to the install page
18
 * but use a redirect immediately. By doing so the $alreadyInstalled variable can be removed.
19
 */
20
define('SHOW_ERROR_CODES', false);
21
22
// Include the libraries that are necessary everywhere
23
require_once __DIR__.'/../../vendor/autoload.php';
24
require_once __DIR__.'/../../app/AppKernel.php';
25
26
$kernel = new AppKernel('', '');
27
28
// Determine the directory path where this current file lies.
29
// This path will be useful to include the other initialisation files.
30
$includePath = __DIR__;
31
32
// Include the main Chamilo platform configuration file.
33
34
$alreadyInstalled = false;
35
if (file_exists($kernel->getConfigurationFile())) {
36
    require_once $kernel->getConfigurationFile();
37
    $alreadyInstalled = true;
38
    // Recalculate a system absolute path symlinks insensible.
39
    $includePath = $_configuration['root_sys'].'main/inc/';
40
} else {
41
    $_configuration = [];
42
    //Redirects to the main/install/ page
43
    if (!$alreadyInstalled) {
44
        $global_error_code = 2;
45
        // The system has not been installed yet.
46
        require_once __DIR__.'/../inc/global_error_message.inc.php';
47
        exit();
48
    }
49
}
50
51
$kernel->setApi($_configuration);
52
53
// Ensure that _configuration is in the global scope before loading
54
// main_api.lib.php. This is particularly helpful for unit tests
55
if (!isset($GLOBALS['_configuration'])) {
56
    $GLOBALS['_configuration'] = $_configuration;
57
}
58
59
// Include the main Chamilo platform library file.
60
require_once $_configuration['root_sys'].'main/inc/lib/api.lib.php';
61
$passwordEncryption = api_get_configuration_value('password_encryption');
62
63
if ($passwordEncryption === 'bcrypt') {
64
    require_once __DIR__.'/../../vendor/ircmaxell/password-compat/lib/password.php';
65
}
66
67
// Check the PHP version
68
api_check_php_version($includePath.'/');
69
70
// Specification for usernames:
71
// 1. ASCII-letters, digits, "." (dot), "_" (underscore) are acceptable, 40 characters maximum length.
72
// 2. Empty username is formally valid, but it is reserved for the anonymous user.
73
// 3. Checking the login_is_email portal setting in order to accept 100 chars maximum
74
75
$defaultUserNameLength = 50;
76
if (api_get_setting('login_is_email') == 'true') {
77
    $defaultUserNameLength = 100;
78
}
79
define('USERNAME_MAX_LENGTH', $defaultUserNameLength);
80
81
// Fix bug in IIS that doesn't fill the $_SERVER['REQUEST_URI'].
82
api_request_uri();
83
84
// Set web proxy environment variables
85
foreach ([
86
             'proxy_settings/stream_context_create/https/proxy',
87
             'proxy_settings/stream_context_create/http/proxy',
88
             'proxy_settings/curl_setopt_array/CURLOPT_PROXY',
89
         ] as $path) {
90
    $value = api_get_configuration_sub_value($path);
91
    if (!empty($value) && is_string($value)) {
92
        // libcurl reads environment variable https_proxy: https://curl.haxx.se/libcurl/c/libcurl-env.html
93
        // \GuzzleHttp\Client::configureDefaults reads environment variable HTTPS_PROXY
94
        foreach (['https_proxy', 'http_proxy', 'HTTPS_PROXY', 'HTTP_PROXY'] as $envVar) {
95
            if (false === getenv($envVar)) {
96
                putenv("$envVar=$value");
97
            }
98
        }
99
        break;
100
    }
101
}
102
103
define('_MPDF_TEMP_PATH', __DIR__.'/../../app/cache/mpdf/');
104
define('_MPDF_TTFONTDATAPATH', __DIR__.'/../../app/cache/mpdf/');
105
106
// Include the libraries that are necessary everywhere
107
require_once __DIR__.'/../../vendor/autoload.php';
108
109
// Do not over-use this variable. It is only for this script's local use.
110
$libraryPath = __DIR__.'/lib/';
111
112
// @todo convert this libs in classes
113
require_once $libraryPath.'database.constants.inc.php';
114
require_once $libraryPath.'text.lib.php';
115
require_once $libraryPath.'array.lib.php';
116
require_once $libraryPath.'online.inc.php';
117
require_once $libraryPath.'banner.lib.php';
118
require_once $libraryPath.'fileManage.lib.php';
119
require_once $libraryPath.'fileUpload.lib.php';
120
require_once $libraryPath.'fileDisplay.lib.php';
121
require_once $libraryPath.'course_category.lib.php';
122
123
if (!is_dir(_MPDF_TEMP_PATH)) {
124
    mkdir(_MPDF_TEMP_PATH, api_get_permissions_for_new_directories(), true);
125
}
126
127
// Connect to the server database and select the main chamilo database.
128
// When $_configuration['db_persistent_connection'] is set, it is expected to be a boolean type.
129
/*$dbPersistConnection = api_get_configuration_value('db_persistent_connection');
130
// $_configuration['db_client_flags'] can be set in configuration.php to pass
131
// flags to the DB connection
132
$dbFlags = api_get_configuration_value('db_client_flags');
133
134
$params = array(
135
    'server' => $_configuration['db_host'],
136
    'username' => $_configuration['db_user'],
137
    'password' => $_configuration['db_password'],
138
    'persistent' => $dbPersistConnection,
139
    'client_flags' => $dbFlags,
140
);*/
141
142
// Doctrine ORM configuration
143
144
$dbParams = [
145
    'driver' => 'pdo_mysql',
146
    'host' => $_configuration['db_host'],
147
    'user' => $_configuration['db_user'],
148
    'password' => $_configuration['db_password'],
149
    'dbname' => $_configuration['main_database'],
150
    // Only relevant for pdo_sqlite, specifies the path to the SQLite database.
151
    'path' => isset($_configuration['db_path']) ? $_configuration['db_path'] : '',
152
    // Only relevant for pdo_mysql, pdo_pgsql, and pdo_oci/oci8,
153
    'port' => isset($_configuration['db_port']) ? $_configuration['db_port'] : '',
154
    'driverOptions' => isset($_configuration['db_client_flags']) && is_array($_configuration['db_client_flags']) ? $_configuration['db_client_flags'] : [],
155
];
156
157
try {
158
    $database = new \Database();
159
    $database->connect($dbParams);
160
} catch (Exception $e) {
161
    $global_error_code = 3;
162
    // The database server is not available or credentials are invalid.
163
    require $includePath.'/global_error_message.inc.php';
164
    exit();
165
}
166
167
/* RETRIEVING ALL THE CHAMILO CONFIG SETTINGS FOR MULTIPLE URLs FEATURE*/
168
if (!empty($_configuration['multiple_access_urls'])) {
169
    $_configuration['access_url'] = 1;
170
    $access_urls = api_get_access_urls();
171
    $root_rel = api_get_self();
172
    $root_rel = substr($root_rel, 1);
173
    $pos = strpos($root_rel, '/');
174
    $root_rel = substr($root_rel, 0, $pos);
175
    $protocol = 'http://';
176
    if (!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') {
177
        $protocol = 'https://';
178
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
179
        $protocol = 'https://';
180
    }
181
182
    //urls with subdomains (HTTP_HOST is preferred - see #6764)
183
    $request_url_root = '';
184
    if (empty($_SERVER['HTTP_HOST'])) {
185
        if (empty($_SERVER['SERVER_NAME'])) {
186
            $request_url_root = $protocol.'localhost/';
187
        } else {
188
            $request_url_root = $protocol.$_SERVER['SERVER_NAME'].'/';
189
        }
190
    } else {
191
        $request_url_root = $protocol.$_SERVER['HTTP_HOST'].'/';
192
    }
193
    //urls with subdirs
194
    $request_url_sub = $request_url_root.$root_rel.'/';
195
196
    // You can use subdirs as multi-urls, but in this case none of them can be
197
    // the root dir. The admin portal should be something like https://host/adm/
198
    // At this time, subdirs will still hold a share cookie, so not ideal yet
199
    // see #6510
200
    foreach ($access_urls as $details) {
201
        if ($request_url_sub == $details['url']) {
202
            $_configuration['access_url'] = $details['id'];
203
            break; //found one match with subdir, get out of foreach
204
        }
205
        // Didn't find any? Now try without subdirs
206
        if ($request_url_root == $details['url']) {
207
            $_configuration['access_url'] = $details['id'];
208
            break; //found one match, get out of foreach
209
        }
210
    }
211
} else {
212
    $_configuration['access_url'] = 1;
213
}
214
215
// Check if APCu is available. If so, store the value in $_configuration
216
if (extension_loaded('apcu')) {
217
    $apcEnabled = ini_get('apc.enabled');
218
    if (!empty($apcEnabled) && $apcEnabled != 'Off' && $apcEnabled != 'off') {
219
        $_configuration['apc'] = true;
220
        $_configuration['apc_prefix'] = $_configuration['main_database'].'_'.$_configuration['access_url'].'_';
221
    }
222
}
223
224
$charset = 'UTF-8';
225
226
// Enables the portability layer and configures PHP for UTF-8
227
\Patchwork\Utf8\Bootup::initAll();
228
229
// Start session after the internationalization library has been initialized.
230
ChamiloSession::start($alreadyInstalled);
231
232
// access_url == 1 is the default chamilo location
233
if ($_configuration['access_url'] != 1) {
234
    $url_info = api_get_access_url($_configuration['access_url']);
235
    if ($url_info['active'] == 1) {
236
        $settings_by_access = &api_get_settings(null, 'list', $_configuration['access_url'], 1);
237
        foreach ($settings_by_access as &$row) {
238
            if (empty($row['variable'])) {
239
                $row['variable'] = 0;
240
            }
241
            if (empty($row['subkey'])) {
242
                $row['subkey'] = 0;
243
            }
244
            if (empty($row['category'])) {
245
                $row['category'] = 0;
246
            }
247
            $settings_by_access_list[$row['variable']][$row['subkey']][$row['category']] = $row;
248
        }
249
    }
250
}
251
252
$result = &api_get_settings(null, 'list', 1);
253
foreach ($result as &$row) {
254
    if ($_configuration['access_url'] != 1) {
255
        if ($url_info['active'] == 1) {
256
            $var = empty($row['variable']) ? 0 : $row['variable'];
257
            $subkey = empty($row['subkey']) ? 0 : $row['subkey'];
258
            $category = empty($row['category']) ? 0 : $row['category'];
259
        }
260
261
        if ($row['access_url_changeable'] == 1 && $url_info['active'] == 1) {
262
            if (isset($settings_by_access_list[$var]) &&
263
                isset($settings_by_access_list[$var][$subkey]) &&
264
                $settings_by_access_list[$var][$subkey][$category]['selected_value'] != '') {
265
                if ($row['subkey'] == null) {
266
                    $_setting[$row['variable']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
267
                } else {
268
                    $_setting[$row['variable']][$row['subkey']] = $settings_by_access_list[$var][$subkey][$category]['selected_value'];
269
                }
270
            } else {
271
                if ($row['subkey'] == null) {
272
                    $_setting[$row['variable']] = $row['selected_value'];
273
                } else {
274
                    $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
275
                }
276
            }
277
        } else {
278
            if ($row['subkey'] == null) {
279
                $_setting[$row['variable']] = $row['selected_value'];
280
            } else {
281
                $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
282
            }
283
        }
284
    } else {
285
        if ($row['subkey'] == null) {
286
            $_setting[$row['variable']] = $row['selected_value'];
287
        } else {
288
            $_setting[$row['variable']][$row['subkey']] = $row['selected_value'];
289
        }
290
    }
291
}
292
293
$result = &api_get_settings('Plugins', 'list', $_configuration['access_url']);
294
$_plugins = [];
295
foreach ($result as &$row) {
0 ignored issues
show
Comprehensibility Bug introduced by
$row is overwriting a variable from outer foreach loop.
Loading history...
296
    $key = &$row['variable'];
297
    if (isset($_setting[$key]) && is_string($_setting[$key])) {
298
        $_setting[$key] = [];
299
    }
300
    if ($row['subkey'] == null) {
301
        $_setting[$key][] = $row['selected_value'];
302
        $_plugins[$key][] = $row['selected_value'];
303
    } else {
304
        $_setting[$key][$row['subkey']] = $row['selected_value'];
305
        $_plugins[$key][$row['subkey']] = $row['selected_value'];
306
    }
307
}
308
309
// Error reporting settings.
310
if (api_get_setting('server_type') == 'test') {
311
    ini_set('display_errors', '1');
312
    ini_set('html_errors', '1');
313
    error_reporting(-1);
314
315
    if (function_exists('opcache_reset')) {
316
        opcache_reset();
317
    }
318
} else {
319
    error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR);
320
}
321
322
ini_set('log_errors', '1');
323
324
// Load allowed tag definitions for kses and/or HTMLPurifier.
325
require_once $libraryPath.'formvalidator/Rule/allowed_tags.inc.php';
326
327
// Before we call local.inc.php, let's define a global $this_section variable
328
// which will then be usable from the banner and header scripts
329
$this_section = SECTION_GLOBAL;
330
331
// Including configuration files
332
$configurationFiles = [
333
    'mail.conf.php',
334
    'profile.conf.php',
335
    'course_info.conf.php',
336
    'add_course.conf.php',
337
    'events.conf.php',
338
    'auth.conf.php',
339
];
340
341
foreach ($configurationFiles as $file) {
342
    $file = api_get_path(CONFIGURATION_PATH).$file;
343
    if (file_exists($file)) {
344
        require_once $file;
345
    }
346
}
347
348
/*  LOAD LANGUAGE FILES SECTION */
349
350
// if we use the javascript version (without go button) we receive a get
351
// if we use the non-javascript version (with the go button) we receive a post
352
$user_language = '';
353
$browser_language = '';
354
355
// see #8149
356
if (!empty($_SESSION['user_language_choice'])) {
357
    $user_language = $_SESSION['user_language_choice'];
358
}
359
360
if (!empty($_GET['language'])) {
361
    $user_language = $_GET['language'];
362
}
363
364
if (!empty($_POST['language_list'])) {
365
    $user_language = str_replace('index.php?language=', '', $_POST['language_list']);
366
}
367
368
if (empty($user_language) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && !isset($_SESSION['_user'])) {
369
    $l = SubLanguageManager::getLanguageFromBrowserPreference($_SERVER['HTTP_ACCEPT_LANGUAGE']);
370
    if (!empty($l)) {
371
        $user_language = $browser_language = $l;
372
    }
373
}
374
375
// Include all files (first english and then current interface language)
376
$langpath = api_get_path(SYS_LANG_PATH);
377
378
/* This will only work if we are in the page to edit a sub_language */
379
if (isset($this_script) && $this_script == 'sub_language') {
380
    // getting the arrays of files i.e notification, trad4all, etc
381
    $language_files_to_load = SubLanguageManager:: get_lang_folder_files_list(
382
        api_get_path(SYS_LANG_PATH).'english',
383
        true
384
    );
385
    //getting parent info
386
    $parent_language = SubLanguageManager::get_all_information_of_language($_REQUEST['id']);
387
    //getting sub language info
388
    $sub_language = SubLanguageManager::get_all_information_of_language($_REQUEST['sub_language_id']);
389
390
    $english_language_array = $parent_language_array = $sub_language_array = [];
391
392
    foreach ($language_files_to_load as $language_file_item) {
393
        $lang_list_pre = array_keys($GLOBALS);
394
        //loading english
395
        $path = $langpath.'english/'.$language_file_item.'.inc.php';
396
        if (file_exists($path)) {
397
            include $path;
398
        }
399
400
        $lang_list_post = array_keys($GLOBALS);
401
        $lang_list_result = array_diff($lang_list_post, $lang_list_pre);
402
        unset($lang_list_pre);
403
404
        //  english language array
405
        $english_language_array[$language_file_item] = compact($lang_list_result);
406
407
        //cleaning the variables
408
        foreach ($lang_list_result as $item) {
409
            unset(${$item});
410
        }
411
        $parent_file = $langpath.$parent_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
412
413
        if (file_exists($parent_file) && is_file($parent_file)) {
414
            include_once $parent_file;
415
        }
416
        //  parent language array
417
        $parent_language_array[$language_file_item] = compact($lang_list_result);
418
419
        //cleaning the variables
420
        foreach ($lang_list_result as $item) {
421
            unset(${$item});
422
        }
423
424
        $sub_file = $langpath.$sub_language['dokeos_folder'].'/'.$language_file_item.'.inc.php';
425
        if (file_exists($sub_file) && is_file($sub_file)) {
426
            include $sub_file;
427
        }
428
429
        //  sub language array
430
        $sub_language_array[$language_file_item] = compact($lang_list_result);
431
432
        //cleaning the variables
433
        foreach ($lang_list_result as $item) {
434
            unset(${$item});
435
        }
436
    }
437
}
438
439
// Checking if we have a valid language. If not we set it to the platform language.
440
$valid_languages = api_get_languages();
441
442
if (!empty($valid_languages)) {
443
    if (!in_array($user_language, $valid_languages['folder'])) {
444
        $user_language = api_get_setting('platformLanguage');
445
    }
446
447
    $language_priority1 = api_get_setting('languagePriority1');
448
    $language_priority2 = api_get_setting('languagePriority2');
449
    $language_priority3 = api_get_setting('languagePriority3');
450
    $language_priority4 = api_get_setting('languagePriority4');
451
452
    if (isset($_GET['language']) ||
453
        (isset($_POST['language_list']) && !empty($_POST['language_list'])) ||
454
        !empty($browser_language)
455
    ) {
456
        $user_selected_language = $user_language; // $_GET['language']; or HTTP_ACCEPT_LANGUAGE
457
        $_SESSION['user_language_choice'] = $user_selected_language;
458
        $platformLanguage = $user_selected_language;
459
    }
460
461
    if (!empty($language_priority4) && api_get_language_from_type($language_priority4) !== false) {
462
        $language_interface = api_get_language_from_type($language_priority4);
463
    } else {
464
        $language_interface = api_get_setting('platformLanguage');
465
    }
466
467
    if (!empty($language_priority3) && api_get_language_from_type($language_priority3) !== false) {
468
        $language_interface = api_get_language_from_type($language_priority3);
469
    } else {
470
        if (isset($_SESSION['user_language_choice'])) {
471
            $language_interface = $_SESSION['user_language_choice'];
472
        }
473
    }
474
475
    if (!empty($language_priority2) && api_get_language_from_type($language_priority2) !== false) {
476
        $language_interface = api_get_language_from_type($language_priority2);
477
    } else {
478
        if (isset($_user['language'])) {
479
            $language_interface = $_user['language'];
480
        }
481
    }
482
483
    if (!empty($language_priority1) && api_get_language_from_type($language_priority1) !== false) {
484
        $language_interface = api_get_language_from_type($language_priority1);
485
    } else {
486
        if (isset($_course['language'])) {
487
            $language_interface = $_course['language'];
488
        }
489
    }
490
491
    // If language is set via browser ignore the priority
492
    if (isset($_GET['language'])) {
493
        $language_interface = $user_language;
494
    }
495
496
    // Load the user language, if user is entering in the terms and condition page
497
    if (isset($_SESSION['term_and_condition']) && isset($_SESSION['term_and_condition']['user_id'])) {
498
        $userTempId = $_SESSION['term_and_condition']['user_id'];
499
        $userTempInfo = api_get_user_info($userTempId);
500
        if (!empty($userTempInfo['language'])) {
501
            $language_interface = $userTempInfo['language'];
502
        }
503
    }
504
505
    $allow = api_get_configuration_value('show_language_selector_in_menu');
506
    // Overwrite all lang configs and use the menu language
507
    if ($allow) {
508
        if (isset($_SESSION['user_language_choice'])) {
509
            $userEntity = api_get_user_entity(api_get_user_id());
510
            if ($userEntity) {
511
                if (isset($_GET['language'])) {
512
                    $language_interface = $_SESSION['user_language_choice'];
513
                    $userEntity->setLanguage($language_interface);
514
                    Database::getManager()->merge($userEntity);
515
                    Database::getManager()->flush();
516
517
                    // Update cache
518
                    api_get_user_info(
519
                        api_get_user_id(),
520
                        true,
521
                        false,
522
                        true,
523
                        false,
524
                        true,
525
                        true
526
                    );
527
                    if (isset($_SESSION['_user'])) {
528
                        $_SESSION['_user']['language'] = $language_interface;
529
                    }
530
                }
531
                $language_interface = $_SESSION['user_language_choice'] = $userEntity->getLanguage();
532
            }
533
        } else {
534
            $userInfo = api_get_user_info();
535
            if (!empty($userInfo['language'])) {
536
                $_SESSION['user_language_choice'] = $userInfo['language'];
537
                $language_interface = $userInfo['language'];
538
            }
539
        }
540
    }
541
}
542
543
// Sometimes the variable $language_interface is changed
544
// temporarily for achieving translation in different language.
545
// We need to save the genuine value of this variable and
546
// to use it within the function get_lang(...).
547
$language_interface_initial_value = $language_interface;
548
549
/**
550
 * Include the trad4all language file.
551
 */
552
$languageFilesToLoad = api_get_language_files_to_load($language_interface);
553
554
foreach ($languageFilesToLoad as $languageFile) {
555
    include $languageFile;
556
}
557
558
// include the local (contextual) parameters of this course or section
559
require $includePath.'/local.inc.php';
560
561
// The global variable $text_dir has been defined in the language file trad4all.inc.php.
562
// For determining text direction correspondent to the current language
563
// we use now information from the internationalization library.
564
$text_dir = api_get_text_direction();
565
566
// ===== "who is logged in?" module section =====
567
568
// check and modify the date of user in the track.e.online table
569
if (!$x = strpos($_SERVER['PHP_SELF'], 'whoisonline.php')) {
570
    if (!empty($_user['user_id'])) {
571
        preventMultipleLogin($_user['user_id']);
572
        LoginCheck($_user['user_id']);
573
    }
574
}
575
576
// ===== end "who is logged in?" module section =====
577
578
// Update of the logout_date field in the table track_e_login
579
// (needed for the calculation of the total connection time)
580
if (!isset($_SESSION['login_as']) && isset($_user) && isset($_user["user_id"])) {
581
    // if $_SESSION['login_as'] is set, then the user is an admin logged as the user
582
    Tracking::updateUserLastLogin($_user["user_id"]);
583
}
584
585
// Add language_measure_frequency to your main/inc/conf/configuration.php in
586
// order to generate language variables frequency measurements (you can then
587
// see them through main/cron/lang/langstats.php)
588
// The langstat object will then be used in the get_lang() function.
589
// This block can be removed to speed things up a bit as it should only ever
590
// be used in development versions.
591
if (isset($_configuration['language_measure_frequency']) &&
592
    $_configuration['language_measure_frequency'] == 1
593
) {
594
    require_once api_get_path(SYS_CODE_PATH).'/cron/lang/langstats.class.php';
595
    $langstats = new langstats();
596
}
597
598
//Default quota for the course documents folder
599
$default_quota = api_get_setting('default_document_quotum');
600
//Just in case the setting is not correctly set
601
if (empty($default_quota)) {
602
    $default_quota = 100000000;
603
}
604
605
define('DEFAULT_DOCUMENT_QUOTA', $default_quota);
606
// Forcing PclZip library to use a custom temporary folder.
607
define('PCLZIP_TEMPORARY_DIR', api_get_path(SYS_ARCHIVE_PATH));
608
609
// Create web/build/main.js
610
$webBuildPath = api_get_path(SYS_PUBLIC_PATH).'build/';
611
if (!is_dir($webBuildPath)) {
612
    if (!mkdir($webBuildPath, api_get_permissions_for_new_directories())) {
613
        error_log(
614
            'Error: '.$webBuildPath.' could not be written. Please check permissions.'
615
        );
616
    }
617
}
618
619
// Load template layout/main.js.tpl and save it into web/build/main.js
620
$file = $webBuildPath.'main.js';
621
if (!empty($language_interface)) {
622
    $file = $webBuildPath.'main.'.$language_interface.'.js';
623
}
624
625
// if portal is in test mode always generate the file
626
if (!file_exists($file) || api_get_setting('server_type') === 'test') {
627
    $template = new Template();
628
    $template->assign('quiz_markers_rolls_js', ChamiloApi::getQuizMarkersRollsJS());
629
    // Force use of default to avoid problems
630
    $tpl = 'default/layout/main.js.tpl';
631
    $contents = $template->fetch($tpl);
632
    if (is_writable($webBuildPath)) {
633
        file_put_contents($file, $contents);
634
    } else {
635
        error_log(
636
            'Error: '.$file.' could not be written. Please check permissions. The web server must be able to write there.'
637
        );
638
    }
639
}
640