diff --git a/filemanager/inc/class.filemanager_hooks.inc.php b/filemanager/inc/class.filemanager_hooks.inc.php index 6f0ab19b71..5b4992969a 100644 --- a/filemanager/inc/class.filemanager_hooks.inc.php +++ b/filemanager/inc/class.filemanager_hooks.inc.php @@ -212,6 +212,35 @@ class filemanager_hooks 'forced' => 'yes', ), ); + { + $link = egw::link('/index.php','menuaction=filemanager.filemanager_merge.show_replacements'); + + $settings['default_document'] = array( + 'type' => 'input', + 'size' => 60, + 'label' => 'Default document to insert entries', + 'name' => 'default_document', + '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 data inserted.',lang('timesheet')).' '. + lang('The document can contain placeholder like {{%3}}, to be replaced with the data (%1full list of placeholder names%2).','','', 'name').' '. + lang('The following document-types are supported:'). implode(',',bo_merge::get_file_extensions()), + 'run_lang' => false, + 'xmlrpc' => True, + 'admin' => False, + ); + $settings['document_dir'] = array( + 'type' => 'input', + 'size' => 60, + 'label' => 'Directory with documents to insert entries', + 'name' => 'document_dir', + '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 %1 data inserted.', lang('timesheet')).' '. + lang('The document can contain placeholder like {{%3}}, to be replaced with the data (%1full list of placeholder names%2).','','','name').' '. + lang('The following document-types are supported:'). implode(',',bo_merge::get_file_extensions()), + 'run_lang' => false, + 'xmlrpc' => True, + 'admin' => False, + 'default' => '/templates/filemanager', + ); + } // Import / Export for nextmatch if ($GLOBALS['egw_info']['user']['apps']['importexport']) { diff --git a/filemanager/inc/class.filemanager_merge.inc.php b/filemanager/inc/class.filemanager_merge.inc.php new file mode 100644 index 0000000000..1500803c50 --- /dev/null +++ b/filemanager/inc/class.filemanager_merge.inc.php @@ -0,0 +1,188 @@ + true, + ); + + /** + * Fields that are numeric, for special numeric handling + */ + protected $numeric_fields = array( + ); + + /** + * Business object to pull records from + */ + protected $bo = null; + + /** + * Constructor + * + */ + function __construct() + { + parent::__construct(); + } + + /** + * Get replacements + * + * @param int $id id of entry + * @param string &$content=null content to create some replacements only if they are use + * @return array|boolean + */ + protected function get_replacements($id,&$content=null) + { + if (!($replacements = $this->filemanager_replacements($id, '', $content))) + { + return false; + } + return $replacements; + } + + /** + * Get filemanager replacements + * + * @param int $id id (vfs path) of entry + * @param string $prefix='' prefix like eg. 'erole' + * @return array|boolean + */ + public function filemanager_replacements($id,$prefix='', &$content = null) + { + $info = array(); + $file = egw_vfs::lstat($id,true); + + $file['mtime'] = egw_time::to($file['mtime']); + $file['ctime'] = egw_time::to($file['ctime']); + + $file['name'] = egw_vfs::basename($id); + $file['dir'] = egw_vfs::decodePath(egw_vfs::dirname($id)); + $file['path'] = $id; + $file['hsize'] = egw_vfs::hsize($file['size']); + $file['mime'] = egw_vfs::mime_content_type($id); + $file['gid'] *= -1; // our widgets use negative gid's + if (($props = egw_vfs::propfind($id))) + { + foreach($props as $prop) $file[$prop['name']] = $prop['val']; + } + if (($file['is_link'] = egw_vfs::is_link($id))) + { + $file['symlink'] = egw_vfs::readlink($id); + } + $extra = egw_vfs::getExtraInfo($id); + + // Convert to human friendly values + if($content && strpos($content, '#') !== 0) + { + $this->cf_link_to_expand($file, $content, $info); + } + + // Set any missing custom fields, or the marker will stay + foreach(config::get_customfields('filemanager') as $name => $field) + { + if(!$file['#'.$name]) $file['#'.$name] = ''; + } + + // Links + /* Not applicable to filemanager + $file['links'] = $this->get_links('filemanager', $id, '!'.egw_link::VFS_APPNAME); + $file['attachments'] = $this->get_links('filemanager', $id, egw_link::VFS_APPNAME); + $file['links_attachments'] = $this->get_links('filemanager', $id); + foreach(array_keys($GLOBALS['egw_info']['user']['apps']) as $app) + { + $file["links/{$app}"] = $this->get_links('filemanager',$id, $app); + } + */ + + // Add markers + foreach($file as $key => &$value) + { + if(!$value) $value = ''; + $info['$$'.($prefix ? $prefix.'/':'').$key.'$$'] = $value; + } + return $info; + } + + /** + * Generate table with replacements for the preferences + * + */ + public function show_replacements() + { + $GLOBALS['egw_info']['flags']['app_header'] = lang('filemanager').' - '.lang('Replacements for inserting entries into documents'); + $GLOBALS['egw_info']['flags']['nonavbar'] = false; + common::egw_header(); + + echo "\n"; + echo '"; + + $n = 0; + $fields = array( + 'name' => 'name', + 'path' => 'path', + 'url' => 'url', + 'comment' => 'comment', + 'mtime' => 'modified', + 'ctime' => 'created', + 'mime' => 'Type', + 'hsize' => 'Size', + 'size' => 'Size (in bytes)', + ); + foreach($fields as $name => $label) + { + if (!($n&1)) echo ''; + echo ''; + if ($n&1) echo "\n"; + $n++; + } + + echo '"; + foreach(config::get_customfields('filemanager') as $name => $field) + { + echo '\n"; + } + + echo '"; + 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'), + 'pagerepeat' => lang('For serial letter use this tag. Put the content, you want to repeat between two Tags.'), + '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'), + '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.'), + 'NELF' => lang('Example {{NELF role}} - if field role is not empty, you will get a new line with the value of field role'), + 'NENVLF' => lang('Example {{NELFNV role}} - if field role is not empty, set a LF without any value of the field'), + 'LETTERPREFIX' => lang('Example {{LETTERPREFIX}} - Gives a letter prefix without double spaces, if the title is empty for example'), + 'LETTERPREFIXCUSTOM' => lang('Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller'), + ) as $name => $label) + { + echo '\n"; + } + + echo "

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

