Skip to content

Commit

Permalink
Merge tab to upload photo and other files to same tab. This reduce
Browse files Browse the repository at this point in the history
duplicate code and avoid users to be lost.
  • Loading branch information
eldy committed Jun 19, 2015
1 parent b5cc7ae commit 20da120
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 241 deletions.
13 changes: 10 additions & 3 deletions htdocs/core/class/html.formfile.class.php
Expand Up @@ -857,9 +857,16 @@ function list_of_documents($filearray,$object,$modulepart,$param='',$forcedownlo
{
if (image_format_supported($file['name']) > 0)
{
// TODO Add link from photo page here


$permtoedit=0;
if ($user->rights->produit->creer && $object->type == Product::TYPE_PRODUCT) $permtoedit=1;
if ($user->rights->service->creer && $object->type == Product::TYPE_SERVICE) $permtoedit=1;
if (empty($conf->global->MAIN_UPLOAD_DOC)) $permtoedit=0;

if ($permtoedit)
{
// Link to resize
print '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$object->id.'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension'])).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'</a> &nbsp; ';
}
}
}
if ($permtodelete)
Expand Down
8 changes: 0 additions & 8 deletions htdocs/core/js/lib_photosresize.js
Expand Up @@ -40,11 +40,3 @@ function updateCoords(c)
jQuery('#w').val(Math.ceil(c.w * ratio));
jQuery('#h').val(Math.ceil(c.h * ratio));
};

/* checkCoords */
function checkCoords()
{
if (parseInt(jQuery('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
2 changes: 2 additions & 0 deletions htdocs/core/lib/product.lib.php
Expand Up @@ -114,10 +114,12 @@ function product_prepare_head($object)
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf,$langs,$object,$head,$h,'product');

/* Merged into the Join files tab
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$object->id;
$head[$h][1] = $langs->trans("Photos");
$head[$h][2] = 'photos';
$h++;
*/

// Attachments
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
Expand Down
87 changes: 73 additions & 14 deletions htdocs/core/photos_resize.php
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2010-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Meos
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
*
Expand Down Expand Up @@ -46,6 +46,8 @@
$action=GETPOST('action','alpha');
$modulepart=GETPOST('modulepart','alpha')?GETPOST('modulepart','alpha'):'produit|service';
$original_file = isset($_REQUEST["file"])?urldecode($_REQUEST["file"]):'';
$backtourl=GETPOST('backtourl');
$cancel=GETPOST("cancel");

// Security check
if (empty($modulepart)) accessforbidden('Bad value for modulepart');
Expand Down Expand Up @@ -78,20 +80,45 @@
* Actions
*/

if ($cancel)
{
if ($backtourl)
{
header("Location: ".$backtourl);
exit;
}
else
{
header("Location: ".DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($_POST["file"]));
exit;
}
}

if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POST["sizex"]) != "") && (isset($_POST["sizey"]) != ""))
{
$fullpath=$dir."/".$original_file;
$result=dol_imageResizeOrCrop($fullpath,0,$_POST['sizex'],$_POST['sizey']);

if ($result == $fullpath)
{
header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$id.'&action=addthumb&file='.urldecode($_POST["file"]));
exit;
$object->add_thumb($fullpath);

if ($backtourl)
{
header("Location: ".$backtourl);
exit;
}
else
{
header("Location: ".DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($_POST["file"]));
exit;
}
}
else
{
$mesg=$result;
setEventMessage($result, 'errors');
$_GET['file']=$_POST["file"];
$action='';
}
}

Expand All @@ -103,13 +130,24 @@

if ($result == $fullpath)
{
header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$id.'&action=addthumb&file='.urldecode($_POST["file"]));
exit;
$object->add_thumb($fullpath);

if ($backtourl)
{
header("Location: ".$backtourl);
exit;
}
else
{
header("Location: ".DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($_POST["file"]));
exit;
}
}
else
{
$mesg=$result;
setEventMessage($result, 'errors');
$_GET['file']=$_POST["file"];
$action='';
}
}

Expand All @@ -123,8 +161,6 @@

print_fiche_titre($langs->trans("ImageEditor"));

if ($mesg) print '<div class="error">'.$mesg.'</div>';

$infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"]));
$height=$infoarray['height'];
$width=$infoarray['width'];
Expand All @@ -133,6 +169,11 @@

print '<br>'."\n";


/*
* Resize image
*/

print '<!-- Form to resize -->'."\n";
print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';

Expand All @@ -145,11 +186,15 @@
print '<input type="hidden" name="action" value="confirm_resize" />';
print '<input type="hidden" name="product" value="'.$id.'" />';
print '<input type="hidden" name="id" value="'.$id.'" />';
print '<br><input class="button" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
print '<br>';
print '<input class="button" id="submitresize" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
print '&nbsp;';
print '<input type="submit" id="cancelresize" name="cancel" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" />';
print '</fieldset>'."\n";
print '</form>';
print '<br>'."\n";


/*
* Crop image
*/
Expand All @@ -168,7 +213,7 @@
$refsizeforcrop='screenwidth';
$ratioforcrop=2;
}

print '<!-- Form to crop -->'."\n";
print '<fieldset id="redim_file">';
print '<legend>'.$langs->trans("Recenter").'</legend>';
Expand All @@ -178,7 +223,7 @@
print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&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" onsubmit="return checkCoords();">
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>
Expand All @@ -188,19 +233,33 @@
<label>W <input type="text" size="4" id="w" name="w" /></label>
<label>H <input type="text" size="4" id="h" name="h" /></label>
</div>
<input type="hidden" id="file" name="file" value="'.urlencode($original_file).'" />
<input type="hidden" id="action" name="action" value="confirm_crop" />
<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="id" value="'.$id.'" />
<br><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Recenter")).'" />
<br>
<input type="submit" id="submitcrop" name="submitcrop" class="button" value="'.dol_escape_htmltag($langs->trans("Recenter")).'" />
&nbsp;
<input type="submit" id="cancelcrop" name="cancel" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" />
</form>'."\n";
print '</fieldset>'."\n";
print '<br>';
}

/* Check that mandatory fields are filled */
print '<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
$("#submitcrop").click(function(e) {
var idClicked = e.target.id;
if (parseInt(jQuery(\'#w\').val())) return true;
alert(\''.dol_escape_js($langs->trans("ErrorFieldRequired", $langs->trans("Dimension"))).'\');
return false;
});
});
</script>';

llxFooter();
$db->close();

0 comments on commit 20da120

Please sign in to comment.