2007-06-17 15:56:35 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Addressbook - document merge
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package addressbook
|
2009-07-04 12:50:19 +02:00
|
|
|
* @copyright (c) 2007-9 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2007-06-17 15:56:35 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2008-05-10 14:02:49 +02:00
|
|
|
* @version $Id$
|
2007-06-17 15:56:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Addressbook - document merge object
|
|
|
|
*/
|
2009-08-26 19:12:43 +02:00
|
|
|
class addressbook_merge extends bo_merge
|
2007-06-17 15:56:35 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Functions that can be called via menuaction
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-01-04 01:21:37 +01:00
|
|
|
var $public_functions = array(
|
|
|
|
'download_by_request' => true,
|
|
|
|
'show_replacements' => true,
|
|
|
|
);
|
2007-06-17 15:56:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @return addressbook_merge
|
|
|
|
*/
|
2008-05-10 14:02:49 +02:00
|
|
|
function __construct()
|
2007-06-17 15:56:35 +02:00
|
|
|
{
|
2009-08-26 19:12:43 +02:00
|
|
|
parent::__construct();
|
2011-06-16 13:36:15 +02:00
|
|
|
|
|
|
|
// overwrite global export-limit, if an addressbook one is set
|
2011-09-16 15:03:46 +02:00
|
|
|
$this->export_limit = bo_merge::getExportLimit('addressbook');
|
2007-06-17 15:56:35 +02:00
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2009-07-04 12:50:19 +02:00
|
|
|
/**
|
2009-08-26 19:12:43 +02:00
|
|
|
* Get addressbook replacements
|
2009-07-04 12:50:19 +02:00
|
|
|
*
|
2009-08-26 19:12:43 +02:00
|
|
|
* @param int $id id of entry
|
|
|
|
* @param string &$content=null content to create some replacements only if they are use
|
|
|
|
* @return array|boolean
|
2009-07-04 12:50:19 +02:00
|
|
|
*/
|
2011-01-27 18:08:40 +01:00
|
|
|
protected function get_replacements($id,&$content=null)
|
2009-07-04 12:50:19 +02:00
|
|
|
{
|
2009-08-26 19:12:43 +02:00
|
|
|
if (!($replacements = $this->contact_replacements($id)))
|
2009-08-03 13:44:45 +02:00
|
|
|
{
|
2009-08-26 19:12:43 +02:00
|
|
|
return false;
|
2007-06-17 15:56:35 +02:00
|
|
|
}
|
2012-04-11 22:03:11 +02:00
|
|
|
if($content && strpos($content, '$$#') !== 0)
|
|
|
|
{
|
|
|
|
$this->cf_link_to_expand($this->contacts->read($id), $content, $replacements,'addressbook');
|
|
|
|
}
|
|
|
|
|
2011-10-26 18:45:38 +02:00
|
|
|
// Links
|
2013-02-07 10:36:07 +01:00
|
|
|
$replacements += $this->get_all_links('addressbook', $id, $prefix, $content);
|
2010-05-26 14:41:19 +02:00
|
|
|
if (!(strpos($content,'$$calendar/') === false))
|
2008-02-07 03:45:48 +01:00
|
|
|
{
|
2010-05-26 14:41:19 +02:00
|
|
|
$replacements += $this->calendar_replacements($id,!(strpos($content,'$$calendar/-1/') === false));
|
2008-02-07 03:45:48 +01:00
|
|
|
}
|
2007-06-17 15:56:35 +02:00
|
|
|
return $replacements;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return replacements for the calendar (next events) of a contact
|
2008-05-10 14:02:49 +02:00
|
|
|
*
|
2007-06-17 15:56:35 +02:00
|
|
|
* @param int $contact contact-id
|
2008-02-07 03:45:48 +01:00
|
|
|
* @param boolean $last_event_too=false also include information about the last event
|
2007-06-17 15:56:35 +02:00
|
|
|
* @return array
|
|
|
|
*/
|
2009-08-26 19:12:43 +02:00
|
|
|
protected function calendar_replacements($id,$last_event_too=false)
|
2007-06-17 15:56:35 +02:00
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$calendar = new calendar_boupdate();
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2008-02-07 03:45:48 +01:00
|
|
|
// next events
|
|
|
|
$events = $calendar->search(array(
|
2007-06-19 19:06:32 +02:00
|
|
|
'start' => $calendar->now_su,
|
|
|
|
'users' => 'c'.$id,
|
|
|
|
'offset' => 0,
|
|
|
|
'num_rows' => 20,
|
|
|
|
'order' => 'cal_start',
|
2012-01-19 19:17:28 +01:00
|
|
|
'enum_recurring' => true
|
2008-02-07 03:45:48 +01:00
|
|
|
));
|
2012-01-19 19:17:28 +01:00
|
|
|
if (!$events)
|
2008-02-15 03:17:47 +01:00
|
|
|
{
|
|
|
|
$events = array();
|
|
|
|
}
|
2011-04-06 23:39:17 +02:00
|
|
|
if ($last_event_too==true)
|
2008-02-15 03:17:47 +01:00
|
|
|
{
|
|
|
|
$last = $calendar->search(array(
|
2008-02-07 03:45:48 +01:00
|
|
|
'end' => $calendar->now_su,
|
|
|
|
'users' => 'c'.$id,
|
|
|
|
'offset' => 0,
|
|
|
|
'num_rows' => 1,
|
|
|
|
'order' => 'cal_start DESC',
|
2012-01-19 19:17:28 +01:00
|
|
|
'enum_recurring' => true
|
2008-02-07 03:45:48 +01:00
|
|
|
));
|
2011-04-06 23:39:17 +02:00
|
|
|
$events['-1'] = $last ? array_shift($last) : array(); // returned events are indexed by cal_id!
|
2008-02-07 03:45:48 +01:00
|
|
|
}
|
|
|
|
$replacements = array();
|
2012-01-19 19:17:28 +01:00
|
|
|
$n = 1; // Returned events are indexed by cal_id, need to index sequentially
|
|
|
|
foreach($events as $key => $event)
|
2007-06-19 19:06:32 +02:00
|
|
|
{
|
2012-01-19 19:17:28 +01:00
|
|
|
// Use -1 for previous key
|
|
|
|
if($key < 0) $n = $key;
|
|
|
|
|
2007-06-19 19:06:32 +02:00
|
|
|
foreach($calendar->event2array($event) as $name => $data)
|
|
|
|
{
|
|
|
|
if (substr($name,-4) == 'date') $name = substr($name,0,-4);
|
|
|
|
$replacements['$$calendar/'.$n.'/'.$name.'$$'] = is_array($data['data']) ? implode(', ',$data['data']) : $data['data'];
|
|
|
|
}
|
|
|
|
foreach(array('start','end') as $what)
|
|
|
|
{
|
|
|
|
foreach(array(
|
|
|
|
'date' => $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],
|
|
|
|
'day' => 'l',
|
|
|
|
'time' => $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i',
|
|
|
|
) as $name => $format)
|
|
|
|
{
|
2011-04-06 23:39:17 +02:00
|
|
|
$value = $event[$what] ? date($format,$event[$what]) : '';
|
2007-06-19 19:06:32 +02:00
|
|
|
if ($format == 'l') $value = lang($value);
|
|
|
|
$replacements['$$calendar/'.$n.'/'.$what.$name.'$$'] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$duration = ($event['end'] - $event['start'])/60;
|
|
|
|
$replacements['$$calendar/'.$n.'/duration$$'] = floor($duration/60).lang('h').($duration%60 ? $duration%60 : '');
|
|
|
|
|
|
|
|
++$n;
|
|
|
|
}
|
2011-06-16 13:36:15 +02:00
|
|
|
|
2011-04-06 23:39:17 +02:00
|
|
|
// Need to set some keys if there is no previous event
|
|
|
|
if($last_event_too && count($events['-1']) == 0) {
|
|
|
|
$replacements['$$calendar/-1/start$$'] = '';
|
|
|
|
$replacements['$$calendar/-1/end$$'] = '';
|
|
|
|
$replacements['$$calendar/-1/owner$$'] = '';
|
|
|
|
$replacements['$$calendar/-1/updated$$'] = '';
|
|
|
|
}
|
2007-06-19 19:06:32 +02:00
|
|
|
return $replacements;
|
2007-06-17 15:56:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate table with replacements for the preferences
|
|
|
|
*
|
|
|
|
*/
|
2009-08-26 19:12:43 +02:00
|
|
|
public function show_replacements()
|
2007-06-17 15:56:35 +02:00
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('Addressbook').' - '.lang('Replacements for inserting contacts into documents');
|
|
|
|
$GLOBALS['egw_info']['flags']['nonavbar'] = false;
|
2009-08-26 19:12:43 +02:00
|
|
|
common::egw_header();
|
2007-06-17 15:56:35 +02:00
|
|
|
|
|
|
|
echo "<table width='90%' align='center'>\n";
|
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Contact fields:')."</h3></td></tr>";
|
|
|
|
|
|
|
|
$n = 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";
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
if (!($n&1)) echo '<tr>';
|
2011-02-18 17:59:52 +01:00
|
|
|
echo '<td>{{'.$name.'}}</td><td>'.$label.'</td>';
|
2011-02-16 18:47:31 +01:00
|
|
|
if($name == 'cat_id')
|
|
|
|
{
|
|
|
|
if ($n&1) echo "</tr>\n";
|
2011-02-18 17:59:52 +01:00
|
|
|
echo '<td>{{categories}}</td><td>'.lang('Category path').'</td>';
|
2011-02-16 18:47:31 +01:00
|
|
|
$n++;
|
|
|
|
}
|
2007-06-17 15:56:35 +02:00
|
|
|
if ($n&1) echo "</tr>\n";
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
|
2009-07-04 12:50:19 +02:00
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
|
|
|
|
foreach($this->contacts->customfields as $name => $field)
|
|
|
|
{
|
2011-02-18 17:59:52 +01:00
|
|
|
echo '<tr><td>{{#'.$name.'}}</td><td colspan="3">'.$field['label']."</td></tr>\n";
|
2009-07-04 12:50:19 +02:00
|
|
|
}
|
|
|
|
|
2007-06-17 15:56:35 +02:00
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";
|
|
|
|
foreach(array(
|
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}}'),
|
2007-06-17 15:56:35 +02:00
|
|
|
'date' => lang('Date'),
|
2007-06-19 19:06:32 +02:00
|
|
|
'user/n_fn' => lang('Name of current user, all other contact fields are valid too'),
|
|
|
|
'user/account_lid' => lang('Username'),
|
2008-04-15 10:26:50 +02:00
|
|
|
'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'),
|
2009-07-04 12:50:19 +02:00
|
|
|
'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 17:59:52 +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'),
|
2011-07-04 20:12:12 +02:00
|
|
|
'LETTERPREFIX' => lang('Example {{LETTERPREFIX}} - Gives a letter prefix without double spaces, if the title is empty for example'),
|
2011-02-18 17:59:52 +01:00
|
|
|
'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'),
|
2008-04-15 10:26:50 +02:00
|
|
|
) as $name => $label)
|
2007-06-17 15:56:35 +02:00
|
|
|
{
|
2011-02-18 17:59:52 +01:00
|
|
|
echo '<tr><td>{{'.$name.'}}</td><td colspan="3">'.$label."</td></tr>\n";
|
2007-06-17 15:56:35 +02:00
|
|
|
}
|
2009-07-04 12:50:19 +02:00
|
|
|
|
2007-06-19 19:06:32 +02:00
|
|
|
$GLOBALS['egw']->translation->add_app('calendar');
|
2008-02-15 03:17:47 +01:00
|
|
|
echo '<tr><td colspan="4"><h3>'.lang('Calendar fields:')." # = 1, 2, ..., 20, -1</h3></td></tr>";
|
2007-06-17 15:56:35 +02:00
|
|
|
foreach(array(
|
2007-06-19 19:06:32 +02:00
|
|
|
'title' => lang('Title'),
|
|
|
|
'description' => lang('Description'),
|
|
|
|
'participants' => lang('Participants'),
|
2007-07-09 11:51:41 +02:00
|
|
|
'location' => lang('Location'),
|
2007-06-19 19:06:32 +02:00
|
|
|
'start' => lang('Start').': '.lang('Date').'+'.lang('Time'),
|
|
|
|
'startday' => lang('Start').': '.lang('Weekday'),
|
|
|
|
'startdate'=> lang('Start').': '.lang('Date'),
|
|
|
|
'starttime'=> lang('Start').': '.lang('Time'),
|
|
|
|
'end' => lang('End').': '.lang('Date').'+'.lang('Time'),
|
|
|
|
'endday' => lang('End').': '.lang('Weekday'),
|
|
|
|
'enddate' => lang('End').': '.lang('Date'),
|
|
|
|
'endtime' => lang('End').': '.lang('Time'),
|
|
|
|
'duration' => lang('Duration'),
|
2007-07-09 11:51:41 +02:00
|
|
|
'category' => lang('Category'),
|
2007-06-19 19:06:32 +02:00
|
|
|
'priority' => lang('Priority'),
|
|
|
|
'updated' => lang('Updated'),
|
|
|
|
'recur_type' => lang('Repetition'),
|
|
|
|
'access' => lang('Access').': '.lang('public').', '.lang('private'),
|
2007-07-09 11:51:41 +02:00
|
|
|
'owner' => lang('Owner'),
|
2007-06-17 15:56:35 +02:00
|
|
|
) as $name => $label)
|
|
|
|
{
|
2007-06-19 19:06:32 +02:00
|
|
|
if (in_array($name,array('start','end')) && $n&1) // main values, which should be in the first column
|
|
|
|
{
|
|
|
|
echo "</tr>\n";
|
|
|
|
$n++;
|
|
|
|
}
|
2007-06-17 15:56:35 +02:00
|
|
|
if (!($n&1)) echo '<tr>';
|
2011-02-18 17:59:52 +01:00
|
|
|
echo '<td>{{calendar/#/'.$name.'}}</td><td>'.$label.'</td>';
|
2007-06-17 15:56:35 +02:00
|
|
|
if ($n&1) echo "</tr>\n";
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
echo "</table>\n";
|
|
|
|
|
2009-08-26 19:12:43 +02:00
|
|
|
common::egw_footer();
|
2007-06-17 15:56:35 +02:00
|
|
|
}
|
2008-06-09 14:32:15 +02:00
|
|
|
}
|