photos_resize.php 23 KB

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