photos_resize.php 23 KB

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