NEW Feature to crop/resize images available on user and expense reports

This commit is contained in:
Laurent Destailleur 2017-04-14 13:21:02 +02:00
parent 846204bdb4
commit 5931bc4068
5 changed files with 62 additions and 15 deletions

View File

@ -999,6 +999,7 @@ class FormFile
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="modulepart" value="'.$modulepart.'">';
}
print '<div class="div-table-responsive-no-min">';
print '<table width="100%" id="tablelines" class="'.($useinecm?'liste noborder':'liste').'">'."\n";
print '<tr class="liste_titre nodrag nodrop">';
@ -1182,7 +1183,7 @@ class FormFile
if (in_array($modulepart, array('product','produit','service'))) $newmodulepart='produit|service';
$disablecrop=1;
if (in_array($modulepart, array('product','produit','service','holiday','project'))) $disablecrop=0;
if (in_array($modulepart, array('product','produit','service','expensereport','holiday','project','user'))) $disablecrop=0;
if (! $disablecrop && image_format_supported($file['name']) > 0)
{
@ -1256,7 +1257,7 @@ class FormFile
print '</td></tr>';
}
print "</table>";
print '</div>';
if (! $editline && $nboflines > 1) {
if (! empty($conf->use_javascript_ajax) && $permtoeditline) {

View File

@ -33,6 +33,7 @@ function updateCoords(c)
//alert(parseInt(jQuery("#ratioforcrop").val()));
ratio=1;
if (parseInt(jQuery("#ratioforcrop").val()) > 0) ratio = parseInt(jQuery("#ratioforcrop").val());
//console.log(ratio);
jQuery('#x').val(Math.ceil(c.x * ratio));
jQuery('#y').val(Math.ceil(c.y * ratio));
jQuery('#x2').val(Math.ceil(c.x2 * ratio));

View File

@ -59,6 +59,18 @@ elseif ($modulepart == 'holiday')
if (! $user->rights->holiday->read) accessforbidden();
$accessallowed=1;
}
elseif ($modulepart == 'expensereport')
{
$result=restrictedArea($user,'expensereport',$id,'expensereport');
if (! $user->rights->expensereport->lire) accessforbidden();
$accessallowed=1;
}
elseif ($modulepart == 'user')
{
$result=restrictedArea($user,'user',$id,'user');
if (! $user->rights->user->user->lire) accessforbidden();
$accessallowed=1;
}
// Security:
// Limit access if permissions are wrong
@ -103,12 +115,36 @@ elseif ($modulepart == 'holiday')
$dir=$conf->holiday->dir_output; // By default
}
}
elseif ($modulepart == 'user')
{
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
$object = new User($db);
if ($id > 0)
{
$result = $object->fetch($id);
if ($result <= 0) dol_print_error($db,'Failed to load object');
$dir=$conf->user->dir_output; // By default
}
}
elseif ($modulepart == 'expensereport')
{
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
$object = new ExpenseReport($db);
if ($id > 0)
{
$result = $object->fetch($id);
if ($result <= 0) dol_print_error($db,'Failed to load object');
$dir=$conf->expensereport->dir_output; // By default
}
}
if (empty($backtourl))
{
if (in_array($modulepart, array('product','produit','service','produit|service'))) $backtourl=DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($_POST["file"]);
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"]);
}
@ -185,7 +221,7 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS
}
else
{
dol_print_error('', 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
dol_print_error('', 'confirm_resize on photo_resize without backtourl defined for modulepart='.$modulepart);
exit;
}
}
@ -253,7 +289,7 @@ if ($action == 'confirm_crop')
}
else
{
dol_print_error('', 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
dol_print_error('', 'confirm_crop on photo_resize without backtourl defined for modulepart='.$modulepart);
exit;
}
}
@ -294,8 +330,8 @@ print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" meth
print '<fieldset id="redim_file">';
print '<legend>'.$langs->trans("Resize").'</legend>';
print $langs->trans("ResizeDesc").'<br>';
print $langs->trans("NewLength").': <input class="flat" name="sizex" size="10" type="text" > px &nbsp; '.$langs->trans("or").' &nbsp; ';
print $langs->trans("NewHeight").': <input class="flat" name="sizey" size="10" type="text" > px &nbsp; <br>';
print $langs->trans("NewLength").': <input name="sizex" type="number" class="flat maxwidth50"> px &nbsp; '.$langs->trans("or").' &nbsp; ';
print $langs->trans("NewHeight").': <input name="sizey" type="number" class="flat maxwidth50"> px &nbsp; <br>';
print '<input type="hidden" name="file" value="'.dol_escape_htmltag(GETPOST('file')).'" />';
print '<input type="hidden" name="action" value="confirm_resize" />';
@ -323,11 +359,12 @@ if (! empty($conf->use_javascript_ajax))
$height=$infoarray['height'];
$width=$infoarray['width'];
$widthforcrop=$width; $refsizeforcrop='orig'; $ratioforcrop=1;
// If image is too large, we use another scale.
if (! empty($_SESSION['dol_screenwidth']) && ($widthforcrop > round($_SESSION['dol_screenwidth']/2)))
{
$widthforcrop=min(round($_SESSION['dol_screenwidth']/2),$widthforcrop);
$widthforcrop=round($_SESSION['dol_screenwidth']/2);
$refsizeforcrop='screenwidth';
$ratioforcrop=2;
$ratioforcrop=1;
}
print '<!-- Form to crop -->'."\n";
@ -342,12 +379,12 @@ if (! empty($conf->use_javascript_ajax))
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">
<div class="jc_coords">
'.$langs->trans("NewSizeAfterCropping").':
<label>X1 <input type="text" size="4" id="x" name="x" /></label>
<label>Y1 <input type="text" size="4" id="y" name="y" /></label>
<label>X2 <input type="text" size="4" id="x2" name="x2" /></label>
<label>Y2 <input type="text" size="4" id="y2" name="y2" /></label>
<label>W <input type="text" size="4" id="w" name="w" /></label>
<label>H <input type="text" size="4" id="h" name="h" /></label>
<label>X1 <input type="number" class="flat maxwidth50" id="x" name="x" /></label>
<label>Y1 <input type="number" class="flat maxwidth50" id="y" name="y" /></label>
<label>X2 <input type="number" class="flat maxwidth50" id="x2" name="x2" /></label>
<label>Y2 <input type="number" class="flat maxwidth50" id="y2" name="y2" /></label>
<label>W <input type="number" class="flat maxwidth50" id="w" name="w" /></label>
<label>H <input type="number" class="flat maxwidth50" id="h" name="h" /></label>
</div>
<input type="hidden" id="file" name="file" value="'.dol_escape_htmltag($original_file).'" />
@ -370,6 +407,7 @@ if (! empty($conf->use_javascript_ajax))
print '<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
$("#submitcrop").click(function(e) {
console.log("We click on submitcrop");
var idClicked = e.target.id;
if (parseInt(jQuery(\'#w\').val())) return true;
alert(\''.dol_escape_js($langs->trans("ErrorFieldRequired", $langs->trans("Dimension"))).'\');

View File

@ -18,6 +18,12 @@
* or see http://www.gnu.org/
*/
// Following var can be set
// $permission = permission or not to add a file
// $permtoedit = permission or not to edit file name, crop file
// $modulepart = for download
// $param = param to add to download links
$langs->load("link");
if (empty($relativepathwithnofile)) $relativepathwithnofile='';
if (empty($permtoedit)) $permtoedit=-1;

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
@ -166,6 +166,7 @@ if ($object->id)
$modulepart = 'user';
$permission = $user->rights->user->user->creer;
$permtoedit = $user->rights->user->user->creer;
$param = '&id=' . $object->id;
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
}