DataObjects/I18n.php
[Pman.Core] / DataObjects / Person.php
index 53a97f4..c80e75e 100644 (file)
@@ -237,15 +237,13 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             (!$this->company_id || ($ff->Pman['auth_comptype'] != $this->company()->comptype))
            ){
             
-            // force a logout - without a check on the isAuth - as this is called from there..
-            $db = $this->getDatabaseConnection();
-            $appname = empty($ff->appNameShort) ? $ff->project : $ff->appNameShort;
-            $sesPrefix =$appname.'-' .get_class($this) .'-'.$db->dsn['database'] ;
+            $sesPrefix = $this->sesPrefix();
        
             $_SESSION[get_class($this)][$sesPrefix .'-auth'] = "";
+            
             return false;
             
-            $ff->page->jerr("Login not permited to outside companies");
+            //$ff->page->jerr("Login not permited to outside companies");
         }
         return true;
         
@@ -258,15 +256,9 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         
         @session_start();
        
-        
-        $db = $this->getDatabaseConnection();
-        // we combine db + project names,
-        // otherwise if projects use different 'auth' objects
-        // then we get unserialize issues.
         $ff= HTML_FlexyFramework::get();
-        $appname = empty($ff->appNameShort) ? $ff->project : $ff->appNameShort;
-        
-        $sesPrefix = $appname .'-' .get_class($this) .'-'.$db->dsn['database'] ;
+       
+        $sesPrefix = $this->sesPrefix();
         
         if (!empty($_SESSION[get_class($this)][$sesPrefix .'-auth'])) {
             // in session...
@@ -276,12 +268,14 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             $u = DB_DataObject::factory($this->tableName());
             if ($a->id && $u->get($a->id)) { //&& strlen($u->passwd)) {
               
-                return $u->verifyAuth();
+                return $u->verifyAuth();  // got authentication...
                 
     
             }
             
             unset($_SESSION[get_class($this)][$sesPrefix .'-auth']);
+            unset($_SESSION[get_class($this)][$sesPrefix .'-timeout']);
+            setcookie('Pman.timeout', -1, time() + (30*60), '/');
             
         }
         if (!$this->canInitializeSystem()) {
@@ -317,6 +311,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         //var_dump($ff->Pman['local_autoauth']);         var_dump($_SERVER); exit;
         $u = DB_DataObject::factory($this->tableName());
         $ff = HTML_FlexyFramework::get();
+        
         if (!empty($ff->Pman['local_autoauth']) && 
             (!empty($_SERVER['SERVER_ADDR'])) &&
             ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
@@ -375,26 +370,32 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         if (!$this->isAuth()) {
             return false;
         }
-        $db = $this->getDatabaseConnection();
         
         $ff= HTML_FlexyFramework::get();
-        $appname = empty($ff->appNameShort) ? $ff->project : $ff->appNameShort;
-
-        $sesPrefix =$appname.'-' .get_class($this) .'-'.$db->dsn['database'] ;
         
+        $sesPrefix = $this->sesPrefix();
         
         //var_dump(array(get_class($this),$sesPrefix .'-auth'));
        
         if (!empty($_SESSION[get_class($this)][$sesPrefix .'-auth'])) {
             $a = unserialize($_SESSION[get_class($this)][$sesPrefix .'-auth']);
             
-            
             $u = DB_DataObject::factory($this->tableName()); // allow extending this ...
             $u->autoJoin();
             if ($u->get($a->id)) { /// && strlen($u->passwd)) {  // should work out the pid .. really..
-                return clone($u);
+                
+                $_SESSION[get_class($this)][$sesPrefix .'-auth-timeout'] = time() + (30*60); // eg. 30 minutes
+                setcookie('Pman.timeout', time() + (30*60), time() + (30*60), '/');
+                
+                $user = clone ($u);
+                
+                return clone($user);
+            
             }
             unset($_SESSION[get_class($this)][$sesPrefix .'-auth']);
+            unset($_SESSION[get_class($this)][$sesPrefix .'-timeout']);
+            setcookie('Pman.timeout', -1, time() + (30*60), '/');
+            
         }
         
         
@@ -440,8 +441,6 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         if (!$this->verifyAuth()) { // check for company valid..
             return false;
         }
-        $db = $this->getDatabaseConnection();
-        
         
         // open up iptables at login..
         $dbname = $this->database();
@@ -458,17 +457,20 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             $gr = DB_DataObject::Factory('group_rights');
             $gr->applyDefs($g, 0);
         }
-        $ff= HTML_FlexyFramework::get();
-        $appname = empty($ff->appNameShort) ? $ff->project : $ff->appNameShort;
-        $sesPrefix =$appname.'-' .get_class($this) .'-'.$db->dsn['database'] ;
-       
+        
+        $sesPrefix = $this->sesPrefix();
         
         // we should not store the whole data in the session - otherwise it get's huge.
         $p = DB_DAtaObject::Factory($this->tableName());
         $p->get($this->pid());
         
+        $d = $p->toArray();
+        
+        $_SESSION[get_class($this)][$sesPrefix .'-auth-timeout'] = time() + (30*60); // eg. 30 minutes
+        setcookie('Pman.timeout', time() + (30*60), time() + (30*60), '/');
+        
         //var_dump(array(get_class($this),$sesPrefix .'-auth'));
-        $_SESSION[get_class($this)][$sesPrefix .'-auth'] = serialize((object)$p->toArray());
+        $_SESSION[get_class($this)][$sesPrefix .'-auth'] = serialize((object)$d);
         // ensure it's written so that ajax calls can fetch it..
         
         
@@ -477,14 +479,12 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     function logout()
     {
         $this->isAuth(); // force session start..
-        $db = $this->getDatabaseConnection();
-        $ff= HTML_FlexyFramework::get();
-        $appname = empty($ff->appNameShort) ? $ff->project : $ff->appNameShort;
-        $sesPrefix =$appname.'-' .get_class($this) .'-'.$db->dsn['database'] ;
         
-         $_SESSION[get_class($this)][$sesPrefix .'-auth'] = "";
-       
+        $sesPrefix = $this->sesPrefix();
         
+        $_SESSION[get_class($this)][$sesPrefix .'-auth-timeout'] = -1;
+        
+        $_SESSION[get_class($this)][$sesPrefix .'-auth'] = "";
         
     }    
     function genPassKey ($t) 
@@ -520,10 +520,10 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
        
     }      
     
