Fix crop of image on invoices.

This commit is contained in:
Laurent Destailleur 2021-01-16 15:35:15 +01:00
parent 064b00e979
commit 892bd432e4
2 changed files with 46 additions and 12 deletions

View File

@ -1042,7 +1042,8 @@ class FormFile
if ($disablecrop == -1) if ($disablecrop == -1)
{ {
$disablecrop = 1; $disablecrop = 1;
if (in_array($modulepart, array('bank', 'bom', 'expensereport', 'holiday', 'medias', 'member', 'mrp', 'project', 'product', 'produit', 'propal', 'service', 'societe', 'tax', 'tax-vat', 'ticket', 'user'))) $disablecrop = 0; // Values here must be supported by the photo_resize.php page.
if (in_array($modulepart, array('bank', 'bom', 'expensereport', 'facture', 'facture_fournisseur', 'holiday', 'medias', 'member', 'mrp', 'project', 'product', 'produit', 'propal', 'service', 'societe', 'tax', 'tax-vat', 'ticket', 'user'))) $disablecrop = 0;
} }
// Define relative path used to store the file // Define relative path used to store the file

View File

@ -42,6 +42,7 @@ $file = GETPOST('file', 'alpha');
$num = GETPOST('num', 'alpha'); // Used for document on bank statement $num = GETPOST('num', 'alpha'); // Used for document on bank statement
$website = GETPOST('website', 'alpha'); $website = GETPOST('website', 'alpha');
// Security check // Security check
if (empty($modulepart)) accessforbidden('Bad value for modulepart'); if (empty($modulepart)) accessforbidden('Bad value for modulepart');
$accessallowed = 0; $accessallowed = 0;
@ -85,6 +86,11 @@ if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'serv
$permtoadd = ($user->rights->mailing->creer || $user->rights->website->write); $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write);
if (!$permtoadd) accessforbidden(); if (!$permtoadd) accessforbidden();
$accessallowed = 1; $accessallowed = 1;
} elseif ($modulepart == 'facture_fourn' || $modulepart == 'facture_fournisseur')
{
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
if (!$user->rights->fournisseur->facture->lire) accessforbidden();
$accessallowed = 1;
} else // ticket, holiday, expensereport, societe... } else // ticket, holiday, expensereport, societe...
{ {
$result = restrictedArea($user, $modulepart, $id, $modulepart); $result = restrictedArea($user, $modulepart, $id, $modulepart);
@ -230,10 +236,28 @@ if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'serv
if ($result <= 0) dol_print_error($db, 'Failed to load object'); if ($result <= 0) dol_print_error($db, 'Failed to load object');
$dir = $conf->bank->dir_output; // By default $dir = $conf->bank->dir_output; // By default
} }
} elseif ($modulepart == 'facture') {
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$object = new Facture($db);
if ($id > 0)
{
$result = $object->fetch($id);
if ($result <= 0) dol_print_error($db, 'Failed to load object');
$dir = $conf->$modulepart->dir_output; // By default
}
} elseif ($modulepart == 'facture_fourn' || $modulepart == 'facture_fournisseur') {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
$object = new FactureFournisseur($db);
if ($id > 0)
{
$result = $object->fetch($id);
if ($result <= 0) dol_print_error($db, 'Failed to load object');
$dir = $conf->fournisseur->dir_output.'/facture'; // By default
}
} elseif ($modulepart == 'medias') { } elseif ($modulepart == 'medias') {
$dir = $dolibarr_main_data_root.'/'.$modulepart; $dir = $dolibarr_main_data_root.'/'.$modulepart;
} else { } else {
print 'Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.'; print 'Bug: Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.';
} }
if (empty($backtourl)) if (empty($backtourl))
@ -250,6 +274,8 @@ if (empty($backtourl))
elseif (in_array($modulepart, array('tax'))) $backtourl = DOL_URL_ROOT."/compta/sociales/document.php?id=".$id.'&file='.urldecode($file); elseif (in_array($modulepart, array('tax'))) $backtourl = DOL_URL_ROOT."/compta/sociales/document.php?id=".$id.'&file='.urldecode($file);
elseif (in_array($modulepart, array('ticket'))) $backtourl = DOL_URL_ROOT."/ticket/document.php?id=".$id.'&file='.urldecode($file); elseif (in_array($modulepart, array('ticket'))) $backtourl = DOL_URL_ROOT."/ticket/document.php?id=".$id.'&file='.urldecode($file);
elseif (in_array($modulepart, array('user'))) $backtourl = DOL_URL_ROOT."/user/document.php?id=".$id.'&file='.urldecode($file); elseif (in_array($modulepart, array('user'))) $backtourl = DOL_URL_ROOT."/user/document.php?id=".$id.'&file='.urldecode($file);
elseif (in_array($modulepart, array('facture'))) $backtourl = DOL_URL_ROOT."/compta/facture/document.php?id=".$id.'&file='.urldecode($file);
elseif (in_array($modulepart, array('facture_fourn', 'facture_fournisseur'))) $backtourl = DOL_URL_ROOT."/fourn/facture/document.php?id=".$id.'&file='.urldecode($file);
elseif (in_array($modulepart, array('bank')) && preg_match('/\/statement\/([^\/]+)\//', $file, $regs)) { elseif (in_array($modulepart, array('bank')) && preg_match('/\/statement\/([^\/]+)\//', $file, $regs)) {
$num = $regs[1]; $num = $regs[1];
$backtourl = DOL_URL_ROOT."/compta/bank/account_statement_document.php?id=".$id.'&num='.urlencode($num).'&file='.urldecode($file); $backtourl = DOL_URL_ROOT."/compta/bank/account_statement_document.php?id=".$id.'&num='.urlencode($num).'&file='.urldecode($file);
@ -269,10 +295,8 @@ if (empty($backtourl))
* Actions * Actions
*/ */
if ($cancel) if ($cancel) {
{ if ($backtourl) {
if ($backtourl)
{
header("Location: ".$backtourl); header("Location: ".$backtourl);
exit; exit;
} else { } else {
@ -283,6 +307,10 @@ if ($cancel)
if ($action == 'confirm_resize' && GETPOSTISSET("file") && GETPOSTISSET("sizex") && GETPOSTISSET("sizey")) if ($action == 'confirm_resize' && GETPOSTISSET("file") && GETPOSTISSET("sizex") && GETPOSTISSET("sizey"))
{ {
if (empty($dir)) {
print 'Bug: Value for $dir could not be defined.';
}
$fullpath = $dir."/".$original_file; $fullpath = $dir."/".$original_file;
$result = dol_imageResizeOrCrop($fullpath, 0, GETPOST('sizex', 'int'), GETPOST('sizey', 'int')); $result = dol_imageResizeOrCrop($fullpath, 0, GETPOST('sizex', 'int'), GETPOST('sizey', 'int'));
@ -350,9 +378,13 @@ if ($action == 'confirm_resize' && GETPOSTISSET("file") && GETPOSTISSET("sizex")
// Crop d'une image // Crop d'une image
if ($action == 'confirm_crop') if ($action == 'confirm_crop')
{ {
if (empty($dir)) {
print 'Bug: Value for $dir could not be defined.';
}
$fullpath = $dir."/".$original_file; $fullpath = $dir."/".$original_file;
//var_dump($_POST['w'].'x'.$_POST['h'].'-'.$_POST['x'].'x'.$_POST['y']);exit; //var_dump($fullpath.' '.$_POST['w'].'x'.$_POST['h'].'-'.$_POST['x'].'x'.$_POST['y']);exit;
$result = dol_imageResizeOrCrop($fullpath, 1, GETPOST('w', 'int'), GETPOST('h', 'int'), GETPOST('x', 'int'), GETPOST('y', 'int')); $result = dol_imageResizeOrCrop($fullpath, 1, GETPOST('w', 'int'), GETPOST('h', 'int'), GETPOST('x', 'int'), GETPOST('y', 'int'));
if ($result == $fullpath) if ($result == $fullpath)
@ -399,8 +431,7 @@ if ($action == 'confirm_crop')
$result = $ecmfile->create($user); $result = $ecmfile->create($user);
} }
if ($backtourl) if ($backtourl) {
{
header("Location: ".$backtourl); header("Location: ".$backtourl);
exit; exit;
} else { } else {
@ -419,10 +450,12 @@ if ($action == 'confirm_crop')
* View * View
*/ */
llxHeader($head, $langs->trans("Image"), '', '', 0, 0, array('/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js', '/core/js/lib_photosresize.js'), array('/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css')); $title= $langs->trans("ImageEditor");
llxHeader($head, $title, '', '', 0, 0, array('/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js', '/core/js/lib_photosresize.js'), array('/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css'));
print load_fiche_titre($langs->trans("ImageEditor")); print load_fiche_titre($title);
$infoarray = dol_getImageSize($dir."/".GETPOST("file", 'alpha')); $infoarray = dol_getImageSize($dir."/".GETPOST("file", 'alpha'));
$height = $infoarray['height']; $height = $infoarray['height'];