2011-01-26 00:55:57 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package timesheet
|
|
|
|
* @subpackage importexport
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright 2011 Nathan Gray
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-26 20:27:29 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Link;
|
2011-01-26 00:55:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* class import_csv for timesheet
|
|
|
|
*/
|
2016-04-26 20:27:29 +02:00
|
|
|
class timesheet_import_csv implements importexport_iface_import_plugin
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
private static $plugin_options = array(
|
|
|
|
'fieldsep', // char
|
|
|
|
'charset', // string
|
|
|
|
'update_cats', // string {override|add} overides record
|
|
|
|
// with cat(s) from csv OR add the cat from
|
|
|
|
// csv file to exeisting cat(s) of record
|
|
|
|
'num_header_lines', // int number of header lines
|
|
|
|
'field_conversion', // array( $csv_col_num => conversion)
|
|
|
|
'field_mapping', // array( $csv_col_num => adb_filed)
|
|
|
|
'conditions', /* => array containing condition arrays:
|
|
|
|
'type' => exists, // exists
|
|
|
|
'string' => '#kundennummer',
|
|
|
|
'true' => array(
|
|
|
|
'action' => update,
|
|
|
|
'last' => true,
|
|
|
|
),
|
|
|
|
'false' => array(
|
|
|
|
'action' => insert,
|
|
|
|
'last' => true,
|
|
|
|
),*/
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
public static $special_fields = array(
|
|
|
|
'addressbook' => 'Link to Addressbook, use nlast,nfirst[,org] or contact_id from addressbook',
|
|
|
|
'link_1' => '1. link: appname:appid the entry should be linked to, eg.: addressbook:123',
|
|
|
|
'link_2' => '2. link: appname:appid the entry should be linked to, eg.: addressbook:123',
|
|
|
|
'link_3' => '3. link: appname:appid the entry should be linked to, eg.: addressbook:123',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* actions wich could be done to data entries
|
|
|
|
*/
|
|
|
|
protected static $actions = array( 'none', 'update', 'insert', 'delete', );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* conditions for actions
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $conditions = array( 'exists' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var definition
|
|
|
|
*/
|
|
|
|
private $definition;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var business object
|
|
|
|
*/
|
|
|
|
private $bo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For figuring out if a record has changed
|
|
|
|
*/
|
|
|
|
protected $tracking;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $dry_run = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $user = null;
|
|
|
|
|
2011-12-15 17:24:47 +01:00
|
|
|
/**
|
|
|
|
* List of import warnings
|
|
|
|
*/
|
|
|
|
protected $warnings = array();
|
|
|
|
|
2011-01-26 00:55:57 +01:00
|
|
|
/**
|
|
|
|
* List of import errors
|
|
|
|
*/
|
|
|
|
protected $errors = array();
|
|
|
|
|
|
|
|
/**
|
2016-09-12 18:41:44 +02:00
|
|
|
* List of actions, and how many times that action was taken
|
|
|
|
*/
|
|
|
|
protected $results = array();
|
2011-01-26 00:55:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* imports entries according to given definition object.
|
|
|
|
* @param resource $_stream
|
|
|
|
* @param string $_charset
|
|
|
|
* @param definition $_definition
|
|
|
|
*/
|
2016-09-12 18:41:44 +02:00
|
|
|
public function import( $_stream, importexport_definition $_definition )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$import_csv = new importexport_import_csv( $_stream, array(
|
|
|
|
'fieldsep' => $_definition->plugin_options['fieldsep'],
|
|
|
|
'charset' => $_definition->plugin_options['charset'],
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->definition = $_definition;
|
|
|
|
|
|
|
|
$this->user = $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
|
|
|
|
// dry run?
|
|
|
|
$this->dry_run = isset( $_definition->plugin_options['dry_run'] ) ? $_definition->plugin_options['dry_run'] : false;
|
|
|
|
|
|
|
|
// fetch the bo
|
|
|
|
$this->bo = new timesheet_bo();
|
|
|
|
|
|
|
|
// Get the tracker for changes
|
|
|
|
$this->tracking = new timesheet_tracking($this->bo);
|
|
|
|
|
|
|
|
// set FieldMapping.
|
|
|
|
$import_csv->mapping = $_definition->plugin_options['field_mapping'];
|
|
|
|
|
|
|
|
// set FieldConversion
|
|
|
|
$import_csv->conversion = $_definition->plugin_options['field_conversion'];
|
|
|
|
|
|
|
|
// Add extra conversions
|
|
|
|
$import_csv->conversion_class = $this;
|
|
|
|
|
|
|
|
//check if file has a header lines
|
|
|
|
if ( isset( $_definition->plugin_options['num_header_lines'] ) && $_definition->plugin_options['num_header_lines'] > 0) {
|
|
|
|
$import_csv->skip_records($_definition->plugin_options['num_header_lines']);
|
|
|
|
} elseif(isset($_definition->plugin_options['has_header_line']) && $_definition->plugin_options['has_header_line']) {
|
|
|
|
// First method is preferred
|
|
|
|
$import_csv->skip_records(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set Owner
|
2016-08-03 17:57:49 +02:00
|
|
|
$plugin_options = $_definition->plugin_options;
|
|
|
|
$plugin_options['record_owner'] = isset( $_definition->plugin_options['record_owner'] ) ?
|
2011-04-06 00:57:06 +02:00
|
|
|
$_definition->plugin_options['record_owner'] : $this->user;
|
2016-08-03 17:57:49 +02:00
|
|
|
$_definition->plugin_options = $plugin_options;
|
2011-01-26 00:55:57 +01:00
|
|
|
|
|
|
|
// Used to try to automatically match names to account IDs
|
2016-04-26 20:27:29 +02:00
|
|
|
$addressbook = new Api\Contacts\Storage();
|
2011-01-26 00:55:57 +01:00
|
|
|
|
|
|
|
// For converting human-friendly lookups
|
2016-04-26 20:27:29 +02:00
|
|
|
$categories = new Api\Categories('timesheet');
|
2011-01-26 00:55:57 +01:00
|
|
|
$lookups = array(
|
2016-09-12 18:41:44 +02:00
|
|
|
'ts_status' => $this->bo->status_labels
|
2011-01-26 00:55:57 +01:00
|
|
|
);
|
|
|
|
|
2011-04-06 19:22:37 +02:00
|
|
|
// Status need leading spaces removed
|
2016-09-12 18:41:44 +02:00
|
|
|
foreach($lookups['ts_status'] as $id => &$label)
|
|
|
|
{
|
2011-04-06 19:22:37 +02:00
|
|
|
$label = str_replace(' ', '',trim($label));
|
|
|
|
if($label == '') unset($lookups['ts_status'][$id]);
|
|
|
|
}
|
|
|
|
|
2011-01-26 00:55:57 +01:00
|
|
|
// Start counting successes
|
|
|
|
$count = 0;
|
|
|
|
$this->results = array();
|
|
|
|
|
|
|
|
// Failures
|
|
|
|
$this->errors = array();
|
|
|
|
|
2016-09-12 18:41:44 +02:00
|
|
|
while ( $record = $import_csv->get_record() )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$success = false;
|
|
|
|
|
|
|
|
// don't import empty records
|
|
|
|
if( count( array_unique( $record ) ) < 2 ) continue;
|
|
|
|
|
2012-10-10 18:24:46 +02:00
|
|
|
$result = importexport_import_csv::convert($record, timesheet_egw_record::$types, 'timesheet', $lookups, $_definition->plugin_options['convert']);
|
2012-09-20 18:28:42 +02:00
|
|
|
if($result) $this->warnings[$import_csv->get_current_position()] = $result;
|
2011-04-04 19:01:17 +02:00
|
|
|
|
2016-04-26 20:27:29 +02:00
|
|
|
// Automatically handle text Api\Categories without explicit Api\Translation
|
2016-09-12 18:41:44 +02:00
|
|
|
foreach(array('ts_status','cat_id') as $field)
|
|
|
|
{
|
|
|
|
if(!is_numeric($record[$field]))
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
$translate_key = 'translate'.(substr($field,0,2) == 'ts' ? substr($field,2) : '_cat_id');
|
2016-09-12 18:41:44 +02:00
|
|
|
if(!is_null($lookups[$field]) && ($key = array_search($record[$field], $lookups[$field])))
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
$record[$field] = $key;
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
elseif(array_key_exists($translate_key, $_definition->plugin_options))
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
$t_field = $_definition->plugin_options[$translate_key];
|
2016-09-12 18:41:44 +02:00
|
|
|
switch ($t_field)
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
case '':
|
|
|
|
case '0':
|
|
|
|
// Skip that field
|
|
|
|
unset($record[$field]);
|
|
|
|
break;
|
|
|
|
case '~skip~':
|
|
|
|
continue 2;
|
|
|
|
default:
|
2016-09-12 18:41:44 +02:00
|
|
|
if(strpos($t_field, 'add') === 0)
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
// Check for a parent
|
|
|
|
list($name, $parent_name) = explode('~',$t_field);
|
2016-09-12 18:41:44 +02:00
|
|
|
if($parent_name)
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
$parent = importexport_helper_functions::cat_name2id($parent_name);
|
|
|
|
}
|
|
|
|
|
2016-09-12 18:41:44 +02:00
|
|
|
if($field == 'cat_id')
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
$record[$field] = importexport_helper_functions::cat_name2id($record[$field], $parent);
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
elseif ($field == 'ts_status')
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
end($this->bo->status_labels);
|
|
|
|
$id = key($this->bo->status_labels)+1;
|
|
|
|
$this->bo->status_labels[$id] = $record[$field];
|
|
|
|
$this->bo->status_labels_config[$id] = array(
|
|
|
|
'name' => $record[$field],
|
|
|
|
'parent' => $parent,
|
|
|
|
'admin' => false
|
|
|
|
);
|
2016-04-26 20:27:29 +02:00
|
|
|
Api\Config::save_value('status_labels',$this->bo->status_labels_config,TIMESHEET_APP);
|
2011-03-29 23:46:54 +02:00
|
|
|
$lookups[$field][$id] = $name;
|
|
|
|
$record[$field] = $id;
|
|
|
|
}
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
elseif(!is_null($lookups[$field]) && ($key = array_search($t_field, $lookups[$field])))
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
$record[$field] = $key;
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-29 23:46:54 +02:00
|
|
|
$record[$field] = $t_field;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-09 19:26:43 +01:00
|
|
|
|
2011-01-26 00:55:57 +01:00
|
|
|
// Set creator, unless it's supposed to come from CSV file
|
2016-09-12 18:41:44 +02:00
|
|
|
if($_definition->plugin_options['owner_from_csv'] && $record['ts_owner'])
|
|
|
|
{
|
|
|
|
if(!is_numeric($record['ts_owner']))
|
|
|
|
{
|
2016-04-26 20:27:29 +02:00
|
|
|
// Automatically handle text owner without explicit Api\Translation
|
2011-04-04 23:24:06 +02:00
|
|
|
$new_owner = importexport_helper_functions::account_name2id($record['ts_owner']);
|
2016-09-12 18:41:44 +02:00
|
|
|
if($new_owner == '')
|
|
|
|
{
|
2011-04-04 23:24:06 +02:00
|
|
|
$this->errors[$import_csv->get_current_position()] = lang(
|
|
|
|
'Unable to convert "%1" to account ID. Using plugin setting (%2) for %3.',
|
|
|
|
$record['ts_owner'],
|
2016-04-26 20:27:29 +02:00
|
|
|
Api\Accounts::username($_definition->plugin_options['record_owner']),
|
2011-04-04 23:24:06 +02:00
|
|
|
lang($this->bo->field2label['ts_owner'])
|
|
|
|
);
|
2011-04-06 00:57:06 +02:00
|
|
|
$record['ts_owner'] = $_definition->plugin_options['record_owner'];
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-04 23:24:06 +02:00
|
|
|
$record['ts_owner'] = $new_owner;
|
|
|
|
}
|
2011-01-26 00:55:57 +01:00
|
|
|
}
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
elseif ($_definition->plugin_options['record_owner'])
|
|
|
|
{
|
2011-04-06 00:57:06 +02:00
|
|
|
$record['ts_owner'] = $_definition->plugin_options['record_owner'];
|
2011-01-26 00:55:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check account IDs
|
2016-09-12 18:41:44 +02:00
|
|
|
foreach(array('ts_modifier') as $field)
|
|
|
|
{
|
|
|
|
if($record[$field] && !is_numeric($record[$field]))
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
// Try an automatic conversion
|
2011-03-29 23:46:54 +02:00
|
|
|
$account_id = importexport_helper_functions::account_name2id($record[$field]);
|
2016-09-12 18:41:44 +02:00
|
|
|
if($account_id && strtoupper(Api\Accounts::username($account_id)) == strtoupper($record[$field]))
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$record[$field] = $account_id;
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$this->errors[$import_csv->get_current_position()] = lang(
|
2011-03-29 23:46:54 +02:00
|
|
|
'Unable to convert "%1" to account ID. Using plugin setting (%2) for %3.',
|
|
|
|
$record[$field],
|
2016-04-26 20:27:29 +02:00
|
|
|
Api\Accounts::username($_definition->plugin_options['record_owner']),
|
2011-03-29 23:46:54 +02:00
|
|
|
$this->bo->field2label[$field] ? lang($this->bo->field2label[$field]) : $field
|
2011-01-26 00:55:57 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special values
|
|
|
|
if ($record['addressbook'] && !is_numeric($record['addressbook']))
|
|
|
|
{
|
|
|
|
list($lastname,$firstname,$org_name) = explode(',',$record['addressbook']);
|
|
|
|
$record['addressbook'] = self::addr_id($lastname,$firstname,$org_name);
|
|
|
|
}
|
2016-09-20 17:42:53 +02:00
|
|
|
if ($record['pm_id'] && !is_numeric($record['pm_id']))
|
|
|
|
{
|
|
|
|
$pms = Link::query('projectmanager',$record['pm_id']);
|
|
|
|
$record['pm_id'] = key($pms);
|
|
|
|
}
|
2011-01-26 00:55:57 +01:00
|
|
|
|
2016-09-12 18:41:44 +02:00
|
|
|
if ( $_definition->plugin_options['conditions'] )
|
|
|
|
{
|
|
|
|
foreach ( $_definition->plugin_options['conditions'] as $condition )
|
|
|
|
{
|
2011-03-22 00:06:32 +01:00
|
|
|
$results = array();
|
2016-09-12 18:41:44 +02:00
|
|
|
switch ( $condition['type'] )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
// exists
|
|
|
|
case 'exists' :
|
2016-09-12 18:41:44 +02:00
|
|
|
if($record[$condition['string']])
|
|
|
|
{
|
2011-03-22 00:06:32 +01:00
|
|
|
$results = $this->bo->search(array($condition['string'] => $record[$condition['string']]));
|
|
|
|
}
|
2011-01-26 00:55:57 +01:00
|
|
|
|
2016-09-12 18:41:44 +02:00
|
|
|
if ( is_array( $results ) && count( array_keys( $results )) >= 1 )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
// apply action to all records matching this exists condition
|
|
|
|
$action = $condition['true'];
|
2016-09-12 18:41:44 +02:00
|
|
|
foreach ( (array)$results as $result )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$record['ts_id'] = $result['ts_id'];
|
2016-09-12 18:41:44 +02:00
|
|
|
if ( $_definition->plugin_options['update_cats'] == 'add' )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
if ( !is_array( $result['cat_id'] ) ) $result['cat_id'] = explode( ',', $result['cat_id'] );
|
|
|
|
if ( !is_array( $record['cat_id'] ) ) $record['cat_id'] = explode( ',', $record['cat_id'] );
|
|
|
|
$record['cat_id'] = implode( ',', array_unique( array_merge( $record['cat_id'], $result['cat_id'] ) ) );
|
|
|
|
}
|
|
|
|
$success = $this->action( $action['action'], $record, $import_csv->get_current_position() );
|
|
|
|
}
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$action = $condition['false'];
|
|
|
|
$success = ($this->action( $action['action'], $record, $import_csv->get_current_position() ));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// not supported action
|
|
|
|
default :
|
|
|
|
die('condition / action not supported!!!');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($action['last']) break;
|
|
|
|
}
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
// unconditional insert
|
|
|
|
$success = $this->action( 'insert', $record, $import_csv->get_current_position() );
|
|
|
|
}
|
|
|
|
if($success) $count++;
|
|
|
|
}
|
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* perform the required action
|
|
|
|
*
|
|
|
|
* @param int $_action one of $this->actions
|
|
|
|
* @param array $_data tracker data for the action
|
|
|
|
* @return bool success or not
|
|
|
|
*/
|
2016-09-12 18:41:44 +02:00
|
|
|
private function action ( $_action, $_data, $record_num = 0 )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$result = true;
|
2016-09-12 18:41:44 +02:00
|
|
|
switch ($_action)
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
case 'none' :
|
|
|
|
return true;
|
|
|
|
case 'update' :
|
|
|
|
// Only update if there are changes
|
2011-04-06 20:31:52 +02:00
|
|
|
$old_record = new timesheet_egw_record($_data['ts_id']);
|
|
|
|
$old = $old_record->get_record_array();
|
2011-01-26 00:55:57 +01:00
|
|
|
|
2016-09-12 18:41:44 +02:00
|
|
|
if(!$this->definition->plugin_options['change_owner'])
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
// Don't change creator of an existing ticket
|
|
|
|
unset($_data['ts_owner']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge to deal with fields not in import record
|
|
|
|
$_data = array_merge($old, $_data);
|
|
|
|
$changed = $this->tracking->changed_fields($_data, $old);
|
2016-09-12 18:41:44 +02:00
|
|
|
if(count($changed) == 0 && !$this->definition->plugin_options['update_timestamp'])
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-04-06 20:31:52 +02:00
|
|
|
|
|
|
|
// Clear old link, if different
|
2016-09-12 18:41:44 +02:00
|
|
|
if ($_data['ts_id'] && array_key_exists('pm_id', $_data) && $_data['pm_id'] != $old['pm_id'])
|
|
|
|
{
|
2016-04-26 20:27:29 +02:00
|
|
|
Link::unlink2(0,TIMESHEET_APP,$_data['ts_id'],0,'projectmanager',$old['pm_id']);
|
2011-04-06 20:31:52 +02:00
|
|
|
}
|
2016-04-26 20:27:29 +02:00
|
|
|
|
2011-01-26 00:55:57 +01:00
|
|
|
// Fall through
|
|
|
|
case 'insert' :
|
2016-09-12 18:41:44 +02:00
|
|
|
if ( $this->dry_run )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
//print_r($_data);
|
|
|
|
$this->results[$_action]++;
|
|
|
|
break;
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$result = $this->bo->save( $_data);
|
2011-04-06 20:31:52 +02:00
|
|
|
$_data['ts_id'] = $this->bo->data['ts_id'];
|
|
|
|
|
|
|
|
// Set projectmanager link
|
2016-09-12 18:41:44 +02:00
|
|
|
if ($_data['pm_id'])
|
|
|
|
{
|
2016-04-26 20:27:29 +02:00
|
|
|
Link::link(TIMESHEET_APP,$_data['ts_id'],'projectmanager',$_data['pm_id']);
|
2016-09-12 18:41:44 +02:00
|
|
|
|
|
|
|
// notify the link-class about the update, as other apps may be subscribed to it
|
|
|
|
Link::notify_update(TIMESHEET_APP,$this->data['ts_id'],$this->data);
|
2011-04-06 20:31:52 +02:00
|
|
|
}
|
|
|
|
|
2016-09-12 18:41:44 +02:00
|
|
|
if($result)
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$this->errors[$record_num] = lang('Permissions error - %1 could not %2',
|
|
|
|
$GLOBALS['egw']->accounts->id2name($_data['owner']),
|
|
|
|
lang($_action)
|
2011-03-29 23:46:54 +02:00
|
|
|
) . ' ' . $result;
|
2016-09-12 18:41:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$this->results[$_action]++;
|
|
|
|
$result = $this->bo->data['ts_id'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2016-04-26 20:27:29 +02:00
|
|
|
throw new Api\Exception('Unsupported action');
|
2011-01-26 00:55:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process some additional fields
|
2016-09-12 18:41:44 +02:00
|
|
|
if(!is_numeric($result))
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
$_link_id = false;
|
2016-09-12 18:41:44 +02:00
|
|
|
foreach(self::$special_fields as $field => $desc)
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
if(!$_data[$field]) continue;
|
|
|
|
|
|
|
|
// Links
|
2016-09-12 18:41:44 +02:00
|
|
|
if(strpos($field, 'link') === 0)
|
|
|
|
{
|
|
|
|
list($app, $app_id) = explode(':', $_data[$field]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
$app = $field;
|
2016-09-12 18:41:44 +02:00
|
|
|
$app_id = $_data[$field];
|
2011-01-26 00:55:57 +01:00
|
|
|
}
|
2016-09-12 18:41:44 +02:00
|
|
|
if ($app && $app_id)
|
|
|
|
{
|
|
|
|
$link_id = Link::link('timesheet',$_data['ts_id'],$app,$app_id);
|
2011-01-26 00:55:57 +01:00
|
|
|
}
|
|
|
|
}
|
2016-09-12 18:41:44 +02:00
|
|
|
return true;
|
2011-01-26 00:55:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
2016-09-12 18:41:44 +02:00
|
|
|
public static function get_name()
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
return lang('Timesheet CSV import');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
2016-09-12 18:41:44 +02:00
|
|
|
public static function get_description()
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
return lang("Imports entries into the timesheet from a CSV File. ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retruns file suffix(s) plugin can handle (e.g. csv)
|
|
|
|
*
|
|
|
|
* @return string suffix (comma seperated)
|
|
|
|
*/
|
2016-09-12 18:41:44 +02:00
|
|
|
public static function get_filesuffix()
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
return 'csv';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return etemplate components for options.
|
|
|
|
* @abstract We can't deal with etemplate objects here, as an uietemplate
|
|
|
|
* objects itself are scipt orientated and not "dialog objects"
|
|
|
|
*
|
|
|
|
* @return array (
|
|
|
|
* name => string,
|
|
|
|
* content => array,
|
|
|
|
* sel_options => array,
|
|
|
|
* preserv => array,
|
|
|
|
* )
|
|
|
|
*/
|
2016-09-12 18:41:44 +02:00
|
|
|
public function get_options_etpl()
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
// lets do it!
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns etemplate name for slectors of this plugin
|
|
|
|
*
|
|
|
|
* @return string etemplate name
|
|
|
|
*/
|
2016-09-12 18:41:44 +02:00
|
|
|
public function get_selectors_etpl()
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
// lets do it!
|
|
|
|
}
|
|
|
|
|
2011-12-15 17:24:47 +01:00
|
|
|
/**
|
2016-09-12 18:41:44 +02:00
|
|
|
* Returns warnings that were encountered during importing
|
|
|
|
* Maximum of one warning message per record, but you can append if you need to
|
|
|
|
*
|
|
|
|
* @return Array (
|
|
|
|
* record_# => warning message
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function get_warnings()
|
|
|
|
{
|
2011-12-15 17:24:47 +01:00
|
|
|
return $this->warnings;
|
|
|
|
}
|
|
|
|
|
2011-01-26 00:55:57 +01:00
|
|
|
/**
|
2016-09-12 18:41:44 +02:00
|
|
|
* Returns errors that were encountered during importing
|
|
|
|
* Maximum of one error message per record, but you can append if you need to
|
|
|
|
*
|
|
|
|
* @return Array (
|
|
|
|
* record_# => error message
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function get_errors()
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
return $this->errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-12 18:41:44 +02:00
|
|
|
* Returns a list of actions taken, and the number of records for that action.
|
|
|
|
* Actions are things like 'insert', 'update', 'delete', and may be different for each plugin.
|
|
|
|
*
|
|
|
|
* @return Array (
|
|
|
|
* action => record count
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public function get_results()
|
|
|
|
{
|
|
|
|
return $this->results;
|
|
|
|
}
|
2011-01-26 00:55:57 +01:00
|
|
|
// end of iface_export_plugin
|
|
|
|
|
|
|
|
// Extra conversion functions - must be static
|
2016-09-12 18:41:44 +02:00
|
|
|
public static function addr_id( $n_family,$n_given=null,$org_name=null )
|
|
|
|
{
|
2011-01-26 00:55:57 +01:00
|
|
|
|
|
|
|
// find in Addressbook, at least n_family AND (n_given OR org_name) have to match
|
|
|
|
static $contacts;
|
|
|
|
if (is_null($n_given) && is_null($org_name))
|
|
|
|
{
|
|
|
|
// Maybe all in one
|
|
|
|
list($n_family, $n_given, $org_name) = explode(',', $n_family);
|
|
|
|
}
|
|
|
|
$n_family = trim($n_family);
|
|
|
|
if(!is_null($n_given)) $n_given = trim($n_given);
|
|
|
|
if (!is_object($contacts))
|
|
|
|
{
|
|
|
|
$contacts =& CreateObject('phpgwapi.contacts');
|
|
|
|
}
|
|
|
|
if (!is_null($org_name)) // org_name given?
|
|
|
|
{
|
|
|
|
$org_name = trim($org_name);
|
|
|
|
$addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,n_given=$n_given,org_name=$org_name" );
|
|
|
|
if (!count($addrs))
|
|
|
|
{
|
|
|
|
$addrs = $contacts->read( 0,0,array('id'),'',"n_family=$n_family,org_name=$org_name",'','n_family,org_name');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!is_null($n_given) && (is_null($org_name) || !count($addrs))) // first name given and no result so far
|
|
|
|
{
|
|
|
|
$addrs = $contacts->search(array('n_family' => $n_family, 'n_given' => $n_given));
|
|
|
|
}
|
|
|
|
if (is_null($n_given) && is_null($org_name)) // just one name given, check against fn (= full name)
|
|
|
|
{
|
|
|
|
$addrs = $contacts->read( 0,0,array('id'),'',"n_fn=$n_family",'','n_fn' );
|
|
|
|
}
|
|
|
|
if (count($addrs))
|
|
|
|
{
|
|
|
|
return $addrs[0]['id'];
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|