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