Can resize and crop images in the ticketsup module

This commit is contained in:
Laurent Destailleur 2018-03-19 11:49:05 +01:00
parent f8ca4b1b5c
commit f46df6d8e5
5 changed files with 37 additions and 15 deletions

View File

@ -69,6 +69,7 @@ $object = new Commande($db);
/*
* Actions
*/
if ($object->fetch($id))
{
$object->fetch_thirdparty();

View File

@ -1226,14 +1226,14 @@ class FormFile
if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
$disablecrop=1;
if (in_array($modulepart, array('societe','product','produit','service','expensereport','holiday','project','user'))) $disablecrop=0;
if (in_array($modulepart, array('societe','product','produit','service','expensereport','holiday','project','ticketsup','user'))) $disablecrop=0;
if (! $disablecrop && image_format_supported($file['name']) > 0)
{
if ($permtoeditline)
{
// Link to resize
print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"),'resize','class="paddingrightonly"').'</a>';
print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"),'resize','class="paddingrightonly"').'</a>';
}
}

View File

@ -77,6 +77,12 @@ elseif ($modulepart == 'societe')
if (! $user->rights->societe->lire) accessforbidden();
$accessallowed=1;
}
elseif ($modulepart == 'ticketsup')
{
$result=restrictedArea($user,'ticketsup',$id,'ticketsup');
if (! $user->rights->ticketsup->read) accessforbidden();
$accessallowed=1;
}
// Security:
// Limit access if permissions are wrong
@ -154,6 +160,20 @@ elseif ($modulepart == 'expensereport')
$dir=$conf->expensereport->dir_output; // By default
}
}
elseif ($modulepart == 'ticketsup')
{
require_once DOL_DOCUMENT_ROOT.'/ticketsup/class/ticketsup.class.php';
$object = new Ticketsup($db);
if ($id > 0)
{
$result = $object->fetch($id);
if ($result <= 0) dol_print_error($db,'Failed to load object');
$dir=$conf->ticketsup->dir_output; // By default
}
}
else {
print 'Action crop for module part '.$modulepart.' is not supported yet.';
}
if (empty($backtourl))
{
@ -161,8 +181,9 @@ if (empty($backtourl))
else if (in_array($modulepart, array('expensereport'))) $backtourl=DOL_URL_ROOT."/expensereport/document.php?id=".$id.'&file='.urldecode($_POST["file"]);
else if (in_array($modulepart, array('holiday'))) $backtourl=DOL_URL_ROOT."/holiday/document.php?id=".$id.'&file='.urldecode($_POST["file"]);
else if (in_array($modulepart, array('project'))) $backtourl=DOL_URL_ROOT."/projet/document.php?id=".$id.'&file='.urldecode($_POST["file"]);
else if (in_array($modulepart, array('user'))) $backtourl=DOL_URL_ROOT."/user/document.php?id=".$id.'&file='.urldecode($_POST["file"]);
else if (in_array($modulepart, array('societe'))) $backtourl=DOL_URL_ROOT."/societe/document.php?id=".$id.'&file='.urldecode($_POST["file"]);
else if (in_array($modulepart, array('ticketsup'))) $backtourl=DOL_URL_ROOT."/ticketsup/document.php?id=".$id.'&file='.urldecode($_POST["file"]);
else if (in_array($modulepart, array('user'))) $backtourl=DOL_URL_ROOT."/user/document.php?id=".$id.'&file='.urldecode($_POST["file"]);
}

View File

@ -185,6 +185,7 @@ ToLink=Link
Select=Select
Choose=Choose
Resize=Resize
ResizeOrCrop=Resize or Crop
Recenter=Recenter
Author=Author
User=User

View File

@ -33,12 +33,10 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT . "/core/lib/company.lib.php";
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php';
$langs->load("companies");
$langs->load('other');
$langs->load("ticketsup");
$langs->loadLangs(array("companies","other","ticketsup"));
$action = GETPOST('action');
$confirm = GETPOST('confirm');
$action = GETPOST('action','alpha');
$confirm = GETPOST('confirm','alpha');
$id = GETPOST('id', 'int');
$track_id = GETPOST('track_id', 'alpha');
$ref = GETPOST('ref', 'alpha');
@ -61,7 +59,6 @@ $pagenext = $page + 1;
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "name";
}
@ -75,22 +72,22 @@ $object->ref = $object->track_id;
if ($result < 0) {
setEventMessage($object->error, 'errors');
setEventMessages($object->error, $object->errors, 'errors');
} else {
$upload_dir = $conf->ticketsup->dir_output . "/" . dol_sanitizeFileName($object->track_id);
}
/*
* Actions
*/
// Included file moved into Dolibarr 4, keep it for compatibility
$res=@include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
if (! $res) {
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php';
}
include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
$object->ref = $old_ref;
/*
* View
*/
@ -155,10 +152,12 @@ if ($object->id) {
foreach ($filearray as $key => $file) {
$totalsize += $file['size'];
}
// For compatibility we use track ID for directory
$object->ref = $object->track_id;
$modulepart = 'ticketsup';
$permission = $user->rights->ticketsup->write;
$permtoedit = $user->rights->ticketsup->write;
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';