|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright (c) 2018 Justin Kuenzel (jukusoft.com) |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Project: RocketCMS |
|
22
|
|
|
* License: Apache 2.0 license |
|
23
|
|
|
* User: Justin |
|
24
|
|
|
* Date: 28.08.2018 |
|
25
|
|
|
* Time: 17:04 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
class SettingsPage extends PageType { |
|
29
|
|
|
|
|
30
|
|
|
public function getContent(): string { |
|
31
|
|
|
$template = new DwooTemplate("pages/settings"); |
|
32
|
|
|
|
|
33
|
|
|
$template->assign("form_action", DomainUtils::generateURL("admin/settings", array("option" => "save"))); |
|
34
|
|
|
$template->assign("content", ""); |
|
35
|
|
|
|
|
36
|
|
|
$categories = array(); |
|
37
|
|
|
|
|
38
|
|
|
$all_settings_by_category = Settings::listAllSettingsByCategory(); |
|
39
|
|
|
|
|
40
|
|
|
$save = false; |
|
|
|
|
|
|
41
|
|
|
$save_success = true; |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
if (isset($_REQUEST['option']) && $_REQUEST['option'] == "save") { |
|
44
|
|
|
$save = true; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
foreach (SettingsCategory::listAllCategories() as $category) { |
|
48
|
|
|
$category = SettingsCategory::cast($category); |
|
49
|
|
|
|
|
50
|
|
|
$settings = array(); |
|
51
|
|
|
|
|
52
|
|
|
if (isset($all_settings_by_category[$category->getCategory()])) { |
|
53
|
|
|
//list settings |
|
54
|
|
|
$rows = $all_settings_by_category[$category->getCategory()]; |
|
55
|
|
|
|
|
56
|
|
|
foreach ($rows as $key=>$row) { |
|
57
|
|
|
$datatype = $row['datatype']; |
|
58
|
|
|
$datatype_params = unserialize($row['datatype_params']); |
|
59
|
|
|
|
|
60
|
|
|
$obj = new $datatype(); |
|
61
|
|
|
|
|
62
|
|
|
if (!($obj instanceof DataType_Base)) { |
|
63
|
|
|
throw new IllegalArgumentException("obj of class name '" . $datatype . "' has to be an instance of DataType_Base."); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
//load instance |
|
67
|
|
|
$obj->load($row, $datatype_params); |
|
68
|
|
|
|
|
69
|
|
|
//try to validate |
|
70
|
|
|
if (!$obj->val()) { |
|
71
|
|
|
$save_success = false; |
|
72
|
|
|
} else { |
|
73
|
|
|
//save object |
|
74
|
|
|
$obj->save(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$settings[] = array( |
|
78
|
|
|
'title' => Translator::translateTitle($row['title']), |
|
79
|
|
|
'description' => Translator::translateTitle($row['description']), |
|
80
|
|
|
'code' => $obj->getFormCode() |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$categories[] = array( |
|
86
|
|
|
'title' => $category->getTitle(), |
|
87
|
|
|
'settings' => $settings |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
Settings::saveAsync(); |
|
92
|
|
|
|
|
93
|
|
|
$template->assign("categories", $categories); |
|
94
|
|
|
|
|
95
|
|
|
return $template->getCode(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function listRequiredPermissions(): array { |
|
99
|
|
|
return array("can_see_global_settings", "can_edit_global_settings"); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
?> |
|
|
|
|
|
|
105
|
|
|
|