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);
52 $this->logged = false;
54 $Auth_Result = get_user_for_login($loginname, $password);
56 if (db_num_rows($Auth_Result) > 0)
58 $myrow = db_fetch($Auth_Result);
59 if (! @$myrow["inactive"]) {
60 $this->access = $myrow["full_access"];
61 $this->name = $myrow["real_name"];
62 $this->pos = $myrow["pos"];
63 $this->loginname = $loginname;
64 $this->username = $this->loginname;
65 $this->prefs = new user_prefs($myrow);
66 $this->user = @$myrow["id"];
67 update_user_visitdate($this->username);
75 function check_user_access()
77 global $security_groups;
78 return is_array($security_groups[$this->access]);
81 function can_access_page($page_level)
83 global $security_groups;
84 // first registered company has site admin privileges
85 return isset($page_level) && in_array($page_level, $security_groups[$this->access])
86 && ($this->company == 0 || $page_level != 20);
89 function get_db_connection()
91 global $db_connections;
93 $connection = $db_connections[$this->company];
95 //print_r($connection);
97 $db = mysql_connect($connection["host"] ,
98 $connection["dbuser"], $connection["dbpassword"]);
99 mysql_select_db($connection["dbname"],$db);
101 if (!defined('TB_PREF'))
102 define('TB_PREF', $connection["tbpref"]);
107 function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec,
108 $showgl, $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep,
109 $theme, $pagesize, $show_hints, $profile, $rep_popup, $query_size,
110 $graphic_links, $lang, $stickydate) {
111 update_user_display_prefs($this->user, $price_dec,
112 $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
113 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize,
114 $show_hints, $profile, $rep_popup, $query_size, $graphic_links, $lang, $stickydate);
117 $user = get_user($this->user);
118 $this->prefs = new user_prefs($user);
122 //--------------------------------------------------------------------------
124 function round2($number, $decimals=0)
126 $delta = ($number < 0 ? -.000001 : .000001);
127 return round($number+$delta, $decimals);
130 function number_format2($number, $decimals=0)
132 global $thoseps, $decseps;
133 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
134 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
135 //return number_format($number, $decimals, $dsep, $tsep);
136 $delta = ($number < 0 ? -.000001 : .000001);
137 return number_format($number+$delta, $decimals, $dsep, $tsep);
142 function fallback_mode() {
143 return $_SESSION["wa_current_user"]->ui_mode==0;
146 function price_format($number) {
147 return number_format2($number,
148 $_SESSION["wa_current_user"]->prefs->price_dec());
150 // 2008-06-15. Added extra parameter $stock_id and reference for $dec
151 //--------------------------------------------------------------------
152 function qty_format($number, $stock_id=null, &$dec) {
153 $dec = get_qty_dec($stock_id);
154 return number_format2($number, $dec);
157 function get_qty_dec($stock_id=null)
159 global $path_to_root;
160 include_once($path_to_root."/inventory/includes/db/items_units_db.inc");
161 if ($stock_id != null)
162 $dec = get_unit_dec($stock_id);
163 if ($stock_id == null || $dec == -1 || $dec == null)
164 $dec = $_SESSION["wa_current_user"]->prefs->qty_dec();
167 //-------------------------------------------------------------------
168 function exrate_format($number) {
169 return number_format2($number,
170 $_SESSION["wa_current_user"]->prefs->exrate_dec());
173 function percent_format($number) {
174 return number_format2($number,
175 $_SESSION["wa_current_user"]->prefs->percent_dec());
178 function user_numeric($input) {
179 global $decseps, $thoseps;
182 $sep = $thoseps[user_tho_sep()];
183 if($sep!='') $num = str_replace( $sep, '', $num);
184 str_replace($sep, '', $num);
185 $sep = $decseps[user_dec_sep()];
186 if($sep!='.') $num = str_replace( $sep, '.', $num);
188 if (!is_numeric($num))
191 if ($num == (int)$num)
197 function user_company()
199 return $_SESSION["wa_current_user"]->company;
204 return $_SESSION["wa_current_user"]->pos;
207 function user_language()
209 return $_SESSION["wa_current_user"]->prefs->language();
212 function user_qty_dec()
214 return $_SESSION["wa_current_user"]->prefs->qty_dec();
217 function user_price_dec()
219 return $_SESSION["wa_current_user"]->prefs->price_dec();
222 function user_exrate_dec()
224 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
227 function user_percent_dec()
229 return $_SESSION["wa_current_user"]->prefs->percent_dec();
232 function user_show_gl_info()
234 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
237 function user_show_codes()
239 return $_SESSION["wa_current_user"]->prefs->show_codes();
242 function user_date_format()
244 return $_SESSION["wa_current_user"]->prefs->date_format();
247 function user_date_display()
249 return $_SESSION["wa_current_user"]->prefs->date_display();
252 function user_date_sep()
254 return $_SESSION["wa_current_user"]->prefs->date_sep();
257 function user_tho_sep()
259 return $_SESSION["wa_current_user"]->prefs->tho_sep();
262 function user_dec_sep()
264 return $_SESSION["wa_current_user"]->prefs->dec_sep();
267 function user_theme()
269 return $_SESSION["wa_current_user"]->prefs->get_theme();
272 function user_pagesize()
274 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
277 function user_hints()
279 return $_SESSION["wa_current_user"]->prefs->show_hints();
282 function user_print_profile()
284 return $_SESSION["wa_current_user"]->prefs->print_profile();
287 function user_rep_popup()
289 return $_SESSION["wa_current_user"]->prefs->rep_popup();
292 function user_query_size()
294 return $_SESSION["wa_current_user"]->prefs->query_size();
297 function user_graphic_links()
299 return $_SESSION["wa_current_user"]->prefs->graphic_links();
302 function sticky_doc_date()
304 return $_SESSION["wa_current_user"]->prefs->sticky_date();
307 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
308 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
309 $print_profile, $rep_popup, $query_size, $graphic_links, $lang, $stickydate)
312 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
313 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
314 $print_profile, $rep_popup, $query_size, $graphic_links, $lang, $stickydate);
317 function add_user_js_data() {
318 global $path_to_root, $thoseps, $decseps, $date_system, $dateseps;
320 $ts = $thoseps[user_tho_sep()];
321 $ds = $decseps[user_dec_sep()];
325 . "theme: '". $path_to_root . '/themes/'. user_theme().'/'."',\n"
326 . "loadtxt: '"._('Requesting data...')."',\n"
327 . "date: '".Today()."',\n" // server date
328 . "datesys: ".$date_system.",\n"
329 . "datefmt: ".user_date_format().",\n"
330 . "datesep: '".$dateseps[user_date_sep()]."',\n"
333 . "pdec : " . user_price_dec() . "}\n";
338 //--------------------------------------------------------------------------