fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [7381] property: prepare for import


From: Sigurd Nes
Subject: [Fmsystem-commits] [7381] property: prepare for import
Date: Wed, 15 Jun 2011 13:20:46 +0000

Revision: 7381
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7381
Author:   sigurdne
Date:     2011-06-15 13:20:45 +0000 (Wed, 15 Jun 2011)
Log Message:
-----------
property: prepare for import

Added Paths:
-----------
    trunk/property/inc/class.uiimport.inc.php
    trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb
    trunk/property/inc/import/default/cvs_import_vedlikeholdsplan_bkb

Added: trunk/property/inc/class.uiimport.inc.php
===================================================================
--- trunk/property/inc/class.uiimport.inc.php                           (rev 0)
+++ trunk/property/inc/class.uiimport.inc.php   2011-06-15 13:20:45 UTC (rev 
7381)
@@ -0,0 +1,346 @@
+<?php
+
+       class property_uiimport
+       {
+               var $public_functions = array
+               (
+                       'index'         => true
+               );
+
+               const DELIMITER = ";";
+               const ENCLOSING = "'";
+               
+               // List of messages, warnings and errors to be displayed to the 
user after the import
+               protected $messages = array();
+               protected $warnings = array();
+               protected $errors = array();
+               
+               // File system path to import folder on server
+               protected $file;
+               protected $district;
+               protected $csvdata;
+               protected $account;
+               protected $conv_type;
+               protected $import_conversion;
+               
+               // Label on the import button. Changes as we step through the 
import process.
+               protected $import_button_label;
+               
+               protected $defalt_values;
+               
+               public function __construct()
+               {
+                       set_time_limit(10000); //Set the time limit for this 
request oto 3000 seconds
+                       $this->account          = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
+               }
+               
+
+               /**
+                * Public method. 
+                * 
+                * @return unknown_type
+                */
+               public function index()
+               {
+                       // Set the submit button label to its initial state
+                       $this->import_button_label = "Start import";
+
+                       // If the parameter 'importsubmit' exist (submit button 
in import form), set path
+                       if (phpgw::get_var("importsubmit")) 
+                       {
+                               // Get the path for user input or use a default 
path
+                               
+                               if($this->file = $_FILES['file']['tmp_name'])
+                               {
+                                       $this->csvdata = 
$this->getcsvdata($this->file);
+                               }
+
+                               $this->conv_type        = 
phpgw::get_var('conv_type');
+//_debug_array($this->csvdata);
+                               phpgwapi_cache::session_set('property', 'file', 
$this->file);
+                               phpgwapi_cache::session_set('property', 
'csvdata', $this->csvdata);
+                               phpgwapi_cache::session_set('property', 
'conv_type', $this->conv_type);
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'property.uiimport.index', 'importstep' => 'true'));
+                       } 
+                       else if(phpgw::get_var("importstep"))
+                       {
+                               $start_time = time(); // Start time of import
+                               $start = date("G:i:s",$start_time);
+                               echo "<h3>Import started at: {$start}</h3>";
+                               echo "<ul>";
+                               $this->file = 
phpgwapi_cache::session_get('property', 'file');
+                               $this->csvdata = 
phpgwapi_cache::session_get('property', 'csvdata');
+                               $this->conv_type = 
phpgwapi_cache::session_get('property', 'conv_type');
+
+                               if($this->conv_type)
+                               {
+                                       if ( preg_match('/\.\./', 
$this->conv_type) )
+                                       {
+                                               break;
+                                       }
+
+                                       $file = PHPGW_SERVER_ROOT . 
"/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}/{$this->conv_type}";
+       
+                                       if ( is_file($file) )
+                                       {
+//_debug_Array($file);die();
+                                               require_once $file;
+                                               $this->import_conversion = new 
import_conversion;
+                                       }
+                               }
+
+                               $result = $this->import(); // Do import step, 
result determines if finished for this area
+                               echo '<li class="info">Aktiviteter: finished 
step ' .$result. '</li>';
+                               while($result != '1')
+                               {
+                                       $result = $this->import();
+                                       echo '<li class="info">Aktiviteter: 
finished step ' .$result. '</li>';
+                                       flush();
+                               }
+
+                               echo "</ul>";
+                               $end_time = time();
+                               $difference = ($end_time - $start_time) / 60;
+                               $end = date("G:i:s",$end_time);
+                               echo "<h3>Import ended at: {$end}. Import 
lasted {$difference} minutes.";
+                               
+                               $this->messages = 
array_merge($this->messages,$this->import_conversion->messages);
+                               $this->warnings = 
array_merge($this->warnings,$this->import_conversion->warnings);
+                               $this->errors = 
array_merge($this->errors,$this->import_conversion->errors);
+
+                               if ($this->errors)
+                               { 
+                                       echo "<ul>";
+                                       foreach ($this->errors as $error)
+                                       {
+                                               echo '<li class="error">Error: 
' . $error . '</li>';
+                                       }
+               
+                                       echo "</ul>";
+                               }
+               
+                               if ($this->warnings)
+                               { 
+                                       echo "<ul>";
+                                       foreach ($this->warnings as $warning)
+                                       {
+                                               echo '<li 
class="warning">Warning: ' . $warning . '</li>';
+                                       }
+                                       echo "</ul>";
+                               }
+               
+                               if ($this->messages)
+                               {
+                                       echo "<ul>";
+               
+                                       foreach ($this->messages as $message)
+                                       {
+                                               echo '<li class="info">' . 
$message . '</li>';
+                                       }
+                                       echo "</ul>";
+                               }
+                       }
+                       else
+                       {
+
+                               $conv_list = 
$this->get_import_conv($this->conv_type);
+                               
+                               $conv_option = '<option value="">' . lang('none 
selected') . '</option>' . "\n";
+                               foreach ( $conv_list as $conv)
+                               {
+                                       $selected = '';
+                                       if ( $conv['selected'])
+                                       {
+                                               $selected = 'selected =  
"selected"';
+                                       }
+
+                                       $conv_option .=  <<<HTML
+                                       <option 
value='{$conv['id']}'{$selected}>{$conv['name']}</option>
+HTML;
+                               }                       
+                               $html = <<<HTML
+                               <h1><img 
src="rental/templates/base/images/32x32/actions/document-save.png" /> 
Importer</h1>
+                               <div id="messageHolder"></div>
+                               <form 
action="index.php?menuaction=property.uiimport.index" method="post" 
enctype="multipart/form-data">
+                                       <fieldset>
+                                               <label for="file">Choose 
file:</label> <input type="file" name="file" id="file" />
+                                               <label for="conv_type">Choose 
conversion:</label>
+                                               <select name="conv_type" 
id="conv_type">
+                                               {$conv_option}
+                                               </select>
+                                               <input type="submit" 
name="importsubmit" value="{$this->import_button_label}"  />
+                                       </fieldset>
+                               </form>
+HTML;
+                               echo $html;
+                       }
+               }
+               
+               /**
+                * Import Facilit data to Portico Estate's rental module
+                * The function assumes CSV files have been uploaded to a 
location on the server reachable by the
+                * web server user.  The CSV files must correspond to the table 
names from Facilit, as exported
+                * from Access. Field should be enclosed in single quotes and 
separated by comma.  The CSV files
+                * must contain the column headers on the first line.
+                * 
+                * @return unknown_type
+                */
+               public function import()
+               {
+                       $steps = 1;
+                       
+                       /* Import logic:
+                        * 
+                        * 1. Do step logic if the session variable is not set
+                        * 2. Set step result on session
+                        * 3. Set label for import button
+                        * 4. Log messages for this step
+                        *  
+                        */
+                       
+                       $this->messages = array();
+                       $this->warnings = array();
+                       $this->errors = array();
+                       
+                       // Import data if not done before and put them on the 
users session
+                       if (!phpgwapi_cache::session_get('property', 
'data_import'))
+                       {
+                               phpgwapi_cache::session_set('property', 
'data_import', $this->import_data()); 
+                $this->log_messages(1);
+                               return '1';
+                       }
+
+                       // We're done with the import, so clear all session 
variables so we're ready for a new one
+                       phpgwapi_cache::session_clear('property', 
'data_import');
+                       phpgwapi_cache::session_clear('property', 'conv_type');
+                       return '1';
+               }
+               
+               protected function import_data()
+               {
+                       $start_time = time();
+                       
+                       $datalines = $this->csvdata;
+                       
+                       $this->messages[] = "Read 'import_all.csv' file in " . 
(time() - $start_time) . " seconds";
+                       $this->messages[] = "'importfile.csv' contained " . 
count($datalines) . " lines";
+                       
+                       $this->db           = & $GLOBALS['phpgw']->db;
+       
+                       $ok = true;
+                       $_ok = false;
+                       $this->db->transaction_begin();
+
+                       //Do your magic...
+                       foreach ($datalines as $data)
+                       {
+                               if(!$_ok = $this->import_conversion->add($data))
+                               {
+                                       $ok = false;
+                               }
+                       }
+                       
+                       if($ok)
+                       {
+                               $this->messages[] = "Imported data. (" . 
(time() - $start_time) . " seconds)";
+                               $this->db->transaction_commit();
+                               return true;
+                       }
+                       else
+                       {
+                               $this->errors[] = "Import of data failed. (" . 
(time() - $start_time) . " seconds)";
+                               $this->db->transaction_abort();
+                               return false;
+                       }
+               }
+
+
+               protected function getcsvdata($path, $skipfirstline = true)
+               {
+                       // Open the csv file
+                       $handle = fopen($path, "r");
+                       
+                       if ($skipfirstline)
+                       {
+                               // Read the first line to get the headers out 
of the way
+                               $this->getcsv($handle);
+                       }
+                       
+                       $result = array();
+                       
+                       while(($data = $this->getcsv($handle)) !== false)
+                       {
+                               $result[] = $data;
+                       }
+                       
+                       fclose($handle);
+                       
+                       return $result;
+               }
+                       
+               
+               /**
+                * Read the next line from the given file handle and parse it 
to CSV according to the rules set up
+                * in the class constants DELIMITER and ENCLOSING.  Returns 
FALSE like getcsv on EOF.
+                * 
+                * @param file-handle $handle
+                * @return array of values from the parsed csv line
+                */
+               protected function getcsv($handle)
+               {
+                       return fgetcsv($handle, 1000, self::DELIMITER, 
self::ENCLOSING);
+               }
+               
+
+               private function log_messages($step)
+        {
+               sort($this->errors);
+               sort($this->warnings);
+               sort($this->messages);
+               
+            $msgs = array_merge(
+               array('----------------Errors--------------------'),
+               $this->errors,
+               array('---------------Warnings-------------------'),
+               $this->warnings,
+               array('---------------Messages-------------------'),
+               $this->messages
+            );
+
+            $path = $GLOBALS['phpgw_info']['server']['temp_dir'];
+            if(is_dir($path.'/logs') || mkdir($path.'/logs'))
+            {
+                file_put_contents("$path/logs/$step.log", implode(PHP_EOL, 
$msgs));
+            }
+        }
+
+               protected function get_import_conv($selected='')
+               {
+                       $dir_handle = @opendir(PHPGW_SERVER_ROOT . 
"/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}");
+                       $i=0; $myfilearray = array();
+                       while ($file = readdir($dir_handle))
+                       {
+                               if ((substr($file, 0, 1) != '.') && 
is_file(PHPGW_SERVER_ROOT . 
"/property/inc/import/{$GLOBALS['phpgw_info']['user']['domain']}/{$file}") )
+                               {
+                                       $myfilearray[$i] = $file;
+                                       $i++;
+                               }
+                       }
+                       closedir($dir_handle);
+                       sort($myfilearray);
+
+                       for ($i=0;$i<count($myfilearray);$i++)
+                       {
+                               $fname = preg_replace('/_/',' 
',$myfilearray[$i]);
+
+                               $conv_list[] = array
+                               (
+                                       'id'            => $myfilearray[$i],
+                                       'name'          => $fname,
+                                       'selected'      => 
$myfilearray[$i]==$selected ? 1 : 0
+                               );
+                       }
+
+                       return $conv_list;
+               }
+       }

