31 if (!defined(
'NOREQUIRESOC')) {
32 define(
'NOREQUIRESOC',
'1');
34 if (!defined(
'NOREQUIRETRAN')) {
35 define(
'NOREQUIRETRAN',
'1');
37 if (!defined(
'NOCSRFCHECK')) {
38 define(
'NOCSRFCHECK',
'1');
40 if (!defined(
'NOTOKENRENEWAL')) {
41 define(
'NOTOKENRENEWAL',
'1');
43 if (!defined(
'NOREQUIREMENU')) {
44 define(
'NOREQUIREMENU',
'1');
46 if (!defined(
'NOREQUIREHTML')) {
47 define(
'NOREQUIREHTML',
'1');
49 if (!defined(
'NOREQUIREAJAX')) {
50 define(
'NOREQUIREAJAX',
'1');
55 if (isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'mycompany' && preg_match(
'/^\/?logos\//', $_GET[
'file'])) {
56 if (!defined(
"NOLOGIN")) {
59 if (!defined(
"NOCSRFCHECK")) {
60 define(
"NOCSRFCHECK", 1);
62 if (!defined(
"NOIPCHECK")) {
63 define(
"NOIPCHECK", 1);
67 if (isset($_GET[
"hashp"]) && !defined(
"NOLOGIN")) {
68 if (!defined(
"NOLOGIN")) {
71 if (!defined(
"NOCSRFCHECK")) {
72 define(
"NOCSRFCHECK", 1);
74 if (!defined(
"NOIPCHECK")) {
75 define(
"NOIPCHECK", 1);
79 if (isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'medias') {
80 if (!defined(
"NOLOGIN")) {
83 if (!defined(
"NOCSRFCHECK")) {
84 define(
"NOCSRFCHECK", 1);
86 if (!defined(
"NOIPCHECK")) {
87 define(
"NOIPCHECK", 1);
92 if (isset($_GET[
"modulepart"]) && $_GET[
"modulepart"] ==
'product' && isset($_GET[
"publictakepos"])) {
93 if (!defined(
"NOLOGIN")) {
96 if (!defined(
"NOCSRFCHECK")) {
97 define(
"NOCSRFCHECK", 1);
99 if (!defined(
"NOIPCHECK")) {
100 define(
"NOIPCHECK", 1);
105 $entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
106 if (is_numeric($entity)) {
107 define(
"DOLENTITY", $entity);
129 require
'main.inc.php';
130 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
132 $action =
GETPOST(
'action',
'aZ09');
133 $original_file =
GETPOST(
'file',
'alphanohtml');
134 $hashp =
GETPOST(
'hashp',
'aZ09');
135 $modulepart =
GETPOST(
'modulepart',
'alpha');
136 $urlsource =
GETPOST(
'urlsource',
'alpha');
137 $entity =
GETPOST(
'entity',
'int') ?
GETPOST(
'entity',
'int') : $conf->entity;
140 if (empty($modulepart) && empty($hashp)) {
143 if (empty($original_file) && empty($hashp) && $modulepart !=
'barcode') {
146 if ($modulepart ==
'fckeditor') {
147 $modulepart =
'medias';
164 if (
GETPOST(
"cache",
'alpha')) {
167 if (empty($dolibarr_nocache)) {
168 header(
'Cache-Control: max-age=3600, public, must-revalidate');
169 header(
'Pragma: cache');
171 header(
'Cache-Control: no-cache');
177 if (!empty($hashp)) {
178 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
180 $result = $ecmfile->fetch(0,
'',
'',
'', $hashp);
182 $tmp = explode(
'/', $ecmfile->filepath, 2);
184 if (is_numeric($tmp[0])) {
185 $tmp = explode(
'/', $tmp[1], 2);
187 $moduleparttocheck = $tmp[0];
190 if ($moduleparttocheck == $modulepart) {
192 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
198 $modulepart = $moduleparttocheck;
199 $original_file = (($tmp[1] ? $tmp[1].
'/' :
'').$ecmfile->filename);
202 $langs->load(
"errors");
208 $type =
'application/octet-stream';
209 if (
GETPOST(
'type',
'alpha')) {
210 $type =
GETPOST(
'type',
'alpha');
216 if (preg_match(
'/html/i', $type)) {
220 if (preg_match(
'/\.noexe$/i', $original_file)) {
225 $original_file = preg_replace(
'/\.\.+/',
'..', $original_file);
226 $original_file = str_replace(
'../',
'/', $original_file);
227 $original_file = str_replace(
'..\\',
'/', $original_file);
230 $refname = basename(dirname($original_file).
"/");
231 if ($refname ==
'thumbs') {
233 $refname = basename(dirname(dirname($original_file)).
"/");
242 if (empty($modulepart)) {
248 if ($modulepart ===
'medias' && $entity != $conf->entity) {
249 $conf->entity = $entity;
250 $conf->setValues($db);
254 $accessallowed = $check_access[
'accessallowed'];
255 $sqlprotectagainstexternals = $check_access[
'sqlprotectagainstexternals'];
256 $fullpath_original_file = $check_access[
'original_file'];
258 if (!empty($hashp)) {
260 $sqlprotectagainstexternals =
'';
261 } elseif (isset($_GET[
"publictakepos"])) {
262 if (!empty($conf->global->TAKEPOS_AUTO_ORDER)) {
267 if ($user->socid > 0) {
268 if ($sqlprotectagainstexternals) {
269 $resql = $db->query($sqlprotectagainstexternals);
271 $num = $db->num_rows(
$resql);
274 $obj = $db->fetch_object(
$resql);
275 if ($user->socid != $obj->fk_soc) {
288 if (!$accessallowed) {
294 if (preg_match(
'/\.\./', $fullpath_original_file) || preg_match(
'/[<>|]/', $fullpath_original_file)) {
295 dol_syslog(
"Refused to deliver file ".$fullpath_original_file);
296 print
"ErrorFileNameInvalid: ".dol_escape_htmltag($original_file);
302 if ($modulepart ==
'barcode') {
303 $generator =
GETPOST(
"generator",
"aZ09");
304 $encoding =
GETPOST(
"encoding",
"aZ09");
305 $readable =
GETPOST(
"readable",
'aZ09') ?
GETPOST(
"readable",
"aZ09") :
"Y";
306 if (in_array($encoding, array(
'EAN8',
'EAN13'))) {
307 $code =
GETPOST(
"code",
'alphanohtml');
309 $code =
GETPOST(
"code",
'restricthtml');
312 if (empty($generator) || empty($encoding)) {
313 print
'Error: Parameter "generator" or "encoding" not defined';
317 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
321 foreach ($dirbarcode as $reldir) {
326 if (!is_dir($newdir)) {
330 $result = @include_once $newdir.$generator.
'.modules.php';
337 $classname =
"mod".ucfirst($generator);
338 $module =
new $classname($db);
339 if ($module->encodingIsSupported($encoding)) {
340 $result = $module->buildBarCode($code, $encoding, $readable);
346 $filename = basename($fullpath_original_file);
349 dol_syslog(
"viewimage.php return file $fullpath_original_file filename=$filename content-type=$type");
352 if (!
dol_is_file($fullpath_original_file) && empty($_GET[
"noalt"])) {
353 $fullpath_original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/nophoto.png';
362 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
365 header(
'Content-Disposition: inline; filename="'.basename($fullpath_original_file).
'"');
368 $fullpath_original_file_osencoded =
dol_osencode($fullpath_original_file);
370 readfile($fullpath_original_file_osencoded);
374 if (is_object($db)) {
Class to manage ECM files.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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 to g...
dol_is_file($pathoffile)
Return if path is a file.
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)
Return value of a param into GET or POST supervariable.
dolIsAllowedForPreview($file)
Return if a file is qualified for preview.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined('NOREQUIREMENU')) 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.
if(is_numeric($entity)) llxHeader()
Header empty.