DataObjects/core.sql
[Pman.Core] / DataObjects / Person.php
index 7b823ba..2f9b8de 100644 (file)
@@ -111,7 +111,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         $headers['Date'] = date('r');
         
         return array(
-            'recipents' => $recipents,
+            'recipients' => $recipents,
             'headers'    => $headers,
             'body'      => $body
         );
@@ -130,7 +130,8 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     {
         
         $ar = $this->buildMail($templateFile, $args);
-         
+      
+        
         //print_r($recipents);exit;
         $mailOptions = PEAR::getStaticProperty('Mail','options');
         $mail = Mail::factory("SMTP",$mailOptions);
@@ -138,13 +139,17 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         if (PEAR::isError($mail)) {
             return $mail;
         } 
-        $oe = error_reporting(E_ALL ^ E_NOTICE);
-        $ret = $mail->send($ar['recipents'],$ar['headers'],$ar['body']);
+        $oe = error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT);
+        $ret = $mail->send($ar['recipients'],$ar['headers'],$ar['body']);
         error_reporting($oe);
        
         return $ret;
     
     }
+    
+  
+    
+    
     function getEmailFrom()
     {
         return '"' . addslashes($this->name) . '" <' . $this->email . '>';
@@ -168,11 +173,17 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     function isAuth()
     {
         $db = $this->getDatabaseConnection();
-        $sesPrefix = $db->dsn['database'];
+        // we combine db + project names,
+        // otherwise if projects use different 'auth' objects
+        // then we get unserialize issues.
+        $sesPrefix = get_class($this) .'-'.$db->dsn['database'] ;
+        
+        
         @session_start();
         if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
             // in session...
             $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
+            
             $u = DB_DataObject::factory('Person');
             if ($u->get($a->id)) { //&& strlen($u->passwd)) {
                 $u->verifyAuth();
@@ -192,8 +203,6 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') &&
             $u->get('email', $ff->Pman['local_autoauth'])
         ) {
-            $db = $this->getDatabaseConnection();
-            $sesPrefix = $db->dsn['database'];
             $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($u);
             return true;
         }
@@ -220,7 +229,8 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             return false;
         }
         $db = $this->getDatabaseConnection();
-        $sesPrefix = $db->dsn['database'];
+        $sesPrefix = get_class($this) .'-'.$db->dsn['database'] ;
+        
         if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
             $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
             
@@ -246,8 +256,6 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         $this->isAuth(); // force session start..
         $this->verifyAuth();
         $db = $this->getDatabaseConnection();
-        
-        
         // refresh admin group if we are logged in as one..
         //DB_DataObject::debugLevel(1);
         $g = DB_DataObject::factory('Groups');
@@ -259,10 +267,8 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             $gr = DB_DataObject::Factory('Group_Rights');
             $gr->applyDefs($g, 0);
         }
-            
-            
-        
-        $sesPrefix = $db->dsn['database'];
+             
+        $sesPrefix = get_class($this) .'-'.$db->dsn['database'] ;
         $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($this);
         
     }
@@ -270,7 +276,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     {
         $this->isAuth(); // force session start..
          $db = $this->getDatabaseConnection();
-        $sesPrefix = $db->dsn['database'];
+        $sesPrefix = get_class($this) .'-'.$db->dsn['database'] ;
         $_SESSION[__CLASS__][$sesPrefix .'-auth'] = "";
         
     }    
@@ -311,7 +317,10 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         $x->get($this->company_id);
         return $x;
     }
-    
+    function loadCompany()
+    {
+        $this->company = $this->company();
+    }
     
     function active()
     {
@@ -438,15 +447,16 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     /**
      *Basic group fetching - probably needs to filter by type eventually.
      *
+     *@param String $what - fetchall() argument - eg. 'name' returns names of all groups that they are members of.
      */
     
-    function groups()
+    function groups($what=false)
     {
         $g = DB_DataObject::Factory('Group_Members');
         $grps = $g->listGroupMembership($this);
         $g = DB_DataObject::Factory('Groups');
         $g->whereAddIn('id', $grps, 'int');
-        return $g->fetchAll();
+        return $g->fetchAll($what);
         
     }
     
@@ -468,12 +478,14 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     }    
     
     //  ------------ROO HOOKS------------------------------------
