forked from opendocman/opendocman
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Settings_class.php
197 lines (177 loc) · 6.09 KB
/
Settings_class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/*
Settings_class.php - Container for settings related info
Copyright (C) 2010-2014 Stephen Lawrence Jr.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
if (!defined('Settings_class')) {
define('Settings_class', 'true', false);
/**
* Class that handles the opendocman settings values
*
* @author Stephen J. Lawrence Jr.
*/
class Settings
{
protected $connection;
public function Settings(PDO $pdo)
{
$this->connection = $pdo;
}
/**
* Get value for a specific setting based on the key
* @param string $key
*/
public function get($key)
{
}
/**
* Save all the settings
* @param array $data Array of values to be saved ($key,$value)
* @return bool
*/
public function save($data)
{
foreach ($data as $key=>$value) {
$query = "
UPDATE
{$GLOBALS['CONFIG']['db_prefix']}settings
SET VALUE = :value
WHERE
name = :key
";
$stmt = $this->connection->prepare($query);
$stmt->execute(array(
':value' => $value,
':key' => $key
));
}
return true;
}
/**
* Load settings to an array
* return array
*/
public function load()
{
$query = "
SELECT
name,
value
FROM
{$GLOBALS['CONFIG']['db_prefix']}settings
";
$stmt = $this->connection->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll();
foreach ($result as $row) {
$GLOBALS['CONFIG'][$row['name']] = $row['value'];
}
}
/**
* Show the settings edit form
*/
public function edit()
{
$query = "SELECT * FROM {$GLOBALS['CONFIG']['db_prefix']}settings";
$stmt = $this->connection->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll();
$GLOBALS['smarty']->assign('themes', $this->getThemes());
$GLOBALS['smarty']->assign('languages', $this->getLanguages());
$GLOBALS['smarty']->assign('useridnums', $this->getUserIdNums());
$GLOBALS['smarty']->assign('settings_array', $result);
display_smarty_template('settings.tpl');
}
/**
* Validate a specific setting based on its validation type
* @param string $key The name of the setting to be tested
* @param string $value The value of the setting to be tested
*/
public function validate($key, $value)
{
// NOT IMPLEMENTED
}
/**
* This function will return an array of the possible theme names found in the /templates folder
* for use in the settings form
*/
public function getThemes()
{
$themes = $this->getFolders(ABSPATH . 'templates');
return $themes;
}
/**
* @return mixed
*/
public function getLanguages()
{
$languages = $this->getFolders(ABSPATH . 'includes/language');
return str_replace('.php', '', $languages);
}
/**
* @param string $path
* @return array
*/
public function getFolders($path = '.')
{
$file_list=array();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
// Filter out any other types of folders that might be in here
if ($file != 'layouts' && $file != 'views' && $file != "." && $file != ".." && $file != ".svn" && $file != 'README' && $file != 'sync.sh' && $file != 'common' && $file != 'DataTables') {
array_push($file_list, $file);
}
}
closedir($handle);
}
return $file_list;
}
/**
* Return an array of user names
* @return array
*/
public function getUserIdNums()
{
$query = "
SELECT
id,
username
FROM
{$GLOBALS['CONFIG']['db_prefix']}user
";
$stmt = $this->connection->prepare($query);
$stmt->execute();
$result = $stmt->fetchAll();
return $result;
}
public static function get_db_version($prefix = '')
{
global $pdo;
if(empty($prefix)) {
$prefix = !empty($_SESSION['db_prefix']) ? $_SESSION['db_prefix'] : $GLOBALS['CONFIG']['db_prefix'];
}
$query1 = "SHOW TABLES LIKE :table";
$stmt = $pdo->prepare($query1);
$stmt->execute(array(':table' => $prefix . 'odmsys'));
if ($stmt->rowCount() > 0) {
$query2 = "SELECT sys_value from {$prefix}odmsys WHERE sys_name='version'";
$stmt = $pdo->prepare($query2);
$stmt->execute();
$result_array = $stmt->fetch();
}
$db_version = (!empty($result_array['sys_value']) ? $result_array['sys_value'] : 'Unknown');
return $db_version;
}
}
}