[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [7451] property: more on import
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [7451] property: more on import |
Date: |
Wed, 29 Jun 2011 14:01:42 +0000 |
Revision: 7451
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7451
Author: sigurdne
Date: 2011-06-29 14:01:42 +0000 (Wed, 29 Jun 2011)
Log Message:
-----------
property: more on import
Modified Paths:
--------------
trunk/property/inc/class.uiimport.inc.php
trunk/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb
trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb
trunk/property/inc/import/default/cvs_import_romdata_bkb
trunk/property/inc/import/default/cvs_import_vedlikeholdsplan_bkb
Added Paths:
-----------
trunk/property/inc/import/default/cvs_oppdater_rental_party_bkb
Modified: trunk/property/inc/class.uiimport.inc.php
===================================================================
--- trunk/property/inc/class.uiimport.inc.php 2011-06-29 08:32:32 UTC (rev
7450)
+++ trunk/property/inc/class.uiimport.inc.php 2011-06-29 14:01:42 UTC (rev
7451)
@@ -57,29 +57,33 @@
// If the parameter 'importsubmit' exist (submit button
in import form), set path
if (phpgw::get_var("importsubmit"))
{
+
+ if($GLOBALS['phpgw']->session->is_repost())
+ {
+ die('Hmm... looks like a repost!');
+ }
+
// Get the path for user input or use a default
path
if($this->file = $_FILES['file']['tmp_name'])
{
- $this->csvdata =
$this->getcsvdata($this->file);
+ switch ($_FILES['file']['type'])
+ {
+ case 'application/vnd.ms-excel':
+ $this->csvdata =
$this->getexceldata($this->file);
+ break;
+ case 'text/csv':
+ $this->csvdata =
$this->getcsvdata($this->file);
+ break;
+ }
}
$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)
{
@@ -92,20 +96,14 @@
if ( is_file($file) )
{
-//_debug_Array($file);die();
require_once $file;
$this->import_conversion = new
import_conversion;
+ $this->import_conversion->debug
= phpgw::get_var('debug', 'bool');
}
}
$result = $this->import(); // Do import step,
result determines if finished for this area
echo '<li class="info">Import: finished step '
.$result. '</li>';
- while($result != '1')
- {
- $result = $this->import();
- echo '<li class="info">Import: finished
step ' .$result. '</li>';
- flush();
- }
echo "</ul>";
$end_time = time();
@@ -167,16 +165,19 @@
<option
value='{$conv['id']}'{$selected}>{$conv['name']}</option>
HTML;
}
+ $action =
$GLOBALS['phpgw']->link('/index.php',
array('menuaction'=>'property.uiimport.index'));
$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">
+ <form action="{$action}" 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>
+ <label
for="debug">Debug:</label>
+ <input type="checkbox"
name="debug" id="debug" value ='1' />
<input type="submit"
name="importsubmit" value="{$this->import_button_label}" />
</fieldset>
</form>
@@ -210,18 +211,9 @@
$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');
+ $this->import_data();
+ $this->log_messages(1);
return '1';
}
@@ -285,7 +277,30 @@
return $result;
}
-
+
+ protected function getexceldata($path, $skipfirstline = true)
+ {
+ $data = CreateObject('phpgwapi.excelreader');
+ $data->setOutputEncoding('CP1251');
+ $data->read($path);
+ $result = array();
+
+ $start = $skipfirstline ? 2 : 1; // Read the first line
to get the headers out of the way
+
+ $rows = $data->sheets[0]['numRows']+1;
+
+ for ($i=$start; $i<$rows; $i++ ) //First data entry on
row 2
+ {
+ foreach($data->sheets[0]['cells'][$i] as
&$value)
+ {
+ $value = utf8_encode(trim($value));
+ }
+ $result[] =
array_values($data->sheets[0]['cells'][$i]);
+ }
+
+ return $result;
+ }
+
/**
* Read the next line from the given file handle and parse it
to CSV according to the rules set up
Modified: trunk/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb
2011-06-29 08:32:32 UTC (rev 7450)
+++ trunk/property/inc/import/default/cvs_import_kunstoversikt_bilde_bkb
2011-06-29 14:01:42 UTC (rev 7451)
@@ -9,8 +9,8 @@
protected $dir = '/u01/kunst/001';
protected $entity_id = 4;
protected $cat_id = 1;
+ public $debug = true;
-
public function __construct()
{
set_time_limit(10000); //Set the time limit for this
request
@@ -23,7 +23,6 @@
public function add($data)
{
-// $debug = true;
$error = false;
//_debug_array($data);
@@ -50,7 +49,7 @@
{
$this->errors[] ="This file already
exists: {$to_file}";
}
- else if (!$debug)
+ else if (!$this->debug)
{
$this->bofiles->create_document_dir("{$this->category_dir}/{$location[0]}/{$data[0]}");
$this->bofiles->vfs->override_acl = 1;
@@ -74,33 +73,4 @@
return true;
}
-
-
- /**
- * 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 == "''"));
- }
}
Modified: trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb
2011-06-29 08:32:32 UTC (rev 7450)
+++ trunk/property/inc/import/default/cvs_import_kunstoversikt_bkb
2011-06-29 14:01:42 UTC (rev 7451)
@@ -5,6 +5,7 @@
public $messages = array();
public $warnings = array();
public $errors = array();
+ public $debug = true;
public function __construct()
{
@@ -15,10 +16,9 @@
public function add($data)
{
-// $debug = true;
$error = false;
$table = 'fm_entity_4_1';
- $byggid = $this->decode($data[0]);
+ $byggid = $data[0];
if(!$byggid)
{
$this->errors[] = "Mangler objekt, hopper over:
{$data[1]}";
@@ -92,7 +92,7 @@
$sql = "INSERT INTO {$table} ({$cols}) VALUES
({$values})";
}
- if($debug)
+ if($this->debug)
{
_debug_array($sql);
}
@@ -103,42 +103,14 @@
if(!$error)
{
- $this->messages[] = "Successfully imported
location: Title ({$this->decode($data[1])})";
+ $this->messages[] = "Successfully imported
location: Title ({$data[1]})";
$ok = true;
}
else
{
- $this->errors[] = "Error importing location:
Title ({$this->decode($data[1])})";
+ $this->errors[] = "Error importing location:
Title ({$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 == "''"));
- }
}
Modified: trunk/property/inc/import/default/cvs_import_romdata_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_romdata_bkb 2011-06-29
08:32:32 UTC (rev 7450)
+++ trunk/property/inc/import/default/cvs_import_romdata_bkb 2011-06-29
14:01:42 UTC (rev 7451)
@@ -5,7 +5,7 @@
public $messages = array();
public $warnings = array();
public $errors = array();
- protected $debug = false;
+ protected $debug = true;
public function __construct()
{
Modified: trunk/property/inc/import/default/cvs_import_vedlikeholdsplan_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_import_vedlikeholdsplan_bkb
2011-06-29 08:32:32 UTC (rev 7450)
+++ trunk/property/inc/import/default/cvs_import_vedlikeholdsplan_bkb
2011-06-29 14:01:42 UTC (rev 7451)
@@ -5,7 +5,7 @@
public $messages = array();
public $warnings = array();
public $errors = array();
-
+ public $debug = true;
public function __construct()
{
set_time_limit(10000); //Set the time limit for this
request oto 3000 seconds
@@ -16,10 +16,10 @@
public function add($data)
{
- $debug = true;
+ $debug = $this->debug;
$error = false;
- $type = $this->decode($data[0]);
- $location_code = $this->decode($data[1]);
+ $type = $data[0];
+ $location_code = $data[1];
$location_data =
execMethod('property.solocation.read_single', $location_code );
_debug_array($data);
@@ -304,42 +304,14 @@
if(!$error)
{
- $this->messages[] = "Successfully imported
location: Title ({$this->decode($data[1])})";
+ $this->messages[] = "Successfully imported
location: Title ({$data[1]})";
$ok = true;
}
else
{
- $this->errors[] = "Error importing location:
Title ({$this->decode($data[1])})";
+ $this->errors[] = "Error importing location:
Title ({$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_oppdater_rental_party_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_oppdater_rental_party_bkb
(rev 0)
+++ trunk/property/inc/import/default/cvs_oppdater_rental_party_bkb
2011-06-29 14:01:42 UTC (rev 7451)
@@ -0,0 +1,104 @@
+<?php
+ class import_conversion
+ {
+ protected $db;
+ public $messages = array();
+ public $warnings = array();
+ public $errors = array();
+ public $debug = true;
+
+ 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)
+ {
+ $error = false;
+ $table = 'rental_party';
+ $id = (int)$data[0];
+
+ $fields = array
+ (
+ 'id',
+ 'identifier',
+ 'first_name',
+ 'last_name',
+ 'comment',
+ 'is_inactive',
+ 'title',
+ 'company_name',
+ 'department',
+ 'address_1',
+ 'address_2',
+ 'postal_code',
+ 'place',
+ 'phone',
+ 'mobile_phone',
+ 'fax',
+ 'email',
+ 'url',
+ 'account_number',
+ 'reskontro',
+ 'location_id',
+ 'result_unit_number',
+ 'org_enhet_id'
+ );
+
+ $value_set = array();
+ foreach ($fields as $key => $field)
+ {
+ $value_set[$field] =
$this->db->db_addslashes($data[$key]);
+ }
+ unset($value_set['id']);
+ unset($value_set['is_inactive']);
+
+ $this->db->query("SELECT id FROM {$table} WHERE id =
{$id}",__LINE__,__FILE__);
+ if($this->db->next_record())
+ {
+ $this->warnings[] = "ID finnes fra før: {$id},
oppdaterer";
+ $value_set =
$this->db->validate_update($value_set);
+ $sql = "UPDATE {$table} SET {$value_set} WHERE
id = {$id}";
+ }
+ else
+ {
+ $this->warnings[] = "ID fantes ikke fra før:
{$id}";
+ }
+
+ if($this->debug)
+ {
+ _debug_array($sql);
+ }
+ else
+ {
+ $request_ok =
$this->db->query($sql,__LINE__,__FILE__);
+ }
+
+ if(!$error)
+ {
+ $this->messages[] = "Successfully updated
party: Title ({$data[7]})";
+ $ok = true;
+ }
+ else
+ {
+ $this->errors[] = "Error updating location:
Title ({$data[7]})";
+ $ok = false;
+ }
+ return $ok;
+ }
+
+
+ /**
+ * 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 == "''"));
+ }
+ }
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [7451] property: more on import,
Sigurd Nes <=