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