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 //--------------------------------------------------------------------------
33 function current_user()
37 $this->loginname = $this->username = $this->name = "";
38 $this->company = isset($def_coy)? $def_coy : 0;
39 $this->logged = false;
41 $this->prefs = new user_prefs();
49 function set_company($company)
51 $this->company = $company;
54 function login($company, $loginname, $password)
56 $this->set_company($company);
57 $this->logged = false;
59 $Auth_Result = get_user_for_login($loginname, $password);
61 if (db_num_rows($Auth_Result) > 0)
63 $myrow = db_fetch($Auth_Result);
64 if (! @$myrow["inactive"]) {
65 $this->access = $myrow["full_access"];
66 $this->name = $myrow["real_name"];
67 $this->pos = $myrow["pos"];
68 $this->loginname = $loginname;
69 $this->username = $this->loginname;
70 $this->prefs = new user_prefs($myrow);
71 $this->user = @$myrow["id"];
72 update_user_visitdate($this->username);
74 $this->last_act = time();
75 $this->timeout = session_timeout();
82 function check_user_access()
84 global $security_groups;
85 return is_array($security_groups[$this->access]);
88 function can_access_page($page_level)
90 global $security_groups;
91 // first registered company has site admin privileges
92 return isset($page_level) && in_array($page_level, $security_groups[$this->access])
93 && ($this->company == 0 || $page_level != 20);
96 function get_db_connection()
98 global $db_connections;
100 $connection = $db_connections[$this->company];
102 //print_r($connection);
104 $db = mysql_connect($connection["host"] ,
105 $connection["dbuser"], $connection["dbpassword"]);
106 mysql_select_db($connection["dbname"],$db);
108 if (!defined('TB_PREF'))
109 define('TB_PREF', $connection["tbpref"]);
114 function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec,
115 $showgl, $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep,
116 $theme, $pagesize, $show_hints, $profile, $rep_popup, $query_size,
117 $graphic_links, $lang, $stickydate, $startup_tab) {
118 update_user_display_prefs($this->user, $price_dec,
119 $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
120 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize,
121 $show_hints, $profile, $rep_popup, $query_size, $graphic_links, $lang, $stickydate, $startup_tab);
124 $user = get_user($this->user);
125 $this->prefs = new user_prefs($user);
129 //--------------------------------------------------------------------------
131 function round2($number, $decimals=0)
133 $delta = ($number < 0 ? -.000001 : .000001);
134 return round($number+$delta, $decimals);
137 function number_format2($number, $decimals=0)
139 global $thoseps, $decseps;
140 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
141 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
142 //return number_format($number, $decimals, $dsep, $tsep);
143 $delta = ($number < 0 ? -.000001 : .000001);
144 return number_format($number+$delta, $decimals, $dsep, $tsep);
149 function fallback_mode() {
150 return $_SESSION["wa_current_user"]->ui_mode==0;
153 function price_format($number) {
154 return number_format2($number,
155 $_SESSION["wa_current_user"]->prefs->price_dec());
158 // 2008-06-15. Added extra parameter $stock_id and reference for $dec
159 //--------------------------------------------------------------------
160 function qty_format($number, $stock_id=null, &$dec) {
161 $dec = get_qty_dec($stock_id);
162 return number_format2($number, $dec);
165 function get_qty_dec($stock_id=null)
167 global $path_to_root;
168 include_once($path_to_root."/inventory/includes/db/items_units_db.inc");
169 if ($stock_id != null)
170 $dec = get_unit_dec($stock_id);
171 if ($stock_id == null || $dec == -1 || $dec == null)
172 $dec = $_SESSION["wa_current_user"]->prefs->qty_dec();
175 //-------------------------------------------------------------------
176 function exrate_format($number) {
177 return number_format2($number,
178 $_SESSION["wa_current_user"]->prefs->exrate_dec());
181 function percent_format($number) {
182 return number_format2($number,
183 $_SESSION["wa_current_user"]->prefs->percent_dec());
186 function user_numeric($input) {
187 global $decseps, $thoseps;
190 $sep = $thoseps[user_tho_sep()];
191 if($sep!='') $num = str_replace( $sep, '', $num);
192 str_replace($sep, '', $num);
193 $sep = $decseps[user_dec_sep()];
194 if($sep!='.') $num = str_replace( $sep, '.', $num);
196 if (!is_numeric($num))
199 if ($num == (int)$num)
205 function user_company()
207 return $_SESSION["wa_current_user"]->company;
212 return $_SESSION["wa_current_user"]->pos;
215 function user_language()
217 return $_SESSION["wa_current_user"]->prefs->language();
220 function user_qty_dec()
222 return $_SESSION["wa_current_user"]->prefs->qty_dec();
225 function user_price_dec()
227 return $_SESSION["wa_current_user"]->prefs->price_dec();
230 function user_exrate_dec()
232 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
235 function user_percent_dec()
237 return $_SESSION["wa_current_user"]->prefs->percent_dec();
240 function user_show_gl_info()
242 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
245 function user_show_codes()
247 return $_SESSION["wa_current_user"]->prefs->show_codes();
250 function user_date_format()
252 return $_SESSION["wa_current_user"]->prefs->date_format();
255 function user_date_display()
257 return $_SESSION["wa_current_user"]->prefs->date_display();
260 function user_date_sep()
262 return $_SESSION["wa_current_user"]->prefs->date_sep();
265 function user_tho_sep()
267 return $_SESSION["wa_current_user"]->prefs->tho_sep();
270 function user_dec_sep()
272 return $_SESSION["wa_current_user"]->prefs->dec_sep();
275 function user_theme()
277 return $_SESSION["wa_current_user"]->prefs->get_theme();
280 function user_pagesize()
282 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
285 function user_hints()
287 return $_SESSION["wa_current_user"]->prefs->show_hints();
290 function user_print_profile()
292 return $_SESSION["wa_current_user"]->prefs->print_profile();
295 function user_rep_popup()
297 return $_SESSION["wa_current_user"]->prefs->rep_popup();
300 function user_query_size()
302 return $_SESSION["wa_current_user"]->prefs->query_size();
305 function user_graphic_links()
307 return $_SESSION["wa_current_user"]->prefs->graphic_links();
310 function sticky_doc_date()
312 return $_SESSION["wa_current_user"]->prefs->sticky_date();
315 function user_startup_tab()
317 return $_SESSION["wa_current_user"]->prefs->start_up_tab();
320 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
321 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
322 $print_profile, $rep_popup, $query_size, $graphic_links, $lang, $stickydate, $startup_tab)
325 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
326 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
327 $print_profile, $rep_popup, $query_size, $graphic_links, $lang, $stickydate, $startup_tab);
330 function add_user_js_data() {
331 global $path_to_root, $thoseps, $decseps, $date_system, $dateseps;
333 $ts = $thoseps[user_tho_sep()];
334 $ds = $decseps[user_dec_sep()];
338 . "theme: '". $path_to_root . '/themes/'. user_theme().'/'."',\n"
339 . "loadtxt: '"._('Requesting data...')."',\n"
340 . "date: '".Today()."',\n" // server date
341 . "datesys: ".$date_system.",\n"
342 . "datefmt: ".user_date_format().",\n"
343 . "datesep: '".$dateseps[user_date_sep()]."',\n"
346 . "pdec : " . user_price_dec() . "}\n";
351 //--------------------------------------------------------------------------
353 function session_timeout()
355 $tout = @get_company_pref('login_tout'); // mask warning for db ver. 2.2
356 return $tout ? $tout : ini_get('session.gc_maxlifetime');