photos_resize.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <?php
  2. /* Copyright (C) 2010-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2009 Meos
  4. * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2016 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/core/photos_resize.php
  22. * \ingroup core
  23. * \brief File of page to resize photos
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("products", "other"));
  30. $id = GETPOST('id', 'int');
  31. $action = GETPOST('action', 'alpha');
  32. $modulepart = GETPOST('modulepart', 'alpha') ?GETPOST('modulepart', 'alpha') : 'produit|service';
  33. $original_file = GETPOST("file");
  34. $backtourl = GETPOST('backtourl');
  35. $cancel = GETPOST('cancel', 'alpha');
  36. $file = GETPOST('file', 'alpha');
  37. $num = GETPOST('num', 'alpha'); // Used for document on bank statement
  38. $website = GETPOST('website', 'alpha');
  39. // Security check
  40. if (empty($modulepart)) accessforbidden('Bad value for modulepart');
  41. $accessallowed = 0;
  42. if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'service' || $modulepart == 'produit|service')
  43. {
  44. $result = restrictedArea($user, 'produit|service', $id, 'product&product');
  45. if ($modulepart == 'produit|service' && (!$user->rights->produit->lire && !$user->rights->service->lire)) accessforbidden();
  46. $accessallowed = 1;
  47. }
  48. elseif ($modulepart == 'project')
  49. {
  50. $result = restrictedArea($user, 'projet', $id);
  51. if (!$user->rights->projet->lire) accessforbidden();
  52. $accessallowed = 1;
  53. }
  54. elseif ($modulepart == 'bom')
  55. {
  56. $result = restrictedArea($user, $modulepart, $id, 'bom_bom');
  57. if (!$user->rights->bom->read) accessforbidden();
  58. $accessallowed = 1;
  59. }
  60. elseif ($modulepart == 'member')
  61. {
  62. $result = restrictedArea($user, 'adherent', $id, '', '', 'fk_soc', 'rowid');
  63. if (!$user->rights->adherent->lire) accessforbidden();
  64. $accessallowed = 1;
  65. }
  66. elseif ($modulepart == 'user')
  67. {
  68. $result = restrictedArea($user, $modulepart, $id, $modulepart);
  69. if (!$user->rights->user->user->lire) accessforbidden();
  70. $accessallowed = 1;
  71. }
  72. elseif ($modulepart == 'tax')
  73. {
  74. $result = restrictedArea($user, $modulepart, $id, 'chargesociales', 'charges');
  75. if (!$user->rights->tax->charges->lire) accessforbidden();
  76. $accessallowed = 1;
  77. }
  78. elseif ($modulepart == 'bank')
  79. {
  80. $result = restrictedArea($user, 'banque', $id, 'bank_account');
  81. if (!$user->rights->banque->lire) accessforbidden();
  82. $accessallowed = 1;
  83. } elseif ($modulepart == 'medias')
  84. {
  85. $permtoadd = ($user->rights->mailing->creer || $user->rights->website->write);
  86. if (!$permtoadd) accessforbidden();
  87. $accessallowed = 1;
  88. } else // ticket, holiday, expensereport, societe...
  89. {
  90. $result = restrictedArea($user, $modulepart, $id, $modulepart);
  91. if (empty($user->rights->$modulepart->read) && empty($user->rights->$modulepart->lire)) accessforbidden();
  92. $accessallowed = 1;
  93. }
  94. // Security:
  95. // Limit access if permissions are wrong
  96. if (!$accessallowed)
  97. {
  98. accessforbidden();
  99. }
  100. // Define dir according to modulepart
  101. if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'service' || $modulepart == 'produit|service')
  102. {
  103. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  104. $object = new Product($db);
  105. if ($id > 0)
  106. {
  107. $result = $object->fetch($id);
  108. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  109. $dir = $conf->product->multidir_output[$object->entity]; // By default
  110. if ($object->type == Product::TYPE_PRODUCT) $dir = $conf->product->multidir_output[$object->entity];
  111. if ($object->type == Product::TYPE_SERVICE) $dir = $conf->service->multidir_output[$object->entity];
  112. }
  113. }
  114. elseif ($modulepart == 'project')
  115. {
  116. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  117. $object = new Project($db);
  118. if ($id > 0)
  119. {
  120. $result = $object->fetch($id);
  121. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  122. $dir = $conf->project->multidir_output[$object->entity]; // By default
  123. }
  124. }
  125. elseif ($modulepart == 'propal')
  126. {
  127. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  128. $object = new Propal($db);
  129. if ($id > 0)
  130. {
  131. $result = $object->fetch($id);
  132. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  133. $dir = $conf->propal->multidir_output[$object->entity]; // By default
  134. }
  135. }
  136. elseif ($modulepart == 'holiday')
  137. {
  138. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  139. $object = new Holiday($db);
  140. if ($id > 0)
  141. {
  142. $result = $object->fetch($id);
  143. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  144. $dir = $conf->$modulepart->dir_output; // By default
  145. }
  146. }
  147. elseif ($modulepart == 'member')
  148. {
  149. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  150. $object = new Adherent($db);
  151. if ($id > 0)
  152. {
  153. $result = $object->fetch($id);
  154. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  155. $dir = $conf->adherent->dir_output; // By default
  156. }
  157. }
  158. elseif ($modulepart == 'societe')
  159. {
  160. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  161. $object = new Societe($db);
  162. if ($id > 0)
  163. {
  164. $result = $object->fetch($id);
  165. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  166. $dir = $conf->$modulepart->dir_output;
  167. }
  168. }
  169. elseif ($modulepart == 'user')
  170. {
  171. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  172. $object = new User($db);
  173. if ($id > 0)
  174. {
  175. $result = $object->fetch($id);
  176. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  177. $dir = $conf->$modulepart->dir_output; // By default
  178. }
  179. }
  180. elseif ($modulepart == 'expensereport')
  181. {
  182. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  183. $object = new ExpenseReport($db);
  184. if ($id > 0)
  185. {
  186. $result = $object->fetch($id);
  187. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  188. $dir = $conf->expensereport->dir_output; // By default
  189. }
  190. }
  191. elseif ($modulepart == 'tax')
  192. {
  193. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  194. $object = new ChargeSociales($db);
  195. if ($id > 0)
  196. {
  197. $result = $object->fetch($id);
  198. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  199. $dir = $conf->$modulepart->dir_output; // By default
  200. }
  201. }
  202. elseif ($modulepart == 'ticket')
  203. {
  204. require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
  205. $object = new Ticket($db);
  206. if ($id > 0)
  207. {
  208. $result = $object->fetch($id);
  209. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  210. $dir = $conf->$modulepart->dir_output; // By default
  211. }
  212. }
  213. elseif ($modulepart == 'bom')
  214. {
  215. require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  216. $object = new BOM($db);
  217. if ($id > 0)
  218. {
  219. $result = $object->fetch($id);
  220. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  221. $dir = $conf->$modulepart->dir_output; // By default
  222. }
  223. } elseif ($modulepart == 'mrp') {
  224. require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
  225. $object = new MO($db);
  226. if ($id > 0)
  227. {
  228. $result = $object->fetch($id);
  229. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  230. $dir = $conf->$modulepart->dir_output; // By default
  231. }
  232. } elseif ($modulepart == 'bank') {
  233. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  234. $object = new Account($db);
  235. if ($id > 0)
  236. {
  237. $result = $object->fetch($id);
  238. if ($result <= 0) dol_print_error($db, 'Failed to load object');
  239. $dir = $conf->bank->dir_output; // By default
  240. }
  241. } elseif ($modulepart == 'medias') {
  242. $dir = $dolibarr_main_data_root.'/'.$modulepart;
  243. } else {
  244. print 'Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.';
  245. }
  246. if (empty($backtourl))
  247. {
  248. $regs = array();
  249. if (in_array($modulepart, array('product', 'produit', 'service', 'produit|service'))) $backtourl = DOL_URL_ROOT."/product/document.php?id=".$id.'&file='.urldecode($file);
  250. elseif (in_array($modulepart, array('expensereport'))) $backtourl = DOL_URL_ROOT."/expensereport/document.php?id=".$id.'&file='.urldecode($file);
  251. elseif (in_array($modulepart, array('holiday'))) $backtourl = DOL_URL_ROOT."/holiday/document.php?id=".$id.'&file='.urldecode($file);
  252. elseif (in_array($modulepart, array('member'))) $backtourl = DOL_URL_ROOT."/adherents/document.php?id=".$id.'&file='.urldecode($file);
  253. elseif (in_array($modulepart, array('project'))) $backtourl = DOL_URL_ROOT."/projet/document.php?id=".$id.'&file='.urldecode($file);
  254. elseif (in_array($modulepart, array('propal'))) $backtourl = DOL_URL_ROOT."/comm/propal/document.php?id=".$id.'&file='.urldecode($file);
  255. elseif (in_array($modulepart, array('societe'))) $backtourl = DOL_URL_ROOT."/societe/document.php?id=".$id.'&file='.urldecode($file);
  256. elseif (in_array($modulepart, array('tax'))) $backtourl = DOL_URL_ROOT."/compta/sociales/document.php?id=".$id.'&file='.urldecode($file);
  257. elseif (in_array($modulepart, array('ticket'))) $backtourl = DOL_URL_ROOT."/ticket/document.php?id=".$id.'&file='.urldecode($file);
  258. elseif (in_array($modulepart, array('user'))) $backtourl = DOL_URL_ROOT."/user/document.php?id=".$id.'&file='.urldecode($file);
  259. elseif (in_array($modulepart, array('bank')) && preg_match('/\/statement\/([^\/]+)\//', $file, $regs)) {
  260. $num = $regs[1];
  261. $backtourl = DOL_URL_ROOT."/compta/bank/account_statement_document.php?id=".$id.'&num='.urlencode($num).'&file='.urldecode($file);
  262. }
  263. elseif (in_array($modulepart, array('bank'))) $backtourl = DOL_URL_ROOT."/compta/bank/document.php?id=".$id.'&file='.urldecode($file);
  264. elseif (in_array($modulepart, array('mrp'))) $backtourl = DOL_URL_ROOT."/mrp/mo_document.php?id=".$id.'&file='.urldecode($file);
  265. elseif (in_array($modulepart, array('medias'))) {
  266. $section_dir = dirname($file);
  267. if (! preg_match('/\/$/', $section_dir)) $section_dir.='/';
  268. $backtourl = DOL_URL_ROOT."/website/index.php?action=file_manager&website=".$website.'&section_dir='.urlencode($section_dir);
  269. }
  270. // Generic case that should work for everybody else
  271. else $backtourl = DOL_URL_ROOT."/".$modulepart."/".$modulepart."_document.php?id=".$id.'&file='.urldecode($file);
  272. }
  273. /*
  274. * Actions
  275. */
  276. if ($cancel)
  277. {
  278. if ($backtourl)
  279. {
  280. header("Location: ".$backtourl);
  281. exit;
  282. }
  283. else
  284. {
  285. dol_print_error('', 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
  286. exit;
  287. }
  288. }
  289. if ($action == 'confirm_resize' && GETPOSTISSET("file") && GETPOSTISSET("sizex") && GETPOSTISSET("sizey"))
  290. {
  291. $fullpath = $dir."/".$original_file;
  292. $result = dol_imageResizeOrCrop($fullpath, 0, GETPOST('sizex', 'int'), GETPOST('sizey', 'int'));
  293. if ($result == $fullpath)
  294. {
  295. // If image is related to a given object, we create also thumbs.
  296. if (is_object($object)) {
  297. $object->addThumbs($fullpath);
  298. }
  299. // Update/create database for file $fullpath
  300. $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $fullpath);
  301. $rel_filename = preg_replace('/^[\\/]/', '', $rel_filename);
  302. include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
  303. $ecmfile = new EcmFiles($db);
  304. $result = $ecmfile->fetch(0, '', $rel_filename);
  305. if ($result > 0) // If found
  306. {
  307. $filename = basename($rel_filename);
  308. $rel_dir = dirname($rel_filename);
  309. $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
  310. $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
  311. $ecmfile->label = md5_file(dol_osencode($fullpath));
  312. $result = $ecmfile->update($user);
  313. }
  314. elseif ($result == 0) // If not found
  315. {
  316. $filename = basename($rel_filename);
  317. $rel_dir = dirname($rel_filename);
  318. $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
  319. $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
  320. $ecmfile->filepath = $rel_dir;
  321. $ecmfile->filename = $filename;
  322. $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file
  323. $ecmfile->fullpath_orig = $fullpath;
  324. $ecmfile->gen_or_uploaded = 'unknown';
  325. $ecmfile->description = ''; // indexed content
  326. $ecmfile->keyword = ''; // keyword content
  327. $result = $ecmfile->create($user);
  328. if ($result < 0)
  329. {
  330. setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
  331. }
  332. $result = $ecmfile->create($user);
  333. }
  334. if ($backtourl)
  335. {
  336. header("Location: ".$backtourl);
  337. exit;
  338. }
  339. else
  340. {
  341. dol_print_error('', 'confirm_resize on photo_resize without backtourl defined for modulepart='.$modulepart);
  342. exit;
  343. }
  344. }
  345. else
  346. {
  347. setEventMessages($result, null, 'errors');
  348. $_GET['file'] = $_POST["file"];
  349. $action = '';
  350. }
  351. }
  352. // Crop d'une image
  353. if ($action == 'confirm_crop')
  354. {
  355. $fullpath = $dir."/".$original_file;
  356. //var_dump($_POST['w'].'x'.$_POST['h'].'-'.$_POST['x'].'x'.$_POST['y']);exit;
  357. $result = dol_imageResizeOrCrop($fullpath, 1, GETPOST('w', 'int'), GETPOST('h', 'int'), GETPOST('x', 'int'), GETPOST('y', 'int'));
  358. if ($result == $fullpath)
  359. {
  360. if (is_object($object)) {
  361. $object->addThumbs($fullpath);
  362. }
  363. // Update/create database for file $fullpath
  364. $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $fullpath);
  365. $rel_filename = preg_replace('/^[\\/]/', '', $rel_filename);
  366. include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
  367. $ecmfile = new EcmFiles($db);
  368. $result = $ecmfile->fetch(0, '', $rel_filename);
  369. if ($result > 0) // If found
  370. {
  371. $filename = basename($rel_filename);
  372. $rel_dir = dirname($rel_filename);
  373. $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
  374. $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
  375. $ecmfile->label = md5_file(dol_osencode($fullpath));
  376. $result = $ecmfile->update($user);
  377. }
  378. elseif ($result == 0) // If not found
  379. {
  380. $filename = basename($rel_filename);
  381. $rel_dir = dirname($rel_filename);
  382. $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
  383. $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
  384. $ecmfile->filepath = $rel_dir;
  385. $ecmfile->filename = $filename;
  386. $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file
  387. $ecmfile->fullpath_orig = $fullpath;
  388. $ecmfile->gen_or_uploaded = 'unknown';
  389. $ecmfile->description = ''; // indexed content
  390. $ecmfile->keyword = ''; // keyword content
  391. $result = $ecmfile->create($user);
  392. if ($result < 0)
  393. {
  394. setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
  395. }
  396. $result = $ecmfile->create($user);
  397. }
  398. if ($backtourl)
  399. {
  400. header("Location: ".$backtourl);
  401. exit;
  402. }
  403. else
  404. {
  405. dol_print_error('', 'confirm_crop on photo_resize without backtourl defined for modulepart='.$modulepart);
  406. exit;
  407. }
  408. }
  409. else
  410. {
  411. setEventMessages($result, null, 'errors');
  412. $_GET['file'] = $_POST["file"];
  413. $action = '';
  414. }
  415. }
  416. /*
  417. * View
  418. */
  419. 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'));
  420. print load_fiche_titre($langs->trans("ImageEditor"));
  421. $infoarray = dol_getImageSize($dir."/".GETPOST("file", 'alpha'));
  422. $height = $infoarray['height'];
  423. $width = $infoarray['width'];
  424. print $langs->trans("CurrentInformationOnImage").': ';
  425. print $langs->trans("Width").': <strong>'.$width.'</strong> x '.$langs->trans("Height").': <strong>'.$height.'</strong><br>';
  426. print '<br>'."\n";
  427. /*
  428. * Resize image
  429. */
  430. print '<!-- Form to resize -->'."\n";
  431. print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.$id.($num ? '&num='.$num : '').'" method="POST">';
  432. print '<input type="hidden" name="token" value="'.newToken().'">';
  433. print '<fieldset id="redim_file">';
  434. print '<legend>'.$langs->trans("Resize").'</legend>';
  435. print $langs->trans("ResizeDesc").'<br>';
  436. print $langs->trans("NewLength").': <input name="sizex" type="number" class="flat maxwidth50"> px &nbsp; '.$langs->trans("or").' &nbsp; ';
  437. print $langs->trans("NewHeight").': <input name="sizey" type="number" class="flat maxwidth50"> px &nbsp; <br>';
  438. print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'" />';
  439. print '<input type="hidden" name="action" value="confirm_resize" />';
  440. print '<input type="hidden" name="product" value="'.$id.'" />';
  441. print '<input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />';
  442. print '<input type="hidden" name="id" value="'.$id.'" />';
  443. print '<br>';
  444. print '<input class="button" id="submitresize" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
  445. print '&nbsp;';
  446. print '<input type="submit" id="cancelresize" name="cancel" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" />';
  447. print '</fieldset>'."\n";
  448. print '</form>';
  449. print '<br>'."\n";
  450. /*
  451. * Crop image
  452. */
  453. print '<br>'."\n";
  454. if (!empty($conf->use_javascript_ajax))
  455. {
  456. $infoarray = dol_getImageSize($dir."/".GETPOST("file"));
  457. $height = $infoarray['height'];
  458. $width = $infoarray['width'];
  459. $widthforcrop = $width; $refsizeforcrop = 'orig'; $ratioforcrop = 1;
  460. // If image is too large, we use another scale.
  461. if (!empty($_SESSION['dol_screenwidth']) && ($widthforcrop > round($_SESSION['dol_screenwidth'] / 2)))
  462. {
  463. $ratioforcrop = 2;
  464. $widthforcrop = round($_SESSION['dol_screenwidth'] / $ratioforcrop);
  465. $refsizeforcrop = 'screenwidth';
  466. }
  467. print '<!-- Form to crop -->'."\n";
  468. print '<fieldset id="redim_file">';
  469. print '<legend>'.$langs->trans("Recenter").'</legend>';
  470. print $langs->trans("DefineNewAreaToPick").'...<br>';
  471. print '<br><div class="center">';
  472. print '<div style="border: 1px solid #888888; width: '.$widthforcrop.'px;">';
  473. print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$object->entity.'&file='.urlencode($original_file).'" alt="" id="cropbox" width="'.$widthforcrop.'px"/>';
  474. print '</div>';
  475. print '</div><br>';
  476. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.($num ? '&num='.$num : '').'" method="POST">';
  477. print '<input type="hidden" name="token" value="'.newToken().'">';
  478. print '
  479. <div class="jc_coords">
  480. '.$langs->trans("NewSizeAfterCropping").':
  481. <label>X1 <input type="number" class="flat maxwidth50" id="x" name="x" /></label>
  482. <label>Y1 <input type="number" class="flat maxwidth50" id="y" name="y" /></label>
  483. <label>X2 <input type="number" class="flat maxwidth50" id="x2" name="x2" /></label>
  484. <label>Y2 <input type="number" class="flat maxwidth50" id="y2" name="y2" /></label>
  485. <label>W <input type="number" class="flat maxwidth50" id="w" name="w" /></label>
  486. <label>H <input type="number" class="flat maxwidth50" id="h" name="h" /></label>
  487. </div>
  488. <input type="hidden" id="file" name="file" value="'.dol_escape_htmltag($original_file).'" />
  489. <input type="hidden" id="action" name="action" value="confirm_crop" />
  490. <input type="hidden" id="product" name="product" value="'.dol_escape_htmltag($id).'" />
  491. <input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.'" />
  492. <input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.'" /><!-- field used by core/lib/lib_photoresize.js -->
  493. <input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />
  494. <input type="hidden" name="id" value="'.dol_escape_htmltag($id).'" />
  495. <br>
  496. <input type="submit" id="submitcrop" name="submitcrop" class="button" value="'.dol_escape_htmltag($langs->trans("Recenter")).'" />
  497. &nbsp;
  498. <input type="submit" id="cancelcrop" name="cancel" class="button" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" />
  499. </form>'."\n";
  500. print '</fieldset>'."\n";
  501. print '<br>';
  502. }
  503. /* Check that mandatory fields are filled */
  504. print '<script type="text/javascript" language="javascript">
  505. jQuery(document).ready(function() {
  506. $("#submitcrop").click(function(e) {
  507. console.log("We click on submitcrop");
  508. var idClicked = e.target.id;
  509. if (parseInt(jQuery(\'#w\').val())) return true;
  510. alert(\''.dol_escape_js($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Dimension"))).'\');
  511. return false;
  512. });
  513. });
  514. </script>';
  515. llxFooter();
  516. $db->close();