PageRenderTime 229ms CodeModel.GetById 12ms RepoModel.GetById 2ms app.codeStats 1ms

/htdocs/core/photos_resize.php

https://github.com/asterix14/dolibarr
PHP | 211 lines | 132 code | 35 blank | 44 comment | 34 complexity | 6627807b95ed99450c8c02a8e30e5585 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009 Meos
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/photos_resize.php
  20. * \ingroup core
  21. * \brief File of page to resize photos
  22. */
  23. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
  24. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');
  25. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  26. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  27. //if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
  28. //if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1');
  29. //if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show
  30. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
  31. //if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
  32. //if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
  33. require("../main.inc.php");
  34. require_once(DOL_DOCUMENT_ROOT."/core/lib/product.lib.php");
  35. require_once(DOL_DOCUMENT_ROOT."/core/lib/images.lib.php");
  36. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  37. $langs->load("products");
  38. $langs->load("other");
  39. $modulepart=$_REQUEST['modulepart']?$_REQUEST['modulepart']:'produit|service';
  40. if (isset($_GET["id"]))
  41. {
  42. $id = isset($_GET["id"])?$_GET["id"]:'';
  43. }
  44. $original_file = isset($_REQUEST["file"])?urldecode($_REQUEST["file"]):'';
  45. // Security check
  46. if (empty($modulepart)) accessforbidden('Bad value for modulepart');
  47. $accessallowed=0;
  48. if ($modulepart)
  49. {
  50. if ($modulepart=='produit|service')
  51. {
  52. $result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid);
  53. if ($modulepart=='produit|service' && (! $user->rights->produit->lire && ! $user->rights->service->lire)) accessforbidden();
  54. $accessallowed=1;
  55. }
  56. }
  57. // Security:
  58. // Limit access if permissions are wrong
  59. if (! $accessallowed)
  60. {
  61. accessforbidden();
  62. }
  63. /*
  64. * Actions
  65. */
  66. if ($_POST["action"] == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POST["sizex"]) != "") && (isset($_POST["sizey"]) != ""))
  67. {
  68. $product=new Product($db);
  69. $result=$product->fetch($_POST["id"]);
  70. if ($result <= 0) dol_print_error($db,'Failed to load object');
  71. $dir=$conf->product->dir_output; // By default
  72. if ($product->type == 0) $dir=$conf->product->dir_output;
  73. if ($product->type == 1) $dir=$conf->service->dir_output;
  74. $fullpath=$dir."/".$original_file;
  75. $result=dol_imageResizeOrCrop($fullpath,0,$_POST['sizex'],$_POST['sizey']);
  76. if ($result == $fullpath)
  77. {
  78. header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$_POST["id"].'&action=addthumb&file='.urldecode($_POST["file"]));
  79. exit;
  80. }
  81. else
  82. {
  83. $mesg=$result;
  84. $_GET['file']=$_POST["file"];
  85. $_GET['id']=$_POST["id"];
  86. }
  87. }
  88. // Crop d'une image
  89. if ($_POST["action"] == 'confirm_crop')
  90. {
  91. $product=new Product($db);
  92. $result=$product->fetch($_POST["id"]);
  93. if ($result <= 0) dol_print_error($db,'Failed to load object');
  94. $dir=$conf->product->dir_output; // By default
  95. if ($product->type == 0) $dir=$conf->product->dir_output;
  96. if ($product->type == 1) $dir=$conf->service->dir_output;
  97. $fullpath=$dir."/".$original_file;
  98. $result=dol_imageResizeOrCrop($fullpath,1,$_POST['w'],$_POST['h'],$_POST['x'],$_POST['y']);
  99. if ($result == $fullpath)
  100. {
  101. header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$_POST["id"].'&action=addthumb&file='.urldecode($_POST["file"]));
  102. exit;
  103. }
  104. else
  105. {
  106. $mesg=$result;
  107. $_GET['file']=$_POST["file"];
  108. $_GET['id']=$_POST["id"];
  109. }
  110. }
  111. /*
  112. * View
  113. */
  114. 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'));
  115. print_fiche_titre($langs->trans("ImageEditor"));
  116. if ($mesg) print '<div class="error">'.$mesg.'</div>';
  117. $infoarray=dol_getImageSize($conf->product->dir_output."/".urldecode($_GET["file"]));
  118. $height=$infoarray['height'];
  119. $width=$infoarray['width'];
  120. print $langs->trans("CurrentInformationOnImage").':';
  121. print '<ul>
  122. <li>'.$langs->trans("Width").': '.$width.' px</li>
  123. <li>'.$langs->trans("Height").': '.$height.' px</li>
  124. </ul>';
  125. print '<br>'."\n";
  126. print '<!-- Form to resize -->'."\n";
  127. print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.$_GET['id'].'" method="POST">';
  128. print '<fieldset id="redim_file">';
  129. print '<legend>'.$langs->trans("Resize").'</legend>';
  130. print $langs->trans("ResizeDesc").'<br>';
  131. print $langs->trans("NewLength").': <input class="flat" name="sizex" size="10" type="text" > px <br> ';
  132. print $langs->trans("NewHeight").': <input class="flat" name="sizey" size="10" type="text" > px &nbsp; <br>';
  133. print '<input type="hidden" name="file" value="'.$_GET['file'].'" />';
  134. print '<input type="hidden" name="action" value="confirm_resize" />';
  135. print '<input type="hidden" name="product" value="'.$_REQUEST['id'].'" />';
  136. print '<input type="hidden" name="id" value="'.$_REQUEST['id'].'" />';
  137. print '<br><input class="button" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
  138. print '</fieldset>';
  139. print '<br></form>';
  140. /*
  141. * Recadrage d'une image
  142. */
  143. print '<br>'."\n";
  144. if (! empty($conf->use_javascript_ajax))
  145. {
  146. $infoarray=dol_getImageSize($conf->product->dir_output."/".urldecode($_GET["file"]));
  147. $height=$infoarray['height'];
  148. $width=$infoarray['width'];
  149. print '<!-- Form to crop -->'."\n";
  150. print '<fieldset id="redim_file">';
  151. print '<legend>'.$langs->trans("Recenter").'</legend>';
  152. print $langs->trans("DefineNewAreaToPick").'...<br>';
  153. print '<br><center>';
  154. print '<div style="border: 1px solid #888888; width: '.$width.'px;"><img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.$original_file.'" alt="" id="cropbox" /></div>';
  155. print '</center><br>';
  156. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$_GET['id'].'" method="post" onsubmit="return checkCoords();">
  157. <div class="jc_coords">
  158. '.$langs->trans("NewSizeAfterCropping").':
  159. <label>X1 <input type="text" size="4" id="x" name="x" /></label>
  160. <label>Y1 <input type="text" size="4" id="y" name="y" /></label>
  161. <label>X2 <input type="text" size="4" id="x2" name="x2" /></label>
  162. <label>Y2 <input type="text" size="4" id="y2" name="y2" /></label>
  163. <label>W <input type="text" size="4" id="w" name="w" /></label>
  164. <label>H <input type="text" size="4" id="h" name="h" /></label>
  165. </div>
  166. <input type="hidden" id="file" name="file" value="'.urlencode($original_file).'" />
  167. <input type="hidden" id="action" name="action" value="confirm_crop" />
  168. <input type="hidden" id="product" name="product" value="'.$_REQUEST['id'].'" />
  169. <input type="hidden" name="id" value="'.$_REQUEST['id'].'" />
  170. <br><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Recenter")).'" />
  171. </form>';
  172. print '</fieldset>';
  173. }
  174. llxFooter();
  175. ?>