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