1 |
joko |
1.1 |
<? |
2 |
|
|
// ----------------------------------------------------------------------------- |
3 |
joko |
1.5 |
// $Id: helper.php,v 1.4 2002/12/22 13:29:54 jonen Exp $ |
4 |
joko |
1.1 |
// ----------------------------------------------------------------------------- |
5 |
|
|
// $Log: helper.php,v $ |
6 |
joko |
1.5 |
// Revision 1.4 2002/12/22 13:29:54 jonen |
7 |
|
|
// + added number format helper functions: |
8 |
|
|
// + number_format_locale() |
9 |
|
|
// + is_amount() |
10 |
|
|
// |
11 |
jonen |
1.4 |
// Revision 1.3 2002/12/11 01:00:22 joko |
12 |
|
|
// + renamed function 'sai' to 'array_init' |
13 |
|
|
// |
14 |
joko |
1.3 |
// Revision 1.2 2002/12/01 04:49:54 joko |
15 |
|
|
// + function Dumper (from function dumpVar) |
16 |
|
|
// |
17 |
joko |
1.2 |
// Revision 1.1 2002/11/12 05:42:31 joko |
18 |
|
|
// + initial checkin |
19 |
|
|
// |
20 |
joko |
1.1 |
// Revision 1.1 2002/10/29 19:15:57 cvsjoko |
21 |
|
|
// + new checkin |
22 |
|
|
// |
23 |
|
|
// Revision 1.4 2002/10/26 18:24:54 cvsmax |
24 |
|
|
// + add note to care about UTC! |
25 |
|
|
// |
26 |
|
|
// Revision 1.3 2002/10/25 12:05:30 cvsmax |
27 |
|
|
// + bugfix: some db related functions wasn`t updated to new structure, done. |
28 |
|
|
// + bugfix: reworked function validate_idle() |
29 |
|
|
// |
30 |
|
|
// Revision 1.2 2002/10/17 03:37:40 cvsmax |
31 |
|
|
// - removed unused function cont_auth() |
32 |
|
|
// |
33 |
|
|
// Revision 1.1 2002/10/10 02:53:55 cvsmax |
34 |
|
|
// + create new partly from old 'func_main.inc' |
35 |
|
|
// |
36 |
|
|
// |
37 |
|
|
// ----------------------------------------------------------------------------- |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
function get_date_forDisplay($arg_date) { |
41 |
|
|
$date = new Date($arg_date); |
42 |
|
|
// TODO: |
43 |
|
|
// - determine this constant by asking $site->user->country, i believe we'll need some kind of mapping here |
44 |
|
|
// - or can it be integrated with TimeZone? no, it's a locale setting (localization/preferences), isn't it? |
45 |
|
|
return $date->getDate( DATE_FORMAT_GERMAN_SHORT ); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
function get_date_forStorage($arg_date) { |
49 |
|
|
|
50 |
|
|
// was: |
51 |
|
|
//$unixtime = mktime(0, 0, 0, $arg_date[1], $arg_date[0], $arg_date[2]); |
52 |
|
|
//return date("Y-m-d", $unixtime); // english format |
53 |
|
|
|
54 |
|
|
// if $arg_date is an array, it is in "german"-format (really in locale format, isn't it?) |
55 |
|
|
// TODO: check this! (do a generic reverse-map!) |
56 |
|
|
if (is_array($arg_date)) { |
57 |
|
|
$arg_date = join('.', $arg_date); |
58 |
|
|
} |
59 |
|
|
$date = new Date($arg_date); |
60 |
|
|
$date_res = $date->getDate( DATE_FORMAT_ENGLISH_SHORT ); |
61 |
|
|
return $date_res; |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
// ------------------------------------------------- |
65 |
joko |
1.3 |
// array initializer |
66 |
joko |
1.1 |
// initializes passed variable (taken by reference) with an empty array |
67 |
|
|
// does this only if it doesn't exist yet or initialization is explicitely requested ($clear = 1) |
68 |
joko |
1.3 |
function array_init(&$var, $clear = 0) { |
69 |
joko |
1.1 |
if (!is_array($var) || $clear) { $var = array(); } |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
|
73 |
|
|
// format functions |
74 |
|
|
function isvalidemailaddress($mail) { |
75 |
jonen |
1.4 |
// TODO: review for regex process load |
76 |
joko |
1.1 |
//return ((($string = trim($string)) != '') && (($atpos = strpos($string, '@' , 1)) > 1) && (($rdotpos = strrpos($string, '.')) > ($atpos + 2)) && (strlen($string) > $rdotpos + 2)); |
77 |
|
|
if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*"."@([a-z0-9]+([\.-][a-z0-9]+))*$",$mail, $regs) ) { |
78 |
|
|
return "format"; |
79 |
|
|
} |
80 |
|
|
elseif( gethostbyname($regs[2]) == $regs[2] ) { |
81 |
|
|
return "host"; |
82 |
|
|
} |
83 |
|
|
return "valid"; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
|
function dumpVar($var) { |
87 |
joko |
1.2 |
return Dumper($var); |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
function Dumper($var) { |
91 |
joko |
1.1 |
ob_start(); |
92 |
|
|
print_r($var); |
93 |
|
|
$var_dump = ob_get_contents(); |
94 |
|
|
ob_end_clean(); |
95 |
|
|
$var_dump = str_replace("\n", "<br>", $var_dump); |
96 |
|
|
$var_dump = str_replace(" ", " ", $var_dump); |
97 |
|
|
return $var_dump; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
function session_register_safe($varname) { |
101 |
|
|
if (!session_is_registered($varname)) { |
102 |
|
|
session_register($varname); |
103 |
|
|
return 1; |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
//------------ getMonths --------------------- |
108 |
|
|
// TODO: localize! |
109 |
|
|
function getMonthNames() { |
110 |
|
|
for ($i=1;$i<=12;$i++) { |
111 |
|
|
$utime = strtotime("2001-$i-24 12:00:00"); |
112 |
|
|
$name = date("F",$utime); |
113 |
|
|
$months[$i] = $name; |
114 |
|
|
} |
115 |
|
|
return $months; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
function null2nbsp_string($arg) { |
119 |
|
|
if ($arg == '') { |
120 |
|
|
$arg = ' '; |
121 |
|
|
} |
122 |
|
|
return $arg; |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
function null2nbsp_arraywalker(&$item, $key) { |
126 |
|
|
$item = null2nbsp_string($item); |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
function null2nbsp($arg) { |
130 |
|
|
if (is_array($arg)) { |
131 |
|
|
array_walk($arg, 'null2nbsp_arraywalker'); |
132 |
|
|
$result = $arg; |
133 |
|
|
} else { |
134 |
|
|
$result = null2nbsp_string($arg); |
135 |
|
|
} |
136 |
|
|
return $result; |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
//------------ en- and decode Birthdate ----------- |
140 |
|
|
function getEncodedBirthdate($birthdate) { |
141 |
|
|
print "birthday: $birthdate<br>"; |
142 |
|
|
if($birthdate) { |
143 |
|
|
$utime = strtotime($birthdate); |
144 |
|
|
print "utime: $utime<br>"; |
145 |
|
|
$birthday = array ( date("d",$utime), date("m",$utime), date("Y",$utime) ); |
146 |
|
|
} |
147 |
|
|
else { |
148 |
|
|
$birthday = array('', '', '1960'); |
149 |
|
|
} |
150 |
|
|
return $birthday; |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
/* |
154 |
|
|
function dprint($message) { |
155 |
|
|
print '<span style="font-family:Verdana,Helvetica;font-size:7pt;">'; |
156 |
|
|
print $message; |
157 |
|
|
print '</span><br>'; |
158 |
|
|
} |
159 |
|
|
*/ |
160 |
jonen |
1.4 |
|
161 |
|
|
function number_format_storage($string) { |
162 |
|
|
$locale_info = localeconv(); |
163 |
|
|
$string = str_replace($locale_info["decimal_point"], ".", $string); |
164 |
|
|
return $string; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
function number_format_locale1($string) { |
168 |
|
|
$locale_info = localeconv(); |
169 |
|
|
$string = str_replace(".", $locale_info["decimal_point"], $string); |
170 |
|
|
return $string; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
|
174 |
|
|
function number_format_locale ($num, $decimals = null) { |
175 |
|
|
$locale = localeconv(); |
176 |
|
|
if(!isset($decimals)) $decimals = $locale['frac_digits']; |
177 |
|
|
return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']); |
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
function is_amount($amount) { |
182 |
|
|
//if( (number_format_locale((string)doubleval($amount)) === number_format_locale((string)$amount)) && number_format_locale((doubleval($amount)) >number_format_locale(0)) ) { |
183 |
|
|
if( ((string)doubleval($amount) === (string)$amount) && (doubleval($amount) > 0) ) { |
184 |
|
|
return 1; |
185 |
|
|
} |
186 |
|
|
} |
187 |
joko |
1.5 |
|
188 |
|
|
|
189 |
|
|
// from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php |
190 |
|
|
function is_hash( $var ) { |
191 |
|
|
if( is_array( $var ) ) { |
192 |
|
|
$keys = array_keys( $var ); |
193 |
|
|
$all_num = true; |
194 |
|
|
for( $i=0; $i<count($keys); $i++ ) |
195 |
|
|
if( is_string($keys[$i] ) ) return true; |
196 |
|
|
} |
197 |
|
|
return false; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
// from: php.net - http://www.php.net/manual/en/function.array-merge-recursive.php |
201 |
|
|
function array_join_merge( $arr1, $arr2 ) { |
202 |
|
|
if( is_array( $arr1 ) and is_array( $arr2 ) ) { |
203 |
|
|
// the same -> merge |
204 |
|
|
$new_array = array(); |
205 |
|
|
|
206 |
|
|
if( is_hash( $arr1 ) and is_hash( $arr2 ) ) { |
207 |
|
|
// hashes -> merge based on keys |
208 |
|
|
$keys = array_merge( array_keys( $arr1 ), array_keys( $arr2 ) ); |
209 |
|
|
foreach( $keys as $key ) { |
210 |
|
|
$new_array[$key] = array_join_merge( $arr1[$key], $arr2[$key] ); |
211 |
|
|
} |
212 |
|
|
} else { |
213 |
|
|
// two real arrays -> merge |
214 |
|
|
$new_array = |
215 |
|
|
array_reverse(array_unique(array_reverse(array_merge($arr1,$arr2)))); |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
return $new_array; |
219 |
|
|
} else { |
220 |
|
|
// not the same ... take new one if defined, else the old one stays |
221 |
|
|
return $arr2 ? $arr2 : $arr1; |
222 |
|
|
} |
223 |
|
|
} |
224 |
joko |
1.1 |
|
225 |
|
|
?> |