Fix crop on media file manager

This commit is contained in:
Laurent Destailleur 2020-06-03 11:20:59 +02:00
parent f92426034f
commit 8894570054
4 changed files with 43 additions and 21 deletions

View File

@ -61,13 +61,15 @@ 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;
}
$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;

View File

@ -1035,7 +1035,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
@ -1292,11 +1292,11 @@ class FormFile
// Delete or view link
// ($param must start with &)
print '<td class="valignmiddle right actionbuttons nowraponall"><!-- action on files -->';
if ($useinecm == 1 || $useinecm == 5)
if ($useinecm == 1 || $useinecm == 5) // ECM manual tree
{
print '<a href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
print '<a class="editfielda" href="'.DOL_URL_ROOT.'/ecm/file_card.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_edit('default', 0, 'class="paddingrightonly"').'</a>';
}
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';
@ -1306,7 +1306,13 @@ class FormFile
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("ResizeOrCrop")).'">'.img_picto($langs->trans("ResizeOrCrop"), 'resize', 'class="paddingrightonly"').'</a>';
$moreparaminurl = '';
if ($object->id > 0) {
$moreparaminurl = '&id='.$object->id;
} elseif (GETPOST('website', 'alpha')) {
$moreparaminurl = '&website='.GETPOST('website', 'alpha');
}
print '<a class="editfielda" href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode($newmodulepart).$moreparaminurl.'&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

@ -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');
@ -80,6 +80,11 @@ if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'serv
$result = restrictedArea($user, 'banque', $id, 'bank_account');
if (!$user->rights->banque->lire) accessforbidden();
$accessallowed = 1;
} 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);
@ -207,8 +212,7 @@ if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'serv
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)
@ -217,8 +221,7 @@ if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'serv
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)
@ -227,6 +230,8 @@ if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'serv
if ($result <= 0) dol_print_error($db, 'Failed to load object');
$dir = $conf->bank->dir_output; // By default
}
} elseif ($modulepart == 'medias') {
$dir = $dolibarr_main_data_root.'/'.$modulepart;
} else {
print 'Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.';
}
@ -250,6 +255,8 @@ if (empty($backtourl))
$backtourl = DOL_URL_ROOT."/compta/bank/account_statement_document.php?id=".$id.'&num='.urlencode($num).'&file='.urldecode($file);
} 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);
}
@ -278,7 +285,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);
@ -343,7 +353,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);

View File

@ -670,10 +670,12 @@ body[class*="colorblind-"] .text-success{
color : <?php print $textDanger; ?>
}
.editfielda span.fa-pencil-alt, .editfielda span.fa-pencil-ruler, .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-pencil-ruler: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 {