- Add merge print directory to sidebox so it's available from all views

- Add day_n, yesterday, today & tomorrow tables
This commit is contained in:
Nathan Gray 2011-02-15 20:35:46 +00:00
parent 04a081fd58
commit 8b1440560e
4 changed files with 194 additions and 28 deletions

View File

@ -591,8 +591,8 @@ class calendar_hooks
'size' => 60,
'label' => 'Default document to insert entries',
'name' => 'default_document',
'help' => lang('If you specify a document (full vfs path) here, infolog displays an extra document icon for each entry. That icon allows to download the specified document with the contact data inserted.').' '.
lang('The document can contain placeholder like $$info_subject$$, to be replaced with the contact data (%1full list of placeholder names%2).','<a href="'.$link.'" target="_blank">','</a>').' '.
'help' => lang('If you specify a document (full vfs path) here, %1 displays an extra document icon for each entry. That icon allows to download the specified document with the contact data inserted.',lang('calendar')).' '.
lang('The document can contain placeholder like $$calendar_title$$, to be replaced with the contact data (%1full list of placeholder names%2).','<a href="'.$link.'" target="_blank">','</a>').' '.
lang('At the moment the following document-types are supported:').'*.rtf, *.txt',
'run_lang' => false,
'xmlrpc' => True,
@ -603,8 +603,8 @@ class calendar_hooks
'size' => 60,
'label' => 'Directory with documents to insert entries',
'name' => 'document_dir',
'help' => lang('If you specify a directory (full vfs path) here, infolog displays an action for each document. That action allows to download the specified document with the infolog data inserted.').' '.
lang('The document can contain placeholder like $$info_subject$$, to be replaced with the contact data (%1full list of placeholder names%2).','<a href="'.$link.'" target="_blank">','</a>').' '.
'help' => lang('If you specify a directory (full vfs path) here, %1 displays an action for each document. That action allows to download the specified document with the infolog data inserted.',lang('calendar')).' '.
lang('The document can contain placeholder like $$calendar_title$$, to be replaced with the contact data (%1full list of placeholder names%2).','<a href="'.$link.'" target="_blank">','</a>').' '.
lang('At the moment the following document-types are supported:').'*.rtf, *.txt',
'run_lang' => false,
'xmlrpc' => True,

View File

