From 28d9dbf47196f64e79b2337cdef29f4c09cdfbeb Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 19 Jun 2007 17:06:32 +0000 Subject: [PATCH] fixed some bugs in the document templates and added the ability to print the next appointments of a contact --- .../inc/class.addressbook_merge.inc.php | 100 +++++++++++++++--- addressbook/inc/class.bocontacts.inc.php | 27 +++++ addressbook/inc/class.uicontacts.inc.php | 2 +- 3 files changed, 115 insertions(+), 14 deletions(-) diff --git a/addressbook/inc/class.addressbook_merge.inc.php b/addressbook/inc/class.addressbook_merge.inc.php index 42be281641..c13323a849 100644 --- a/addressbook/inc/class.addressbook_merge.inc.php +++ b/addressbook/inc/class.addressbook_merge.inc.php @@ -95,7 +95,7 @@ class addressbook_merge // extends bo_merge { $cats[] = $GLOBALS['egw']->cats->id2name($cat_id); } - $value = explode(', ',$cats); + $value = implode(', ',$cats); } break; case 'jpegphoto': // returning a link might make more sense then the binary photo @@ -112,8 +112,14 @@ class addressbook_merge // extends bo_merge $value = $contact[$value]; } break; + case 'account_id': + if ($value) + { + $replacements['$$'.($prefix ? $prefix.'/':'').'account_lid$$'] = $GLOBALS['egw']->accounts->id2name($value); + } + break; } - if ($name != 'photo') $replacements[($prefix ? $prefix.'[':'').'$$'.$name.'$$'.($prefix ? ']':'')] = $value; + if ($name != 'photo') $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = $value; } return $replacements; } @@ -128,7 +134,42 @@ class addressbook_merge // extends bo_merge */ function calendar_replacements($id) { - return array(); + require_once(EGW_INCLUDE_ROOT.'/calendar/inc/class.bocalupdate.inc.php'); + $calendar =& new bocalupdate(); + + $replacements = array(); $n = 1; + foreach($calendar->search(array( + 'start' => $calendar->now_su, + 'users' => 'c'.$id, + 'offset' => 0, + 'num_rows' => 20, + 'order' => 'cal_start', + )) as $event) + { + 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) + { + $value = date($format,$event[$what]); + 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; + } + return $replacements; } /** @@ -162,17 +203,27 @@ class addressbook_merge // extends bo_merge $err = lang('Contact not found!'); return false; } - if (strpos($content,'$$user[') !== null) + if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id'))) { - $replacements += $this->contact_replacements('account_id:'.$GLOBALS['egw_info']['user']['account_id'],'user'); + $replacements += $this->contact_replacements($user,'user'); } - if (strpos($content,'$$calendar[') !== null) + if (strpos($content,'$$calendar/') !== null) { $replacements += $this->calendar_replacements($id); } $replacements['$$date$$'] = date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],time()+$this->contacts->tz_offset_s); - - return str_replace(array_keys($replacements),array_values($replacements),$content); + + if ($this->contacts->prefs['csv_charset']) // if we have an export-charset defined, use it here to + { + $replacements = $GLOBALS['egw']->translation->convert($replacements,$GLOBALS['egw']->translation->charset(),$this->contacts->prefs['csv_charset']); + } + $content = str_replace(array_keys($replacements),array_values($replacements),$content); + + if (strpos($content,'$$calendar/') !== null) // remove not existing event-replacements + { + $content = preg_replace('/\$\$calendar\/[0-9]+\/[a-z_]+\$\$/','',$content); + } + return $content; } /** @@ -230,19 +281,42 @@ class addressbook_merge // extends bo_merge echo '

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

"; foreach(array( 'date' => lang('Date'), - 'user[n_fn]' => lang('Name of current user, all other contact fields are valid too'), - 'user[account_lid]' => lang('Username'), + 'user/n_fn' => lang('Name of current user, all other contact fields are valid too'), + 'user/account_lid' => lang('Username'), ) as $name => $label) { echo '$$'.$name.'$$'.$label."\n"; } - - echo '

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

"; + $GLOBALS['egw']->translation->add_app('calendar'); + echo '

'.lang('Calendar fields:')." # = 1, 2, ..., 20

"; foreach(array( + 'title' => lang('Title'), + 'description' => lang('Description'), + 'participants' => lang('Participants'), + 'category' => lang('Location'), + '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'), + 'owner' => lang('Owner'), + 'priority' => lang('Priority'), + 'updated' => lang('Updated'), + 'recur_type' => lang('Repetition'), + 'access' => lang('Access').': '.lang('public').', '.lang('private'), ) as $name => $label) { + if (in_array($name,array('start','end')) && $n&1) // main values, which should be in the first column + { + echo "\n"; + $n++; + } if (!($n&1)) echo ''; - echo '$$'.$name.'$$'.$label.''; + echo '$$calendar/#/'.$name.'$$'.$label.''; if ($n&1) echo "\n"; $n++; } diff --git a/addressbook/inc/class.bocontacts.inc.php b/addressbook/inc/class.bocontacts.inc.php index 00730d0c4a..df246b4052 100755 --- a/addressbook/inc/class.bocontacts.inc.php +++ b/addressbook/inc/class.bocontacts.inc.php @@ -791,8 +791,35 @@ class bocontacts extends socontacts { return array( 'type' => 'c',// one char type-identifiy for this resources + 'info' => 'addressbook.bocontacts.calendar_info',// info method, returns array with id, type & name for a given id ); } + + /** + * returns info about contacts for calender + * + * @param int/array $ids single contact-id or array of id's + * @return array + */ + function calendar_info($ids) + { + if (!$ids) return null; + + $data = array(); + foreach(!is_array($ids) ? array($ids) : $ids as $id) + { + if (!($contact = $this->read($id))) continue; + + $data[] = array( + 'res_id' => $id, + 'email' => $contact['email'] ? $contact['email'] : $contact['email_home'], + 'rights' => EGW_ACL_READ_FOR_PARTICIPANTS, + 'name' => $this->link_title($contact), + ); + } + //echo "

calendar_info(".print_r($ids,true).")="; _debug_array($data); + return $data; + } /** * Called by delete-account hook, when an account get deleted --> deletes/moves the personal addressbook diff --git a/addressbook/inc/class.uicontacts.inc.php b/addressbook/inc/class.uicontacts.inc.php index ff912bcc90..3024e0af6e 100644 --- a/addressbook/inc/class.uicontacts.inc.php +++ b/addressbook/inc/class.uicontacts.inc.php @@ -480,7 +480,7 @@ class uicontacts extends bocontacts } if (substr($action,0,9) == 'document-') { - $document = substr($action,10); + $document = substr($action,9); $action = 'document'; } // Security: stop non-admins to export more then the configured number of contacts