mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
* Add option to merge documents as PDF
This commit is contained in:
parent
2a4faf0137
commit
707c57ecf0
@ -725,7 +725,7 @@ export abstract class EgwApp
|
||||
framework.pushState('view');
|
||||
if(templateName)
|
||||
{
|
||||
this.et2_view.load(this.appname+'.'+templateName,templateURL, data, typeof et2_callback == 'function'?et2_callback:function(){}, app);
|
||||
this.et2_view.load(this.appname + '.' + templateName, templateURL, data, typeof et2_callback == 'function' ? et2_callback : function() {}, app);
|
||||
}
|
||||
|
||||
// define a global close function for view template
|
||||
@ -733,6 +733,49 @@ export abstract class EgwApp
|
||||
this.et2_view.close = destroy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge selected entries into template document
|
||||
*
|
||||
* @param {egwAction} _action
|
||||
* @param {egwActionObject[]} _selected
|
||||
*/
|
||||
merge(_action : egwAction, _selected : egwActionObject[])
|
||||
{
|
||||
// Find what we need
|
||||
let nm = null;
|
||||
let action = _action;
|
||||
let as_pdf = false;
|
||||
|
||||
// Find Select all
|
||||
while(nm == null && action != null)
|
||||
{
|
||||
if(action.data != null && action.data.nextmatch)
|
||||
{
|
||||
nm = action.data.nextmatch;
|
||||
}
|
||||
action = action.parent;
|
||||
}
|
||||
let all = nm?.getSelection().all || false;
|
||||
|
||||
as_pdf = action.getActionById('as_pdf')?.checked || false;
|
||||
|
||||
// Get list of entry IDs
|
||||
let ids = [];
|
||||
for(let i = 0; !all && i < _selected.length; i++)
|
||||
{
|
||||
let split = _selected[i].id.split("::");
|
||||
ids.push(split[1]);
|
||||
}
|
||||
|
||||
let vars = {
|
||||
..._action.data.merge_data,
|
||||
pdf: as_pdf,
|
||||
select_all: all,
|
||||
id: JSON.stringify(ids)
|
||||
};
|
||||
egw.open_link(egw.link('/index.php', vars), '_blank');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes actions and handlers on sidebox (delete)
|
||||
*
|
||||
@ -741,12 +784,12 @@ export abstract class EgwApp
|
||||
_init_sidebox(sidebox)
|
||||
{
|
||||
// Initialize egw tutorial sidebox, but only for non-popups, as calendar edit app.js has this.et2 set to tutorial et2 object
|
||||
if (!this.egw.is_popup())
|
||||
if(!this.egw.is_popup())
|
||||
{
|
||||
var egw_fw = egw_getFramework();
|
||||
var tutorial = jQuery('#egw_tutorial_'+this.appname+'_sidebox', egw_fw ? egw_fw.sidemenuDiv : document);
|
||||
var tutorial = jQuery('#egw_tutorial_' + this.appname + '_sidebox', egw_fw ? egw_fw.sidemenuDiv : document);
|
||||
// _init_sidebox gets currently called multiple times, which needs to be fixed
|
||||
if (tutorial.length && !this.tutorial_initialised)
|
||||
if(tutorial.length && !this.tutorial_initialised)
|
||||
{
|
||||
this.egwTutorial_init(tutorial[0]);
|
||||
this.tutorial_initialised = true;
|
||||
|
@ -16,6 +16,7 @@ namespace EGroupware\Api\Storage;
|
||||
use DOMDocument;
|
||||
use EGroupware\Api;
|
||||
use EGroupware\Api\Vfs;
|
||||
use EGroupware\Collabora\Conversion;
|
||||
use EGroupware\Stylite;
|
||||
use tidy;
|
||||
use uiaccountsel;
|
||||
@ -2115,7 +2116,6 @@ abstract class Merge
|
||||
$export_limit=null)
|
||||
{
|
||||
$documents = array();
|
||||
$editable_mimes = array();
|
||||
if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
|
||||
|
||||
try {
|
||||
@ -2200,13 +2200,6 @@ abstract class Merge
|
||||
}
|
||||
foreach($files as $file)
|
||||
{
|
||||
$edit_attributes = array(
|
||||
'menuaction' => $GLOBALS['egw_info']['flags']['currentapp'].'.'.get_called_class().'.merge_entries',
|
||||
'document' => $file['path'],
|
||||
'merge' => get_called_class(),
|
||||
'id' => '$id',
|
||||
'select_all' => '$select_all'
|
||||
);
|
||||
if (count($dircount) > 1)
|
||||
{
|
||||
$name_arr = explode('/', $file['name']);
|
||||
@ -2223,30 +2216,24 @@ abstract class Merge
|
||||
}
|
||||
switch($count)
|
||||
{
|
||||
case (count($name_arr)-1):
|
||||
$current_level[$prefix.$file['name']] = array(
|
||||
'icon' => Api\Vfs::mime_icon($file['mime']),
|
||||
'caption' => Api\Vfs::decodePath($name_arr[$count]),
|
||||
'group' => 2,
|
||||
'postSubmit' => true, // download needs post submit (not Ajax) to work,
|
||||
'target' => '_blank',
|
||||
'url' => urldecode(http_build_query($edit_attributes))
|
||||
);
|
||||
if ($file['mime'] == 'message/rfc822')
|
||||
case (count($name_arr) - 1):
|
||||
$current_level[$prefix . $file['name']];
|
||||
self::document_editable_action($current_level[$prefix . $file['name']], $file);
|
||||
if($file['mime'] == 'message/rfc822')
|
||||
{
|
||||
self::document_mail_action($current_level[$prefix.$file['name']], $file);
|
||||
self::document_mail_action($current_level[$prefix . $file['name']], $file);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if(!is_array($current_level[$prefix.$name_arr[$count]]))
|
||||
if(!is_array($current_level[$prefix . $name_arr[$count]]))
|
||||
{
|
||||
// create parent folder
|
||||
$current_level[$prefix.$name_arr[$count]] = array(
|
||||
'icon' => 'phpgwapi/foldertree_folder',
|
||||
'caption' => Api\Vfs::decodePath($name_arr[$count]),
|
||||
'group' => 2,
|
||||
'children' => array(),
|
||||
$current_level[$prefix . $name_arr[$count]] = array(
|
||||
'icon' => 'phpgwapi/foldertree_folder',
|
||||
'caption' => Api\Vfs::decodePath($name_arr[$count]),
|
||||
'group' => 2,
|
||||
'children' => array(),
|
||||
);
|
||||
}
|
||||
break;
|
||||
@ -2255,50 +2242,47 @@ abstract class Merge
|
||||
}
|
||||
else if (count($files) >= self::SHOW_DOCS_BY_MIME_LIMIT)
|
||||
{
|
||||
if (!isset($documents[$file['mime']]))
|
||||
if(!isset($documents[$file['mime']]))
|
||||
{
|
||||
$documents[$file['mime']] = array(
|
||||
'icon' => Api\Vfs::mime_icon($file['mime']),
|
||||
'caption' => Api\MimeMagic::mime2label($file['mime']),
|
||||
'group' => 2,
|
||||
'icon' => Api\Vfs::mime_icon($file['mime']),
|
||||
'caption' => Api\MimeMagic::mime2label($file['mime']),
|
||||
'group' => 2,
|
||||
'children' => array(),
|
||||
);
|
||||
}
|
||||
$documents[$file['mime']]['children'][$prefix.$file['name']] = array(
|
||||
'caption' => Api\Vfs::decodePath($file['name']),
|
||||
'target' => '_blank',
|
||||
'postSubmit' => true, // download needs post submit (not Ajax) to work
|
||||
);
|
||||
$documents[$file['mime']]['children'][$prefix.$file['name']]['url'] = urldecode(http_build_query($edit_attributes));
|
||||
if ($file['mime'] == 'message/rfc822')
|
||||
$documents[$file['mime']]['children'][$prefix . $file['name']] = array();
|
||||
self::document_editable_action($documents[$file['mime']]['children'][$prefix . $file['name']], $file);
|
||||
if($file['mime'] == 'message/rfc822')
|
||||
{
|
||||
self::document_mail_action($documents[$file['mime']]['children'][$prefix.$file['name']], $file);
|
||||
self::document_mail_action($documents[$file['mime']]['children'][$prefix . $file['name']], $file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$documents[$prefix.$file['name']] = array(
|
||||
'icon' => Api\Vfs::mime_icon($file['mime']),
|
||||
'caption' => Api\Vfs::decodePath($file['name']),
|
||||
'group' => 2,
|
||||
'target' => '_blank'
|
||||
);
|
||||
$documents[$prefix.$file['name']]['url'] = urldecode(http_build_query($edit_attributes));
|
||||
if ($file['mime'] == 'message/rfc822')
|
||||
$documents[$prefix . $file['name']] = array();
|
||||
self::document_editable_action($documents[$prefix . $file['name']], $file);
|
||||
if($file['mime'] == 'message/rfc822')
|
||||
{
|
||||
self::document_mail_action($documents[$prefix.$file['name']], $file);
|
||||
self::document_mail_action($documents[$prefix . $file['name']], $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add PDF checkbox
|
||||
$documents['as_pdf'] = array(
|
||||
'caption' => 'As PDF',
|
||||
'checkbox' => true,
|
||||
);
|
||||
return array(
|
||||
'icon' => 'etemplate/merge',
|
||||
'caption' => $caption,
|
||||
'children' => $documents,
|
||||
'icon' => 'etemplate/merge',
|
||||
'caption' => $caption,
|
||||
'children' => $documents,
|
||||
// disable action if no document or export completly forbidden for non-admins
|
||||
'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit,'ISALLOWED') || self::is_export_limit_excepted()),
|
||||
'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed
|
||||
'group' => $group,
|
||||
'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit, 'ISALLOWED') || self::is_export_limit_excepted()),
|
||||
'hideOnDisabled' => true,
|
||||
// do not show 'Insert in document', if no documents defined or no export allowed
|
||||
'group' => $group,
|
||||
);
|
||||
}
|
||||
|
||||
@ -2348,15 +2332,24 @@ abstract class Merge
|
||||
*/
|
||||
private static function document_editable_action(Array &$action, $file)
|
||||
{
|
||||
unset($action['postSubmit']);
|
||||
$edit_attributes = array(
|
||||
'menuaction' => 'collabora.EGroupware\\collabora\\Ui.merge_edit',
|
||||
'document' => $file['path'],
|
||||
'merge' => get_called_class(),
|
||||
'id' => '$id',
|
||||
'select_all' => '$select_all'
|
||||
static $action_base = array(
|
||||
// The same for every file
|
||||
'group' => 2,
|
||||
// Overwritten for every file
|
||||
'icon' => '', //Api\Vfs::mime_icon($file['mime']),
|
||||
'caption' => '', //Api\Vfs::decodePath($name_arr[$count]),
|
||||
);
|
||||
$action['url'] = urldecode(http_build_query($edit_attributes));
|
||||
$edit_attributes = array(
|
||||
'menuaction' => $GLOBALS['egw_info']['flags']['currentapp'] . '.' . get_called_class() . '.merge_entries',
|
||||
'document' => $file['path'],
|
||||
'merge' => get_called_class(),
|
||||
);
|
||||
$action = array_merge($action_base, $action, array(
|
||||
'icon' => Api\Vfs::mime_icon($file['mime']),
|
||||
'caption' => Api\Vfs::decodePath($file['name']),
|
||||
'onExecute' => 'javaScript:app.' . $GLOBALS['egw_info']['flags']['currentapp'] . '.merge',
|
||||
'merge_data' => $edit_attributes
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2397,18 +2390,19 @@ abstract class Merge
|
||||
* Merge the selected IDs into the given document, save it to the VFS, then
|
||||
* either open it in the editor or have the browser download the file.
|
||||
*
|
||||
* @param String[]|null $ids Allows extending classes to process IDs in their own way. Leave null to pull from request.
|
||||
* @param string[]|null $ids Allows extending classes to process IDs in their own way. Leave null to pull from request.
|
||||
* @param Merge|null $document_merge Already instantiated Merge object to do the merge.
|
||||
* @param boolean|null $pdf Convert result to PDF
|
||||
* @throws Api\Exception
|
||||
* @throws Api\Exception\AssertionFailed
|
||||
*/
|
||||
public static function merge_entries(array $ids = null, Merge &$document_merge = null)
|
||||
public static function merge_entries(array $ids = null, Merge &$document_merge = null, $pdf = null)
|
||||
{
|
||||
if (is_null($document_merge) && class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
|
||||
if(is_null($document_merge) && class_exists($_REQUEST['merge']) && is_subclass_of($_REQUEST['merge'], 'EGroupware\\Api\\Storage\\Merge'))
|
||||
{
|
||||
$document_merge = new $_REQUEST['merge']();
|
||||
}
|
||||
elseif (is_null($document_merge))
|
||||
elseif(is_null($document_merge))
|
||||
{
|
||||
$document_merge = new Api\Contacts\Merge();
|
||||
}
|
||||
@ -2428,12 +2422,17 @@ abstract class Merge
|
||||
$ids = self::get_all_ids($document_merge);
|
||||
}
|
||||
|
||||
if(is_null($pdf))
|
||||
{
|
||||
$pdf = (boolean)$_REQUEST['pdf'];
|
||||
}
|
||||
|
||||
$filename = $document_merge->get_filename($_REQUEST['document']);
|
||||
$result = $document_merge->merge_file($_REQUEST['document'], $ids, $filename, '', $header);
|
||||
|
||||
if(!is_file($result) || !is_readable($result))
|
||||
{
|
||||
throw new Api\Exception\AssertionFailed("Unable to generate merge file\n". $result);
|
||||
throw new Api\Exception\AssertionFailed("Unable to generate merge file\n" . $result);
|
||||
}
|
||||
// Put it into the vfs using user's configured home dir if writable,
|
||||
// or expected home dir (/home/username) if not
|
||||
@ -2462,11 +2461,20 @@ abstract class Merge
|
||||
// ignore failed discovery
|
||||
unset($e);
|
||||
}
|
||||
if($editable_mimes[Vfs::mime_content_type($target)])
|
||||
|
||||
// PDF conversion
|
||||
if($editable_mimes[Vfs::mime_content_type($target)] && $pdf)
|
||||
{
|
||||
$error = '';
|
||||
$convert = new Conversion();
|
||||
$convert->convert($target, $target, 'pdf', $error);
|
||||
}
|
||||
if($editable_mimes[Vfs::mime_content_type($target)] &&
|
||||
!in_array(Vfs::mime_content_type($target), explode(',', $GLOBALS['egw_info']['user']['preferences']['filemanager']['collab_excluded_mimes'])))
|
||||
{
|
||||
\Egroupware\Api\Egw::redirect_link('/index.php', array(
|
||||
'menuaction' => 'collabora.EGroupware\\Collabora\\Ui.editor',
|
||||
'path'=> $target
|
||||
'path' => $target
|
||||
));
|
||||
}
|
||||
else
|
||||
|
@ -2396,14 +2396,15 @@ class Vfs extends Vfs\Base
|
||||
*/
|
||||
static function make_unique($path)
|
||||
{
|
||||
$filename = Vfs::basename($path);
|
||||
$dupe_count = 0;
|
||||
while(is_file(Vfs::PREFIX . $path))
|
||||
{
|
||||
$dupe_count++;
|
||||
$path = Vfs::dirname($path) . '/' .
|
||||
pathinfo($path, PATHINFO_FILENAME) .
|
||||
pathinfo($filename, PATHINFO_FILENAME) .
|
||||
' (' . ($dupe_count + 1) . ')' . '.' .
|
||||
pathinfo($path, PATHINFO_EXTENSION);
|
||||
pathinfo($filename, PATHINFO_EXTENSION);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user