From f46df6d8e5003e1dc55880b79d52ecc029cf1db4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 Mar 2018 11:49:05 +0100 Subject: [PATCH] Can resize and crop images in the ticketsup module --- htdocs/commande/document.php | 1 + htdocs/core/class/html.formfile.class.php | 4 ++-- htdocs/core/photos_resize.php | 23 ++++++++++++++++++++++- htdocs/langs/en_US/main.lang | 1 + htdocs/ticketsup/document.php | 23 +++++++++++------------ 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php index ee688bed307..5a3f0c1973f 100644 --- a/htdocs/commande/document.php +++ b/htdocs/commande/document.php @@ -69,6 +69,7 @@ $object = new Commande($db); /* * Actions */ + if ($object->fetch($id)) { $object->fetch_thirdparty(); diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 5eef895bb0c..251a03399d7 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -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 ''.img_picto($langs->trans("Resize"),'resize','class="paddingrightonly"').''; + print ''.img_picto($langs->trans("ResizeOrCrop"),'resize','class="paddingrightonly"').''; } } diff --git a/htdocs/core/photos_resize.php b/htdocs/core/photos_resize.php index 9a11523f39b..c40a9b26c66 100644 --- a/htdocs/core/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -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"]); } diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 52dd0aba17e..2066dfa4760 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -185,6 +185,7 @@ ToLink=Link Select=Select Choose=Choose Resize=Resize +ResizeOrCrop=Resize or Crop Recenter=Recenter Author=Author User=User diff --git a/htdocs/ticketsup/document.php b/htdocs/ticketsup/document.php index a19a972c143..94348e1054c 100644 --- a/htdocs/ticketsup/document.php +++ b/htdocs/ticketsup/document.php @@ -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';