addUser('a','b','test','michal@kamdata.com',1); } function addUser ($userName,$givenPassword,$fullName,$email,$sUser=0,$sBlokovani=0) { $s=sprintf('insert into KAMuzivatel (Jmeno,Heslo,PlneJmeno,Email,DatVlozeni,Suser,Blokovani) values (%s,%s,%s,%s,now(),%d,%d)',TextSQL(LCrypt(Dorovnej($userName,100))),TextSQL(md5($givenPassword)),TextSQL(LCrypt(Dorovnej($fullName,100))),TextSQL(LCrypt(Dorovnej($email,100))),$sUser,$sBlokovani); $this->doLockedSQL('KAMuzivatel',$s); } function changeUser($IDuz,$userName,$fullName,$email,$sUser=0,$sBlokovani=0) { $s=sprintf('update KAMuzivatel set Jmeno=%s, PlneJmeno=%s, Email=%s, Suser=%d, Blokovani=%d where ID=%d',TextSQL(LCrypt(Dorovnej($userName,100))),TextSQL(LCrypt(Dorovnej($fullName,100))),TextSQL(LCrypt(Dorovnej($email,100))),$sUser,$sBlokovani,$IDuz); $this->doUpdate('KAMuzivatel',$s); } function doLogin($userName,$givenPassword) { $ok=false; $s=sprintf('select ID, PlneJmeno, Suser from KAMuzivatel where Jmeno=%s and Heslo=%s and Blokovani=0',TextSQL(LCrypt(Dorovnej($userName,100))),TextSQL(md5($givenPassword))); $this->doQuery($s); if ($this->result) { if ($this->getNumRow()==1) { $this->getNextRow(); $ID=$this->record["ID"]; $PlneJmeno=trim(LDecrypt($this->record["PlneJmeno"])); $Suser=$this->record["Suser"]; session_start(); $_SESSION["IDuziv"]=$ID; $_SESSION["JmenoUziv"]=$PlneJmeno; $_SESSION["TypUziv"]=$Suser; $_SESSION["Timestamp"]=time(); $this->doLockedSQL('KAMuzivatel','update KAMuzivatel set DatPrihlaseni=now() where ID='.$ID); $ok=true; } } return $ok; } function doLogout($sessionNotRunning=true) { if ($sessionNotRunning) session_start(); session_unset(); session_destroy(); } function checkLogin($s='admlogin.php?ErrCode=2') { $ok=false; session_start(); if ((IsSet($_SESSION["IDuziv"]))&&(IsSet($_SESSION["TypUziv"]))&&(IsSet($_SESSION["Timestamp"]))) { if (($_SESSION["IDuziv"]!=0)&&(($_SESSION["Timestamp"]+30*60)>=time())) { $_SESSION["Timestamp"]=time(); $ok=true; } } if (!$ok) { $this->doLogout(false); Header('Location: '.$s); Exit(); } } function checkLoginAdmin($s='admlogin.php?ErrCode=2') { $this->checkLogin($s); if ($_SESSION["TypUziv"]!=1) { $this->doLogout(false); Header('Location: '.$s); Exit(); } } function changePasswordByID ($ID,$givenPassword) { $this->doUpdate('KAMuzivatel','update KAMuzivatel set Heslo='.TextSQL(md5($givenPassword)).' where ID='.$ID); } function changePasswordByEmail ($email,$givenPassword) { $s=sprintf('update KAMuzivatel set Heslo=%s where Blokovani=0 and Email=%s',TextSQL(md5($givenPassword)),TextSQL(LCrypt(Dorovnej($email,100)))); $this->doUpdate('KAMuzivatel',$s); } function userBlock($ID) { $s='update KAMuzivatel set Blokovani=1 where ID='.$ID; $this->doUpdate('KAMuzivatel',$s); } function userUnblock($ID) { $s='update KAMuzivatel set Blokovani=0 where ID='.$ID; $this->doUpdate('KAMuzivatel',$s); } function userExists($name) { $ok=false; $this->doQuery ('select count(*) from KAMuzivatel where Jmeno='.TextSQL(LCrypt(Dorovnej($name,100)))); $this->getNextRow(); if ($this->record[0]==1) $ok=true; return $ok; } function emailExists($email) { $ok=false; $this->doQuery ('select count(*) from KAMuzivatel where Email='.TextSQL(LCrypt(Dorovnej($email,100)))); $this->getNextRow(); if ($this->record[0]==1) $ok=true; return $ok; } function doUpdate($table,$s) { $this->doLockedSQL($table,$s);; } function doLockedSQL($table,$s) { $this->lock($table); $this->doQuery($s); $this->unlock(); } function doExists($s) { $ok=false; $this->doQuery($s); if ($this->result) { $this->getNextRow(); if ($this->record[0]>0) $ok=true; } return $ok; } function convertDokType ($i) { $ok=""; switch ($i) { case 0: $ok="txt"; break; case 1: $ok="html"; break; case 2: $ok="pdf"; break; case 3: $ok="ps"; break; case 4: $ok="doc"; break; case 5: $ok="xls"; break; case 6: $ok="ppt"; break; case 7: $ok="jpg"; break; } return $ok; } function mimeDokType ($i) { $ok="text/plain"; switch ($i) { case 0: $ok="text/plain"; break; case 1: $ok="text/html"; break; case 2: $ok="application/pdf"; break; case 3: $ok="application/postscript"; break; case 4: $ok="application/msword"; break; case 5: $ok="application/vnd.ms-excel"; break; case 6: $ok="application/vnd.ms-powerpoint"; break; case 7: $ok="image/jpeg"; break; } return $ok; } } ?>