19
19
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
21
21
defined('XIBO') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");
28
function __construct(database $db, user $user)
33
require_once('lib/data/setting.data.class.php');
22
require_once('lib/data/setting.data.class.php');
23
class adminDAO extends baseDAO {
36
25
function displayPage() {
38
27
// Set some information about the form
39
28
Theme::Set('form_id', 'SettingsForm');
40
Theme::Set('form_action', 'index.php?p=group&q=Delete');
41
Theme::Set('settings_help_button_url', HelpManager::Link('Content', 'Config'));
42
Theme::Set('settings_form', $this->display_settings());
29
Theme::Set('form_action', 'index.php?p=admin&q=Edit');
31
$libraryLimit = Config::GetSetting('LIBRARY_SIZE_LIMIT_KB');
33
// Get all of the settings in an array
34
$settings = Config::GetAll(NULL, array('userSee' => 1));
36
$currentCategory = '';
37
$catagories = array();
38
$formFields = array();
40
// Go through each setting, validate it and add it to the array
41
foreach ($settings as $setting) {
43
if ($currentCategory != $setting['cat']) {
44
$currentCategory = $setting['cat'];
45
$catagories[] = array('tabId' => $setting['cat'], 'tabName' => ucfirst($setting['cat']));
48
// Are there any options
50
if (!empty($setting['options'])) {
51
// Change to an id=>value array
52
foreach (explode('|', Kit::ValidateParam($setting['options'], _HTMLSTRING)) as $tempOption)
53
$options[] = array('id' => $tempOption, 'value' => $tempOption);
56
// Validate the current setting
57
if ($setting['type'] == 'checkbox' && isset($setting['value']))
58
$validated = $setting['value'];
59
else if (isset($setting['value']))
60
$validated = Kit::ValidateParam($setting['value'], $setting['type']);
62
$validated = $setting['default'];
64
// Time zone type requires special handling.
65
if ($setting['fieldType'] == 'timezone') {
66
$options = $this->TimeZoneDropDown($validated);
69
// Get a list of settings and assign them to the settings field
70
$formFields[] = array(
71
'name' => $setting['setting'],
72
'type' => $setting['type'],
73
'fieldType' => $setting['fieldType'],
74
'helpText' => $setting['helptext'],
75
'title' => $setting['title'],
76
'options' => $options,
77
'validation' => $setting['validation'],
78
'value' => $validated,
79
'enabled' => $setting['userChange'],
80
'catId' => $setting['cat'],
81
'cat' => ucfirst($setting['cat'])
85
Theme::Set('cats', $catagories);
86
Theme::Set('form_fields', $formFields);
88
// Provide some bandwidth and library information to the theme.
89
// Library Size in Bytes
90
$fileSize = $this->db->GetSingleValue('SELECT IFNULL(SUM(FileSize), 0) AS SumSize FROM media', 'SumSize', _INT);
91
$limitPcnt = ($libraryLimit > 0) ? (($fileSize / ($libraryLimit * 1024)) * 100) : '';
93
Theme::Set('library_info', $this->FormatByteSize($fileSize) . (($libraryLimit > 0) ? sprintf(__(' / %d %% of %s'), $limitPcnt, $this->FormatByteSize($libraryLimit * 1024)) : ''));
95
// Monthly bandwidth - optionally tested against limits
96
$xmdsLimit = Config::GetSetting('MONTHLY_XMDS_TRANSFER_LIMIT_KB');
97
$startOfMonth = strtotime(date('m').'/01/'.date('Y').' 00:00:00');
99
$sql = sprintf('SELECT IFNULL(SUM(Size), 0) AS BandwidthUsage FROM `bandwidth` WHERE Month > %d AND Month < %d', $startOfMonth, $startOfMonth + (86400 * 2));
100
$bandwidthUsage = $this->db->GetSingleValue($sql, 'BandwidthUsage', _INT);
101
$usagePcnt = ($xmdsLimit > 0) ? (((double)$bandwidthUsage / ($xmdsLimit * 1024)) * 100) : '';
103
Theme::Set('bandwidth_info', $this->FormatByteSize($bandwidthUsage) . (($xmdsLimit > 0) ? sprintf(__(' / %d %% of %s'), $usagePcnt, $this->FormatByteSize($xmdsLimit * 1024)) : ''));
44
106
// Render the Theme and output
45
107
Theme::Render('settings_page');
110
function actionMenu() {
114
if (Config::GetSetting('SETTING_IMPORT_ENABLED') == 1) {
116
'title' => __('Import'),
117
'class' => 'XiboFormButton',
119
'link' => 'index.php?p=admin&q=RestoreForm',
120
'help' => __('Import a database'),
125
// Always show export
127
'title' => __('Export'),
128
'class' => 'XiboFormButton',
130
'link' => 'index.php?p=admin&q=BackupForm',
131
'help' => __('Export a database'),
135
if (Config::GetSetting('SETTING_LIBRARY_TIDY_ENABLED') == 1) {
137
'title' => __('Tidy Library'),
138
'class' => 'XiboFormButton',
140
'link' => 'index.php?p=admin&q=TidyLibrary',
141
'help' => __('Run through the library and remove and unnecessary files'),
150
$response = new ResponseManager();
53
153
if (!Kit::CheckToken())
54
154
trigger_error(__('Sorry the form has expired. Please refresh.'), E_USER_ERROR);
56
$refer = Kit::GetParam('refer', _POST, _STRING);
57
$usertype = Kit::GetParam('usertype', _SESSION, _INT);
59
$ids = Kit::GetParam('id', _POST, _ARRAY);
60
$values = Kit::GetParam('value', _POST, _ARRAY);
66
setMessage(__("Only admin users are allowed to modify settings"));
70
// Get the SettingId for LIBRARY_LOCATION
71
$SQL = sprintf("SELECT settingid FROM setting WHERE setting = '%s'", 'LIBRARY_LOCATION');
73
if (!$result = $db->query($SQL))
75
trigger_error($db->error());
76
trigger_error(__('Cannot find the Library Location Setting - this is serious.'), E_USER_ERROR);
79
if ($db->num_rows($result) == 0)
81
trigger_error(__('Cannot find the Library Location Setting - this is serious.'), E_USER_ERROR);
84
$row = $db->get_row($result);
85
$librarySettingId = $row[0];
87
// Loop through and modify the settings
88
for ($i=0; $i<$size; $i++)
90
$value = Kit::ValidateParam($values[$i], _STRING);
93
// Is this the library location setting
94
if ($id == $librarySettingId)
96
// Check for a trailing slash and add it if its not there
97
$value = rtrim($value, '/') . '/';
99
// Attempt to add the directory specified
100
if (!file_exists($value . 'temp'))
102
// Make the directory with broad permissions recursively (so will add the whole path)
103
mkdir($value . 'temp', 0777, true);
106
if (!is_writable($value . 'temp'))
108
trigger_error(__('The Library Location you have picked is not writable'), E_USER_ERROR);
112
$SQL = sprintf("UPDATE setting SET value = '%s' WHERE settingid = %d ", $db->escape_string($value), $id);
114
if(!$db->query($SQL))
116
trigger_error($db->error());
117
trigger_error(__('Update of settings failed.'), E_USER_ERROR);
121
$response = new ResponseManager();
122
$response->SetFormSubmitResponse(__('Settings Updated'), false);
156
Kit::ClassLoader('setting');
157
$data = new Setting($this->db);
159
// Get all of the settings in an array
160
$settings = Config::GetAll(NULL, array('userChange' => 1, 'userSee' => 1));
162
// Go through each setting, validate it and add it to the array
163
foreach ($settings as $setting) {
164
// Check to see if we have a setting that matches in the provided POST vars.
165
$value = Kit::GetParam($setting['setting'], _POST, $setting['type'], (($setting['type'] == 'checkbox') ? NULL : $setting['default']));
167
// Check the library location setting
168
if ($setting['setting'] == 'LIBRARY_LOCATION') {
169
// Check for a trailing slash and add it if its not there
170
$value = rtrim($value, '/');
171
$value = rtrim($value, '\\') . DIRECTORY_SEPARATOR;
173
// Attempt to add the directory specified
174
if (!file_exists($value . 'temp'))
175
// Make the directory with broad permissions recursively (so will add the whole path)
176
mkdir($value . 'temp', 0777, true);
178
if (!is_writable($value . 'temp'))
179
trigger_error(__('The Library Location you have picked is not writeable'), E_USER_ERROR);
183
if (!$data->Edit($setting['setting'], $value))
184
trigger_error($data->GetErrorMessage(), E_USER_ERROR);
187
$response->SetFormSubmitResponse(__('Settings Updated'), false);
123
188
$response->Respond();
126
function display_settings()
129
$user =& $this->user;
131
$helpObject = new HelpManager($db, $user);
133
$helpButton = $helpObject->HelpButton("content/config/settings", true);
135
//one giant form, split into tabs
136
$form = '<form id="SettingsForm" method="post" class="XiboForm" action="index.php?p=admin&q=modify">' . Kit::Token();
140
//get all the tabs, ordered by catagory
141
$SQL = "SELECT DISTINCT cat FROM setting WHERE userChange = 1 ORDER BY cat";
143
if (!$results = $db->query($SQL))
145
trigger_error($db->error());
146
trigger_error(__("Can't get the setting catagories"), E_USER_ERROR);
149
while ($row = $db->get_row($results))
152
$ucat = ucfirst($cat);
153
$cat_tab = $cat."_tab";
155
// generate the li and a for this tab
156
$tabs .= "<li><a href='#$cat_tab'><span>$ucat</span><i class='icon-chevron-right pull-right'></i></a></li>";
158
// for each one, call display_cat to get the settings specific to that cat
159
$cat_page = $this->display_cat($cat);
168
$msgSave = __('Save');
169
$msgCategories = __('Categories');
174
<div class="well affix">
175
<ul class="nav nav-list ">
176
<li class="nav-header">$msgCategories</li>
186
//end the form and output
192
function display_cat($cat)
198
$title = ucfirst($cat);
199
$output .= '<h3>' . __($title) . ' ' . __('Settings') . '</h3>';
202
Firstly we want to individually get the user module
208
$SQL.= "SELECT settingid, setting, value, helptext FROM setting WHERE setting = 'userModule'";
210
if(!$results = $db->query($SQL))
212
trigger_error($db->error());
213
trigger_error(__('Can not get settings'), E_USER_ERROR);
216
$row = $db->get_row($results);
217
$settingid = Kit::ValidateParam($row[0], _INT);
218
$setting = Kit::ValidateParam($row[1], _STRING);
219
$setting = __($setting);
220
$value = Kit::ValidateParam($row[2], _STRING);
221
$helptext = Kit::ValidateParam($row[3], _HTMLSTRING);
228
// we need to make a drop down out of the files that match a string, in a directory
229
$files = scandir("modules/");
232
foreach ($files as $file)
235
if($file == $value) $selected = "selected";
237
if(preg_match("^module_user^", $file))
240
$select.= "<option value='$file' $selected>$file</option>";
245
<input type="hidden" name="id[]" value="$settingid">
246
<select name="value[]">
252
if ($cat == 'content')
254
$libraryLimit = Config::GetSetting('LIBRARY_SIZE_LIMIT_KB');
256
// Library Size in Bytes
257
$fileSize = $this->db->GetSingleValue('SELECT IFNULL(SUM(FileSize), 0) AS SumSize FROM media', 'SumSize', _INT);
258
$limitPcnt = ($libraryLimit > 0) ? (($fileSize / ($libraryLimit * 1024)) * 100) : '';
260
$output .= '<p>' . sprintf(__('You have %s of media in the library.'), $this->FormatByteSize($fileSize)) . (($libraryLimit > 0) ? sprintf(__(' This is %d %% of your %s limit.'), $limitPcnt, $this->FormatByteSize($libraryLimit * 1024)) : '') . '</p>';
262
// Monthly bandwidth - optionally tested against limits
263
$xmdsLimit = Config::GetSetting('MONTHLY_XMDS_TRANSFER_LIMIT_KB');
264
$startOfMonth = strtotime(date('m').'/01/'.date('Y').' 00:00:00');
266
$sql = sprintf('SELECT IFNULL(SUM(Size), 0) AS BandwidthUsage FROM `bandwidth` WHERE Month = %d', $startOfMonth);
267
$bandwidthUsage = $this->db->GetSingleValue($sql, 'BandwidthUsage', _INT);
269
Debug::LogEntry('audit', $sql);
271
$usagePcnt = ($xmdsLimit > 0) ? (($bandwidthUsage / ($xmdsLimit * 1024)) * 100) : '';
273
$output .= '<p>' . sprintf(__('You have used %s of bandwidth this month.'), $this->FormatByteSize($bandwidthUsage)) . (($xmdsLimit > 0) ? sprintf(__(' This is %d %% of your %s limit.'), $usagePcnt, $this->FormatByteSize($xmdsLimit * 1024)) : '') . '</p>';
276
if ($cat == 'general')
278
$output .= '<p>' . __('Import / Export Database') . '</p>';
280
if (Config::GetSetting('SETTING_IMPORT_ENABLED') == 'On')
281
$output .= '<button class="XiboFormButton" href="index.php?p=admin&q=RestoreForm">' . __('Import') . '</button>';
283
$output .= '<button class="XiboFormButton" href="index.php?p=admin&q=BackupForm">' . __('Export') . '</button>';
285
if (Config::GetSetting('SETTING_LIBRARY_TIDY_ENABLED') == 'On')
286
$output .= '<button class="XiboFormButton" href="index.php?p=admin&q=TidyLibrary">' . __('Tidy Library') . '</button>';
289
// Need to now get all the Misc settings
291
$SQL.= sprintf("SELECT settingid, setting, value, helptext FROM setting WHERE type = 'text' AND cat='%s' AND userChange = 1", $cat);
293
if (!$results = $db->query($SQL))
295
trigger_error($db->error());
296
trigger_error(__('Can not get settings'), E_USER_ERROR);
299
while($row = $db->get_row($results))
301
$settingid = Kit::ValidateParam($row[0], _INT);
302
$setting = Kit::ValidateParam($row[1], _STRING);
303
$value = Kit::ValidateParam($row[2], _STRING);
304
$helptext = Kit::ValidateParam($row[3], _HTMLSTRING);
309
<input type="hidden" name="id[]" value="$settingid">
310
<input type="text" name="value[]" value="$value">
312
if($setting == "mail_to")
314
$msgTestEmail = __('Test Email');
315
//show another form here, for test
317
<a id="test_email" href="index.php?p=admin&q=SendEmail" class="XiboFormButton">$msgTestEmail</a>
324
$SQL.= sprintf("SELECT settingid, setting, value, helptext, options FROM setting WHERE type = 'dropdown' AND cat='%s' AND userChange = 1", $db->escape_string($cat));
326
if (!$results = $db->query($SQL))
328
trigger_error($db->error());
329
trigger_error(__('Can not get settings'), E_USER_ERROR);
332
while($row = $db->get_row($results))
334
$settingid = Kit::ValidateParam($row[0], _INT);
335
$setting = Kit::ValidateParam($row[1], _STRING);
336
$value = Kit::ValidateParam($row[2], _STRING);
337
$helptext = Kit::ValidateParam($row[3], _HTMLSTRING);
338
$options = Kit::ValidateParam($row[4], _STRING);
342
$options = explode("|", $options);
343
foreach ($options as $option)
345
if($option == $value)
347
$select.="<option value='$option' selected>$option</option>";
351
$select.="<option value='$option'>$option</option>";
358
<input type="hidden" name="id[]" value="$settingid">
359
<select name="value[]">$select</select>
363
// Also deal with the timezone setting type
365
$SQL.= sprintf("SELECT settingid, setting, value, helptext FROM setting WHERE type = 'timezone' AND cat='%s' AND userChange = 1", $cat);
367
if (!$results = $db->query($SQL))
369
trigger_error($db->error());
370
trigger_error(__('Can not get settings'), E_USER_ERROR);
373
while($row = $db->get_row($results))
375
$settingid = Kit::ValidateParam($row[0], _INT);
376
$setting = Kit::ValidateParam($row[1], _STRING);
377
$selectedzone = Kit::ValidateParam($row[2], _STRING);
378
$helptext = Kit::ValidateParam($row[3], _HTMLSTRING);
379
$options = $this->TimeZoneIdentifiersList();
384
// Create a Zone array containing the timezones
385
// From: http://php.oregonstate.edu/manual/en/function.timezone-identifiers-list.php
386
foreach($options as $zone)
388
$zone = explode('/',$zone);
389
$zonen[$i]['continent'] = isset($zone[0]) ? $zone[0] : '';
390
$zonen[$i]['city'] = isset($zone[1]) ? $zone[1] : '';
391
$zonen[$i]['subcity'] = isset($zone[2]) ? $zone[2] : '';
398
foreach($zonen as $zone)
402
if($continent == 'Africa' || $continent == 'America' || $continent == 'Antarctica' || $continent == 'Arctic' || $continent == 'Asia' || $continent == 'Atlantic' || $continent == 'Australia' || $continent == 'Europe' || $continent == 'Indian' || $continent == 'Pacific' || $continent == 'General')
404
if(!isset($selectcontinent))
406
$structure .= '<optgroup label="'.$continent.'">'; // continent
408
elseif($selectcontinent != $continent)
410
$structure .= '</optgroup><optgroup label="'.$continent.'">'; // continent
413
if(isset($city) != '')
415
if (!empty($subcity) != '')
417
$city = $city . '/'. $subcity;
419
$structure .= "<option ".((($continent.'/'.$city)==$selectedzone)?'selected="selected "':'')." value=\"".($continent.'/'.$city)."\">".str_replace('_',' ',$city)."</option>"; //Timezone
423
if (!empty($subcity) != '')
425
$city = $city . '/'. $subcity;
427
$structure .= "<option ".(($continent==$selectedzone)?'selected="selected "':'')." value=\"".$continent."\">".$continent."</option>"; //Timezone
430
$selectcontinent = $continent;
433
$structure .= '</optgroup>';
440
<input type="hidden" name="id[]" value="$settingid">
441
<select name="value[]">$structure</select>
449
192
* Timezone functionality
452
private function TimeZoneIdentifiersList()
454
if (function_exists('timezone_identifiers_list'))
456
return timezone_identifiers_list();
195
private function TimeZoneIdentifiersList() {
197
if (function_exists('timezone_identifiers_list'))
198
return timezone_identifiers_list();
459
200
$list[] = 'Europe/London';
460
201
$list[] = 'America/New_York';
461
202
$list[] = 'Europe/Paris';