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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
<?php
function emptyIfZero($value){ if($value==0){ return ''; } return $value; }
function numf($num, $dec=2){ $numout = ( empty($num) || !is_numeric($num) )? 0 : $num; $numout = number_format($numout, $dec, '.', ''); $numout = rtrim(rtrim($numout, '0'), '.'); return empty($numout)? 0 : $numout; //return $numout; //return number_format($num, $dec, '.', ''); }
function numfs($num, $dec=2){ $numout = number_format($num, $dec, '.', ','); return $numout; //return $numout; //return number_format($num, $dec, '.', ''); } //echo numfs(2461521454654.2241545);
function qtyf($num, $dec=3){ return numf($num, 3); }
function datef($dat, $char=19){ if(substr($dat, 0, 10)=="1900-01-01"){ return ""; } return substr($dat, 0, $char); } //echo numf('5').HTML_EOL; // echo numf(0.1000).HTML_EOL; // echo numf(100223).HTML_EOL; // echo numf(.95).HTML_EOL;
function txtf($str){ return html_entity_decode($str, ENT_QUOTES); }
function lastUpdate($record){
if (!empty($record['lastupdate'])){ $date = datef($record['lastupdate']); } elseif (!empty($record['createdate'])){ $date = datef($record['createdate']); } else { $date = "---"; }
if (!empty($record['lastupby'])){ $user = $record['lastupby']; } elseif (!empty($record['createby'])){ $user = $record['createby']; } else { $user = "---"; }
return $date . " (" . $user . ")";
}
function hasValue(){ $a = func_get_args ();
foreach($a as $val){ if(!empty($val)){ return ture; } } return false; } //echo "hv=".hasValue((float)"0.0",0,0,0.1);
function html_hiddenfield($fieldname, $value, $showvalue=true, $class="", $id=""){ $s = ""; $s .= "<input type='hidden' name='$fieldname' value='$value' "; if($class){ $s .= "class='$class' "; }
if($id){ $s .= "id='$id' "; } else{ $s .= "id='$fieldname' "; }
$s .= "/>";
if($showvalue){ $s .= $value; } return $s; } //echo html_hiddenfield("price", 500, true, "posint", "poval");
function imageResize($width, $height, $target) { //takes the larger size of the width and height and applies the formula accordingly...this is so this script will work dynamically with any size image if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format...this is so you can plug this function inside an image tag and just get the return "width=\"$width\" height=\"$height\""; }
function getOrgFilename($filename){ $pos = strripos($filename, '_'); if($pos){ //echo "name="; return substr($filename, $pos+1); } return $filename;
} //echo getOrgFilename("MA____STERMOLD332012-06-12-061418a1.jpg");
function isValidEmail($email){ return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); }
/*function initCounter() { //create log in database table 'audit_counter' global $dbh; $sql = "INSERT INTO audit_counter SET page = :page, ipaddress = :ipaddress, sessionID = :sessionID, customerID = :customerID, created = NOW()"; $sth = $dbh->prepare($sql); $sth->execute( array( ':page' => $_SERVER['PHP_SELF'], ':ipaddress' => getRealIpAddr(), ':customerID' => $_SESSION['customerID'], ':sessionID' => session_id() ) ); }*/
function reqvar_date($d){ //echo "var= $d".$_REQUEST[$d]; if( !empty($_REQUEST[$d]) ) return mysql_real_escape_string($_REQUEST[$d]); else return date("Y-m-d"); }
if(!function_exists('filter_var')) { function filter_var($inp, $flag="") { return $inp; }
}
function pdf_add_attribute($pdf, $label, $val, &$lr, $showBorder=0){
if(empty($val)){ return; }
$pdf->MultiCell(120, $row_height, $label, $showBorder, 'L', 0, 0);
$pdf->MultiCell(120, $row_height, $val, $showBorder, 'L', 0, $lr);
if($lr==0){//Left cell $lr=1; } else { //Right cell $lr=0; } }
function pdf_newline($pdf, &$lr, $showBorder=0){
if($lr==0){//Left cell return; } else { //Right cell $pdf->MultiCell(20, $row_height, ' ', $showBorder, 'L', 0, 1); } }
function getphptime($digits=23){ return substr(date_create_from_format('U.u', microtime(true))->format('Y-m-d H:i:s.u'), 0, $digits); } //echo getphptime();
function realbasename($str){ return strtok(basename($str), '?'); }
function page_offset($page, $rowperpage_setting=false){ if( $rowperpage_setting ){ $rowperpage = $rowperpage_setting; } else { $rowperpage = ROW_PER_PAGE; } $start = ($page-1) * $rowperpage +1; //start from 1 $end = $start + $rowperpage -1; //to 50 return array($start, $end); }
function number_page($ttlrow, $rowperpage_setting=false){ if( $rowperpage_setting ){ $rowperpage = $rowperpage_setting; } else { $rowperpage = ROW_PER_PAGE; } return ceil($ttlrow/$rowperpage); }
function pagination($ttlrow, $currentpage, $rowperpage_setting=false, $idprefix=""){ if( $rowperpage_setting ){ $rowperpage = $rowperpage_setting; } else { $rowperpage = ROW_PER_PAGE; } $number_page = number_page($ttlrow, $rowperpage); //vdump($ttlrow, $number_page, $currentpage);
$s=''; $s.=TOTAL.': '.$ttlrow.WS.ITEMS.' / '.$number_page.WS.PAGES.'<br />'; $s.='<div>'; if($currentpage > 1) { $s.='<button name="p" value="1" id="'.$idprefix.'_first">|<</button>'; $s.='<button name="p" value="'.($currentpage-1).'" id="'.$idprefix.'_prev"><</button>'; }
for($i=$currentpage-2; $i<=$currentpage+2; $i++){ if($i>=1 &$i<=$number_page){ if($i==$currentpage) { $s.='<button name="p" value="'.$i.'" id="'.$idprefix.'_current" disabled="disabled" style="font-size: 150%; font-weight:bold;">'.$i.'</button>'; }else{ $s.='<button name="p" value="'.$i.'" id="'.$idprefix.'_'.$i.'">'.$i.'</button>'; } } } if($currentpage < $number_page) { $s.='<button name="p" value="'.($currentpage+1).'" id="'.$idprefix.'_next">></button>'; $s.='<button name="p" value="'.$number_page.'" id="'.$idprefix.'_last">>|</button>'; } $s.='<input type="number" name="pg" value="" class="minifield" id="'.$idprefix.'_pg" />'; $s.='</div>'; return $s; }
if (!function_exists('json_encode')) { function json_encode($data) { //echo "JD"; switch ($type = gettype($data)) { case 'NULL': return 'null'; case 'boolean': return ($data ? 'true' : 'false'); case 'integer': case 'double': case 'float': //return $data; return '"' . addslashes($data) . '"'; case 'string': return '"' . addslashes($data) . '"'; case 'object': $data = get_object_vars($data); case 'array': $output_index_count = 0; $output_indexed = array(); $output_associative = array(); foreach ($data as $key => $value) { $output_indexed[] = json_encode($value); $output_associative[] = json_encode($key) . ':' . json_encode($value); if ($output_index_count !== NULL && $output_index_count++ !== $key) { $output_index_count = NULL; } } if ($output_index_count !== NULL) { return '[' . implode(',', $output_indexed) . ']'; } else { return '{' . implode(',', $output_associative) . '}'; } default: return ''; // Not supported } } }
function form_dest($godest, $formdest){ if( $godest && $formdest ){ header("Location: $formdest"); print "Saved."; exit; } }
function simpleTip($str, $maxleng=20, &$desc=''){ if( strlen($str)<$maxleng ){ $desc = $str; return $str; } $desc = mb_substr($str, 0, $maxleng, 'UTF-8'); return '<span class="tip" title="'.$str.'">'.$desc.'…</span>'; }
function simpleTip2($str, $tip){
return '<span class="tip" title="'.$tip.'">'.$str.'</span>'; } /* <input type="hidden" name="godest" id="godest" /> <input type="hidden" name="formdest" value="ord_dtl_index.php?act=resume" /> form_dest($_REQUEST['godest'], $_REQUEST['formdest']); */ function radio_checked($checkedval, $myval){ if($checkedval==$myval){ return 'checked="checked"'; } }
function checkbox_checked($val){ if(!empty($val)){ return 'checked="checked"'; } }
function option_selected($checkedval, $myval){ if($checkedval==$myval){ return 'selected="selected"'; } }
function html_yesnoicon($val){ if($val){ return '<span class="ui-icon ui-icon-check" style="display:inline-block;">'; //return '<img src="images/" />'; }else{ return '<span class="ui-icon ui-icon-close" style="display:inline-block;">'; } }
|