From ae3d7865939fc8145b12704b0b18eed50d7054ca Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 3 Jun 2020 11:20:59 +0200 Subject: [PATCH] Fix crop on media file manager Conflicts: htdocs/core/ajax/ajaxdirpreview.php htdocs/core/photos_resize.php htdocs/theme/eldy/global.inc.php --- htdocs/core/ajax/ajaxdirpreview.php | 19 +++++++------ htdocs/core/class/html.formfile.class.php | 16 +++++++---- htdocs/core/photos_resize.php | 34 ++++++++++++++--------- htdocs/theme/eldy/global.inc.php | 6 ++-- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php index 83227b00e51..32d4f8d3bfa 100644 --- a/htdocs/core/ajax/ajaxdirpreview.php +++ b/htdocs/core/ajax/ajaxdirpreview.php @@ -61,15 +61,16 @@ if (!isset($mode) || $mode != 'noajax') // For ajax call $upload_dir = dirname(str_replace("../", "/", $rootdirfordoc.'/'.$file)); - $ecmdir = new EcmDirectory($db); - $result = $ecmdir->fetch($section); - if (!$result > 0) - { - //dol_print_error($db,$ecmdir->error); - //exit; - } -} -else // For no ajax call + $ecmdir = new EcmDirectory($db); + if ($section > 0) { + $result = $ecmdir->fetch($section); + if (!$result > 0) + { + //dol_print_error($db,$ecmdir->error); + //exit; + } + } +} else // For no ajax call { $rootdirfordoc = $conf->ecm->dir_output; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 0da4b2ca390..651280369a1 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1107,7 +1107,7 @@ class FormFile if ($disablecrop == -1) { $disablecrop = 1; - if (in_array($modulepart, array('bank', 'bom', 'expensereport', 'holiday', 'member', 'mrp', 'project', 'product', 'produit', 'propal', 'service', 'societe', 'tax', 'tax-vat', 'ticket', 'user'))) $disablecrop = 0; + 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; } // Define relative path used to store the file @@ -1375,11 +1375,11 @@ class FormFile // Delete or view link // ($param must start with &) print ''; - if ($useinecm == 1 || $useinecm == 5) + if ($useinecm == 1 || $useinecm == 5) // ECM manual tree { - print ''.img_edit('default', 0, 'class="paddingrightonly"').''; + print ''.img_edit('default', 0, 'class="paddingrightonly"').''; } - if (empty($useinecm) || $useinecm == 2 || $useinecm == 6) + if (empty($useinecm) || $useinecm == 2 || $useinecm == 6) // 6=Media file manager { $newmodulepart = $modulepart; if (in_array($modulepart, array('product', 'produit', 'service'))) $newmodulepart = 'produit|service'; @@ -1389,7 +1389,13 @@ class FormFile if ($permtoeditline) { // Link to resize - print ''.img_picto($langs->trans("ResizeOrCrop"), 'resize', 'class="paddingrightonly"').''; + $moreparaminurl = ''; + if ($object->id > 0) { + $moreparaminurl = '&id='.$object->id; + } elseif (GETPOST('website', 'alpha')) { + $moreparaminurl = '&website='.GETPOST('website', 'alpha'); + } + print ''.img_picto($langs->trans("ResizeOrCrop"), 'resize', 'class="paddingrightonly"').''; } } diff --git a/htdocs/core/photos_resize.php b/htdocs/core/photos_resize.php index 2686efa6419..bd480dc865e 100644 --- a/htdocs/core/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -40,7 +40,7 @@ $cancel = GETPOST('cancel', 'alpha'); $file = GETPOST('file', 'alpha'); $num = GETPOST('num', 'alpha'); // Used for document on bank statement - +$website = GETPOST('website', 'alpha'); // Security check if (empty($modulepart)) accessforbidden('Bad value for modulepart'); @@ -86,8 +86,12 @@ elseif ($modulepart == 'bank') $result = restrictedArea($user, 'banque', $id, 'bank_account'); if (!$user->rights->banque->lire) accessforbidden(); $accessallowed = 1; -} -else // ticket, holiday, expensereport, societe... +} elseif ($modulepart == 'medias') +{ + $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write); + if (!$permtoadd) accessforbidden(); + $accessallowed = 1; +} else // ticket, holiday, expensereport, societe... { $result = restrictedArea($user, $modulepart, $id, $modulepart); if (empty($user->rights->$modulepart->read) && empty($user->rights->$modulepart->lire)) accessforbidden(); @@ -224,9 +228,7 @@ elseif ($modulepart == 'bom') if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->$modulepart->dir_output; // By default } -} -elseif ($modulepart == 'mrp') -{ +} elseif ($modulepart == 'mrp') { require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php'; $object = new MO($db); if ($id > 0) @@ -235,9 +237,7 @@ elseif ($modulepart == 'mrp') if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->$modulepart->dir_output; // By default } -} -elseif ($modulepart == 'bank') -{ +} elseif ($modulepart == 'bank') { require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $object = new Account($db); if ($id > 0) @@ -246,8 +246,9 @@ elseif ($modulepart == 'bank') if ($result <= 0) dol_print_error($db, 'Failed to load object'); $dir = $conf->bank->dir_output; // By default } -} -else { +} elseif ($modulepart == 'medias') { + $dir = $dolibarr_main_data_root.'/'.$modulepart; +} else { print 'Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.'; } @@ -271,6 +272,8 @@ if (empty($backtourl)) } elseif (in_array($modulepart, array('bank'))) $backtourl = DOL_URL_ROOT."/compta/bank/document.php?id=".$id.'&file='.urldecode($file); elseif (in_array($modulepart, array('mrp'))) $backtourl = DOL_URL_ROOT."/mrp/mo_document.php?id=".$id.'&file='.urldecode($file); + elseif (in_array($modulepart, array('medias'))) $backtourl = DOL_URL_ROOT."/website/index.php?action=file_manager&website=".$website."&file=".urldecode($file).'&preopend=image'; + // Generic case that should work for everybody else else $backtourl = DOL_URL_ROOT."/".$modulepart."/".$modulepart."_document.php?id=".$id.'&file='.urldecode($file); } @@ -301,7 +304,10 @@ if ($action == 'confirm_resize' && GETPOSTISSET("file") && GETPOSTISSET("sizex") if ($result == $fullpath) { - $object->addThumbs($fullpath); + // If image is related to a given object, we create also thumbs. + if (is_object($object)) { + $object->addThumbs($fullpath); + } // Update/create database for file $fullpath $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $fullpath); @@ -371,7 +377,9 @@ if ($action == 'confirm_crop') if ($result == $fullpath) { - $object->addThumbs($fullpath); + if (is_object($object)) { + $object->addThumbs($fullpath); + } // Update/create database for file $fullpath $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $fullpath); diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 15a58295949..0ec69d4934a 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -667,10 +667,12 @@ body[class*="colorblind-"] .text-success{ color : } -.editfielda span.fa-pencil-alt, .editfielda span.fa-trash, .editfieldlang { +.editfielda span.fa-pencil-alt, .editfielda span.fa-pencil-ruler, .editfielda span.fa-trash, .editfielda span.fa-crop, +.editfieldlang { color: #ccc !important; } -.editfielda span.fa-pencil-alt:hover, .editfielda span.fa-trash:hover, .editfieldlang:hover { +.editfielda span.fa-pencil-alt:hover, .editfielda span.fa-pencil-ruler:hover, .editfielda span.fa-trash:hover, .editfielda span.fa-crop:hover, +.editfieldlang:hover { color: var(--colortexttitle) !important; } .fawidth30 {