-    function applyFilters($q, $au)
+    function applyFilters($q, $au, $roo)
     {
         //DB_DataObject::DebugLevel(1);
         if (!empty($q['query']['person_not_internal'])) {
             $this->whereAdd(" join_company_id_id.isOwner = 0 ");
         }
+        
+        
         if (!empty($q['query']['person_internal_only_all'])) {
             
             
@@ -520,7 +532,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         $tn_p = $this->tableName();
         $tn_gm = DB_DataObject::Factory('Group_Members')->tableName();
         $tn_g = DB_DataObject::Factory('Groups')->tableName();
-        
+
         ///---------------- Group views --------
         if (!empty($q['query']['in_group'])) {
             // DB_DataObject::debugLevel(1);
@@ -558,12 +570,14 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             }
             
             
+
             if ( $q['query']['not_in_directory'] > -1) {
+                $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
                 // can list current - so that it does not break!!!
-                $x->whereAdd('Person.id NOT IN 
-                    ( SELECT distinct person_id FROM ProjectDirectory WHERE
-                        project_id = ' . $q['query']['not_in_directory'] . ' AND 
-                        company_id = ' . $this->company_id . ')');
+                $x->whereAdd("$tn_p.id NOT IN 
+                    ( SELECT distinct person_id FROM $tn_pd WHERE
+                        project_id = " . $q['query']['not_in_directory'] . " AND 
+                        company_id = " . $this->company_id . ')');
             }
         }
         
@@ -573,9 +587,9 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             //DB_DataObject::debugLevel(1);
             $do = DB_DataObject::factory('ProjectDirectory');
             $do->project_id = $q['query']['project_member_of'];
-            
+            $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
             $this->joinAdd($do,array('joinType' => 'LEFT', 'useWhereAsOn' => true));
-            $this->selectAdd('IF(ProjectDirectory.id IS NULL, 0,  ProjectDirectory.id )  as is_member');
+            $this->selectAdd("IF($tn_pd.id IS NULL, 0,  $tn_pd.id )  as is_member");
                 
                 
             if (!empty($q['query']['project_member_filter'])) {
@@ -589,10 +603,10 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         if (!empty($q['query']['search'])) {
             $s = $this->escape($q['query']['search']);
                     $this->whereAdd("
-                        Person.name LIKE '%$s%'  OR
-                        Person.email LIKE '%$s%'  OR
-                        Person.role LIKE '%$s%'  OR
-                        Person.remarks LIKE '%$s%' 
+                        $tn_p.name LIKE '%$s%'  OR
+                        $tn_p.email LIKE '%$s%'  OR
+                        $tn_p.role LIKE '%$s%'  OR
+                        $tn_p.remarks LIKE '%$s%' 
                         
                     ");
         }
@@ -696,20 +710,11 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             // extra case change passwod?
             case 'P': //??? password
                 // standard perms -- for editing + if the user is dowing them selves..
-                $ret = $isStaff ? $au->hasPerm("Core.Person", "E") : $au->hasPerm("Core.Staff", "E");
+                $ret = $isStaff ? $au->hasPerm("Core.Staff", "E") : $au->hasPerm("Core.Person", "E");
                 return $ret || $au->id == $this->id;
             
-            case 'S': // list..
-                return $au->hasPerm("Core.Person", "S");
-            
-            case 'E': // edit
-                return $isStaff ? $au->hasPerm("Core.Person", "E") : $au->hasPerm("Core.Staff", "E");
-            
-            case 'A': // add
-                return $isStaff ? $au->hasPerm("Core.Person", "A") : $au->hasPerm("Core.Staff", "A");
-            
-            case 'D': // add
-                return $isStaff ? $au->hasPerm("Core.Person", "D") : $au->hasPerm("Core.Staff", "D");
+            default:                
+                return $isStaff ? $au->hasPerm("Core.Staff", $lvl) : $au->hasPerm("Core.Person", $lvl);
         
         }
         return false;