dolibarr 21.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 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 * Copyright (C) 2024 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
35// Load translation files required by the page
36$langs->loadLangs(array("products", "other"));
37
38$id = GETPOSTINT('id');
39$action = GETPOST('action', 'aZ09');
40$modulepart = GETPOST('modulepart', 'alpha') ? GETPOST('modulepart', 'alpha') : 'produit|service';
41$original_file = GETPOST("file");
42$backtourl = GETPOST('backtourl');
43$cancel = GETPOST('cancel', 'alpha');
44
45$file = GETPOST('file', 'alpha');
46$num = GETPOST('num', 'alpha'); // Used for document on bank statement
47$website = GETPOST('website', 'alpha');
48
49
50// Security check
51if (empty($modulepart)) {
52 accessforbidden('Bad value for modulepart');
53}
54$accessallowed = 0;
55if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'service' || $modulepart == 'produit|service') {
56 $result = restrictedArea($user, 'produit|service', $id, 'product&product');
57 if ($modulepart == 'produit|service' && (!$user->hasRight('produit', 'lire') && !$user->hasRight('service', 'lire'))) {
59 }
60 $accessallowed = 1;
61} elseif ($modulepart == 'project') {
62 $result = restrictedArea($user, 'projet', $id);
63 if (!$user->hasRight('projet', 'lire')) {
65 }
66 $accessallowed = 1;
67} elseif ($modulepart == 'bom') {
68 $result = restrictedArea($user, $modulepart, $id, 'bom_bom');
69 if (!$user->hasRight('bom', 'read')) {
71 }
72 $accessallowed = 1;
73} elseif ($modulepart == 'member') {
74 $result = restrictedArea($user, 'adherent', $id, '', '', 'fk_soc', 'rowid');
75 if (!$user->hasRight('adherent', 'lire')) {
77 }
78 $accessallowed = 1;
79} elseif ($modulepart == 'user') {
80 $result = restrictedArea($user, $modulepart, $id, $modulepart, $modulepart);
81 if (!$user->hasRight('user', 'user', 'lire')) {
83 }
84 $accessallowed = 1;
85} elseif ($modulepart == 'tax') {
86 $result = restrictedArea($user, $modulepart, $id, 'chargesociales', 'charges');
87 if (!$user->hasRight('tax', 'charges', 'lire')) {
89 }
90 $accessallowed = 1;
91} elseif ($modulepart == 'bank') {
92 $result = restrictedArea($user, 'banque', $id, 'bank_account');
93 if (!$user->hasRight('banque', 'lire')) {
95 }
96 $accessallowed = 1;
97} elseif ($modulepart == 'medias') {
98 $permtoadd = ($user->hasRight('mailing', 'creer') || $user->hasRight('website', 'write'));
99 if (!$permtoadd) {
101 }
102 $accessallowed = 1;
103} elseif ($modulepart == 'facture_fourn' || $modulepart == 'facture_fournisseur') {
104 $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
105 if (!$user->hasRight('fournisseur', 'facture', 'lire')) {
107 }
108 $accessallowed = 1;
109} else {
110 // ticket, holiday, expensereport, societe...
111 $result = restrictedArea($user, $modulepart, $id, $modulepart);
112 if (!$user->hasRight($modulepart, 'read') && !$user->hasRight($modulepart, 'lire')) {
114 }
115 $accessallowed = 1;
116}
117
118// Security:
119// Limit access if permissions are wrong
120if (!$accessallowed) {
122}
123
124// Define dir according to modulepart
125$dir = '';
126if ($modulepart == 'produit' || $modulepart == 'product' || $modulepart == 'service' || $modulepart == 'produit|service') {
127 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
128 $object = new Product($db);
129 if ($id > 0) {
130 $result = $object->fetch($id);
131 if ($result <= 0) {
132 dol_print_error($db, 'Failed to load object');
133 }
134 $dir = $conf->product->multidir_output[$object->entity]; // By default
135 if ($object->type == Product::TYPE_PRODUCT) {
136 $dir = $conf->product->multidir_output[$object->entity];
137 }
138 if ($object->type == Product::TYPE_SERVICE) {
139 $dir = $conf->service->multidir_output[$object->entity];
140 }
141 }
142} elseif ($modulepart == 'project') {
143 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
144 $object = new Project($db);
145 if ($id > 0) {
146 $result = $object->fetch($id);
147 if ($result <= 0) {
148 dol_print_error($db, 'Failed to load object');
149 }
150 $dir = $conf->project->multidir_output[$object->entity]; // By default
151 }
152} elseif ($modulepart == 'propal') {
153 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
154 $object = new Propal($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->propal->multidir_output[$object->entity]; // By default
161 }
162} elseif ($modulepart == 'holiday') {
163 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
164 $object = new Holiday($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->$modulepart->dir_output; // By default
171 }
172} elseif ($modulepart == 'member') {
173 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
174 $object = new Adherent($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->adherent->dir_output; // By default
181 }
182} elseif ($modulepart == 'societe') {
183 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
184 $object = new Societe($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->$modulepart->dir_output;
191 }
192} elseif ($modulepart == 'user') {
193 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
194 $object = new User($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; // By default
201 }
202} elseif ($modulepart == 'expensereport') {
203 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
204 $object = new ExpenseReport($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->expensereport->dir_output; // By default
211 }
212} elseif ($modulepart == 'tax') {
213 require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
214 $object = new ChargeSociales($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->$modulepart->dir_output; // By default
221 }
222} elseif ($modulepart == 'ticket') {
223 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
224 $object = new Ticket($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 == 'bom') {
233 require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
234 $object = new BOM($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 == 'mrp') {
243 require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
244 $object = new Mo($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 == 'bank') {
253 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
254 $object = new Account($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->bank->dir_output; // By default
261 }
262} elseif ($modulepart == 'facture') {
263 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
264 $object = new Facture($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->$modulepart->dir_output; // By default
271 }
272} elseif ($modulepart == 'facture_fourn' || $modulepart == 'facture_fournisseur') {
273 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
274 $object = new FactureFournisseur($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->fournisseur->dir_output.'/facture'; // By default
281 }
282} elseif ($modulepart == 'medias') {
283 $dir = $dolibarr_main_data_root.'/'.$modulepart;
284} else {
285 print 'Bug: Action crop for modulepart = '.$modulepart.' is not supported yet by photos_resize.php.';
286}
287
288if (empty($backtourl)) {
289 $regs = array();
290
291 if (in_array($modulepart, array('product', 'produit', 'service', 'produit|service'))) {
292 $backtourl = DOL_URL_ROOT."/product/document.php?id=".((int) $id).'&file='.urlencode($file);
293 } elseif (in_array($modulepart, array('expensereport'))) {
294 $backtourl = DOL_URL_ROOT."/expensereport/document.php?id=".((int) $id).'&file='.urlencode($file);
295 } elseif (in_array($modulepart, array('holiday'))) {
296 $backtourl = DOL_URL_ROOT."/holiday/document.php?id=".((int) $id).'&file='.urlencode($file);
297 } elseif (in_array($modulepart, array('member'))) {
298 $backtourl = DOL_URL_ROOT."/adherents/document.php?id=".((int) $id).'&file='.urlencode($file);
299 } elseif (in_array($modulepart, array('project'))) {
300 $backtourl = DOL_URL_ROOT."/projet/document.php?id=".((int) $id).'&file='.urlencode($file);
301 } elseif (in_array($modulepart, array('propal'))) {
302 $backtourl = DOL_URL_ROOT."/comm/propal/document.php?id=".((int) $id).'&file='.urlencode($file);
303 } elseif (in_array($modulepart, array('societe'))) {
304 $backtourl = DOL_URL_ROOT."/societe/document.php?id=".((int) $id).'&file='.urlencode($file);
305 } elseif (in_array($modulepart, array('tax'))) {
306 $backtourl = DOL_URL_ROOT."/compta/sociales/document.php?id=".((int) $id).'&file='.urlencode($file);
307 } elseif (in_array($modulepart, array('ticket'))) {
308 $backtourl = DOL_URL_ROOT."/ticket/document.php?id=".((int) $id).'&file='.urlencode($file);
309 } elseif (in_array($modulepart, array('user'))) {
310 $backtourl = DOL_URL_ROOT."/user/document.php?id=".((int) $id).'&file='.urlencode($file);
311 } elseif (in_array($modulepart, array('facture'))) {
312 $backtourl = DOL_URL_ROOT."/compta/facture/document.php?id=".((int) $id).'&file='.urlencode($file);
313 } elseif (in_array($modulepart, array('facture_fourn', 'facture_fournisseur'))) {
314 $backtourl = DOL_URL_ROOT."/fourn/facture/document.php?id=".((int) $id).'&file='.urlencode($file);
315 } elseif (in_array($modulepart, array('bank')) && preg_match('/\/statement\/([^\/]+)\//', $file, $regs)) {
316 $num = $regs[1];
317 $backtourl = DOL_URL_ROOT."/compta/bank/account_statement_document.php?id=".((int) $id).'&num='.urlencode($num).'&file='.urlencode($file);
318 } elseif (in_array($modulepart, array('bank'))) {
319 $backtourl = DOL_URL_ROOT."/compta/bank/document.php?id=".((int) $id).'&file='.urlencode($file);
320 } elseif (in_array($modulepart, array('mrp'))) {
321 $backtourl = DOL_URL_ROOT."/mrp/mo_document.php?id=".((int) $id).'&file='.urlencode($file);
322 } elseif (in_array($modulepart, array('medias'))) {
323 $section_dir = dirname($file);
324 if (!preg_match('/\/$/', $section_dir)) {
325 $section_dir .= '/';
326 }
327 $backtourl = DOL_URL_ROOT.'/website/index.php?action=file_manager'.($website ? '&website='.urlencode($website) : '').'&section_dir='.urlencode($section_dir);
328 } else {
329 // Generic case that should work for everybody else
330 $backtourl = DOL_URL_ROOT."/".$modulepart."/".$modulepart."_document.php?id=".((int) $id).'&file='.urlencode($file);
331 }
332}
333
334
335/*
336 * Actions
337 */
338
339if ($cancel) {
340 if ($backtourl) {
341 header("Location: ".$backtourl);
342 exit;
343 } else {
344 dol_print_error(null, 'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
345 exit;
346 }
347}
348
349if ($action == 'confirm_resize' && GETPOSTISSET("file") && GETPOSTISSET("sizex") && GETPOSTISSET("sizey")) { // Test on permission already done
350 if (empty($dir)) {
351 dol_print_error(null, 'Bug: Value for $dir could not be defined.');
352 exit;
353 }
354
355 $fullpath = $dir."/".$original_file;
356
357 $result = dol_imageResizeOrCrop($fullpath, 0, GETPOSTINT('sizex'), GETPOSTINT('sizey'));
358
359 if ($result == $fullpath) {
360 // If image is related to a given object, we create also thumbs.
361 if (is_object($object)) {
362 $object->addThumbs($fullpath);
363 }
364
365 // Update/create database for file $fullpath
366 $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $fullpath);
367 $rel_filename = preg_replace('/^[\\/]/', '', $rel_filename);
368
369 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
370 $ecmfile = new EcmFiles($db);
371 $result = $ecmfile->fetch(0, '', $rel_filename);
372 if ($result > 0) { // If found
373 $filename = basename($rel_filename);
374 $rel_dir = dirname($rel_filename);
375 $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
376 $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
377
378 $ecmfile->label = md5_file(dol_osencode($fullpath));
379 $result = $ecmfile->update($user);
380 } elseif ($result == 0) { // If not found
381 $filename = basename($rel_filename);
382 $rel_dir = dirname($rel_filename);
383 $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
384 $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
385
386 $ecmfile->filepath = $rel_dir;
387 $ecmfile->filename = $filename;
388 $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file
389 $ecmfile->fullpath_orig = $fullpath;
390 $ecmfile->gen_or_uploaded = 'unknown';
391 $ecmfile->description = ''; // indexed content
392 $ecmfile->keywords = ''; // keyword content
393 $result = $ecmfile->create($user);
394 if ($result < 0) {
395 setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
396 }
397 $result = $ecmfile->create($user);
398 }
399
400 if ($backtourl) {
401 header("Location: ".$backtourl);
402 exit;
403 } else {
404 dol_print_error(null, 'confirm_resize on photo_resize without backtourl defined for modulepart='.$modulepart);
405 exit;
406 }
407 } else {
408 setEventMessages($result, null, 'errors');
409 $action = '';
410 }
411}
412
413// Crop d'une image
414if ($action == 'confirm_crop') {
415 if (empty($dir)) {
416 print 'Bug: Value for $dir could not be defined.';
417 }
418
419 $fullpath = $dir."/".$original_file;
420
421 $result = dol_imageResizeOrCrop($fullpath, 1, GETPOSTINT('w'), GETPOSTINT('h'), GETPOSTINT('x'), GETPOSTINT('y'));
422
423 if ($result == $fullpath) {
424 if (is_object($object)) {
425 $object->addThumbs($fullpath);
426 }
427
428 // Update/create database for file $fullpath
429 $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $fullpath);
430 $rel_filename = preg_replace('/^[\\/]/', '', $rel_filename);
431
432 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
433 $ecmfile = new EcmFiles($db);
434 $result = $ecmfile->fetch(0, '', $rel_filename);
435 if ($result > 0) { // If found
436 $filename = basename($rel_filename);
437 $rel_dir = dirname($rel_filename);
438 $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
439 $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
440
441 $ecmfile->label = md5_file(dol_osencode($fullpath));
442 $result = $ecmfile->update($user);
443 } elseif ($result == 0) { // If not found
444 $filename = basename($rel_filename);
445 $rel_dir = dirname($rel_filename);
446 $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
447 $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
448
449 $ecmfile->filepath = $rel_dir;
450 $ecmfile->filename = $filename;
451 $ecmfile->label = md5_file(dol_osencode($fullpath)); // $fullpath is a full path to file
452 $ecmfile->fullpath_orig = $fullpath;
453 $ecmfile->gen_or_uploaded = 'unknown';
454 $ecmfile->description = ''; // indexed content
455 $ecmfile->keywords = ''; // keyword content
456 $result = $ecmfile->create($user);
457 if ($result < 0) {
458 setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
459 }
460 }
461
462 if ($backtourl) {
463 header("Location: ".$backtourl);
464 exit;
465 } else {
466 dol_print_error(null, 'confirm_crop on photo_resize without backtourl defined for modulepart='.$modulepart);
467 exit;
468 }
469 } else {
470 setEventMessages($result, null, 'errors');
471 $action = '';
472 }
473}
474
475
476/*
477 * View
478 */
479
480$head = '';
481$title = $langs->trans("ImageEditor");
482$morejs = array('/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js', '/core/js/lib_photosresize.js');
483$morecss = array('/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css');
484
485llxHeader($head, $title, '', '', 0, 0, $morejs, $morecss);
486
487
488print load_fiche_titre($title);
489
490$infoarray = dol_getImageSize($dir."/".GETPOST("file", 'alpha'));
491$height = $infoarray['height'];
492$width = $infoarray['width'];
493print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("CurrentInformationOnImage").': </span>';
494print '<span class="opacitymedium">';
495print $langs->trans("Width").': <strong>'.$width.'</strong> x '.$langs->trans("Height").': <strong>'.$height.'</strong>';
496print '</span><br>';
497
498print '<br>'."\n";
499
500
501/*
502 * Resize image
503 */
504
505print '<!-- Form to resize -->'."\n";
506print '<form name="redim_file" action="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).($num ? '&num='.urlencode($num) : '').'" method="POST">';
507print '<input type="hidden" name="token" value="'.newToken().'">';
508print '<input type="hidden" name="backtourl" value="'.$backtourl.'">';
509
510print '<fieldset id="redim_file">';
511print '<legend>'.$langs->trans("Resize").'</legend>';
512print $langs->trans("ResizeDesc").'<br>';
513print $langs->trans("NewLength").': <input name="sizex" type="number" class="flat maxwidth50 right"> px &nbsp; <span class="opacitymedium">'.$langs->trans("or").'</span> &nbsp; ';
514print $langs->trans("NewHeight").': <input name="sizey" type="number" class="flat maxwidth50 right"> px &nbsp; <br>';
515
516print '<input type="hidden" name="file" value="'.dol_escape_htmltag($file).'" />';
517print '<input type="hidden" name="action" value="confirm_resize" />';
518print '<input type="hidden" name="product" value="'.$id.'" />';
519print '<input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />';
520print '<input type="hidden" name="id" value="'.$id.'" />';
521print '<br>';
522print '<input class="button" id="submitresize" name="sendit" value="'.dol_escape_htmltag($langs->trans("Resize")).'" type="submit" />';
523print '&nbsp;';
524print '<input type="submit" id="cancelresize" name="cancel" class="button button-cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" />';
525print '</fieldset>'."\n";
526print '</form>';
527
528print '<br>'."\n";
529
530
531/*
532 * Crop image
533 */
534
535print '<br>'."\n";
536
537if (!empty($conf->use_javascript_ajax)) {
538 $infoarray = dol_getImageSize($dir."/".GETPOST("file"));
539 $height = $infoarray['height'];
540 $width = $infoarray['width'];
541 $widthforcrop = $width;
542 $refsizeforcrop = 'orig';
543 $ratioforcrop = 1;
544
545 // If image is too large, we use another scale.
546 if (!empty($_SESSION['dol_screenwidth'])) {
547 $widthforcroporigin = $widthforcrop;
548 while ($widthforcrop > round($_SESSION['dol_screenwidth'] / 1.5)) {
549 //var_dump($widthforcrop.' '.round($_SESSION['dol_screenwidth'] / 1.5));
550 $ratioforcrop = 2 * $ratioforcrop;
551 $widthforcrop = floor($widthforcroporigin / $ratioforcrop);
552 $refsizeforcrop = 'screenwidth';
553 }
554 }
555
556 print '<!-- Form to crop -->'."\n";
557 print '<fieldset id="redim_file">';
558 print '<legend>'.$langs->trans("Crop").'</legend>';
559 print $langs->trans("DefineNewAreaToPick").'...<br>';
560 print '<br><div class="center">';
561
562 if (empty($conf->dol_no_mouse_hover)) {
563 print '<div style="border: 1px solid #888888; width: '.$widthforcrop.'px;">';
564 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"/>';
565 print '</div>';
566 print '</div><br>';
567
568 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).($num ? '&num='.urlencode($num) : '').'" method="POST">';
569 print '<input type="hidden" name="token" value="'.newToken().'">';
570 print '<input type="hidden" name="backtourl" value="'.$backtourl.'">';
571 print '
572 <div class="jc_coords">
573 '.$langs->trans("NewSizeAfterCropping").':
574 &nbsp; <label>X1=<input type="number" class="flat maxwidth50" id="x" name="x" /></label>
575 &nbsp; <label>Y1=<input type="number" class="flat maxwidth50" id="y" name="y" /></label>
576 &nbsp; <label>X2=<input type="number" class="flat maxwidth50" id="x2" name="x2" /></label>
577 &nbsp; <label>Y2=<input type="number" class="flat maxwidth50" id="y2" name="y2" /></label>
578 &nbsp; <label>W=<input type="number" class="flat maxwidth50" id="w" name="w" /></label>
579 &nbsp; <label>H=<input type="number" class="flat maxwidth50" id="h" name="h" /></label>
580 </div>
581
582 <input type="hidden" id="file" name="file" value="'.dol_escape_htmltag($original_file).'" />
583 <input type="hidden" id="action" name="action" value="confirm_crop" />
584 <input type="hidden" id="product" name="product" value="'.dol_escape_htmltag((string) $id).'" />
585 <input type="hidden" id="dol_screenwidth" name="dol_screenwidth" value="'.($_SESSION['dol_screenwidth'] ?? 'null').'" />
586 <input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.'" />
587 <input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
588 <input type="hidden" id="imagewidth" name="imagewidth" value="'.$width.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
589 <input type="hidden" id="imageheight" name="imageheight" value="'.$height.'" /><!-- value in field used by js/lib/lib_photoresize.js -->
590 <input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).'" />
591 <input type="hidden" name="id" value="'.dol_escape_htmltag((string) $id).'" />
592 <br>
593 <input type="submit" id="submitcrop" name="submitcrop" class="button" value="'.dol_escape_htmltag($langs->trans("Crop")).'" />
594 &nbsp;
595 <input type="submit" id="cancelcrop" name="cancel" class="button button-cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'" />
596 </form>'."\n";
597 } else {
598 $langs->load("other");
599 print '<div class="opacitymedium">'.$langs->trans("FeatureNotAvailableOnDevicesWithoutMouse").'</div>';
600 }
601 print '</fieldset>'."\n";
602 print '<br>';
603}
604
605/* Check that mandatory fields are filled */
606print '<script nonce="'.getNonce().'" type="text/javascript">
607jQuery(document).ready(function() {
608 $("#submitcrop").click(function(e) {
609 console.log("We click on submitcrop");
610 var idClicked = e.target.id;
611 if (parseInt(jQuery(\'#w\').val())) return true;
612 alert(\''.dol_escape_js($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Size"))).'\');
613 return false;
614 });
615});
616</script>';
617
618llxFooter();
619$db->close();
$id
Definition account.php:39
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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
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:34
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.