/[cvs]/nfo/php/libs/org.netfrag.flib/utils/helper.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.flib/utils/helper.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Sun Dec 22 13:29:54 2002 UTC (21 years, 8 months ago) by jonen
Branch: MAIN
Changes since 1.3: +32 -1 lines
+ added number format helper functions:
  + number_format_locale()
  + is_amount()

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed