2011-01-26 21:16:18 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Infolog - document merge
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @package infolog
|
2016-04-30 19:05:23 +02:00
|
|
|
* @copyright (c) 2007-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2011-01-26 21:16:18 +01:00
|
|
|
* @copyright 2011 Nathan Gray
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-30 19:05:23 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Link;
|
|
|
|
|
2011-01-26 21:16:18 +01:00
|
|
|
/**
|
|
|
|
* Infolog - document merge object
|
|
|
|
*/
|
2016-04-30 19:05:23 +02:00
|
|
|
class infolog_merge extends Api\Storage\Merge
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Functions that can be called via menuaction
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2011-01-29 12:55:42 +01:00
|
|
|
var $public_functions = array(
|
2012-09-29 12:16:39 +02:00
|
|
|
'download_by_request' => true,
|
2011-01-29 12:55:42 +01:00
|
|
|
'show_replacements' => true,
|
2021-06-23 19:31:47 +02:00
|
|
|
'merge_entries' => true,
|
2011-01-29 12:55:42 +01:00
|
|
|
);
|
2011-01-26 21:16:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Business object to pull records from
|
|
|
|
*/
|
|
|
|
protected $bo = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->bo = new infolog_bo();
|
2012-02-13 19:59:00 +01:00
|
|
|
|
|
|
|
$this->date_fields += array(
|
|
|
|
'info_startdate',
|
|
|
|
'info_enddate',
|
|
|
|
'info_datecompleted',
|
|
|
|
'info_datemodified',
|
|
|
|
'info_created',
|
|
|
|
);
|
2014-11-19 13:20:59 +01:00
|
|
|
|
2016-04-30 19:05:23 +02:00
|
|
|
// switch of handling of Api\Html formated content, if Api\Html is not used
|
|
|
|
$this->parse_html_styles = Api\Storage\Customfields::use_html('infolog');
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get infolog replacements
|
|
|
|
*
|
|
|
|
* @param int $id id of entry
|
|
|
|
* @param string &$content=null content to create some replacements only if they are use
|
|
|
|
* @return array|boolean
|
|
|
|
*/
|
2021-10-06 19:58:39 +02:00
|
|
|
protected function get_replacements($id, &$content = null)
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
2021-10-06 19:58:39 +02:00
|
|
|
if(!($replacements = $this->infolog_replacements($id, '', $content)))
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $replacements;
|
|
|
|
}
|
|
|
|
|
2021-10-06 19:58:39 +02:00
|
|
|
/**
|
|
|
|
* Override contact filename placeholder to use info_contact
|
|
|
|
*
|
|
|
|
* @param $document
|
|
|
|
* @param $ids
|
|
|
|
* @return array|void
|
|
|
|
*/
|
|
|
|
public function get_filename_placeholders($document, $ids)
|
|
|
|
{
|
|
|
|
$placeholders = parent::get_filename_placeholders($document, $ids);
|
|
|
|
if(count($ids) == 1 && ($info = $this->bo->read($ids[0])))
|
|
|
|
{
|
|
|
|
$placeholders['$$contact_title$$'] = $info['info_contact']['title'] ??
|
|
|
|
(is_array($info['info_contact']) && Link::title($info['info_contact']['app'], $info['info_contact']['id'])) ??
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
return $placeholders;
|
|
|
|
}
|
|
|
|
|
2011-01-26 21:16:18 +01:00
|
|
|
/**
|
|
|
|
* Get infolog replacements
|
|
|
|
*
|
|
|
|
* @param int $id id of entry
|
2021-10-06 19:58:39 +02:00
|
|
|
* @param string $prefix ='' prefix like eg. 'erole'
|
2011-01-26 21:16:18 +01:00
|
|
|
* @return array|boolean
|
|
|
|
*/
|
2021-10-06 19:58:39 +02:00
|
|
|
public function infolog_replacements($id, $prefix = '', &$content = '')
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
|
|
|
$record = new infolog_egw_record($id);
|
|
|
|
$info = array();
|
2021-05-07 18:15:05 +02:00
|
|
|
// Keep original value for further processing
|
|
|
|
$info_owner = $record->info_owner;
|
2011-01-26 21:16:18 +01:00
|
|
|
|
|
|
|
// Convert to human friendly values
|
2011-04-07 17:28:45 +02:00
|
|
|
$types = infolog_egw_record::$types;
|
2021-04-21 21:29:09 +02:00
|
|
|
// We have specific requirements for floats, we'll do them in Merge
|
|
|
|
unset($types['float']);
|
|
|
|
|
2011-01-26 21:16:18 +01:00
|
|
|
$_selects = $this->bo->enums + array('status' => $this->bo->status[$record->info_type]);
|
|
|
|
foreach($_selects as $name => $value)
|
|
|
|
{
|
|
|
|
$selects['info_'.$name] = $value;
|
2012-04-25 19:47:49 +02:00
|
|
|
if(!in_array('info_'.$name, $types['select'])) $types['select'][] = 'info_'.$name;
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|
2012-04-02 23:25:42 +02:00
|
|
|
|
2016-05-18 23:41:20 +02:00
|
|
|
if($content && strpos($content, '$$#') !== FALSE)
|
2012-04-02 23:25:42 +02:00
|
|
|
{
|
|
|
|
$this->cf_link_to_expand($record->get_record_array(), $content, $info);
|
|
|
|
}
|
|
|
|
|
2011-01-26 21:16:18 +01:00
|
|
|
importexport_export_csv::convert($record, $types, 'infolog', $selects);
|
2017-11-15 23:41:12 +01:00
|
|
|
|
2017-02-01 17:35:24 +01:00
|
|
|
$array = $record->get_record_array();
|
2021-04-21 21:29:09 +02:00
|
|
|
foreach(array('info_price') as $key)
|
|
|
|
{
|
|
|
|
$array[$key] = self::number_format($array[$key],2,$this->mimetype);
|
|
|
|
}
|
2011-01-26 21:16:18 +01:00
|
|
|
if($record->info_contact)
|
|
|
|
{
|
|
|
|
$array['info_contact'] = $array['info_link']['title'];
|
|
|
|
}
|
2011-04-18 20:54:11 +02:00
|
|
|
|
2011-01-26 21:16:18 +01:00
|
|
|
// Set any missing custom fields, or the marker will stay
|
2016-02-17 00:42:25 +01:00
|
|
|
foreach($this->bo->customfields as $name => $field)
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
2021-10-07 10:14:08 +02:00
|
|
|
if (empty($array['#'.$name]))
|
2013-06-04 23:24:17 +02:00
|
|
|
{
|
|
|
|
$array['#'.$name] = '';
|
|
|
|
}
|
2016-04-30 19:05:23 +02:00
|
|
|
// Format date cfs per user Api\Preferences
|
2018-02-01 18:44:17 +01:00
|
|
|
if($array['#'.$name] && ($field['type'] == 'date' || $field['type'] == 'date-time'))
|
2016-02-17 00:42:25 +01:00
|
|
|
{
|
|
|
|
$this->date_fields[] = '#'.$name;
|
2016-04-30 19:05:23 +02:00
|
|
|
$array['#'.$name] = Api\DateTime::to($array['#'.$name], $field['type'] == 'date' ? true : '');
|
2016-02-17 00:42:25 +01:00
|
|
|
}
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|
|
|
|
|
2014-09-09 23:26:45 +02:00
|
|
|
// Timesheet time
|
|
|
|
if(strpos($content, 'info_sum_timesheets'))
|
|
|
|
{
|
2016-04-30 19:05:23 +02:00
|
|
|
$links = Link::get_links('infolog',$id,'timesheet');
|
2014-10-16 01:02:42 +02:00
|
|
|
$sum = ExecMethod('timesheet.timesheet_bo.sum',$links);
|
2014-09-09 23:26:45 +02:00
|
|
|
$info['$$info_sum_timesheets$$'] = $sum['duration'];
|
|
|
|
}
|
|
|
|
|
2012-04-25 19:47:49 +02:00
|
|
|
// Check for linked project ID
|
2016-04-30 19:05:23 +02:00
|
|
|
$links = Link::get_links('infolog', $id, 'projectmanager');
|
2014-11-19 13:20:59 +01:00
|
|
|
foreach($links as $app_id)
|
|
|
|
{
|
2012-04-25 19:47:49 +02:00
|
|
|
$array['pm_id'] = $app_id;
|
2016-04-30 19:05:23 +02:00
|
|
|
$array['project'] = Link::title('projectmanager', $app_id);
|
2012-04-25 19:47:49 +02:00
|
|
|
break;
|
|
|
|
}
|
2017-06-19 22:32:41 +02:00
|
|
|
if (strpos($content, '$$project/') !== false && $array['pm_id'] && class_exists('projectmanager_merge'))
|
|
|
|
{
|
|
|
|
$pm_merge = new projectmanager_merge($array['pm_id']);
|
|
|
|
$info += $pm_merge->projectmanager_replacements($array['pm_id'],'project',$content);
|
|
|
|
}
|
2017-11-15 23:41:12 +01:00
|
|
|
|
2011-01-26 21:16:18 +01:00
|
|
|
// Add markers
|
2011-01-31 18:26:22 +01:00
|
|
|
foreach($array as $key => &$value)
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
2011-01-31 18:26:22 +01:00
|
|
|
if(!$value) $value = '';
|
2011-01-29 12:55:42 +01:00
|
|
|
$info['$$'.($prefix ? $prefix.'/':'').$key.'$$'] = $value;
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|
2014-06-18 17:50:23 +02:00
|
|
|
|
2018-10-04 19:17:06 +02:00
|
|
|
// Links
|
|
|
|
$info += $this->get_all_links('infolog', $id, $prefix, $content);
|
|
|
|
|
2017-11-15 23:41:12 +01:00
|
|
|
// Add contact fields
|
2018-01-24 09:20:16 +01:00
|
|
|
if($array['info_link'] && $array['info_link']['app'] && $array['info_link']['id'])
|
2017-11-15 23:41:12 +01:00
|
|
|
{
|
|
|
|
$info+=$this->get_app_replacements($array['info_link']['app'], $array['info_link']['id'], $content, 'info_contact');
|
|
|
|
}
|
2021-05-07 18:15:05 +02:00
|
|
|
// Add owner fields
|
2021-05-20 09:11:21 +02:00
|
|
|
$info += $this->contact_replacements(Api\Accounts::id2name($info_owner,'person_id'),'info_owner');
|
2017-11-15 23:41:12 +01:00
|
|
|
|
2014-06-18 17:50:23 +02:00
|
|
|
// Add parent
|
|
|
|
if($record->info_id_parent)
|
|
|
|
{
|
|
|
|
$info += $this->infolog_replacements($record->info_id_parent, 'info_id_parent', $content);
|
|
|
|
}
|
2011-01-26 21:16:18 +01:00
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
2021-09-27 22:46:41 +02:00
|
|
|
public function get_placeholder_list($prefix = '')
|
|
|
|
{
|
|
|
|
$tracking = new infolog_tracking($this->bo);
|
2021-10-12 22:18:18 +02:00
|
|
|
$placeholders = array(
|
|
|
|
'infolog' => [],
|
|
|
|
lang('parent') => [],
|
|
|
|
lang($tracking->field2label['info_from']) => []
|
|
|
|
) + parent::get_placeholder_list($prefix);
|
|
|
|
|
2021-09-27 22:46:41 +02:00
|
|
|
$fields = array('info_id' => lang('Infolog ID'), 'pm_id' => lang('Project ID'),
|
|
|
|
'project' => lang('Project name')) + $tracking->field2label + array('info_sum_timesheets' => lang('Used time'));
|
|
|
|
Api\Translation::add_app('projectmanager');
|
|
|
|
|
2021-10-12 22:18:18 +02:00
|
|
|
$group = 'infolog';
|
2021-09-27 22:46:41 +02:00
|
|
|
foreach($fields as $name => $label)
|
|
|
|
{
|
|
|
|
if(in_array($name, array('custom')))
|
|
|
|
{
|
|
|
|
// dont show them
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$marker = $this->prefix($prefix, $name, '{');
|
|
|
|
if(!array_filter($placeholders, function ($a) use ($marker)
|
|
|
|
{
|
|
|
|
return array_key_exists($marker, $a);
|
|
|
|
}))
|
|
|
|
{
|
2021-10-04 22:45:57 +02:00
|
|
|
$placeholders[$group][] = [
|
|
|
|
'value' => $marker,
|
|
|
|
'label' => $label
|
|
|
|
];
|
2021-09-27 22:46:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-12 22:18:18 +02:00
|
|
|
// Don't add any linked placeholders if we're not at the top level
|
|
|
|
// This avoids potential recursion
|
|
|
|
if(!$prefix)
|
|
|
|
{
|
|
|
|
// Add contact placeholders
|
|
|
|
$contact_merge = new Api\Contacts\Merge();
|
|
|
|
$contact = $contact_merge->get_placeholder_list($this->prefix($prefix, 'info_contact'));
|
|
|
|
$this->add_linked_placeholders($placeholders, lang($tracking->field2label['info_from']), $contact);
|
2021-10-04 22:45:57 +02:00
|
|
|
|
2021-10-12 22:18:18 +02:00
|
|
|
// Add parent placeholders
|
|
|
|
$this->add_linked_placeholders(
|
|
|
|
$placeholders,
|
|
|
|
lang('parent'),
|
|
|
|
$this->get_placeholder_list(($prefix ? $prefix . '/' : '') . 'info_id_parent')
|
|
|
|
);
|
|
|
|
}
|
2021-09-27 22:46:41 +02:00
|
|
|
return $placeholders;
|
|
|
|
}
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|