photos_resize.php 23 KB

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