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
*/
class addressbook_merge // extends bo_merge
{
/**
* Functions that can be called via menuaction
*
* @ var array
*/
var $public_functions = array ( 'show_replacements' => true );
/**
2008-05-10 14:02:49 +02:00
* Instance of the addressbook_bo class
2007-06-17 15:56:35 +02:00
*
2008-05-10 14:02:49 +02:00
* @ var addressbook_bo
2007-06-17 15:56:35 +02:00
*/
var $contacts ;
/**
* Constructor
*
* @ return addressbook_merge
*/
2008-05-10 14:02:49 +02:00
function __construct ()
2007-06-17 15:56:35 +02:00
{
2009-06-08 18:21:14 +02:00
$this -> contacts = new addressbook_bo ();
2007-06-17 15:56:35 +02:00
}
2008-05-10 14:02:49 +02:00
2009-07-04 12:50:19 +02:00
/**
* Return if merge - print is implemented for given mime - type ( and / or extension )
*
* @ param string $mimetype eg . text / plain
* @ param string $extension only checked for applications / msword and . rtf
*/
static function is_implemented ( $mimetype , $extension = null )
{
2009-08-03 13:44:45 +02:00
static $zip_available ;
if ( is_null ( $zip_available ))
{
$zip_available = check_load_extension ( 'zip' ) &&
class_exists ( 'ZipArchive' ); // some PHP has zip extension, but no ZipArchive (eg. RHEL5!)
}
2009-07-04 12:50:19 +02:00
switch ( $mimetype )
{
case 'application/msword' :
if ( strtolower ( $extension ) != '.rtf' ) break ;
case 'application/rtf' :
2009-07-07 12:12:31 +02:00
case 'text/rtf' :
2009-07-04 12:50:19 +02:00
return true ; // rtf files
case 'application/vnd.oasis.opendocument.text' :
2009-08-03 13:44:45 +02:00
if ( ! $zip_available ) break ;
2009-07-04 12:50:19 +02:00
return true ; // open office write xml files
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' :
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d' : // mimetypes in vfs are limited to 64 chars
2009-08-03 13:44:45 +02:00
if ( ! $zip_available ) break ;
2009-07-04 12:50:19 +02:00
return true ; // ms word xml format
default :
if ( substr ( $mimetype , 0 , 5 ) == 'text/' )
{
return true ; // text files
}
break ;
}
return false ;
// As browsers not always return correct mime types, one could use a negative list instead
//return !($mimetype == egw_vfs::DIR_MIME_TYPE || substr($mimetype,0,6) == 'image/');
}
2007-06-17 15:56:35 +02:00
/**
* Return replacements for a contact
*
* @ param int / string / array $contact contact - array or id
* @ param string $prefix = '' prefix like eg . 'user'
* @ return array
*/
function contact_replacements ( $contact , $prefix = '' )
{
if ( ! is_array ( $contact ))
{
$contact = $this -> contacts -> read ( $contact );
}
if ( ! is_array ( $contact )) return array ();
$replacements = array ();
2008-04-17 11:17:56 +02:00
foreach ( array_keys ( $this -> contacts -> contact_fields ) as $name )
2007-06-17 15:56:35 +02:00
{
2008-04-17 11:17:56 +02:00
$value = $contact [ $name ];
2007-06-17 15:56:35 +02:00
switch ( $name )
{
case 'created' : case 'modified' :
$value = date ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'dateformat' ] . ' ' .
2008-11-21 10:25:16 +01:00
( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'timeformat' ] == 12 ? 'h:i a' : 'H:i' ), $value );
2007-06-17 15:56:35 +02:00
break ;
case 'bday' :
if ( $value )
{
list ( $y , $m , $d ) = explode ( '-' , $value );
2009-06-08 21:48:26 +02:00
$value = $GLOBALS [ 'egw' ] -> common -> dateformatorder ( $y , $m , $d , true );
2007-06-17 15:56:35 +02:00
}
break ;
case 'owner' : case 'creator' : case 'modifier' :
$value = $GLOBALS [ 'egw' ] -> common -> grab_owner_name ( $value );
break ;
case 'cat_id' :
if ( $value )
{
2008-02-07 03:45:48 +01:00
// if cat-tree is displayed, we return a full category path not just the name of the cat
$use = $GLOBALS [ 'egw_info' ][ 'server' ][ 'cat_tab' ] == 'Tree' ? 'path' : 'name' ;
2007-06-17 15:56:35 +02:00
$cats = array ();
foreach ( is_array ( $value ) ? $value : explode ( ',' , $value ) as $cat_id )
{
2008-03-25 11:01:29 +01:00
$cats [] = $GLOBALS [ 'egw' ] -> categories -> id2name ( $cat_id , $use );
2007-06-17 15:56:35 +02:00
}
2007-06-19 19:06:32 +02:00
$value = implode ( ', ' , $cats );
2007-06-17 15:56:35 +02:00
}
break ;
case 'jpegphoto' : // returning a link might make more sense then the binary photo
if ( $contact [ 'photo' ])
{
$value = ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'webserver_url' ]{ 0 } == '/' ?
( $_SERVER [ 'HTTPS' ] ? 'https://' : 'http://' ) . $_SERVER [ 'HTTP_HOST' ] : '' ) .
$GLOBALS [ 'egw' ] -> link ( '/index.php' , $contact [ 'photo' ]);
}
break ;
case 'tel_prefer' :
if ( $value && $contact [ $value ])
{
$value = $contact [ $value ];
}
break ;
2007-06-19 19:06:32 +02:00
case 'account_id' :
if ( $value )
{
$replacements [ '$$' . ( $prefix ? $prefix . '/' : '' ) . 'account_lid$$' ] = $GLOBALS [ 'egw' ] -> accounts -> id2name ( $value );
}
break ;
2007-06-17 15:56:35 +02:00
}
2007-06-19 19:06:32 +02:00
if ( $name != 'photo' ) $replacements [ '$$' . ( $prefix ? $prefix . '/' : '' ) . $name . '$$' ] = $value ;
2007-06-17 15:56:35 +02:00
}
2009-06-29 15:27:13 +02:00
// set custom fields
foreach ( $this -> contacts -> customfields as $name => $field )
2008-02-07 03:45:48 +01:00
{
2009-06-29 15:27:13 +02:00
$name = '#' . $name ;
$value = ( string ) $contact [ $name ];
switch ( $field [ 'type' ])
2008-02-07 03:45:48 +01:00
{
2009-06-29 15:27:13 +02:00
case 'select-account' :
if ( $value ) $value = common :: grab_owner_name ( $value );
break ;
case 'select' :
if ( count ( $field [ 'values' ]) == 1 && isset ( $field [ 'values' ][ '@' ]))
{
$field [ 'values' ] = customfields_widget :: _get_options_from_file ( $field [ 'values' ][ '@' ]);
}
$values = array ();
foreach ( $field [ 'rows' ] > 1 ? explode ( ',' , $value ) : ( array ) $value as $value )
{
$values [] = $field [ 'values' ][ $value ];
}
$value = implode ( ', ' , $values );
break ;
case 'date' :
case 'date-time' :
if ( $value )
{
$format = $field [ 'len' ] ? $field [ 'len' ] : ( $field [ 'type' ] == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s' );
$date = array_combine ( preg_split ( '/[\\/. :-]/' , $format ), preg_split ( '/[\\/. :-]/' , $value ));
$value = common :: dateformatorder ( $date [ 'Y' ], $date [ 'm' ], $date [ 'd' ], true );
if ( isset ( $date [ 'H' ])) $value .= ' ' . common :: formattime ( $date [ 'H' ], $date [ 'i' ]);
}
break ;
2008-02-07 03:45:48 +01:00
}
2009-06-29 15:27:13 +02:00
$replacements [ '$$' . ( $prefix ? $prefix . '/' : '' ) . $name . '$$' ] = $value ;
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
*/
2008-02-07 03:45:48 +01:00
function calendar_replacements ( $id , $last_event_too = false )
2007-06-17 15:56:35 +02:00
{
2008-06-09 14:32:15 +02:00
require_once ( EGW_INCLUDE_ROOT . '/calendar/inc/class.calendar_boupdate.inc.php' );
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' ,
2008-02-07 03:45:48 +01:00
));
2008-02-15 03:17:47 +01:00
if ( $events )
2008-02-07 03:45:48 +01:00
{
2008-02-15 03:17:47 +01:00
array_unshift ( $events , false ); unset ( $events [ 0 ]); // renumber the array to start with key 1, instead of 0
}
else
{
$events = array ();
}
if ( $last_event_too = true )
{
$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' ,
));
2008-02-15 03:17:47 +01:00
if ( $last ) $events [ '-1' ] = array_shift ( $last ); // returned events are indexed by cal_id!
2008-02-07 03:45:48 +01:00
}
$replacements = array ();
foreach ( $events as $n => $event )
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 )
{
$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 ;
2007-06-17 15:56:35 +02:00
}
/**
* Merges a given document with contact data
*
2009-07-04 12:50:19 +02:00
* @ param string $document path / url of document
2007-06-17 15:56:35 +02:00
* @ param array $ids array with contact id ( s )
* @ param string & $err error - message on error
2009-07-04 12:50:19 +02:00
* @ param string $mimetype mimetype of complete document , eg . text /* , application / vnd . oasis . opendocument . text , application / rtf
2009-08-03 14:06:59 +02:00
* @ param array $fix = null regular expression => replacement pairs eg . to fix garbled placeholders
2007-06-17 15:56:35 +02:00
* @ return string / boolean merged document or false on error
*/
2009-08-03 14:06:59 +02:00
function & merge ( $document , $ids , & $err , $mimetype , array $fix = null )
2007-06-17 15:56:35 +02:00
{
2009-07-04 12:50:19 +02:00
if ( ! ( $content = file_get_contents ( $document )))
2007-06-17 15:56:35 +02:00
{
2007-06-19 12:19:47 +02:00
$err = lang ( " Document '%1' does not exist or is not readable for you! " , $document );
2007-06-17 15:56:35 +02:00
return false ;
}
2009-08-03 14:06:59 +02:00
// fix garbled placeholders
if ( $fix && is_array ( $fix ))
{
$content = preg_replace ( array_keys ( $fix ), array_values ( $fix ), $content );
//die("<pre>".htmlspecialchars($content)."</pre>\n");
}
2008-04-09 16:59:55 +02:00
list ( $contentstart , $contentrepeat , $contentend ) = preg_split ( '/\$\$pagerepeat\$\$/' , $content , - 1 , PREG_SPLIT_NO_EMPTY ); //get differt parts of document, seperatet by Pagerepeat
2009-08-03 13:44:45 +02:00
if ( $mimetype == 'application/vnd.oasis.opendocument.text' && count ( $ids ) > 1 )
{
//for odt files we have to slpit the content and add a style for page break to the style area
2009-08-02 14:32:39 +02:00
list ( $contentstart , $contentrepeat , $contentend ) = preg_split ( '/office:body>/' , $content , - 1 , PREG_SPLIT_NO_EMPTY ); //get differt parts of document, seperatet by Pagerepeat
$contentstart = substr ( $contentstart , 0 , strlen ( $contentstart ) - 1 ); //remove "<"
$contentrepeat = substr ( $contentrepeat , 0 , strlen ( $contentrepeat ) - 2 ); //remove "</";
2009-08-03 14:06:59 +02:00
// need to add page-break style to the style list
2009-08-02 14:32:39 +02:00
list ( $stylestart , $stylerepeat , $styleend ) = preg_split ( '/<\/office:automatic-styles>/' , $content , - 1 , PREG_SPLIT_NO_EMPTY ); //get differt parts of document style sheets
$contentstart = $stylestart . '<style:style style:name="P200" style:family="paragraph" style:parent-style-name="Standard"><style:paragraph-properties fo:break-before="page"/></style:style></office:automatic-styles>' ;
$contentstart .= '<office:body>' ;
$contentend = '</office:body></office:document-content>' ;
}
2009-02-22 13:24:24 +01:00
list ( $Labelstart , $Labelrepeat , $Labeltend ) = preg_split ( '/\$\$label\$\$/' , $contentrepeat , - 1 , PREG_SPLIT_NO_EMPTY ); //get the Lable content
preg_match_all ( '/\$\$labelplacement\$\$/' , $contentrepeat , $countlables , PREG_SPLIT_NO_EMPTY );
2009-07-04 12:50:19 +02:00
$countlables = count ( $countlables [ 0 ]) + 1 ;
2009-02-22 13:24:24 +01:00
preg_replace ( '/\$\$labelplacement\$\$/' , '' , $Labelrepeat , 1 );
2009-07-04 12:50:19 +02:00
if ( $countlables > 1 ) $lableprint = true ;
2008-04-09 16:59:55 +02:00
if ( count ( $ids ) > 1 && ! $contentrepeat )
2007-06-17 15:56:35 +02:00
{
2008-04-09 16:59:55 +02:00
$err = lang ( 'for more then one contact in a document use the tag pagerepeat!' );
2007-06-17 15:56:35 +02:00
return false ;
}
2008-05-10 14:02:49 +02:00
foreach ( $ids as $id )
{
2008-04-09 16:59:55 +02:00
if ( $contentrepeat ) $content = $contentrepeat ; //content to repeat
// generate replacements
2009-02-22 13:24:24 +01:00
if ( $lableprint ) $content = $Labelrepeat ;
2008-04-09 16:59:55 +02:00
if ( ! ( $replacements = $this -> contact_replacements ( $id )))
{
$err = lang ( 'Contact not found!' );
return false ;
}
if ( strpos ( $content , '$$user/' ) !== null && ( $user = $GLOBALS [ 'egw' ] -> accounts -> id2name ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ], 'person_id' )))
{
$replacements += $this -> contact_replacements ( $user , 'user' );
}
if ( strpos ( $content , '$$calendar/' ) !== null )
{
$replacements += $this -> calendar_replacements ( $id , strpos ( $content , '$$calendar/-1/' ) !== null );
}
$replacements [ '$$date$$' ] = date ( $GLOBALS [ 'egw_info' ][ 'user' ][ 'preferences' ][ 'common' ][ 'dateformat' ], time () + $this -> contacts -> tz_offset_s );
2008-05-10 14:02:49 +02:00
2008-04-09 16:59:55 +02:00
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 );
2008-05-10 14:02:49 +02:00
2008-04-09 16:59:55 +02:00
if ( strpos ( $content , '$$calendar/' ) !== null ) // remove not existing event-replacements
{
$content = preg_replace ( '/\$\$calendar\/[0-9]+\/[a-z_]+\$\$/' , '' , $content );
}
2008-04-15 10:26:50 +02:00
$this -> replacements = $replacements ;
if ( strpos ( $content , '$$IF' ))
{ //Example use to use: $$IF n_prefix~Herr~Sehr geehrter~Sehr geehrte$$
$content = preg_replace_callback ( '/\$\$IF ([0-9a-z_-]+)~(.*)~(.*)~(.*)\$\$/imU' , Array ( $this , 'replace_callback' ), $content );
}
2008-04-09 16:59:55 +02:00
if ( $contentrepeat ) $contentrep [ $id ] = $content ;
2007-06-19 19:06:32 +02:00
}
2009-02-22 13:24:24 +01:00
if ( $Labelrepeat )
{
$countpage = 0 ;
$count = 0 ;
$contentrepeatpages [ $countpage ] = $Labelstart . $Labeltend ;
foreach ( $contentrep as $Label )
{
$count = $count + 1 ;
if ( $count % $countlables == 0 )
{
$countpage = $countpage + 1 ;
$contentrepeatpages [ $countpage ] = $Labelstart . $Labeltend ;
}
$contentrepeatpages [ $countpage ] = preg_replace ( '/\$\$labelplacement\$\$/' , $Label , $contentrepeatpages [ $countpage ], 1 );
}
$contentrepeatpages [ $countpage ] = preg_replace ( '/\$\$labelplacement\$\$/' , '' , $contentrepeatpages [ $countpage ], - 1 ); //clean empty fields
2009-07-04 12:50:19 +02:00
switch ( $mimetype )
{
case 'application/msword' :
if ( strtolower ( substr ( $document , - 4 )) != '.rtf' ) break ; // no binary word documents
case 'application/rtf' :
2009-07-07 12:12:31 +02:00
case 'text/rtf' :
2009-07-04 12:50:19 +02:00
return $contentstart . implode ( '\\par \\page\\pard\\plain' , $contentrepeatpages ) . $contentend ;
case 'application/vnd.oasis.opendocument.text' :
// todo OO writer files
break ;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' :
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d' : // mimetypes in vfs are limited to 64 chars
// todo ms word xml files
break ;
}
$err = lang ( '%1 not implemented for %2!' , '$$labelplacement$$' , $mimetype );
return false ;
2009-02-22 13:24:24 +01:00
}
2008-05-10 14:02:49 +02:00
if ( $contentrepeat )
2007-06-19 19:06:32 +02:00
{
2009-07-04 12:50:19 +02:00
switch ( $mimetype )
{
case 'application/msword' :
if ( strtolower ( substr ( $document , - 4 )) != '.rtf' ) break ; // no binary word documents
case 'application/rtf' :
2009-07-07 12:12:31 +02:00
case 'text/rtf' :
2009-07-04 12:50:19 +02:00
return $contentstart . implode ( '\\par \\page\\pard\\plain' , $contentrep ) . $contentend ;
case 'application/vnd.oasis.opendocument.text' :
2009-08-02 14:32:39 +02:00
return $contentstart . implode ( '' , $contentrep ) . $contentend ;
2009-07-04 12:50:19 +02:00
break ;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' :
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d' : // mimetypes in vfs are limited to 64 chars
// todo ms word xml files
break ;
}
$err = lang ( '%1 not implemented for %2!' , '$$pagerepeat$$' , $mimetype );
return false ;
2008-05-10 14:02:49 +02:00
}
2007-06-19 19:06:32 +02:00
return $content ;
2007-06-17 15:56:35 +02:00
}
2008-05-10 14:02:49 +02:00
2009-07-04 12:50:19 +02:00
/**
* Callback for preg_replace to process $$IF
*
* @ param array $param
* @ return string
*/
2008-04-15 10:26:50 +02:00
function replace_callback ( $param )
{
2009-02-22 13:24:24 +01:00
if ( array_key_exists ( '$$' . $param [ 4 ] . '$$' , $this -> replacements )) $param [ 4 ] = $this -> replacements [ '$$' . $param [ 4 ] . '$$' ];
if ( array_key_exists ( '$$' . $param [ 3 ] . '$$' , $this -> replacements )) $param [ 3 ] = $this -> replacements [ '$$' . $param [ 3 ] . '$$' ];
2008-04-15 10:26:50 +02:00
$replace = preg_match ( '/' . $param [ 2 ] . '/' , $this -> replacements [ '$$' . $param [ 1 ] . '$$' ]) ? $param [ 3 ] : $param [ 4 ];
return $replace ;
2008-05-10 14:02:49 +02:00
}
2008-04-15 10:26:50 +02:00
2007-06-17 15:56:35 +02:00
/**
* Download document merged with contact ( s )
*
* @ param string $document vfs - path of document
* @ param array $ids array with contact id ( s )
* @ return string with error - message on error , otherwise it does NOT return
*/
function download ( $document , $ids )
{
2009-07-04 12:50:19 +02:00
$content_url = egw_vfs :: PREFIX . $document ;
switch (( $mime_type = egw_vfs :: mime_content_type ( $document )))
{
case 'application/vnd.oasis.opendocument.text' :
$archive = tempnam ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ], basename ( $document , '.odt' ) . '-' ) . '.odt' ;
copy ( $content_url , $archive );
$content_url = 'zip://' . $archive . '#' . ( $content_file = 'content.xml' );
break ;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.d' : // mimetypes in vfs are limited to 64 chars
2009-08-03 13:44:45 +02:00
$mime_type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ;
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' :
2009-07-04 12:50:19 +02:00
$archive = tempnam ( $GLOBALS [ 'egw_info' ][ 'server' ][ 'temp_dir' ], basename ( $document , '.dotx' ) . '-' ) . '.dotx' ;
copy ( $content_url , $archive );
$content_url = 'zip://' . $archive . '#' . ( $content_file = 'word/document.xml' );
2009-08-03 14:06:59 +02:00
$fix = array ( // regular expression to fix garbled placeholders
'/' . preg_quote ( '$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:t>' , '/' ) . '([a-z0-9_]+)' .
preg_quote ( '</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:t>' , '/' ) . '/i' => '$$\\1$$' ,
'/' . preg_quote ( '$$</w:t></w:r><w:proofErr w:type="spellStart"/><w:r><w:rPr><w:lang w:val="' , '/' ) .
'([a-z]{2}-[A-Z]{2})' . preg_quote ( '"/></w:rPr><w:t>' , '/' ) . '([a-z0-9_]+)' .
preg_quote ( '</w:t></w:r><w:proofErr w:type="spellEnd"/><w:r><w:rPr><w:lang w:val="' , '/' ) .
'([a-z]{2}-[A-Z]{2})' . preg_quote ( '"/></w:rPr><w:t>$$' , '/' ) . '/i' => '$$\\2$$' ,
);
2009-07-04 12:50:19 +02:00
break ;
}
2009-08-03 14:06:59 +02:00
if ( ! ( $merged =& $this -> merge ( $content_url , $ids , $err , $mime_type , $fix )))
2007-06-17 15:56:35 +02:00
{
return $err ;
}
2009-07-04 12:50:19 +02:00
if ( isset ( $archive ))
{
$zip = new ZipArchive ;
if ( $zip -> open ( $archive , ZIPARCHIVE :: CHECKCONS ) !== true ) throw new Exception ( " !ZipArchive::open(' $archive ',ZIPARCHIVE::OVERWRITE) " );
if ( $zip -> addFromString ( $content_file , $merged ) !== true ) throw new Exception ( " !ZipArchive::addFromString(' $content_file ', \$ merged) " );
if ( $zip -> close () !== true ) throw new Exception ( " !ZipArchive::close() " );
unset ( $zip );
unset ( $merged );
2009-08-03 13:44:45 +02:00
if ( file_exists ( '/usr/bin/zip' ) && version_compare ( PHP_VERSION , '5.3.1' , '<' )) // fix broken zip archives generated by current php
2009-07-04 12:50:19 +02:00
{
exec ( '/usr/bin/zip -F ' . escapeshellarg ( $archive ));
}
ExecMethod2 ( 'phpgwapi.browser.content_header' , basename ( $document ), $mime_type );
readfile ( $archive , 'r' );
}
else
{
ExecMethod2 ( 'phpgwapi.browser.content_header' , basename ( $document ), $mime_type );
echo $merged ;
}
2007-06-17 15:56:35 +02:00
$GLOBALS [ 'egw' ] -> common -> egw_exit ();
}
2008-05-10 14:02:49 +02:00
2007-06-17 15:56:35 +02:00
/**
* Generate table with replacements for the preferences
*
*/
function show_replacements ()
{
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'app_header' ] = lang ( 'Addressbook' ) . ' - ' . lang ( 'Replacements for inserting contacts into documents' );
$GLOBALS [ 'egw_info' ][ 'flags' ][ 'nonavbar' ] = false ;
$GLOBALS [ 'egw' ] -> common -> egw_header ();
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>' ;
echo '<td>$$' . $name . '$$</td><td>' . $label . '</td>' ;
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 )
{
echo '<tr><td>$$#' . $name . '$$</td><td colspan="3">' . $field [ 'label' ] . " </td></tr> \n " ;
}
2007-06-17 15:56:35 +02:00
echo '<tr><td colspan="4"><h3>' . lang ( 'General fields:' ) . " </h3></td></tr> " ;
foreach ( array (
'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' ),
2008-04-15 10:26:50 +02: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.' ),
) as $name => $label )
2007-06-17 15:56:35 +02:00
{
echo '<tr><td>$$' . $name . '$$</td><td colspan="3">' . $label . " </td></tr> \n " ;
}
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>' ;
2007-06-19 19:06:32 +02: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 " ;
$GLOBALS [ 'egw' ] -> common -> egw_footer ();
}
2008-06-09 14:32:15 +02:00
}