{{'.$name.'}}'.lang($label).'

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

{{#'.$name.'}}'.$field['label']."

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

{{'.$name.'}}'.$label."
\n"; + + common::egw_footer(); + } +} diff --git a/filemanager/inc/class.filemanager_ui.inc.php b/filemanager/inc/class.filemanager_ui.inc.php index 4c76e4cb10..e9910afece 100644 --- a/filemanager/inc/class.filemanager_ui.inc.php +++ b/filemanager/inc/class.filemanager_ui.inc.php @@ -152,6 +152,11 @@ class filemanager_ui 'group' => $group, 'onExecute' => 'javaScript:do_clipboard', ), + 'documents' => filemanager_merge::document_action( + $GLOBALS['egw_info']['user']['preferences']['filemanager']['document_dir'], + ++$group, 'Insert in document', 'document_', + $GLOBALS['egw_info']['user']['preferences']['filemanager']['default_document'] + ), 'delete' => array( 'caption' => lang('Delete'), 'group' => ++$group, @@ -617,6 +622,10 @@ function force_download(_action, _senders) return lang('You need to select some files first!'); } $errs = $dirs = $files = 0; + + // Dialogs / options + list($action, $settings) = explode('_', $action, 2); + switch($action) { case 'mail': @@ -726,6 +735,12 @@ function force_download(_action, _senders) $ret = lang('%1 errors linking (%2)!',$errs,$ret); } return $ret." egw_vfs::symlink('$to','$path')"; + case 'document': + if (!$settings) $settings = $GLOBALS['egw_info']['user']['preferences']['filemanager']['default_document']; + $document_merge = new filemanager_merge(); + $msg = $document_merge->download($settings, $selected, '', $GLOBALS['egw_info']['user']['preferences']['filemanager']['document_dir']); + $failed = count($selected); + return false; } return "Unknown action '$action'!"; } @@ -1229,8 +1244,12 @@ function force_download(_action, _senders) 'align' => 'right', )); } +echo 'HERE'; +_debug_array($path); +_debug_array($content); if (($extra_tabs = egw_vfs::getExtraInfo($path,$content))) { +_debug_array($extra_tabs); $tabs =& $tpl->get_widget_by_name('tabs=general|perms|eacl|preview|custom'); foreach(isset($extra_tabs[0]) ? $extra_tabs : array($extra_tabs) as $extra_tab) {