dolibarr 20.0.0
photos_resize.php
Go to the documentation of this file.
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
33
34// Load translation files required by the page
35$langs->loadLangs(array("products", "other"));
36
37$id = GETPOSTINT('id');
38$action = GETPOST('action', 'aZ09');
39$modulepart = GETPOST('modulepart', 'alpha') ? GETPOST('modulepart', 'alpha') : 'produit|service';
40$original_file = GETPOST("file");
41$backtourl = GETPOST('backtourl');
42$cancel = GETPOST('cancel', 'alpha');
43
44$file = GETPOST('file', 'alpha');
45$num = GETPOST('num', 'alpha'); // Used for document on bank statement
46$website = GETPOST('website', 'alpha');
47
48
49// Security check
50if (empty($modulepart)) {
51 accessforbidden('Bad value for modulepart');
52}
53$accessallowed = 0;
54if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'service' || $modulepart == 'produit|service') {
55 $result = restrictedArea($user, 'produit|service', $id, 'product&product');
56 if ($modulepart == 'produit|service' && (!$user->hasRight('produit', 'lire') && !$user->hasRight('service', 'lire'))) {
58 }
59 $accessallowed = 1;
60} elseif ($modulepart == 'project') {
61 $result = restrictedArea($user, 'projet', $id);
62 if (!$user->hasRight('projet', 'lire')) {
64 }
65 $accessallowed = 1;
66} elseif ($modulepart == 'bom') {
67 $result = restrictedArea($user, $modulepart, $id, 'bom_bom');
68 if (!$user->hasRight('bom', 'read')) {
70 }
71 $accessallowed = 1;
72} elseif ($modulepart == 'member') {
73 $result = restrictedArea($user, 'adherent', $id, '', '', 'fk_soc', 'rowid');
74 if (!$user->hasRight('adherent', 'lire')) {
76 }
77 $accessallowed = 1;
78} elseif ($modulepart == 'user') {
79 $result = restrictedArea($user, $modulepart, $id, $modulepart, $modulepart);
80 if (!$user->hasRight('user', 'user', 'lire')) {
82 }
83 $accessallowed = 1;
84} elseif ($modulepart == 'tax') {
85 $result = restrictedArea($user, $modulepart, $id, 'chargesociales', 'charges');
86 if (!$user->hasRight('tax', 'charges', 'lire')) {
88 }
89 $accessallowed = 1;
90} elseif ($modulepart == 'bank') {
91 $result = restrictedArea($user, 'banque', $id, 'bank_account');
92 if (!$user->hasRight('banque', 'lire')) {
94 }
95 $accessallowed = 1;
96} elseif ($modulepart == 'medias') {
97 $permtoadd = ($user->hasRight('mailing', 'creer') || $user->hasRight('website', 'write'));
98 if (!$permtoadd) {
100 }
101 $accessallowed = 1;
102} elseif ($modulepart == 'facture_fourn' || $modulepart == 'facture_fournisseur') {
103 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
104 if (!$user->hasRight('fournisseur', 'facture', 'lire')) {
106 }
107 $accessallowed = 1;
108} else {
109 // ticket, holiday, expensereport, societe...
110 $result = restrictedArea($user, $modulepart, $id, $modulepart);
111 if (!$user->hasRight($modulepart, 'read') && !$user->hasRight($modulepart, 'lire')) {
113 }
114 $accessallowed = 1;
115}
116
117// Security:
118// Limit access if permissions are wrong
119if (!$accessallowed) {
121}
122
123// Define dir according to modulepart
124$dir = '';
125if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'service' || $modulepart == 'produit|service') {
126 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
127 $object = new Product($db);
128 if ($id > 0) {
129 $result = $object->fetch($id);
130 if ($result <= 0) {
131 dol_print_error($db, 'Failed to load object');
132 }
133 $dir = $conf->product->multidir_output[$object->entity]; // By default
134 if ($object->type == Product::TYPE_PRODUCT) {
135 $dir = $conf->product->multidir_output[$object->entity];
136 }
137 if ($object->type == Product::TYPE_SERVICE) {
138 $dir = $conf->service->multidir_output[$object->entity];
139 }
140 }
141} elseif ($modulepart == 'project') {
142 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
143 $object = new Project($db);
144 if ($id > 0) {
145 $result = $object->fetch($id);
146 if ($result <= 0) {
147 dol_print_error($db, 'Failed to load object');
148 }
149 $dir = $conf->project->multidir_output[$object->entity]; // By default
150 }
151} elseif ($modulepart == 'propal') {
152 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
153 $object = new Propal($db);
154 if ($id > 0) {
155 $result = $object->fetch($id);
156 if ($result <= 0) {
157 dol_print_error($db, 'Failed to load object');
158 }
159 $dir = $conf->propal->multidir_output[$object->entity]; // By default
160 }
161} elseif ($modulepart == 'holiday') {
162 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
163 $object = new Holiday($db);
164 if ($id > 0) {
165 $result = $object->fetch($id);
166 if ($result <= 0) {
167 dol_print_error($db, 'Failed to load object');
168 }
169 $dir = $conf->$modulepart->dir_output; // By default
170 }
171} elseif ($modulepart == 'member') {
172 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
173 $object = new Adherent($db);
174 if ($id > 0) {
175 $result = $object->fetch($id);
176 if ($result <= 0) {
177 dol_print_error($db, 'Failed to load object');
178 }
179 $dir = $conf->adherent->dir_output; // By default
180 }
181} elseif ($modulepart == 'societe') {
182 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
183 $object = new Societe($db);
184 if ($id > 0) {
185 $result = $object->fetch($id);
186 if ($result <= 0) {
187 dol_print_error($db, 'Failed to load object');
188 }
189 $dir = $conf->$modulepart->dir_output;
190 }
191} elseif ($modulepart == 'user') {
192 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
193 $object = new User($db);
194 if ($id > 0) {
195 $result = $object->fetch($id);
196 if ($result <= 0) {
197 dol_print_error($db, 'Failed to load object');
198 }
199 $dir = $conf->$modulepart->dir_output; // By default
200 }
201} elseif ($modulepart == 'expensereport') {
202 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
203 $object = new ExpenseReport($db);
204 if ($id > 0) {
205 $result = $object->fetch($id);
206 if ($result <= 0) {
207 dol_print_error($db, 'Failed to load object');
208 }
209 $dir = $conf->expensereport->dir_output; // By default
210 }
211} elseif ($modulepart == 'tax') {
212 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
213 $object = new ChargeSociales($db);
214 if ($id > 0) {
215 $result = $object->fetch($id);
216 if ($result <= 0) {
217 dol_print_error($db, 'Failed to load object');
218 }
219 $dir = $conf->$modulepart->dir_output; // By default
220 }
221} elseif ($modulepart == 'ticket') {
222 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
223 $object = new Ticket($db);
224 if ($id > 0) {
225 $result = $object->fetch($id);
226 if ($result <= 0) {
227 dol_print_error($db, 'Failed to load object');
228 }
229 $dir = $conf->$modulepart->dir_output; // By default
230 }
231} elseif ($modulepart == 'bom') {
232 require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
233 $object = new BOM($db);
234 if ($id > 0) {
235 $result = $object->fetch($id);
236 if ($result <= 0) {
237 dol_print_error($db, 'Failed to load object');
238 }
239 $dir = $conf->$modulepart->dir_output; // By default
240 }
241} elseif ($modulepart == 'mrp') {
242 require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
243 $object = new Mo($db);
244 if ($id > 0) {
245 $result = $object->fetch($id);
246 if ($result <= 0) {
247 dol_print_error($db, 'Failed to load object');
248 }
249 $dir = $conf->$modulepart->dir_output; // By default
250 }
251} elseif ($modulepart == 'bank') {
252 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
253 $object = new Account($db);
254 if ($id > 0) {
255 $result = $object->fetch($id);
256 if ($result <= 0) {
257 dol_print_error($db, 'Failed to load object');
258 }
259 $dir = $conf->bank->dir_output; // By default
260 }
261} elseif ($modulepart == 'facture') {
262 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
263 $object = new Facture($db);
264 if ($id > 0) {
265 $result = $object->fetch($id);
266 if ($result <= 0) {
267 dol_print_error($db, 'Failed to load object');
268 }
269 $dir = $conf->$modulepart->dir_output; // By default
270 }
271} elseif ($modulepart == 'facture_fourn' || $modulepart == 'facture_fournisseur') {
272 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
273 $object = new FactureFournisseur($db);
274 if ($id > 0) {
275 $result = $object->fetch($id);
276 if ($result <= 0) {
277 dol_print_error($db, 'Failed to load object');
278 }
279 $dir = $conf->fournisseur->dir_output.'/facture'; // By default
280 }
281} elseif ($modulepart == 'medias') {
282 $dir = $dolibarr_main_data_root.'/'.$modulepart;
283} else {
284 print 'Bug: Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.';
285}
286
287if (empty($backtourl)) {
288 $regs = array();
289
290 if (in_array($modulepart, array('product', 'produit', 'service', 'produit|service'))) {
291 $backtourl = DOL_URL_ROOT."/product/document.php?id=".((int) $id).'&file='.urlencode($file);
292 } elseif (in_array($modulepart, array('expensereport'))) {
293 $backtourl = DOL_URL_ROOT."/expensereport/document.php?id=".((int) $id).'&file='.urlencode($file);
294 } elseif (in_array($modulepart, array('holiday'))) {
295 $backtourl = DOL_URL_ROOT."/holiday/document.php?id=".((int) $id).'&file='.urlencode($file);
296 } elseif (in_array($modulepart, array('member'))) {
297 $backtourl = DOL_URL_ROOT."/adherents/document.php?id=".((int) $id).'&file='.urlencode($file);
298 } elseif (in_array($modulepart, array('project'))) {
299 $backtourl = DOL_URL_ROOT."/projet/document.php?id=".((int) $id).'&file='.urlencode($file);
300 } elseif (in_array($modulepart, array('propal'))) {
301 $backtourl = DOL_URL_ROOT."/comm/propal/document.php?id=".((int) $id).'&file='.urlencode($file);
302 } elseif (in_array($modulepart, array('societe'))) {
303 $backtourl = DOL_URL_ROOT."/societe/document.php?id=".((int) $id).'&file='.urlencode($file);
304 } elseif (in_array($modulepart, array('tax'))) {
305 $backtourl = DOL_URL_ROOT."/compta/sociales/document.php?id=".((int) $id).'&file='.urlencode($file);
306 } elseif (in_array($modulepart, array('ticket'))) {
307 $backtourl = DOL_URL_ROOT."/ticket/document.php?id=".((int) $id).'&file='.urlencode($file);
308 } elseif (in_array($modulepart, array('user'))) {
309 $backtourl = DOL_URL_ROOT."/user/document.php?id=".((int) $id).'&file='.urlencode($file);
310 } elseif (in_array($modulepart, array('facture'))) {
311 $backtourl = DOL_URL_ROOT."/compta/facture/document.php?id=".((int) $id).'&file='.urlencode($file);
312 } elseif (in_array($modulepart, array('facture_fourn', 'facture_fournisseur'))) {
313 $backtourl = DOL_URL_ROOT."/fourn/facture/document.php?id=".((int) $id).'&file='.urlencode($file);
314 } elseif (in_array($modulepart, array('bank')) && preg_match('/\/statement\/([^\/]+)\//', $file, $regs)) {
315 $num = $regs[1];
316 $backtourl = DOL_URL_ROOT."/compta/bank/account_statement_document.php?id=".((int) $id).'&num='.urlencode($num).'&file='.urlencode($file);
317 } elseif (in_array($modulepart, array('bank'))) {
318 $backtourl = DOL_URL_ROOT."/compta/bank/document.php?id=".((int) $id).'&file='.urlencode($file);
319 } elseif (in_array($modulepart, array('mrp'))) {
320 $backtourl = DOL_URL_ROOT."/mrp/mo_document.php?id=".((int) $id).'&file='.urlencode($file);
321 } elseif (in_array($modulepart, array('medias'))) {
322 $section_dir = dirname($file);
323 if (!preg_match('/\/$/', $section_dir)) {
324 $section_dir .= '/';
325 }
326 $backtourl = DOL_URL_ROOT.'/website/index.php?action=file_manager'.($website ? '&website='.urlencode($website) : '').'&section_dir='.urlencode($section_dir);
327 } else {
328 // Generic case that should work for everybody else
329 $backtourl = DOL_URL_ROOT."/".$modulepart."/".$modulepart."_document.php?id=".((int) $id).'&file='.urlencode($file);
330 }
331}
332
333
334/*
335 * Actions
336 */
337
338if ($cancel) {
339 if ($backtourl) {
340 header("Location: ".$backtourl);
341 exit;
342 } else {
343 dol_print_error(null, 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
344 exit;
345 }
346}
347
348if ($action == 'confirm_resize' && GETPOSTISSET("file") && GETPOSTISSET("sizex") && GETPOSTISSET("sizey")) {
349 if (empty($dir)) {
350 dol_print_error(null, 'Bug: Value for $dir could not be defined.');
351 exit;
352 }
353
354 $fullpath = $dir."/".$original_file;
355
356 $result = dol_imageResizeOrCrop($fullpath, 0, GETPOSTINT('sizex'), GETPOSTINT('sizey'));
357
358 if ($result == $fullpath) {
359 // If image is related to a given object, we create also thumbs.
360 if (is_object($object)) {
361 $object->addThumbs($fullpath);
362 }
363
364 // Update/create database for file $fullpath
365 $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $fullpath);
366 $rel_filename = preg_replace('/^[\\/]/', '', $rel_filename);
367
368 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
369 $ecmfile = new EcmFiles($db);
370 $result = $ecmfile->fetch(0, '', $rel_filename);
371 if ($result > 0) { // If found
372 $filename = basename($rel_filename);
373 $rel_dir = dirname($rel_filename);
374 $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
375 $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
376
377 $ecmfile->label = md5_file(dol_osencode($fullpath));
378 $result = $ecmfile->update($user);
379 } elseif ($result == 0) { // If not found
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
385 $ecmfile->filepath = $rel_dir;
386 $ecmfile->filename = $filename;
387 $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file
388 $ecmfile->fullpath_orig = $fullpath;
389 $ecmfile->gen_or_uploaded = 'unknown';
390 $ecmfile->description = ''; // indexed content
391 $ecmfile->keywords = ''; // keyword content
392 $result = $ecmfile->create($user);
393 if ($result < 0) {
394 setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
395 }
396 $result = $ecmfile->create($user);
397 }
398
399 if ($backtourl) {
400 header("Location: ".$backtourl);
401 exit;
402 } else {
403 dol_print_error(null, 'confirm_resize on photo_resize without backtourl defined for modulepart='.$modulepart);
404 exit;
405 }
406 } else {
407 setEventMessages($result, null, 'errors');
408 $action = '';
409 }
410}
411
412// Crop d'une image
413if ($action == 'confirm_crop') {
414 if (empty($dir)) {
415 print 'Bug: Value for $dir could not be defined.';
416 }
417
418 $fullpath = $dir."/".$original_file;
419
420 $result = dol_imageResizeOrCrop($fullpath, 1, GETPOSTINT('w'), GETPOSTINT('h'), GETPOSTINT('x'), GETPOSTINT('y'));
421
422 if ($result == $fullpath) {
423 if (is_object($object)) {
424 $object->addThumbs($fullpath);
425 }
426
427 // Update/create database for file $fullpath
428 $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $fullpath);
429 $rel_filename = preg_replace('/^[\\/]/', '', $rel_filename);
430
431 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
432 $ecmfile = new EcmFiles($db);
433 $result = $ecmfile->fetch(0, '', $rel_filename);
434 if ($result > 0) { // If found
435 $filename = basename($rel_filename);
436 $rel_dir = dirname($rel_filename);
437 $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
438 $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
439
440 $ecmfile->label = md5_file(dol_osencode($fullpath));
441 $result = $ecmfile->update($user);
442 } elseif ($result == 0) { // If not found
443 $filename = basename($rel_filename);
444 $rel_dir = dirname($rel_filename);
445 $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
446 $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
447
448 $ecmfile->filepath = $rel_dir;
449 $ecmfile->filename = $filename;
450 $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file
451 $ecmfile->fullpath_orig = $fullpath;
452 $ecmfile->gen_or_uploaded = 'unknown';
453 $ecmfile->description = ''; // indexed content
454 $ecmfile->keywords = ''; // keyword content
455 $result = $ecmfile->create($user);
456 if ($result < 0) {
457 setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
458 }
459 }
460
461 if ($backtourl) {
462 header("Location: ".$backtourl);
463 exit;
464 } else {
465 dol_print_error(null, 'confirm_crop on photo_resize without backtourl defined for modulepart='.$modulepart);
466 exit;
467 }
468 } else {
469 setEventMessages($result, null, 'errors');
470 $action = '';
471 }
472}
473
474
475/*
476 * View
477 */
478
479$head = '';
480$title = $langs->trans("ImageEditor");
481$morejs = array('/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js', '/core/js/lib_photosresize.js');
482$morecss = array('/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css');
483
484llxHeader($head, $title, '', '', 0, 0, $morejs, $morecss);
485
486
487print load_fiche_titre($title);
488
489$infoarray = dol_getImageSize($dir."/".GETPOST("file", 'alpha'));
490$height = $infoarray['height'];
491$width = $infoarray['width'];
492print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("CurrentInformationOnImage").': </span>';
493print '<span class="opacitymedium">';
494print $langs->trans("Width").': <strong>'.$width.'</strong> x '.$langs->trans("Height").': <strong>'.$height.'</strong>';
495print '</span><br>';
496
497print '<br>'."\n";
498
499
500/*
501 * Resize image
502 */
503
504print '<!-- Form to resize -->'."\n";
505print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).($num ? '&num='.urlencode($num) : '').'" method="POST">';
506print '<input type="hidden" name="token" value="'.newToken().'">';
507print '<input type="hidden" name="backtourl" value="'.$backtourl.'">';
508
509print '<fieldset id="redim_file">';
510print '<legend>'.$langs->trans("Resize").'</legend>';
511print $langs->trans("ResizeDesc").'<br>';
512print $langs->trans("NewLength").': <input name="sizex" type="number" class="flat maxwidth50 right"> px &nbsp; <span class="opacitymedium">'.$langs->trans("or").'</span> &nbsp; ';
513print $langs->trans("NewHeight").': <input name="sizey" type="number" class="flat maxwidth50 right"> px &nbsp; <br>';
514
515print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'" />';
516print '<input type="hidden" name="action" value="confirm_resize" />';
517print '<input type="hidden" name="product" value="'.$id.'" />';
518print '<input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />';
519print '<input type="hidden" name="id" value="'.$id.'" />';
520print '<br>';
521print '<input class="button" id="submitresize" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
522print '&nbsp;';
523print '<input type="submit" id="cancelresize" name="cancel" class="button button-cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" />';
524print '</fieldset>'."\n";
525print '</form>';
526
527print '<br>'."\n";
528
529
530/*
531 * Crop image
532 */
533
534print '<br>'."\n";
535
536if (!empty($conf->use_javascript_ajax)) {
537 $infoarray = dol_getImageSize($dir."/".GETPOST("file"));
538 $height = $infoarray['height'];
539 $width = $infoarray['width'];
540 $widthforcrop = $width;
541 $refsizeforcrop = 'orig';
542 $ratioforcrop = 1;
543
544 // If image is too large, we use another scale.
545 if (!empty($_SESSION['dol_screenwidth'])) {
546 $widthforcroporigin = $widthforcrop;
547 while ($widthforcrop > round($_SESSION['dol_screenwidth'] / 1.5)) {
548 //var_dump($widthforcrop.' '.round($_SESSION['dol_screenwidth'] / 1.5));
549 $ratioforcrop = 2 * $ratioforcrop;
550 $widthforcrop = floor($widthforcroporigin / $ratioforcrop);
551 $refsizeforcrop = 'screenwidth';
552 }
553 }
554
555 print '<!-- Form to crop -->'."\n";
556 print '<fieldset id="redim_file">';
557 print '<legend>'.$langs->trans("Crop").'</legend>';
558 print $langs->trans("DefineNewAreaToPick").'...<br>';
559 print '<br><div class="center">';
560
561 if (empty($conf->dol_no_mouse_hover)) {
562 print '<div style="border: 1px solid #888888; width: '.$widthforcrop.'px;">';
563 print '<img src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.urlencode($modulepart).'&entity='.((int) $object->entity).'&file='.urlencode($original_file).'" alt="" id="cropbox" width="'.$widthforcrop.'px"/>';
564 print '</div>';
565 print '</div><br>';
566
567 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).($num ? '&num='.urlencode($num) : '').'" method="POST">';
568 print '<input type="hidden" name="token" value="'.newToken().'">';
569 print '<input type="hidden" name="backtourl" value="'.$backtourl.'">';
570 print '
571 <div class="jc_coords">
572 '.$langs->trans("NewSizeAfterCropping").':
573 &nbsp; <label>X1=<input type="number" class="flat maxwidth50" id="x" name="x" /></label>
574 &nbsp; <label>Y1=<input type="number" class="flat maxwidth50" id="y" name="y" /></label>
575 &nbsp; <label>X2=<input type="number" class="flat maxwidth50" id="x2" name="x2" /></label>
576 &nbsp; <label>Y2=<input type="number" class="flat maxwidth50" id="y2" name="y2" /></label>
577 &nbsp; <label>W=<input type="number" class="flat maxwidth50" id="w" name="w" /></label>
578 &nbsp; <label>H=<input type="number" class="flat maxwidth50" id="h" name="h" /></label>
579 </div>
580
581 <input type="hidden" id="file" name="file" value="'.dol_escape_htmltag($original_file).'" />
582 <input type="hidden" id="action" name="action" value="confirm_crop" />
583 <input type="hidden" id="product" name="product" value="'.dol_escape_htmltag($id).'" />
584 <input type="hidden" id="dol_screenwidth" name="dol_screenwidth" value="'.($_SESSION['dol_screenwidth'] ?? 'null').'" />
585 <input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.'" />
586 <input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
587 <input type="hidden" id="imagewidth" name="imagewidth" value="'.$width.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
588 <input type="hidden" id="imageheight" name="imageheight" value="'.$height.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
589 <input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />
590 <input type="hidden" name="id" value="'.dol_escape_htmltag($id).'" />
591 <br>
592 <input type="submit" id="submitcrop" name="submitcrop" class="button" value="'.dol_escape_htmltag($langs->trans("Crop")).'" />
593 &nbsp;
594 <input type="submit" id="cancelcrop" name="cancel" class="button button-cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" />
595 </form>'."\n";
596 } else {
597 $langs->load("other");
598 print '<div class="opacitymedium">'.$langs->trans("FeatureNotAvailableOnDevicesWithoutMouse").'</div>';
599 }
600 print '</fieldset>'."\n";
601 print '<br>';
602}
603
604/* Check that mandatory fields are filled */
605print '<script nonce="'.getNonce().'" type="text/javascript">
606jQuery(document).ready(function() {
607 $("#submitcrop").click(function(e) {
608 console.log("We click on submitcrop");
609 var idClicked = e.target.id;
610 if (parseInt(jQuery(\'#w\').val())) return true;
611 alert(\''.dol_escape_js($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size"))).'\');
612 return false;
613 });
614});
615</script>';
616
617llxFooter();
618$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
Class to manage bank accounts.
Class to manage members of a foundation.
Class for BOM.
Definition bom.class.php:45
Class for managing the social charges.
Class to manage ECM files.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
Class of the module paid holiday.
Class for Mo.
Definition mo.class.php:36
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $src_y=0, $filetowrite='', $newquality=0)
Resize or crop an image file (Supported extensions are gif, jpg, png, bmp and webp)
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)
Class to generate the form for creating a new ticket.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.