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