This repository has been archived by the owner on Feb 21, 2019. It is now read-only.
forked from emaijala/MLInvoice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings_list.php
184 lines (169 loc) · 6.22 KB
/
settings_list.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
<?php
/*******************************************************************************
MLInvoice: web-based invoicing application.
Copyright (C) 2010-2015 Ere Maijala
This program is free software. See attached LICENSE.
*******************************************************************************/
/*******************************************************************************
MLInvoice: web-pohjainen laskutusohjelma.
Copyright (C) 2010-2015 Ere Maijala
Tämä ohjelma on vapaa. Lue oheinen LICENSE.
*******************************************************************************/
require_once 'sqlfuncs.php';
require_once 'miscfuncs.php';
require_once 'localize.php';
function createSettingsList()
{
if (!sesAdminAccess()) {
?>
<div class="form_container ui-widget-content">
<?php echo $GLOBALS['locNoAccess'] . "\n"?>
</div>
<?php
return;
}
require 'settings_def.php';
$messages = '';
$blnSave = getPostRequest('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 .= $GLOBALS['locErrValueMissing'] . ": '$label'<br>\n";
continue;
} else {
$newValue = '';
}
}
if (in_array($type,
[
'CURRENCY',
'PERCENT'
]))
$newValue = str_replace($GLOBALS['locDecimalSeparator'], '.',
$newValue);
if (in_array($type,
[
'CURRENCY',
'PERCENT',
'INT'
])) {
$newValue = trim($newValue);
if (!is_numeric($newValue)) {
$messages .= $GLOBALS['locErrInvalidValue'] . " '$label'<br>\n";
continue;
}
}
if (isset($elem['session']) && $elem['session'])
$_SESSION[$name] = $newValue;
mysqli_param_query('DELETE from {prefix}settings WHERE name=?',
[
$name
]);
mysqli_param_query(
'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 type="text/javascript">
<!--
$(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">
<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 $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']) ? cond_utf8_decode($elem['default']) : '');
} else {
$res = mysqli_param_query(
'SELECT value from {prefix}settings WHERE name=?',
[
$name
]);
if ($row = mysqli_fetch_assoc($res))
$value = $row['value'];
else
$value = isset($elem['default']) ? cond_utf8_decode(
$elem['default']) : '';
}
if ($elemType == 'CURRENCY')
$value = miscRound2Decim($value);
elseif ($elemType == 'PERCENT')
$value = miscRound2Decim($value, 1);
}
if ($elemType == 'CURRENCY' || $elemType == 'PERCENT')
$elemType = 'INT';
if ($elemType == 'CHECK') {
?>
<div class="field" style="clear: both">
<?php echo htmlFormElement($name, $elemType, $value, $elem['style'], '', 'MODIFY', '', '', [], isset($elem['elem_attributes']) ? $elem['elem_attributes'] : '', isset($elem['options']) ? $elem['options'] : null)?>
<label for="<?php echo $name?>"><?php echo $elem['label']?></label>
</div>
<?php
} else {
?>
<div class="label" style="clear: both">
<label for="<?php echo $name?>"><?php echo $elem['label']?></label>
</div>
<div class="field" style="clear: both">
<?php echo htmlFormElement($name, $elemType, $value, $elem['style'], '', 'MODIFY', '', '', [], isset($elem['elem_attributes']) ? $elem['elem_attributes'] : '', isset($elem['options']) ? $elem['options'] : null)?>
</div>
<?php
}
}
?>
<input type="hidden" name="saveact" value="0">
<?php createSettingsListButtons()?>
</form>
</div>
</div>
<?php
}
function createSettingsListButtons()
{
?>
<div class="form_buttons" style="clear: both">
<a class="actionlink save_button" href="#"
onclick="document.getElementById('admin_form').saveact.value=1; document.getElementById('admin_form').submit(); return false;"><?php echo $GLOBALS['locSave']?></a>
</div>
<?php
}