NEW Function "crop" images available on project, product and holiday

attachment tab.
This commit is contained in:
Laurent Destailleur 2016-10-28 19:42:04 +02:00
parent f1ec2c04ed
commit 4f5c5a2b0e
2 changed files with 38 additions and 13 deletions

View File

@ -1029,7 +1029,7 @@ class FormFile
{
// Delete or view link
// ($param must start with &)
print '<td class="valignmiddle right">';
print '<td class="valignmiddle right"><!-- action on files -->';
if ($useinecm)
{
print '<a href="'.DOL_URL_ROOT.'/ecm/docfile.php?urlfile='.urlencode($file['name']).$param.'" class="editfilelink" rel="'.urlencode($file['name']).'">'.img_view('default', 0, 'class="paddingrightonly"').'</a>';
@ -1039,10 +1039,10 @@ class FormFile
$newmodulepart=$modulepart;
if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
$disablecrop=0;
if ($modulepart == 'expensereport') $disablecrop=1; // TODO Remove this in future
$disablecrop=1;
if (in_array($modulepart, array('product','produit','service','holiday','project'))) $disablecrop=0;
if (image_format_supported($file['name']) > 0 && ! $disablecrop)
if (! $disablecrop && image_format_supported($file['name']) > 0)
{
if ($permtoeditline)
{

View File

@ -46,14 +46,19 @@ if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'serv
if ($modulepart=='produit|service' && (! $user->rights->produit->lire && ! $user->rights->service->lire)) accessforbidden();
$accessallowed=1;
}
elseif ($modulepart == 'project')
{
$result=restrictedArea($user,'projet',$id);
if (! $user->rights->projet->lire) accessforbidden();
$accessallowed=1;
}
elseif ($modulepart == 'holiday')
{
$result=restrictedArea($user,'holiday',$id,'holiday');
if ($modulepart=='holiday' && (! $user->rights->holiday->read)) accessforbidden();
if (! $user->rights->holiday->read) accessforbidden();
$accessallowed=1;
}
// Security:
// Limit access if permissions are wrong
if (! $accessallowed)
@ -75,6 +80,17 @@ if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'serv
if ($object->type == Product::TYPE_SERVICE) $dir=$conf->service->multidir_output[$object->entity];
}
}
elseif ($modulepart == 'project')
{
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
$object = new Project($db);
if ($id > 0)
{
$result = $object->fetch($id);
if ($result <= 0) dol_print_error($db,'Failed to load object');
$dir=$conf->projet->dir_output; // By default
}
}
elseif ($modulepart == 'holiday')
{
require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
@ -87,6 +103,13 @@ elseif ($modulepart == 'holiday')
}
}
if (empty($backtourl))
{
if (in_array($modulepart, array('product','produit','service'))) $backtourl=DOL_URL_ROOT."/product/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"]);
}
/*
* Actions
@ -101,8 +124,8 @@ if ($cancel)
}
else
{
header("Location: ".DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($_POST["file"]));
exit;
dol_print_error('', 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
exit;
}
}
@ -122,8 +145,8 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS
}
else
{
header("Location: ".DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($_POST["file"]));
exit;
dol_print_error('', 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
exit;
}
}
else
@ -151,8 +174,8 @@ if ($action == 'confirm_crop')
}
else
{
header("Location: ".DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($_POST["file"]));
exit;
dol_print_error('', 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
exit;
}
}
else
@ -197,6 +220,7 @@ print $langs->trans("NewHeight").': <input class="flat" name="sizey" size="10" t
print '<input type="hidden" name="file" value="'.$_GET['file'].'" />';
print '<input type="hidden" name="action" value="confirm_resize" />';
print '<input type="hidden" name="product" value="'.$id.'" />';
print '<input type="hidden" name="modulepart" value="'.$modulepart.'" />';
print '<input type="hidden" name="id" value="'.$id.'" />';
print '<br>';
print '<input class="button" id="submitresize" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
@ -232,7 +256,7 @@ if (! empty($conf->use_javascript_ajax))
print $langs->trans("DefineNewAreaToPick").'...<br>';
print '<br><div class="center">';
print '<div style="border: 1px solid #888888; width: '.$widthforcrop.'px;">';
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&entity='.$object->entity.'&file='.$original_file.'" alt="" id="cropbox" width="'.$widthforcrop.'px"/>';
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$object->entity.'&file='.$original_file.'" alt="" id="cropbox" width="'.$widthforcrop.'px"/>';
print '</div>';
print '</div><br>';
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">
@ -251,6 +275,7 @@ if (! empty($conf->use_javascript_ajax))
<input type="hidden" id="product" name="product" value="'.$id.'" />
<input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.'" />
<input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.'" />
<input type="hidden" name="modulepart" value="'.$modulepart.'" />
<input type="hidden" name="id" value="'.$id.'" />
<br>
<input type="submit" id="submitcrop" name="submitcrop" class="button" value="'.dol_escape_htmltag($langs->trans("Recenter")).'" />