fix #8131 - chinese translations
[Pman.Core] / DataObjects / Core_company.php
index cb0af57..4ae8fb3 100644 (file)
@@ -35,10 +35,17 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
     public $country;                         // string(4)  not_null
     public $is_system;                       // int(2)
     
+    
+    public $comptype_id;
+    public $address1;
+    public $address2;
+    public $address3;
+    
+    
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
     
-    function applyFilters($q, $au)
+    function applyFilters($q, $au, $roo)
     {
         
         $tn = $this->tableName();
@@ -79,7 +86,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
         }
         if (!empty($q['query']['comptype'])) {
            
-            $this->whereAddIn('comptype', explode(',', $q['query']['comptype']), 'string');
+            $this->whereAddIn($tn.'.comptype', explode(',', $q['query']['comptype']), 'string');
             
         }
         
@@ -134,7 +141,9 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
     {
         $db = $this->getDatabaseConnection();
         $sesPrefix = $db->dsn['database'];
-        @session_start();
+        if  (empty($_SERVER['PHP_AUTH_USER'])) {
+            @session_start();
+        }
         if (!empty($_SESSION[__CLASS__][$sesPrefix .'-auth'])) {
             // in session...
             $a = unserialize($_SESSION[__CLASS__][$sesPrefix .'-auth']);
@@ -255,6 +264,18 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
     {
         // we still use comptype in some old systems...
         
+        if(!empty($q['comptype']) && empty($q['comptype_id'])) {
+            $en = DB_DataObject::Factory('core_enum');
+            $en->setFrom(array(
+                'etype' => 'COMPTYPE',
+                'name' => $q['comptype'],
+                'active' => 1
+            ));
+            if($en->find(true)) {
+                $this->comptype_id = $en->id;
+            }
+        }
+        
         if (!empty($q['comptype_id'])) {
             $en = DB_DataObject::Factory('core_enum');
             $en->get($q['comptype_id']);
@@ -266,7 +287,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
                 $roo->jok('OK');
             }
             
-            $roo->jerr('EXIST');
+            $roo->jerror('NOTICE-EXIST-CHECK','EXIST');
         }
     }
     
@@ -274,13 +295,24 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
     {
         // we still use comptype in some old systems...
         
+        if(!empty($q['comptype']) && empty($q['comptype_id'])) {
+            $en = DB_DataObject::Factory('core_enum');
+            $en->setFrom(array(
+                'etype' => 'COMPTYPE',
+                'name' => $q['comptype'],
+                'active' => 1
+            ));
+            if($en->find(true)) {
+                $this->comptype_id = $en->id;
+            }
+        }
+        
         if (!empty($q['comptype_id'])) {
             $en = DB_DataObject::Factory('core_enum');
             $en->get($q['comptype_id']);
             $this->comptype = $en->name;
         }
         
-        
         if(!empty($q['_flag_delete'])){
             $this->deleted_dt = $this->sqlValue("NOW()");
             $this->deleted_by = $roo->getAuthUser()->id;
@@ -295,7 +327,7 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
                 $roo->jok('OK');
             }
             
-            $roo->jerr('EXIST');
+            $roo->jerror('NOTICE-EXIST-CHECK','EXIST');
         }
         
         if(!empty($q['_merge_id'])){
@@ -472,12 +504,38 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject
         $companies->insert();
         $companies->onInsert(array(), $roo);
     }
+    
+    function owner()
+    {
+        if (empty($this->owner_id)) {
+            return false;
+        }
+        static $cache = false;
+        if ($cache !== false && isset($cache[$this->owner_id])) {
+            return $cache[$this->owner_id]; 
+        }
+        $o = DB_DataObject::factory('core_company');
+        if (!$o->get($this->owner_id)) {
+            return false;
+        }
+        $cache[$this->owner_id] = $o;
+        return $o;
+        
+    }
+    
+    /// look up the company which is the system owner...
     static function lookupOwner()
     {
+        static $cache = false;
+        if ($cache !== false) {
+            return clone($cache); // no updating this object..
+        }
+        
         $enum = DB_DataObject::Factory('core_enum')->lookup('COMPTYPE', 'OWNER'  );
         $companies = DB_DataObject::factory('core_company');
         $companies->comptype_id = $enum;
         if ($companies->find(true)) {
+            $cache = clone($companies);
             return $companies;
         }
         return false;