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
/
ext_search.php
executable file
·313 lines (273 loc) · 10 KB
/
ext_search.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?php
/*******************************************************************************
MLInvoice: web-based invoicing application.
Copyright (C) 2010-2015 Ere Maijala
Portions based on:
PkLasku : web-based invoicing software.
Copyright (C) 2004-2008 Samu Reinikainen
This program is free software. See attached LICENSE.
*******************************************************************************/
/*******************************************************************************
MLInvoice: web-pohjainen laskutusohjelma.
Copyright (C) 2010-2015 Ere Maijala
Perustuu osittain sovellukseen:
PkLasku : web-pohjainen laskutusohjelmisto.
Copyright (C) 2004-2008 Samu Reinikainen
Tämä ohjelma on vapaa. Lue oheinen LICENSE.
*******************************************************************************/
require_once 'htmlfuncs.php';
require_once 'sqlfuncs.php';
require_once 'sessionfuncs.php';
require_once 'miscfuncs.php';
require_once 'datefuncs.php';
sesVerifySession();
require_once 'localize.php';
$strFunc = getRequest('func', '');
$strForm = getRequest('form', '');
if ($strFunc == 'open_invoices')
$strFunc = 'invoices';
$strList = $strFunc;
$blnSearch = getPost('search_x', FALSE) ? TRUE : FALSE;
$blnSave = getPost('save_x', FALSE) ? TRUE : FALSE;
$strFields = getPost('fields', FALSE);
$strSearchField = getPost('searchfield', FALSE);
$strSearchName = getPost('searchname', '');
if ($strSearchField !== FALSE) {
if ($strFields === FALSE) {
$strFields = $strSearchField;
} else {
$strFields .= ",$strSearchField";
}
}
if ($strFields !== FALSE) {
$astrSelectedFields = explode(',', $strFields);
} else {
$astrSelectedFields = [];
}
require 'form_switch.php';
for ($j = 0; $j < count($astrSelectedFields); $j ++) {
$tmpDelete = getPost('delete_' . $astrSelectedFields[$j] . '_x', FALSE);
if ($tmpDelete) {
$astrSelectedFields[$j] = '';
}
}
$strFields = implode(',', $astrSelectedFields);
for ($j = 0; $j < count($astrFormElements); $j ++) {
if ($astrFormElements[$j]['type'] == 'RESULT' &&
$astrFormElements[$j]['name'] != '') {
$astrFormElements[$j]['type'] = 'TEXT';
}
}
$listValues = [];
for ($j = 0; $j < count($astrFormElements); $j ++) {
if ($astrFormElements[$j]['type'] != '' &&
$astrFormElements[$j]['type'] != 'LABEL' &&
$astrFormElements[$j]['type'] != 'HIDINT' &&
$astrFormElements[$j]['type'] != 'IFORM' &&
$astrFormElements[$j]['type'] != 'BUTTON' &&
$astrFormElements[$j]['type'] != 'JSBUTTON' &&
!in_array($astrFormElements[$j]['name'], $astrSelectedFields, true)) {
$listValues[$astrFormElements[$j]['name']] = str_replace('<br>', ' ',
$astrFormElements[$j]['label']);
}
$strControlType = $astrFormElements[$j]['type'];
$strControlName = $astrFormElements[$j]['name'];
if ($strControlType == 'IFORM' || $strControlType == 'BUTTON') {
$astrValues[$strControlName] = '';
} elseif ($strControlType != 'LABEL') {
if ($strControlType == 'INTDATE') {
$astrValues[$strControlName] = getPost($strControlName, '');
} else {
$astrValues[$strControlName] = getPost($strControlName, '');
}
}
}
$strListBox = htmlListBox('searchfield', $listValues, false, '', true);
$comparisonValues = [
'=' => $GLOBALS['locSearchEqual'],
'!=' => $GLOBALS['locSearchNotEqual'],
'<' => $GLOBALS['locSearchLessThan'],
'>' => $GLOBALS['locSearchGreaterThan']
];
$strOnLoad = '';
if ($blnSearch || $blnSave) {
$strWhereClause = '';
for ($j = 0; $j < count($astrFormElements); $j ++) {
$elem = $astrFormElements[$j];
$name = $elem['name'];
if (in_array($name, $astrSelectedFields, true)) {
$strSearchOperator = getPost("operator_$name", '');
if ($strSearchOperator)
$strSearchOperator = " $strSearchOperator ";
$strSearchMatch = getPost("searchmatch_$name", '=');
// do LIKE || NOT LIKE search to elements with text or varchar datatype
if ($elem['type'] == 'TEXT' || $elem['type'] == 'AREA') {
if ($strSearchMatch == '=') {
$strSearchMatch = 'LIKE';
} else {
$strSearchMatch = 'NOT LIKE';
}
$strSearchValue = "'%" . addcslashes($astrValues[$name], "'\\") . "%'";
} elseif ($astrFormElements[$j]['type'] == 'INT' ||
$astrFormElements[$j]['type'] == 'LIST' ||
$astrFormElements[$j]['type'] == 'SELECT' ||
$astrFormElements[$j]['type'] == 'SEARCHLIST') {
$strSearchValue = $astrValues[$name];
} elseif ($astrFormElements[$j]['type'] == 'CHECK') {
$strSearchValue = $astrValues[$name] ? 1 : 0;
} elseif ($astrFormElements[$j]['type'] == 'INTDATE') {
$strSearchValue = dateConvDate2DBDate($astrValues[$name]);
}
if ($strSearchValue)
$strWhereClause .= "$strSearchOperator$strListTableAlias$name $strSearchMatch $strSearchValue";
}
}
$strWhereClause = urlencode($strWhereClause);
if ($blnSearch) {
$strLink = "index.php?func=$strFunc&where=$strWhereClause";
$strOnLoad = "opener.location.href='$strLink'";
}
if ($blnSave && $strSearchName) {
$strQuery = 'INSERT INTO {prefix}quicksearch(user_id, name, func, whereclause) ' .
'VALUES (?, ?, ?, ?)';
$intRes = mysqli_param_query($strQuery,
[
$_SESSION['sesUSERID'],
$strSearchName,
$strFunc,
$strWhereClause
]);
} elseif ($blnSave && !$strSearchName) {
$strOnLoad = "alert('" . $GLOBALS['locErrorNoSearchName'] . "')";
}
}
echo htmlPageStart(_PAGE_TITLE_);
?>
<body onload="<?php echo $strOnLoad?>">
<script type="text/javascript">
<!--
$(function() {
$('input[class~="hasCalendar"]').datepicker();
});
-->
</script>
<div class="form_container ui-widget-content">
<div class="form ui-widget">
<form method="post"
action="ext_search.php?func=<?php echo $strFunc?>&form=<?php echo $strForm?>"
target="_self" name="search_form">
<input type="hidden" name="fields" value="<?php echo $strFields?>">
<table>
<thead>
<tr>
<th class="sublabel">
<?php echo $GLOBALS['locSearchField']?>
</td>
<th class="sublabel">
</td>
<th class="sublabel">
<?php echo $GLOBALS['locSearchTerm']?>
</td>
<td></td>
</tr>
</thead>
<tbody>
<?php
$fieldCount = 0;
for ($j = 0; $j < count($astrFormElements); $j ++) {
if (in_array($astrFormElements[$j]['name'], $astrSelectedFields, true)) {
$strSearchMatch = getPost('searchmatch_' . $astrFormElements[$j]['name'],
'=');
if ($astrFormElements[$j]['style'] == 'xxlong') {
$astrFormElements[$j]['style'] = 'long';
}
if (++$fieldCount > 1) {
$strSelectedOperator = getPost(
'operator_' . $astrFormElements[$j]['name'], 'AND');
$strOperator = htmlListBox('operator_' . $astrFormElements[$j]['name'],
[
'AND' => $GLOBALS['locSearchAND'],
'OR' => $GLOBALS['locSearchOR']
], $strSelectedOperator);
?>
<tr>
<td colspan="4">
<?php echo $strOperator?>
</td>
</tr>
<?php
}
?>
<tr class="search_row">
<td class="label">
<?php echo $astrFormElements[$j]['label']?>
</td>
<td class="field">
<?php echo htmlListBox('searchmatch_' . $astrFormElements[$j]['name'], $comparisonValues, $strSearchMatch, '', 0)?>
</td>
<td class="field">
<?php echo htmlFormElement($astrFormElements[$j]['name'], $astrFormElements[$j]['type'], $astrValues[$astrFormElements[$j]['name']], $astrFormElements[$j]['style'], $astrFormElements[$j]['listquery'], 'MODIFY', $astrFormElements[$j]['parent_key'], '', [], '', isset($astrFormElements[$j]['options']) ? $astrFormElements[$j]['options'] : NULL)?>
</td>
<td><input type="hidden"
name="delete_<?php echo $astrFormElements[$j]['name']?>_x"
value="0"> <a class="tinyactionlink" href="#"
title="<?php echo $GLOBALS['locDelRow']?>"
onclick="self.document.forms[0].delete_<?php echo $astrFormElements[$j]['name']?>_x.value=1; self.document.forms[0].submit(); return false;">
X </a></td>
</tr>
<?php
}
}
?>
<tr>
<td class="label">
<?php echo $GLOBALS['locSelectSearchField']?>
</td>
<td class="field" colspan="3">
<?php echo $strListBox?>
</td>
</tr>
<tr>
<td colspan="4"
style="text-align: center; padding-top: 8px; padding-bottom: 8px">
<input type="hidden" name="search_x" value="0"> <a
class="actionlink" href="#"
onclick="self.document.forms[0].search_x.value=1; self.document.forms[0].submit(); return false;"><?php echo $GLOBALS['locSearch']?></a>
<a class="actionlink" href="#"
onclick="self.close(); return false;"><?php echo $GLOBALS['locClose']?></a>
</td>
</tr>
<tr>
<td class="sublabel" colspan="4">
<?php echo $GLOBALS['locSearchSave']?>
</td>
</tr>
<?php
if ($blnSave && $strSearchName) {
?>
<tr>
<td colspan="4">
<?php echo $GLOBALS['locSearchSaved']?>
</td>
</tr>
<?php
}
?>
<tr>
<td class="label">
<?php echo $GLOBALS['locSearchName']?>
</td>
<td class="field"><input class="medium" type="text"
name="searchname" value="<?php echo $strSearchName?>"></td>
<td><input type="hidden" name="save_x" value="0"> <a
class="actionlink" href="#"
onclick="self.document.forms[0].save_x.value=1; self.document.forms[0].submit(); return false;"><?php echo $GLOBALS['locSaveSearch']?></a>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</body>
</html>