2 /**********************************************************************
3 Copyright (C) 2005-2008 FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 include_once($path_to_root . "/includes/prefs/userprefs.inc");
14 //--------------------------------------------------------------------------
31 function current_user()
33 $this->loginname = $username = $this->name = $this->company = "";
34 $this->logged = false;
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, $graphic_links) {
113 update_user_display_prefs($this->username, $price_dec,
114 $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
115 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize,
116 $show_hints, $profile, $rep_popup, $query_size, $graphic_links);
119 $user = get_user($this->username);
120 $this->prefs = new user_prefs($user);
124 //--------------------------------------------------------------------------
126 function round2($number, $decimals=0)
128 $delta = ($number < 0 ? -.000001 : .000001);
129 return round($number+$delta, $decimals);
132 function number_format2($number, $decimals=0)
134 global $thoseps, $decseps;
135 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
136 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
137 //return number_format($number, $decimals, $dsep, $tsep);
138 $delta = ($number < 0 ? -.000001 : .000001);
139 return number_format($number+$delta, $decimals, $dsep, $tsep);
144 function fallback_mode() {
145 return $_SESSION["wa_current_user"]->ui_mode==0;
148 function price_format($number) {
149 return number_format2($number,
150 $_SESSION["wa_current_user"]->prefs->price_dec());
152 // 2008-06-15. Added extra parameter $stock_id and reference for $dec
153 //--------------------------------------------------------------------
154 function qty_format($number, $stock_id=null, &$dec) {
155 $dec = get_qty_dec($stock_id);
156 return number_format2($number, $dec);
159 function get_qty_dec($stock_id=null)
161 global $path_to_root;
162 include_once($path_to_root."/inventory/includes/db/items_units_db.inc");
163 if ($stock_id != null)
164 $dec = get_unit_dec($stock_id);
165 if ($stock_id == null || $dec == -1 || $dec == null)
166 $dec = $_SESSION["wa_current_user"]->prefs->qty_dec();
169 //-------------------------------------------------------------------
170 function exrate_format($number) {
171 return number_format2($number,
172 $_SESSION["wa_current_user"]->prefs->exrate_dec());
175 function percent_format($number) {
176 return number_format2($number,
177 $_SESSION["wa_current_user"]->prefs->percent_dec());
180 function user_numeric($input) {
181 global $decseps, $thoseps;
184 $sep = $thoseps[user_tho_sep()];
185 if($sep!='') $num = str_replace( $sep, '', $num);
186 str_replace($sep, '', $num);
187 $sep = $decseps[user_dec_sep()];
188 if($sep!='.') $num = str_replace( $sep, '.', $num);
190 if (!is_numeric($num))
193 if ($num == (int)$num)
199 function user_company()
201 return $_SESSION["wa_current_user"]->company;
206 return $_SESSION["wa_current_user"]->pos;
209 function user_language()
211 return $_SESSION["wa_current_user"]->prefs->language();
214 function user_qty_dec()
216 return $_SESSION["wa_current_user"]->prefs->qty_dec();
219 function user_price_dec()
221 return $_SESSION["wa_current_user"]->prefs->price_dec();
224 function user_exrate_dec()
226 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
229 function user_percent_dec()
231 return $_SESSION["wa_current_user"]->prefs->percent_dec();
234 function user_show_gl_info()
236 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
239 function user_show_codes()
241 return $_SESSION["wa_current_user"]->prefs->show_codes();
244 function user_date_format()
246 return $_SESSION["wa_current_user"]->prefs->date_format();
249 function user_date_display()
251 return $_SESSION["wa_current_user"]->prefs->date_display();
254 function user_date_sep()
256 return $_SESSION["wa_current_user"]->prefs->date_sep();
259 function user_tho_sep()
261 return $_SESSION["wa_current_user"]->prefs->tho_sep();
264 function user_dec_sep()
266 return $_SESSION["wa_current_user"]->prefs->dec_sep();
269 function user_theme()
271 return $_SESSION["wa_current_user"]->prefs->get_theme();
274 function user_pagesize()
276 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
279 function user_hints()
281 return $_SESSION["wa_current_user"]->prefs->show_hints();
284 function user_print_profile()
286 return $_SESSION["wa_current_user"]->prefs->print_profile();
289 function user_rep_popup()
291 return $_SESSION["wa_current_user"]->prefs->rep_popup();
294 function user_query_size()
296 return $_SESSION["wa_current_user"]->prefs->query_size();
299 function user_graphic_links()
301 return $_SESSION["wa_current_user"]->prefs->graphic_links();
304 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
305 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
306 $print_profile, $rep_popup, $query_size, $graphic_links)
309 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
310 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
311 $print_profile, $rep_popup, $query_size, $graphic_links);
314 function add_user_js_data() {
315 global $path_to_root, $thoseps, $decseps;
317 $ts = $thoseps[user_tho_sep()];
318 $ds = $decseps[user_dec_sep()];
320 $js = "\n<script type=\"text/javascript\">\n"
323 . "theme: '". $path_to_root . '/themes/'. 'default' /*user_theme()*/.'/'."',\n"
324 . "loadtxt: '"._('Requesting data...')."',\n"
327 . "pdec : " . user_price_dec() . "}\n--></script>";
332 //--------------------------------------------------------------------------