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 ($modulepart ==
'fckeditor') {
159 $modulepart =
'medias';
163if ($user->socid > 0) {
164 $socid = $user->socid;
168if (in_array($modulepart, array(
'facture_paiement',
'unpaid'))) {
169 if (!$user->hasRight(
'societe',
'client',
'voir')) {
170 $original_file =
'private/'.$user->id.
'/'.$original_file;
190 if (
GETPOST(
'type',
'alpha') ==
'link') {
191 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
193 $result = $link->fetch(0, $hashp);
194 if ($result > 0 && !empty($link->url)) {
195 if (preg_match(
'/^(http|dav)/', $link->url)) {
196 header(
'Location: '.$link->url);
200 $langs->load(
"errors");
204 include_once DOL_DOCUMENT_ROOT .
'/ecm/class/ecmfiles.class.php';
206 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
208 $tmp = explode(
'/', $ecmfile->filepath, 2);
210 if (is_numeric($tmp[0])) {
211 $tmp = explode(
'/', $tmp[1], 2);
213 $moduleparttocheck = $tmp[0];
216 if ($moduleparttocheck == $modulepart) {
218 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
224 $modulepart = $moduleparttocheck;
225 $original_file = (($tmp[1] ? $tmp[1] .
'/' :
'') . $ecmfile->filename);
228 $entity = $ecmfile->entity;
229 if (
isModEnabled(
'multicompany') && !empty($ecmfile->src_object_type) && $ecmfile->src_object_id > 0) {
230 $object = fetchObjectByElement($ecmfile->src_object_id, $ecmfile->src_object_type);
231 if (is_object($object) &&
$object->id > 0) {
236 if ($entity !=
$conf->entity) {
237 $conf->entity = $entity;
243 $langs->load(
"errors");
251if (preg_match(
'/\.(html|htm)$/i', $original_file)) {
254if (isset($_GET[
"attachment"])) {
255 $attachment =
GETPOST(
"attachment",
'alpha') ? true :
false;
262$type =
'application/octet-stream';
264 $type =
GETPOST(
'type',
'alpha');
272 $type =
'application/octet-stream';
276$original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
277$original_file = str_replace(
'../',
'/', $original_file);
278$original_file = str_replace(
'..\\',
'/', $original_file);
281if (empty($modulepart)) {
287$accessallowed = $check_access[
'accessallowed'];
288$sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
289$fullpath_original_file = $check_access[
'original_file'];
294 $sqlprotectagainstexternals =
'';
297 if ($user->socid > 0) {
298 if ($sqlprotectagainstexternals) {
299 $resql =
$db->query($sqlprotectagainstexternals);
301 $num =
$db->num_rows($resql);
304 $obj =
$db->fetch_object($resql);
305 if ($user->socid != $obj->fk_soc) {
313 } elseif ($modulepart ==
'ticket' && !
getDolGlobalString(
'TICKET_EMAIL_MUST_EXISTS')) {
314 if ($sqlprotectagainstexternals) {
315 $resql =
$db->query($sqlprotectagainstexternals);
317 $num =
$db->num_rows($resql);
328if (!$accessallowed) {
334if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
335 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
336 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
343$filename = basename($fullpath_original_file);
344$filename = preg_replace(
'/\.noexe$/i',
'', $filename);
347dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
348$fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
351if (!file_exists($fullpath_original_file_osencoded)) {
352 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
353 print $langs->trans(
"ErrorFileDoesNotExists") .
' : ' .
dol_escape_htmltag($original_file);
358$hookmanager->initHooks(array(
'document'));
359$parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
360 'entity' => $entity,
'fullpath_original_file' => $fullpath_original_file,
361 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
363$reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters, $object, $action);
365 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').implode(
', ', $hookmanager->errors) :
'');
366 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
367 print
"ErrorDownloadDocumentHooks: ".$errors;
376if ($modulepart ==
'facture') {
377 $refname = basename(dirname($original_file).
"/");
378 if ($refname ==
'thumbs' || $refname ==
'temp') {
380 $refname = basename(dirname(dirname($original_file)).
"/");
383 $invoice = fetchObjectByElement(0, $modulepart, $refname);
385 if ($original_file == preg_replace(
'/facture\//',
'', $invoice->last_main_doc)) {
388 $action =
'DOC_DOWNLOAD';
390 $action =
'DOC_PREVIEW';
393 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);
398 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"facture SET pos_print_counter = pos_print_counter + 1";
399 $sql .=
" WHERE rowid = ".((int) $invoice->id);
402 $invoice->pos_print_counter += 1;
408 if ($invoice->pos_print_counter == 2) {
410 $outputlangs->setDefaultLang(
GETPOST(
'lang'));
411 $outputlangs->loadLangs(array(
"admin",
"blockedlog"));
417 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
418 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
419 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
420 $moreparams = isset($moreparams) ? $moreparams :
null;
422 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
424 dol_syslog(
"Failed to regenerate PDF", LOG_WARNING);
429 $result = $invoice->call_trigger($action, $user);
433 http_response_code(500);
434 print
'Error in trigger: '.$invoice->errorsToString();
446header(
'Content-Description: File Transfer');
448 header(
'Content-Encoding: '.$encoding);
452if ($attachment > 0) {
453 header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
454} elseif (empty($attachment)) {
455 header(
'Content-Disposition: inline; filename="'.$filename.
'"');
458header(
'Cache-Control: Public, must-revalidate');
459header(
'Pragma: public');
466 $readfile = !$imgres;
475 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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.