Added: trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb              
                (rev 0)
+++ trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb      
2011-06-15 13:20:45 UTC (rev 7381)
@@ -0,0 +1,122 @@
+<?php
+       class import_conversion
+       {
+               protected $db;
+               public $messages = array();
+               public $warnings = array();
+               public $errors = array();
+
+               public function __construct()
+               {
+                       set_time_limit(10000); //Set the time limit for this 
request
+                       $this->account          = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
+                       $this->db           = & $GLOBALS['phpgw']->db;
+               }
+
+               public function add($data)
+               {
+//                     $debug = true;
+                       $error = false;
+                       $table = 'fm_entity_4_1';
+                       $byggid = $this->decode($data[0]);
+                       $location_code = substr($byggid,0,4) . '-0' . 
substr($byggid,-1);
+//_debug_array($location_code);
+                       $location_data = 
execMethod('property.solocation.read_single', $location_code );
+_debug_array($data);
+//_debug_array($location_data);die();
+                       if(!$location_data)
+                       {
+                               $this->errors[] = "Error importing location: 
{$location_code}";
+                               $error = true;
+                               return false;
+                       }
+
+                       if($location_data['street_name'])
+                       {
+                               $address[]= $location_data['street_name'];
+                               $address[]= $location_data['street_number'];
+                               $address        = 
$this->db->db_addslashes(implode(" ", $address));
+                       }
+
+                       if(!$address)
+                       {
+                               $address = 
$this->db->db_addslashes($location_data['loc1_name']);
+                       }
+
+                       $id = (int)$data[2];
+
+                       $this->messages[] = "Dagens dato er lagt inn som 
registreringsdato for {$id}  (mangler info)";
+                       $entry_date = time();
+
+_debug_array($entry_date_info);
+_debug_array($entry_date);
+                       $value_set = array();
+
+                       $value_set['id']                                        
= $id;
+                       $value_set['num']                                       
= sprintf('%04s',$id);
+               $value_set['loc1']                                      = 
$location_data['loc1'];
+               $value_set['loc2']                                      = 
$location_data['loc2'];
+                       $value_set['user_id']                           = 
$this->account;
+                       $value_set['location_code']                     = 
$location_code;
+                       $value_set['address']                           = 
$address;
+                       $value_set['entry_date']                        = 
$entry_date;
+                       $value_set['museumsnr']                         = 
$this->db->db_addslashes($data[1]);
+                       $value_set['betegnelse']                        = 
$this->db->db_addslashes($data[3]);
+                       $value_set['beskrivelse']                       = 
$this->db->db_addslashes($data[4]);
+                       $value_set['tilstand']                          = 
$this->db->db_addslashes($data[5]);
+
+                       $cols = implode(',', array_keys($value_set));
+                       $values = 
$this->db->validate_insert(array_values($value_set));
+
+                       $sql = "INSERT INTO {$table} ({$cols}) VALUES 
({$values})";
+
+                       if($debug)
+                       {
+                               _debug_array($sql);
+                       }
+                       else
+                       {
+                               $request_ok = 
$this->db->query($sql,__LINE__,__FILE__);
+                       }
+
+                       if(!$error)
+                       {
+                               $this->messages[] = "Successfully imported 
location: Title ({$this->decode($data[1])})";
+                               $ok = true;
+                       }
+                       else
+                       {
+                               $this->errors[] = "Error importing location: 
Title ({$this->decode($data[1])})";
+                               $ok = false;
+                       }
+                       return $ok;
+               }
+
+               /**
+                * Convert from the locale encoding to UTF-8 encoding and 
escape single quotes
+                * 
+                * @param string $value The value to convert
+                * @return string
+                */
+               protected function decode($value)
+               {
+                       $converted = mb_convert_encoding($value, 'UTF-8');
+                       if ($this->is_null(trim($converted)))
+                       {
+                               return null;
+                       }
+                       return stripslashes($converted);
+               }
+               
+               /**
+                * Test a value for null according to several formats that can 
exist in the export.
+                * Returns true if the value is null according to these rules, 
false otherwise.
+                * 
+                * @param string $value The value to test
+                * @return bool
+                */
+               protected function is_null($value)
+               {
+                       return ((trim($value) == "") || ($data == "<NULL>") || 
($data == "''"));
+               }
+       }

