mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-28 17:48:56 +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');
|
framework.pushState('view');
|
||||||
if(templateName)
|
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
|
// define a global close function for view template
|
||||||
@ -733,6 +733,49 @@ export abstract class EgwApp
|
|||||||
this.et2_view.close = destroy;
|
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)
|
* Initializes actions and handlers on sidebox (delete)
|
||||||
*
|
*
|
||||||
@ -741,12 +784,12 @@ export abstract class EgwApp
|
|||||||
_init_sidebox(sidebox)
|
_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
|
// 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 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
|
// _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.egwTutorial_init(tutorial[0]);
|
||||||
this.tutorial_initialised = true;
|
this.tutorial_initialised = true;
|
||||||
|
@ -16,6 +16,7 @@ namespace EGroupware\Api\Storage;
|
|||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use EGroupware\Api;
|
use EGroupware\Api;
|
||||||
use EGroupware\Api\Vfs;
|
use EGroupware\Api\Vfs;
|
||||||
|
use EGroupware\Collabora\Conversion;
|
||||||
use EGroupware\Stylite;
|
use EGroupware\Stylite;
|
||||||
use tidy;
|
use tidy;
|
||||||
use uiaccountsel;
|
use uiaccountsel;
|
||||||
@ -2115,7 +2116,6 @@ abstract class Merge
|
|||||||
$export_limit=null)
|
$export_limit=null)
|
||||||
{
|
{
|
||||||
$documents = array();
|
$documents = array();
|
||||||
$editable_mimes = array();
|
|
||||||
if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
|
if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -2200,13 +2200,6 @@ abstract class Merge
|
|||||||
}
|
}
|
||||||
foreach($files as $file)
|
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)
|
if (count($dircount) > 1)
|
||||||
{
|
{
|
||||||
$name_arr = explode('/', $file['name']);
|
$name_arr = explode('/', $file['name']);
|
||||||
@ -2223,26 +2216,20 @@ abstract class Merge
|
|||||||
}
|
}
|
||||||
switch($count)
|
switch($count)
|
||||||
{
|
{
|
||||||
case (count($name_arr)-1):
|
case (count($name_arr) - 1):
|
||||||
$current_level[$prefix.$file['name']] = array(
|
$current_level[$prefix . $file['name']];
|
||||||
'icon' => Api\Vfs::mime_icon($file['mime']),
|
self::document_editable_action($current_level[$prefix . $file['name']], $file);
|
||||||
'caption' => Api\Vfs::decodePath($name_arr[$count]),
|
if($file['mime'] == 'message/rfc822')
|
||||||
'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')
|
|
||||||
{
|
{
|
||||||
self::document_mail_action($current_level[$prefix.$file['name']], $file);
|
self::document_mail_action($current_level[$prefix . $file['name']], $file);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if(!is_array($current_level[$prefix.$name_arr[$count]]))
|
if(!is_array($current_level[$prefix . $name_arr[$count]]))
|
||||||
{
|
{
|
||||||
// create parent folder
|
// create parent folder
|
||||||
$current_level[$prefix.$name_arr[$count]] = array(
|
$current_level[$prefix . $name_arr[$count]] = array(
|
||||||
'icon' => 'phpgwapi/foldertree_folder',
|
'icon' => 'phpgwapi/foldertree_folder',
|
||||||
'caption' => Api\Vfs::decodePath($name_arr[$count]),
|
'caption' => Api\Vfs::decodePath($name_arr[$count]),
|
||||||
'group' => 2,
|
'group' => 2,
|
||||||
@ -2255,7 +2242,7 @@ abstract class Merge
|
|||||||
}
|
}
|
||||||
else if (count($files) >= self::SHOW_DOCS_BY_MIME_LIMIT)
|
else if (count($files) >= self::SHOW_DOCS_BY_MIME_LIMIT)
|
||||||
{
|
{
|
||||||
if (!isset($documents[$file['mime']]))
|
if(!isset($documents[$file['mime']]))
|
||||||
{
|
{
|
||||||
$documents[$file['mime']] = array(
|
$documents[$file['mime']] = array(
|
||||||
'icon' => Api\Vfs::mime_icon($file['mime']),
|
'icon' => Api\Vfs::mime_icon($file['mime']),
|
||||||
@ -2264,40 +2251,37 @@ abstract class Merge
|
|||||||
'children' => array(),
|
'children' => array(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$documents[$file['mime']]['children'][$prefix.$file['name']] = array(
|
$documents[$file['mime']]['children'][$prefix . $file['name']] = array();
|
||||||
'caption' => Api\Vfs::decodePath($file['name']),
|
self::document_editable_action($documents[$file['mime']]['children'][$prefix . $file['name']], $file);
|
||||||
'target' => '_blank',
|
if($file['mime'] == 'message/rfc822')
|
||||||
'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')
|
|
||||||
{
|
{
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
$documents[$prefix.$file['name']] = array(
|
$documents[$prefix . $file['name']] = array();
|
||||||
'icon' => Api\Vfs::mime_icon($file['mime']),
|
self::document_editable_action($documents[$prefix . $file['name']], $file);
|
||||||
'caption' => Api\Vfs::decodePath($file['name']),
|
if($file['mime'] == 'message/rfc822')
|
||||||
'group' => 2,
|
|
||||||
'target' => '_blank'
|
|
||||||
);
|
|
||||||
$documents[$prefix.$file['name']]['url'] = urldecode(http_build_query($edit_attributes));
|
|
||||||
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(
|
return array(
|
||||||
'icon' => 'etemplate/merge',
|
'icon' => 'etemplate/merge',
|
||||||
'caption' => $caption,
|
'caption' => $caption,
|
||||||
'children' => $documents,
|
'children' => $documents,
|
||||||
// disable action if no document or export completly forbidden for non-admins
|
// 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()),
|
'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
|
'hideOnDisabled' => true,
|
||||||
|
// do not show 'Insert in document', if no documents defined or no export allowed
|
||||||
'group' => $group,
|
'group' => $group,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -2348,15 +2332,24 @@ abstract class Merge
|
|||||||
*/
|
*/
|
||||||
private static function document_editable_action(Array &$action, $file)
|
private static function document_editable_action(Array &$action, $file)
|
||||||
{
|
{
|
||||||
unset($action['postSubmit']);
|
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]),
|
||||||
|
);
|
||||||
$edit_attributes = array(
|
$edit_attributes = array(
|
||||||
'menuaction' => 'collabora.EGroupware\\collabora\\Ui.merge_edit',
|
'menuaction' => $GLOBALS['egw_info']['flags']['currentapp'] . '.' . get_called_class() . '.merge_entries',
|
||||||
'document' => $file['path'],
|
'document' => $file['path'],
|
||||||
'merge' => get_called_class(),
|
'merge' => get_called_class(),
|
||||||
'id' => '$id',
|
|
||||||
'select_all' => '$select_all'
|
|
||||||
);
|
);
|
||||||
$action['url'] = urldecode(http_build_query($edit_attributes));
|
$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
|
* 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.
|
* 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 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
|
||||||
* @throws Api\Exception\AssertionFailed
|
* @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']();
|
$document_merge = new $_REQUEST['merge']();
|
||||||
}
|
}
|
||||||
elseif (is_null($document_merge))
|
elseif(is_null($document_merge))
|
||||||
{
|
{
|
||||||
$document_merge = new Api\Contacts\Merge();
|
$document_merge = new Api\Contacts\Merge();
|
||||||
}
|
}
|
||||||
@ -2428,12 +2422,17 @@ abstract class Merge
|
|||||||
$ids = self::get_all_ids($document_merge);
|
$ids = self::get_all_ids($document_merge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(is_null($pdf))
|
||||||
|
{
|
||||||
|
$pdf = (boolean)$_REQUEST['pdf'];
|
||||||
|
}
|
||||||
|
|
||||||
$filename = $document_merge->get_filename($_REQUEST['document']);
|
$filename = $document_merge->get_filename($_REQUEST['document']);
|
||||||
$result = $document_merge->merge_file($_REQUEST['document'], $ids, $filename, '', $header);
|
$result = $document_merge->merge_file($_REQUEST['document'], $ids, $filename, '', $header);
|
||||||
|
|
||||||
if(!is_file($result) || !is_readable($result))
|
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,
|
// Put it into the vfs using user's configured home dir if writable,
|
||||||
// or expected home dir (/home/username) if not
|
// or expected home dir (/home/username) if not
|
||||||
@ -2462,11 +2461,20 @@ abstract class Merge
|
|||||||
// ignore failed discovery
|
// ignore failed discovery
|
||||||
unset($e);
|
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(
|
\Egroupware\Api\Egw::redirect_link('/index.php', array(
|
||||||
'menuaction' => 'collabora.EGroupware\\Collabora\\Ui.editor',
|
'menuaction' => 'collabora.EGroupware\\Collabora\\Ui.editor',
|
||||||
'path'=> $target
|
'path' => $target
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2396,14 +2396,15 @@ class Vfs extends Vfs\Base
|
|||||||
*/
|
*/
|
||||||
static function make_unique($path)
|
static function make_unique($path)
|
||||||
{
|
{
|
||||||
|
$filename = Vfs::basename($path);
|
||||||
$dupe_count = 0;
|
$dupe_count = 0;
|
||||||
while(is_file(Vfs::PREFIX . $path))
|
while(is_file(Vfs::PREFIX . $path))
|
||||||
{
|
{
|
||||||
$dupe_count++;
|
$dupe_count++;
|
||||||
$path = Vfs::dirname($path) . '/' .
|
$path = Vfs::dirname($path) . '/' .
|
||||||
pathinfo($path, PATHINFO_FILENAME) .
|
pathinfo($filename, PATHINFO_FILENAME) .
|
||||||
' (' . ($dupe_count + 1) . ')' . '.' .
|
' (' . ($dupe_count + 1) . ')' . '.' .
|
||||||
pathinfo($path, PATHINFO_EXTENSION);
|
pathinfo($filename, PATHINFO_EXTENSION);
|
||||||
}
|
}
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user