-class myDB extends DB {
-// Datenbankklasse
-
- var $rc = false;
- var $showErr = false;
- var $db = false;
- var $debug = false;
- var $logsql = false;
- var $errfile = false;
- var $logfile = false;
-
-
-/****************************************************
-* uudecode
-* in: string
-* out: string
-* dekodiert Perl-UU-kodierte Passwort-Strings
-* http://de3.php.net/base64_decode (bug #171)
-*****************************************************/
- function uudecode($encode) {
- $b64chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
- $encode = preg_replace("/^./m","",$encode);
- $encode = preg_replace("/\n/m","",$encode);
- for($i=0; $i<strlen($encode); $i++) {
- if ($encode[$i] == '')
- $encode[$i] = ' ';
- $encode[$i] = $b64chars[ord($encode[$i])-32];
- }
-
- while(strlen($encode) % 4)
- $encode .= "=";
-
- return base64_decode($encode);
- }
-
- function dbFehler($sql,$err) {
- if ($this->showErr)
- echo "$sql : $err\n";
- }
-
- function showDebug($sql) {
- echo $sql."\n";
- if ($this->debug==2) {
- print_r($this->rc);
- };
- }
-
- function logSql($sql) {
- if (!$this->logfile) $this->logfile=fopen("import.sql","a");
- fputs($this->logfile,$sql."\n");
- }
- function myDB($usr) {
- // Datenbankparameter des ERP-Users benutzen.
- $tmp = file_get_contents("../users/$usr.conf");
- preg_match("/dbname => '(.+)'/",$tmp,$hits);
- $dbname=$hits[1];
- preg_match("/dbpasswd => '(.+)'/",$tmp,$hits);
- if ($hits[1]) {
- $dbpasswd=$this->uudecode($hits[1]);
- } else {
- $dbpasswd="";
- };
- preg_match("/dbuser => '(.+)'/",$tmp,$hits);
- $dbuser=$hits[1];
- preg_match("/dbhost => '(.+)'/",$tmp,$hits);
- $dbhost=$hits[1];
- if (!$dbhost) $dbhost="localhost";
- if ($dbpasswd) {
- $dns=$dbuser.":".$dbpasswd."@".$dbhost."/".$dbname;
- } else {
- $dns=$dbuser."@".$dbhost."/".$dbname;
- };
- $dns="pgsql://".$dns;
- $this->db=DB::connect($dns);
- if (!$this->db) DB::dbFehler("oh oh oh",$this->db->getDebugInfo());
- if (DB::isError($this->db)) {
- $this->dbFehler("Connect",$this->db->getDebugInfo());
- die ($this->db->getDebugInfo());
- }
- return $this->db;
- }
-
- function query($sql) {
- $this->rc=@$this->db->query($sql);
- if ($this->logsql) $this->logSql($sql);
- if ($this->debug) $this->showDebug($sql);
- if(DB::isError($this->rc)) {
- $this->dbFehler($sql,$this->rc->getMessage());
- return false;
- } else {
- return $this->rc;
- }
- }
- function getAll($sql) {
- $this->rc=@$this->db->getAll($sql,DB_FETCHMODE_ASSOC);
- if ($this->logsql) $this->logSql($sql);
- if ($this->debug) $this->showDebug($sql);
- if(DB::isError($this->rc)) {
- $this->dbFehler($sql,$this->rc->getMessage());
- return false;
- } else {
- return $this->rc;
- }
- }
+function anmelden() {
+ ini_set("gc_maxlifetime","3600");
+ $tmp = @file_get_contents("../config/authentication.pl");
+ preg_match("/'db'[ ]*=> '(.+)'/",$tmp,$hits);
+ $dbname=$hits[1];
+ preg_match("/'password'[ ]*=> '(.+)'/",$tmp,$hits);
+ $dbpasswd=$hits[1];
+ preg_match("/'user'[ ]*=> '(.+)'/",$tmp,$hits);
+ $dbuser=$hits[1];
+ preg_match("/'host'[ ]*=> '(.+)'/",$tmp,$hits);
+ $dbhost=($hits[1])?$hits[1]:"localhost";
+ preg_match("/'port'[ ]*=> '?(.+)'?/",$tmp,$hits);
+ $dbport=($hits[1])?$hits[1]:"5432";
+ preg_match("/[ ]*\\\$self->\{cookie_name\}[ ]*=[ ]*'(.+)'/",$tmp,$hits);
+ $cookiename=$hits[1];
+ if (!$cookiename) $cookiename='lx_office_erp_session_id';
+ $cookie=$_COOKIE[$cookiename];
+ if (!$cookie) header("location: ups.html");
+ $auth=authuser($dbhost,$dbport,$dbuser,$dbpasswd,$dbname,$cookie);
+ if (!$auth) { return false; };
+ $_SESSION["sessid"]=$cookie;
+ $_SESSION["cookie"]=$cookiename;
+ $_SESSION["employee"]=$auth["login"];
+ $_SESSION["mansel"]=$auth["dbname"];
+ $_SESSION["dbname"]=$auth["dbname"];
+ $_SESSION["dbhost"]=(!$auth["dbhost"])?"localhost":$auth["dbhost"];
+ $_SESSION["dbport"]=(!$auth["dbport"])?"5432":$auth["dbport"];
+ $_SESSION["dbuser"]=$auth["dbuser"];
+ $_SESSION["dbpasswd"]=$auth["dbpasswd"];
+ $_SESSION["db"]=new myDB($_SESSION["dbhost"],$_SESSION["dbuser"],$_SESSION["dbpasswd"],$_SESSION["dbname"],$_SESSION["dbport"],$showErr);
+ $_SESSION["authcookie"]=$authcookie;
+ $sql="select * from employee where login='".$auth["login"]."'";
+ $rs=$_SESSION["db"]->getAll($sql);
+ if(!$rs) {
+ return false;
+ } else {
+ if ($rs) {
+ $tmp=$rs[0];
+ $_SESSION["termbegin"]=(($tmp["termbegin"]>=0)?$tmp["termbegin"]:8);
+ $_SESSION["termend"]=($tmp["termend"])?$tmp["termend"]:19;
+ $_SESSION["Pre"]=$tmp["pre"];
+ $_SESSION["interv"]=($tmp["interv"]>0)?$tmp["interv"]:60;
+ $_SESSION["loginCRM"]=$tmp["id"];
+ $_SESSION["lang"]=$tmp["countrycode"]; //"de";
+ $_SESSION["kdview"]=$tmp["kdview"];
+ $sql="select * from defaults";
+ $rs=$_SESSION["db"]->getAll($sql);
+ $_SESSION["ERPver"]=$rs[0]["version"];
+ return true;
+ } else {
+ return false;
+ }
+ }
+}