00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00031 include_once("constant.php");
00032
00033 class cl_user {
00034 var $id;
00035 var $pass;
00036 var $db;
00037 var $admin;
00038 var $valid;
00039
00040 function cl_user ($p_cn,$p_id=-1){
00041
00042 if ( $p_id == -1 ) {
00043 echo_debug('class_user.php',__LINE__," g_user = ".$_SESSION['g_user']);
00044 $this->id=$_SESSION['g_user'];
00045 $this->pass=$_SESSION['g_pass'];
00046 $this->valid=(isset ($_SESSION['isValid']))?1:0;
00047 $this->db=$p_cn;
00048 if ( isset($_SESSION['g_theme']) )
00049 $this->theme=$_SESSION['g_theme'];
00050
00051 $this->admin=( isset($_SESSION['use_admin']) )?$_SESSION['use_admin']:0;
00052
00053 if ( isset($_SESSION['use_name']) )
00054 $this->name=$_SESSION['use_name'];
00055 if ( isset($_SESSION['use_first_name']) )
00056 $this->first_name=$_SESSION['use_first_name'];
00057 }
00058 else
00059 {
00060 $this->id=$p_id;
00061 $this->db=$p_cn;
00062 $Sql="select use_first_name,
00063 use_name,
00064 use_login,
00065 use_active,
00066 use_admin,
00067 from ac_users
00068 where use_id=$p_id";
00069 $cn=DbConnect();
00070 $Res=pg_exec($cn,$Sql);
00071 if (($Max=pg_NumRows($Res)) == 0 ) return -1;
00072 $row=pg_fetch_array($Res,0);
00073 $this->first_name=$row['use_first_name'];
00074 $this->name=$row['use_name'];
00075 $this->active=$row['use_active'];
00076 $this->login=$row['use_login'];
00077 $this->admin=$row['use_admin'];
00078 }
00079 }
00085 function Check()
00086 {
00087
00088 $res=0;
00089 $pass5=md5($this->pass);
00090 if ( $this->valid == 1 ) { return; }
00091 $cn=DbConnect();
00092 if ( $cn != false ) {
00093 $sql="select ac_users.use_login,ac_users.use_active, ac_users.use_pass,
00094 use_admin,use_first_name,use_name
00095 from ac_users
00096 where ac_users.use_login='$this->id'
00097 and ac_users.use_active=1
00098 and ac_users.use_pass='$pass5'";
00099 echo_debug('class_user.php',__LINE__,"Sql = $sql");
00100 $ret=pg_exec($cn,$sql);
00101 $res=pg_NumRows($ret);
00102 echo_debug('class_user.php',__LINE__,"Number of found rows : $res");
00103 if ( $res >0 ) {
00104 $r=pg_fetch_array($ret,0);
00105 $_SESSION['use_admin']=$r['use_admin'];
00106 $_SESSION['use_name']=$r['use_name'];
00107 $_SESSION['use_first_name']=$r['use_first_name'];
00108
00109 $this->admin=$_SESSION['use_admin'];
00110 $this->name=$_SESSION['use_name'];
00111 $this->first_name=$_SESSION['use_first_name'];
00112 $this->GetGlobalPref();
00113
00114 }
00115 }
00116
00117 if ( $res == 0 ) {
00118 echo '<META HTTP-EQUIV="REFRESH" content="4;url=index.html">';
00119 echo "<BR><BR><BR><BR><BR><BR>";
00120 echo "<P ALIGN=center><BLINK>
00121 <FONT size=+12 COLOR=RED>
00122 Invalid user <BR> or<BR> Invalid password
00123 </FONT></BLINK></P></BODY></HTML>";
00124 session_unset();
00125
00126 exit -1;
00127 } else {
00128 $this->valid=1;
00129 }
00130
00131 return $ret;
00132
00133 }
00134
00135 function getJrn() {
00136 }
00143 function Admin() {
00144 $res=0;
00145
00146 if ( $this->id != 'phpcompta') {
00147 $pass5=md5($this->pass);
00148 $sql="select use_id from ac_users where use_login='$this->id'
00149 and use_active=1 and use_admin=1 and use_pass='$pass5'";
00150
00151 $cn=DbConnect();
00152
00153 $this->admin=CountSql($cn,$sql);
00154 } else $this->admin=1;
00155
00156 return $this->admin;
00157 }
00158 function AccessJrn($p_cn,$p_jrn_id) {
00159 $this->Admin();
00160 if ( $this->admin==1) return true;
00161 $sql=CountSql($p_cn,"select uj_id
00162 from user_sec_jrn
00163 where
00164 uj_priv in ('R','W')
00165 and uj_jrn_id=".$p_jrn_id.
00166 " and uj_login = '".$this->id."'");
00167 if ( $sql != 0 ) return true;
00168 return false;
00169
00170 }
00178 function SetPeriode($p_periode) {
00179 $sql="update user_local_pref set parameter_value='$p_periode' where user_id='$this->id' and parameter_type='PERIODE'";
00180 $Res=ExecSql($this->db,$sql);
00181 }
00192 function GetPeriode() {
00193 $array=$this->GetPreferences();
00194 return $array['PERIODE'];
00195 }
00204 function GetPreferences ()
00205 {
00206
00207 $sql="select parameter_type,parameter_value from user_local_pref where user_id='".$this->id."'";
00208 $Res=ExecSql($this->db,$sql);
00209 if (pg_NumRows($Res) == 0 ) {
00210
00211 $sql=sprintf("insert into user_local_pref (user_id,parameter_value,parameter_type)
00212 select '%s',min(p_id),'PERIODE' from parm_periode where p_closed=false",
00213 $this->id);
00214 $Res=ExecSql($this->db,$sql);
00215
00216 $l_array=$this->GetPreferences();
00217 } else {
00218 for ( $i =0;$i < pg_NumRows($Res);$i++) {
00219 $row= pg_fetch_array($Res,0);
00220 $type=$row['parameter_type'];
00221 $l_array[$type]=$row['parameter_value'];
00222 }
00223 }
00224 return $l_array;
00225 }
00237 function CheckAction ( $p_cn,$p_action_id)
00238 {
00239
00240 if ( $this->admin==1 ) return 1;
00241
00242 $Res=ExecSql($p_cn,"select * from user_sec_act where ua_login='".$this->id."' and ua_act_id=$p_action_id");
00243 $Count=pg_NumRows($Res);
00244 if ( $Count == 0 ) return 0;
00245 if ( $Count == 1 ) return 1;
00246 echo "<H2 class=\"error\"> Invalid action !!! $Count select * from user_sec_act where ua_login='$p_login' and ua_act_id=$p_action_id </H2>";
00247 }
00257 function GetGlobalPref()
00258 {
00259 echo_debug('class_user.php',__LINE__,"function GetGlobalPref");
00260 $cn=Dbconnect();
00261
00262 $Res=ExecSql ($cn,"select parameter_type,parameter_value from
00263 user_global_pref
00264 where user_id='".$this->id."'");
00265 $Max=pg_NumRows($Res);
00266 if ( $Max == 0 ) {
00267 $this->insert_default_global_pref();
00268 $this->GetGlobalPref();
00269 return;
00270 }
00271
00272 $line=array();
00273 for ($i=0;$i<$Max;$i++) {
00274 $row=pg_fetch_array($Res,$i);
00275 $type=$row['parameter_type'];
00276 $line[$type]=$row['parameter_value'];;
00277 }
00278
00279 $array_pref=array ('g_theme'=>'THEME','g_pagesize'=>'PAGESIZE');
00280 foreach ($array_pref as $name=>$parameter ) {
00281 if ( ! isset ($line[$parameter]) ) {
00282 echo_debug("Missing pref : ".$parameter);
00283 $this->insert_default_global_pref($parameter);
00284 $this->GetGlobalPref();
00285 return;
00286 }
00287 $_SESSION[$name]=$line[$parameter];
00288 }
00289 }
00290
00299 function insert_default_global_pref($p_type="",$p_value="") {
00300 echo_debug('class_user.php',__LINE__,"function insert_default_global_pref");
00301 echo_debug('class_user.php',__LINE__,"parameter p_type $p_type p_value $p_value");
00302
00303 $default_parameter= array("THEME"=>"Light",
00304 "PAGESIZE"=>"50");
00305 $cn=Dbconnect();
00306 $Sql="insert into user_global_pref(user_id,parameter_type,parameter_value)
00307 values ('%s','%s','%s')";
00308 if ( $p_type == "" ) {
00309 foreach ( $default_parameter as $name=>$value) {
00310 $Insert=sprintf($Sql,$this->id,$name,$value);
00311 ExecSql($cn,$Insert);
00312 }
00313 }
00314 else {
00315 $value=($p_value=="")?$default_parameter[$p_type]:$p_value;
00316 $Insert=sprintf($Sql,$this->id,$p_type,$value);
00317 ExecSql($cn,$Insert);
00318 }
00319
00320
00321 }
00322
00331 function update_global_pref($p_type,$p_value="") {
00332 $default_parameter= array("THEME"=>"Light",
00333 "PAGESIZE"=>"50");
00334 $cn=Dbconnect();
00335 $Sql="update user_global_pref set parameter_value='%s'
00336 where parameter_type='%s' and
00337 user_id='%s'";
00338 $value=($p_value=="")?$default_parameter[$p_type]:$p_value;
00339 $Update=sprintf($Sql,$value,$p_type,$this->id);
00340 ExecSql($cn,$Update);
00341
00342 }
00343 }
00344 ?>