DataObjects/pman.ini
authorAlan Knowles <alan@roojs.com>
Fri, 7 Oct 2016 07:02:36 +0000 (15:02 +0800)
committerAlan Knowles <alan@roojs.com>
Fri, 7 Oct 2016 07:02:36 +0000 (15:02 +0800)
DataObjects/Companies.php [deleted file]
DataObjects/Core_groups.php [deleted file]
DataObjects/Group_members.php [deleted file]
DataObjects/Group_rights.php [deleted file]
DataObjects/Office.php [deleted file]
DataObjects/Person.php [deleted file]
DataObjects/Projects.php [deleted file]
DataObjects/pman.ini [deleted file]

diff --git a/DataObjects/Companies.php b/DataObjects/Companies.php
deleted file mode 100644 (file)
index a7830f6..0000000
+++ /dev/null
@@ -1,424 +0,0 @@
-<?php
-/**
- * Table Definition for Companies
- */
-require_once 'DB/DataObject.php';
-
-class Pman_Core_DataObjects_Companies extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'Companies';                       // table name
-    public $code;                            // string(32)  not_null
-    public $name;                            // string(128)  
-    public $remarks;                         // blob(65535)  blob
-    public $owner_id;                        // int(11)  not_null
-    public $address;                         // blob(65535)  blob
-    public $tel;                             // string(32)  
-    public $fax;                             // string(32)  
-    public $email;                           // string(128)  
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $isOwner;                         // int(11)  
-    public $logo_id;                         // int(11)  not_null
-    public $background_color;                // string(8)  not_null
-    public $comptype;                        // string(8)  not_null
-    public $url;                             // string(254)  not_null
-    public $main_office_id;                  // int(11)  not_null
-    public $created_by;                      // int(11)  not_null
-    public $created_dt;                      // datetime(19)  not_null binary
-    public $updated_by;                      // int(11)  not_null
-    public $updated_dt;                      // datetime(19)  not_null binary
-    public $passwd;                          // string(64)  not_null
-    public $dispatch_port;                   // string(255)  not_null
-    public $province;                        // string(255)  not_null
-    public $country;                         // string(4)  not_null
-    public $is_system;                       // int(2)
-    
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    
-    function applyFilters($q, $au)
-    {
-       $tn = $this->tableName();
-        $this->selectAdd("i18n_translate('c' , {$tn}.country, 'en') as country_display_name ");
-      
-        $tn = $this->tableName();
-        //DB_DataObject::debugLevel(1);
-        $x = DB_DataObject::factory('Companies');
-        $x->comptype= 'OWNER';
-        $x->find(true);
-        
-        if (!empty($q['query']['company_project_id'])) {
-            $add = '';
-            if (!empty($q['query']['company_include_self'])) {
-                $add = " OR {$tn}.id = {$x->id}";
-            }
-            if (!empty($q['query']['company_not_self'])) {
-                $add = " AND {$tn}.id != {$x->id}";
-            }
-            $pids = array();
-            $pid = $q['query']['company_project_id'];
-            if (strpos($pid, ',')) {
-                $bits = explode(',', $pid);
-                foreach($bits as $b) {
-                    $pids[] = (int)$b;
-                }
-            } else {
-                $pids = array($pid);
-            }
-            
-            
-            $pids = implode(',', $pids);
-            $this->whereAdd("{$tn}.id IN (
-                SELECT distinct(company_id) FROM ProjectDirectory where project_id IN ($pids)
-            ) $add" );
-             
-        }
-        if (!empty($q['query']['comptype'])) {
-           
-            $this->whereAddIn('comptype', explode(',', $q['query']['comptype']), 'string');
-            
-        }
-        
-        // depricated - should be moved to module specific (texon afair)
-        
-         if (!empty($q['query']['province'])) {
-             $prov = $this->escape($q['query']['province']);
-            $this->whereAdd("province LIKE '$prov%'");
-            
-            
-        }
-        // ADD comptype_display name.. = for combos..
-        $this->selectAdd("
-            (SELECT display_name
-                FROM
-                    core_enum
-                WHERE
-                    etype='comptype'
-                    AND
-                    name={$tn}.comptype
-                LIMIT 1
-                ) as comptype_display_name
-        ");
-        
-        if(!empty($q['search']['name'])){
-            $s = $this->escape($q['search']['name']);
-            $this->whereAdd("
-                {$tn}.name LIKE '%$s%'
-            ");
-        }
-        if(!empty($q['search']['name_starts'])){
-            $s = $this->escape($q['search']['name_starts']);
-            $this->whereAdd("
-                {$tn}.name LIKE '$s%'
-            ");
-        }
-    }
-    
-    function toEventString() {
-        return $this->name;
-    }
-    
-    // ---------- AUTHENTICATION
-     function isAuth()
-    {
-        $db = $this->getDatabaseConnection();
-        $sesPrefix = $db->dsn['database'];
-        @session_start();
-        if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
-            // in session...
-            $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
-            $u = DB_DataObject::factory('Companies');
-            if ($u->get($a->id)) { //&& strlen($u->passwd)) {
-                return true;
-            }
-            $_SESSION[__CLASS__][$sesPrefix .'-auth'] = '';
-            
-        }
-        // not in session or not matched...
-        
-        
-        return false;
-        
-    }
-    function getAuthUser()
-    {
-        if (!$this->isAuth()) {
-            return false;
-        }
-        $db = $this->getDatabaseConnection();
-        $sesPrefix = $db->dsn['database'];
-        if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
-            $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
-            
-            $u = DB_DataObject::factory('Companies');
-            if ($u->get($a->id)) { /// && strlen($u->passwd)) {
-                return clone($u);
-            }
-             
-        }
-        
-        
-        return false;
-    }     
-    function login()
-    {
-        $this->isAuth(); // force session start..
-         $db = $this->getDatabaseConnection();
-        $sesPrefix = $db->dsn['database'];
-        $_SESSION[__CLASS__][$sesPrefix .'-auth'] = serialize($this);
-        
-    }
-    function logout()
-    {
-        $this->isAuth(); // force session start..
-        $db = $this->getDatabaseConnection();
-        $sesPrefix = $db->dsn['database'];
-        $_SESSION[__CLASS__][$sesPrefix .'-auth'] = "";
-        
-    }    
-    // ---------- AUTHENTICATION
-    function checkPassword($val)
-    {
-        //echo '<pre>'.$val .  print_R($this,true);
-        if (substr($this->passwd,0,1) == '$') {
-            return crypt($val,$this->passwd) == $this->passwd ;
-        }
-        // old style md5 passwords...- cant be used with courier....
-        return md5($val) == $this->passwd;
-    }
-    function setPassword($value) 
-    {
-        $salt='';
-        while(strlen($salt)<9) {
-            $salt.=chr(rand(64,126));
-            //php -r var_dump(crypt('testpassword', '$1$'. (rand(64,126)). '$'));
-        }
-        $this->passwd = crypt($value, '$1$'. $salt. '$');
-       
-    }      
-    function onUpload($controller)
-    {
-        $image = DB_DataObject::factory('Images');
-        return $image->onUploadWithTbl($this, 'logo_id');
-         
-    }
-    function  onUpdate($old, $req,$roo) 
-    {
-        if (!empty($req['password1'])) {
-            $this->setPassword($req['password1']);
-            $this->update();
-        }
-    }
-    function onInsert($req, $roo)
-    {
-        if (!empty($this->logo_id)) { // update images table to sycn with this..
-            $img = DB_DataObject::factory('Images');
-            if ($img->get($this->logo_id) && ($img->onid != $this->id)) {
-                $img->onid = $this->id;
-                $img->update();
-            }
-        }
-        if (!empty($req['password1'])) {
-            $this->setPassword($req['password1']);
-            $this->update();
-        }
-        $img = DB_DataObject::factory('Images');
-        $img->onid= 0;
-        
-        $img->ontable = 'Companies';
-        $img->imgtype = 'LOGO';
-        // should check uploader!!!
-        if ($img->find()) {
-            while($img->fetch()) {
-                $ii = clone($img);
-                $ii->onid = $this->id;
-                $ii->update();
-                $this->logo_id = $ii->id;
-            }
-            $this->update();
-        }
-        
-        
-        
-        
-    }
-    
-    function beforeUpdate($old, $q,$roo)
-    {
-        if(!empty($this->is_system) && 
-            ($old->code != $this->code  ) // used to be not allowed to change name..
-        ){
-            $roo->jerr('This company is not allow to editing Ref. or Company Name...');
-        }
-    }
-    
-    function beforeDelete($req, $roo)
-    {
-        // should check for members....
-        if(!empty($this->is_system) && 
-            ($old->code != $this->code || $old->name != $this->name)
-        ){
-            $roo->jerr('This company is not allow to delete');
-        }
-        $img = DB_DataObject::factory('Images');
-        $img->ontable = 'Companies';
-        $img->onid = $this->id;
-        $img->find();
-        while ($img->fetch()) {
-            $img->beforeDelete();
-            $img->delete();
-        }
-        return true;
-        
-         
-    }
-    /**
-     * check who is trying to access this. false == access denied..
-     */
-    function checkPerm($lvl, $au, $changes = false) 
-    {
-        
-        // do we have an empty system..
-        if ($au && $au->id == -1) {
-            return true;
-        }
-        
-        
-        
-        if ($au->company()->comptype != 'OWNER') {
-            
-            // hacking!
-            if ($changes && isset($changes['comptype']) && $changes['comptype'] != $this->comptype) {
-                return false;
-            }
-            
-            return $this->id == $au->company_id;
-        }
-        
-        return $au->hasPerm("Core.Companies", $lvl);    
-    }
-    
-    function logoImageToHTML($size)
-    {
-        $i = DB_DataObject::factory('Images');
-        if (!$this->logo_id || !$i->get($this->logo_id)) {
-            return '';
-        }
-        return $i->toHTML($size);
-        
-    }
-     function firstImage($filter='image/%')
-    {
-        $i = DB_DataObject::factory('Images');
-        //DB_DataObject::debugLevel(1);
-        $im = $i->gather($this, $filter);
-        if (empty($im)) {
-            return false;
-        }
-        return $im[0];
-    }
-    
-    function firstImageTag($size =-1, $base="/Images/Thumb", $filter='image/%')
-    {
-        $fm = $this->firstImage($filter);
-         if (empty($fm)) {
-            return '';
-        }
-        return $fm->toHTML($size, $base);
-    }
-    
-    function toRooSingleArray($authUser, $request)
-    {
-        $ret = $this->toArray();
-       // DB_DataObject::debugLevel(1);
-        // get the comptype display
-        $e = DB_DataObject::Factory('core_enum')->lookupObject('COMPTYPE', $this->comptype);
-        
-        $ret['comptype_display'] = $ret['comptype'];
-        if ($e   && !empty($e->name_display)) {
-            $ret['comptype_display'] = $e->name_display;
-        }
-        
-        
-        return $ret;
-    }
-    
-    /**
-     * # 2028 
-     * create the suppliers...
-     * 
-     * @param object $roo
-     * @param array $data
-     * 
-     */
-    function initCompaniesArray($roo, $data)
-    {
-        $tn = $this->tableName();
-        
-        foreach($data as $d){
-            $com = DB_DataObject::factory($tn);
-            $com->setFrom($d);
-            if(!$com->find(true)){
-                $com->created_dt = Date('Y-m-d H:i:s');
-                $com->updated_dt = Date('Y-m-d H:i:s');
-                $com->is_system = 1;// new column.. block the user changing the code and name..
-                $com->insert();
-            }
-        }
-        
-        
-    }
-    
-    
-    function initCompanies($roo, $opts)
-    {
-        $companies = DB_DataObject::factory('companies');
-        
-        $ctype = empty($opts['add-company-with-type']) ? 'OWNER' : $opts['add-company-with-type'];
-        
-        $enum = DB_DataObject::Factory('core_enum')->lookup('COMPTYPE', $ctype  );
-        
-        if (empty($enum)) {
-            $roo->jerr("invalid company type '$ctype'");
-        }
-        if ($ctype =='OWNER') {
-            $companies = DB_DataObject::factory('companies');
-            $companies->comptype_id = $enum;
-            if ($companies->count()) {
-                $roo->jerr("Owner  company already exists");
-            }
-        }
-        $companies = DB_DataObject::factory('companies');
-        
-        // check that 
-        $companies->setFrom(array(
-            'name' => $opts['add-company'],
-            'comptype' => $ctype,
-            'comptype_id' => $enum,
-        ));
-        if ($companies->find(true)) {
-            $roo->jerr("company already exists");
-        }
-        $companies->setFrom(array(
-            'background_color' => '',
-            'created_dt' => $this->sqlValue('NOW()'),
-            'updated_dt' => $this->sqlValue('NOW()')
-        ));
-        
-        
-        $companies->insert();
-        $companies->onInsert(array(), $roo);
-    }
-    function lookupOwner()
-    {
-        $enum = DB_DataObject::Factory('core_enum')->lookup('COMPTYPE', 'OWNER'  );
-        $companies = DB_DataObject::factory('companies');
-        $companies->comptype_id = $enum;
-        if ($companies->find(true)) {
-            return $companies;
-        }
-        return false;
-    }
-}
diff --git a/DataObjects/Core_groups.php b/DataObjects/Core_groups.php
deleted file mode 100644 (file)
index 1343436..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-<?php
-/**
- * Table Definition for Groups
- *
- * group types
- *
- * 0 = permission group..
- * 1 = team
- * 2 = contact group
- *
- *
- *  NOTE - used to be called Groups ....
- * 
- */
-require_once 'DB/DataObject.php';
-
-class Pman_Core_DataObjects_Core_groups extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'core_groups';                          // table name
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $name;                            // string(64)  not_null
-    public $type;                            // int(11)  
-    public $leader;                          // int(11)  not_null
-    public $is_system;                       // used by timesheets?
-    
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    
-    
-    function memberTable()
-    {
-        return 'core_group_members';
-    }
-    function rightsTable()
-    {
-        return 'core_group_rights';
-    }
-    function personTable()
-    {
-        $ff = HTML_FlexyFramework::get();
-        return empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
-    }
-    
-    
-    // group types??
-    function applyFilters($q, $au, $roo)
-    {
-        if (!empty($q['query']['name_starts'])) {
-            $v = $this->escape($q['query']['name_starts']);
-            $this->whereAdd("{$this->tableName()}.name like '{$v}%'");
-        }
-    }
-    
-    function toEventString() {
-        return $this->name;
-    }
-    
-    function beforeDelete()
-    {
-        $x = DB_DataObject::factory($this->tableName());
-        $x->query("DELETE FROM {$this->rightsTable()} WHERE group_id = {$this->id}");
-        $x->query("DELETE FROM {$this->membersTable()} WHERE group_id = {$this->id}");
-    }
-    /**
-     * check who is trying to access this. false == access denied..
-     */
-    function checkPerm($lvl, $au) 
-    {
-        return $au->hasPerm("Core.Groups", $lvl);    
-    } 
-    function onUpdate($old, $req, $roo)
-    {
-        $this->ensureLeaderMembership($roo);
-    }
-    function onInsert($req, $roo)
-    {
-        $this->ensureLeaderMembership($roo);
-    }
-    function ensureLeaderMembership($roo)
-    {
-        
-        // groups - make sure the leader is a member...
-        if (!$this->type || !$this->leader)
-        {
-            return true;
-        }
-        
-        $pi = DB_DataObject::factory($this->personTable());
-        $pi->get($this->leader);
-            
-        $p = DB_DataObject::factory($this->membersTable());
-        $p->group_id = $this->id;
-        $p->user_id = $this->leader;
-        //$p->type = 1; //???????
-        if (!$p->count()) {
-            
-            $p->insert();
-            $roo->addEvent("ADD", $p, $this->toEventString(). " Added " . $pi->toEventString());
-        }
-             
-    }
-    
-    
-    function memberCount()
-    {
-        $gm = DB_Dataobject::factory($this->membersTable());
-        $gm->group_id = $this->id;
-        return $gm->count();
-    }
-    
-    function memberIds()
-    {
-        $gm = DB_Dataobject::factory($this->membersTable());
-        $gm->group_id = $this->id;
-        return $gm->fetchAll('user_id');
-        
-    }
-    
-    
-    function addMember($person)
-    {
-        $gm = DB_Dataobject::factory($this->membersTable());
-        $gm->group_id = $this->id;
-        $gm->user_id = $person->id;
-        if (!$gm->count()) {
-            $gm->insert();
-        }
-    }
-    /**
-     *
-     *  grab a list of members - default is the array of person objects..
-     *  @param $what  = set to 'email' to get a list of email addresses.
-     *
-     *
-     */
-    
-    function members($what = false)
-    {
-        $ids = $this->memberIds();
-        if (!$ids) {
-            return array();
-        }
-        //$p = DB_Dataobject::factory(empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable']);
-        // groups databse is hard coded to person.. so this should not be used for other tables.????
-        $p = DB_Dataobject::factory( 'Person' );
-        
-        $p->whereAdd('id IN ('. implode(',', $ids) .')');
-        $p->active = 1;
-        return $p->fetchAll($what);
-    }
-    
-    
-    
-    
-    function lookup($k,$v = false) {
-        if ($v === false) {
-            $v = $k;
-            $k = 'id';
-        }
-        $this->get($k,$v);
-
-        return $this;
-    } 
-    
-    function lookUpMembers($name, $what=false)
-    {
-        if (!$this->get('name', $name)) {
-            return array();
-        }
-        return $this->members($what);
-        
-    }
-    
-    function lookupMembersByGroupId($id, $what=false)
-    {
-        if (!$this->get($id)) {
-            return array();
-        }
-        
-        return $this->members($what);
-    }
-    
-    function postListFilter($ar, $au, $req)
-    {      
-        if(!empty($req['_direct_return'])){
-            return $ar;
-        }
-        
-        $ret[] = array( 'id' => 0, 'name' => 'EVERYONE');
-        $ret[] = array( 'id' => -1, 'name' => 'NOT_IN_GROUP');
-        return array_merge($ret, $ar);
-
-    }
-    
-    function initGroups()
-    {
-        
-        $g = DB_DataObject::factory($this->tableName());
-        $g->type = 0;
-        $g->name = 'Administrators';
-        if ($g->count()) {
-            return;
-        }
-        $g->insert();
-        $gr = DB_DataObject::factory($this->rightsTable());
-        $gr->genDefault();
-    }
-    
-    function initDatabase($roo, $data)
-    {
-        $this->initGroups();
-        
-        foreach($data as $gi) {
-            $g = DB_DataObject::factory($this->tableName());
-            $g->setFrom($gi);
-            
-            if(!$g->find(true)){
-                $g->insert();
-            }
-            
-            if(count($g->members()) || empty($gi['members'])){
-                continue;
-            }
-            
-            foreach ($gi['members'] as $m){
-                $g->addMember($m);
-            }
-            
-        }
-     
-    }
-    
-}
diff --git a/DataObjects/Group_members.php b/DataObjects/Group_members.php
deleted file mode 100755 (executable)
index 2512b27..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php
-/**
- * Table Definition for Group_Members
- */
-require_once 'DB/DataObject.php';
-
-class Pman_Core_DataObjects_Group_members extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'group_members';                   // table name
-    public $group_id;                        // int(11)  
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $user_id;                         // int(11)  not_null
-
-    
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    
-   
-    
-    var $inAdmin = false;
-    
-    
-    function change($person, $group, $state)
-    {
-        $gm = DB_DataObject::factory('group_members');
-        $gm->group_id = $group->id;
-        $gm->user_id = $person->id;
-        $gm->find(true);
-        if ($state) {
-            if (!$gm->id) {
-                $gm->insert();
-            }
-            return;
-        }
-        // remove..
-        if ($gm->id) {
-            $gm->delete();
-        }
-        
-    }
-    
-    /**
-     * Get a list of memberships for a person
-     * @param Pman_Core_DataObjects_Person $person who
-     * @param String column to fetch.. eg. group_id or 'name'
-     *
-     */
-    
-    
-    function listGroupMembership($person, $arrayof = 'group_id') 
-    {
-        $this->inAdmin = false;
-        $t = clone($this);
-        //DB_DataObject::debugLevel(1);
-         
-        $grp = DB_DataObject::factory('Groups');
-        $t->joinAdd($grp , 'LEFT');
-        //$person->id = (int)$person->id;
-        $t->whereAdd("
-            user_id = {$person->id}
-        ");
-        $t->selectAdd();
-        $t->selectAdd("distinct(group_id), {$grp->tableName()}.name as name");
-        $t->whereAdd('group_id IS NOT NULL');
-        
-        $t->find();
-        
-        $ret = array() ;
-       // $ret = $arrayof == 'group_id' ? array(0) : array();
-        // default member of 'All groups'!!
-        
-        while ($t->fetch()) {
-            $ret[] = $t->$arrayof;
-            if ($t->name == 'Administrators') { /// mmh... bit risky?
-                $this->inAdmin = true;
-            }
-        }
-        if ($arrayof == 'group_id' && !count($ret)) {
-            $ret = array(0); /// default if they are not a member of any group.
-        }
-        //var_dump($ret);
-        return $ret;
-        
-    }
-    function checkPerm($lvl, $au) 
-    {
-        return false;
-    }
-    
-   
-}
diff --git a/DataObjects/Group_rights.php b/DataObjects/Group_rights.php
deleted file mode 100755 (executable)
index b3877d3..0000000
+++ /dev/null
@@ -1,287 +0,0 @@
-<?php
-/**
- * Table Definition for Group_Rights
- *
- * // what they mean:
-        // A - add
-        // D - delete
-        // E - edit
-        // S - list
-        // P - print / export
-        // I - import
-        // M????
- *
- * 
- */
-require_once 'DB/DataObject.php';
-
-class Pman_Core_DataObjects_Group_rights extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'group_rights';                    // table name
-    public $rightname;                       // string(64)  not_null
-    public $group_id;                        // int(11)  not_null
-    public $accessmask;                      // string(10)  not_null
-    public $id;                              // int(11)  not_null primary_key auto_increment
-
-    
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    
-    
-    var $fullRights = "ADESPIM";
-    
-    
-    function groupsWithRights($rightname, $right)
-    {
-        $t = clone($this);
-        $t->rightname = $rightname;
-        $t->whereAdd("accessmask like '{$this->escape($right)}'");
-        $t->selectAdd();
-        $t->selectAdd('distinct(group_id) as group_id');
-        return $t->fetchAll('group_id');
-         
-    }
-    
-    
-    function listPermsFromGroupIds($grps, $isAdmin=false, $isOwner = false) {
-        
-        $t = clone($this);
-        $t->whereAdd('group_id IN ('. implode(',', $grps).')');
-        $t->autoJoin();
-        $t->find();
-        
-         $ret = array();
-        while($t->fetch()) {
-            
-           
-            
-            
-            if (isset($ret[$t->rightname])) {
-                $ret[$t->rightname] = $this->mergeMask($ret[$t->rightname], $t->accessmask);
-                continue;
-            }
-            $ret[$t->rightname] = $t->accessmask;
-        }
-        // blank out rights that are disabled by the system..
-        $defs = $this->defaultPermData();
-        
-        
-        
-        //echo "<PRE>";print_r($defs);
-        $r = array();
-        foreach($defs as $k=>$v) {
-            
-            
-            
-            if (empty($v[0])) { // delete right if not there..
-                $r[$k] = '';
-                continue;
-            }
-            
-            
-            if (isset($ret[$k])) {
-                if (empty($ret[$k]) && $isAdmin) {
-                    $r[$k] = $v[0] ; // -- it's admin they get rights... can not be disabled..
-                    continue;
-                }
-                // in theory non-owners could sneak in rights here..??
-                $r[$k] = $ret[$k];
-                continue;
-            }
-            // not set contition...
-            if (!$isOwner) {
-                $r[$k] = '';
-                continue;
-            }
-            
-            $r[$k] = $isAdmin ? $v[0] : $v[1];
-            
-       
-        }
-        
-        return $r;
-    }
-    function mergeMask($a, $b) 
-    {
-        // default 
-        $ret = '';
-        for($i=0; $i< strlen($this->fullRights) ; $i++) {
-            if ((strpos($a, $this->fullRights[$i]) > -1) ||
-                (strpos($b, $this->fullRights[$i]) > -1)
-            ) {
-                $ret .= $this->fullRights[$i];
-            }
-        }
-        return $ret;
-        
-        
-    }
-    
-    
-    function defaultPermData()
-    {
-        
-        // we should do better caching of this... really..
-        
-        
-        
-        
-        // what they mean:
-        // A - add
-        // D - delete
-        // E - edit
-        // S - list
-        // P - print / export
-        // I - import
-        // M????
-        
-        
-        $gid = empty($this->group_id) ? 0 : $this->group_id;
-        static $Pman_DataObjects_Group_Right = array();
-        
-        
-        if (!empty($Pman_DataObjects_Group_Right[$gid])) {
-            return $Pman_DataObjects_Group_Right[$gid];
-        }
-        $has_admin = true; ///?? not sure..
-        if ($gid) {
-            $g = DB_DataObject::factory('groups');
-            $g->get($this->group_id);
-            $has_admin = $g->type  == 2 ? false : true;
-        }
-        
-        
-        
-        $ff = HTML_FlexyFramework::get();
-        //print_R($ff);
-        $enabled =  array('Core') ;
-        $enabled = explode(',', $ff->enable);
-        $disabled =  explode(',', $ff->disable? $ff->disable: '');
-        $pman = $ff->rootDir . '/Pman/';
-        $ret = array();
-         //echo '<PRE>';print_r($enabled);
-        foreach($enabled as $module) {
-            
-            if (($module == 'Admin') && !$has_admin) {
-                continue;
-            }
-            
-            $fn = $pman. $module.  '/'.$module. '.perms.json';
-            if (!file_exists($fn)) {
-                continue;
-            }
-            $ar = (array)json_decode(file_get_contents($fn));
-            if (empty($ar)) {
-                // since these are critical files.. die'ing with error is ok.
-                die("invalid json file: " . $fn);
-               }
-           // echo '<PRE>';print_r($ar);
-            foreach($ar as $k=> $perm) {
-                if ($k[0] == '/') {
-                    continue; // it's a comment..
-                }
-                if (in_array($module, $disabled) || in_array($module.'.'. $k, $disabled)) {
-                    continue;
-                }
-                $ret[$module.'.'. $k ] = $perm;
-            }
-            
-        }
-        $Pman_DataObjects_Group_Right[$gid] = $ret;
-       // print_r($ret);
-        return $Pman_DataObjects_Group_Right[$gid];
-         
-        
-    }
-    
-    function adminRights() // get the admin rights - used when no accounts are available..
-    {
-        $defs = $this->defaultPermData();
-        $ret = array();
-        foreach($defs as $k=>$v) {
-            $ret[$k] = $v[0];
-        
-        }
-        return $ret;
-        
-    }
-    
-    function validate()
-    {
-        // all groups must have the minimum privaligess..
-        // admin group must have all the privaliges
-        $g = DB_DataObject::Factory('groups');
-        $g->get($this->group_id);
-        $defs = $this->defaultPermData();
-        switch($g->name) {
-            case "Administrators";
-                $this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][0]);
-                break;
-                
-            default:
-                //$this->accessmask = $this->mergeMask($this->accessmask, $defs[$this->rightname][1]);
-                break;
-        
-        }
-        
-    }
-    /**
-     * generates the default admin group.
-     * and returns it.
-     */
-    function genDefault()
-    {
-        // need to create to special groups, admin & DEFAULT.
-        $g = DB_DataObject::Factory('Groups');
-        //$g->name = 'Default';
-        //if (!$g->find(true)) {
-        //    $g->insert();
-        //}
-        $g->id = 0;
-        $this->applyDefs($g, 1);
-    
-        $g = DB_DataObject::Factory('Groups');
-        $g->name = 'Administrators';
-        $g->type = 0;
-        if (!$g->find(true)) {
-            $g->insert();
-        }
-        $this->applyDefs($g, 0);
-        return $g;
-        
-    }
-        
-    function applyDefs($g, $usecol) {
-        
-        $defs = $this->defaultPermData();
-        //echo '<PRE>';print_r($defs);
-        //$usecol = 1;
-        foreach($defs as $rightname => $defdata) {
-            $gr = DB_DataObject::Factory('group_rights');
-            $gr->rightname  = $rightname;
-            $gr->group_id = $g->id;
-            if (!$gr->find(true)) {
-                $gr->accessmask = $defdata[$usecol];
-                $gr->insert();
-                continue;
-            }
-            $oldgr = clone($gr);
-            $gr->accessmask = $gr->mergeMask($gr->accessmask, $defdata[$usecol]);
-            if ($gr->accessmask == $oldgr->accessmask) {
-                continue;
-            }
-            $gr->update($oldgr);
-        }
-        
-    }
-        
-    function checkPerm($lvl, $au) 
-    {
-        return false;
-    }  
-    
-}
diff --git a/DataObjects/Office.php b/DataObjects/Office.php
deleted file mode 100644 (file)
index 75d47c2..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * Table Definition for Office
- */
-require_once 'DB/DataObject.php';
-
-class Pman_Core_DataObjects_Office extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'Office';                          // table name
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $company_id;                      // int(11)  not_null
-    public $name;                            // string(64)  not_null
-    public $address;                         // blob(65535)  not_null blob
-    public $address2;                         // blob(65535)  not_null blob
-    public $address3;                         // blob(65535)  not_null blob 
-    public $phone;                           // string(32)  not_null
-    public $fax;                             // string(32)  not_null
-    public $email;                           // string(128)  not_null
-    public $role;                            // string(32)  not_null
-    public $country;                         // string(4)
-    
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    function applyFilters($q, $au)
-    {
-        //DB_DataObject::debugLevel(1);
-        $tn  = $this->tableName();
-        $this->selectAdd("   i18n_translate('c' , {$tn}.country, 'en') as office_id_country_name");
-    }
-    
-    
-    function toEventString() {
-        return $this->name;
-    }
-    /**
-     * check who is trying to access this. false == access denied..
-     */
-    function checkPerm($lvl, $au) 
-    {
-        return $au->hasPerm("Core.Offices", $lvl);    
-    }
-    
-    function company()
-    {
-        $c = DB_DataObject::Factory('Companies');
-        $c->get($this->company_id);
-        return $c;
-        
-    }
-    
-    function beforeDelete($dependants_array, $roo)
-    {
-        if (count($dependants_array) != 1) {
-            //$roo->jerr("more than one dependant type....");
-            return true; // standard error message.
-        }
-        
-        $p = DB_DAtaObject::Factory('Person');
-        
-        if (!is_a($dependants_array[0], get_class($p))) {
-            $roo->jerr("dep is not a person..");
-            return true;
-        }
-        
-        $p->office_id = $this->id;
-        if ($p->count() > 1) {
-            return true; // default err..
-        }
-        $p->find(true);
-        $pp = clone($p);
-        $p->office_id = 0;
-        $p->update($pp);
-        return true;
-    }
-    
-    
-}
\ No newline at end of file
diff --git a/DataObjects/Person.php b/DataObjects/Person.php
deleted file mode 100644 (file)
index d2c61b0..0000000
+++ /dev/null
@@ -1,1216 +0,0 @@
-<?php
-/**
- * Table Definition for Person
- */
-require_once 'DB/DataObject.php';
-
-
-class Pman_Core_DataObjects_Person extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'Person';                          // table name
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $email;                           // string(128)  not_null
-    public $alt_email;
-    
-    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 $role;                            // string(32)  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 $active;                          // int(11)  not_null
-    public $deleted_by;                      // int(11)  not_null
-    public $deleted_dt;                      // datetime(19)  binary
-
-
-    public $name_facebook; // VARCHAR(128) NULL;
-    public $url_blog; // VARCHAR(256) NULL ;
-    public $url_twitter; // VARCHAR(256) NULL ;
-    public $url_linkedin; // VARCHAR(256) NULL ;
-    public $linkedin_id; // VARCHAR(256) NULL ;
-    
-    public $phone_mobile; // varchar(32)  NOT NULL  DEFAULT '';
-    public $phone_direct; // varchar(32)  NOT NULL  DEFAULT '';
-    public $countries; // VARCHAR(128) NULL;
-    
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    
-    function owner()
-    {
-        $p = DB_DataObject::Factory($this->tableName());
-        $p->get($this->owner_id);
-        return $p;
-    }
-    
-    /**
-     *
-     *
-     *
-     *
-     *  FIXME !!!! -- USE Pman_Core_Mailer !!!!!
-     *
-     *
-     *
-     *  
-     */
-    function buildMail($templateFile, $args)
-    {
-          
-        $args = (array) $args;
-        $content  = clone($this);
-        
-        foreach((array)$args as $k=>$v) {
-            $content->$k = $v;
-        }
-        
-        $ff = HTML_FlexyFramework::get();
-        
-        
-        //?? is this really the place for this???
-        if (
-                !$ff->cli && 
-                empty($args['no_auth']) &&
-                !in_array($templateFile, array(
-                    // templates that can be sent without authentication.
-                     'password_reset' ,
-                     'password_welcome'
-                 ))
-            ) {
-            
-            $content->authUser = $this->getAuthUser();
-            if (!$content->authUser) {
-                return PEAR::raiseError("Not authenticated");
-            }
-        }
-        
-        // should handle x-forwarded...
-        
-        $content->HTTP_HOST = isset($_SERVER["HTTP_HOST"]) ?
-            $_SERVER["HTTP_HOST"] :
-            (isset($ff->HTTP_HOST) ? $ff->HTTP_HOST : 'localhost');
-            
-        /* use the regex compiler, as it doesnt parse <tags */
-        
-        $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 );
-        $template->compile("mail/$templateFile.txt");
-        
-        /* use variables from this object to ouput data. */
-        $mailtext = $template->bufferedOutputObject($content);
-        
-        $htmlbody = false;
-        // if a html file with the same name exists, use that as the body
-        // I've no idea where this code went, it was here before..
-        if (false !== $template->resolvePath ( "mail/$templateFile.html" )) {
-            $tops['nonHTML'] = false;
-            $template = new HTML_Template_Flexy( $tops );
-            $template->compile("mail/$templateFile.html");
-            $htmlbody = $template->bufferedOutputObject($content);
-            
-        }
-        
-        
-        
-        //echo "<PRE>";print_R($mailtext);
-        //print_R($mailtext);exit;
-        /* With the output try and send an email, using a few tricks in Mail_MimeDecode. */
-        require_once 'Mail/mimeDecode.php';
-        require_once 'Mail.php';
-        
-        $decoder = new Mail_mimeDecode($mailtext);
-        $parts = $decoder->getSendArray();
-        
-        if (PEAR::isError($parts)) {
-            return $parts;
-            //echo "PROBLEM: {$parts->message}";
-            //exit;
-        } 
-        list($recipents,$headers,$body) = $parts;
-        $recipents = array($this->email);
-        if (!empty($content->bcc) && is_array($content->bcc)) {
-            $recipents =array_merge($recipents, $content->bcc);
-        }
-        $headers['Date'] = date('r');
-        
-        if ($htmlbody !== false) {
-            require_once 'Mail/mime.php';
-            $mime = new Mail_mime(array('eol' => "\n"));
-            $mime->setTXTBody($body);
-            $mime->setHTMLBody($htmlbody);
-            // I think there might be code in mediaoutreach toEmail somewhere
-            // h embeds images here..
-            $body = $mime->get();
-            $headers = $mime->headers($headers);
-            
-        }
-        
-         
-        
-        return array(
-            'recipients' => $recipents,
-            'headers'    => $headers,
-            'body'      => $body
-        );
-        
-        
-    }
-    
-    
-    /**
-     * send a template
-     * - user must be authenticate or args[no_auth] = true
-     *   or template = password_[reset|welcome]
-     * 
-     */
-    function sendTemplate($templateFile, $args)
-    {
-        
-        $ar = $this->buildMail($templateFile, $args);
-      
-        
-        //print_r($recipents);exit;
-        $mailOptions = PEAR::getStaticProperty('Mail','options');
-        $mail = Mail::factory("SMTP",$mailOptions);
-        
-        if (PEAR::isError($mail)) {
-            return $mail;
-        } 
-        $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()
-    {
-        if (empty($this->name)) {
-            return $this->email;
-        }
-        return '"' . addslashes($this->name) . '" <' . $this->email . '>';
-    }
-    
-    function toEventString() 
-    {
-        return empty($this->name) ? $this->email : $this->name;
-    } 
-    
-    function verifyAuth()
-    { 
-        $ff= HTML_FlexyFramework::get();
-        if (!empty($ff->Pman['auth_comptype']) &&
-            (!$this->company_id || ($ff->Pman['auth_comptype'] != $this->company()->comptype))
-           ){
-            
-            $sesPrefix = $this->sesPrefix();
-       
-            $_SESSION[get_class($this)][$sesPrefix .'-auth'] = "";
-            
-            return false;
-            
-            //$ff->page->jerr("Login not permited to outside companies");
-        }
-        return true;
-        
-    }    
-   
-   
-    //   ---------------- authentication / passwords and keys stuff  ----------------
-    function isAuth()
-    {
-        
-        @session_start();
-       
-        $ff= HTML_FlexyFramework::get();
-       
-        $sesPrefix = $this->sesPrefix();
-        
-        if (!empty($_SESSION[get_class($this)][$sesPrefix .'-auth'])) {
-            // in session...
-            $a = unserialize($_SESSION[get_class($this)][$sesPrefix .'-auth']);
-            
-            
-            $u = DB_DataObject::factory($this->tableName());
-            if ($a->id && $u->get($a->id)) { //&& strlen($u->passwd)) {
-              
-                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), '/');
-            
-        }
-        
-        // http basic auth..
-        $u = DB_DataObject::factory($this->tableName());
-        
-        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[get_class($this)][$sesPrefix .'-auth'] = serialize($u);
-            return true; 
-        }
-        
-        if (!$this->canInitializeSystem()) {
-            return false;
-        }
-        
-        
-        // local auth - 
-        $default_admin = false;
-        if (!empty($ff->Pman['local_autoauth']) && 
-            ($ff->Pman['local_autoauth'] === true) &&
-            (!empty($_SERVER['SERVER_ADDR'])) &&
-            ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
-            ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')  
-        ) {
-            $group = DB_DataObject::factory('Groups');
-            $group->get('name', 'Administrators');
-            
-            $member = DB_DataObject::factory('group_members');
-            $member->autoJoin();
-            $member->group_id = $group->id;
-            $member->whereAdd("
-                join_user_id_id.id IS NOT NULL
-            ");
-            if($member->find(true)){
-                $default_admin = DB_DataObject::factory($this->tableName());
-                if(!$default_admin->get($member->user_id)){
-                    $default_admin = false;
-                }
-            }
-        }
-        
-        //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') &&
-            ($_SERVER['REMOTE_ADDR'] == '127.0.0.1')  &&
-            ($default_admin ||  $u->get('email', $ff->Pman['local_autoauth']))
-        ) {
-            $_SESSION[get_class($this)][$sesPrefix .'-auth'] = serialize($default_admin ? $default_admin : $u);
-            return true;
-        }
-        
-        //var_dump(session_id());
-        //var_dump($_SESSION[__CLASS__]);
-        
-        //if (!empty(   $_SESSION[__CLASS__][$sesPrefix .'-empty'] )) {
-        //    return false;
-        //}
-        //die("got this far?");
-        // not in session or not matched...
-        $u = DB_DataObject::factory($this->tableName());
-        $u->whereAdd(' LENGTH(passwd) > 0');
-        $n = $u->count();
-        $_SESSION[get_class($this)][$sesPrefix .'-empty']  = $n;
-        $error =  PEAR::getStaticProperty('DB_DataObject','lastError');
-        if ($error) {
-            die($error->toString()); // not really a good thing to do...
-        }
-        if (!$n){ // authenticated as there are no users in the system...
-            return true;
-        }
-        
-        return false;
-        
-    }
-    
-    function canInitializeSystem()
-    {
-        return !strcasecmp(get_class($this) , __CLASS__);
-    }
-    
-    function getAuthUser()
-    {
-        if (!$this->isAuth()) {
-            return false;
-        }
-        
-        $ff= HTML_FlexyFramework::get();
-        
-        $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..
-                
-                $_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), '/');
-            
-        }
-        
-        
-        
-        if (!$this->canInitializeSystem()) {
-            return false;
-        }
-        
-        
-        
-        if (empty(   $_SESSION[get_class($this)][$sesPrefix .'-empty'] )) {
-            $u = DB_DataObject::factory($this->tableName());
-            $u->whereAdd(' LENGTH(passwd) > 0');
-            $_SESSION[get_class($this)][$sesPrefix .'-empty']  = $u->count();
-        }
-                
-             
-        if (isset(   $_SESSION[get_class($this)][$sesPrefix .'-empty'] ) && $_SESSION[get_class($this)][$sesPrefix .'-empty']  < 1) {
-            
-            // fake person - open system..
-            //$ce = DB_DataObject::factory('core_enum');
-            //$ce->initEnums();
-            
-            
-            $u = DB_DataObject::factory($this->tableName());
-            $u->id = -1;
-            
-            // if a company has been created fill that in in company_id_id
-            $c = DB_DAtaObject::factory('Companies')->lookupOwner();
-            if ($c) {
-                $u->company_id_id = $c->pid();
-                $u->company_id = $c->pid();
-            }
-            
-            return $u;
-            
-        }
-        return false;
-    }     
-    function login()
-    {
-        $this->isAuth(); // force session start..
-        if (!$this->verifyAuth()) { // check for company valid..
-            return false;
-        }
-        
-        // open up iptables at login..
-        $dbname = $this->database();
-        touch( '/tmp/run_pman_admin_iptables-'.$dbname);
-         
-        // refresh admin group if we are logged in as one..
-        //DB_DataObject::debugLevel(1);
-        $g = DB_DataObject::factory('Groups');
-        $g->type = 0;
-        $g->get('name', 'Administrators');
-        $gm = DB_DataObject::Factory('group_members');
-        if (in_array($g->id,$gm->listGroupMembership($this))) {
-            // refresh admin groups.
-            $gr = DB_DataObject::Factory('group_rights');
-            $gr->applyDefs($g, 0);
-        }
-        
-        $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)$d);
-        // ensure it's written so that ajax calls can fetch it..
-        
-        
-        
-    }
-    function logout()
-    {
-        $this->isAuth(); // force session start..
-        
-        $sesPrefix = $this->sesPrefix();
-        
-        $_SESSION[get_class($this)][$sesPrefix .'-auth-timeout'] = -1;
-        
-        $_SESSION[get_class($this)][$sesPrefix .'-auth'] = "";
-        
-    }    
-    function genPassKey ($t) 
-    {
-        return md5($this->email . $t. $this->passwd);
-    }
-    function simpleAuthKey($m = 0)
-    {
-        $month = $m > -1 ? date('Y-m') : date('Y-m', strtotime('LAST MONTH'));
-        
-        return md5(implode(',' ,  array($month, $this->email , $this->passwd, $this->id)));
-    } 
-    function checkPassword($val)
-    {
-        
-        if (substr($this->passwd,0,1) == '$') {
-            
-            return crypt($val,$this->passwd) == $this->passwd ;
-        }
-        // old style md5 passwords...- cant be used with courier....
-        return md5($val) == $this->passwd;
-    }
-    
-    function setPassword($value) 
-    {
-        $salt='';
-        while(strlen($salt)<9) {
-            $salt.=chr(rand(64,126));
-            //php -r var_dump(crypt('testpassword', '$1$'. (rand(64,126)). '$'));
-        }
-        $this->passwd = crypt($value, '$1$'. $salt. '$');
-       
-       
-    }      
-    
-    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($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;
-    }
-    
-    function company()
-    {
-        $x = DB_DataObject::factory('Companies');
-        $x->autoJoin();
-        $x->get($this->company_id);
-        return $x;
-    }
-    function loadCompany()
-    {
-        $this->company = $this->company();
-    }
-    
-    function active()
-    { 
-        return $this->active;
-    }
-    function authUserName($n) // set username prior to acheck user exists query.
-    {
-        
-        $this->whereAdd('LENGTH(passwd) > 1'); 
-        $this->email = $n;
-    }
-    function lang()
-    {
-        if (!func_num_args()) {
-            return $this->lang;
-        }
-        $val = array_shift(func_get_args());
-        if ($val == $this->lang) {
-            return;
-        }
-        $uu = clone($this);
-        $this->lang = $val;
-        $this->update($uu);
-        return $this->lang;
-    }
-            
-    
-    function authUserArray()
-    {
-        
-        $aur = $this->toArray();
-        
-        if ($this->id < 1) {
-            return $aur;
-        }
-        
-        
-        //DB_DataObject::debugLevel(1);
-        $c = DB_Dataobject::factory('Companies');
-        $im = DB_Dataobject::factory('Images');
-        $c->joinAdd($im, 'LEFT');
-        $c->selectAdd();
-        $c->selectAs($c, 'company_id_%s');
-        $c->selectAs($im, 'company_id_logo_id_%s');
-        $c->id = $this->company_id;
-        $c->limit(1);
-        $c->find(true);
-        
-        $aur = array_merge( $c->toArray(),$aur);
-        
-        if (empty($c->company_id_logo_id_id))  {
-                 
-            $im = DB_Dataobject::factory('Images');
-            $im->ontable = 'Companies';
-            $im->onid = $c->id;
-            $im->imgtype = 'LOGO';
-            $im->limit(1);
-            $im->selectAdd();
-            $im->selectAs($im,  'company_id_logo_id_%s');
-            if ($im->find(true)) {
-                    
-                foreach($im->toArray() as $k=>$v) {
-                    $aur[$k] = $v;
-                }
-            }
-        }
-      
-        // perms + groups.
-        $aur['perms']  = $this->getPerms();
-        $g = DB_DataObject::Factory('group_members');
-        $aur['groups']  = $g->listGroupMembership($this, 'name');
-        
-        $aur['passwd'] = '';
-        $aur['dailykey'] = '';
-        
-        
-        
-        return $aur;
-    }
-    
-    //   ----------PERMS------  ----------------
-    function getPerms() 
-    {
-         //DB_DataObject::debugLevel(1);
-        // find out all the groups they are a member of.. + Default..
-        
-        // ------ INIITIALIZE IF NO GROUPS ARE SET UP.
-        
-        $g = DB_DataObject::Factory('group_rights');
-        if (!$g->count()) {
-            $g->genDefault();
-        }
-        
-        if ($this->id < 0) {
-            return $g->adminRights(); // system is not set up - so they get full rights.
-        }
-        //DB_DataObject::debugLevel(1);
-        $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->group_id = $g->id;
-                $gm->user_id = $this->id;
-                $gm->insert();
-            }
-            
-        }
-        
-        // ------ STANDARD PERMISSION HANDLING.
-        $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, $isOwner);
-        //echo '<PRE>';print_r($ret);
-        return $ret;
-         
-        
-    }
-    /**
-     *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($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($what);
-        
-    }
-    
-    
-    
-    function hasPerm($name, $lvl) 
-    {
-        static $pcache = array();
-        
-        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])) {
-            return false;
-        }
-        
-        return strpos($pcache[$this->id][$name], $lvl) > -1;
-        
-    }    
-    
-    //  ------------ROO HOOKS------------------------------------
-    function applyFilters($q, $au, $roo)
-    {
-        //DB_DataObject::DebugLevel(1);
-        
-        if (!empty($q['query']['is_owner'])) {
-            $this->whereAdd(" join_company_id_id.comptype = 'OWNER'");
-        }
-        
-        if (!empty($q['query']['person_not_internal'])) {
-            $this->whereAdd(" join_company_id_id.isOwner = 0 ");
-        }
-        
-        if (!empty($q['query']['person_internal_only_all'])) {
-            
-            
-            // must be internal and not current user (need for distribution list)
-            // user has a projectdirectory entry and role is not blank.
-            //DB_DataObject::DebugLevel(1);
-            $pd = DB_DataObject::factory('ProjectDirectory');
-            $pd->whereAdd("role != ''");
-            $pd->selectAdd();
-            $pd->selectAdd('distinct(person_id) as person_id');
-            $roled = $pd->fetchAll('person_id');
-            $rs = $roled  ? "  OR
-                    {$this->tableName()}.id IN (".implode(',', $roled) . ") 
-                    " : '';
-            $this->whereAdd(" join_company_id_id.comptype = 'OWNER' $rs ");
-            
-        }
-        // -- for distribution
-        if (!empty($q['query']['person_internal_only'])) {
-            // must be internal and not current user (need for distribution list)
-            $this->whereAdd(" join_company_id_id.comptype = 'OWNER'");
-            
-            //$this->whereAdd(($this->tableName() == 'Person' ? 'Person' : "join_person_id_id") .
-            //    ".id  != ".$au->id);
-            $this->whereAdd("{$this->tableName()}.id != {$au->id}");
-        } 
-        
-        if (!empty($q['query']['comptype_or_company_id'])) {
-           // DB_DataObject::debugLevel(1);
-            $bits = explode(',', $q['query']['comptype_or_company_id']);
-            $id = (int) array_pop($bits);
-            $ct = $this->escape($bits[0]);
-            
-            $this->whereAdd(" join_company_id_id.comptype = '$ct' OR {$this->tableName()}.company_id = $id");
-            
-        }
-        
-        
-        // staff list..
-        if (!empty($q['query']['person_inactive'])) {
-           // DB_Dataobject::debugLevel(1);
-            $this->active = 1;
-        }
-        $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);
-            $ing = (int) $q['query']['in_group'];
-            if ($q['query']['in_group'] == -1) {
-             
-                // list all staff who are not in a group.
-                $this->whereAdd("{$this->tableName()}.id NOT IN (
-                    SELECT distinct(user_id) FROM $tn_gm LEFT JOIN
-                        $tn_g ON $tn_g.id = $tn_gm.group_id
-                        WHERE $tn_g.type = ".$q['query']['type']."
-                    )");
-                
-                
-            } else {
-                
-                $this->whereAdd("$tn_p.id IN (
-                    SELECT distinct(user_id) FROM $tn_gm
-                        WHERE group_id = $ing
-                    )");
-               }
-            
-        }
-        
-        // #2307 Search Country!!
-        if (!empty($q['query']['in_country'])) {
-            // DB_DataObject::debugLevel(1);
-            $inc = $q['query']['in_country'];
-            $this->whereAdd("$tn_p.countries LIKE '%{$inc}%'");
-        }
-        
-        if (!empty($q['query']['not_in_directory'])) { 
-            // it's a Person list..
-            // DB_DATaobjecT::debugLevel(1);
-            
-            // specific to project directory which is single comp. login
-            //
-            $owncomp = DB_DataObject::Factory('Companies');
-            $owncomp->get('comptype', 'OWNER');
-            if ($q['company_id'] == $owncomp->id) {
-                $this->active =1;
-            }
-            
-            
-
-            if ( $q['query']['not_in_directory'] > -1) {
-                $tn_pd = DB_DataObject::Factory('ProjectDirectory')->tableName();
-                // can list current - so that it does not break!!!
-                $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'])) {
-               // this is also a flag to return if they are a member..
-            //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($tn_pd.id IS NULL, 0,  $tn_pd.id )  as is_member");
-                
-                
-            if (!empty($q['query']['project_member_filter'])) {
-                $this->having('is_member !=0');
-            
-            }
-            
-        }
-        
-        if(!empty($q['query']['name'])){
-            $this->whereAdd("
-                {$this->tableName()}.name LIKE '%{$this->escape($q['query']['name'])}%'
-            ");
-        }
-         if(!empty($q['query']['name_starts'])){
-            $this->whereAdd("
-                {$this->tableName()}.name LIKE '{$this->escape($q['query']['name_starts'])}%'
-            ");
-        }
-        
-        if (!empty($q['query']['search'])) {
-            
-            // use our magic search builder...
-            
-             require_once 'Text/SearchParser.php';
-            $x = new Text_SearchParser($q['query']['search']);
-            
-            $props = array(
-                    "$tn_p.name",
-                    "$tn_p.email",
-                    "$tn_p.role",
-                    "$tn_p.phone",
-                    "$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,
-                'map' => array(
-                    'company' => 'join_company_id_id.name',
-                    //'country' => 'Clipping.country',
-                    //  'media' => 'Clipping.media_name',
-                ),
-                'escape' => array($this->getDatabaseConnection(), 'escapeSimple'), /// pear db or mdb object..
-
-            ));
-            
-            
-            $this->whereAdd($str); /*
-                        $tn_p.name LIKE '%$s%'  OR
-                        $tn_p.email LIKE '%$s%'  OR
-                        $tn_p.role LIKE '%$s%'  OR
-                        $tn_p.phone LIKE '%$s%' OR
-                        $tn_p.remarks LIKE '%$s%' 
-                        
-                    ");*/
-        }
-        
-        // project directory rules -- this may distrupt things.
-        $p = DB_DataObject::factory('ProjectDirectory');
-        // if project directories are set up, then we can apply project query rules..
-        if ($p->count()) {
-            $p->autoJoin();
-            $pids = $p->projects($au);
-            if (isset($q['query']['project_id'])) {   
-                $pid = (int)$q['query']['project_id'];
-                if (!in_array($pid, $pids)) {
-                    $roo->jerr("Project not in users valid projects");
-                }
-                $pids = array($pid);
-            }
-            // project roles..
-            //if (empty($q['_anyrole'])) {  // should be project_directry_role
-            //    $p->whereAdd("{$p->tableName()}.role != ''");
-            // }
-            if (!empty($q['query']['role'])) {  // should be project_directry_role
-                $role = $this->escape($q['query']['role']); 
-               
-                $p->whereAdd("{$p->tableName()}.role LIKE '%{$role}%'");
-                 
-            }
-            
-            if (!$roo->hasPerm('Core.Projects_All', 'S')) {
-                $peps = $p->people($pids);
-                $this->whereAddIn("{$tn}.id", $peps, 'int');
-            }
-        }    
-        
-        // fixme - this needs a more generic fix - it was from the mtrack_person code...
-        if (isset($q['query']['ticket_id'])) {  
-            // find out what state the ticket is in.
-            $t = DB_DataObject::Factory('mtrack_ticket');
-            $t->autoJoin();
-            $t->get($q['query']['ticket_id']);
-            
-            if (!$this->checkPerm('S', $au)) {
-                $roo->jerr("permssion denied to query state of ticket");
-            }
-            
-            $p = DB_DataObject::factory('ProjectDirectory');
-            $pids = array($t->project_id);
-           
-            $peps = $p->people($pids);
-            
-            $this->whereAddIn($this->tableName().'.id', $peps, 'int');
-            
-            //$this->whereAdd('join_prole != ''");
-            
-        }  
-    }
-    function setFromRoo($ar, $roo)
-    {
-        $this->setFrom($ar);
-        if (!empty($ar['passwd1'])) {
-            $this->setPassword($ar['passwd1']);
-        }
-        
-        
-        if (    $this->id &&
-                ($this->email == $roo->old->email)&&
-                ($this->company_id == $roo->old->company_id)
-            ) {
-            return true;
-        }
-        if (empty($this->email)) {
-            return true;
-        }
-        $xx = DB_Dataobject::factory($this->tableName());
-        $xx->setFrom(array(
-            'email' => $this->email,
-           // 'company_id' => $x->company_id
-        ));
-        
-        if ($xx->count()) {
-            return "Duplicate Email found";
-        }
-        return true;
-    }
-    /**
-     *
-     * before Delete - delete significant dependancies..
-     * this is called after checkPerm..
-     */
-    
-    function beforeDelete()
-    {
-        
-        $e = DB_DataObject::Factory('Events');
-        $e->whereAdd('person_id = ' . $this->id);
-        $e->delete(true);
-        
-        // anything else?  
-        
-    }
-    
-    
-    /***
-     * Check if the a user has access to modify this item.
-     * @param String $lvl Level (eg. Core.Projects)
-     * @param Pman_Core_DataObjects_Person $au The authenticated user.
-     * @param boolean $changes alllow changes???
-     *
-     * @return false if no access..
-     */
-    function checkPerm($lvl, $au, $changes=false) //heck who is trying to access this. false == access denied..
-    {
-         
-       // do we have an empty system..
-        if ($au && $au->id == -1) {
-            return true;
-        }
-        // if not authenticated... do not allow in???
-        if (!$au ) {
-            return false;
-        }
-        
-        // determine if it's staff!!!
-        $owncomp = DB_DataObject::Factory('Companies');
-        $owncomp->get('comptype', 'OWNER');
-        $isStaff = ($au->company_id ==  $owncomp->id);
-       
-       
-        if (!$isStaff) {
-            
-            // - can not change company!!!
-            if ($changes && 
-                isset($changes['company_id']) && 
-                $changes['company_id'] != $au->company_id) {
-                return false;
-            }
-            // can only set new emails..
-            if ($changes && 
-                    !empty($this->email) && 
-                    isset($changes['email']) && 
-                    $changes['email'] != $this->email) {
-                return false;
-            }
-            
-            
-            // mtrack had the idea that all 'S' should be allowed.. - but filtered later..
-            // ???? do we want this?
-            
-            // edit self... - what about other staff members...
-            
-            //return $this->company_id == $au->company_id;
-        }
-        
-         
-        // yes, only owner company can mess with this...
-        
-        
-        
-    
-        switch ($lvl) {
-            // extra case change passwod?
-            case 'P': //??? password
-                // standard perms -- for editing + if the user is dowing them selves..
-                $ret = $isStaff ? $au->hasPerm("Core.Staff", "E") : $au->hasPerm("Core.Person", "E");
-                return $ret || $au->id == $this->id;
-            
-            default:                
-                return $isStaff ? $au->hasPerm("Core.Staff", $lvl) : $au->hasPerm("Core.Person", $lvl);
-        
-        }
-        return false;
-    }
-    
-    function beforeInsert($req, $roo)
-    {
-        $p = DB_DataObject::factory('person');
-        if ($roo->authUser->id > -1 ||  $p->count() > 1) {
-            return;
-        }
-        $c = DB_DAtaObject::Factory('Companies');
-        $tc =$c->count();
-        if (!$tc || $tc> 1) {
-            $roo->jerr("can not create initial user as multiple companies already exist");
-        }
-        $c->find(true);
-        $this->company_id = $c->id;
-        
-    }
-    
-    function onInsert($req, $roo)
-    {
-         
-        $p = DB_DataObject::factory('person');
-        if ($roo->authUser->id < 0 && $p->count() == 1) {
-            // this seems a bit risky...
-            
-            $g = DB_DataObject::factory('Groups');
-            $g->initGroups();
-            
-            $g->type = 0;
-            $g->get('name', 'Administrators');
-            
-            $p = DB_DataObject::factory('group_members');
-            $p->group_id = $g->id;
-            $p->user_id = $this->id;     
-            if (!$p->count()) {
-                $p->insert();
-                $roo->addEvent("ADD", $p, $g->toEventString(). " Added " . $this->toEventString());
-            }
-            $this->login();
-        }
-        if (!empty($req['project_id_addto'])) {
-            $pd = DB_DataObject::factory('ProjectDirectory');
-            $pd->project_id = $req['project_id_addto'];
-            $pd->person_id = $this->id; 
-            $pd->ispm =0;
-            $pd->office_id = $this->office_id;
-            $pd->company_id = $this->company_id;
-            $pd->insert();
-        }
-        
-    }
-    
-    function importFromArray($roo, $persons, $opts)
-    {
-        if (empty($opts['prefix'])) {
-            $roo->jerr("opts[prefix] is empty - you can not just create passwords based on the user names");
-        }
-        
-        if (!is_array($persons) || empty($persons)) {
-            $roo->jerr("error in the person data. - empty on not valid");
-        }
-        DB_DataObject::factory('groups')->initGroups();
-        
-        foreach($persons as $person){
-            $p = DB_DataObject::factory('person');
-            if($p->get('name', $person['name'])){
-                continue;
-            }
-            $p->setFrom($person);
-            
-            $companies = DB_DataObject::factory('companies');
-            if(!$companies->get('comptype', 'OWNER')){
-                $roo->jerr("Missing OWNER companies!");
-            }
-            $p->company_id = $companies->pid();
-            // strip the 'spaces etc.. make lowercase..
-            $name = strtolower(str_replace(' ', '', $person['name']));
-            $p->setPassword("{$opts['prefix']}{$name}");
-            $p->insert();
-            // set up groups
-            // if $person->groups is set.. then
-            // add this person to that group eg. groups : [ 'Administrator' ] 
-            if(!empty($person['groups'])){
-                $groups = DB_DataObject::factory('groups');
-                if(!$groups->get('name', $person['groups'])){
-                    $roo->jerr("Missing groups : {$person['groups']}");
-                }
-                $gm = DB_DataObject::factory('group_members');
-                $gm->change($p, $groups, true);
-            }
-            
-            $p->onInsert(array(), $roo);
-        }
-    }
-    
-    // this is for the To: "{getEmailName()}" <email@address>
-    // not good for Dear XXXX, - use {person.firstname} for that.
-    function getEmailName()
-    {
-        $name = array();
-        
-        if(!empty($this->honor)){
-            array_push($name, $this->honor);
-        }
-        
-        if(!empty($this->name)){
-            array_push($name, $this->name);
-            
-            return implode(' ', $name);
-        }
-        
-        if(!empty($this->firstname) || !empty($this->lastname)){
-            array_push($name, $this->firstname);
-            array_push($name, $this->lastname);
-            
-            $name = array_filter($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;
-    }
-    
- }
diff --git a/DataObjects/Projects.php b/DataObjects/Projects.php
deleted file mode 100644 (file)
index 62d2ba3..0000000
+++ /dev/null
@@ -1,300 +0,0 @@
-<?php
-/**
- * Table Definition for Projects
- */
-require_once 'DB/DataObject.php';
-
-class Pman_Core_DataObjects_Projects extends DB_DataObject 
-{
-    ###START_AUTOCODE
-    /* the code below is auto generated do not remove the above tag */
-
-    public $__table = 'Projects';            // table name
-    public $id;                              // int(11)  not_null primary_key auto_increment
-    public $name;                            // string(254)  not_null
-    public $remarks;                         // blob(65535)  not_null blob
-    public $owner_id;                        // int(11)  
-    public $code;                            // string(32)  not_null multiple_key
-    public $active;                          // int(11)  
-    public $type;                            // string(1)  not_null
-    public $client_id;                       // int(11)  not_null
-    public $team_id;                         // int(11)  not_null
-    public $file_location;                   // string(254)  not_null
-    public $open_date;                       // date(10)  binary
-    public $open_by;                         // int(11)  not_null
-    public $close_date;                      // date(10)  binary
-    public $countries;                       // string(128)  not_null
-    public $languages;                       // string(128)  not_null
-    public $agency_id;                       // int(11)  not_null
-    public $updated_dt;                      // datetime(19)  not_null binary
-
-    
-    /* the code above is auto generated do not remove the tag below */
-    ###END_AUTOCODE
-    function getProjectManagers()
-    {
-        $c = DB_DataObject::factory('Companies');
-        $c->isOwner = 1;
-        if (!$c->find(true)) {
-            return array();
-        }
-        
-        
-        $pmids = array();
-        $pd = DB_DataObject::factory('ProjectDirectory');
-        $pd->project_id = $this->id;
-        $pd->company_id = $c->id;
-        $pd->ispm = 1;
-        if (!$pd->count()) {
-            return array();
-        }
-        $pd->selectAdd();
-        $pd->selectAdd('distinct (person_id)');
-        
-        $pd->find();
-        while ($pd->fetch()) {
-            $pmids[] = $pd->person_id;
-            
-        }
-        $ret = array();
-        $p =  DB_DataObject::factory('Person');
-        $p->whereAdd('id IN ('. implode(',', $pmids) .')');
-        $p->find();
-        while ($p->fetch()) {
-            $ret[] = clone($p);
-        }
-        return $ret;
-        
-    }
-
-    function toEventString() {
-        $c = $this->client();
-        return ($c->id ? $c->toEventString() : '??'). ':' . $this->name;
-    }
-    
-    /**
-     * apply filter arguemnts
-     * @param $query - see below
-     * @param $authUser  - authenticated user
-     * 
-     * Query specs:
-     *   [query]
-     *       project_search = text string.
-     *       project_indaterange - a/c/o 
-     *       project_filter = ALL || P,N,U ....
-     * 
-     * // to get a users valid project list - just use array('query' => array('project_filter'=> 'ALL'));
-     * 
-     */
-    
-    function applyFilters($q, $au)
-    {
-         
-        if (!empty($q['query']['project_search'])) {
-            $s = $this->escape($q['query']['project_search']);
-            $this->whereAdd(" (Projects.code LIKE '$s%') OR (Projects.name LIKE '%$s%')");
-        }
-        // types of project to list ... - default is only the open ones...
-        if (!empty($q['query']['project_indaterange'])) {
-            switch($q['query']['project_indaterange']) {
-                case 'A': // all
-                    break; 
-                case 'C': // current
-                     $this->whereAdd('Projects.close_date >= NOW()');
-                    break;
-                case 'O': // old
-                    $this->whereAdd('Projects.close_date < NOW()');
-                    break;
-               }
-        }
-        
-        if (empty($q['query']['project_filter'])  || $q['query']['project_filter'] != 'ALL') {
-            
-               
-            $pf = empty($q['query']['project_filter']) ? 'P,N,U' : $q['query']['project_filter'];
-        
-         
-        
-            $this->whereAddIn("Projects.type", explode(',', $pf), 'string');
-        }
-         // user projects!!!! - make sure they can only see project they are suppsed to..
-         // only applies to document stuff..
-        
-        //&& $au->hasPerm('Documents.Documents','S') << this is dependant on the doc modules
-          
-        if (!$au->hasPerm('Core.Projects_All','S') ) {
-            
-            
-            
-            $pr = DB_DataObject::factory('Projects');
-            $pr->whereAdd("Projects.type IN ('N','X')");
-            $prjs = $pr->fetchAll('id');
-            
-            //DB_DataObject::debugLevel(1);
-            $pd = DB_DataObject::factory('ProjectDirectory');
-            $pd->joinAdd(DB_DataObject::factory('Projects'), 'LEFT');
-            $pd->whereAdd("Projects.type NOT IN ('N','X')");
-            $pd->person_id = $au->id;
-            
-            $prjs = array_merge($prjs, $pd->fetchAll('project_id'));
-            if (count($prjs)) {
-                $this->whereAdd("
-                     (Projects.id IN (".implode(',', $prjs).")) 
-                ");
-            }  else {
-                $this->whereAdd("1=0"); // can see nothing!!!
-            }
-        }
-        
-        if (!empty($q['query']['distinct_client_id'])) {
-          // DB_DataObjecT::debuglevel(1);
-            $this->selectAdd();
-            $this->selectAdd('distinct(client_id)');
-            $this->selectAs(DB_DataObject::factory('Companies'), 'client_id_%s','join_client_id_id');
-            $this->groupBy('client_id');
-             
-        }
-        
-        // this is clipping related..  -- we should have an API for addons like this.. (and docs)
-        
-       
-        
-        
-        
-                 
-        
-        
-        
-    }
-    function onInsert()
-    {
-        $oo = clone($this);
-        if (empty($this->code)) {
-            $this->code = 'C' + $this->client_id + '-P' + $this->id;
-            $dt = new DateTime();
-            $this->updated_dt = $dt->format('Y-m-d H:i:s');
-            $this->update($oo);
-        }
-    }
-    
-    function onUpdate($old)
-    {
-        $oo = clone($this);
-        if (empty($this->code)) {
-            $this->code = 'C' + $this->client_id + '-P' + $this->id;
-            $dt = new DateTime();
-            $this->updated_dt = $dt->format('Y-m-d H:i:s');
-            $this->update($oo);
-        }
-        
-        if ($old->code == $this->code) {
-            return;
-        }
-        
-        $opts = HTML_FlexyFramework::get()->Pman;
-        
-        $olddir =  $opts['storedir'] . '/' . $old->code;
-        $newdir =  $opts['storedir'] . '/' . $this->code;
-        if ( file_exists($olddir)) {
-            rename($olddir, $newdir);
-        }
-         
-        
-    }
-    
-    function prune()
-    {
-        if (!$this->prune) { // non-expiring..
-            return;
-        }
-        
-        $d = DB_DataObject::factory('Document');
-        $d->whereAdd("date_rec < NOW - INTERVAL {$this->expires} DAYS"); 
-        $d->find();
-        while ($d->fetch()) {
-            $d->prune();
-        }
-        
-        
-        
-        
-        
-        
-        
-    }
-    /**
-     * our camp interface uses the format Cxxx-Pyyyyyy to refer to the project.
-     */
-    function getByCodeRef($str)
-    {
-        $bits = explode('-', $str);
-        if ((count($bits) != 2) || $bits[0][0] != 'C' ||  $bits[1][0] != 'P' ) {
-            return false;
-        }
-        $comp = substr($bits[0], 1);
-        $id = (int) substr($bits[1], 1);
-        return $id && $this->get($id);
-        
-    }
-    
-   
-    
-    
-   
-    function setFromRoo($q) 
-    {
-        $this->setFrom($q);
-        if (isset($q['open_date'])) {
-            $this->open_date = date('Y-m-d', strtotime(
-                implode('-', array_reverse(explode('/', $q['open_date'])))
-            ));
-        }
-        return true;
-    }
-    
-    
-    /**
-     * fetch a list of user projects.
-     * if you need to filter open/closed.. then add whereAdds before calling
-     */
-    function userProjects($au, $data='id') // COMPANY BASED!!!!
-    {
-        
-        $id = (int) $au->company_id;
-        
-        $this->whereAdd("
-            (client_id= $id) OR (agency_id= $id)
-        ");
-        
-        return empty($data) ? $this->fetchAll() :$this->fetchAll($data); 
-         
-            
-    }
-    
-    // DEPRICATED - use userProjects
-    
-    function getUserProjects($au, $data='id') // COMPANY BASED!!!!
-    {
-        return $this->userProjects($au, $data);
-         
-            
-    }
-    
-    
-    function client()
-    {
-        $c = DB_DataObject::factory('Companies');
-        $c->get($this->client_id);
-        return $c;
-    }
-    
-    /**
-     * check who is trying to access this. false == access denied..
-     */
-    function checkPerm($lvl, $au) 
-    {
-        return $au->hasPerm("Core.Projects_Member_Of",$lvl) || $au->hasPerm("Core.Projects_All",$lvl);
-    }
-    
-}
diff --git a/DataObjects/pman.ini b/DataObjects/pman.ini
deleted file mode 100644 (file)
index 0ac280c..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-
-[Companies]
-code = 130
-name = 2
-remarks = 66
-owner_id = 129
-address = 66
-tel = 2
-fax = 2
-email = 2
-id = 129
-isOwner = 1
-logo_id = 129
-background_color = 130
-comptype = 130
-
-url = 130
-main_office_id = 129
-created_by = 129
-created_dt = 142
-updated_by = 129
-updated_dt = 142
-passwd = 130
-
-dispatch_port = 130
-province = 130
-country = 130
-
-[Companies__keys]
-id = N
-
-[Events]
-id = 129
-person_name = 2
-event_when = 14
-action = 2
-ipaddr = 2
-on_id = 1
-on_table = 2
-person_id = 1
-remarks = 66
-
-[Events__keys]
-id = N
-
-[group_members]
-group_id = 1
-id = 129
-user_id = 129
-
-[group_members__keys]
-id = N
-
-[group_rights]
-rightname = 130
-group_id = 129
-AccessMask = 130
-id = 129
-
-[group_rights__keys]
-id = N
-
-[Groups]
-id = 129
-name = 130
-type = 1
-leader = 129
-
-[Groups__keys]
-id = N
-
-[Images]
-id = 129
-filename = 130
-ontable = 130
-onid = 129
-mimetype = 130
-width = 129
-height = 129
-filesize = 129
-displayorder = 129
-language = 130
-parent_image_id = 129
-created = 142
-imgtype = 130
-linkurl = 130
-descript = 194
-title = 130
-
-[Images__keys]
-id = N
-
-[Office]
-id = 129
-company_id = 129
-name = 130
-address = 194
-phone = 130
-fax = 130
-email = 130
-role = 130
-
-[Office__keys]
-id = N
-
-[Person]
-id = 129
-office_id = 1
-name = 130
-phone = 130
-fax = 130
-email = 130
-company_id = 1
-role = 130
-active = 1
-remarks = 194
-passwd = 130
-owner_id = 129
-lang = 2
-no_reset_sent = 1
-project_id = 1
-action_type = 2
-deleted_by = 1
-deleted_dt = 142
-
-
-
-[Person__keys]
-id = N
-
-[Projects]
-id = 129
-name = 130
-remarks = 194
-owner_id = 1
-code = 130
-active = 1
-type = 130
-client_id = 129
-team_id = 129
-file_location = 130
-open_date = 6
-open_by = 129
-countries = 130
-languages = 130
-close_date = 6
-agency_id = 129
-
-[Projects__keys]
-id = N
-
-[i18n]
-id = 129
-ltype = 130
-lkey = 130
-inlang = 130
-lval = 130
-
-[i18n__keys]
-id = N
-
-[proftp_groups]
-id = 129
-grpid = 129
-grpname = 130
-grpmembers = 66
-
-[proftp_groups__keys]
-id = N
-
-[translations]
-id = 129
-module = 130
-tfile = 130
-tlang = 130
-tkey = 130
-tval = 194
-
-[translations__keys]
-id = N
-
-[core_company_type]
-id = 129
-name = 130
-
-[core_company_type__keys]
-id = N
-
-[core_image_type]
-id = 129
-name = 130
-
-[core_image_type__keys]
-id = N
-