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