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);
103function llxHeader($head =
'', $title =
'', $help_url =
'', $target =
'', $disablejs = 0, $disablehead = 0, $arrayofjs =
'', $arrayofcss =
'', $morequerystring =
'', $morecssonbody =
'', $replacemainareaby =
'', $disablenofollow = 0, $disablenoindex = 0)
118function llxFooter($comment =
'', $zone =
'private', $disabledoutputofmessages = 0)
122require
'main.inc.php';
130require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
131require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
134$action =
GETPOST(
'action',
'aZ09');
135$original_file =
GETPOST(
'file',
'alphanohtml');
136$hashp =
GETPOST(
'hashp',
'aZ09');
137$modulepart =
GETPOST(
'modulepart',
'alpha');
138$urlsource =
GETPOST(
'urlsource',
'alpha');
139$entity = GETPOSTISSET(
'entity') ?
GETPOSTINT(
'entity') :
$conf->entity;
142if (empty($modulepart) && empty($hashp)) {
145if (empty($original_file) && empty($hashp)) {
148if ($modulepart ==
'fckeditor') {
149 $modulepart =
'medias';
153if ($user->socid > 0) {
154 $socid = $user->socid;
158if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
159 if (!$user->hasRight(
'societe',
'client',
'voir')) {
160 $original_file =
'private/'.$user->id.
'/'.$original_file;
180 if (
GETPOST(
'type',
'alpha') ==
'link') {
181 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
183 $result = $link->fetch(0, $hashp);
184 if ($result > 0 && !empty($link->url)) {
185 if (preg_match(
'/^(http|dav)/', $link->url)) {
186 header(
'Location: '.$link->url);
190 $langs->load(
"errors");
194 include_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
196 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
198 $tmp = explode(
'/', $ecmfile->filepath, 2);
200 if (is_numeric($tmp[0])) {
201 $tmp = explode(
'/', $tmp[1], 2);
203 $moduleparttocheck = $tmp[0];
206 if ($moduleparttocheck == $modulepart) {
208 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
214 $modulepart = $moduleparttocheck;
215 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
218 $entity = $ecmfile->entity;
219 if (
isModEnabled(
'multicompany') && !empty($ecmfile->src_object_type) && $ecmfile->src_object_id > 0) {
220 $object = fetchObjectByElement($ecmfile->src_object_id, $ecmfile->src_object_type);
221 if (is_object($object) &&
$object->id > 0) {
226 if ($entity !=
$conf->entity) {
227 $conf->entity = $entity;
231 $langs->load(
"errors");
239if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
242if (isset($_GET[
"attachment"])) {
243 $attachment =
GETPOST(
"attachment",
'alpha') ? true :
false;
250$type =
'application/octet-stream';
252 $type =
GETPOST(
'type',
'alpha');
254 $type = dol_mimetype($original_file);
259if (!in_array($type, array(
'text/x-javascript')) && !dolIsAllowedForPreview($original_file)) {
260 $type =
'application/octet-stream';
264$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
265$original_file = str_replace(
'../',
'/', $original_file);
266$original_file = str_replace(
'..\\',
'/', $original_file);
269if (empty($modulepart)) {
275$accessallowed = $check_access[
'accessallowed'];
276$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
277$fullpath_original_file = $check_access[
'original_file'];
282 $sqlprotectagainstexternals =
'';
285 if ($user->socid > 0) {
286 if ($sqlprotectagainstexternals) {
287 $resql =
$db->query($sqlprotectagainstexternals);
289 $num =
$db->num_rows($resql);
292 $obj =
$db->fetch_object($resql);
293 if ($user->socid != $obj->fk_soc) {
301 } elseif ($modulepart ==
'ticket' && !
getDolGlobalString(
'TICKET_EMAIL_MUST_EXISTS')) {
302 if ($sqlprotectagainstexternals) {
303 $resql =
$db->query($sqlprotectagainstexternals);
305 $num =
$db->num_rows($resql);
316if (!$accessallowed) {
322if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
323 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
324 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
331$filename = basename($fullpath_original_file);
332$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
335dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
336$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
339if (!file_exists($fullpath_original_file_osencoded)) {
340 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
341 print $langs->trans(
"ErrorFileDoesNotExists") .
' : ' .
dol_escape_htmltag($original_file);
346$hookmanager->initHooks(array(
'document'));
347$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
348 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
349 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
351$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
353 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
354 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
355 print
"ErrorDownloadDocumentHooks: ".$errors;
364if ($modulepart ==
'facture') {
365 $refname = basename(dirname($original_file).
"/");
366 if ($refname ==
'thumbs' || $refname ==
'temp') {
368 $refname = basename(dirname(dirname($original_file)).
"/");
371 $invoice = fetchObjectByElement(0, $modulepart, $refname);
373 if ($original_file == preg_replace(
'/facture\//',
'', $invoice->last_main_doc)) {
376 $action =
'DOC_DOWNLOAD';
377 if (GETPOSTISSET(
'attachement') ||
GETPOST(
'preview')) {
378 $action =
'DOC_PREVIEW';
381 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);
386 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture SET pos_print_counter = pos_print_counter + 1";
387 $sql .=
" WHERE rowid = ".((int) $invoice->id);
390 $invoice->pos_print_counter += 1;
396 if ($invoice->pos_print_counter == 2) {
398 $outputlangs->setDefaultLang(
GETPOST(
'lang'));
399 $outputlangs->loadLangs(array(
"admin",
"blockedlog"));
405 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
406 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
407 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
408 $moreparams = isset($moreparams) ? $moreparams :
null;
410 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
412 dol_syslog(
"Failed to regenerate PDF", LOG_WARNING);
417 $result = $invoice->call_trigger($action, $user);
421 http_response_code(500);
422 print
'Error in trigger: '.$invoice->errorsToString();
434header(
'Content-Description: File Transfer');
436 header(
'Content-Encoding: '.$encoding);
440if ($attachment > 0) {
441 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
442} elseif (empty($attachment)) {
443 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
446header(
'Cache-Control: Public, must-revalidate');
447header(
'Pragma: public');
454 $readfile = !$imgres;
463 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
465 readfileLowMemory($fullpath_original_file_osencoded);
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...
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.