Added: trunk/property/inc/import/default/cvs_import_vedlikeholdsplan_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_vedlikeholdsplan_bkb           
                (rev 0)
+++ trunk/property/inc/import/default/cvs_import_vedlikeholdsplan_bkb   
2011-06-15 13:20:45 UTC (rev 7381)
@@ -0,0 +1,345 @@
+<?php
+       class import_conversion
+       {
+               protected $db;
+               public $messages = array();
+               public $warnings = array();
+               public $errors = array();
+
+               public function __construct()
+               {
+                       set_time_limit(10000); //Set the time limit for this 
request oto 3000 seconds
+                       $this->account          = 
(int)$GLOBALS['phpgw_info']['user']['account_id'];
+                       $this->db           = & $GLOBALS['phpgw']->db;
+               }
+
+               public function add($data)
+               {
+
+                       $debug = true;
+                       $error = false;
+                       $type = $this->decode($data[0]);
+                       $location_code = $this->decode($data[1]);
+
+                       $location_data = 
execMethod('property.solocation.read_single', $location_code );
+_debug_array($data);
+//_debug_array($location_data);die();
+                       if(!$location_data)
+                       {
+                               $this->errors[] = "Error importing location: 
{$location_code}";
+                               $error = true;
+                               return false;
+                       }
+
+                       $value_set = array();
+
+               $value_set['loc1'] = $location_data['loc1'];
+               $value_set['loc2'] = $location_data['loc2'];
+
+
+                       if($location_data['street_name'])
+                       {
+                               $address[]= $location_data['street_name'];
+                               $address[]= $location_data['street_number'];
+                               $address        = 
$this->db->db_addslashes(implode(" ", $address));
+                       }
+
+                       if(!$address)
+                       {
+                               $address = 
$this->db->db_addslashes($location_data['loc1_name']);
+                       }
+
+
+                       $this->db->query("SELECT value FROM fm_idgenerator 
WHERE name = 'request'");
+                       $this->db->next_record();
+                       $id = $this->db->f('value')+1;
+
+                       if($data[4])
+                       {
+                               $entry_date_info = explode('/',$data[4]);
+                       }
+                       else if($data[5])
+                       {
+                               $entry_date_info = explode('/',$data[5]);
+                       }
+                       //YYYY/MM/DD
+                       
+                       if(isset($entry_date_info[0]) && 
ctype_digit($entry_date_info[0]))
+                       {
+                               $entry_date = 
strtotime("{$entry_date_info[0]}/06/24");
+                       }
+                       else
+                       {
+                               $this->messages[] = "Dagens dato er lagt inn 
som registreringsdato for {$id}  (mangler info)";
+                               $entry_date = time();
+                       }
+
+//$category = ????;
+//$authorities_demands
+//$building_part
+//$coordinator
+_debug_array($entry_date_info);
+_debug_array($entry_date);
+
+                       $value_set['id']                                        
= $id;
+                       $value_set['title']                                     
= $this->db->db_addslashes("{$data[7]}: {$data[10]}");
+                       $value_set['owner']                                     
= $this->account;
+                       $value_set['category']                          = 
$category;
+                       $value_set['descr']                                     
= $this->db->db_addslashes("{$type}\n{$data[7]}: {$data[10]}");
+                       $value_set['location_code']                     = 
$location_code;
+                       $value_set['address']                           = 
$address;
+                       $value_set['entry_date']                        = 
$entry_date;
+                       $value_set['budget']                            = 
(int)str_replace(',', '', $data[12]);
+                       $value_set['status']                            = 
$data['status'];
+       //              $value_set['branch_id']                         = 
$data['branch_id'];
+       //              $value_set['coordinator']                       = 
$coordinator;
+                       $value_set['authorities_demands']       = 
$authorities_demands;
+                       $value_set['building_part']                     = 
$building_part;
+       //              $value_set['start_date']                        = 
$data['start_date'];
+       //              $value_set['end_date']                          = 
$data['end_date'];
+       //              $value_set['regulations']                       = 
$data['regulations'] ? ',' . implode(',',$data['regulations']) . ',' : '';
+
+                       $cols = implode(',', array_keys($value_set));
+                       $values = 
$this->db->validate_insert(array_values($value_set));
+
+                       $sql = "INSERT INTO fm_request ({$cols}) VALUES 
({$values})";
+
+                       if($debug)
+                       {
+                               _debug_array($sql);
+                       }
+                       else
+                       {
+//                             $request_ok = 
$this->db->query($sql,__LINE__,__FILE__);
+                       }
+
+                       $condition = array();
+                       
+                       if($data[8] || $data[9])
+                       {
+                               $condition[1] = array
+                               (
+                                       'degree'                => 
(int)$data[8],
+                                       'probability'   =>      2,
+                                       'consequence'   =>      (int)$data[9]
+                               );
+                       }
+                       
+                       
+                       foreach ($condition as $condition_type => $value_type)
+                       {
+                               $sql = "INSERT INTO fm_request_condition 
(request_id,condition_type,degree,probability,consequence,user_id,entry_date) "
+                                       . "VALUES ("
+                                       . $id. ","
+                                       . $condition_type . ","
+                                       . $value_type['degree']. ","
+                                       . $value_type['probability']. ","
+                                       . $value_type['consequence']. ","
+                                       . $this->account . ","
+                                       . time() . ")";
+
+                               if($debug)
+                               {
+                                       _debug_array($sql);
+                               }
+                               else
+                               {
+//                                     
$this->db->query($sql,__LINE__,__FILE__);
+                               }
+                       }
+
+/*
+                       $value_set['in_progress_date']  = time();
+                       $value_set['closed_date']               = time();
+                       $value_set['delivered_date']    = time();
+*/
+
+                       for ($i=13; $i<27; $i++)
+                       {
+                               $data[$i] = str_replace(',', '', $data[$i]);
+                       }
+
+                       $consume_data = array();
+                       if($data[13] && ctype_digit($data[13]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[13],
+                                        'date' => strtotime("2012/06/24")
+                               );
+                       }
+
+                       if($data[14] && ctype_digit($data[14]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[14],
+                                        'date' => strtotime("2011/06/24")
+                               );
+                       }
+                       if($data[15] && ctype_digit($data[15]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[15],
+                                        'date' => strtotime("2010/06/24")
+                               );
+                       }
+                       if($data[16] && ctype_digit($data[16]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[16],
+                                        'date' => strtotime("2009/06/24")
+                               );
+                       }
+                       if($data[17] && ctype_digit($data[17]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[17],
+                                        'date' => strtotime("2008/06/24")
+                               );
+                       }
+
+                       if($data[18] && ctype_digit($data[18]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[18],
+                                        'date' => strtotime("2007/06/24")
+                               );
+                       }
+                       if($data[19] && ctype_digit($data[19]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[19],
+                                        'date' => strtotime("2006/06/24")
+                               );
+                       }
+                       if($data[20] && ctype_digit($data[20]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[20],
+                                        'date' => strtotime("2005/06/24")
+                               );
+                       }
+                       if($data[21] && ctype_digit($data[21]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[21],
+                                        'date' => strtotime("2004/06/24")
+                               );
+                       }
+
+                       if($data[22] && ctype_digit($data[22]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[22],
+                                        'date' => strtotime("2003/06/24")
+                               );
+                       }
+                       if($data[23] && ctype_digit($data[23]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[23],
+                                        'date' => strtotime("2002/06/24")
+                               );
+                       }
+                       if($data[24] && ctype_digit($data[24]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[24],
+                                        'date' => strtotime("2001/06/24")
+                               );
+                       }
+
+                       if($data[25] && ctype_digit($data[25]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[25],
+                                        'date' => strtotime("2000/06/24")
+                               );
+                       }
+
+                       if($data[26] && ctype_digit($data[26]))
+                       {
+                               $consume_data[] = array
+                               (
+                                        'value' => (int)$data[26],
+                                        'date' => strtotime("1999/06/24")
+                               );
+                       }
+
+
+                       foreach ($consume_data as $consume)
+                       {
+                               $sql = "INSERT INTO fm_request_consume 
(request_id,amount,date,user_id,entry_date) "
+                                       . "VALUES ("
+                                       . $id . ","
+                                       . (int)$consume['value'] . ","
+                                       . (int)$consume['date'] . ","
+                                       . $this->account . ","
+                                       . time() . ")";
+                               if($debug)
+                               {
+                                       _debug_array($sql);
+                               }
+                               else
+                               {
+//                                     
$this->db->query($sql,__LINE__,__FILE__);
+                               }
+                       }
+
+
+//                     $this->db->query("UPDATE fm_idgenerator set value = 
value + 1 where name = 'request'");
+
+
+                       if(!$error)
+                       {
+                               $this->messages[] = "Successfully imported 
location: Title ({$this->decode($data[1])})";
+                               $ok = true;
+                       }
+                       else
+                       {
+                               $this->errors[] = "Error importing location: 
Title ({$this->decode($data[1])})";
+                               $ok = false;
+                       }
+                       return $ok;
+               }
+
+               /**
+                * Convert from the locale encoding to UTF-8 encoding and 
escape single quotes
+                * 
+                * @param string $value The value to convert
+                * @return string
+                */
+               protected function decode($value)
+               {
+                       $converted = mb_convert_encoding($value, 'UTF-8');
+                       if ($this->is_null(trim($converted)))
+                       {
+                               return null;
+                       }
+                       return stripslashes($converted);
+               }
+               
+               /**
+                * Test a value for null according to several formats that can 
exist in the export.
+                * Returns true if the value is null according to these rules, 
false otherwise.
+                * 
+                * @param string $value The value to test
+                * @return bool
+                */
+               protected function is_null($value)
+               {
+                       return ((trim($value) == "") || ($data == "<NULL>") || 
($data == "''"));
+               }
+       }




reply via email to

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