diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index c833be593d..109b49296e 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -857,7 +857,9 @@ class addressbook_ui extends addressbook_bo return false; case 'document': - $msg = $this->download_document($checked,$document); + if (!$document) $document = $this->prefs['default_document']; + $document_merge = new addressbook_merge(); + $msg = $document_merge->download($document, $checked, '', $this->prefs['document_dir']); return false; case 'infolog_add': @@ -2306,32 +2308,6 @@ class addressbook_ui extends addressbook_bo common::egw_footer(); } - /** - * Download a document with inserted contact(s) - * - * @param array $ids contact-ids - * @param string $document vfs-path of document - * @return string error-message or error, otherwise the function does NOT return! - */ - function download_document($ids,$document='') - { - if (!$document) - { - $document = $this->prefs['default_document']; - } - elseif ($document[0] != '/') - { - $document = $this->prefs['document_dir'].'/'.$document; - } - if (!@egw_vfs::stat($document)) - { - return lang("Document '%1' does not exist or is not readable for you!",$document); - } - $document_merge = new addressbook_merge(); - - return $document_merge->download($document,$ids); - } - /** * Set up history log widget */ diff --git a/calendar/inc/class.calendar_uilist.inc.php b/calendar/inc/class.calendar_uilist.inc.php index 585c21775a..70631a23d5 100644 --- a/calendar/inc/class.calendar_uilist.inc.php +++ b/calendar/inc/class.calendar_uilist.inc.php @@ -529,8 +529,11 @@ class calendar_uilist extends calendar_ui echo $ical; common::egw_exit(); break; + case 'document': - $msg = $this->download_document($checked,$settings); + if (!$settings) $settings = $GLOBALS['egw_info']['user']['preferences']['calendar']['default_document']; + $document_merge = new calendar_merge(); + $msg = $document_merge->download($settings, $checked, '', $GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir']); $failed = count($checked); return false; } @@ -706,32 +709,6 @@ class calendar_uilist extends calendar_ui return $checked; } - /** - * Download a document with inserted entries - * - * @param array $ids timesheet-ids - * @param string $document vfs-path of document - * @return string error-message or error, otherwise the function does NOT return! - */ - function download_document($ids,$document='') - { - if (!$document) - { - $document = $GLOBALS['egw_info']['user']['preferences']['calendar']['default_document']; - } - elseif ($document[0] != '/') - { - $document = $GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir'].'/'.$document; - } - if (!@egw_vfs::stat($document)) - { - return lang("Document '%1' does not exist or is not readable for you!",$document); - } - $document_merge = new calendar_merge(); - - return $document_merge->download($document,$ids); - } - /** * Get actions / context menu items * diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index 192de6bb64..c4b662146b 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -5,7 +5,7 @@ * @link http://www.egroupware.org * @author Ralf Becker * @package addressbook - * @copyright (c) 2007-10 by Ralf Becker + * @copyright (c) 2007-11 by Ralf Becker * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ @@ -752,10 +752,15 @@ abstract class bo_merge * @param string $document vfs-path of document * @param array $ids array with contact id(s) * @param string $name='' name to use for downloaded document + * @param string $dirs comma or whitespace separated directories, used if $document is a relative path * @return string with error-message on error, otherwise it does NOT return */ - public function download($document,$ids,$name='') + public function download($document, $ids, $name='', $dirs='') { + if (($error = $this->check_document($document, $dirs))) + { + return $error; + } $content_url = egw_vfs::PREFIX.$document; switch (($mimetype = egw_vfs::mime_content_type($document))) { @@ -974,6 +979,35 @@ abstract class bo_merge ); } + /** + * Check if given document (relative path from document_actions()) exists in one of the given dirs + * + * @param string &$document maybe relative path of document, on return true absolute path to existing document + * @param string $dirs comma or whitespace separated directories + * @return string|boolean false if document exists, otherwise string with error-message + */ + public static function check_document(&$document, $dirs) + { + if($document[0] !== '/') + { + // split multiple comma or whitespace separated directories + // to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split + if ($dirs && ($dirs = preg_split('/[,\s]+\//', $dirs))) + { + foreach($dirs as $n => $dir) + { + if ($n) $dir = '/'.$dir; // re-adding trailing slash removed by split + if (egw_vfs::stat($dir.'/'.$document) && egw_vfs::is_readable($dir.'/'.$document)) + { + $document = $dir.'/'.$document; + return false; + } + } + } + } + return lang("Document '%1' does not exist or is not readable for you!",$document); + } + /** * Get a list of supported extentions */ diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index a84c5d58fb..3e5582d2b4 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -1051,7 +1051,9 @@ class infolog_ui return $failed == 0; case 'document': - $msg = $this->download_document($checked,$settings); + if (!$settings) $settings = $this->prefs['default_document']; + $document_merge = new infolog_merge(); + $msg = $document_merge->download($settings, $checked, '', $this->prefs['document_dir']); $failed = count($checked); return false; @@ -2214,58 +2216,4 @@ class infolog_ui } return $fields; } - - /** - * Returning document actions / files from the document_dir - * - * @return array - */ - function get_document_actions() - { - if (!$this->prefs['document_dir']) return array(); - - //if (!is_array($actions = egw_session::appsession('document_actions','infolog'))) - //{ - $actions = array(); - if (($files = egw_vfs::find($this->prefs['document_dir'],array('need_mime'=>true),true))) - { - foreach($files as $file) - { - // return only the mime-types we support - if (!infolog_merge::is_implemented($file['mime'],substr($file['name'],-4))) continue; - - $actions['document_'.$file['name']] = /*lang('Insert in document').': '.*/$file['name']; - } - } - egw_session::appsession('document_actions','infolog',$actions); - //} - return $actions; - } - - /** - * Download a document with inserted entries - * - * @param array $ids infolog-ids - * @param string $document vfs-path of document - * @return string error-message or error, otherwise the function does NOT return! - */ - function download_document($ids,$document='') - { - if (!$document) - { - $document = $this->prefs['default_document']; - } - elseif($document[0] !== '/') - { - $document = $this->prefs['document_dir'].'/'.$document; - } - if (!@egw_vfs::stat($document)) - { - return lang("Document '%1' does not exist or is not readable for you!",$document); - } - require_once(EGW_INCLUDE_ROOT.'/infolog/inc/class.infolog_merge.inc.php'); - $document_merge = new infolog_merge(); - - return $document_merge->download($document,$ids); - } } diff --git a/timesheet/inc/class.timesheet_ui.inc.php b/timesheet/inc/class.timesheet_ui.inc.php index 76cc9bee3f..58f4d4033b 100644 --- a/timesheet/inc/class.timesheet_ui.inc.php +++ b/timesheet/inc/class.timesheet_ui.inc.php @@ -1036,7 +1036,9 @@ class timesheet_ui extends timesheet_bo break; case 'document': - $msg = $this->download_document($checked,$settings); + if (!$settings) $settings = $GLOBALS['egw_info']['user']['preferences']['timesheet']['default_document']; + $document_merge = new timesheet_merge(); + $msg = $document_merge->download($settings, $checked, '', $GLOBALS['egw_info']['user']['preferences']['timesheet']['document_dir']); $failed = count($checked); return false; } @@ -1145,30 +1147,4 @@ class timesheet_ui extends timesheet_bo } '; } - - /** - * Download a document with inserted entries - * - * @param array $ids timesheet-ids - * @param string $document vfs-path of document - * @return string error-message or error, otherwise the function does NOT return! - */ - function download_document($ids,$document='') - { - if (!$document) - { - $document = $GLOBALS['egw_info']['user']['preferences']['timesheet']['default_document']; - } - elseif ($document[0] != '/') - { - $document = $GLOBALS['egw_info']['user']['preferences']['timesheet']['document_dir'].'/'.$document; - } - if (!@egw_vfs::stat($document)) - { - return lang("Document '%1' does not exist or is not readable for you!",$document); - } - $document_merge = new timesheet_merge(); - - return $document_merge->download($document,$ids); - } }