forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectAsset.php
297 lines (278 loc) · 10.5 KB
/
SelectAsset.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
<?php
include ('includes/session.php');
$Title = _('Select an Asset');
$ViewTopic = 'FixedAssets';
$BookMark = 'AssetSelection';
include ('includes/header.php');
if (isset($_GET['AssetID'])) {
//The page is called with a AssetID
$_POST['Select'] = $_GET['AssetID'];
}
if (isset($_GET['NewSearch']) OR isset($_POST['Next']) OR isset($_POST['Previous']) OR isset($_POST['Go'])) {
unset($AssetID);
unset($_SESSION['SelectedAsset']);
unset($_POST['Select']);
}
if (!isset($_POST['PageOffset'])) {
$_POST['PageOffset'] = 1;
} else {
if ($_POST['PageOffset'] == 0) {
$_POST['PageOffset'] = 1;
}
}
if (isset($_POST['AssetCode'])) {
$_POST['AssetCode'] = trim(mb_strtoupper($_POST['AssetCode']));
}
// Always show the search facilities
$SQL = "SELECT categoryid,
categorydescription
FROM fixedassetcategories
ORDER BY categorydescription";
$result = DB_query($SQL);
if (DB_num_rows($result) == 0) {
echo '<p><font size="4" color="red">' . _('Problem Report') . ':</font><br />' . _('There are no asset categories currently defined please use the link below to set them up');
echo '<br /><a href="' . $RootPath . '/FixedAssetCategories.php">' . _('Define Asset Categories') . '</a>';
exit;
}
// end of showing search facilities
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">
<div>
<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/magnifier.png" title="' . _('Search') . '" alt="" />' . ' ' . $Title . '</p>
<table class="selection">
<tr>
<td>' . _('In Asset Category') . ':</td>
<td><select name="AssetCategory">';
if (!isset($_POST['AssetCategory'])) {
$_POST['AssetCategory'] = 'ALL';
}
if ($_POST['AssetCategory']=='ALL'){
echo '<option selected="selected" value="ALL">' . _('Any asset category') . '</option>';
} else {
echo '<option value="ALL">' . _('Any asset category') . '</option>';
}
while ($myrow = DB_fetch_array($result)) {
if ($myrow['categoryid'] == $_POST['AssetCategory']) {
echo '<option selected="selected" value="' . $myrow['categoryid'] . '">' . $myrow['categorydescription'] . '</option>';
} else {
echo '<option value="' . $myrow['categoryid'] . '">' . $myrow['categorydescription'] . '</option>';
}
}
echo '</select></td>
<td>' . _('Enter partial description') . ':</td>
<td>';
if (isset($_POST['Keywords'])) {
echo '<input type="text" name="Keywords" autofocus="autofocus" value="' . $_POST['Keywords'] . '" size="20" maxlength="25" />';
} else {
echo '<input type="text" name="Keywords" autofocus="autofocus" size="20" maxlength="25" />';
}
echo '</td>
</tr>
<tr>
<td>' . _('Asset Location') . ':</td>
<td><select name="AssetLocation">';
if (!isset($_POST['AssetLocation'])) {
$_POST['AssetLocation'] = 'ALL';
}
if ($_POST['AssetLocation']=='ALL'){
echo '<option selected="selected" value="ALL">' . _('Any asset location') . '</option>';
} else {
echo '<option value="ALL">' . _('Any asset location') . '</option>';
}
$result = DB_query("SELECT locationid, locationdescription FROM fixedassetlocations");
while ($myrow = DB_fetch_array($result)) {
if ($myrow['locationid'] == $_POST['AssetLocation']) {
echo '<option selected="selected" value="' . $myrow['locationid'] . '">' . $myrow['locationdescription'] . '</option>';
} else {
echo '<option value="' . $myrow['locationid'] . '">' . $myrow['locationdescription'] . '</option>';
}
}
echo '</select>';
echo ' </td>
<td><b>' . _('OR') . ' ' . '</b>' . _('Enter partial asset code') . ':</td>
<td>';
if (isset($_POST['AssetCode'])) {
echo '<input type="text" class="number" name="AssetCode" value="' . $_POST['AssetCode'] . '" size="15" maxlength="13" />';
} else {
echo '<input type="text" name="AssetCode" size="15" maxlength="13" />';
}
echo '</td>
</tr>
</table>
<br />
<div class="centre">
<input type="submit" name="Search" value="' . _('Search Now') . '" />
</div>
<br />
</div>';
// query for list of record(s)
if(isset($_POST['Go']) OR isset($_POST['Next']) OR isset($_POST['Previous'])) {
$_POST['Search']='Search';
}
if (isset($_POST['Search']) OR isset($_POST['Go']) OR isset($_POST['Next']) OR isset($_POST['Previous'])) {
if (!isset($_POST['Go']) AND !isset($_POST['Next']) AND !isset($_POST['Previous'])) {
// if Search then set to first page
$_POST['PageOffset'] = 1;
}
if ($_POST['Keywords'] AND $_POST['AssetCode']) {
prnMsg( _('Asset description keywords have been used in preference to the asset code extract entered'), 'info' );
}
$SQL = "SELECT assetid,
description,
datepurchased,
fixedassetlocations.locationdescription
FROM fixedassets INNER JOIN fixedassetlocations
ON fixedassets.assetlocation=fixedassetlocations.locationid ";
if ($_POST['Keywords']) {
//insert wildcard characters in spaces
$_POST['Keywords'] = mb_strtoupper($_POST['Keywords']);
$SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%';
if ($_POST['AssetCategory'] == 'ALL') {
if ($_POST['AssetLocation']=='ALL'){
$SQL .= "WHERE description " . LIKE . "'" . $SearchString . "'
ORDER BY fixedassets.assetid";
} else {
$SQL .= "WHERE fixedassets.assetlocation='" . $_POST['AssetLocation'] . "'
AND description " . LIKE . "'" . $SearchString . "'
ORDER BY fixedassets.assetid";
}
} else {
if ($_POST['AssetLocation']=='ALL'){
$SQL .= "WHERE description " . LIKE . "'" . $SearchString . "'
AND assetcategoryid='" . $_POST['AssetCategory'] . "'
ORDER BY fixedassets.assetid";
} else {
$SQL .= "WHERE fixedassets.assetlocation='" . $_POST['AssetLocation'] . "'
AND description " . LIKE . "'" . $SearchString . "'
AND assetcategoryid='" . $_POST['AssetCategory'] . "'
ORDER BY fixedassets.assetid";
}
}
} elseif (isset($_POST['AssetCode'])) {
if ($_POST['AssetCategory'] == 'ALL') {
if ($_POST['AssetLocation']=='ALL'){
$SQL .= "WHERE fixedassets.assetid " . LIKE . " '%" . $_POST['AssetCode'] . "%'
ORDER BY fixedassets.assetid";
} else {
$SQL .= "WHERE fixedassets.assetlocation='" . $_POST['AssetLocation'] . "'
AND fixedassets.assetid " . LIKE . " '%" . $_POST['AssetCode'] . "%'
ORDER BY fixedassets.assetid";
}
} else {
if ($_POST['AssetLocation']=='ALL'){
$SQL .= "WHERE fixedassets.assetid " . LIKE . " '%" . $_POST['AssetCode'] . "%'
AND assetcategoryid='" . $_POST['AssetCategory'] . "'
ORDER BY fixedassets.assetid";
} else {
$SQL .= "WHERE fixedassets.assetlocation='" . $_POST['AssetLocation'] . "'
AND fixedassets.assetid " . LIKE . " '%" . $_POST['AssetCode'] . "%'
AND assetcategoryid='" . $_POST['AssetCategory'] . "'
ORDER BY fixedassets.assetid";
}
}
} elseif (!isset($_POST['AssetCode']) AND !isset($_POST['Keywords'])) {
if ($_POST['AssetCategory'] == 'All') {
if ($_POST['AssetLocation']=='ALL'){
$SQL .= 'ORDER BY fixedassets.assetid';
} else {
$SQL .= "WHERE fixedassets.assetlocation='" . $_POST['AssetLocation'] . "'
ORDER BY fixedassets.assetid";
}
} else {
if ($_POST['AssetLocation']=='ALL'){
$SQL .= "WHERE assetcategoryid='" . $_POST['AssetCategory'] . "'
ORDER BY fixedassets.assetid";
} else {
$SQL .= "WHERE assetcategoryid='" . $_POST['AssetCategory'] . "'
AND fixedassets.assetlocation='" . $_POST['AssetLocation'] . "'
ORDER BY fixedassets.assetid";
}
}
}
$ErrMsg = _('No assets were returned by the SQL because');
$DbgMsg = _('The SQL that returned an error was');
$SearchResult = DB_query($SQL, $ErrMsg, $DbgMsg);
if (DB_num_rows($SearchResult) == 0) {
prnMsg(_('No assets were returned by this search please re-enter alternative criteria to try again'), 'info');
}
unset($_POST['Search']);
}
/* end query for list of records */
/* display list if there is more than one record */
if (isset($SearchResult) AND !isset($_POST['Select'])) {
$ListCount = DB_num_rows($SearchResult);
if ($ListCount > 0) {
// If the user hit the search button and there is more than one item to show
$ListPageMax = ceil($ListCount / $_SESSION['DisplayRecordsMax']);
if (isset($_POST['Next'])) {
if ($_POST['PageOffset'] < $ListPageMax) {
$_POST['PageOffset'] ++;
}
}
if (isset($_POST['Previous'])) {
if ($_POST['PageOffset'] > 1) {
$_POST['PageOffset']--;
}
}
if ($_POST['PageOffset'] > $ListPageMax) {
$_POST['PageOffset'] = $ListPageMax;
}
if ($ListPageMax > 1) {
echo '<div class="centre"><p> ' . $_POST['PageOffset'] . ' ' . _('of') . ' ' . $ListPageMax . ' ' . _('pages') . '. ' . _('Go to Page') . ': ';
echo '<select name="PageOffset">';
$ListPage = 1;
while ($ListPage <= $ListPageMax) {
if ($ListPage == $_POST['PageOffset']) {
echo '<option value="' . $ListPage . '" selected="selected">' . $ListPage . '</option>';
} else {
echo '<option value="' . $ListPage . '">' . $ListPage . '</option>';
}
$ListPage++;
}
echo '</select>
<input type="submit" name="Go" value="' . _('Go') . '" />
<input type="submit" name="Previous" value="' . _('Previous') . '" />
<input type="submit" name="Next" value="' . _('Next') . '" />';
echo '<br /></div>';
}
echo '</form>';
echo '<form action="FixedAssetItems.php" method="post">';
echo '<div>';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table class="selection">';
$tableheader = '<tr>
<th>' . _('Asset Code') . '</th>
<th>' . _('Description') . '</th>
<th>' . _('Asset Location') . '</th>
<th>' . _('Date Purchased') . '</th>
</tr>';
echo $tableheader;
$j = 1;
$RowIndex = 0;
if (DB_num_rows($SearchResult) <> 0) {
DB_data_seek($SearchResult, ($_POST['PageOffset'] - 1) * $_SESSION['DisplayRecordsMax']);
}
while (($myrow = DB_fetch_array($SearchResult)) AND ($RowIndex <> $_SESSION['DisplayRecordsMax'])) {
echo '<tr class="striped_row">
<td><input type="submit" name="Select" value="' . $myrow['assetid'] .'" /></td>
<td>' . $myrow['description'] . '</td>
<td>' . $myrow['locationdescription'] . '</td>
<td>' . ConvertSQLDate($myrow['datepurchased']) . '</td>
</tr>';
$j++;
if ($j == 20 AND ($RowIndex + 1 != $_SESSION['DisplayRecordsMax'])) {
$j = 1;
echo $tableheader;
}
$RowIndex = $RowIndex + 1;
//end of page full new headings if
}
//end of while loop
echo '</table>';
echo '</div>
</form>';
} // there were records to list
}
/* end display list if there is more than one record */
include ('includes/footer.php');
?>