forked from extern/egroupware
support for multiple space or comma separated download dirs
This commit is contained in:
parent
2e457e4b75
commit
1774e5674f
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -5,7 +5,7 @@
|
||||
* @link http://www.egroupware.org
|
||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @package addressbook
|
||||
* @copyright (c) 2007-10 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @copyright (c) 2007-11 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||
* @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
|
||||
*/
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
</script>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user