@ -32,6 +32,25 @@ class calendar_merge extends bo_merge
// Object used for getting resource info
protected static $resources;
/**
* Recognised relative days - used as a day table, like day_<n>
*/
protected static $relative = array(
'today',
'tomorrow',
'yesterday',
);
/**
* If you use a range, these extra tags are available
*/
protected static $range_tags = array(
'start' => 'Y-m-d',
'end' => 'Y-m-d',
'month' => 'm',
'year' => 'Y'
);
/**
* Constructor
*/
@ -41,12 +60,23 @@ class calendar_merge extends bo_merge
$this->bo = new calendar_boupdate();
self::$range_tags += array(
'start' => $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],
'end' => $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],
);
// Register table plugins
$this->table_plugins['participant'] = 'participant';
for($i = 0; $i < 7; $i++)
{
$this->table_plugins[date('l', strtotime("+$i days"))] = 'day_plugin';
}
for($i = 1; $i <= 31; $i++) {
$this->table_plugins['day_'.$i] = 'day'; // Numerically by day number (1-31)
}
foreach(self::$relative as $day) {
$this->table_plugins[$day] = 'day'; // Current day
}
}
/**
@ -61,7 +91,7 @@ class calendar_merge extends bo_merge
$prefix = '';
// List events ?
if(is_array($id) && !$id['id'] && strpos($content,'$$calendar/') !== false)
if(is_array($id) && !$id['id'] && strpos($content,'$$calendar/') !== false || strpos($content, '$$table/day') !== false)
{
$events = $this->bo->search($id + array(
'offset' => 0,
@ -79,6 +109,13 @@ class calendar_merge extends bo_merge
foreach($events as $event)
{
$values = $this->calendar_replacements($event,sprintf($prefix,++$n));
if(is_array($id) && $id['start'])
{
foreach(self::$range_tags as $key => $format)
{
$values["$\$range/$key$$"] = date($format, $key == 'end' ? $id['end'] : $id['start']);
}
}
$replacements += $values;
}
return $replacements;
@ -176,6 +213,69 @@ class calendar_merge extends bo_merge
return $days[date('Ymd',$_date)][$plugin][0];
}
/**
* Table plugin for a certain date
*
* Can be either a particular date (2011-02-15) or a day of the month (15)
*
* @param string $plugin
* @param int $id
* @param int $n
* @return array
*/
public function day($plugin,$id,$n)
{
static $days;
// Figure out which day
list($type, $which) = explode('_',$plugin);
if($type == 'day' && $which)
{
$date = $this->bo->date2array($id['start']);
$date['day'] = $which;
$date = $this->bo->date2ts($date);
if(is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end'])) return array();
}
else
{
$date = strtotime($plugin);
}
if($type == 'day' && is_array($id) && !$id['start']) {
$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
if($which && date('d',$event['start']) != $which) return array();
if(date('Ymd',$date) != date('Ymd', $event['start'])) return array();
return $n == 0 ? $this->calendar_replacements($event) : array();
}
// Use start for cache, in case of multiple months
$_date = $id['start'] ? $id['start'] : $date;
if($days[date('Ymd',$_date)][$plugin]) return $days[date('Ymd',$_date)][$plugin][$n];
$events = $this->bo->search(array(
'start' => $date,
'end' => mktime(23,59,59,date('m',$date),date('d',$date),date('Y',$date)),
'offset' => 0,
'num_rows' => 20,
'order' => 'cal_start',
'daywise' => true
));
$replacements = array();
foreach($events as $day => $list)
{
foreach($list as $key => $event)
{
$days[date('Ymd',$_date)][$plugin][] = $this->calendar_replacements($event);
}
}
//_debug_array($days);
return $days[date('Ymd',$_date)][$plugin][0];
}
/**
* Table plugin for a certain date
}
/**
* Table plugin for participants
*
@ -306,6 +406,12 @@ class calendar_merge extends bo_merge
$n++;
}
echo '<tr><td colspan="4"><h3>'.lang('Range fields').":</h3></td></tr>";
echo '<tr><td colspan="4">'.lang('If you select a range (month, week, etc) instead of a list of entries, these extra fields are available').'</td></tr>';
foreach(self::$range_tags as $name => $format)
{
echo '<tr><td>$$range/'.$name.'$$</td><td>'.lang($name)."</td></tr>\n";
}
echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";
$custom = config::get_customfields('calendar');
foreach($custom as $name => $field)
@ -314,13 +420,15 @@ class calendar_merge extends bo_merge
}
echo '<tr><td colspan="4"><h3>'.lang('Participant table').":</h3></td></tr>";
echo '<tr><td colspan="4">$$table/participant$$ ... $$endtable$$</td></tr>';
echo '<tr><td>$$name$$</td></tr>';
echo '<tr><td>$$role$$</td></tr>';
echo '<tr><td>$$quantity$$</td></tr>';
echo '<tr><td>$$status$$</td></tr>';
echo '<tr><td colspan="4">$$table/participant$$ ... </td></tr>';
echo '<tr><td>$$name$$</td><td>'.lang('name').'</td></tr>';
echo '<tr><td>$$role$$</td><td>'.lang('role').'</td></tr>';
echo '<tr><td>$$quantity$$</td><td>'.lang('quantity').'</td></tr>';
echo '<tr><td>$$status$$</td><td>'.lang('status').'</td></tr>';
echo '<tr><td colspan="4">$$endtable$$</td></tr>';
echo '<tr><td colspan="4"><h3>'.lang('Day of week tables').":</h3></td></tr>";
echo '<tr style="vertical-align:top"><td colspan="2"><table >';
echo '<tr><td><h3>'.lang('Day of week tables').":</h3></td></tr>";
$days = array();
for($i = 0; $i < 7; $i++)
{
@ -329,8 +437,15 @@ class calendar_merge extends bo_merge
ksort($days);
foreach($days as $day)
{
echo '<tr><td colspan="4">$$table/'.$day. '$$ ... $$endtable$$</td></tr>';
echo '<tr><td>$$table/'.$day. '$$ ... $$endtable$$</td></tr>';
}
echo '</table></td><td><table >';
echo '<tr><td><h3>'.lang('Daily tables').":</h3></td></tr>";
foreach(self::$relative as $key => $value) {
echo '<tr><td>$$table/'.$value. '$$ ... $$endtable$$</td></tr>';
}
echo '<tr><td>$$table/day_n$$ ... $$endtable$$</td><td>1 <= n <= 31</td></tr>';
echo '</table></td></tr>';
echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";
foreach(array(

View File

@ -773,23 +773,21 @@ function load_cal(url,id) {
'link' => False
);
}
/*
$print_functions = array(
'calendar.calendar_uiviews.day' => 'calendar.pdfcal.day',
'calendar.calendar_uiviews.week' => 'calendar.pdfcal.week',
);
if (isset($print_functions[$_GET['menuaction']]))
{
$file[] = array(
'text' => 'pdf-export / print',
'link' => egw::link('/index.php',array(
'menuaction' => $print_functions[$_GET['menuaction']],
'date' => $this->date,
)),
'target' => '_blank',
);
// Merge print
if ($GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir'])
{
$options = '';
foreach(calendar_merge::get_documents($GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir']) as $key => $value)
{
$options .= '<option value="'.$key.'">'.html::htmlspecialchars($value)."</option>\n";
}
if($options != '') {
$options = '<option value="">'.lang('Insert in document')."</option>\n" . $options;
$file[] = $this->_select_box('merge document...','merge',$options,$baseurl ? $baseurl.'&merge=' : '');
}
}
*/
$appname = 'calendar';
$menu_title = lang('Calendar Menu');
display_sidebox($appname,$menu_title,$file);
@ -829,4 +827,22 @@ function load_cal(url,id) {
display_sidebox($appname,$menu_title,$file);
}
}
public function merge($timespan = array())
{
// Merge print
if($_GET['merge'])
{
if(!$timespan)
{
$timespan = array(array(
'start' => is_array($this->first) ? $this->bo->date2ts($this->first) : $this->first,
'end' => is_array($this->last) ? $this->bo->date2ts($this->last) : $this->last
));
}
list($document, $filename) = explode('_',$_GET['merge'], 2);
return calendar_uilist::download_document($timespan, $filename);
}
return false;
}
}

