36define(
'MAIN_SECURITY_FORCECSP',
"default-src 'none'; form-action 'none'; frame-ancestors 'self'");
40if (!defined(
'NOTOKENRENEWAL')) {
41 define(
'NOTOKENRENEWAL',
'1');
43if (!defined(
'NOREQUIREMENU')) {
44 define(
'NOREQUIREMENU',
'1');
46if (!defined(
'NOREQUIREHTML')) {
47 define(
'NOREQUIREHTML',
'1');
49if (!defined(
'NOREQUIREAJAX')) {
50 define(
'NOREQUIREAJAX',
'1');
54if (isset($_GET[
"hashp"]) && !defined(
"NOLOGIN")) {
55 if (!defined(
"NOLOGIN")) {
58 if (!defined(
"NOCSRFCHECK")) {
59 define(
"NOCSRFCHECK", 1);
61 if (!defined(
"NOIPCHECK")) {
62 define(
"NOIPCHECK", 1);
67if ((isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'medias')) {
68 if (!defined(
"NOLOGIN")) {
71 if (!defined(
"NOCSRFCHECK")) {
72 define(
"NOCSRFCHECK", 1);
74 if (!defined(
"NOIPCHECK")) {
75 define(
"NOIPCHECK", 1);
83$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 0));
87 define(
"DOLENTITY", $entity);
113function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
128function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
132require
'main.inc.php';
140require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
141require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
144$action =
GETPOST(
'action',
'aZ09');
145$original_file =
GETPOST(
'file',
'alphanohtml');
146$hashp =
GETPOST(
'hashp',
'aZ09');
147$modulepart =
GETPOST(
'modulepart',
'alpha');
148$urlsource =
GETPOST(
'urlsource',
'alpha');
149$entity = ($entity > 0 ? $entity :
$conf->entity);
152if (empty($modulepart) && empty($hashp)) {
155if (empty($original_file) && empty($hashp)) {
158if ($hashp ==
'shared') {
161if ($modulepart ==
'fckeditor') {
162 $modulepart =
'medias';
166if ($user->socid > 0) {
167 $socid = $user->socid;
171if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
172 if (!$user->hasRight(
'societe',
'client',
'voir')) {
173 $original_file =
'private/'.$user->id.
'/'.$original_file;
192if (!empty($hashp) && $hashp !=
'shared') {
193 if (
GETPOST(
'type',
'alpha') ==
'link') {
194 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
196 $result = $link->fetch(0, $hashp);
197 if ($result > 0 && !empty($link->url)) {
198 if (preg_match(
'/^(http|dav)/', $link->url)) {
199 header(
'Location: '.$link->url);
203 $langs->load(
"errors");
207 include_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
209 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
211 $tmp = explode(
'/', $ecmfile->filepath, 2);
213 if (is_numeric($tmp[0])) {
214 $tmp = explode(
'/', $tmp[1], 2);
216 $moduleparttocheck = $tmp[0];
219 if ($moduleparttocheck == $modulepart) {
221 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
227 $modulepart = $moduleparttocheck;
228 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
231 $entity = $ecmfile->entity;
232 if (
isModEnabled(
'multicompany') && !empty($ecmfile->src_object_type) && $ecmfile->src_object_id > 0) {
233 $object = fetchObjectByElement($ecmfile->src_object_id, $ecmfile->src_object_type);
234 if (is_object($object) &&
$object->id > 0) {
239 if ($entity !=
$conf->entity) {
240 $conf->entity = $entity;
246 $langs->load(
"errors");
254if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
257if (isset($_GET[
"attachment"])) {
258 $attachment =
GETPOST(
"attachment",
'alpha') ? true :
false;
265$type =
'application/octet-stream';
267 $type =
GETPOST(
'type',
'alpha');
275 $type =
'application/octet-stream';
279$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
280$original_file = str_replace(
'../',
'/', $original_file);
281$original_file = str_replace(
'..\\',
'/', $original_file);
284if (empty($modulepart)) {
290$accessallowed = $check_access[
'accessallowed'];
291$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
292$fullpath_original_file = $check_access[
'original_file'];
295if (!empty($hashp) && $hashp !=
'shared') {
297 $sqlprotectagainstexternals =
'';
300 if ($user->socid > 0) {
301 if ($sqlprotectagainstexternals) {
302 $resql =
$db->query($sqlprotectagainstexternals);
304 $num =
$db->num_rows($resql);
307 $obj =
$db->fetch_object($resql);
308 if ($user->socid != $obj->fk_soc) {
316 } elseif ($modulepart ==
'ticket' && !
getDolGlobalString(
'TICKET_EMAIL_MUST_EXISTS')) {
317 if ($sqlprotectagainstexternals) {
318 $resql =
$db->query($sqlprotectagainstexternals);
320 $num =
$db->num_rows($resql);
331if (!$accessallowed) {
337if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
338 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
339 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
346$filename = basename($fullpath_original_file);
347$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
350dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
351$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
354if (!file_exists($fullpath_original_file_osencoded)) {
355 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
356 print $langs->trans(
"ErrorFileDoesNotExists") .
' : ' .
dol_escape_htmltag($original_file);
361$hookmanager->initHooks(array(
'document'));
362$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
363 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
364 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
366$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
368 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
369 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
370 print
"ErrorDownloadDocumentHooks: ".$errors;
379if ($modulepart ==
'facture') {
380 $refname = basename(dirname($original_file).
"/");
381 if ($refname ==
'thumbs' || $refname ==
'temp') {
383 $refname = basename(dirname(dirname($original_file)).
"/");
386 $invoice = fetchObjectByElement(0, $modulepart, $refname);
388 if ($original_file == preg_replace(
'/facture\//',
'', $invoice->last_main_doc)) {
391 $action =
'DOC_DOWNLOAD';
392 if (GETPOSTISSET(
'attachement') ||
GETPOST(
'preview')) {
393 $action =
'DOC_PREVIEW';
396 dol_syslog(
"Print for action=".$action.
". Current counter of this non draft invoice is already ".$invoice->id.
", so file was already printed, so we regenerate the PDF to add mention DUPLICATA", LOG_DEBUG);
401 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture SET pos_print_counter = pos_print_counter + 1";
402 $sql .=
" WHERE rowid = ".((int) $invoice->id);
405 $invoice->pos_print_counter += 1;
411 if ($invoice->pos_print_counter == 2) {
413 $outputlangs->setDefaultLang(
GETPOST(
'lang'));
414 $outputlangs->loadLangs(array(
"admin",
"blockedlog"));
420 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
421 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
422 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
423 $moreparams = isset($moreparams) ? $moreparams :
null;
425 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
427 dol_syslog(
"Failed to regenerate PDF", LOG_WARNING);
432 $result = $invoice->call_trigger($action, $user);
436 http_response_code(500);
437 print
'Error in trigger: '.$invoice->errorsToString();
449header(
'Content-Description: File Transfer');
451 header(
'Content-Encoding: '.$encoding);
455if ($attachment > 0) {
456 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
457} elseif (empty($attachment)) {
458 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
461header(
'Cache-Control: Public, must-revalidate');
462header(
'Pragma: public');
469 $readfile = !$imgres;
478 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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 ECM files.
Class to manage invoices.
const STATUS_DRAFT
Draft status.
const STATUS_CLOSED
Classified paid.
Class to manage translations.
dol_filesize($pathoffile)
Return size of a file.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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...
correctExifImageOrientation($fileSource, $fileDest, $quality=95)
Add exif orientation correction for image.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.