-    function generatePassword() // genearte a password (add set 'rawPasswd' to it's value)
+    function generatePassword($length = 5) // genearte a password (add set 'rawPasswd' to it's value)
     {
         require_once 'Text/Password.php';
-        $this->rawPasswd = strtr(ucfirst(Text_Password::create(5)).ucfirst(Text_Password::create(5)), array(
+        $this->rawPasswd = strtr(ucfirst(Text_Password::create($length)).ucfirst(Text_Password::create($length)), array(
         "a"=>"4", "e"=>"3",  "i"=>"1",  "o"=>"0", "s"=>"5",  "t"=>"7"));
         $this->setPassword($this->rawPasswd);
         return $this->rawPasswd;
@@ -692,6 +692,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         if (!isset($pcache[$this->id])) {
             $pcache[$this->id] = $this->getPerms();
         }
+        
        // echo "<PRE>";print_r($pcache[$au->id]);
        // var_dump($pcache[$au->id]);
         if (empty($pcache[$this->id][$name])) {
@@ -871,6 +872,15 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
                     "$tn_p.remarks",
                     "join_company_id_id.name"
             );
+            $tbcols = $this->table();
+            foreach(array('firstname','lastname') as $k) {
+                if (isset($tbcols[$k])) {
+                    $props[] = "{$tn_p}.{$k}";
+                }
+            }
+            
+            
+            
             
             $str =  $x->toSQL(array(
                 'default' => $props,
@@ -1156,6 +1166,8 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         }
     }
     
+    // this is for the To: "{getEmailName()}" <email@address>
+    // not good for Dear XXXX, - use {person.firstname} for that.
     function getEmailName()
     {
         $name = array();
@@ -1176,10 +1188,23 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             
             $name = array_filter($name);
             
-            return $name;
+            return implode(' ', $name);
         }
         
         return $this->email;
     }
     
+    function sesPrefix()
+    {
+        $ff= HTML_FlexyFramework::get();
+        
+        $appname = empty($ff->appNameShort) ? $ff->project : $ff->project . '-' . $ff->appNameShort;
+        
+        $db = $this->getDatabaseConnection();
+        
+        $sesPrefix = $appname.'-' .get_class($this) .'-'.$db->dsn['database'] ;
+
+        return $sesPrefix;
+    }
+    
  }