3 include_once($path_to_root . "/includes/prefs/userprefs.inc");
5 //--------------------------------------------------------------------------
20 function current_user()
22 $this->loginname = $username = $this->name = $this->company = "";
23 $this->logged = false;
33 function set_company($company)
35 $this->company = $company;
38 function login($company, $loginname, $password)
40 $this->set_company($company);
42 $Auth_Result = get_user_for_login($loginname, $password);
44 if (db_num_rows($Auth_Result) > 0)
46 $myrow = db_fetch($Auth_Result);
48 $this->access = $myrow["full_access"];
49 $this->name = $myrow["real_name"];
50 $this->loginname = $loginname;
51 $this->username = $this->loginname;
52 $this->prefs = new user_prefs($myrow);
54 update_user_visitdate($loginname);
60 $this->logged = false;
66 function check_user_access()
68 global $security_groups;
69 return is_array($security_groups[$this->access]);
72 function can_access_page($page_level)
74 global $security_groups;
75 // first registered company has site admin privileges
76 return isset($page_level) && in_array($page_level, $security_groups[$this->access])
77 && ($this->company == 0 || $page_level != 20);
80 function get_db_connection()
82 global $db_connections;
84 $connection = $db_connections[$this->company];
86 //print_r($connection);
88 $db = mysql_connect($connection["host"] ,
89 $connection["dbuser"], $connection["dbpassword"]);
90 mysql_select_db($connection["dbname"],$db);
92 if (!defined('TB_PREF'))
93 define('TB_PREF', $connection["tbpref"]);
98 function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec,
99 $showgl, $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep,
100 $theme, $pagesize, $show_hints, $profile, $rep_popup) {
101 update_user_display_prefs($this->username, $price_dec,
102 $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
103 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize,
104 $show_hints, $profile, $rep_popup);
107 $user = get_user($this->username);
108 $this->prefs = new user_prefs($user);
112 //--------------------------------------------------------------------------
114 function number_format2($number, $decimals=0)
116 global $thoseps, $decseps;
117 $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
118 $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
119 return number_format($number, $decimals, $dsep, $tsep);
122 function price_format($number) {
123 return number_format2($number,
124 $_SESSION["wa_current_user"]->prefs->price_dec());
126 // 2008-06-15. Added extra parameter $stock_id and reference for $dec
127 //--------------------------------------------------------------------
128 function qty_format($number, $stock_id=null, &$dec) {
129 $dec = get_qty_dec($stock_id);
130 return number_format2($number, $dec);
133 function get_qty_dec($stock_id=null)
135 global $path_to_root;
136 include_once($path_to_root."/inventory/includes/db/items_units_db.inc");
137 if ($stock_id != null)
138 $dec = get_unit_dec($stock_id);
139 if ($stock_id == null || $dec == -1 || $dec == null)
140 $dec = $_SESSION["wa_current_user"]->prefs->qty_dec();
143 //-------------------------------------------------------------------
144 function exrate_format($number) {
145 return number_format2($number,
146 $_SESSION["wa_current_user"]->prefs->exrate_dec());
149 function percent_format($number) {
150 return number_format2($number,
151 $_SESSION["wa_current_user"]->prefs->percent_dec());
154 function user_numeric($input) {
155 global $decseps, $thoseps;
158 $sep = $thoseps[user_tho_sep()];
159 if($sep!='') $num = str_replace( $sep, '', $num);
160 str_replace($sep, '', $num);
161 $sep = $decseps[user_dec_sep()];
162 if($sep!='.') $num = str_replace( $sep, '.', $num);
164 if (!is_numeric($num))
167 if ($num == (int)$num)
173 function user_company()
175 return $_SESSION["wa_current_user"]->company;
178 function user_language()
180 return $_SESSION["wa_current_user"]->prefs->language();
183 function user_qty_dec()
185 return $_SESSION["wa_current_user"]->prefs->qty_dec();
188 function user_price_dec()
190 return $_SESSION["wa_current_user"]->prefs->price_dec();
193 function user_exrate_dec()
195 return $_SESSION["wa_current_user"]->prefs->exrate_dec();
198 function user_percent_dec()
200 return $_SESSION["wa_current_user"]->prefs->percent_dec();
203 function user_show_gl_info()
205 return $_SESSION["wa_current_user"]->prefs->show_gl_info();
208 function user_show_codes()
210 return $_SESSION["wa_current_user"]->prefs->show_codes();
213 function user_date_format()
215 return $_SESSION["wa_current_user"]->prefs->date_format();
218 function user_date_display()
220 return $_SESSION["wa_current_user"]->prefs->date_display();
223 function user_date_sep()
225 return $_SESSION["wa_current_user"]->prefs->date_sep();
228 function user_tho_sep()
230 return $_SESSION["wa_current_user"]->prefs->tho_sep();
233 function user_dec_sep()
235 return $_SESSION["wa_current_user"]->prefs->dec_sep();
238 function user_theme()
240 return $_SESSION["wa_current_user"]->prefs->get_theme();
243 function user_pagesize()
245 return $_SESSION["wa_current_user"]->prefs->get_pagesize();
248 function user_hints()
250 return $_SESSION["wa_current_user"]->prefs->show_hints();
253 function user_print_profile()
255 return $_SESSION["wa_current_user"]->prefs->print_profile();
258 function user_rep_popup()
260 return $_SESSION["wa_current_user"]->prefs->rep_popup();
263 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
264 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
265 $print_profile, $rep_popup)
268 $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
269 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize, $show_hints,
270 $print_profile, $rep_popup);
273 function add_user_js_data() {
274 global $path_to_root, $thoseps, $decseps;
276 $ts = $thoseps[user_tho_sep()];
277 $ds = $decseps[user_dec_sep()];
279 $js = "\n<script type=\"text/javascript\">\n"
282 . "theme: '". $path_to_root . '/themes/'. 'default' /*user_theme()*/.'/'."',\n"
283 . "loadtxt: '"._('Requesting data...')."',\n"
286 . "pdec : " . user_price_dec() . "}\n--></script>";
291 //--------------------------------------------------------------------------