sync
[Pman.Admin] / Import / Core_templatestr.php
index 9f9e773..9a4f49c 100644 (file)
@@ -58,10 +58,10 @@ class Pman_Admin_Import_Core_templatestr extends Pman
         //$rows = $this->readXLS("/home/alan/Downloads/oll_example.xls") ;
         $rows = $this->readXLS($_FILES['imageUpload']['tmp_name']) ;
         
-         //$ret = $this->processRows($rows);
+        $ret = $this->processRows($rows);
         
          
-        $this->jok("DONE", false, array('extra'=> $rows));
+        $this->jok("DONE", false, array('extra'=> $ret));
         
     }
     
@@ -83,15 +83,44 @@ class Pman_Admin_Import_Core_templatestr extends Pman
     { 
         $ret = array();
         foreach($rows as $r) {
+            if (isset($r['table id'])) {
+                $ret[] = $this->updateTableTranslation($r);
+                continue;
+            }
+            
             $ret[] = $this->updateTranslation($r);
             
         }
         return $ret;
     }        
-    
+    function updateTranslation($r)
+    {
+        // determine the type of file:
+        
+        if (empty($r['template']) || empty($r['module']) || empty($r['code'])) {
+            $this->jerr("missing template / module or code column");
+        }
+
+        if (!isset($r['language'])) {
+            $this->jerr("missing language");
+        }
+
+        // table translation
+        if($r['module'] == 'database') {
+            $arr = explode(':', $r['template']);
+            $r['table'] = $arr[0];
+            $r['column'] = $arr[1];
+            $this->updateTableTranslation($r);
+        }
+        // template translation
+        else {
+            $this->updateTranslationRow($r);
+        }
+        return;
+    }
     
     var $seq = 1;
-    function updateTranslation($r)
+    function updateTranslationRow($r)
     {
         //print_R($r); DB_DataObject::DebugLevel(1);
         $tr = DB_DataObject::Factory('core_templatestr');
@@ -109,13 +138,48 @@ class Pman_Admin_Import_Core_templatestr extends Pman
             $tt->txt = $r['translation'];
             $tt->updated = date('Y-m-d H:i:s');
             $tt->update($tr);
-             
             return 1;
         }
         return 0;
     }
     
     
+    
+    function updateTableTranslation($r)
+    {
+      //   print_R($r); DB_DataObject::DebugLevel(1);
+        $tr = DB_DataObject::Factory('core_templatestr');
+        $tr->autoJoin();
+
+
+        // update duplicate with same on_table, on_col, mdsum and lang
+        // $tr->whereAdd("core_templatestr.on_id='{$tr->escape($r['table id'])}'");
+        $tr->whereAdd("core_templatestr.on_table='{$tr->escape($r['table'])}'");
+        $tr->whereAdd("core_templatestr.on_col='{$tr->escape($r['column'])}'");
+        $tr->whereAdd("join_src_id_id.mdsum='{$tr->escape($r['code'])}'");
+        $tr->lang = $r['language'];
+
+        $duplicate = $tr->fetchAll('id');
+
+        if(!empty($duplicate)) {
+
+            $t = DB_DataObject::factory('core_templatestr');
+            $t->query(
+            "UPDATE 
+                core_templatestr
+            SET 
+                txt = '" . $r['translation'] . "',
+                updated = '" . date('Y-m-d H:i:s') . "' 
+            WHERE 
+                id IN (" . implode(',', $duplicate) . ")"
+            );
+            return 1;
+        }
+
+        return 0;
+    }
+    
+    
     function readXLS($file) {
         
         require_once 'System.php';