3 include_once($path_to_root . "/includes/prefs/userprefs.inc");
5 //--------------------------------------------------------------------------
20 function current_user()
22 $this->loginname = $username = $this->name = $this->company = "";
23 $this->logged = false;
33 function set_company($company)
35 $this->company = $company;
38 function login($company, $loginname, $password)
40 $this->set_company($company);
42 $Auth_Result = get_user_for_login($loginname, $password);
44 if (db_num_rows($Auth_Result) > 0)
46 $myrow = db_fetch($Auth_Result);
48 $this->access = $myrow["full_access"];
49 $this->name = $myrow["real_name"];
50 $this->loginname = $loginname;
51 $this->username = $this->loginname;
52 $this->prefs = new user_prefs($myrow);
54 update_user_visitdate($loginname);
60 $this->logged = false;
66 function check_user_access()
68 global $security_groups;
69 return is_array($security_groups[$this->access]);
72 function can_access_page($page_level)
74 global $security_groups;
75 return isset($page_level) && in_array($page_level, $security_groups[$this->access]);
78 function get_db_connection()
80 global $db_connections;
82 $connection = $db_connections[$this->company];
84 //print_r($connection);
86 $db = mysql_connect($connection["host"] ,
87 $connection["dbuser"], $connection["dbpassword"]);
88 mysql_select_db($connection["dbname"],$db);
90 if (!defined('TB_PREF'))
91 define('TB_PREF', $connection["tbpref"]);
96 function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
97 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints) {
98 update_user_display_prefs($this->username, $price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl,
99 $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints);
102 $user = get_user($this->username);
103 $this->prefs = new user_prefs($user);
107 //--------------------------------------------------------------------------
109 function number_format2($number, $decimals=0)
111 global $thoseps, $decseps;
112 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
113 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
114 return number_format($number, $decimals, $dsep, $tsep);
117 function price_format($number) {
118 return number_format2($number,
119 $_SESSION["wa_current_user"]->prefs->price_dec());
122 function qty_format($number) {
123 return number_format2($number,
124 $_SESSION["wa_current_user"]->prefs->qty_dec());
127 function exrate_format($number) {
128 return number_format2($number,
129 $_SESSION["wa_current_user"]->prefs->exrate_dec());
132 function percent_format($number) {
133 return number_format2($number,
134 $_SESSION["wa_current_user"]->prefs->percent_dec());
137 function user_numeric($input) {
138 global $decseps, $thoseps;
141 $sep = $thoseps[user_tho_sep()];
142 if($sep!='') $num = str_replace( $sep, '', $num);
143 str_replace($sep, '', $num);
144 $sep = $decseps[user_dec_sep()];
145 if($sep!='.') $num = str_replace( $sep, '.', $num);
147 if (!is_numeric($num))
150 if ($num == (int)$num)
156 function user_company()
158 return $_SESSION["wa_current_user"]->company;
161 function user_language()
163 return $_SESSION["wa_current_user"]->prefs->language();
166 function user_qty_dec()
168 return $_SESSION["wa_current_user"]->prefs->qty_dec();
171 function user_price_dec()
173 return $_SESSION["wa_current_user"]->prefs->price_dec();
176 function user_exrate_dec()
178 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
181 function user_percent_dec()
183 return $_SESSION["wa_current_user"]->prefs->percent_dec();
186 function user_show_gl_info()
188 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
191 function user_show_codes()
193 return $_SESSION["wa_current_user"]->prefs->show_codes();
196 function user_date_format()
198 return $_SESSION["wa_current_user"]->prefs->date_format();
201 function user_date_display()
203 return $_SESSION["wa_current_user"]->prefs->date_display();
206 function user_date_sep()
208 return $_SESSION["wa_current_user"]->prefs->date_sep();
211 function user_tho_sep()
213 return $_SESSION["wa_current_user"]->prefs->tho_sep();
216 function user_dec_sep()
218 return $_SESSION["wa_current_user"]->prefs->dec_sep();
221 function user_theme()
223 return $_SESSION["wa_current_user"]->prefs->get_theme();
226 function user_pagesize()
228 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
231 function user_hints()
233 return $_SESSION["wa_current_user"]->prefs->show_hints();
236 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
237 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints)
240 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
241 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints);
244 function add_user_js_data() {
245 global $path_to_root, $thoseps, $decseps;
247 $ts = $thoseps[user_tho_sep()];
248 $ds = $decseps[user_dec_sep()];
250 $js = "\n<script type=\"text/javascript\">\n"
253 . "theme: '". $path_to_root . '/themes/'. 'default' /*user_theme()*/.'/'."',\n"
254 . "loadtxt: '"._('Requesting data...')."',\n"
257 . "pdec : " . user_price_dec() . "}\n--></script>";
262 //--------------------------------------------------------------------------