1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2022-2023 Rafael San José Tovar <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This program is free software; you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU General Public License as published by |
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Alxarafe\Controllers; |
20
|
|
|
|
21
|
|
|
use Alxarafe\Core\Base\BasicController; |
22
|
|
|
use Alxarafe\Core\Singletons\Config; |
23
|
|
|
use Alxarafe\Core\Singletons\FlashMessages; |
24
|
|
|
use Alxarafe\Core\Singletons\Render; |
25
|
|
|
use Alxarafe\Core\Singletons\Translator; |
26
|
|
|
use Alxarafe\Database\DB; |
27
|
|
|
use Alxarafe\Database\Engine; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Controller for editing database and skin settings |
31
|
|
|
* |
32
|
|
|
* @package Alxarafe\Controllers |
33
|
|
|
*/ |
34
|
|
|
class EditConfig extends BasicController |
35
|
|
|
{ |
36
|
|
|
public $language; |
37
|
|
|
|
38
|
|
|
public $checkDebug; |
39
|
|
|
|
40
|
|
|
public function main(): void |
41
|
|
|
{ |
42
|
|
|
$this->dbEngines = Engine::getEngines(); |
|
|
|
|
43
|
|
|
$this->dbEngineName = Config::getVar('database', 'main', 'dbEngineName') ?? $this->dbEngines[0] ?? ''; |
|
|
|
|
44
|
|
|
|
45
|
|
|
$this->skins = Render::getSkins(); |
|
|
|
|
46
|
|
|
$this->skin = Config::getVar('templaterender', 'main', 'skin') ?? $this->skins[0] ?? ''; |
|
|
|
|
47
|
|
|
|
48
|
|
|
$this->checkDebug = Config::getVar('constants', 'boolean', 'DEBUG') ?? false; |
49
|
|
|
|
50
|
|
|
$this->languages = Translator::getAvailableLanguages(); |
|
|
|
|
51
|
|
|
$this->language = Config::getVar('translator', 'main', 'language') ?? key($this->languages) ?? 'es'; |
52
|
|
|
|
53
|
|
|
$this->dbConfig['dbUser'] = Config::getVar('database', 'main', 'dbUser') ?? 'root'; |
|
|
|
|
54
|
|
|
$this->dbConfig['dbPass'] = Config::getVar('database', 'main', 'dbPass') ?? ''; |
55
|
|
|
$this->dbConfig['dbName'] = Config::getVar('database', 'main', 'dbName') ?? 'alxarafe'; |
56
|
|
|
$this->dbConfig['dbHost'] = Config::getVar('database', 'main', 'dbHost') ?? 'localhost'; |
57
|
|
|
$this->dbConfig['dbPrefix'] = Config::getVar('database', 'main', 'dbPrefix') ?? 'tc_'; |
58
|
|
|
$this->dbConfig['dbPort'] = Config::getVar('database', 'main', 'dbPort') ?? ''; |
59
|
|
|
|
60
|
|
|
parent::main(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Save the form changes in the configuration file |
65
|
|
|
* |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
public function doSave(): bool |
69
|
|
|
{ |
70
|
|
|
Config::setVar('constants', 'boolean', 'DEBUG', isset($_POST['debug'])); |
|
|
|
|
71
|
|
|
Config::setVar('translator', 'main', 'language', $_POST['language'] ?? 'en'); |
72
|
|
|
Config::setVar('templaterender', 'main', 'skin', $_POST['skin'] ?? 'default'); |
73
|
|
|
Config::setVar('database', 'main', 'dbEngineName', $_POST['dbEngineName'] ?? ''); |
74
|
|
|
Config::setVar('database', 'main', 'dbUser', $_POST['dbUser'] ?? ''); |
75
|
|
|
Config::setVar('database', 'main', 'dbPass', $_POST['dbPass'] ?? ''); |
76
|
|
|
Config::setVar('database', 'main', 'dbName', $_POST['dbName'] ?? ''); |
77
|
|
|
Config::setVar('database', 'main', 'dbHost', $_POST['dbHost'] ?? ''); |
78
|
|
|
Config::setVar('database', 'main', 'dbPort', $_POST['dbPort'] ?? ''); |
79
|
|
|
Config::setVar('database', 'main', 'dbPrefix', $_POST['dbPrefix'] ?? ''); |
80
|
|
|
|
81
|
|
|
$result = DB::connectToDatabase(); |
82
|
|
|
if (!$result) { |
83
|
|
|
FlashMessages::setError('database_not_found', 'next'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$result = Config::saveConfigFile(); |
87
|
|
|
if ($result) { |
88
|
|
|
FlashMessages::setSuccess('saved', 'next'); |
89
|
|
|
header('location: ' . self::url('Main', 'EditConfig')); |
90
|
|
|
die(); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $result; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setTemplate(): string |
97
|
|
|
{ |
98
|
|
|
return 'config'; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|