3 include_once($path_to_root . "/includes/prefs/userprefs.inc");
5 //--------------------------------------------------------------------------
22 function current_user()
24 $this->loginname = $username = $this->name = $this->company = "";
25 $this->logged = false;
35 function set_company($company)
37 $this->company = $company;
40 function login($company, $loginname, $password)
42 $this->set_company($company);
44 $Auth_Result = get_user_for_login($loginname, $password);
46 if (db_num_rows($Auth_Result) > 0)
48 $myrow = db_fetch($Auth_Result);
50 $this->access = $myrow["full_access"];
51 $this->name = $myrow["real_name"];
52 $this->pos = $myrow["pos"];
53 $this->loginname = $loginname;
54 $this->username = $this->loginname;
55 $this->prefs = new user_prefs($myrow);
57 update_user_visitdate($loginname);
63 $this->logged = false;
69 function check_user_access()
71 global $security_groups;
72 return is_array($security_groups[$this->access]);
75 function can_access_page($page_level)
77 global $security_groups;
78 // first registered company has site admin privileges
79 return isset($page_level) && in_array($page_level, $security_groups[$this->access])
80 && ($this->company == 0 || $page_level != 20);
83 function get_db_connection()
85 global $db_connections;
87 $connection = $db_connections[$this->company];
89 //print_r($connection);
91 $db = mysql_connect($connection["host"] ,
92 $connection["dbuser"], $connection["dbpassword"]);
93 mysql_select_db($connection["dbname"],$db);
95 if (!defined('TB_PREF'))
96 define('TB_PREF', $connection["tbpref"]);
101 function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec,
102 $showgl, $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep,
103 $theme, $pagesize, $show_hints, $profile, $rep_popup, $query_size) {
104 update_user_display_prefs($this->username, $price_dec,
105 $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
106 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize,
107 $show_hints, $profile, $rep_popup, $query_size);
110 $user = get_user($this->username);
111 $this->prefs = new user_prefs($user);
115 //--------------------------------------------------------------------------
117 function number_format2($number, $decimals=0)
119 global $thoseps, $decseps;
120 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
121 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
122 return number_format($number, $decimals, $dsep, $tsep);
127 function fallback_mode() {
128 return $_SESSION["wa_current_user"]->ui_mode==0;
131 function price_format($number) {
132 return number_format2($number,
133 $_SESSION["wa_current_user"]->prefs->price_dec());
135 // 2008-06-15. Added extra parameter $stock_id and reference for $dec
136 //--------------------------------------------------------------------
137 function qty_format($number, $stock_id=null, &$dec) {
138 $dec = get_qty_dec($stock_id);
139 return number_format2($number, $dec);
142 function get_qty_dec($stock_id=null)
144 global $path_to_root;
145 include_once($path_to_root."/inventory/includes/db/items_units_db.inc");
146 if ($stock_id != null)
147 $dec = get_unit_dec($stock_id);
148 if ($stock_id == null || $dec == -1 || $dec == null)
149 $dec = $_SESSION["wa_current_user"]->prefs->qty_dec();
152 //-------------------------------------------------------------------
153 function exrate_format($number) {
154 return number_format2($number,
155 $_SESSION["wa_current_user"]->prefs->exrate_dec());
158 function percent_format($number) {
159 return number_format2($number,
160 $_SESSION["wa_current_user"]->prefs->percent_dec());
163 function user_numeric($input) {
164 global $decseps, $thoseps;
167 $sep = $thoseps[user_tho_sep()];
168 if($sep!='') $num = str_replace( $sep, '', $num);
169 str_replace($sep, '', $num);
170 $sep = $decseps[user_dec_sep()];
171 if($sep!='.') $num = str_replace( $sep, '.', $num);
173 if (!is_numeric($num))
176 if ($num == (int)$num)
182 function user_company()
184 return $_SESSION["wa_current_user"]->company;
189 return $_SESSION["wa_current_user"]->pos;
192 function user_language()
194 return $_SESSION["wa_current_user"]->prefs->language();
197 function user_qty_dec()
199 return $_SESSION["wa_current_user"]->prefs->qty_dec();
202 function user_price_dec()
204 return $_SESSION["wa_current_user"]->prefs->price_dec();
207 function user_exrate_dec()
209 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
212 function user_percent_dec()
214 return $_SESSION["wa_current_user"]->prefs->percent_dec();
217 function user_show_gl_info()
219 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
222 function user_show_codes()
224 return $_SESSION["wa_current_user"]->prefs->show_codes();
227 function user_date_format()
229 return $_SESSION["wa_current_user"]->prefs->date_format();
232 function user_date_display()
234 return $_SESSION["wa_current_user"]->prefs->date_display();
237 function user_date_sep()
239 return $_SESSION["wa_current_user"]->prefs->date_sep();
242 function user_tho_sep()
244 return $_SESSION["wa_current_user"]->prefs->tho_sep();
247 function user_dec_sep()
249 return $_SESSION["wa_current_user"]->prefs->dec_sep();
252 function user_theme()
254 return $_SESSION["wa_current_user"]->prefs->get_theme();
257 function user_pagesize()
259 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
262 function user_hints()
264 return $_SESSION["wa_current_user"]->prefs->show_hints();
267 function user_print_profile()
269 return $_SESSION["wa_current_user"]->prefs->print_profile();
272 function user_rep_popup()
274 return $_SESSION["wa_current_user"]->prefs->rep_popup();
277 function user_query_size()
279 return $_SESSION["wa_current_user"]->prefs->query_size();
282 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
283 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
284 $print_profile, $rep_popup, $query_size)
287 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
288 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
289 $print_profile, $rep_popup, $query_size);
292 function add_user_js_data() {
293 global $path_to_root, $thoseps, $decseps;
295 $ts = $thoseps[user_tho_sep()];
296 $ds = $decseps[user_dec_sep()];
298 $js = "\n<script type=\"text/javascript\">\n"
301 . "theme: '". $path_to_root . '/themes/'. 'default' /*user_theme()*/.'/'."',\n"
302 . "loadtxt: '"._('Requesting data...')."',\n"
305 . "pdec : " . user_price_dec() . "}\n--></script>";
310 //--------------------------------------------------------------------------