Passed
Push — master ( f91339...53c9fd )
by Angel Fernando Quiroz
08:24
created

getEncoreAssetFromManifest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 17
rs 10
c 1
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
use Chamilo\CoreBundle\Framework\Container;
6
use Chamilo\Kernel;
7
use Symfony\Bundle\FrameworkBundle\Console\Application;
8
use Symfony\Component\Console\Input\ArrayInput;
9
use Symfony\Component\Console\Output\ConsoleOutput;
10
use Symfony\Component\Dotenv\Dotenv;
11
use Symfony\Component\ErrorHandler\Debug;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Session\Session as HttpSession;
14
use Symfony\Component\Translation\Loader\PoFileLoader;
15
use Symfony\Component\Translation\Translator;
16
17
/**
18
 * Chamilo installation.
19
 *
20
 * As seen from the user, the installation proceeds in 6 steps.
21
 * The user is presented with several pages where he/she has to make choices
22
 * and/or fill in data.
23
 *
24
 * The aim is, as always, to have good default settings and suggestions.
25
 *
26
 * @todo reduce high level of duplication in this code
27
 * @todo (busy) organise code into functions
28
 */
29
$originalDisplayErrors = ini_get('display_errors');
30
$originalMemoryLimit = ini_get('memory_limit');
31
32
ini_set('display_errors', '1');
33
ini_set('log_errors', '1');
34
ini_set('memory_limit', -1);
35
ini_set('max_execution_time', 0);
36
error_reporting(-1);
37
38
require_once __DIR__.'/../../../vendor/autoload.php';
39
40
define('SYSTEM_INSTALLATION', 1);
41
define('INSTALL_TYPE_UPDATE', 'update');
42
define('FORM_FIELD_DISPLAY_LENGTH', 40);
43
define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
44
define('MAX_FORM_FIELD_LENGTH', 80);
45
46
api_check_php_version();
47
ob_implicit_flush();
48
Debug::enable();
49
50
// Create .env file
51
/*$envFile = api_get_path(SYMFONY_SYS_PATH).'.env';
52
if (file_exists($envFile)) {
53
    echo "Chamilo is already installed. File $envFile exists.";
54
    exit;
55
}*/
56
57
// Defaults settings
58
putenv('APP_LOCALE=en_US');
59
putenv('APP_ENCRYPT_METHOD="bcrypt"');
60
putenv('DATABASE_HOST=');
61
putenv('DATABASE_PORT=');
62
putenv('DATABASE_NAME=');
63
putenv('DATABASE_USER=');
64
putenv('DATABASE_PASSWORD=');
65
putenv('APP_ENV=dev');
66
putenv('APP_DEBUG=1');
67
68
session_start();
69
70
Container::$session = new HttpSession();
71
72
require_once 'install.lib.php';
73
$installationLanguage = 'en_US';
74
75
$httpRequest = Request::createFromGlobals();
76
77
if ($httpRequest->request->get('language_list')) {
78
    $search = ['../', '\\0'];
79
    $installationLanguage = str_replace($search, '', urldecode($httpRequest->request->get('language_list')));
80
    ChamiloSession::write('install_language', $installationLanguage);
81
} elseif (ChamiloSession::has('install_language')) {
82
    $installationLanguage = ChamiloSession::read('install_language');
83
} else {
84
    $tempLanguage = $httpRequest->getPreferredLanguage();
85
    if ($tempLanguage) {
86
        $installationLanguage = $tempLanguage;
87
    }
88
}
89
90
// Set translation
91
$translator = new Translator($installationLanguage);
92
$translator->addLoader('po', new PoFileLoader());
93
Container::$translator = $translator;
94
95
// The function api_get_setting() might be called within the installation scripts.
96
// We need to provide some limited support for it through initialization of the
97
// global array-type variable $_setting.
98
$_setting = [
99
    'platform_charset' => 'UTF-8',
100
    'server_type' => 'production', // 'production' | 'test'
101
    'permissions_for_new_directories' => '0770',
102
    'permissions_for_new_files' => '0660',
103
    'stylesheets' => 'chamilo',
104
];
105
106
$encryptPassForm = 'bcrypt';
107
$urlAppendPath = '';
108
$urlForm = '';
109
$pathForm = '';
110
$emailForm = '';
111
$dbHostForm = 'localhost';
112
$dbUsernameForm = 'root';
113
$dbPassForm = '';
114
$dbNameForm = 'chamilo';
115
$dbPortForm = 3306;
116
$allowSelfReg = 'approval';
117
$allowSelfRegProf = 1;
118
$adminLastName = get_lang('Doe');
119
$adminFirstName = get_lang('John');
120
$loginForm = 'admin';
121
$passForm = '';
122
$institutionUrlForm = 'https://chamilo.org';
123
$languageForm = $installationLanguage;
124
$campusForm = 'My campus';
125
$educationForm = 'Albert Einstein';
126
$adminPhoneForm = '(000) 001 02 03';
127
$institutionForm = 'My Organisation';
128
$session_lifetime = 360000;
129
$installationGuideLink = '../../documentation/installation_guide.html';
130
131
// Setting the error reporting levels.
132
error_reporting(E_ALL);
133
134
// Upgrading from any subversion of 1.11.x
135
$upgradeFromVersion = [
136
    '1.11.0',
137
    '1.11.1',
138
    '1.11.2',
139
    '1.11.4',
140
    '1.11.6',
141
    '1.11.8',
142
    '1.11.10',
143
    '1.11.11',
144
    '1.11.12',
145
    '1.11.14',
146
    '1.11.16',
147
    '1.11.18',
148
    '1.11.20',
149
    '1.11.22',
150
    '1.11.24',
151
    '1.11.26',
152
    '1.11.28',
153
];
154
155
$my_old_version = '';
156
if (empty($tmp_version)) {
157
    $tmp_version = get_config_param('system_version');
158
}
159
160
if (!empty($_POST['old_version'])) {
161
    $my_old_version = $_POST['old_version'];
162
} elseif (!empty($tmp_version)) {
163
    $my_old_version = $tmp_version;
164
}
165
166
$versionData = require __DIR__.'/version.php';
167
$new_version = $versionData['new_version'];
168
169
// A protection measure for already installed systems.
170
/*if (isAlreadyInstalledSystem()) {
171
    echo 'Portal already installed';
172
    exit;
173
}*/
174
175
/* STEP 1 : INITIALIZES FORM VARIABLES IF IT IS THE FIRST VISIT */
176
$badUpdatePath = false;
177
$emptyUpdatePath = true;
178
$proposedUpdatePath = '';
179
180
if (!empty($_POST['updatePath'])) {
181
    $proposedUpdatePath = $_POST['updatePath'];
182
}
183
184
$checkMigrationStatus = [];
185
$isUpdateAvailable = isUpdateAvailable();
186
if (isset($_POST['step2_install']) || isset($_POST['step2_update_8']) || isset($_POST['step2_update_6'])) {
187
    if (isset($_POST['step2_install'])) {
188
        $installType = 'new';
189
        $_POST['step2'] = 1;
190
    } else {
191
        $installType = 'update';
192
        if (isset($_POST['step2_update_8'])) {
193
            $emptyUpdatePath = false;
194
            $proposedUpdatePath = api_add_trailing_slash(empty($_POST['updatePath']) ? api_get_path(SYMFONY_SYS_PATH) : $_POST['updatePath']);
195
196
            if (file_exists($proposedUpdatePath)) {
197
                if (in_array($my_old_version, $upgradeFromVersion)) {
198
                    $_POST['step2'] = 1;
199
                } else {
200
                    $badUpdatePath = true;
201
                }
202
            } else {
203
                $badUpdatePath = true;
204
            }
205
        }
206
    }
207
} elseif (isset($_POST['step1'])) {
208
    $_POST['updatePath'] = '';
209
    $installType = $_GET['installType'] ?? '';
210
    $updateFromConfigFile = '';
211
    unset($_GET['running']);
212
} else {
213
    $installType = $_GET['installType'] ?? '';
214
    $updateFromConfigFile = $_GET['updateFromConfigFile'] ?? false;
215
}
216
217
$showEmailNotCheckedToStudent = 1;
218
$userMailCanBeEmpty = null;
219
$checkEmailByHashSent = null;
220
221
if (!isset($_GET['running'])) {
222
    // Extract the path to append to the url if Chamilo is not installed on the web root directory.
223
    $urlAppendPath = api_remove_trailing_slash(api_get_path(REL_PATH));
224
    $urlForm = api_get_path(WEB_PATH);
225
    $pathForm = api_get_path(SYS_PATH);
226
    $emailForm = 'webmaster@localhost';
227
    if (!empty($_SERVER['SERVER_ADMIN'])) {
228
        $emailForm = $_SERVER['SERVER_ADMIN'];
229
    }
230
    $email_parts = explode('@', $emailForm);
231
    if (isset($email_parts[1]) && 'localhost' === $email_parts[1]) {
232
        $emailForm .= '.localdomain';
233
    }
234
235
    $loginForm = 'admin';
236
    $passForm = api_generate_password(12, false);
237
    $institutionUrlForm = 'https://chamilo.org';
238
    $checkEmailByHashSent = 0;
239
    $userMailCanBeEmpty = 1;
240
    $allowSelfReg = 'approval';
241
    $allowSelfRegProf = 1; //by default, a user can register as teacher (but moderation might be in place)
242
    if (!empty($_GET['profile'])) {
243
        $installationProfile = api_htmlentities($_GET['profile'], ENT_QUOTES);
244
    }
245
} else {
246
    foreach ($_POST as $key => $val) {
247
        if (is_string($val)) {
248
            $val = trim($val);
249
            $_POST[$key] = $val;
250
        } elseif (is_array($val)) {
251
            foreach ($val as $key2 => $val2) {
252
                $val2 = trim($val2);
253
                $_POST[$key][$key2] = $val2;
254
            }
255
        }
256
        $GLOBALS[$key] = $_POST[$key];
257
    }
258
}
259
260
/* NEXT STEPS IMPLEMENTATION */
261
$total_steps = 7;
262
$current_step = 1;
263
if (!$_POST) {
264
    $current_step = 1;
265
} elseif ($httpRequest->request->get('language_list') || !empty($_POST['step1']) || ((!empty($_POST['step2_update_8']) || (!empty($_POST['step2_update_6']))) && ($emptyUpdatePath || $badUpdatePath))) {
266
    $current_step = 2;
267
} elseif (!empty($_POST['step2']) || (!empty($_POST['step2_update_8']) || (!empty($_POST['step2_update_6'])))) {
268
    $current_step = 3;
269
} elseif (!empty($_POST['step3'])) {
270
    $current_step = 4;
271
} elseif (!empty($_POST['step4'])) {
272
    $current_step = 5;
273
} elseif (!empty($_POST['step5'])) {
274
    $current_step = 6;
275
} elseif (isset($_POST['step6'])) {
276
    $current_step = 7;
277
}
278
279
error_log("Step: $current_step");
280
281
if (empty($installationProfile)) {
282
    $installationProfile = '';
283
    if (!empty($_POST['installationProfile'])) {
284
        $installationProfile = api_htmlentities($_POST['installationProfile']);
285
    }
286
}
287
288
$institutionUrlFormResult = '';
289
$institutionUrlFormResult = api_htmlentities($institutionUrlForm, ENT_QUOTES);
290
291
$stepData = [];
292
293
if (isset($_POST['step2'])) {
294
    // STEP 3 : LICENSE
295
    $current_step = 3;
296
    $stepData = display_license_agreement();
297
} elseif (isset($_POST['step3'])) {
298
    $current_step = 4;
299
    // STEP 4 : MYSQL DATABASE SETTINGS
300
    $stepData = display_database_settings_form(
301
        $installType,
302
        $dbHostForm,
303
        $dbUsernameForm,
304
        $dbPassForm,
305
        $dbNameForm,
306
        $dbPortForm
307
    );
308
} elseif (isset($_POST['step4'])) {
309
    $current_step = 5;
310
    // STEP 5 : CONFIGURATION SETTINGS
311
    if ('update' === $installType) {
312
        // Create .env file
313
        $envFile = api_get_path(SYMFONY_SYS_PATH) . '.env';
314
        $distFile = api_get_path(SYMFONY_SYS_PATH) . '.env.dist';
315
        $params = [
316
            '{{DATABASE_HOST}}' => $dbHostForm,
317
            '{{DATABASE_PORT}}' => $dbPortForm,
318
            '{{DATABASE_NAME}}' => $dbNameForm,
319
            '{{DATABASE_USER}}' => $dbUsernameForm,
320
            '{{DATABASE_PASSWORD}}' => $dbPassForm,
321
            '{{APP_INSTALLED}}' => 1,
322
            '{{APP_ENCRYPT_METHOD}}' => $encryptPassForm,
323
            '{{APP_SECRET}}' => generateRandomToken(),
324
            '{{DB_MANAGER_ENABLED}}' => '0',
325
            '{{SOFTWARE_NAME}}' => 'Chamilo',
326
            '{{SOFTWARE_URL}}' => $institutionUrlForm,
327
            '{{DENY_DELETE_USERS}}' => '0',
328
            '{{HOSTING_TOTAL_SIZE_LIMIT}}' => '0',
329
            '{{THEME_FALLBACK}}' => 'chamilo',
330
            '{{PACKAGER}}' => 'chamilo',
331
            '{{DEFAULT_TEMPLATE}}' => 'default',
332
            '{{ADMIN_CHAMILO_ANNOUNCEMENTS_DISABLE}}' => '0',
333
        ];
334
        error_log('Update env file');
335
        updateEnvFile($distFile, $envFile, $params);
336
        (new Dotenv())->load($envFile);
337
338
        $db_name = $dbNameForm;
339
        connectToDatabase(
340
            $dbHostForm,
341
            $dbUsernameForm,
342
            $dbPassForm,
343
            $dbNameForm,
344
            $dbPortForm
345
        );
346
        $manager = Database::getManager();
347
348
        $tmp = get_config_param_from_db('platformLanguage');
349
        if (!empty($tmp)) {
350
            $languageForm = $tmp;
351
        }
352
353
        $tmp = get_config_param_from_db('emailAdministrator');
354
        if (!empty($tmp)) {
355
            $emailForm = $tmp;
356
        }
357
358
        $tmp = get_config_param_from_db('administratorName');
359
        if (!empty($tmp)) {
360
            $adminFirstName = $tmp;
361
        }
362
363
        $tmp = get_config_param_from_db('administratorSurname');
364
        if (!empty($tmp)) {
365
            $adminLastName = $tmp;
366
        }
367
368
        $tmp = get_config_param_from_db('administratorTelephone');
369
        if (!empty($tmp)) {
370
            $adminPhoneForm = $tmp;
371
        }
372
373
        $tmp = get_config_param_from_db('siteName');
374
        if (!empty($tmp)) {
375
            $campusForm = $tmp;
376
        }
377
378
        $tmp = get_config_param_from_db('Institution');
379
        if (!empty($tmp)) {
380
            $institutionForm = $tmp;
381
        }
382
383
        $tmp = get_config_param_from_db('InstitutionUrl');
384
        if (!empty($tmp)) {
385
            $institutionUrlForm = $tmp;
386
        }
387
388
        // For version 1.9
389
        $encryptPassForm = get_config_param('password_encryption');
390
        // Managing the $encryptPassForm
391
        if ('1' == $encryptPassForm) {
392
            $encryptPassForm = 'sha1';
393
        } elseif ('0' == $encryptPassForm) {
394
            $encryptPassForm = 'none';
395
        }
396
397
        $allowSelfReg = 'approval';
398
        $tmp = get_config_param_from_db('allow_registration');
399
        if (!empty($tmp)) {
400
            $allowSelfReg = $tmp;
401
        }
402
403
        $allowSelfRegProf = false;
404
        $tmp = get_config_param_from_db('allow_registration_as_teacher');
405
        if (!empty($tmp)) {
406
            $allowSelfRegProf = $tmp;
407
        }
408
    }
409
410
    $stepData = display_configuration_settings_form(
411
        $installType,
412
        $urlForm,
413
        $languageForm,
414
        $emailForm,
415
        $adminFirstName,
416
        $adminLastName,
417
        $adminPhoneForm,
418
        $campusForm,
419
        $institutionForm,
420
        $institutionUrlForm,
421
        $encryptPassForm,
422
        $allowSelfReg,
423
        $allowSelfRegProf,
424
        $loginForm,
425
        $passForm
426
    );
427
} elseif (isset($_POST['step5'])) {
428
    $current_step = 6;
429
    //STEP 6 : LAST CHECK BEFORE INSTALL
430
431
    if ('new' === $installType) {
432
        $stepData['loginForm'] = $loginForm;
433
        $stepData['passForm'] = $passForm;
434
    }
435
436
    $stepData['adminFirstName'] = $adminFirstName;
437
    $stepData['adminLastName'] = $adminLastName;
438
    $stepData['emailForm'] = $emailForm;
439
    $stepData['adminPhoneForm'] = $adminPhoneForm;
440
441
    $allowSelfRegistrationLiteral = match ($allowSelfReg) {
442
        'true' => get_lang('Yes'),
443
        'approval' => get_lang('Approval'),
444
        default => get_lang('No'),
445
    };
446
447
    if ('update' === $installType) {
448
        $urlForm = get_config_param('root_web');
449
    }
450
451
    $stepData['campusForm'] = $campusForm;
452
    $stepData['languageForm'] = $languageForm;
453
    $stepData['allowSelfRegistrationLiteral'] = $allowSelfRegistrationLiteral;
454
    $stepData['institutionForm'] = $institutionForm;
455
    $stepData['institutionUrlForm'] = $institutionUrlForm;
456
    $stepData['encryptPassForm'] = $encryptPassForm;
457
458
    if ($isUpdateAvailable) {
459
        $envFile = api_get_path(SYMFONY_SYS_PATH) . '.env';
460
        $dotenv = new Dotenv();
461
        $envFile = api_get_path(SYMFONY_SYS_PATH) . '.env';
462
        $dotenv->loadEnv($envFile);
463
        $stepData['dbHostForm'] = $_ENV['DATABASE_HOST'];
464
        $stepData['dbPortForm'] = $_ENV['DATABASE_PORT'];
465
        $stepData['dbUsernameForm'] = $_ENV['DATABASE_USER'];
466
        $stepData['dbPassForm'] = str_repeat('*', api_strlen($_ENV['DATABASE_PASSWORD']));
467
        $stepData['dbNameForm'] = $_ENV['DATABASE_NAME'];
468
    } else {
469
        $stepData['dbHostForm'] = $dbHostForm;
470
        $stepData['dbPortForm'] = $dbPortForm;
471
        $stepData['dbUsernameForm'] = $dbUsernameForm;
472
        $stepData['dbPassForm'] = str_repeat('*', api_strlen($dbPassForm));
473
        $stepData['dbNameForm'] = $dbNameForm;
474
    }
475
} elseif (isset($_POST['step6'])) {
476
    //STEP 6 : INSTALLATION PROCESS
477
    $current_step = 7;
478
479
    if ('update' === $installType) {
480
        // The migration process for updates has been moved to migrate.php and is now
481
        // handled via AJAX requests from Vue.js. This section of the code is no longer
482
        // necessary and has been removed to streamline the update process.
483
484
        error_log('Migration process moved to migrate.php');
485
        error_log('Upgrade 2.0.0 process concluded!  ('.date('Y-m-d H:i:s').')');
486
    } else {
487
        error_log('------------------------------');
488
        $start = date('Y-m-d H:i:s');
489
        error_log('Chamilo installation starts:  ('.$start.')');
490
        set_file_folder_permissions();
491
        error_log("connectToDatabase as user $dbUsernameForm");
492
493
        connectToDatabase(
494
            $dbHostForm,
495
            $dbUsernameForm,
496
            $dbPassForm,
497
            null,
498
            $dbPortForm
499
        );
500
        $manager = Database::getManager();
501
        $dbNameForm = preg_replace('/[^a-zA-Z0-9_\-]/', '', $dbNameForm);
502
503
        // Drop and create the database anyways
504
        error_log("Drop database $dbNameForm");
505
        $schemaManager = $manager->getConnection()->createSchemaManager();
506
507
        try {
508
            $schemaManager->dropDatabase($dbNameForm);
509
        } catch (\Doctrine\DBAL\Exception $e) {
510
            error_log("Database ".$dbNameForm." does not exists");
511
        }
512
513
        $schemaManager->createDatabase($dbNameForm);
514
515
        error_log("Connect to database $dbNameForm with user $dbUsernameForm");
516
        connectToDatabase(
517
            $dbHostForm,
518
            $dbUsernameForm,
519
            $dbPassForm,
520
            $dbNameForm,
521
            $dbPortForm
522
        );
523
524
        $manager = Database::getManager();
525
        // Create .env file
526
        $envFile = api_get_path(SYMFONY_SYS_PATH).'.env';
527
        $distFile = api_get_path(SYMFONY_SYS_PATH).'.env.dist';
528
529
        $params = [
530
            '{{DATABASE_HOST}}' => $dbHostForm,
531
            '{{DATABASE_PORT}}' => $dbPortForm,
532
            '{{DATABASE_NAME}}' => $dbNameForm,
533
            '{{DATABASE_USER}}' => $dbUsernameForm,
534
            '{{DATABASE_PASSWORD}}' => $dbPassForm,
535
            '{{APP_INSTALLED}}' => 1,
536
            '{{APP_ENCRYPT_METHOD}}' => $encryptPassForm,
537
            '{{APP_SECRET}}' => generateRandomToken(),
538
            '{{DB_MANAGER_ENABLED}}' => '0',
539
            '{{SOFTWARE_NAME}}' => 'Chamilo',
540
            '{{SOFTWARE_URL}}' => $institutionUrlForm,
541
            '{{DENY_DELETE_USERS}}' => '0',
542
            '{{HOSTING_TOTAL_SIZE_LIMIT}}' => '0',
543
            '{{THEME_FALLBACK}}' => 'chamilo',
544
            '{{PACKAGER}}' => 'chamilo',
545
            '{{DEFAULT_TEMPLATE}}' => 'default',
546
            '{{ADMIN_CHAMILO_ANNOUNCEMENTS_DISABLE}}' => '0',
547
        ];
548
549
        updateEnvFile($distFile, $envFile, $params);
550
        (new Dotenv())->load($envFile);
551
552
        error_log('Load kernel');
553
        // Load Symfony Kernel
554
        $kernel = new Kernel('dev', true);
555
        $application = new Application($kernel);
556
557
        // Create database
558
        error_log('Create database');
559
        $input = new ArrayInput([]);
560
        $command = $application->find('doctrine:schema:create');
561
        $result = $command->run($input, new ConsoleOutput());
562
563
        // No errors
564
        if (0 === $result) {
565
            $input = new ArrayInput([]);
566
            $input->setInteractive(false);
567
            $command = $application->find('doctrine:fixtures:load');
568
            $result = $command->run($input, new ConsoleOutput());
569
570
            error_log('Delete PHP Session');
571
            session_unset();
572
            $_SESSION = [];
573
            session_destroy();
574
            error_log('Boot kernel');
575
576
            // Boot kernel and get the doctrine from Symfony container
577
            $kernel->boot();
578
            $containerDatabase = $kernel->getContainer();
579
            $sysPath = api_get_path(SYMFONY_SYS_PATH);
580
581
            finishInstallationWithContainer(
582
                $containerDatabase,
583
                $sysPath,
584
                $encryptPassForm,
585
                $passForm,
586
                $adminLastName,
587
                $adminFirstName,
588
                $loginForm,
589
                $emailForm,
590
                $adminPhoneForm,
591
                $languageForm,
592
                $institutionForm,
593
                $institutionUrlForm,
594
                $campusForm,
595
                $allowSelfReg,
596
                $allowSelfRegProf,
597
                $installationProfile,
598
                $kernel
599
            );
600
            error_log('Finish installation');
601
        } else {
602
            error_log('ERROR during installation.');
603
        }
604
    }
605
} elseif (isset($_POST['step1']) || $badUpdatePath) {
606
    //STEP 1 : REQUIREMENTS
607
    //make sure that proposed path is set, shouldn't be necessary but...
608
    if (empty($proposedUpdatePath)) {
609
        $proposedUpdatePath = $_POST['updatePath'];
610
    }
611
612
    $stepData = display_requirements(
613
        $installType,
614
        $badUpdatePath,
615
        $proposedUpdatePath,
616
        $upgradeFromVersion
617
    );
618
} else {
619
    // This is the start screen.
620
    if (!empty($_GET['profile'])) {
621
        $installationProfile = api_htmlentities($_GET['profile'], ENT_QUOTES);
622
    }
623
624
    $stepData['installationProfile'] = $installationProfile;
625
}
626
627
if ($isUpdateAvailable) {
628
    $installType = 'update';
629
}
630
$installerData = [
631
    'poweredBy' => 'Powered by <a href="https://chamilo.org" target="_blank">Chamilo</a> &copy; '.date('Y'),
632
633
    'phpRequiredVersion' => REQUIRED_PHP_VERSION,
634
635
    'installType' => $installType,
636
637
    'badUpdatePath' => $badUpdatePath,
638
639
    'upgradeFromVersion' => $upgradeFromVersion,
640
641
    'langIso' => api_get_language_isocode(),
642
643
    'formAction' => api_get_self().'?'.http_build_query([
644
            'running' => 1,
645
            'installType' => $installType,
646
            'updateFromConfigFile' => $updateFromConfigFile,
647
        ]),
648
649
    'updatePath' => !$badUpdatePath ? api_htmlentities($proposedUpdatePath, ENT_QUOTES) : '',
650
    'urlAppendPath' => api_htmlentities($urlAppendPath, ENT_QUOTES),
651
    'pathForm' => api_htmlentities($pathForm, ENT_QUOTES),
652
    'urlForm' => api_htmlentities($urlForm, ENT_QUOTES),
653
    'dbHostForm' => api_htmlentities($dbHostForm, ENT_QUOTES),
654
    'dbPortForm' => api_htmlentities((string) $dbPortForm, ENT_QUOTES),
655
    'dbUsernameForm' => api_htmlentities($dbUsernameForm, ENT_QUOTES),
656
    'dbPassForm' => api_htmlentities($dbPassForm, ENT_QUOTES),
657
    'dbNameForm' => api_htmlentities($dbNameForm, ENT_QUOTES),
658
    'allowSelfReg' => api_htmlentities($allowSelfReg, ENT_QUOTES),
659
    'allowSelfRegProf' => api_htmlentities((string) $allowSelfRegProf, ENT_QUOTES),
660
    'emailForm' => api_htmlentities($emailForm, ENT_QUOTES),
661
    'adminLastName' => api_htmlentities($adminLastName, ENT_QUOTES),
662
    'adminFirstName' => api_htmlentities($adminFirstName, ENT_QUOTES),
663
    'adminPhoneForm' => api_htmlentities($adminPhoneForm, ENT_QUOTES),
664
    'loginForm' => api_htmlentities($loginForm, ENT_QUOTES),
665
    'passForm' => api_htmlentities($passForm, ENT_QUOTES),
666
    'languageForm' => api_htmlentities($languageForm, ENT_QUOTES),
667
    'campusForm' => api_htmlentities($campusForm, ENT_QUOTES),
668
    'educationForm' => api_htmlentities($educationForm, ENT_QUOTES),
669
    'institutionForm' => api_htmlentities($institutionForm, ENT_QUOTES),
670
    'institutionUrlForm' => $institutionUrlFormResult,
671
    'checkEmailByHashSent' => api_htmlentities((string) $checkEmailByHashSent, ENT_QUOTES),
672
    'showEmailNotCheckedToStudent' => api_htmlentities((string) $showEmailNotCheckedToStudent, ENT_QUOTES),
673
    'userMailCanBeEmpty' => api_htmlentities((string) $userMailCanBeEmpty, ENT_QUOTES),
674
    'encryptPassForm' => api_htmlentities($encryptPassForm, ENT_QUOTES),
675
    'session_lifetime' => api_htmlentities((string) $session_lifetime, ENT_QUOTES),
676
    'old_version' => api_htmlentities($my_old_version, ENT_QUOTES),
677
    'new_version' => api_htmlentities($new_version, ENT_QUOTES),
678
    'installationProfile' => api_htmlentities($installationProfile, ENT_QUOTES),
679
    'currentStep' => $current_step,
680
    'isUpdateAvailable' => $isUpdateAvailable,
681
    'checkMigrationStatus' => $checkMigrationStatus,
682
    'logUrl' => '/main/install/get_migration_status.php',
683
    'stepData' => $stepData,
684
];
685
686
function getEncoreAssetFromManifest(string $assetName): ?string
687
{
688
    $manifestFilePath = __DIR__.'/../../../public/build/manifest.json';
689
690
    if (!file_exists($manifestFilePath)) {
691
        return null;
692
    }
693
694
695
    $manifestPlain = file_get_contents($manifestFilePath);
696
    $manifestJson = json_decode($manifestPlain, true);
697
698
    if (isset($manifestJson[$assetName])) {
699
        return $manifestJson[$assetName];
700
    }
701
702
    return null;
703
}
704
?>
705
<!DOCTYPE html>
706
<html lang="<?php echo $installationLanguage ?>" class="no-js h-100">
707
<head>
708
    <title>
