diff --git a/calendar/inc/class.calendar_hooks.inc.php b/calendar/inc/class.calendar_hooks.inc.php index 87db73b3fc..e6f7438d5d 100644 --- a/calendar/inc/class.calendar_hooks.inc.php +++ b/calendar/inc/class.calendar_hooks.inc.php @@ -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).','','').' '. + '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).','','').' '. 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).','','').' '. + '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).','','').' '. lang('At the moment the following document-types are supported:').'*.rtf, *.txt', 'run_lang' => false, 'xmlrpc' => True, diff --git a/calendar/inc/class.calendar_merge.inc.php b/calendar/inc/class.calendar_merge.inc.php index f253ea21a6..fd19d40b22 100644 --- a/calendar/inc/class.calendar_merge.inc.php +++ b/calendar/inc/class.calendar_merge.inc.php @@ -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_ + */ + 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 '

'.lang('Range fields').":

"; + echo ''.lang('If you select a range (month, week, etc) instead of a list of entries, these extra fields are available').''; + foreach(self::$range_tags as $name => $format) + { + echo '$$range/'.$name.'$$'.lang($name)."\n"; + } echo '

'.lang('Custom fields').":

"; $custom = config::get_customfields('calendar'); foreach($custom as $name => $field) @@ -314,13 +420,15 @@ class calendar_merge extends bo_merge } echo '

'.lang('Participant table').":

"; - echo '$$table/participant$$ ... $$endtable$$'; - echo '$$name$$'; - echo '$$role$$'; - echo '$$quantity$$'; - echo '$$status$$'; + echo '$$table/participant$$ ... '; + echo '$$name$$'.lang('name').''; + echo '$$role$$'.lang('role').''; + echo '$$quantity$$'.lang('quantity').''; + echo '$$status$$'.lang('status').''; + echo '$$endtable$$'; - echo '

'.lang('Day of week tables').":

"; + echo ''; + echo '"; $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 ''; + echo ''; } + echo '

'.lang('Day of week tables').":

$$table/'.$day. '$$ ... $$endtable$$
$$table/'.$day. '$$ ... $$endtable$$
'; + echo '"; + foreach(self::$relative as $key => $value) { + echo ''; + } + echo ''; + echo '

'.lang('Daily tables').":

$$table/'.$value. '$$ ... $$endtable$$
$$table/day_n$$ ... $$endtable$$1 <= n <= 31
'; echo '

'.lang('General fields:')."

"; foreach(array( diff --git a/calendar/inc/class.calendar_ui.inc.php b/calendar/inc/class.calendar_ui.inc.php index a302e134cd..d4ac584a62 100644 --- a/calendar/inc/class.calendar_ui.inc.php +++ b/calendar/inc/class.calendar_ui.inc.php @@ -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 .= '\n"; + } + if($options != '') { + $options = '\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; + } } diff --git a/calendar/inc/class.calendar_uiviews.inc.php b/calendar/inc/class.calendar_uiviews.inc.php index c07d3eb42c..2f6445631e 100644 --- a/calendar/inc/class.calendar_uiviews.inc.php +++ b/calendar/inc/class.calendar_uiviews.inc.php @@ -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 "

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)."

\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();