[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [7456] property: more on import
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [7456] property: more on import |
Date: |
Thu, 30 Jun 2011 13:50:58 +0000 |
Revision: 7456
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7456
Author: sigurdne
Date: 2011-06-30 13:50:58 +0000 (Thu, 30 Jun 2011)
Log Message:
-----------
property: more on import
Modified Paths:
--------------
trunk/property/inc/class.uiimport.inc.php
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-30 08:35:07 UTC (rev
7455)
+++ trunk/property/inc/class.uiimport.inc.php 2011-06-30 13:50:58 UTC (rev
7456)
@@ -24,6 +24,7 @@
protected $import_conversion;
protected $steps = 0;
protected $fields = array();
+ protected $table;
// Label on the import button. Changes as we step through the
import process.
protected $import_button_label;
@@ -43,6 +44,7 @@
// $GLOBALS['phpgw']->common->phpgw_header(true);
$this->account =
(int)$GLOBALS['phpgw_info']['user']['account_id'];
$this->db = & $GLOBALS['phpgw']->db;
+ $this->table = phpgw::get_var('table');
}
@@ -61,14 +63,12 @@
{
if($GLOBALS['phpgw']->session->is_repost() &&
!phpgw::get_var('debug', 'bool'))
{
- echo('Hmm... looks like a repost!');
- $action =
$GLOBALS['phpgw']->link('/index.php',
array('menuaction'=>'property.uiimport.index'));
- echo "<br><a href= '$action'>Start
over</a>" ;
-
- $GLOBALS['phpgw']->common->phpgw_exit();
-
+ phpgwapi_cache::session_set('property',
'import_message', 'Hmm... looks like a repost!');
+
$GLOBALS['phpgw']->redirect_link('/index.php',
array('menuaction'=>'property.uiimport.index'));
}
+ phpgwapi_cache::session_set('property',
'import_settings', $_POST);
+
$this->conv_type =
phpgw::get_var('conv_type');
$start_time = time(); // Start time of import
@@ -112,6 +112,12 @@
$files = $this->get_files($path);
}
+ if(!$files)
+ {
+ phpgwapi_cache::session_set('property',
'import_message', 'Ingen filer er valgt');
+
$GLOBALS['phpgw']->redirect_link('/index.php',
array('menuaction'=>'property.uiimport.index'));
+ }
+
foreach ($files as $file)
{
$valid_type = false;
@@ -177,11 +183,17 @@
}
echo "</ul>";
}
+ echo '<a href="'.
$GLOBALS['phpgw']->link('/home.php') . '">Home</a>';
+ echo '</br><a href="'.
$GLOBALS['phpgw']->link('/index.php',
array('menuaction'=>'property.uiimport.index')) . '">Import</a>';
+
}
else
{
+ $import_settings =
phpgwapi_cache::session_get('property', 'import_settings');
+ $import_message =
phpgwapi_cache::session_get('property', 'import_message');
- $conv_list =
$this->get_import_conv($this->conv_type);
+ phpgwapi_cache::session_clear('property',
'import_message');
+ $conv_list =
$this->get_import_conv($import_settings['conv_type']);
$conv_option = '<option value="">' . lang('none
selected') . '</option>' . "\n";
foreach ( $conv_list as $conv)
@@ -196,25 +208,60 @@
<option
value='{$conv['id']}'{$selected}>{$conv['name']}</option>
HTML;
}
+
+ $tables = $this->db->table_names();
+ sort($tables);
+
+ $table_option = '<option value="">' .
lang('none selected') . '</option>' . "\n";
+ foreach ( $tables as $table)
+ {
+ $selected = $import_settings['table']
== $table ? 'selected = "selected"' : '';
+ $table_option .= <<<HTML
+ <option
value='{$table}'{$selected}>{$table}</option>
+HTML;
+ }
+
+
+ $home = $GLOBALS['phpgw']->link('/home.php');
$action =
$GLOBALS['phpgw']->link('/index.php',
array('menuaction'=>'property.uiimport.index'));
+
+ $debug_checked =
isset($import_settings['debug']) && $import_settings['debug'] ? 'checked =
"checked"' : '';
$html = <<<HTML
<h1><img
src="rental/templates/base/images/32x32/actions/document-save.png" /> Importer
( MsExcel / CSV )</h1>
- <div id="messageHolder"></div>
+ <div id="messageHolder">{$import_message}</div>
<form action="{$action}" method="post"
enctype="multipart/form-data">
<fieldset>
- <label for="file">Choose
file:</label>
- <input type="file" name="file"
id="file" title = 'Single file'/>
- <label for="path">Local
path:</label>
- <input type="text" name="path"
id="path" title = 'Alle filer i katalogen'/>
- <label for="conv_type">Choose
conversion:</label>
- <select name="conv_type"
id="conv_type">
- {$conv_option}
+ <p>
+ <label
for="file">Choose file:</label>
+ <input type="file"
name="file" id="file" title = 'Single file'/>
+ </p>
+ <p>
+ <label for="path">Local
path:</label>
+ <input type="text"
name="path" id="path" value = '{$import_settings['path']}' title = 'Alle filer
i katalogen'/>
+ </p>
+ <p>
+ <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}" />
+ </p>
+ <p>
+ <label
for="table">Choose Table:</label>
+ <select name="table"
id="table">
+ {$table_option}
+ </select>
+ </p>
+
+ <p>
+ <label
for="debug">Debug:</label>
+ <input type="checkbox"
name="debug" id="debug" {$debug_checked} value ='1' />
+ </p>
+ <p>
+ <input type="submit"
name="importsubmit" value="{$this->import_button_label}" />
+ </p>
</fieldset>
</form>
+ <br><a href='$home'>Home</a>
HTML;
echo $html;
}
@@ -249,7 +296,24 @@
protected function import_data()
{
+ $metadata = array();
+ if($this->table && $this->fields)
+ {
+ $metadata = $this->db->metadata($this->table);
+
+ foreach($this->fields as $field)
+ {
+ if(!isset($metadata[$field]))
+ {
+ throw new Exception("Feltet
'{$field}' finnes ikke i tabellen '{$this->table}'");
+ }
+ }
+// _debug_array($metadata);die();
+ }
+
+ $this->import_conversion->table = $this->table;
$this->import_conversion->fields = $this->fields;
+ $this->import_conversion->metadata = $metadata;
$start_time = time();
@@ -320,7 +384,7 @@
if ($skipfirstline)
{
- $this->fields = $data->sheets[0]['cells'][1];
+ $this->fields =
array_values($data->sheets[0]['cells'][1]);
}
$rows = $data->sheets[0]['numRows']+1;
@@ -356,9 +420,9 @@
private function log_messages($step)
{
- sort($this->errors);
- sort($this->warnings);
- sort($this->messages);
+ // sort($this->errors);
+ // sort($this->warnings);
+ // sort($this->messages);
$msgs = array_merge(
array('----------------Errors--------------------'),
Modified: trunk/property/inc/import/default/cvs_oppdater_rental_party_bkb
===================================================================
--- trunk/property/inc/import/default/cvs_oppdater_rental_party_bkb
2011-06-30 08:35:07 UTC (rev 7455)
+++ trunk/property/inc/import/default/cvs_oppdater_rental_party_bkb
2011-06-30 13:50:58 UTC (rev 7456)
@@ -7,6 +7,8 @@
public $errors = array();
public $debug = true;
public $fields = array();
+ public $table;
+ public $metadata = array();
public function __construct()
{
@@ -18,43 +20,32 @@
public function add($data)
{
$error = false;
- $table = 'rental_party';
- $id = (int)$data[0];
+ $table = $this->table;
+ $fields = $this->fields;
+
+ if(!$table)
+ {
+ throw new Exception("Tabell er ikke angitt");
+ }
+
+ if(!$fields)
+ {
+ throw new Exception("Felter er ikke definert");
+ }
+
+ $id = (int)$data[array_search('id', $fields)];
- $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'
- );
+ if(!$id)
+ {
+ throw new Exception("Fant ikke verdi for feltet
'id'");
+ }
$value_set = array();
foreach ($fields as $key => $field)
{
- $value_set[$field] =
$this->db->db_addslashes($data[$key]);
+ $value_set[$field] =
$this->validate_value($data[$key], $field);
}
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())
@@ -102,4 +93,25 @@
{
return ((trim($value) == "") || ($data == "<NULL>") ||
($data == "''"));
}
+
+ protected function validate_value($value,$field)
+ {
+ $datatype = $this->metadata[$field]->type;
+ switch ($datatype)
+ {
+ case 'char':
+ case 'varchar':
+ case 'text':
+ $ret = $this->db->db_addslashes($value);
+ break;
+ case 'bool':
+ $ret = $value ? 'True' : 'False';
+ break;
+ default:
+ $ret = $value;
+ }
+
+ return $ret;
+ }
+
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [7456] property: more on import,
Sigurd Nes <=