31require
'../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
44$langs->loadLangs(array(
"products",
"other"));
47$action =
GETPOST(
'action',
'aZ09');
48$modulepart =
GETPOST(
'modulepart',
'alpha') ?
GETPOST(
'modulepart',
'alpha') :
'produit|service';
49$original_file =
GETPOST(
"file");
50$backtourl =
GETPOST(
'backtourl');
51$cancel =
GETPOST(
'cancel',
'alpha');
53$file =
GETPOST(
'file',
'alpha');
55$website =
GETPOST(
'website',
'alpha');
59if (empty($modulepart)) {
63if ($modulepart ==
'produit' || $modulepart ==
'product' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
64 $result =
restrictedArea($user,
'produit|service', $id,
'product&product');
65 if ($modulepart ==
'produit|service' && (!$user->hasRight(
'produit',
'lire') && !$user->hasRight(
'service',
'lire'))) {
69} elseif ($modulepart ==
'project') {
71 if (!$user->hasRight(
'projet',
'lire')) {
75} elseif ($modulepart ==
'bom') {
77 if (!$user->hasRight(
'bom',
'read')) {
81} elseif ($modulepart ==
'member') {
82 $result =
restrictedArea($user,
'adherent', $id,
'',
'',
'fk_soc',
'rowid');
83 if (!$user->hasRight(
'adherent',
'lire')) {
87} elseif ($modulepart ==
'user') {
88 $result =
restrictedArea($user, $modulepart, $id, $modulepart, $modulepart);
89 if (!$user->hasRight(
'user',
'user',
'lire')) {
93} elseif ($modulepart ==
'tax') {
94 $result =
restrictedArea($user, $modulepart, $id,
'chargesociales',
'charges');
95 if (!$user->hasRight(
'tax',
'charges',
'lire')) {
99} elseif ($modulepart ==
'bank') {
101 if (!$user->hasRight(
'banque',
'lire')) {
105} elseif ($modulepart ==
'medias') {
106 $permtoadd = ($user->hasRight(
'mailing',
'creer') || $user->hasRight(
'website',
'write'));
111} elseif ($modulepart ==
'facture_fourn' || $modulepart ==
'facture_fournisseur') {
112 $result =
restrictedArea($user,
'fournisseur', $id,
'facture_fourn',
'facture');
113 if (!$user->hasRight(
'fournisseur',
'facture',
'lire')) {
120 if (!$user->hasRight($modulepart,
'read') && !$user->hasRight($modulepart,
'lire')) {
128if (!$accessallowed) {
134if ($modulepart ==
'produit' || $modulepart ==
'product' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
135 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
142 $dir =
$conf->product->multidir_output[
$object->entity];
144 $dir =
$conf->product->multidir_output[
$object->entity];
147 $dir =
$conf->service->multidir_output[
$object->entity];
150} elseif ($modulepart ==
'project') {
151 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
158 $dir =
$conf->project->multidir_output[
$object->entity];
160} elseif ($modulepart ==
'propal') {
161 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
170} elseif ($modulepart ==
'holiday') {
171 require_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
178 $dir =
$conf->$modulepart->dir_output;
180} elseif ($modulepart ==
'member') {
181 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
188 $dir =
$conf->adherent->dir_output;
190} elseif ($modulepart ==
'societe') {
191 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
198 $dir =
$conf->$modulepart->dir_output;
200} elseif ($modulepart ==
'user') {
201 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
208 $dir =
$conf->$modulepart->dir_output;
210} elseif ($modulepart ==
'expensereport') {
211 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
218 $dir =
$conf->expensereport->dir_output;
220} elseif ($modulepart ==
'tax') {
221 require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
228 $dir =
$conf->$modulepart->dir_output;
230} elseif ($modulepart ==
'ticket') {
231 require_once DOL_DOCUMENT_ROOT.
'/ticket/class/ticket.class.php';
238 $dir =
$conf->$modulepart->dir_output;
240} elseif ($modulepart ==
'bom') {
241 require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
248 $dir =
$conf->$modulepart->dir_output;
250} elseif ($modulepart ==
'mrp') {
251 require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
258 $dir =
$conf->$modulepart->dir_output;
260} elseif ($modulepart ==
'bank') {
261 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
268 $dir =
$conf->bank->dir_output;
270} elseif ($modulepart ==
'facture') {
271 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
278 $dir =
$conf->$modulepart->dir_output;
280} elseif ($modulepart ==
'facture_fourn' || $modulepart ==
'facture_fournisseur') {
281 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
288 $dir =
$conf->fournisseur->dir_output.
'/facture';
290} elseif ($modulepart ==
'medias') {
291 $dir = $dolibarr_main_data_root.
'/'.$modulepart;
293 print
'Bug: Action crop for modulepart = '.$modulepart.
' is not supported yet by photos_resize.php.';
296if (empty($backtourl)) {
299 if (in_array($modulepart, array(
'product',
'produit',
'service',
'produit|service'))) {
300 $backtourl = DOL_URL_ROOT.
"/product/document.php?id=".((int) $id).
'&file='.urlencode($file);
301 } elseif (in_array($modulepart, array(
'expensereport'))) {
302 $backtourl = DOL_URL_ROOT.
"/expensereport/document.php?id=".((int) $id).
'&file='.urlencode($file);
303 } elseif (in_array($modulepart, array(
'holiday'))) {
304 $backtourl = DOL_URL_ROOT.
"/holiday/document.php?id=".((int) $id).
'&file='.urlencode($file);
305 } elseif (in_array($modulepart, array(
'member'))) {
306 $backtourl = DOL_URL_ROOT.
"/adherents/document.php?id=".((int) $id).
'&file='.urlencode($file);
307 } elseif (in_array($modulepart, array(
'project'))) {
308 $backtourl = DOL_URL_ROOT.
"/projet/document.php?id=".((int) $id).
'&file='.urlencode($file);
309 } elseif (in_array($modulepart, array(
'propal'))) {
310 $backtourl = DOL_URL_ROOT.
"/comm/propal/document.php?id=".((int) $id).
'&file='.urlencode($file);
311 } elseif (in_array($modulepart, array(
'societe'))) {
312 $backtourl = DOL_URL_ROOT.
"/societe/document.php?id=".((int) $id).
'&file='.urlencode($file);
313 } elseif (in_array($modulepart, array(
'tax'))) {
314 $backtourl = DOL_URL_ROOT.
"/compta/sociales/document.php?id=".((int) $id).
'&file='.urlencode($file);
315 } elseif (in_array($modulepart, array(
'ticket'))) {
316 $backtourl = DOL_URL_ROOT.
"/ticket/document.php?id=".((int) $id).
'&file='.urlencode($file);
317 } elseif (in_array($modulepart, array(
'user'))) {
318 $backtourl = DOL_URL_ROOT.
"/user/document.php?id=".((int) $id).
'&file='.urlencode($file);
319 } elseif (in_array($modulepart, array(
'facture'))) {
320 $backtourl = DOL_URL_ROOT.
"/compta/facture/document.php?id=".((int) $id).
'&file='.urlencode($file);
321 } elseif (in_array($modulepart, array(
'facture_fourn',
'facture_fournisseur'))) {
322 $backtourl = DOL_URL_ROOT.
"/fourn/facture/document.php?id=".((int) $id).
'&file='.urlencode($file);
323 } elseif (in_array($modulepart, array(
'bank')) && preg_match(
'/\/statement\/([^\/]+)\//', $file, $regs)) {
325 $backtourl = DOL_URL_ROOT.
"/compta/bank/account_statement_document.php?id=".((int) $id).
'&num='.urlencode($num).
'&file='.urlencode($file);
326 } elseif (in_array($modulepart, array(
'bank'))) {
327 $backtourl = DOL_URL_ROOT.
"/compta/bank/document.php?id=".((int) $id).
'&file='.urlencode($file);
328 } elseif (in_array($modulepart, array(
'mrp'))) {
329 $backtourl = DOL_URL_ROOT.
"/mrp/mo_document.php?id=".((int) $id).
'&file='.urlencode($file);
330 } elseif (in_array($modulepart, array(
'medias'))) {
331 $section_dir = dirname($file);
332 if (!preg_match(
'/\/$/', $section_dir)) {
335 $backtourl = DOL_URL_ROOT.
'/website/index.php?action=file_manager'.($website ?
'&website='.urlencode($website) :
'').
'§ion_dir='.urlencode($section_dir);
338 $backtourl = DOL_URL_ROOT.
"/".$modulepart.
"/".$modulepart.
"_document.php?id=".((int) $id).
'&file='.urlencode($file);
349 header(
"Location: ".$backtourl);
352 dol_print_error(
null,
'Cancel on photo_resize with a not supported value of modulepart='.$modulepart);
357if ($action ==
'confirm_resize' && GETPOSTISSET(
"file") && GETPOSTISSET(
"sizex") && GETPOSTISSET(
"sizey")) {
363 $fullpath = $dir.
"/".$original_file;
367 if ($result == $fullpath) {
374 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $fullpath);
375 $rel_filename = preg_replace(
'/^[\\/]/',
'', $rel_filename);
377 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
379 $result = $ecmfile->fetch(0,
'', $rel_filename);
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);
387 $result = $ecmfile->update($user);
388 } elseif ($result == 0) {
389 $filename = basename($rel_filename);
390 $rel_dir = dirname($rel_filename);
391 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
392 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
394 $ecmfile->filepath = $rel_dir;
395 $ecmfile->filename = $filename;
397 $ecmfile->fullpath_orig = $fullpath;
398 $ecmfile->gen_or_uploaded =
'unknown';
399 $ecmfile->description =
'';
400 $ecmfile->keywords =
'';
401 $result = $ecmfile->create($user);
405 $result = $ecmfile->create($user);
409 header(
"Location: ".$backtourl);
412 dol_print_error(
null,
'confirm_resize on photo_resize without backtourl defined for modulepart='.$modulepart);
422if ($action ==
'confirm_crop') {
424 print
'Bug: Value for $dir could not be defined.';
427 $fullpath = $dir.
"/".$original_file;
431 if ($result == $fullpath) {
437 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $fullpath);
438 $rel_filename = preg_replace(
'/^[\\/]/',
'', $rel_filename);
440 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
442 $result = $ecmfile->fetch(0,
'', $rel_filename);
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);
450 $result = $ecmfile->update($user);
451 } elseif ($result == 0) {
452 $filename = basename($rel_filename);
453 $rel_dir = dirname($rel_filename);
454 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
455 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
457 $ecmfile->filepath = $rel_dir;
458 $ecmfile->filename = $filename;
460 $ecmfile->fullpath_orig = $fullpath;
461 $ecmfile->gen_or_uploaded =
'unknown';
462 $ecmfile->description =
'';
463 $ecmfile->keywords =
'';
464 $result = $ecmfile->create($user);
471 header(
"Location: ".$backtourl);
474 dol_print_error(
null,
'confirm_crop on photo_resize without backtourl defined for modulepart='.$modulepart);
489$title = $langs->trans(
"ImageEditor");
490$morejs = array(
'/includes/jquery/plugins/jcrop/js/jquery.Jcrop.min.js',
'/core/js/lib_photosresize.js');
491$morecss = array(
'/includes/jquery/plugins/jcrop/css/jquery.Jcrop.css');
493llxHeader($head, $title,
'',
'', 0, 0, $morejs, $morecss);
499$height = $infoarray[
'height'];
500$width = $infoarray[
'width'];
501print
'<span class="opacitymedium hideonsmartphone">'.$langs->trans(
"CurrentInformationOnImage").
': </span>';
502print
'<span class="opacitymedium">';
503print $langs->trans(
"Width").
': <strong>'.$width.
'</strong> x '.$langs->trans(
"Height").
': <strong>'.$height.
'</strong>';
513print
'<!-- Form to resize -->'.
"\n";
514print
'<form name="redim_file" action="'.$_SERVER[
"PHP_SELF"].
'?id='.((int) $id).($num ?
'&num='.urlencode($num) :
'').
'" method="POST">';
515print
'<input type="hidden" name="token" value="'.newToken().
'">';
516print
'<input type="hidden" name="backtourl" value="'.$backtourl.
'">';
518print
'<fieldset id="redim_file">';
519print
'<legend>'.$langs->trans(
"Resize").
'</legend>';
520print $langs->trans(
"ResizeDesc").
'<br>';
521print $langs->trans(
"NewLength").
': <input name="sizex" type="number" class="flat maxwidth50 right"> px <span class="opacitymedium">'.$langs->trans(
"or").
'</span> ';
522print $langs->trans(
"NewHeight").
': <input name="sizey" type="number" class="flat maxwidth50 right"> px <br>';
524print
'<input type="hidden" name="file" value="'.dol_escape_htmltag($file).
'" />';
525print
'<input type="hidden" name="action" value="confirm_resize" />';
526print
'<input type="hidden" name="product" value="'.$id.
'" />';
527print
'<input type="hidden" name="modulepart" value="'.dol_escape_htmltag($modulepart).
'" />';
528print
'<input type="hidden" name="id" value="'.$id.
'" />';
530print
'<input class="button" id="submitresize" name="sendit" value="'.dol_escape_htmltag($langs->trans(
"Resize")).
'" type="submit" />';
532print
'<input type="submit" id="cancelresize" name="cancel" class="button button-cancel" value="'.dol_escape_htmltag($langs->trans(
"Cancel")).
'" />';
533print
'</fieldset>'.
"\n";
545if (!empty(
$conf->use_javascript_ajax)) {
547 $height = $infoarray[
'height'];
548 $width = $infoarray[
'width'];
549 $widthforcrop = $width;
550 $refsizeforcrop =
'orig';
554 if (!empty($_SESSION[
'dol_screenwidth'])) {
555 $widthforcroporigin = $widthforcrop;
556 while ($widthforcrop > round($_SESSION[
'dol_screenwidth'] / 1.5)) {
558 $ratioforcrop = 2 * $ratioforcrop;
559 $widthforcrop = floor($widthforcroporigin / $ratioforcrop);
560 $refsizeforcrop =
'screenwidth';
564 print
'<!-- Form to crop -->'.
"\n";
565 print
'<fieldset id="redim_file">';
566 print
'<legend>'.$langs->trans(
"Crop").
'</legend>';
567 print $langs->trans(
"DefineNewAreaToPick").
'...<br>';
568 print
'<br><div class="center">';
570 if (empty(
$conf->dol_no_mouse_hover)) {
571 print
'<div style="border: 1px solid #888888; width: '.$widthforcrop.
'px;">';
572 print
'<img src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.urlencode($modulepart).
'&entity='.((int)
$object->entity).
'&file='.urlencode($original_file).
'" alt="" id="cropbox" width="'.$widthforcrop.
'px"/>';
576 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?id='.((int) $id).($num ?
'&num='.urlencode($num) :
'').
'" method="POST">';
577 print
'<input type="hidden" name="token" value="'.newToken().
'">';
578 print
'<input type="hidden" name="backtourl" value="'.$backtourl.
'">';
580 <div class="jc_coords">
581 '.$langs->trans(
"NewSizeAfterCropping").
':
582 <label>X1=<input type="number" class="flat maxwidth50" id="x" name="x" /></label>
583 <label>Y1=<input type="number" class="flat maxwidth50" id="y" name="y" /></label>
584 <label>X2=<input type="number" class="flat maxwidth50" id="x2" name="x2" /></label>
585 <label>Y2=<input type="number" class="flat maxwidth50" id="y2" name="y2" /></label>
586 <label>W=<input type="number" class="flat maxwidth50" id="w" name="w" /></label>
587 <label>H=<input type="number" class="flat maxwidth50" id="h" name="h" /></label>
590 <input type="hidden" id="file" name="file" value="'.
dol_escape_htmltag($original_file).
'" />
591 <input type="hidden" id="action" name="action" value="confirm_crop" />
592 <input type="hidden" id="product" name="product" value="'.
dol_escape_htmltag((
string) $id).
'" />
593 <input type="hidden" id="dol_screenwidth" name="dol_screenwidth" value="'.($_SESSION[
'dol_screenwidth'] ??
'null').
'" />
594 <input type="hidden" id="refsizeforcrop" name="refsizeforcrop" value="'.$refsizeforcrop.
'" />
595 <input type="hidden" id="ratioforcrop" name="ratioforcrop" value="'.$ratioforcrop.
'" /><!-- value in field used by js/lib/lib_photoresize.js -->
596 <input type="hidden" id="imagewidth" name="imagewidth" value="'.$width.
'" /><!-- value in field used by js/lib/lib_photoresize.js -->
597 <input type="hidden" id="imageheight" name="imageheight" value="'.$height.
'" /><!-- value in field used by js/lib/lib_photoresize.js -->
601 <input type="submit" id="submitcrop" name="submitcrop" class="button" value="'.
dol_escape_htmltag($langs->trans(
"Crop")).
'" />
603 <input type="submit" id="cancelcrop" name="cancel" class="button button-cancel" value="'.
dol_escape_htmltag($langs->trans(
"Cancel")).
'" />
606 $langs->load(
"other");
607 print
'<div class="opacitymedium">'.$langs->trans(
"FeatureNotAvailableOnDevicesWithoutMouse").
'</div>';
609 print
'</fieldset>'.
"\n";
614print
'<script nonce="'.getNonce().
'" type="text/javascript">
615jQuery(document).ready(function() {
616 $("#submitcrop").click(function(e) {
617 console.log("We click on submitcrop");
618 var idClicked = e.target.id;
619 if (parseInt(jQuery(\'#w\').val())) return true;
620 alert(\''.
dol_escape_js($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Size"))).
'\');
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.