Merge branch 'master' of http://git.roojs.com:8081/Pman.Core
[Pman.Core] / DataObjects / Person.php
index 2f9b8de..3ab74eb 100644 (file)
@@ -11,21 +11,28 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
 
     public $__table = 'Person';                          // table name
     public $id;                              // int(11)  not_null primary_key auto_increment
+    public $email;                           // string(128)  not_null
+    
+    public $company_id;                      // int(11)  
     public $office_id;                       // int(11)  
+    
     public $name;                            // string(128)  not_null
+    public $firstname;                            // string(128)  not_null
+    public $lastname;                            // string(128)  not_null
     public $phone;                           // string(32)  not_null
     public $fax;                             // string(32)  not_null
-    public $email;                           // string(128)  not_null
-    public $company_id;                      // int(11)  
+    
     public $role;                            // string(32)  not_null
-    public $active;                          // int(11)  not_null
     public $remarks;                         // blob(65535)  not_null blob
     public $passwd;                          // string(64)  not_null
     public $owner_id;                        // int(11)  not_null
     public $lang;                            // string(8)  
     public $no_reset_sent;                   // int(11)  
     public $action_type;                     // string(32)  
-    public $project_id;                      // int(11)  
+    public $project_id;                      // int(11)
+
+    
+    public $active;                          // int(11)  not_null
     public $deleted_by;                      // int(11)  not_null
     public $deleted_dt;                      // datetime(19)  binary
 
@@ -75,13 +82,22 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             (isset($ff->HTTP_HOST) ? $ff->HTTP_HOST : 'localhost');
             
         /* use the regex compiler, as it doesnt parse <tags */
-        require_once 'HTML/Template/Flexy.php';
-        $template = new HTML_Template_Flexy( array(
+        
+        $tops = array(
             'compiler'    => 'Flexy',
             'nonHTML' => true,
             'filters' => array('SimpleTags','Mail'),
             //     'debug'=>1,
-        ));
+        );
+        
+        
+        
+        if (!empty($args['templateDir'])) {
+            $tops['templateDir'] = $args['templateDir'];
+        }
+        
+        require_once 'HTML/Template/Flexy.php';
+        $template = new HTML_Template_Flexy( $tops );
         
      
          
@@ -207,6 +223,23 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             return true;
         }
            
+        // http basic auth..
+        $u = DB_DataObject::factory('Person');
+
+        if (!empty($_SERVER['PHP_AUTH_USER']) 
+            &&
+            !empty($_SERVER['PHP_AUTH_PW'])
+            &&
+            $u->get('email', $_SERVER['PHP_AUTH_USER'])
+            &&
+            $u->checkPassword($_SERVER['PHP_AUTH_PW'])
+           ) {
+            $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($u);
+            return true; 
+        }
+        
+        
+        
         
         // not in session or not matched...
         $u = DB_DataObject::factory('Person');
@@ -261,10 +294,10 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         $g = DB_DataObject::factory('Groups');
         $g->type = 0;
         $g->get('name', 'Administrators');
-        $gm = DB_DataObject::Factory('Group_Members');
+        $gm = DB_DataObject::Factory('group_members');
         if (in_array($g->id,$gm->listGroupMembership($this))) {
             // refresh admin groups.
-            $gr = DB_DataObject::Factory('Group_Rights');
+            $gr = DB_DataObject::Factory('group_rights');
             $gr->applyDefs($g, 0);
         }
              
@@ -323,7 +356,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     }
     
     function active()
-    {
+    { 
         return $this->active;
     }
     function authUserName($n) // set username prior to acheck user exists query.
@@ -386,7 +419,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
       
         // perms + groups.
         $aur['perms']  = $this->getPerms();
-        $g = DB_DataObject::Factory('Group_Members');
+        $g = DB_DataObject::Factory('group_members');
         $aur['groups']  = $g->listGroupMembership($this, 'name');
         
         $aur['passwd'] = '';
@@ -405,7 +438,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         
         // ------ INIITIALIZE IF NO GROUPS ARE SET UP.
         
-        $g = DB_DataObject::Factory('Group_Rights');
+        $g = DB_DataObject::Factory('group_rights');
         if (!$g->count()) {
             $g->genDefault();
         }
@@ -414,13 +447,13 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             return $g->adminRights(); // system is not set up - so they get full rights.
         }
         //DB_DataObject::debugLevel(1);
-        $g = DB_DataObject::Factory('Group_Members');
+        $g = DB_DataObject::Factory('group_members');
         $g->whereAdd('group_id is NOT NULL AND user_id IS NOT NULL');
         if (!$g->count()) {
             // add the current user to the admin group..
             $g = DB_DataObject::Factory('Groups');
             if ($g->get('name', 'Administrators')) {
-                $gm = DB_DataObject::Factory('Group_Members');
+                $gm = DB_DataObject::Factory('group_members');
                 $gm->group_id = $g->id;
                 $gm->user_id = $this->id;
                 $gm->insert();
@@ -429,16 +462,16 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
         }
         
         // ------ STANDARD PERMISSION HANDLING.
-        
-        $g = DB_DataObject::Factory('Group_Members');
+        $isOwner = $this->company()->comptype == 'OWNER';
+        $g = DB_DataObject::Factory('group_members');
         $grps = $g->listGroupMembership($this);
        //var_dump($grps);
         $isAdmin = $g->inAdmin;
         //echo '<PRE>'; print_r($grps);var_dump($isAdmin);
         // the load all the perms for those groups, and add them all together..
         // then load all those 
-        $g = DB_DataObject::Factory('Group_Rights');
-        $ret =  $g->listPermsFromGroupIds($grps, $isAdmin);
+        $g = DB_DataObject::Factory('group_rights');
+        $ret =  $g->listPermsFromGroupIds($grps, $isAdmin, $isOwner);
         //echo '<PRE>';print_r($ret);
         return $ret;
          
@@ -452,7 +485,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
     
     function groups($what=false)
     {
-        $g = DB_DataObject::Factory('Group_Members');
+        $g = DB_DataObject::Factory('group_members');
         $grps = $g->listGroupMembership($this);
         $g = DB_DataObject::Factory('Groups');
         $g->whereAddIn('id', $grps, 'int');
@@ -530,7 +563,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             $this->active = 1;
         }
         $tn_p = $this->tableName();
-        $tn_gm = DB_DataObject::Factory('Group_Members')->tableName();
+        $tn_gm = DB_DataObject::Factory('group_members')->tableName();
         $tn_g = DB_DataObject::Factory('Groups')->tableName();
 
         ///---------------- Group views --------
@@ -574,12 +607,27 @@ 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("$tn_p.id NOT IN 
+                $this->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 . ')');
             }
         }
+           
+        if (!empty($q['query']['role'])) { 
+            // it's a Person list..
+            // DB_DATaobjecT::debugLevel(1);
+            
+            // specific to project directory which is single comp. login
+            //
+            $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
+                // can list current - so that it does not break!!!
+            $this->whereAdd("$tn_p.id IN 
+                    ( SELECT distinct person_id FROM $tn_pd WHERE
+                        role = '". $this->escape($q['query']['role']) ."'
+            )");
+        
+        }
         
         
         if (!empty($q['query']['project_member_of'])) {
@@ -727,7 +775,7 @@ class Pman_Core_DataObjects_Person extends DB_DataObject
             $g->type = 0;
             $g->get('name', 'Administrators');
             
-            $p = DB_DataObject::factory('Group_Members');
+            $p = DB_DataObject::factory('group_members');
             $p->group_id = $g->id;
             $p->user_id = $this->id;     
             if (!$p->count()) {