forked from emaijala/MLInvoice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_list.php
More file actions
218 lines (208 loc) · 6.74 KB
/
settings_list.php
File metadata and controls
218 lines (208 loc) · 6.74 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* Settings form
*
* PHP version 5
*
* Copyright (C) 2004-2008 Samu Reinikainen
* Copyright (C) 2010-2018 Ere Maijala
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category MLInvoice
* @package MLInvoice\Base
* @author Ere Maijala <ere@labs.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://labs.fi/mlinvoice.eng.php
*/
require_once 'sqlfuncs.php';
require_once 'miscfuncs.php';
require_once 'translator.php';
/**
* Create a list of settings
*
* @return void
*/
function createSettingsList()
{
if (!sesAdminAccess()) {
?>
<div class="form_container ui-widget-content">
<?php echo Translator::translate('NoAccess') . "\n"?>
</div>
<?php
return;
}
include 'settings_def.php';
$messages = '';
$blnSave = getPostOrQuery('saveact', false) ? true : false;
if ($blnSave) {
foreach ($arrSettings as $name => $elem) {
$type = $elem['type'];
$label = $elem['label'];
if ($type == 'LABEL') {
continue;
}
$newValue = getPost($name, null);
if (!isset($newValue) || $newValue === '') {
if (!$elem['allow_null']) {
$messages .= Translator::translate('ErrValueMissing')
. ": '" . Translator::translate($label) . "'<br>\n";
continue;
} else {
$newValue = '';
}
}
if (in_array($type, ['CURRENCY', 'PERCENT'])) {
$newValue = str_replace(
Translator::translate('DecimalSeparator'), '.', $newValue
);
}
if (in_array($type, ['CURRENCY', 'PERCENT', 'INT'])) {
$newValue = trim($newValue);
if (!is_numeric($newValue)) {
$messages .= Translator::translate('ErrInvalidValue')
. ": '" . Translator::translate($label) . "'<br>\n";
continue;
}
}
if (isset($elem['session']) && $elem['session']) {
$_SESSION[$name] = $newValue;
}
dbParamQuery('DELETE from {prefix}settings WHERE name=?', [$name]);
dbParamQuery(
'INSERT INTO {prefix}settings (name, value) VALUES (?, ?)',
[$name, $newValue]
);
}
}
?>
<div class="form_container ui-widget-content">
<?php if ($messages) {?>
<div class="ui-widget ui-state-error"><?php echo $messages?></div>
<?php }?>
<script>
<!--
$(document).ready(function() {
$('input[class~="hasCalendar"]').datepicker();
$('iframe[class~="resizable"]').load(function() {
var iframe = $(this);
var body = iframe.contents().find("body");
var newHeight = body.outerHeight(true) + 10;
// Leave room for calendar popup
if (newHeight < 250)
newHeight = 250;
iframe.css("height", newHeight + 'px');
body.css("overflow", "hidden");
});
$('#admin_form')
.find('input[type="text"],input[type="checkbox"],select,textarea')
.change(function() { $('.save_button').addClass('unsaved'); });
});
-->
</script>
<?php createSettingsListButtons()?>
<div class="form settings-list">
<form method="post" name="admin_form" id="admin_form">
<?php
foreach ($arrSettings as $name => $elem) {
$elemType = $elem['type'];
if ($elemType == 'LABEL') {
?>
<div class="sublabel ui-widget-header ui-state-default">
<?php echo Translator::translate($elem['label'])?>
</div>
<?php
continue;
}
$value = getPost($name, null);
if (!isset($value)) {
if (isset($elem['session']) && $elem['session']) {
$value = isset($_SESSION[$name]) ? $_SESSION[$name]
: (isset($elem['default'])
? condUtf8Decode($elem['default']) : '');
} else {
$value = getSetting($name);
}
if ($elemType == 'CURRENCY') {
$value = miscRound2Decim($value);
} elseif ($elemType == 'PERCENT') {
$value = miscRound2Decim($value, 1);
}
}
if ($elemType == 'CURRENCY' || $elemType == 'PERCENT') {
$elemType = 'INT';
}
$options = null;
if (isset($elem['options'])) {
$options = $elem['options'];
foreach ($options as &$option) {
$option = Translator::translate($option);
}
}
if ($elemType == 'CHECK') {
?>
<div class="field">
<?php
echo htmlFormElement(
$name, $elemType, $value, $elem['style'], '', 'MODIFY', '', '', [],
isset($elem['elem_attributes']) ? $elem['elem_attributes'] : '', $options
);
?>
<label for="<?php echo $name?>">
<?php echo Translator::translate($elem['label'])?>
</label>
</div>
<?php
} else {
?>
<div class="label">
<label for="<?php echo $name?>">
<?php echo Translator::translate($elem['label'])?>
</label>
</div>
<div class="field">
<?php
echo htmlFormElement(
$name, $elemType, $value, $elem['style'], '', 'MODIFY', '', '', [],
isset($elem['elem_attributes']) ? $elem['elem_attributes'] : '', $options
);
?>
</div>
<?php
}
}
?>
<input type="hidden" name="saveact" value="0">
<?php createSettingsListButtons()?>
</form>
</div>
</div>
<?php
}
/**
* Create buttons
*
* @return void
*/
function createSettingsListButtons()
{
?>
<div class="form_buttons">
<a class="actionlink ui-button ui-corner-all ui-widget save_button form-submit" href="#" data-set-field="saveact">
<?php echo Translator::translate('Save')?>
</a>
</div>
<?php
}