From 5931bc4068cec7394e5d024892a7218deb3ab1e2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 14 Apr 2017 13:21:02 +0200 Subject: [PATCH] NEW Feature to crop/resize images available on user and expense reports --- htdocs/core/class/html.formfile.class.php | 5 +- htdocs/core/js/lib_photosresize.js | 1 + htdocs/core/photos_resize.php | 62 +++++++++++++++---- .../tpl/document_actions_post_headers.tpl.php | 6 ++ htdocs/user/document.php | 3 +- 5 files changed, 62 insertions(+), 15 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 56d3b5e29fb..8d90892cfb6 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -999,6 +999,7 @@ class FormFile print ''; print ''; } + print '
'; print ''."\n"; print ''; @@ -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 ''; } print "
"; - + print '
'; if (! $editline && $nboflines > 1) { if (! empty($conf->use_javascript_ajax) && $permtoeditline) { diff --git a/htdocs/core/js/lib_photosresize.js b/htdocs/core/js/lib_photosresize.js index 3463b82931f..9c4c6671b1e 100644 --- a/htdocs/core/js/lib_photosresize.js +++ b/htdocs/core/js/lib_photosresize.js @@ -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)); diff --git a/htdocs/core/photos_resize.php b/htdocs/core/photos_resize.php index 8fcd0d2b930..5b29d25202e 100644 --- a/htdocs/core/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -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 '
'; print ''.$langs->trans("Resize").''; print $langs->trans("ResizeDesc").'
'; -print $langs->trans("NewLength").': px   '.$langs->trans("or").'   '; -print $langs->trans("NewHeight").': px  
'; +print $langs->trans("NewLength").': px   '.$langs->trans("or").'   '; +print $langs->trans("NewHeight").': px  
'; print ''; print ''; @@ -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 ''."\n"; @@ -342,12 +379,12 @@ if (! empty($conf->use_javascript_ajax)) print '
'.$langs->trans("NewSizeAfterCropping").': - - - - - - + + + + + +
@@ -370,6 +407,7 @@ if (! empty($conf->use_javascript_ajax)) print '