*** empty log message ***
[fa-stable.git] / includes / current_user.inc
1 <?php
2
3 include_once($path_to_root . "/includes/prefs/userprefs.inc");
4
5 //--------------------------------------------------------------------------
6
7 class current_user 
8 {
9
10         var $loginname;
11         var $username;
12         var     $name;
13         var $company;
14         var $access;
15
16         var $logged;
17
18         var $prefs;
19
20         function current_user()
21         {
22                 $this->loginname = $username = $this->name = $this->company = "";
23                 $this->logged = false;
24
25                 $this->prefs = null;
26         }
27
28         function logged_in()
29         {
30                 return $this->logged;
31         }
32
33         function set_company($company)
34         {
35                 $this->company = $company;
36         }
37
38         function login($company, $loginname, $password)
39         {
40                 $this->set_company($company);
41
42                 $Auth_Result = get_user_for_login($loginname, $password);
43
44                 if (db_num_rows($Auth_Result) > 0)
45                 {
46             $myrow = db_fetch($Auth_Result);
47
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);
53
54                         update_user_visitdate($loginname);
55                         $this->logged = true;
56                 } 
57                 else 
58                 {
59                         $this->logged = false;
60                 }
61
62                 return $this->logged;
63         }
64
65         function check_user_access()
66         {
67                 global $security_groups;
68                 return is_array($security_groups[$this->access]);
69         }
70
71         function can_access_page($page_level)
72         {
73                 global $security_groups;
74                 return isset($page_level) && in_array($page_level, $security_groups[$this->access]);
75         }
76
77         function get_db_connection()
78         {
79         global $db_connections;
80
81         $connection = $db_connections[$this->company];
82
83         //print_r($connection);
84
85         $db = mysql_connect($connection["host"] ,
86                 $connection["dbuser"], $connection["dbpassword"]);
87         mysql_select_db($connection["dbname"],$db);
88                 
89                 if (!defined('TB_PREF'))
90                         define('TB_PREF', $connection["tbpref"]);
91                 
92         return $db;
93         }
94
95         function update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
96                 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize) {
97                 update_user_display_prefs($this->username, $price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl,
98                         $showcodes, $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize);
99
100                 // re-read the prefs
101                 $user = get_user($this->username);
102                 $this->prefs = new user_prefs($user);
103         }
104 }
105
106 //--------------------------------------------------------------------------
107
108 function number_format2($number, $decimals=0) 
109 {
110         global $thoseps, $decseps;
111         $tsep = $thoseps[$_SESSION["wa_current_user"]->prefs->tho_sep()];
112         $dsep = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()];
113         return number_format($number, $decimals, $dsep, $tsep);
114 }
115
116 function user_company() 
117 {
118         return $_SESSION["wa_current_user"]->company;
119 }
120
121 function user_language() 
122 {
123         return $_SESSION["wa_current_user"]->prefs->language();
124 }
125
126 function user_qty_dec() 
127 {
128         return $_SESSION["wa_current_user"]->prefs->qty_dec();
129 }
130
131 function user_price_dec() 
132 {
133         return $_SESSION["wa_current_user"]->prefs->price_dec();
134 }
135
136 function user_exrate_dec() 
137 {
138         return $_SESSION["wa_current_user"]->prefs->exrate_dec();
139 }
140
141 function user_percent_dec() 
142 {
143         return $_SESSION["wa_current_user"]->prefs->percent_dec();
144 }
145
146 function user_show_gl_info() 
147 {
148         return $_SESSION["wa_current_user"]->prefs->show_gl_info();
149 }
150
151 function user_show_codes() 
152 {
153         return $_SESSION["wa_current_user"]->prefs->show_codes();
154 }
155
156 function user_date_format() 
157 {
158         return $_SESSION["wa_current_user"]->prefs->date_format();
159 }
160
161 function user_date_display() 
162 {
163         return $_SESSION["wa_current_user"]->prefs->date_display();
164 }
165
166 function user_date_sep() 
167 {
168         return $_SESSION["wa_current_user"]->prefs->date_sep();
169 }
170
171 function user_tho_sep() 
172 {
173         return $_SESSION["wa_current_user"]->prefs->tho_sep();
174 }
175
176 function user_dec_sep() 
177 {
178         return $_SESSION["wa_current_user"]->prefs->dec_sep();
179 }
180
181 function user_theme() 
182 {
183         return $_SESSION["wa_current_user"]->prefs->get_theme();
184 }
185
186 function user_pagesize() 
187 {
188         return $_SESSION["wa_current_user"]->prefs->get_pagesize();
189 }
190
191 function set_user_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
192         $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize) 
193 {
194
195         $_SESSION["wa_current_user"]->update_prefs($price_dec, $qty_dec, $exrate_dec, $percent_dec, $showgl, $showcodes,
196                 $date_format, $date_sep, $tho_sep, $dec_sep, $theme, $pagesize);
197 }
198
199 //--------------------------------------------------------------------------
200
201 ?>