mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
Add ability to add unknown categories & statuses
This commit is contained in:
parent
9056a41ebf
commit
ff1b3d3345
@ -25,7 +25,7 @@ class timesheet_export_openoffice implements importexport_iface_export_plugin {
|
|||||||
*/
|
*/
|
||||||
public function export( $_stream, importexport_definition $_definition) {
|
public function export( $_stream, importexport_definition $_definition) {
|
||||||
|
|
||||||
$options = $_definition->options;
|
$options = $_definition->plugin_options;
|
||||||
|
|
||||||
$botimesheet = new timesheet_bo();
|
$botimesheet = new timesheet_bo();
|
||||||
|
|
||||||
@ -33,11 +33,11 @@ class timesheet_export_openoffice implements importexport_iface_export_plugin {
|
|||||||
|
|
||||||
$query = $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP);
|
$query = $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP);
|
||||||
|
|
||||||
$bo_pm = CreateObject('projectmanager.boprojectmanager');
|
$bo_pm = CreateObject('projectmanager.projectmanager_bo');
|
||||||
$childs = $bo_pm->children( $query['col_filter']['pm_id'] );
|
$childs = $bo_pm->children( $query['col_filter']['pm_id'] );
|
||||||
$childs[] = $query['col_filter']['pm_id'];
|
$childs[] = $query['col_filter']['pm_id'];
|
||||||
$pmChilds = implode(",",$childs);
|
$pmChilds = implode(",",$childs);
|
||||||
$botimesheet->db->select( 'egw_links','link_id, link_id1','',
|
$GLOBALS['egw']->db->select( 'egw_links','link_id, link_id1','',
|
||||||
__LINE__,__FILE__,False,
|
__LINE__,__FILE__,False,
|
||||||
'',False,0,
|
'',False,0,
|
||||||
'JOIN egw_pm_projects ON (pm_id = link_id2)
|
'JOIN egw_pm_projects ON (pm_id = link_id2)
|
||||||
@ -189,7 +189,7 @@ class timesheet_export_openoffice implements importexport_iface_export_plugin {
|
|||||||
* @return string html
|
* @return string html
|
||||||
*/
|
*/
|
||||||
public function get_options_etpl() {
|
public function get_options_etpl() {
|
||||||
return 'timesheet.export_openoffice_options';
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,7 +197,7 @@ class timesheet_export_openoffice implements importexport_iface_export_plugin {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function get_selectors_etpl() {
|
public function get_selectors_etpl() {
|
||||||
return '<b>Selectors:</b>';
|
return array('preserv' => true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ class timesheet_import_csv implements importexport_iface_import_plugin {
|
|||||||
// For converting human-friendly lookups
|
// For converting human-friendly lookups
|
||||||
$categories = new categories('timesheet');
|
$categories = new categories('timesheet');
|
||||||
$lookups = array(
|
$lookups = array(
|
||||||
'ts_status' => $bo->status_labels,
|
'ts_status' => $this->bo->status_labels,
|
||||||
'cat_id' => $categories->return_sorted_array(0,False,'','','',true)
|
'cat_id' => $categories->return_sorted_array(0,False,'','','',true)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -163,42 +163,92 @@ class timesheet_import_csv implements importexport_iface_import_plugin {
|
|||||||
// don't import empty records
|
// don't import empty records
|
||||||
if( count( array_unique( $record ) ) < 2 ) continue;
|
if( count( array_unique( $record ) ) < 2 ) continue;
|
||||||
|
|
||||||
|
// Date / time
|
||||||
|
$record['ts_start'] = strtotime($record['ts_start']);
|
||||||
|
|
||||||
// Automatically handle text categories without explicit translation
|
// Automatically handle text categories without explicit translation
|
||||||
$record['cat_id'] = importexport_helper_functions::cat_name2id($record['cat_id']);
|
foreach(array('ts_status','cat_id') as $field) {
|
||||||
|
if(!is_numeric($record[$field])) {
|
||||||
|
$translate_key = 'translate'.(substr($field,0,2) == 'ts' ? substr($field,2) : '_cat_id');
|
||||||
|
if($key = array_search($record[$field], $lookups[$field])) {
|
||||||
|
$record[$field] = $key;
|
||||||
|
} elseif(array_key_exists($translate_key, $_definition->plugin_options)) {
|
||||||
|
$t_field = $_definition->plugin_options[$translate_key];
|
||||||
|
switch ($t_field) {
|
||||||
|
case '':
|
||||||
|
case '0':
|
||||||
|
// Skip that field
|
||||||
|
unset($record[$field]);
|
||||||
|
break;
|
||||||
|
case '~skip~':
|
||||||
|
continue 2;
|
||||||
|
default:
|
||||||
|
if(strpos($t_field, 'add') === 0) {
|
||||||
|
// Check for a parent
|
||||||
|
list($name, $parent_name) = explode('~',$t_field);
|
||||||
|
if($parent_name) {
|
||||||
|
$parent = importexport_helper_functions::cat_name2id($parent_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($field == 'cat_id') {
|
||||||
|
$record[$field] = importexport_helper_functions::cat_name2id($record[$field], $parent);
|
||||||
|
} elseif ($field == 'ts_status') {
|
||||||
|
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
|
||||||
|
);
|
||||||
|
config::save_value('status_labels',$this->bo->status_labels_config,TIMESHEET_APP);
|
||||||
|
$lookups[$field][$id] = $name;
|
||||||
|
$record[$field] = $id;
|
||||||
|
}
|
||||||
|
} elseif($key = array_search($t_field, $lookups[$field])) {
|
||||||
|
$record[$field] = $key;
|
||||||
|
} else {
|
||||||
|
$record[$field] = $t_field;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set creator, unless it's supposed to come from CSV file
|
// Set creator, unless it's supposed to come from CSV file
|
||||||
if($_definition->plugin_options['creator_from_csv']) {
|
if($_definition->plugin_options['owner_from_csv'] && $record['ts_owner'] && !is_numeric($record['ts_owner'])) {
|
||||||
if(!is_numeric($record['ts_owner'])) {
|
// Automatically handle text owner without explicit translation
|
||||||
|
$new_owner = importexport_helper_functions::account_name2id($record['ts_owner']);
|
||||||
|
if($new_owner == '') {
|
||||||
$this->errors[$import_csv->get_current_position()] = lang(
|
$this->errors[$import_csv->get_current_position()] = lang(
|
||||||
'Invalid owner ID: %1. Might be a bad field translation. Used %2 instead.',
|
'Unable to convert "%1" to account ID. Using plugin setting (%2) for %3.',
|
||||||
$record['ts_owner'],
|
$record['ts_owner'],
|
||||||
$_definition->plugin_options['creator']
|
common::grab_owner_name($_definition->plugin_options['creator']),
|
||||||
|
lang($this->bo->field2label['ts_owner'])
|
||||||
);
|
);
|
||||||
$record['ts_owner'] = $_definition->plugin_options['creator'];
|
$record['ts_owner'] = $_definition->plugin_options['creator'];
|
||||||
|
} else {
|
||||||
|
$record['ts_owner'] = $new_owner;
|
||||||
}
|
}
|
||||||
} elseif ($_definition->plugin_options['creator']) {
|
} elseif ($_definition->plugin_options['creator']) {
|
||||||
$record['ts_owner'] = $_definition->plugin_options['creator'];
|
$record['ts_owner'] = $_definition->plugin_options['creator'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check account IDs
|
// Check account IDs
|
||||||
foreach(array('ts_owner','ts_modifier') as $field) {
|
foreach(array('ts_modifier') as $field) {
|
||||||
if($record[$field] && !is_numeric($record[$field])) {
|
if($record[$field] && !is_numeric($record[$field])) {
|
||||||
// Try an automatic conversion
|
// Try an automatic conversion
|
||||||
$contact_id = self::addr_id($record[$field]);
|
$account_id = importexport_helper_functions::account_name2id($record[$field]);
|
||||||
if($contact_id) {
|
if($account_id && strtoupper(common::grab_owner_name($account_id)) == strtoupper($record[$field])) {
|
||||||
$contact = $addressbook->read($contact_id);
|
|
||||||
$account_id = $contact['account_id'];
|
|
||||||
} else {
|
|
||||||
$accounts = $GLOBALS['egw']->accounts->search(array('type' => 'both','query'=>$record[$field]));
|
|
||||||
if($accounts) $account_id = key($accounts);
|
|
||||||
}
|
|
||||||
if($account_id && common::grab_owner_name($account_id) == $record[$field]) {
|
|
||||||
$record[$field] = $account_id;
|
$record[$field] = $account_id;
|
||||||
} else {
|
} else {
|
||||||
$this->errors[$import_csv->get_current_position()] = lang(
|
$this->errors[$import_csv->get_current_position()] = lang(
|
||||||
'Invalid field: %1 = %2, it needs to be a number.', $field, $record[$field]
|
'Unable to convert "%1" to account ID. Using plugin setting (%2) for %3.',
|
||||||
|
$record[$field],
|
||||||
|
common::grab_owner_name($_definition->plugin_options['creator']),
|
||||||
|
$this->bo->field2label[$field] ? lang($this->bo->field2label[$field]) : $field
|
||||||
);
|
);
|
||||||
continue 2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,7 +351,7 @@ class timesheet_import_csv implements importexport_iface_import_plugin {
|
|||||||
$this->errors[$record_num] = lang('Permissions error - %1 could not %2',
|
$this->errors[$record_num] = lang('Permissions error - %1 could not %2',
|
||||||
$GLOBALS['egw']->accounts->id2name($_data['owner']),
|
$GLOBALS['egw']->accounts->id2name($_data['owner']),
|
||||||
lang($_action)
|
lang($_action)
|
||||||
) . $result;
|
) . ' ' . $result;
|
||||||
} else {
|
} else {
|
||||||
$this->results[$_action]++;
|
$this->results[$_action]++;
|
||||||
$result = $this->bo->data['ts_id'];
|
$result = $this->bo->data['ts_id'];
|
||||||
|
@ -21,10 +21,13 @@ class timesheet_wizard_import_csv extends importexport_wizard_basic_import_csv
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->steps += array(
|
$this->steps += array(
|
||||||
|
'wizard_step45' => lang('Import options'),
|
||||||
'wizard_step50' => lang('Manage mapping'),
|
'wizard_step50' => lang('Manage mapping'),
|
||||||
'wizard_step60' => lang('Choose \'creator\' of imported data'),
|
'wizard_step60' => lang('Choose \'creator\' of imported data'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->step_templates['wizard_step45'] = 'timesheet.wizard_import_options';
|
||||||
|
|
||||||
// Field mapping
|
// Field mapping
|
||||||
$bo = new timesheet_bo();
|
$bo = new timesheet_bo();
|
||||||
$this->mapping_fields = array('ts_id' => lang('Timesheet ID')) + $bo->field2label;
|
$this->mapping_fields = array('ts_id' => lang('Timesheet ID')) + $bo->field2label;
|
||||||
@ -57,6 +60,65 @@ class timesheet_wizard_import_csv extends importexport_wizard_basic_import_csv
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wizard_step45(&$content, &$sel_options, &$readonlys, &$preserv)
|
||||||
|
{
|
||||||
|
if($this->debug) error_log(__METHOD__.'->$content '.print_r($content,true));
|
||||||
|
|
||||||
|
// return from step45
|
||||||
|
if ($content['step'] == 'wizard_step45')
|
||||||
|
{
|
||||||
|
switch (array_search('pressed', $content['button']))
|
||||||
|
{
|
||||||
|
case 'next':
|
||||||
|
return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],1);
|
||||||
|
case 'previous' :
|
||||||
|
return $GLOBALS['egw']->importexport_definitions_ui->get_step($content['step'],-1);
|
||||||
|
case 'finish':
|
||||||
|
return 'wizard_finish';
|
||||||
|
default :
|
||||||
|
return $this->wizard_step45($content,$sel_options,$readonlys,$preserv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// init step45
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$content['message'] = $this->steps['wizard_step45'];
|
||||||
|
$content['step'] = 'wizard_step45';
|
||||||
|
|
||||||
|
$ui = new timesheet_ui();
|
||||||
|
$options = array(
|
||||||
|
false => lang('Ignore'),
|
||||||
|
'~skip~' => lang('Skip record'),
|
||||||
|
'add' => lang('Add'),
|
||||||
|
);
|
||||||
|
$set_to = lang('Set to') . ':';
|
||||||
|
$categories = new categories('timesheet');
|
||||||
|
$cat_list = array();
|
||||||
|
foreach((array)$categories->return_sorted_array(0,False,'','','',true) as $cat) {
|
||||||
|
$s = str_repeat(' ',$cat['level']) . stripslashes($cat['name']);
|
||||||
|
|
||||||
|
if (categories::is_global($cat))
|
||||||
|
{
|
||||||
|
$s .= ' ♦';
|
||||||
|
}
|
||||||
|
$cat_list[$cat['id']] = empty($cat['description']) ? $s : array(
|
||||||
|
'label' => $s,
|
||||||
|
'title' => $cat['description'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$sel_options = array(
|
||||||
|
'translate_status' => $options + array($set_to => $ui->status_labels),
|
||||||
|
'translate_cat_id' => $options + array($set_to => $cat_list),
|
||||||
|
);
|
||||||
|
$preserv = $content;
|
||||||
|
foreach($sel_options as $field => $options) {
|
||||||
|
if(!array_key_exists($field,$content)) $content[$field] = $content['plugin_options'][$field];
|
||||||
|
}
|
||||||
|
unset ($preserv['button']);
|
||||||
|
return $this->step_templates['wizard_step45'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function wizard_step50(&$content, &$sel_options, &$readonlys, &$preserv)
|
function wizard_step50(&$content, &$sel_options, &$readonlys, &$preserv)
|
||||||
{
|
{
|
||||||
$result = parent::wizard_step50($content, $sel_options, $readonlys, $preserv);
|
$result = parent::wizard_step50($content, $sel_options, $readonlys, $preserv);
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user