35 if (!defined(
'NOTOKENRENEWAL')) define(
'NOTOKENRENEWAL',
'1');
36 if (!defined(
'NOREQUIREMENU')) define(
'NOREQUIREMENU',
'1');
37 if (!defined(
'NOREQUIREHTML')) define(
'NOREQUIREHTML',
'1');
38 if (!defined(
'NOREQUIREAJAX')) define(
'NOREQUIREAJAX',
'1');
41 if (isset($_GET[
"hashp"]) && !defined(
"NOLOGIN"))
43 if (!defined(
"NOLOGIN")) define(
"NOLOGIN", 1);
44 if (!defined(
"NOCSRFCHECK")) define(
"NOCSRFCHECK", 1);
45 if (!defined(
"NOIPCHECK")) define(
"NOIPCHECK", 1);
48 if ((isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'medias'))
50 if (!defined(
"NOLOGIN")) define(
"NOLOGIN", 1);
51 if (!defined(
"NOCSRFCHECK")) define(
"NOCSRFCHECK", 1);
52 if (!defined(
"NOIPCHECK")) define(
"NOIPCHECK", 1);
74 require
'main.inc.php';
75 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
76 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
79 $action =
GETPOST(
'action',
'aZ09');
80 $original_file =
GETPOST(
'file',
'alphanohtml');
81 $hashp =
GETPOST(
'hashp',
'aZ09');
82 $modulepart =
GETPOST(
'modulepart',
'alpha');
83 $urlsource =
GETPOST(
'urlsource',
'alpha');
84 $entity =
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity;
87 if (empty($modulepart) && empty($hashp))
accessforbidden(
'Bad link. Bad value for parameter modulepart', 0, 0, 1);
88 if (empty($original_file) && empty($hashp))
accessforbidden(
'Bad link. Missing identification to find file (original_file or hashp)', 0, 0, 1);
89 if ($modulepart ==
'fckeditor') $modulepart =
'medias';
92 if ($user->socid > 0) $socid = $user->socid;
95 if (in_array($modulepart, array(
'facture_paiement',
'unpaid')))
97 if (!$user->rights->societe->client->voir || $socid) $original_file =
'private/'.$user->id.
'/'.$original_file;
116 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
118 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
121 $tmp = explode(
'/', $ecmfile->filepath, 2);
123 if (is_numeric($tmp[0]))
125 $tmp = explode(
'/', $tmp[1], 2);
127 $moduleparttocheck = $tmp[0];
131 if ($moduleparttocheck == $modulepart)
134 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
137 accessforbidden(
'Bad link. File is from another module part.', 0, 0, 1);
140 $modulepart = $moduleparttocheck;
141 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
144 $langs->load(
"errors");
145 accessforbidden($langs->trans(
"ErrorFileNotFoundWithSharedLink"), 0, 0, 1);
151 if (preg_match(
'/\.(html|htm)$/i', $original_file)) $attachment =
false;
152 if (isset($_GET[
"attachment"])) $attachment =
GETPOST(
"attachment",
'alpha') ?
true:
false;
153 if (!empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment =
false;
156 $type =
'application/octet-stream';
163 $type =
'application/octet-stream';
167 $original_file = str_replace(
"../",
"/", $original_file);
170 $refname = basename(dirname($original_file).
"/");
173 if (empty($modulepart))
accessforbidden(
'Bad value for parameter modulepart');
177 $accessallowed = $check_access[
'accessallowed'];
178 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
179 $fullpath_original_file = $check_access[
'original_file'];
185 $sqlprotectagainstexternals =
'';
188 if ($user->socid > 0)
190 if ($sqlprotectagainstexternals)
192 $resql = $db->query($sqlprotectagainstexternals);
195 $num = $db->num_rows(
$resql);
199 $obj = $db->fetch_object(
$resql);
200 if ($user->socid != $obj->fk_soc)
221 if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file))
223 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
224 print "ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
231 $filename = basename($fullpath_original_file);
232 $filename = preg_replace(
'/\.noexe$/i',
'', $filename);
235 dol_syslog(
"document.php download $fullpath_original_file filename=$filename content-type=$type");
236 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
239 if (!file_exists($fullpath_original_file_osencoded))
241 dol_syslog(
"ErrorFileDoesNotExists: ".$fullpath_original_file);
242 print "ErrorFileDoesNotExists: ".$original_file;
247 if (!is_object($hookmanager)) {
248 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
251 $hookmanager->initHooks(array(
'document'));
252 $parameters = array(
'ecmfile' => $ecmfile,
'modulepart' => $modulepart,
'original_file' => $original_file,
253 'entity' => $entity,
'refname' => $refname,
'fullpath_original_file' => $fullpath_original_file,
254 'filename' => $filename,
'fullpath_original_file_osencoded' => $fullpath_original_file_osencoded);
255 $reshook = $hookmanager->executeHooks(
'downloadDocument', $parameters);
257 $errors = $hookmanager->error.(is_array($hookmanager->errors) ? (!empty($hookmanager->error) ?
', ' :
'').join($separator, $hookmanager->errors) :
'');
258 dol_syslog(
"document.php - Errors when executing the hook 'downloadDocument' : ".$errors);
259 print "ErrorDownloadDocumentHooks: ".$errors;
265 header(
'Content-Description: File Transfer');
266 if ($encoding) header(
'Content-Encoding: '.$encoding);
268 if ($attachment) header(
'Content-Disposition: attachment; filename="'.$filename.
'"');
269 else header(
'Content-Disposition: inline; filename="'.$filename.
'"');
271 header(
'Cache-Control: Public, must-revalidate');
272 header(
'Pragma: public');
276 if (!$attachment && !empty($conf->global->MAIN_USE_EXIF_ROTATION) &&
image_format_supported($fullpath_original_file_osencoded) == 1) {
278 $readfile = !$imgres;
281 if (is_object($db)) $db->close();
285 header(
'Content-Length: '.
dol_filesize($fullpath_original_file));
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.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
correctExifImageOrientation($fileSource, $fileDest, $quality=95)
Add exif orientation correction for image.
dol_filesize($pathoffile)
Return size of a file.
$conf db
API class for accounts.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser= '', $refname= '', $mode= 'read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices) ...
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return mime type of a file.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Class to manage ECM files.