709
        &mdash; <?php echo $translator->trans('Chamilo installation').' &mdash; '.$translator->trans('Version').' '.$new_version; ?>
710
    </title>
711
    <meta charset="UTF-8">
712
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
713
    <link rel="stylesheet" href="<?php echo getEncoreAssetFromManifest('public/build/app.css'); ?>">
714
    <style>
715
        :root {
716
            --color-primary-base: 46 117 163;
717
            --color-primary-gradient: 36 77 103;
718
            --color-primary-button-text: 46 117 163;
719
            --color-primary-button-alternative-text: 255 255 255;
720
721
            --color-secondary-base: 243 126 47;
722
            --color-secondary-gradient: 224 100 16;
723
            --color-secondary-button-text: 255 255 255;
724
725
            --color-tertiary-base: 51 51 51;
726
            --color-tertiary-gradient: 0 0 0;
727
            --color-tertiary-button-text: 255 255 255;
728
729
            --color-success-base: 119 170 12;
730
            --color-success-gradient: 83 127 0;
731
            --color-success-button-text: 255 255 255;
732
733
            --color-info-base: 13 123 253;
734
            --color-info-gradient: 0 84 211;
735
            --color-info-button-text: 255 255 255;
736
737
            --color-warning-base: 245 206 1;
738
            --color-warning-gradient: 186 152 0;
739
            --color-warning-button-text: 0 0 0;
740
741
            --color-danger-base: 223 59 59;
742
            --color-danger-gradient: 180 0 21;
743
            --color-danger-button-text: 255 255 255;
744
745
            --color-form-base: 46 117 163;
746
        }
747
    </style>
748
    <link rel="stylesheet" href="<?php echo getEncoreAssetFromManifest('public/build/app.css'); ?>">
749
    <link rel="stylesheet" href="<?php echo getEncoreAssetFromManifest('public/build/vue.css'); ?>">
750
    <script type="text/javascript" src="<?php echo getEncoreAssetFromManifest('public/build/legacy_app.js'); ?>"></script>
751
</head>
752
<body class="flex min-h-screen p-2 md:px-16 md:py-8 xl:px-32 xl:py-16 bg-gradient-to-br from-primary to-primary-gradient">
753
<div id="app" class="m-auto"></div>
754
<script>
755
  var installerData = <?php echo json_encode($installerData) ?>;
756
</script>
757
<script type="text/javascript" src="<?php echo getEncoreAssetFromManifest('public/build/runtime.js'); ?>"></script>
758
<script type="text/javascript" src="<?php echo getEncoreAssetFromManifest('public/build/vue_installer.js'); ?>"></script>
759
</body>
760
</html>
761