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 // first registered company has site admin privileges
76 return isset($page_level) && in_array($page_level, $security_groups[$this->access])
77 && ($this->company == 0 || $page_level != 20);
80 function get_db_connection()
82 global $db_connections;
84 $connection = $db_connections[$this->company];
86 //print_r($connection);
88 $db = mysql_connect($connection["host"] ,
89 $connection["dbuser"], $connection["dbpassword"]);
90 mysql_select_db($connection["dbname"],$db);
92 if (!defined('TB_PREF'))
93 define('TB_PREF', $connection["tbpref"]);
98 function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
99 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints) {
100 update_user_display_prefs($this->username, $price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl,
101 $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints);
104 $user = get_user($this->username);
105 $this->prefs = new user_prefs($user);
109 //--------------------------------------------------------------------------
111 function number_format2($number, $decimals=0)
113 global $thoseps, $decseps;
114 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
115 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
116 return number_format($number, $decimals, $dsep, $tsep);
119 function price_format($number) {
120 return number_format2($number,
121 $_SESSION["wa_current_user"]->prefs->price_dec());
123 // 2008-06-15. Added extra parameter $stock_id and reference for $dec
124 //--------------------------------------------------------------------
125 function qty_format($number, $stock_id=null, &$dec) {
126 $dec = get_qty_dec($stock_id);
127 return number_format2($number, $dec);
130 function get_qty_dec($stock_id=null)
132 global $path_to_root;
133 include_once($path_to_root."/inventory/includes/db/items_units_db.inc");
134 if ($stock_id != null)
135 $dec = get_unit_dec($stock_id);
136 if ($stock_id == null || $dec == -1 || $dec == null)
137 $dec = $_SESSION["wa_current_user"]->prefs->qty_dec();
140 //-------------------------------------------------------------------
141 function exrate_format($number) {
142 return number_format2($number,
143 $_SESSION["wa_current_user"]->prefs->exrate_dec());
146 function percent_format($number) {
147 return number_format2($number,
148 $_SESSION["wa_current_user"]->prefs->percent_dec());
151 function user_numeric($input) {
152 global $decseps, $thoseps;
155 $sep = $thoseps[user_tho_sep()];
156 if($sep!='') $num = str_replace( $sep, '', $num);
157 str_replace($sep, '', $num);
158 $sep = $decseps[user_dec_sep()];
159 if($sep!='.') $num = str_replace( $sep, '.', $num);
161 if (!is_numeric($num))
164 if ($num == (int)$num)
170 function user_company()
172 return $_SESSION["wa_current_user"]->company;
175 function user_language()
177 return $_SESSION["wa_current_user"]->prefs->language();
180 function user_qty_dec()
182 return $_SESSION["wa_current_user"]->prefs->qty_dec();
185 function user_price_dec()
187 return $_SESSION["wa_current_user"]->prefs->price_dec();
190 function user_exrate_dec()
192 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
195 function user_percent_dec()
197 return $_SESSION["wa_current_user"]->prefs->percent_dec();
200 function user_show_gl_info()
202 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
205 function user_show_codes()
207 return $_SESSION["wa_current_user"]->prefs->show_codes();
210 function user_date_format()
212 return $_SESSION["wa_current_user"]->prefs->date_format();
215 function user_date_display()
217 return $_SESSION["wa_current_user"]->prefs->date_display();
220 function user_date_sep()
222 return $_SESSION["wa_current_user"]->prefs->date_sep();
225 function user_tho_sep()
227 return $_SESSION["wa_current_user"]->prefs->tho_sep();
230 function user_dec_sep()
232 return $_SESSION["wa_current_user"]->prefs->dec_sep();
235 function user_theme()
237 return $_SESSION["wa_current_user"]->prefs->get_theme();
240 function user_pagesize()
242 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
245 function user_hints()
247 return $_SESSION["wa_current_user"]->prefs->show_hints();
250 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
251 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints)
254 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
255 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints);
258 function add_user_js_data() {
259 global $path_to_root, $thoseps, $decseps;
261 $ts = $thoseps[user_tho_sep()];
262 $ds = $decseps[user_dec_sep()];
264 $js = "\n<script type=\"text/javascript\">\n"
267 . "theme: '". $path_to_root . '/themes/'. 'default' /*user_theme()*/.'/'."',\n"
268 . "loadtxt: '"._('Requesting data...')."',\n"
271 . "pdec : " . user_price_dec() . "}\n--></script>";
276 //--------------------------------------------------------------------------