2011-02-11 19:36:27 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Timesheet - document merge
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @package timesheet
|
2016-04-26 20:27:29 +02:00
|
|
|
* @copyright (c) 2007-16 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2011-02-11 19:36:27 +01:00
|
|
|
* @copyright 2011 Nathan Gray
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-04-26 20:27:29 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Link;
|
|
|
|
|
2011-02-11 19:36:27 +01:00
|
|
|
/**
|
|
|
|
* Timesheet - document merge object
|
|
|
|
*/
|
2016-04-26 20:27:29 +02:00
|
|
|
class timesheet_merge extends Api\Storage\Merge
|
2011-02-11 19:36:27 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Functions that can be called via menuaction
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $public_functions = array(
|
2013-01-04 01:21:37 +01:00
|
|
|
'download_by_request' => true,
|
|
|
|
'show_replacements' => true,
|
2011-02-11 19:36:27 +01:00
|
|
|
'timesheet_replacements' => true,
|
|
|
|
);
|
|
|
|
|
2011-03-14 23:07:23 +01:00
|
|
|
/**
|
|
|
|
* Fields that are numeric, for special numeric handling
|
|
|
|
*/
|
|
|
|
protected $numeric_fields = array(
|
|
|
|
'$$ts_duration$$',
|
|
|
|
'$$ts_quantity$$',
|
|
|
|
'$$ts_unitprice$$'
|
|
|
|
);
|
|
|
|
|
2011-02-11 19:36:27 +01:00
|
|
|
/**
|
|
|
|
* Business object to pull records from
|
|
|
|
*/
|
|
|
|
protected $bo = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2014-11-19 13:20:59 +01:00
|
|
|
|
2016-04-26 20:27:29 +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('timesheet');
|
2014-11-19 13:20:59 +01:00
|
|
|
|
2011-02-11 19:36:27 +01:00
|
|
|
$this->bo = new timesheet_bo();
|
2017-01-17 18:34:10 +01:00
|
|
|
$this->date_fields += timesheet_egw_record::$types['date-time'];
|
2011-02-11 19:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get replacements
|
|
|
|
*
|
|
|
|
* @param int $id id of entry
|
|
|
|
* @param string &$content=null content to create some replacements only if they are use
|
|
|
|
* @return array|boolean
|
|
|
|
*/
|
|
|
|
protected function get_replacements($id,&$content=null)
|
|
|
|
{
|
2012-04-11 22:03:11 +02:00
|
|
|
if (!($replacements = $this->timesheet_replacements($id, '', $content)))
|
2011-02-11 19:36:27 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!(strpos($content,'$$ts_project/') === false))
|
|
|
|
{
|
|
|
|
// Check to see if it's actually a project, then load
|
|
|
|
if($replacements['$$pm_id$$'])
|
|
|
|
{
|
|
|
|
if(!$this->pm)
|
|
|
|
{
|
|
|
|
$this->pm = new projectmanager_merge();
|
|
|
|
}
|
|
|
|
$this->pm->projectmanager_bo = new projectmanager_bo($replacements['$$pm_id$$']);
|
|
|
|
$replacements += $this->pm->projectmanager_replacements($replacements['$$pm_id$$'],'ts_project');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $replacements;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get timesheet replacements
|
|
|
|
*
|
|
|
|
* @param int $id id of entry
|
|
|
|
* @param string $prefix='' prefix like eg. 'erole'
|
|
|
|
* @return array|boolean
|
|
|
|
*/
|
2012-04-11 22:03:11 +02:00
|
|
|
public function timesheet_replacements($id,$prefix='', &$content = null)
|
2011-02-11 19:36:27 +01:00
|
|
|
{
|
|
|
|
$record = new timesheet_egw_record($id);
|
|
|
|
$info = array();
|
|
|
|
|
|
|
|
// Get project manager ID
|
2016-04-26 20:27:29 +02:00
|
|
|
$links = Link\Storage::get_links('timesheet',$id,'projectmanager');
|
2011-02-11 19:36:27 +01:00
|
|
|
if($links)
|
|
|
|
{
|
|
|
|
$record->pm_id = current($links);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert to human friendly values
|
2011-04-04 21:20:12 +02:00
|
|
|
$types = timesheet_egw_record::$types;
|
2011-02-11 19:36:27 +01:00
|
|
|
$_selects = array('status' => $this->bo->status_labels);
|
2011-03-31 18:49:06 +02:00
|
|
|
foreach($_selects['status'] as &$status)
|
|
|
|
{
|
|
|
|
$status = str_replace(' ', '', $status);
|
|
|
|
}
|
2011-02-11 19:36:27 +01:00
|
|
|
foreach($_selects as $name => $value)
|
|
|
|
{
|
|
|
|
$selects['ts_'.$name] = $value;
|
|
|
|
}
|
2012-04-11 22:03:11 +02:00
|
|
|
if($content && strpos($content, '#') !== 0)
|
2014-11-19 14:51:09 +01:00
|
|
|
{
|
|
|
|
$this->cf_link_to_expand($record->get_record_array(), $content, $info);
|
|
|
|
}
|
2012-04-11 22:03:11 +02:00
|
|
|
|
2011-02-11 19:36:27 +01:00
|
|
|
importexport_export_csv::convert($record, $types, 'timesheet', $selects);
|
|
|
|
|
|
|
|
$array = $record->get_record_array();
|
2011-05-12 21:30:01 +02:00
|
|
|
$array['ts_total'] = $array['ts_quantity'] * $array['ts_unitprice'];
|
|
|
|
foreach(array('ts_duration','ts_quantity','ts_unitprice','ts_total') as $key)
|
2011-02-28 21:35:50 +01:00
|
|
|
{
|
|
|
|
$array[$key] = self::number_format($array[$key],2,$this->mimetype);
|
|
|
|
}
|
2012-04-11 22:03:11 +02:00
|
|
|
|
2011-02-28 21:35:50 +01:00
|
|
|
// Set any missing custom fields, or the marker will stay
|
2014-11-19 13:20:59 +01:00
|
|
|
foreach(array_keys($this->bo->customfields) as $name)
|
2011-02-11 19:36:27 +01:00
|
|
|
{
|
|
|
|
if(!$array['#'.$name]) $array['#'.$name] = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add markers
|
|
|
|
foreach($array as $key => &$value)
|
|
|
|
{
|
|
|
|
if(!$value) $value = '';
|
|
|
|
$info['$$'.($prefix ? $prefix.'/':'').$key.'$$'] = $value;
|
|
|
|
}
|
2018-10-04 19:17:06 +02:00
|
|
|
|
|
|
|
// Links
|
|
|
|
$info += $this->get_all_links('timesheet', $id, $prefix, $content);
|
|
|
|
|
2011-02-11 19:36:27 +01:00
|
|
|
return $info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-26 20:27:29 +02:00
|
|
|
* Generate table with replacements for the Api\Preferences
|
2011-02-11 19:36:27 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function show_replacements()
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('timesheet').' - '.lang('Replacements for inserting entries into documents');
|
|
|
|
$GLOBALS['egw_info']['flags']['nonavbar'] = false;
|
2016-05-14 21:26:36 +02:00
|
|
|
echo $GLOBALS['egw']->framework->header();
|
2011-02-11 19:36:27 +01:00
|
|
|
|
|
|
|
echo "<table width='90%' align='center'>\n";
|
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Timesheet fields:')."</h3></td></tr>";
|
|
|
|
|
|
|
|
$n = 0;
|
2017-01-17 18:34:10 +01:00
|
|
|
$fields = array('ts_id' => lang('Timesheet ID')) + $this->bo->field2label + array(
|
|
|
|
'ts_total' => lang('total'),
|
|
|
|
'ts_created' => lang('Created'),
|
|
|
|
'ts_modified' => lang('Modified'),
|
|
|
|
);
|
2011-02-11 19:36:27 +01:00
|
|
|
foreach($fields as $name => $label)
|
|
|
|
{
|
|
|
|
if (in_array($name,array('pl_id','customfields'))) continue; // dont show them
|
|
|
|
|
|
|
|
if (in_array($name,array('ts_title', 'ts_description')) && $n&1) // main values, which should be in the first column
|
|
|
|
{
|
|
|
|
echo "</tr>\n";
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
if (!($n&1)) echo '<tr>';
|
2011-07-06 00:21:49 +02:00
|
|
|
echo '<td>{{'.$name.'}}</td><td>'.lang($label).'</td>';
|
2011-02-11 19:36:27 +01:00
|
|
|
if ($n&1) echo "</tr>\n";
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
|
|
|
|
foreach($this->bo->customfields as $name => $field)
|
|
|
|
{
|
2011-02-18 18:07:16 +01:00
|
|
|
echo '<tr><td>{{#'.$name.'}}</td><td colspan="3">'.$field['label']."</td></tr>\n";
|
2011-02-11 19:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Project fields').':</h3></td></tr>';
|
|
|
|
$pm_merge = new projectmanager_merge();
|
2014-11-19 13:20:59 +01:00
|
|
|
$i = 0;
|
2011-02-11 19:36:27 +01:00
|
|
|
foreach($pm_merge->projectmanager_fields as $name => $label)
|
2014-11-19 13:20:59 +01:00
|
|
|
{
|
|
|
|
if (!($i&1)) echo '<tr>';
|
|
|
|
echo '<td>{{ts_project/'.$name.'}}</td><td>'.$label.'</td>';
|
|
|
|
if ($i&1) echo "</tr>\n";
|
|
|
|
$i++;
|
|
|
|
}
|
2011-02-11 19:36:27 +01:00
|
|
|
|
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";
|
|
|
|
foreach(array(
|
2013-03-20 15:51:09 +01:00
|
|
|
'link' => lang('HTML link to the current record'),
|
2011-10-26 18:45:38 +02:00
|
|
|
'links' => lang('Titles of any entries linked to the current record, excluding attached files'),
|
|
|
|
'attachments' => lang('List of files linked to the current record'),
|
|
|
|
'links_attachments' => lang('Links and attached files'),
|
2012-01-06 19:35:34 +01:00
|
|
|
'links/[appname]' => lang('Links to specified application. Example: {{links/infolog}}'),
|
2011-02-11 19:36:27 +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:07:16 +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'),
|
2017-02-10 10:41:43 +01:00
|
|
|
'NENVLF' => lang('Example {{NENVLF role}} - if field role is not empty, set a LF without any value of the field'),
|
2011-07-06 00:21:49 +02:00
|
|
|
'LETTERPREFIX' => lang('Example {{LETTERPREFIX}} - Gives a letter prefix without double spaces, if the title is empty for example'),
|
2011-02-18 18:07:16 +01:00
|
|
|
'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'),
|
2011-02-11 19:36:27 +01:00
|
|
|
) as $name => $label)
|
|
|
|
{
|
2011-02-18 18:07:16 +01:00
|
|
|
echo '<tr><td>{{'.$name.'}}</td><td colspan="3">'.$label."</td></tr>\n";
|
2011-02-11 19:36:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "</table>\n";
|
|
|
|
|
2016-05-14 21:26:36 +02:00
|
|
|
echo $GLOBALS['egw']->framework->footer();
|
2011-02-11 19:36:27 +01:00
|
|
|
}
|
|
|
|
}
|