3 include_once($path_to_root . "/includes/prefs/userprefs.inc");
5 //--------------------------------------------------------------------------
21 function current_user()
23 $this->loginname = $username = $this->name = $this->company = "";
24 $this->logged = false;
34 function set_company($company)
36 $this->company = $company;
39 function login($company, $loginname, $password)
41 $this->set_company($company);
43 $Auth_Result = get_user_for_login($loginname, $password);
45 if (db_num_rows($Auth_Result) > 0)
47 $myrow = db_fetch($Auth_Result);
49 $this->access = $myrow["full_access"];
50 $this->name = $myrow["real_name"];
51 $this->loginname = $loginname;
52 $this->username = $this->loginname;
53 $this->prefs = new user_prefs($myrow);
55 update_user_visitdate($loginname);
61 $this->logged = false;
67 function check_user_access()
69 global $security_groups;
70 return is_array($security_groups[$this->access]);
73 function can_access_page($page_level)
75 global $security_groups;
76 // first registered company has site admin privileges
77 return isset($page_level) && in_array($page_level, $security_groups[$this->access])
78 && ($this->company == 0 || $page_level != 20);
81 function get_db_connection()
83 global $db_connections;
85 $connection = $db_connections[$this->company];
87 //print_r($connection);
89 $db = mysql_connect($connection["host"] ,
90 $connection["dbuser"], $connection["dbpassword"]);
91 mysql_select_db($connection["dbname"],$db);
93 if (!defined('TB_PREF'))
94 define('TB_PREF', $connection["tbpref"]);
99 function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec,
100 $showgl, $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep,
101 $theme, $pagesize, $show_hints, $profile, $rep_popup) {
102 update_user_display_prefs($this->username, $price_dec,
103 $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
104 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize,
105 $show_hints, $profile, $rep_popup);
108 $user = get_user($this->username);
109 $this->prefs = new user_prefs($user);
113 //--------------------------------------------------------------------------
115 function number_format2($number, $decimals=0)
117 global $thoseps, $decseps;
118 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
119 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
120 return number_format($number, $decimals, $dsep, $tsep);
125 function fallback_mode() {
126 return $_SESSION["wa_current_user"]->ui_mode==0;
129 function price_format($number) {
130 return number_format2($number,
131 $_SESSION["wa_current_user"]->prefs->price_dec());
133 // 2008-06-15. Added extra parameter $stock_id and reference for $dec
134 //--------------------------------------------------------------------
135 function qty_format($number, $stock_id=null, &$dec) {
136 $dec = get_qty_dec($stock_id);
137 return number_format2($number, $dec);
140 function get_qty_dec($stock_id=null)
142 global $path_to_root;
143 include_once($path_to_root."/inventory/includes/db/items_units_db.inc");
144 if ($stock_id != null)
145 $dec = get_unit_dec($stock_id);
146 if ($stock_id == null || $dec == -1 || $dec == null)
147 $dec = $_SESSION["wa_current_user"]->prefs->qty_dec();
150 //-------------------------------------------------------------------
151 function exrate_format($number) {
152 return number_format2($number,
153 $_SESSION["wa_current_user"]->prefs->exrate_dec());
156 function percent_format($number) {
157 return number_format2($number,
158 $_SESSION["wa_current_user"]->prefs->percent_dec());
161 function user_numeric($input) {
162 global $decseps, $thoseps;
165 $sep = $thoseps[user_tho_sep()];
166 if($sep!='') $num = str_replace( $sep, '', $num);
167 str_replace($sep, '', $num);
168 $sep = $decseps[user_dec_sep()];
169 if($sep!='.') $num = str_replace( $sep, '.', $num);
171 if (!is_numeric($num))
174 if ($num == (int)$num)
180 function user_company()
182 return $_SESSION["wa_current_user"]->company;
185 function user_language()
187 return $_SESSION["wa_current_user"]->prefs->language();
190 function user_qty_dec()
192 return $_SESSION["wa_current_user"]->prefs->qty_dec();
195 function user_price_dec()
197 return $_SESSION["wa_current_user"]->prefs->price_dec();
200 function user_exrate_dec()
202 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
205 function user_percent_dec()
207 return $_SESSION["wa_current_user"]->prefs->percent_dec();
210 function user_show_gl_info()
212 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
215 function user_show_codes()
217 return $_SESSION["wa_current_user"]->prefs->show_codes();
220 function user_date_format()
222 return $_SESSION["wa_current_user"]->prefs->date_format();
225 function user_date_display()
227 return $_SESSION["wa_current_user"]->prefs->date_display();
230 function user_date_sep()
232 return $_SESSION["wa_current_user"]->prefs->date_sep();
235 function user_tho_sep()
237 return $_SESSION["wa_current_user"]->prefs->tho_sep();
240 function user_dec_sep()
242 return $_SESSION["wa_current_user"]->prefs->dec_sep();
245 function user_theme()
247 return $_SESSION["wa_current_user"]->prefs->get_theme();
250 function user_pagesize()
252 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
255 function user_hints()
257 return $_SESSION["wa_current_user"]->prefs->show_hints();
260 function user_print_profile()
262 return $_SESSION["wa_current_user"]->prefs->print_profile();
265 function user_rep_popup()
267 return $_SESSION["wa_current_user"]->prefs->rep_popup();
270 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
271 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
272 $print_profile, $rep_popup)
275 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
276 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
277 $print_profile, $rep_popup);
280 function add_user_js_data() {
281 global $path_to_root, $thoseps, $decseps;
283 $ts = $thoseps[user_tho_sep()];
284 $ds = $decseps[user_dec_sep()];
286 $js = "\n<script type=\"text/javascript\">\n"
289 . "theme: '". $path_to_root . '/themes/'. 'default' /*user_theme()*/.'/'."',\n"
290 . "loadtxt: '"._('Requesting data...')."',\n"
293 . "pdec : " . user_price_dec() . "}\n--></script>";
298 //--------------------------------------------------------------------------