fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [7431] property: custom import/update


From: Sigurd Nes
Subject: [Fmsystem-commits] [7431] property: custom import/update
Date: Fri, 24 Jun 2011 17:23:16 +0000

Revision: 7431
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7431
Author:   sigurdne
Date:     2011-06-24 17:23:15 +0000 (Fri, 24 Jun 2011)
Log Message:
-----------
property: custom import/update

Modified Paths:
--------------
    trunk/property/inc/import/default/cvs_import_romdata_bkb

Modified: trunk/property/inc/import/default/cvs_import_romdata_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_romdata_bkb    2011-06-24 
16:53:33 UTC (rev 7430)
+++ trunk/property/inc/import/default/cvs_import_romdata_bkb    2011-06-24 
17:23:15 UTC (rev 7431)
@@ -5,6 +5,7 @@
                public $messages = array();
                public $warnings = array();
                public $errors = array();
+               protected $debug = false;
 
                public function __construct()
                {
@@ -45,13 +46,19 @@
                                $_ok = 
$this->add_location(array('location_code' => $location_code, 'name' => 
$this->decode($data[6]), 'area' => $this->decode($data[7])));
                                $ok = $_ok && $ok ? $_ok : false;
                        }
+                       else
+                       {
+                               $this->warnings[] = "location_code finnes fra 
før: {$location_code}, oppdaterer";
+                               $_ok = 
$this->update_location(array('location_code' => $location_code, 'name' => 
$this->decode($data[6]), 'area' => $this->decode($data[7])));
+                               $ok = $_ok && $ok ? $_ok : false;               
        
+                       }
 
                        return $ok;
                }
 
                protected function add_location($data)
                {
-                       $debug = false;
+                       $debug = $this->debug;
                        $error = false;
                        $ok = true;
                        $value_set = array();
@@ -91,7 +98,6 @@
 
                        $sql2 = "INSERT INTO fm_locations (level, 
location_code) VALUES ({$type_id}, '{$data['location_code']}')";
 
-
                        if($debug)
                        {
                                _debug_array($sql);
@@ -100,21 +106,59 @@
                        {
                                $_ok = $this->db->query($sql,__LINE__,__FILE__);
                                $ok = $_ok ? $_ok : false;
+                               $_ok = 
$this->db->query($sql2,__LINE__,__FILE__);
+                               $ok = $_ok ? $_ok : false;
                        }
 
-                       if(!$error)
+                       if(!$error && $ok)
                        {
                                $this->messages[] = "Successfully imported 
location: {$data['location_code']}";
-                               $ok = true;
                        }
                        else
                        {
                                $this->errors[] = "Error importing location: 
{$data['location_code']}";
-                               $ok = false;
                        }
                        return $ok;
                }
 
+               protected function update_location($data)
+               {
+                       $debug = $this->debug;
+                       $ok = false;
+                       $value_set = array();
+
+                       $location_arr = explode('-',$data['location_code']);
+                       $type_id = count($location_arr);
+ 
+                       $value_set["loc{$type_id}_name"]        = 
$this->db->db_addslashes($data['name']);
+                       $value_set['area_net']                          = 
$data['area'] ? str_replace(',','.',$data['area']) : 0;
+
+                       $table = "fm_location{$type_id}";
+
+                       $value_set      = 
$this->db->validate_update($value_set);
+                       $sql = "UPDATE {$table} SET {$value_set} WHERE 
location_code = '{$data['location_code']}'";
+
+                       if($debug)
+                       {
+                               _debug_array($sql);
+                               $ok = true;
+                       }
+                       else
+                       {
+                               $ok = $this->db->query($sql,__LINE__,__FILE__);
+                       }
+
+                       if($ok)
+                       {
+                               $this->messages[] = "Successfully updated 
location: {$data['location_code']}";
+                       }
+                       else
+                       {
+                               $this->errors[] = "Error update location: 
{$data['location_code']}";
+                       }
+                       return $ok;
+               }
+
                /**
                 * Convert from the locale encoding to UTF-8 encoding and 
escape single quotes
                 * 
@@ -123,7 +167,7 @@
                 */
                protected function decode($value)
                {
-                       $converted = mb_convert_encoding($value, 'UTF-8');
+                       $converted = $value;// mb_convert_encoding($value, 
'UTF-8');
                        if ($this->is_null(trim($converted)))
                        {
                                return null;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]