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
|
2014-11-19 13:20:59 +01:00
|
|
|
* @copyright (c) 2007-14 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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Infolog - document merge object
|
|
|
|
*/
|
|
|
|
class infolog_merge extends bo_merge
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
);
|
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
|
|
|
|
|
|
|
// switch of handling of html formated content, if html is not used
|
|
|
|
$this->parse_html_styles = egw_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
|
|
|
|
*/
|
2011-01-27 18:39:32 +01:00
|
|
|
protected function get_replacements($id,&$content=null)
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
2012-04-02 23:25:42 +02:00
|
|
|
if (!($replacements = $this->infolog_replacements($id, '', $content)))
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-31 18:26:22 +01:00
|
|
|
if (!(strpos($content,'$$info_contact/') === false))
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
2011-01-31 18:26:22 +01:00
|
|
|
// Check to see if it's actually a contact, then load
|
|
|
|
if(is_array($replacements['$$info_link$$']) && $replacements['$$info_link$$']['app'] == 'addressbook')
|
|
|
|
{
|
|
|
|
$replacements += $this->contact_replacements($replacements['$$info_link$$']['id'],'info_contact');
|
|
|
|
}
|
2011-02-18 18:03:20 +01:00
|
|
|
if(is_array($replacements['$$info_link$$'])) unset($replacements['$$info_link$$']);
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|
|
|
|
return $replacements;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get infolog replacements
|
|
|
|
*
|
|
|
|
* @param int $id id of entry
|
2011-01-29 12:55:42 +01:00
|
|
|
* @param string $prefix='' prefix like eg. 'erole'
|
2011-01-26 21:16:18 +01:00
|
|
|
* @return array|boolean
|
|
|
|
*/
|
2012-04-25 19:47:49 +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();
|
|
|
|
|
|
|
|
// Convert to human friendly values
|
2011-04-07 17:28:45 +02:00
|
|
|
$types = infolog_egw_record::$types;
|
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
|
|
|
|
|
|
|
if($content && strpos($content, '$$#') !== 0)
|
|
|
|
{
|
|
|
|
$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);
|
|
|
|
if($record->info_contact)
|
|
|
|
{
|
|
|
|
$array['info_contact'] = $array['info_link']['title'];
|
|
|
|
}
|
2011-04-18 20:54:11 +02:00
|
|
|
|
|
|
|
// Make sure line breaks get preserved (Needed for emails in particular)
|
|
|
|
switch($this->mimetype)
|
|
|
|
{
|
|
|
|
case 'application/vnd.oasis.opendocument.text': // open office
|
|
|
|
case 'application/vnd.oasis.opendocument.spreadsheet':
|
|
|
|
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
|
|
|
|
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
|
|
|
$record->info_des = nl2br($record->info_des);
|
|
|
|
}
|
|
|
|
|
2011-01-26 21:16:18 +01:00
|
|
|
// Set any missing custom fields, or the marker will stay
|
|
|
|
$array = $record->get_record_array();
|
2016-02-17 00:42:25 +01:00
|
|
|
foreach($this->bo->customfields as $name => $field)
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
2013-06-04 23:24:17 +02:00
|
|
|
if(!$array['#'.$name])
|
|
|
|
{
|
|
|
|
$array['#'.$name] = '';
|
|
|
|
}
|
2016-02-17 00:42:25 +01:00
|
|
|
// Format date cfs per user preferences
|
|
|
|
if($field['type'] == 'date' || $field['type'] == 'date-time')
|
|
|
|
{
|
|
|
|
$this->date_fields[] = '#'.$name;
|
|
|
|
$array['#'.$name] = egw_time::to($array['#'.$name], $field['type'] == 'date' ? true : '');
|
|
|
|
}
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|
|
|
|
|
2011-10-26 00:39:16 +02:00
|
|
|
// Links
|
2013-03-04 18:43:46 +01:00
|
|
|
$array += $this->get_all_links('infolog', $id, $prefix, $content);
|
2011-10-26 00:39:16 +02:00
|
|
|
|
2014-09-09 23:26:45 +02:00
|
|
|
// Timesheet time
|
|
|
|
if(strpos($content, 'info_sum_timesheets'))
|
|
|
|
{
|
|
|
|
$links = egw_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
|
|
|
|
$links = egw_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;
|
|
|
|
$array['project'] = egw_link::title('projectmanager', $app_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate table with replacements for the preferences
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function show_replacements()
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('infolog').' - '.lang('Replacements for inserting entries into documents');
|
|
|
|
$GLOBALS['egw_info']['flags']['nonavbar'] = false;
|
|
|
|
common::egw_header();
|
|
|
|
|
|
|
|
echo "<table width='90%' align='center'>\n";
|
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Infolog fields:')."</h3></td></tr>";
|
|
|
|
|
|
|
|
$n = 0;
|
|
|
|
$tracking = new infolog_tracking($this->bo);
|
2014-09-09 23:28:57 +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'));
|
2011-07-05 23:44:21 +02:00
|
|
|
translation::add_app('projectmanager');
|
2011-01-31 18:26:22 +01:00
|
|
|
foreach($fields as $name => $label)
|
2011-01-26 21:16:18 +01:00
|
|
|
{
|
|
|
|
if (in_array($name,array('custom'))) continue; // dont show them
|
|
|
|
|
|
|
|
if (in_array($name,array('info_subject', 'info_des')) && $n&1) // main values, which should be in the first column
|
|
|
|
{
|
|
|
|
echo "</tr>\n";
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
if (!($n&1)) echo '<tr>';
|
2011-07-05 23:44:21 +02:00
|
|
|
echo '<td>{{'.$name.'}}</td><td>'.lang($label).'</td>';
|
2011-01-26 21:16:18 +01:00
|
|
|
if ($n&1) echo "</tr>\n";
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
|
2013-06-04 23:24:17 +02:00
|
|
|
$contact_custom = false;
|
2011-01-26 21:16:18 +01:00
|
|
|
foreach($this->bo->customfields as $name => $field)
|
|
|
|
{
|
2013-06-04 23:24:17 +02:00
|
|
|
echo '<tr><td>{{#'.$name.'}}</td><td colspan="3">'.$field['label'].($field['type'] == 'select-account' ? '*':'')."</td></tr>\n";
|
|
|
|
if($field['type'] == 'select-account') $contact_custom = true;
|
|
|
|
}
|
|
|
|
if($contact_custom)
|
|
|
|
{
|
|
|
|
echo '<tr><td /><td colspan="3">* '.lang('Addressbook placeholders available'). '</td></tr>';
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|
2014-11-19 13:20:59 +01:00
|
|
|
|
2014-06-18 17:50:23 +02:00
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Parent').":</h3></td></tr>";
|
|
|
|
echo '<tr><td>{{info_id_parent/info_subject}}</td><td colspan="3">'.lang('All other %1 fields are valid',lang('infolog'))."</td></tr>\n";
|
2011-01-26 21:16:18 +01:00
|
|
|
|
2011-01-31 18:26:22 +01:00
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Contact fields').':</h3></td></tr>';
|
2014-11-19 13:20:59 +01:00
|
|
|
$i = 0;
|
|
|
|
foreach($this->contacts->contact_fields as $name => $label)
|
|
|
|
{
|
|
|
|
if (in_array($name,array('tid','label','geo'))) continue; // dont show them, as they are not used in the UI atm.
|
|
|
|
|
|
|
|
if (in_array($name,array('email','org_name','tel_work','url')) && $n&1) // main values, which should be in the first column
|
|
|
|
{
|
|
|
|
echo "</tr>\n";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
if (!($i&1)) echo '<tr>';
|
|
|
|
echo '<td>{{info_contact/'.$name.'}}</td><td>'.$label.'</td>';
|
|
|
|
if ($i&1) echo "</tr>\n";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
|
|
|
|
foreach($this->contacts->customfields as $name => $field)
|
|
|
|
{
|
|
|
|
echo '<tr><td>{{info_contact/#'.$name.'}}</td><td colspan="3">'.$field['label']."</td></tr>\n";
|
|
|
|
}
|
2011-01-31 18:26:22 +01:00
|
|
|
|
2011-01-26 21:16:18 +01:00
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";
|
|
|
|
foreach(array(
|
2013-03-19 21:56:58 +01:00
|
|
|
'link' => lang('HTML link to the current record'),
|
2011-10-26 17:06:37 +02:00
|
|
|
'links' => lang('Titles of any entries linked to the current record, excluding attached files'),
|
2011-10-26 00:52:34 +02:00
|
|
|
'attachments' => lang('List of files linked to the current record'),
|
2011-10-26 17:06:37 +02:00
|
|
|
'links_attachments' => lang('Links and attached files'),
|
2013-03-04 18:43:46 +01:00
|
|
|
'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'),
|
|
|
|
'links/href' => lang('Links wrapped in an HREF tag with download link'),
|
|
|
|
'links/link' => lang('Download url for links'),
|
2011-01-26 21:16:18 +01:00
|
|
|
'date' => lang('Date'),
|
|
|
|
'user/n_fn' => lang('Name of current user, all other contact fields are valid too'),
|
|
|
|
'user/account_lid' => lang('Username'),
|
|
|
|
'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'),
|
|
|
|
'label' => lang('Use this tag for addresslabels. Put the content, you want to repeat, between two tags.'),
|
|
|
|
'labelplacement' => lang('Tag to mark positions for address labels'),
|
2011-02-18 18:03:20 +01:00
|
|
|
'IF fieldname' => lang('Example {{IF n_prefix~Mr~Hello Mr.~Hello Ms.}} - search the field "n_prefix", for "Mr", if found, write Hello Mr., else write Hello Ms.'),
|
|
|
|
'NELF' => lang('Example {{NELF role}} - if field role is not empty, you will get a new line with the value of field role'),
|
|
|
|
'NENVLF' => lang('Example {{NELFNV role}} - if field role is not empty, set a LF without any value of the field'),
|
|
|
|
'LETTERPREFIX' => lang('Example {{LETTERPREFIX}} - Gives a letter prefix without double spaces, if the title is emty for example'),
|
|
|
|
'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'),
|
2011-01-26 21:16:18 +01:00
|
|
|
) as $name => $label)
|
|
|
|
{
|
2011-02-18 18:03:20 +01:00
|
|
|
echo '<tr><td>{{'.$name.'}}</td><td colspan="3">'.$label."</td></tr>\n";
|
2011-01-26 21:16:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "</table>\n";
|
|
|
|
|
|
|
|
common::egw_footer();
|
|
|
|
}
|
|
|
|
}
|