31require
'../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
36$langs->loadLangs(array(
"products",
"other"));
39$action =
GETPOST(
'action',
'aZ09');
40$modulepart =
GETPOST(
'modulepart',
'alpha') ?
GETPOST(
'modulepart',
'alpha') :
'produit|service';
41$original_file =
GETPOST(
"file");
42$backtourl =
GETPOST(
'backtourl');
43$cancel =
GETPOST(
'cancel',
'alpha');
45$file =
GETPOST(
'file',
'alpha');
47$website =
GETPOST(
'website',
'alpha');
51if (empty($modulepart)) {
55if ($modulepart ==
'produit' || $modulepart ==
'product' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
56 $result =
restrictedArea($user,
'produit|service', $id,
'product&product');
57 if ($modulepart ==
'produit|service' && (!$user->hasRight(
'produit',
'lire') && !$user->hasRight(
'service',
'lire'))) {
61} elseif ($modulepart ==
'project') {
63 if (!$user->hasRight(
'projet',
'lire')) {
67} elseif ($modulepart ==
'bom') {
69 if (!$user->hasRight(
'bom',
'read')) {
73} elseif ($modulepart ==
'member') {
74 $result =
restrictedArea($user,
'adherent', $id,
'',
'',
'fk_soc',
'rowid');
75 if (!$user->hasRight(
'adherent',
'lire')) {
79} elseif ($modulepart ==
'user') {
80 $result =
restrictedArea($user, $modulepart, $id, $modulepart, $modulepart);
81 if (!$user->hasRight(
'user',
'user',
'lire')) {
85} elseif ($modulepart ==
'tax') {
86 $result =
restrictedArea($user, $modulepart, $id,
'chargesociales',
'charges');
87 if (!$user->hasRight(
'tax',
'charges',
'lire')) {
91} elseif ($modulepart ==
'bank') {
93 if (!$user->hasRight(
'banque',
'lire')) {
97} elseif ($modulepart ==
'medias') {
98 $permtoadd = ($user->hasRight(
'mailing',
'creer') || $user->hasRight(
'website',
'write'));
103} elseif ($modulepart ==
'facture_fourn' || $modulepart ==
'facture_fournisseur') {
104 $result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture');
105 if (!$user->hasRight(
'fournisseur',
'facture',
'lire')) {
112 if (!$user->hasRight($modulepart,
'read') && !$user->hasRight($modulepart,
'lire')) {
120if (!$accessallowed) {
126if ($modulepart ==
'produit' || $modulepart ==
'product' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
127 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
134 $dir = $conf->product->multidir_output[
$object->entity];
136 $dir = $conf->product->multidir_output[
$object->entity];
139 $dir = $conf->service->multidir_output[
$object->entity];
142} elseif ($modulepart ==
'project') {
143 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
150 $dir = $conf->project->multidir_output[
$object->entity];
152} elseif ($modulepart ==
'propal') {
153 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
160 $dir = $conf->propal->multidir_output[
$object->entity];
162} elseif ($modulepart ==
'holiday') {
163 require_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
170 $dir = $conf->$modulepart->dir_output;
172} elseif ($modulepart ==
'member') {
173 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
180 $dir = $conf->adherent->dir_output;
182} elseif ($modulepart ==
'societe') {
183 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
190 $dir = $conf->$modulepart->dir_output;
192} elseif ($modulepart ==
'user') {
193 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
200 $dir = $conf->$modulepart->dir_output;
202} elseif ($modulepart ==
'expensereport') {
203 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
210 $dir = $conf->expensereport->dir_output;
212} elseif ($modulepart ==
'tax') {
213 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
220 $dir = $conf->$modulepart->dir_output;
222} elseif ($modulepart ==
'ticket') {
223 require_once DOL_DOCUMENT_ROOT.
'/ticket/class/ticket.class.php';
230 $dir = $conf->$modulepart->dir_output;
232} elseif ($modulepart ==
'bom') {
233 require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
240 $dir = $conf->$modulepart->dir_output;
242} elseif ($modulepart ==
'mrp') {
243 require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
250 $dir = $conf->$modulepart->dir_output;
252} elseif ($modulepart ==
'bank') {
253 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
260 $dir = $conf->bank->dir_output;
262} elseif ($modulepart ==
'facture') {
263 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
270 $dir = $conf->$modulepart->dir_output;
272} elseif ($modulepart ==
'facture_fourn' || $modulepart ==
'facture_fournisseur') {
273 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
280 $dir = $conf->fournisseur->dir_output.
'/facture';
282} elseif ($modulepart ==
'medias') {
283 $dir = $dolibarr_main_data_root.
'/'.$modulepart;
285 print
'Bug: Action crop for modulepart = '.$modulepart.
' is not supported yet by photos_resize.php.';
288if (empty($backtourl)) {
291 if (in_array($modulepart, array(
'product',
'produit',
'service',
'produit|service'))) {
292 $backtourl = DOL_URL_ROOT.
"/product/document.php?id=".((int) $id).
'&file='.urlencode($file);
293 } elseif (in_array($modulepart, array(
'expensereport'))) {
294 $backtourl = DOL_URL_ROOT.
"/expensereport/document.php?id=".((int) $id).
'&file='.urlencode($file);
295 } elseif (in_array($modulepart, array(
'holiday'))) {
296 $backtourl = DOL_URL_ROOT.
"/holiday/document.php?id=".((int) $id).
'&file='.urlencode($file);
297 } elseif (in_array($modulepart, array(
'member'))) {
298 $backtourl = DOL_URL_ROOT.
"/adherents/document.php?id=".((int) $id).
'&file='.urlencode($file);
299 } elseif (in_array($modulepart, array(
'project'))) {
300 $backtourl = DOL_URL_ROOT.
"/projet/document.php?id=".((int) $id).
'&file='.urlencode($file);
301 } elseif (in_array($modulepart, array(
'propal'))) {
302 $backtourl = DOL_URL_ROOT.
"/comm/propal/document.php?id=".((int) $id).
'&file='.urlencode($file);
303 } elseif (in_array($modulepart, array(
'societe'))) {
304 $backtourl = DOL_URL_ROOT.
"/societe/document.php?id=".((int) $id).
'&file='.urlencode($file);
305 } elseif (in_array($modulepart, array(
'tax'))) {
306 $backtourl = DOL_URL_ROOT.
"/compta/sociales/document.php?id=".((int) $id).
'&file='.urlencode($file);
307 } elseif (in_array($modulepart, array(
'ticket'))) {
308 $backtourl = DOL_URL_ROOT.
"/ticket/document.php?id=".((int) $id).
'&file='.urlencode($file);
309 } elseif (in_array($modulepart, array(
'user'))) {
310 $backtourl = DOL_URL_ROOT.
"/user/document.php?id=".((int) $id).
'&file='.urlencode($file);
311 } elseif (in_array($modulepart, array(
'facture'))) {
312 $backtourl = DOL_URL_ROOT.
"/compta/facture/document.php?id=".((int) $id).
'&file='.urlencode($file);
313 } elseif (in_array($modulepart, array(
'facture_fourn',
'facture_fournisseur'))) {
314 $backtourl = DOL_URL_ROOT.
"/fourn/facture/document.php?id=".((int) $id).
'&file='.urlencode($file);
315 } elseif (in_array($modulepart, array(
'bank')) && preg_match(
'/\/statement\/([^\/]+)\//', $file, $regs)) {
317 $backtourl = DOL_URL_ROOT.
"/compta/bank/account_statement_document.php?id=".((int) $id).
'&num='.urlencode($num).
'&file='.urlencode($file);
318 } elseif (in_array($modulepart, array(
'bank'))) {
319 $backtourl = DOL_URL_ROOT.
"/compta/bank/document.php?id=".((int) $id).
'&file='.urlencode($file);
320 } elseif (in_array($modulepart, array(
'mrp'))) {
321 $backtourl = DOL_URL_ROOT.
"/mrp/mo_document.php?id=".((int) $id).
'&file='.urlencode($file);
322 } elseif (in_array($modulepart, array(
'medias'))) {
323 $section_dir = dirname($file);
324 if (!preg_match(
'/\/$/', $section_dir)) {
327 $backtourl = DOL_URL_ROOT.
'/website/index.php?action=file_manager'.($website ?
'&website='.urlencode($website) :
'').
'§ion_dir='.urlencode($section_dir);
330 $backtourl = DOL_URL_ROOT.
"/".$modulepart.
"/".$modulepart.
"_document.php?id=".((int) $id).
'&file='.urlencode($file);
341 header(
"Location: ".$backtourl);
344 dol_print_error(
null,
'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
349if ($action ==
'confirm_resize' && GETPOSTISSET(
"file") && GETPOSTISSET(
"sizex") && GETPOSTISSET(
"sizey")) {
355 $fullpath = $dir.
"/".$original_file;
359 if ($result == $fullpath) {
366 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $fullpath);
367 $rel_filename = preg_replace(
'/^[\\/]/',
'', $rel_filename);
369 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
371 $result = $ecmfile->fetch(0,
'', $rel_filename);
373 $filename = basename($rel_filename);
374 $rel_dir = dirname($rel_filename);
375 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
376 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
379 $result = $ecmfile->update($user);
380 } elseif ($result == 0) {
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);
386 $ecmfile->filepath = $rel_dir;
387 $ecmfile->filename = $filename;
389 $ecmfile->fullpath_orig = $fullpath;
390 $ecmfile->gen_or_uploaded =
'unknown';
391 $ecmfile->description =
'';
392 $ecmfile->keywords =
'';
393 $result = $ecmfile->create($user);
397 $result = $ecmfile->create($user);
401 header(
"Location: ".$backtourl);
404 dol_print_error(
null,
'confirm_resize on photo_resize without backtourl defined for modulepart='.$modulepart);
414if ($action ==
'confirm_crop') {
416 print
'Bug: Value for $dir could not be defined.';
419 $fullpath = $dir.
"/".$original_file;
423 if ($result == $fullpath) {
429 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $fullpath);
430 $rel_filename = preg_replace(
'/^[\\/]/',
'', $rel_filename);
432 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
434 $result = $ecmfile->fetch(0,
'', $rel_filename);
436 $filename = basename($rel_filename);
437 $rel_dir = dirname($rel_filename);
438 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
439 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
442 $result = $ecmfile->update($user);
443 } elseif ($result == 0) {
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);
449 $ecmfile->filepath = $rel_dir;
450 $ecmfile->filename = $filename;
452 $ecmfile->fullpath_orig = $fullpath;
453 $ecmfile->gen_or_uploaded =
'unknown';
454 $ecmfile->description =
'';
455 $ecmfile->keywords =
'';
456 $result = $ecmfile->create($user);
463 header(
"Location: ".$backtourl);
466 dol_print_error(
null,
'confirm_crop on photo_resize without backtourl defined for modulepart='.$modulepart);
481$title = $langs->trans(
"ImageEditor");
482$morejs = array(
'/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js',
'/core/js/lib_photosresize.js');
483$morecss = array(
'/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css');
485llxHeader($head, $title,
'',
'', 0, 0, $morejs, $morecss);
491$height = $infoarray[
'height'];
492$width = $infoarray[
'width'];
493print
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"CurrentInformationOnImage").
': </span>';
494print
'<span class="opacitymedium">';
495print $langs->trans(
"Width").
': <strong>'.$width.
'</strong> x '.$langs->trans(
"Height").
': <strong>'.$height.
'</strong>';
505print
'<!-- Form to resize -->'.
"\n";
506print
'<form name="redim_file" action="'.$_SERVER[
"PHP_SELF"].
'?id='.((int) $id).($num ?
'&num='.urlencode($num) :
'').
'" method="POST">';
507print
'<input type="hidden" name="token" value="'.newToken().
'">';
508print
'<input type="hidden" name="backtourl" value="'.$backtourl.
'">';
510print
'<fieldset id="redim_file">';
511print
'<legend>'.$langs->trans(
"Resize").
'</legend>';
512print $langs->trans(
"ResizeDesc").
'<br>';
513print $langs->trans(
"NewLength").
': <input name="sizex" type="number" class="flat maxwidth50 right"> px <span class="opacitymedium">'.$langs->trans(
"or").
'</span> ';
514print $langs->trans(
"NewHeight").
': <input name="sizey" type="number" class="flat maxwidth50 right"> px <br>';
516print
'<input type="hidden" name="file" value="'.dol_escape_htmltag($file).
'" />';
517print
'<input type="hidden" name="action" value="confirm_resize" />';
518print
'<input type="hidden" name="product" value="'.$id.
'" />';
519print
'<input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).
'" />';
520print
'<input type="hidden" name="id" value="'.$id.
'" />';
522print
'<input class="button" id="submitresize" name="sendit" value="'.dol_escape_htmltag($langs->trans(
"Resize")).
'" type="submit" />';
524print
'<input type="submit" id="cancelresize" name="cancel" class="button button-cancel" value="'.dol_escape_htmltag($langs->trans(
"Cancel")).
'" />';
525print
'</fieldset>'.
"\n";
537if (!empty($conf->use_javascript_ajax)) {
539 $height = $infoarray[
'height'];
540 $width = $infoarray[
'width'];
541 $widthforcrop = $width;
542 $refsizeforcrop =
'orig';
546 if (!empty($_SESSION[
'dol_screenwidth'])) {
547 $widthforcroporigin = $widthforcrop;
548 while ($widthforcrop > round($_SESSION[
'dol_screenwidth'] / 1.5)) {
550 $ratioforcrop = 2 * $ratioforcrop;
551 $widthforcrop = floor($widthforcroporigin / $ratioforcrop);
552 $refsizeforcrop =
'screenwidth';
556 print
'<!-- Form to crop -->'.
"\n";
557 print
'<fieldset id="redim_file">';
558 print
'<legend>'.$langs->trans(
"Crop").
'</legend>';
559 print $langs->trans(
"DefineNewAreaToPick").
'...<br>';
560 print
'<br><div class="center">';
562 if (empty($conf->dol_no_mouse_hover)) {
563 print
'<div style="border: 1px solid #888888; width: '.$widthforcrop.
'px;">';
564 print
'<img src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.urlencode($modulepart).
'&entity='.((int)
$object->entity).
'&file='.urlencode($original_file).
'" alt="" id="cropbox" width="'.$widthforcrop.
'px"/>';
568 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.((int) $id).($num ?
'&num='.urlencode($num) :
'').
'" method="POST">';
569 print
'<input type="hidden" name="token" value="'.newToken().
'">';
570 print
'<input type="hidden" name="backtourl" value="'.$backtourl.
'">';
572 <div class="jc_coords">
573 '.$langs->trans(
"NewSizeAfterCropping").
':
574 <label>X1=<input type="number" class="flat maxwidth50" id="x" name="x" /></label>
575 <label>Y1=<input type="number" class="flat maxwidth50" id="y" name="y" /></label>
576 <label>X2=<input type="number" class="flat maxwidth50" id="x2" name="x2" /></label>
577 <label>Y2=<input type="number" class="flat maxwidth50" id="y2" name="y2" /></label>
578 <label>W=<input type="number" class="flat maxwidth50" id="w" name="w" /></label>
579 <label>H=<input type="number" class="flat maxwidth50" id="h" name="h" /></label>
582 <input type="hidden" id="file" name="file" value="'.
dol_escape_htmltag($original_file).
'" />
583 <input type="hidden" id="action" name="action" value="confirm_crop" />
584 <input type="hidden" id="product" name="product" value="'.
dol_escape_htmltag((
string) $id).
'" />
585 <input type="hidden" id="dol_screenwidth" name="dol_screenwidth" value="'.($_SESSION[
'dol_screenwidth'] ??
'null').
'" />
586 <input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.
'" />
587 <input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.
'" /><!-- value in field used by js/lib/lib_photoresize.js -->
588 <input type="hidden" id="imagewidth" name="imagewidth" value="'.$width.
'" /><!-- value in field used by js/lib/lib_photoresize.js -->
589 <input type="hidden" id="imageheight" name="imageheight" value="'.$height.
'" /><!-- value in field used by js/lib/lib_photoresize.js -->
593 <input type="submit" id="submitcrop" name="submitcrop" class="button" value="'.
dol_escape_htmltag($langs->trans(
"Crop")).
'" />
595 <input type="submit" id="cancelcrop" name="cancel" class="button button-cancel" value="'.
dol_escape_htmltag($langs->trans(
"Cancel")).
'" />
598 $langs->load(
"other");
599 print
'<div class="opacitymedium">'.$langs->trans(
"FeatureNotAvailableOnDevicesWithoutMouse").
'</div>';
601 print
'</fieldset>'.
"\n";
606print
'<script nonce="'.getNonce().
'" type="text/javascript">
607jQuery(document).ready(function() {
608 $("#submitcrop").click(function(e) {
609 console.log("We click on submitcrop");
610 var idClicked = e.target.id;
611 if (parseInt(jQuery(\'#w\').val())) return true;
612 alert(\''.
dol_escape_js($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"))).
'\');
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
Class to manage bank accounts.
Class to manage members of a foundation.
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 to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage proposals.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dol_imageResizeOrCrop($file, $mode, $newWidth, $newHeight, $src_x=0, $src_y=0, $filetowrite='', $newquality=0)
Resize or crop an image file (Supported extensions are gif, jpg, png, bmp and webp)
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)
Class to generate the form for creating a new ticket.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.