SimpleExcel.php
[Pman.Core] / I18n.php
index 0470e79..8367964 100644 (file)
--- a/I18n.php
+++ b/I18n.php
@@ -47,7 +47,7 @@
  */
 require_once 'Pman.php';
 
-class Pman_Core_I18N extends Pman
+class Pman_Core_I18n extends Pman
 {
  
     
@@ -81,57 +81,104 @@ class Pman_Core_I18N extends Pman
     }
      
     
-    function guessUsersLanguage() {
-         
+    function guessUsersLanguage()
+    {
+        $this->sessionState(0);
+        
         $lang = !$this->authUser || empty($this->authUser->lang ) ? 'en' : $this->authUser->lang;
         
         /// verify the selected language..
         $i = DB_DataObject::Factory('I18n');
         $i->ltype = 'l';                           // string(1)  not_null multiple_key
         $i->lkey = $lang;                            // string(8)  not_null
-        if (!$i->count()) {
-            $this->jerr('invalid lang configured: ' . $lang);
+        if (!$i->count()) {    
+            $i = DB_DataObject::Factory('I18n');
+            $i->buildDb();
+            
+            $i = DB_DataObject::Factory('I18n');
+            $i->ltype = 'l';                           // string(1)  not_null multiple_key
+            $i->lkey = $lang;  
+            if (!$i->count()) { 
+                $this->jerr('invalid lang configured: ' . $lang);
+            }
         }
         
         
         return explode('_', $lang);
     }
      
-    function get($s ='')
+    function get($s ='', $opts=array())
     {
      
-     
+        $this->sessionState(0);
         $lbits = $this->guessUsersLanguage();
          
+        if ($this->authUser && !empty($_REQUEST['_debug'])) {
+            DB_DataObject::debugLevel(1);
+        }
         
-        $i = DB_DataObject::Factory('I18n');
         
+        
+        $i = DB_DataObject::Factory('I18n');
+        $i->is_active = 1;
         switch($s) {
             case 'Lang':
+                 
+                
                 $i->ltype = 'l';
                 $i->applyFilters($_REQUEST, $this->authUser, $this);
-                $this->jdata($i->toTransList('l',  $lbits[0]));
+                $this->jdata($i->toTransList('l',  implode('_',$lbits)));
                 break;
 
             case 'Country':
                 $i->ltype = 'c';
                 $i->applyFilters($_REQUEST, $this->authUser, $this);
-                $this->jdata($i->toTransList('c',  $lbits[0]));
-                
-                $ret = $this->getList('c', $lbits[0],empty($_REQUEST['filter']) ? false : $_REQUEST['filter']);
+                $this->jdata($i->toTransList('c',  implode('_',$lbits)));
+               
                 break;
                 
-             case 'Currency':
+            case 'Currency':
                 $i->ltype = 'm';
                 $i->applyFilters($_REQUEST, $this->authUser, $this);
-                $this->jdata($i->toTransList('m',  $lbits[0]));
+                $this->jdata($i->toTransList('m',  implode('_',$lbits)));
                 break;
+            
+            case 'Timezone':
+                $ar = DateTimeZone::listAbbreviations();
+                $ret = array();
+                $tza = array();
+                foreach($ar as $tl => $sar) {
+                    foreach($sar as $tz) {
+                        $tza[]  = $tz['timezone_id'];
+                    
+                    }
+                }
+                $tza= array_unique($tza);
+                sort($tza);
+                foreach($tza as $tz) {
+                    //filtering..
+                    if (empty($_REQUEST['q']) ||
+                            0 === strcasecmp(
+                                    substr($tz,0, strlen($_REQUEST['q'])),
+                                    $_REQUEST['q'])
+                    ) {
+                        $ret[] = array('tz' => $tz);
+                    }
+                    
+                }
+                $this->jdata($ret);
+                
+                
+                
              
                 
+        }
+        if (!empty($_REQUEST['debug'])) {
+            DB_DataObject::debugLevel(1);
         }
         
         $i = DB_DataObject::Factory('I18n');
-        $i->buildDb();
+        $i->buildDB();
       
        
         $i = DB_DataObject::Factory('I18n');
@@ -141,7 +188,9 @@ class Pman_Core_I18N extends Pman
         $ar = array();
         foreach($langs as $lang)
         {
-            $rlang = array_shift(explode('_', strtoupper($lang)));
+            //$rlang = array_shift(explode('_', strtoupper($lang)));
+            $ll = explode('_', $lang);
+            $rlang = array_shift($ll);
             
             $ar[$lang] = array();
             $i = DB_DataObject::Factory('I18n');
@@ -153,6 +202,7 @@ class Pman_Core_I18N extends Pman
         }
         //echo '<PRE>';print_r($ar);
         header('Content-type: text/javascript');
+        echo "Roo.namespace('Pman.I18n');";
         echo 'Pman.I18n.Data = ' .  json_encode($ar);
         exit;
         
@@ -165,7 +215,7 @@ class Pman_Core_I18N extends Pman
      /**
      * translate (used by database building);
      * usage :
-     * require_once 'Pman/Core/I18N.php';
+     * require_once 'Pman/Core/I18n.php';
      * $x = new Pman_Core_I18N();
      * $x->translate($this->authuser, 'c', 'US');
      * @param au - auth User
@@ -193,6 +243,54 @@ class Pman_Core_I18N extends Pman
         
         
     }
+    /**
+     * translate a list of items
+     * @param Pman_Core_DataObjects_Person $au Authenticated user
+     * @param String                      $type  c/l/m
+     * @param String                      $k     'comma' seperated list of keys to translate
+     */
+    
+    function translateList($au, $type, $k)  
+    {
+        $ar = explode(',', $k);
+        $ret = array();
+        foreach($ar as $kk) {
+            $ret[] = $this->translate($au, $type, $kk);
+        }
+        return implode(', ', $ret);
+    }
+    /**
+     * DO NOT USE THIS -- see core_curr_rates dataobject.
+     */
+    
+    
+    function convertCurrency($val, $from, $to)
+    {
+        
+        return DB_DAtaObject::Factory('core_curr_rate')->convert($val,$from,$to);
+    
+    }
+    /**
+     * DO NOT USE THIS -- see core_curr_rates dataobject.
+     *
+     */
+    
+    
+    
+    function loadRates()
+    {   
+        static $rates = array();
+        
+        if (!empty($rates)) {
+            $this->rates = $rates;
+            return;
+        }
+        
+        $this->rates = $rates = DB_DAtaObject::Factory('core_curr_rate')->currentRates();
+        
+    }
+    
+    
      
     
 }
\ No newline at end of file