* Copyright (C) 2009 Meos * Copyright (C) 2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/core/photos_resize.php * \ingroup core * \brief File of page to resize photos */ //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); //if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $langs->load("products"); $langs->load("other"); $id=GETPOST('id','int'); $action=GETPOST('action','alpha'); $modulepart=GETPOST('modulepart','alpha')?GETPOST('modulepart','alpha'):'produit|service'; $original_file = isset($_REQUEST["file"])?urldecode($_REQUEST["file"]):''; // Security check if (empty($modulepart)) accessforbidden('Bad value for modulepart'); $accessallowed=0; if ($modulepart=='produit|service') { $result=restrictedArea($user,'produit|service',$id,'product&product'); if ($modulepart=='produit|service' && (! $user->rights->produit->lire && ! $user->rights->service->lire)) accessforbidden(); $accessallowed=1; } // Security: // Limit access if permissions are wrong if (! $accessallowed) { accessforbidden(); } $object = new Product($db); if ($id > 0) { $result = $object->fetch($id); if ($result <= 0) dol_print_error($db,'Failed to load object'); $dir=$conf->product->multidir_output[$object->entity]; // By default if ($object->type == 0) $dir=$conf->product->multidir_output[$object->entity]; if ($object->type == 1) $dir=$conf->service->multidir_output[$object->entity]; } /* * Actions */ 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; } else { $mesg=$result; $_GET['file']=$_POST["file"]; } } // Crop d'une image if ($action == 'confirm_crop') { $fullpath=$dir."/".$original_file; $result=dol_imageResizeOrCrop($fullpath,1,$_POST['w'],$_POST['h'],$_POST['x'],$_POST['y']); if ($result == $fullpath) { header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$id.'&action=addthumb&file='.urldecode($_POST["file"])); exit; } else { $mesg=$result; $_GET['file']=$_POST["file"]; } } /* * View */ llxHeader($head, $langs->trans("Image"), '', '', 0, 0, array('/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js','/core/js/lib_photosresize.js'), array('/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css')); print_fiche_titre($langs->trans("ImageEditor")); if ($mesg) print '
'.$mesg.'
'; $infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); $height=$infoarray['height']; $width=$infoarray['width']; print $langs->trans("CurrentInformationOnImage").': '; print $langs->trans("Width").': '.$width.' x '.$langs->trans("Height").': '.$height.'
'; print '
'."\n"; print ''."\n"; print '
'; print '
'; print ''.$langs->trans("Resize").''; print $langs->trans("ResizeDesc").'
'; print $langs->trans("NewLength").': px   '.$langs->trans("or").'   '; print $langs->trans("NewHeight").': px  
'; print ''; print ''; print ''; print ''; print '
'; print '
'."\n"; print '
'; print '
'."\n"; /* * Crop image */ print '
'."\n"; if (! empty($conf->use_javascript_ajax)) { $infoarray=dol_getImageSize($dir."/".urldecode($_GET["file"])); $height=$infoarray['height']; $width=$infoarray['width']; $widthforcrop=$width; $refsizeforcrop='orig'; $ratioforcrop=1; if (! empty($_SESSION['dol_screenwidth']) && ($widthforcrop > round($_SESSION['dol_screenwidth']/2))) { $widthforcrop=min(round($_SESSION['dol_screenwidth']/2),$widthforcrop); $refsizeforcrop='screenwidth'; $ratioforcrop=2; } print ''."\n"; print '
'; print ''.$langs->trans("Recenter").''; print $langs->trans("DefineNewAreaToPick").'...
'; print '
'; print '
'; print ''; print '
'; print '

'; print '
'.$langs->trans("NewSizeAfterCropping").':

'."\n"; print '
'."\n"; print '
'; } llxFooter(); $db->close();