2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/prefs/userprefs.inc");
14 //--------------------------------------------------------------------------
31 function current_user()
33 $this->loginname = $this->username = $this->name = $this->company = "";
34 $this->logged = false;
36 $this->prefs = new user_prefs();
44 function set_company($company)
46 $this->company = $company;
49 function login($company, $loginname, $password)
51 $this->set_company($company);
53 $Auth_Result = get_user_for_login($loginname, $password);
55 if (db_num_rows($Auth_Result) > 0)
57 $myrow = db_fetch($Auth_Result);
59 $this->access = $myrow["full_access"];
60 $this->name = $myrow["real_name"];
61 $this->pos = $myrow["pos"];
62 $this->loginname = $loginname;
63 $this->username = $this->loginname;
64 $this->prefs = new user_prefs($myrow);
66 update_user_visitdate($loginname);
72 $this->logged = false;
78 function check_user_access()
80 global $security_groups;
81 return is_array($security_groups[$this->access]);
84 function can_access_page($page_level)
86 global $security_groups;
87 // first registered company has site admin privileges
88 return isset($page_level) && in_array($page_level, $security_groups[$this->access])
89 && ($this->company == 0 || $page_level != 20);
92 function get_db_connection()
94 global $db_connections;
96 $connection = $db_connections[$this->company];
98 //print_r($connection);
100 $db = mysql_connect($connection["host"] ,
101 $connection["dbuser"], $connection["dbpassword"]);
102 mysql_select_db($connection["dbname"],$db);
104 if (!defined('TB_PREF'))
105 define('TB_PREF', $connection["tbpref"]);
110 function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec,
111 $showgl, $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep,
112 $theme, $pagesize, $show_hints, $profile, $rep_popup, $query_size,
113 $graphic_links, $lang) {
114 update_user_display_prefs($this->username, $price_dec,
115 $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
116 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize,
117 $show_hints, $profile, $rep_popup, $query_size, $graphic_links, $lang);
120 $user = get_user($this->username);
121 $this->prefs = new user_prefs($user);
125 //--------------------------------------------------------------------------
127 function round2($number, $decimals=0)
129 $delta = ($number < 0 ? -.000001 : .000001);
130 return round($number+$delta, $decimals);
133 function number_format2($number, $decimals=0)
135 global $thoseps, $decseps;
136 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
137 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
138 //return number_format($number, $decimals, $dsep, $tsep);
139 $delta = ($number < 0 ? -.000001 : .000001);
140 return number_format($number+$delta, $decimals, $dsep, $tsep);
145 function fallback_mode() {
146 return $_SESSION["wa_current_user"]->ui_mode==0;
149 function price_format($number) {
150 return number_format2($number,
151 $_SESSION["wa_current_user"]->prefs->price_dec());
153 // 2008-06-15. Added extra parameter $stock_id and reference for $dec
154 //--------------------------------------------------------------------
155 function qty_format($number, $stock_id=null, &$dec) {
156 $dec = get_qty_dec($stock_id);
157 return number_format2($number, $dec);
160 function get_qty_dec($stock_id=null)
162 global $path_to_root;
163 include_once($path_to_root."/inventory/includes/db/items_units_db.inc");
164 if ($stock_id != null)
165 $dec = get_unit_dec($stock_id);
166 if ($stock_id == null || $dec == -1 || $dec == null)
167 $dec = $_SESSION["wa_current_user"]->prefs->qty_dec();
170 //-------------------------------------------------------------------
171 function exrate_format($number) {
172 return number_format2($number,
173 $_SESSION["wa_current_user"]->prefs->exrate_dec());
176 function percent_format($number) {
177 return number_format2($number,
178 $_SESSION["wa_current_user"]->prefs->percent_dec());
181 function user_numeric($input) {
182 global $decseps, $thoseps;
185 $sep = $thoseps[user_tho_sep()];
186 if($sep!='') $num = str_replace( $sep, '', $num);
187 str_replace($sep, '', $num);
188 $sep = $decseps[user_dec_sep()];
189 if($sep!='.') $num = str_replace( $sep, '.', $num);
191 if (!is_numeric($num))
194 if ($num == (int)$num)
200 function user_company()
202 return $_SESSION["wa_current_user"]->company;
207 return $_SESSION["wa_current_user"]->pos;
210 function user_language()
212 return $_SESSION["wa_current_user"]->prefs->language();
215 function user_qty_dec()
217 return $_SESSION["wa_current_user"]->prefs->qty_dec();
220 function user_price_dec()
222 return $_SESSION["wa_current_user"]->prefs->price_dec();
225 function user_exrate_dec()
227 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
230 function user_percent_dec()
232 return $_SESSION["wa_current_user"]->prefs->percent_dec();
235 function user_show_gl_info()
237 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
240 function user_show_codes()
242 return $_SESSION["wa_current_user"]->prefs->show_codes();
245 function user_date_format()
247 return $_SESSION["wa_current_user"]->prefs->date_format();
250 function user_date_display()
252 return $_SESSION["wa_current_user"]->prefs->date_display();
255 function user_date_sep()
257 return $_SESSION["wa_current_user"]->prefs->date_sep();
260 function user_tho_sep()
262 return $_SESSION["wa_current_user"]->prefs->tho_sep();
265 function user_dec_sep()
267 return $_SESSION["wa_current_user"]->prefs->dec_sep();
270 function user_theme()
272 return $_SESSION["wa_current_user"]->prefs->get_theme();
275 function user_pagesize()
277 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
280 function user_hints()
282 return $_SESSION["wa_current_user"]->prefs->show_hints();
285 function user_print_profile()
287 return $_SESSION["wa_current_user"]->prefs->print_profile();
290 function user_rep_popup()
292 return $_SESSION["wa_current_user"]->prefs->rep_popup();
295 function user_query_size()
297 return $_SESSION["wa_current_user"]->prefs->query_size();
300 function user_graphic_links()
302 return $_SESSION["wa_current_user"]->prefs->graphic_links();
305 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
306 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
307 $print_profile, $rep_popup, $query_size, $graphic_links, $lang)
310 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
311 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
312 $print_profile, $rep_popup, $query_size, $graphic_links, $lang);
315 function add_user_js_data() {
316 global $path_to_root, $thoseps, $decseps;
318 $ts = $thoseps[user_tho_sep()];
319 $ds = $decseps[user_dec_sep()];
321 $js = "\n<script type=\"text/javascript\">\n"
324 . "theme: '". $path_to_root . '/themes/'. 'default' /*user_theme()*/.'/'."',\n"
325 . "loadtxt: '"._('Requesting data...')."',\n"
328 . "pdec : " . user_price_dec() . "}\n--></script>";
333 //--------------------------------------------------------------------------