View File

@ -188,6 +188,7 @@ class calendar_uiviews extends calendar_ui
}
}
/**
* Calculate iso8601 week-number, which is defined for Monday as first day of week only
*
@ -338,6 +339,9 @@ class calendar_uiviews extends calendar_ui
$this->bo->long_date($this->first,$this->planner_days > 1 ? $this->last : 0);
}
$merge = $this->merge();
if($merge) return $merge;
$search_params = $this->search_params;
$search_params['daywise'] = false;
$search_params['start'] = $this->first;
@ -390,6 +394,9 @@ class calendar_uiviews extends calendar_ui
$GLOBALS['egw_info']['flags']['app_header'] .= ': '.$this->year;
$merge = $this->merge();
if($merge) return $merge;
$days =& $this->bo->search(array(
'start' => $this->first,
'end' => $this->last,
@ -609,6 +616,28 @@ class calendar_uiviews extends calendar_ui
$this->use_time_grid = !$this->cal_prefs['use_time_grid'] || $this->cal_prefs['use_time_grid'] == 'all'; // all views
// Merge print
if($weeks)
{
// Split up span into multiple weeks
$timespan = array();
$this->first = $this->datetime->get_weekday_start($this->year,$this->month,$this->day);
for($i = 0; $i < $weeks; $i++)
{
$timespan[] = array(
'start' => strtotime("+$i weeks", $this->first),
'end' => strtotime('+' . ($i+1).' weeks', $this->first) -1
);
}
} else {
$timespan[] = array(
'start' => mktime(0,0,0,$this->month,1,$this->year),
'end' => mktime(0,0,0,$this->month+1,1,$this->year)-1
);
}
$merge = $this->merge($timespan);
if($merge) return $merge;
if ($weeks)
{
$this->first = $this->datetime->get_weekday_start($this->year,$this->month,$this->day);
@ -789,6 +818,9 @@ class calendar_uiviews extends calendar_ui
# $class = $class == 'row_on' ? 'th' : 'row_on';
//echo "<p>weekdaystarts='".$this->cal_prefs['weekdaystarts']."', get_weekday_start($this->year,$this->month,$this->day)=".date('l Y-m-d',$wd_start).", first=".date('l Y-m-d',$this->first)."</p>\n";
$merge = $this->merge();
if($merge) return $merge;
$search_params = array(
'start' => $this->first,
'end' => $this->last,
@ -843,6 +875,9 @@ class calendar_uiviews extends calendar_ui
$this->search_params['end'] = $this->last = $this->first+DAY_s-1;
$merge = $this->merge();
if($merge) return $merge;
if (!$home)
{
$this->do_header();