64function dol_dir_list($utf8_path, $types =
"all", $recursive = 0, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename =
"", $donotfollowsymlinks = 0, $nbsecondsold = 0)
69 if ($recursive <= 1) {
74 if (!empty($filter) && !is_array($filter)) {
75 if (strlen($filter) > 25000) {
76 dol_syslog(
"Value for filter is too large", LOG_ERR);
80 if ((
int) preg_match(
'/(?:^|[^\\\\])\//', $filter) > 0) {
81 $excludefilter_ok =
false;
82 $error_info .=
" error='filter_has_unescaped_slash'";
83 dol_syslog(
"'$filter' has unescaped '/'", LOG_ERR);
89 $excludefilter_ok =
true;
90 $exclude_array = ($excludefilter ===
null || $excludefilter ===
'') ? array() : (is_array($excludefilter) ? $excludefilter : array($excludefilter));
91 foreach ($exclude_array as $f) {
93 if ((
int) preg_match(
'/(?:^|[^\\\\])\//', $f) > 0) {
94 $excludefilter_ok =
false;
95 $error_info .=
" error='excludefilter_has_unescaped_slash'";
100 dol_syslog(
"files.lib.php::dol_dir_list path=".$utf8_path.
" types=".$types.
" recursive=".$recursive.
" filter=".json_encode($filter).
" excludefilter=".json_encode($excludefilter).$error_info);
102 if (!$filter_ok || !$excludefilter_ok) {
108 $exclude_array = ($excludefilter ===
null || $excludefilter ===
'') ? array() : (is_array($excludefilter) ? $excludefilter : array($excludefilter));
112 $excludefilterarray = array_merge(array(
'^\.'), $exclude_array);
114 $loaddate = ($mode == 1 || $mode == 2 || $nbsecondsold != 0 || $sortcriteria ==
'date');
115 $loadsize = ($mode == 1 || $mode == 3 || $sortcriteria ==
'size');
116 $loadperm = ($mode == 1 || $mode == 4 || $sortcriteria ==
'perm');
120 $file_list = array();
123 $utf8_path = preg_replace(
'/([\\/]+)$/',
'', $utf8_path);
125 if (preg_match(
'/\*/', $utf8_path)) {
126 $utf8_path_array = glob($utf8_path, GLOB_ONLYDIR);
129 $utf8_path_array = array($utf8_path);
132 foreach ($utf8_path_array as $utf8_path_cursor) {
134 if (!$nohook && $hookmanager instanceof
HookManager) {
135 $hookmanager->resArray = array();
137 $hookmanager->initHooks(array(
'fileslib'));
142 'recursive' => $recursive,
144 'excludefilter' => $exclude_array,
145 'sortcriteria' => $sortcriteria,
146 'sortorder' => $sortorder,
147 'loaddate' => $loaddate,
148 'loadsize' => $loadsize,
151 $reshook = $hookmanager->executeHooks(
'getDirList', $parameters,
$object);
155 if (empty($reshook)) {
156 if (!is_dir($os_path)) {
160 if (($dir = opendir($os_path)) ===
false) {
168 while (
false !== ($os_file = readdir($dir))) {
169 $os_fullpathfile = ($os_path ? $os_path.
'/' :
'').$os_file;
172 $utf8_file = mb_convert_encoding($os_file,
'UTF-8',
'ISO-8859-1');
174 $utf8_file = $os_file;
177 $utf8_fullpathfile = $utf8_path_cursor.
"/".$utf8_file;
181 foreach ($excludefilterarray as $filt) {
182 if (preg_match(
'/'.$filt.
'/i', $utf8_file) || preg_match(
'/'.$filt.
'/i', $utf8_fullpathfile)) {
190 $isdir = is_dir($os_fullpathfile);
194 if (($types ==
"directories") || ($types ==
"all")) {
195 if ($loaddate || $sortcriteria ==
'date') {
198 if ($loadsize || $sortcriteria ==
'size') {
201 if ($loadperm || $sortcriteria ==
'perm') {
205 $qualifiedforfilter = 0;
206 if (empty($filter)) {
207 $qualifiedforfilter = 1;
209 $testpregmatch =
false;
210 if (is_array($filter)) {
211 $chunks = array_chunk($filter, 500);
212 foreach ($chunks as $chunk) {
213 $testpregmatch = preg_match(
'/'.implode(
'|', $chunk).
'/i', $utf8_file);
214 if ($testpregmatch) {
219 $testpregmatch = preg_match(
'/'.$filter.
'/i', $utf8_file);
221 if ($testpregmatch) {
222 $qualifiedforfilter = 1;
226 if ($qualifiedforfilter) {
228 preg_match(
'/([^\/]+)\/[^\/]+$/', $utf8_fullpathfile, $reg);
229 $level1name = (isset($reg[1]) ? $reg[1] :
'');
230 $file_list[] = array(
231 "name" => $utf8_file,
232 "path" => $utf8_path,
233 "level1name" => $level1name,
234 "relativename" => ($relativename ? $relativename.
'/' :
'').$utf8_file,
235 "fullname" => $utf8_fullpathfile,
245 if ($recursive > 0) {
246 if (empty($donotfollowsymlinks) || !is_link($os_fullpathfile)) {
248 $file_list = array_merge($file_list,
dol_dir_list($utf8_fullpathfile, $types, $recursive + 1, $filter, $exclude_array, $sortcriteria, $sortorder, $mode, $nohook, ($relativename !=
'' ? $relativename.
'/' :
'').$utf8_file, $donotfollowsymlinks, $nbsecondsold));
251 } elseif (in_array($types, array(
"files",
"all"))) {
253 if ($loaddate || $sortcriteria ==
'date') {
256 if ($loadsize || $sortcriteria ==
'size') {
260 $qualifiedforfilter = 0;
261 if (empty($filter)) {
262 $qualifiedforfilter = 1;
264 $testpregmatch =
false;
265 if (is_array($filter)) {
266 $chunks = array_chunk($filter, 500);
267 foreach ($chunks as $chunk) {
268 $testpregmatch = preg_match(
'/'.implode(
'|', $chunk).
'/i', $utf8_file);
269 if ($testpregmatch) {
274 $testpregmatch = preg_match(
'/'.$filter.
'/i', $utf8_file);
276 if ($testpregmatch) {
277 $qualifiedforfilter = 1;
281 if ($qualifiedforfilter) {
282 if (empty($nbsecondsold) || $filedate <= ($now - $nbsecondsold)) {
283 preg_match(
'/([^\/]+)\/[^\/]+$/', $utf8_fullpathfile, $reg);
284 $level1name = (isset($reg[1]) ? $reg[1] :
'');
285 $file_list[] = array(
286 "name" => $utf8_file,
287 "path" => $utf8_path,
288 "level1name" => $level1name,
289 "relativename" => ($relativename ? $relativename.
'/' :
'').$utf8_file,
290 "fullname" => $utf8_fullpathfile,
305 if (!empty($sortcriteria) && $sortorder) {
306 $file_list =
dol_sort_array($file_list, $sortcriteria, ($sortorder == SORT_ASC ?
'asc' :
'desc'));
309 if ($hookmanager instanceof
HookManager && is_array($hookmanager->resArray)) {
310 $file_list = array_merge($file_list, $hookmanager->resArray);
1112function dol_move($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array(), $entity =
null)
1117 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
1122 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
1126 if ($overwriteifexists || !$destexists) {
1131 $testvirusarray = array();
1134 $testvirusarray =
dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
1135 if (count($testvirusarray)) {
1136 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1142 if (count($testvirusarray)) {
1143 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1148 global $dolibarr_main_restrict_os_commands;
1149 if (!empty($dolibarr_main_restrict_os_commands)) {
1150 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1151 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1152 if (in_array(basename($destfile), $arrayofallowedcommand)) {
1155 dol_syslog(
"files.lib.php::dol_move canceled because target filename ".basename($destfile).
" is using a reserved command name. we ignore the move request.", LOG_WARNING);
1160 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1163 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
1166 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1168 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1173 if ($result && $indexdatabase) {
1175 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1176 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1177 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1178 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1179 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1182 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1183 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1185 $ecmfiletarget =
new EcmFiles($db);
1186 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter,
'',
'',
'', 0, $entity);
1187 if ($resultecmtarget > 0) {
1188 $ecmfiletarget->delete($user);
1192 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore,
'',
'',
'', 0, $entity);
1193 if ($resultecm > 0) {
1194 $filename = basename($rel_filetorenameafter);
1195 $rel_dir = dirname($rel_filetorenameafter);
1196 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1197 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1199 $ecmfile->filepath = $rel_dir;
1200 $ecmfile->filename = $filename;
1202 $resultecm = $ecmfile->update($user);
1203 } elseif ($resultecm == 0) {
1204 $filename = basename($rel_filetorenameafter);
1205 $rel_dir = dirname($rel_filetorenameafter);
1206 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1207 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1209 $ecmfile->filepath = $rel_dir;
1210 $ecmfile->filename = $filename;
1212 $ecmfile->fullpath_orig = basename($srcfile);
1213 if (!empty($moreinfo) && !empty($moreinfo[
'gen_or_uploaded'])) {
1214 $ecmfile->gen_or_uploaded = $moreinfo[
'gen_or_uploaded'];
1216 $ecmfile->gen_or_uploaded =
'unknown';
1218 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1219 $ecmfile->description = $moreinfo[
'description'];
1221 $ecmfile->description =
'';
1223 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1224 $ecmfile->keywords = $moreinfo[
'keywords'];
1226 $ecmfile->keywords =
'';
1228 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1229 $ecmfile->note_private = $moreinfo[
'note_private'];
1231 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1232 $ecmfile->note_public = $moreinfo[
'note_public'];
1234 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1235 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1237 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1238 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1240 if (!empty($moreinfo) && !empty($moreinfo[
'position'])) {
1241 $ecmfile->position = $moreinfo[
'position'];
1243 if (!empty($moreinfo) && !empty($moreinfo[
'cover'])) {
1244 $ecmfile->cover = $moreinfo[
'cover'];
1246 if (! empty($entity)) {
1247 $ecmfile->entity = $entity;
1250 $resultecm = $ecmfile->create($user);
1251 if ($resultecm < 0) {
1254 if (!empty($moreinfo) && !empty($moreinfo[
'array_options']) && is_array($moreinfo[
'array_options'])) {
1255 $ecmfile->array_options = $moreinfo[
'array_options'];
1256 $resultecm = $ecmfile->insertExtraFields();
1257 if ($resultecm < 0) {
1262 } elseif ($resultecm < 0) {
1266 if ($resultecm > 0) {
1274 if (empty($newmask)) {
1281 dolChmod($newpathofdestfile, $newmask);
2013function dol_add_file_process($upload_dir, $allowoverwrite = 0, $updatesessionordb = 0, $keyforsourcefile =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1,
$object =
null, $forceFullTextIndexation =
'', $mode = 0)
2015 global $db, $user, $conf, $langs;
2021 $_FILES = array($keyforsourcefile => array());
2022 $_FILES[$keyforsourcefile][
'tmp_name'] = $keyforsourcefile;
2023 $_FILES[$keyforsourcefile][
'name'] = $keyforsourcefile;
2027 if (!empty($_FILES[$keyforsourcefile])) {
2028 dol_syslog(
'dol_add_file_process varfiles = '.$keyforsourcefile.
' upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' updatesessionordb='.$updatesessionordb.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
2029 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
2030 if (is_array($_FILES[$keyforsourcefile][
"name"]) && count($_FILES[$keyforsourcefile][
"name"]) > $maxfilesinform) {
2031 $langs->load(
"errors");
2032 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
2040 $TFile = $_FILES[$keyforsourcefile];
2042 if (!is_array($TFile[
'name'])) {
2043 foreach ($TFile as $key => &$val) {
2048 $nbfile = count($TFile[
'name']);
2050 for ($i = 0; $i < $nbfile; $i++) {
2051 if (empty($TFile[
'name'][$i])) {
2056 $destfile = trim($TFile[
'name'][$i]);
2057 $destfull = $upload_dir.
"/".$destfile;
2058 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
2060 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
2061 $destfile = trim(preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask));
2062 $destfull = $upload_dir.
"/".$destfile;
2065 $filenameto = basename($destfile);
2066 if (preg_match(
'/^\./', $filenameto)) {
2067 $langs->load(
"errors");
2068 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
2072 $info = pathinfo($destfull);
2073 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
2074 $info = pathinfo($destfile);
2075 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
2080 $defaultexecutableextensions = function_exists(
'getExecutableContent') ? implode(
',',
getExecutableContent()) :
'htm,html,shtml,js,phar,php,php3,php4,php5,phtml,pht,pl,py,cgi,ksh,sh,bash,bat,cmd,wpk,exe';
2081 $fileextensionrestriction =
getDolGlobalString(
"MAIN_FILE_EXTENSION_UPLOAD_RESTRICTION", $defaultexecutableextensions);
2082 if (!empty($fileextensionrestriction)) {
2083 $arrayofregexextension = explode(
",", $fileextensionrestriction);
2085 foreach ($arrayofregexextension as $fileextension) {
2086 if (preg_match(
'/\.'.preg_quote(trim($fileextension),
'/').
'$/i', $destfull)) {
2087 $langs->load(
"errors");
2088 setEventMessages($langs->trans(
"ErrorFilenameExtensionNotAllowed", $filenameto),
null,
'errors');
2100 global $dolibarr_main_restrict_os_commands;
2101 if (!empty($dolibarr_main_restrict_os_commands)) {
2102 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
2103 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
2104 if (in_array($destfile, $arrayofallowedcommand)) {
2105 $langs->load(
"errors");
2106 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
2112 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $keyforsourcefile, $upload_dir, $mode);
2114 if (is_numeric($resupload) && $resupload > 0) {
2115 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2118 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
2119 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
2120 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
2121 $maxheightmini = $tmparraysize[
'maxheightmini'];
2126 if ($generatethumbs) {
2132 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
2135 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
2140 if (empty($updatesessionordb)) {
2141 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2143 $formmail->trackid = $trackid;
2144 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
2148 if ($updatesessionordb == 1) {
2150 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false &&
getDolGlobalString(
'PRODUCT_ALLOW_EXTERNAL_DOWNLOAD')) {
2155 if ($allowoverwrite) {
2159 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile,
$object, $forceFullTextIndexation);
2161 if ($allowoverwrite) {
2164 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
2171 $langs->load(
"errors");
2172 if (is_numeric($resupload) && $resupload < 0) {
2174 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
2175 if (preg_match(
'/File is a PDF with javascript inside/', $resupload)) {
2176 setEventMessages($langs->trans(
"ErrorFileIsAnInfectedPDFWithJSInside"),
null,
'errors');
2190 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
2193 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2194 $linkObject =
new Link($db);
2195 $linkObject->entity = $conf->entity;
2196 $linkObject->url = $link;
2197 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
2198 $linkObject->objectid =
GETPOSTINT(
'objectid');
2199 $linkObject->label =
GETPOST(
'label',
'alpha');
2200 $res = $linkObject->create($user);
2208 $langs->load(
"errors");
2209 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
2977 global $conf, $db, $user, $hookmanager;
2978 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2981 if (!is_object($fuser)) {
2985 if (empty($modulepart)) {
2986 return 'ErrorBadParameter';
2988 if (empty($entity)) {
2996 if ($modulepart ==
'facture') {
2997 $modulepart =
'invoice';
2998 } elseif ($modulepart ==
'users') {
2999 $modulepart =
'user';
3000 } elseif ($modulepart ==
'tva') {
3001 $modulepart =
'tax-vat';
3002 } elseif ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
3004 $modulepart =
'delivery';
3005 } elseif ($modulepart ==
'propale') {
3006 $modulepart =
'propal';
3010 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
3014 $sqlprotectagainstexternals =
'';
3018 if (empty($refname)) {
3019 $refname = basename(dirname($original_file).
"/");
3020 if ($refname ==
'thumbs' || $refname ==
'temp') {
3022 $refname = basename(dirname(dirname($original_file)).
"/");
3029 $download =
'download';
3030 if ($mode ==
'write') {
3033 $download =
'upload';
3037 if ($modulepart ==
'common') {
3040 $original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/'.$original_file;
3041 } elseif ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
3046 if (empty($entity)) {
3050 $original_file = (empty($conf->medias->multidir_output[$entity]) ? (empty($conf->medias->dir_output) ? DOL_DATA_ROOT.
'/medias' : $conf->medias->dir_output) : $conf->medias->multidir_output[$entity]).
'/'.$original_file;
3051 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
3053 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
3054 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
3055 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
3056 $accessallowed = $user->admin;
3057 $relative_file = $original_file;
3058 $ent = ($entity > 0 ? $entity : $conf->entity);
3059 $path_with_entity = $dolibarr_main_data_root .
'/' . $ent .
'/doctemplates/' . $relative_file;
3060 if ($ent > 1 && file_exists(
dol_osencode($path_with_entity))) {
3061 $original_file = $path_with_entity;
3063 $original_file = $dolibarr_main_data_root .
'/doctemplates/' . $relative_file;
3065 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
3067 $accessallowed = ($fuser->hasRight(
'website',
'write') && preg_match(
'/\.jpg$/i', basename($original_file)));
3068 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
3069 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
3072 $tmp = explode(
',', $dolibarr_main_document_root_alt);
3075 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
3076 $original_file = $dirins.
'/'.$original_file;
3077 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
3080 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
3081 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
3084 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
3087 $original_file = $conf->user->dir_output.
'/'.$original_file;
3088 } elseif ($modulepart ==
'userphotopublic' && !empty($conf->user->dir_output)) {
3093 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
3094 if ((
int) $reg[1]) {
3095 $tmpobject =
new User($db);
3096 $tmpobject->fetch((
int) $reg[1],
'',
'', 1);
3098 $securekey =
GETPOST(
'securekey',
'alpha', 1);
3100 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
3101 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
3102 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
3103 if ($encodedsecurekey == $securekey) {
3112 $original_file = $conf->user->dir_output.
'/'.$original_file;
3113 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
3116 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
3117 } elseif ($modulepart ==
'memberphoto' && !empty($conf->member->dir_output)) {
3121 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
3125 if (preg_match(
'/^MEM\d\d\d\d-\d\d\d\d\/photos\//', $original_file)) {
3128 $original_file = $conf->member->dir_output.
'/'.$original_file;
3129 } elseif ($modulepart ==
'apercufacture' && !empty($conf->invoice->multidir_output[$entity])) {
3131 if ($fuser->hasRight(
'facture', $lire)) {
3134 $original_file = $conf->invoice->multidir_output[$entity].
'/'.$original_file;
3135 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
3137 if ($fuser->hasRight(
'propal', $lire)) {
3140 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3141 } elseif ($modulepart ==
'apercucommande' && !empty($conf->order->multidir_output[$entity])) {
3143 if ($fuser->hasRight(
'commande', $lire)) {
3146 $original_file = $conf->order->multidir_output[$entity].
'/'.$original_file;
3147 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->dir_output)) {
3149 if ($fuser->hasRight(
'ficheinter', $lire)) {
3152 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
3153 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contract->multidir_output[$entity])) {
3155 if ($fuser->hasRight(
'contrat', $lire)) {
3158 $original_file = $conf->contract->multidir_output[$entity].
'/'.$original_file;
3159 } elseif (($modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
3161 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
3164 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
3165 } elseif (($modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
3167 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3170 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3171 } elseif (($modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
3173 if ($fuser->hasRight(
'fournisseur', $lire)) {
3176 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3177 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
3178 if ($fuser->hasRight(
'holiday', $read) || $fuser->hasRight(
'holiday',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3181 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3182 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
3183 $tmpholiday =
new Holiday($db);
3184 $tmpholiday->fetch(0, $refname);
3185 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
3188 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
3189 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
3190 if ($fuser->hasRight(
'expensereport', $lire) || $fuser->hasRight(
'expensereport',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3193 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3194 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
3196 $tmpexpensereport->fetch(0, $refname);
3197 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
3200 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
3201 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
3203 if ($fuser->hasRight(
'expensereport', $lire)) {
3206 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
3207 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
3209 if ($fuser->hasRight(
'propal', $lire)) {
3212 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
3213 } elseif ($modulepart ==
'orderstats' && !empty($conf->order->dir_temp)) {
3215 if ($fuser->hasRight(
'commande', $lire)) {
3218 $original_file = $conf->order->dir_temp.
'/'.$original_file;
3219 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
3220 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3223 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
3224 } elseif ($modulepart ==
'billstats' && !empty($conf->invoice->dir_temp)) {
3226 if ($fuser->hasRight(
'facture', $lire)) {
3229 $original_file = $conf->invoice->dir_temp.
'/'.$original_file;
3230 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
3231 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
3234 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
3235 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
3237 if ($fuser->hasRight(
'expedition', $lire)) {
3240 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
3241 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
3243 if ($fuser->hasRight(
'deplacement', $lire)) {
3246 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
3247 } elseif ($modulepart ==
'memberstats' && !empty($conf->member->dir_temp)) {
3249 if ($fuser->hasRight(
'adherent', $lire)) {
3252 $original_file = $conf->member->dir_temp.
'/'.$original_file;
3253 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
3255 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
3258 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
3259 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
3261 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
3264 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
3265 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
3266 } elseif (($modulepart ==
'actions' || $modulepart ==
'actioncomm') && !empty($conf->agenda->dir_output)) {
3268 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3271 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3272 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3274 $tmpobject->fetch((
int) $refname);
3275 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3276 if ($user->socid && $tmpobject->socid) {
3281 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
3282 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
3284 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
3285 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3287 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
3290 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
3291 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
3293 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3296 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
3297 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
3300 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
3301 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
3304 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
3305 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
3308 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
3309 } elseif ($modulepart ==
'barcode') {
3314 $original_file =
'';
3315 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
3318 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
3319 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3322 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3323 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
3326 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3327 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
3329 $canreaduser = (!empty($fuser->admin) || $fuser->hasRight(
'user',
'user', $lire));
3330 if ($fuser->id == (
int) $refname) {
3333 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3336 $original_file = $conf->user->dir_output.
'/'.$original_file;
3337 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
3339 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
3340 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3342 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3345 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
3346 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
3347 } elseif (($modulepart ==
'contact' || $modulepart ==
'socpeople') && !empty($conf->societe->multidir_output[$entity])) {
3349 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
3350 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3352 if ($fuser->hasRight(
'societe', $lire)) {
3355 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3356 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->invoice->multidir_output[$entity])) {
3358 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3361 $original_file = $conf->invoice->multidir_output[$entity].
'/'.$original_file;
3362 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3363 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
3365 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3368 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3369 } elseif ($modulepart ==
'massfilesarea_orders') {
3370 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3373 $original_file = $conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3374 } elseif ($modulepart ==
'massfilesarea_sendings') {
3375 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3378 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3379 } elseif ($modulepart ==
'massfilesarea_receipts') {
3380 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3383 $original_file = $conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3384 } elseif ($modulepart ==
'massfilesarea_invoices') {
3385 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3388 $original_file = $conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3389 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3390 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3393 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3394 } elseif ($modulepart ==
'massfilesarea_interventions') {
3395 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3398 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3399 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
3400 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3403 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3404 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3405 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3408 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3409 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3410 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3413 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3414 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contract->dir_output)) {
3415 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3418 $original_file = $conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3419 } elseif ($modulepart ==
'massfilesarea_stock' && !empty($conf->stock->dir_output)) {
3420 if ($fuser->hasRight(
'stock', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3423 $original_file = $conf->stock->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3424 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->dir_output)) {
3426 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3429 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
3430 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3431 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
3433 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3436 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
3438 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset($conf->propal->multidir_output[$entity])) {
3440 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3443 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3444 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3445 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->order->multidir_output[$entity])) {
3447 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3450 $original_file = $conf->order->multidir_output[$entity].
'/'.$original_file;
3451 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3452 } elseif ($modulepart ==
'project' && !empty($conf->project->multidir_output[$entity])) {
3454 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3457 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3458 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3459 $tmpproject =
new Project($db);
3460 $tmpproject->fetch(0, $refname);
3461 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3464 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3465 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3466 } elseif ($modulepart ==
'project_task' && !empty($conf->project->multidir_output[$entity])) {
3467 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3470 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3471 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3472 $tmptask =
new Task($db);
3473 $tmptask->fetch(0, $refname);
3474 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3477 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3478 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3479 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
3481 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3484 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3485 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3486 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
3488 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3491 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3492 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3493 } elseif ($modulepart ==
'supplier_payment') {
3495 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3498 $original_file = preg_replace(
"/payment\//",
"", $original_file);
3499 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
3500 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3501 } elseif ($modulepart ==
'payment') {
3503 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3506 $original_file = $conf->compta->payment->dir_output.
'/'.$original_file;
3507 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->invoice->dir_output)) {
3509 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3512 if ($fuser->socid > 0) {
3513 $original_file = $conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3515 $original_file = $conf->invoice->dir_output.
'/payments/'.$original_file;
3517 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
3519 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3522 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
3523 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment' || $modulepart ==
'shipping') && !empty($conf->expedition->dir_output)) {
3525 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3528 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3530 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
3532 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3535 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3536 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
3538 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3541 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
3542 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3544 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
3545 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3547 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3551 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
3553 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
3555 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3557 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
3558 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3560 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3564 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3566 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3568 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3569 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3571 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3575 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3577 } elseif ($modulepart ==
'entrepot') {
3579 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3580 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3582 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3586 $original_file = $conf->stock->multidir_output[$entity].
'/'.$original_file;
3588 } elseif ($modulepart ==
'contract' && !empty($conf->contract->multidir_output[$entity])) {
3590 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3593 $original_file = $conf->contract->multidir_output[$entity].
'/'.$original_file;
3594 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3595 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
3597 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3600 $original_file = $conf->don->dir_output.
'/'.$original_file;
3601 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
3603 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3606 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3607 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3609 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3612 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3613 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3615 if ($fuser->hasRight(
'banque', $lire)) {
3618 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3619 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3622 $accessallowed = $user->hasRight(
'export',
'lire');
3623 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3624 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3626 $accessallowed = $user->hasRight(
'import',
'run');
3627 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3628 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3630 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3631 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3632 } elseif ($modulepart ==
'hrm' && !empty($conf->hrm->dir_output)) {
3634 $accessallowed = $user->hasRight(
'hrm',
'all',
'read');
3635 $original_file = $conf->hrm->dir_output.
'/'.$original_file;
3636 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3639 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3640 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3642 if ($fuser->admin) {
3645 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3646 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3648 if ($fuser->admin) {
3651 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3652 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3656 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3659 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3660 } elseif ($modulepart ==
'member' && !empty($conf->member->dir_output)) {
3662 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3665 $original_file = $conf->member->dir_output.
'/'.$original_file;
3666 } elseif ($modulepart ==
'ticket' && !empty($conf->ticket->multidir_output[$entity])) {
3668 if ($fuser->hasRight(
'ticket', $read)) {
3671 if (!isset($_SESSION[
'email_customer'])) {
3672 $sqlprotectagainstexternals =
'';
3674 $email_split = explode(
'@', $_SESSION[
'email_customer']);
3676 $sqlprotectagainstexternals =
'SELECT t.rowid, t.fk_soc FROM '.MAIN_DB_PREFIX.
'ticket t';
3677 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'element_contact ec ON ec.element_id = t.rowid';
3678 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'socpeople c ON c.rowid = ec.fk_socpeople';
3679 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_contact tc ON tc.element = "ticket" AND tc.rowid = ec.fk_c_type_contact';
3680 $sqlprotectagainstexternals.=
' WHERE t.ref LIKE "'.$db->sanitize($refname).
'"';
3681 $sqlprotectagainstexternals.=
' AND (';
3682 $sqlprotectagainstexternals.=
' (';
3683 $sqlprotectagainstexternals.=
' tc.rowid IS NOT NULL';
3684 $sqlprotectagainstexternals.=
' AND c.email = "'.$db->sanitize($email_split[0]).
'@'.$db->sanitize($email_split[1]).
'"';
3685 $sqlprotectagainstexternals.=
' )';
3686 $sqlprotectagainstexternals.=
' OR t.origin_email = "'.$db->sanitize($email_split[0]).
'@'.$db->sanitize($email_split[1]).
'"';
3687 $sqlprotectagainstexternals.=
' )';
3689 $original_file = $conf->ticket->multidir_output[$entity].
'/'.$original_file;
3699 if (preg_match(
'/^specimen/i', $original_file)) {
3702 if ($fuser->admin) {
3706 $tmpmodulepart = explode(
'-', $modulepart);
3707 if (!empty($tmpmodulepart[1])) {
3708 $modulepart = $tmpmodulepart[0];
3709 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3714 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3715 $tmpmodule = $reg[1];
3716 if (empty($conf->$tmpmodule->dir_temp)) {
3717 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3720 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3723 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3724 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3725 $tmpmodule = $reg[1];
3726 if (empty($conf->$tmpmodule->dir_temp)) {
3727 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3730 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3733 $original_file = $conf->$tmpmodule->dir_temp.
'/'.$original_file;
3734 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3735 $tmpmodule = $reg[1];
3736 if (empty($conf->$tmpmodule->dir_output)) {
3737 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3740 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3743 $original_file = $conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3744 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3745 $tmpmodule = $reg[1];
3746 if (empty($conf->$tmpmodule->dir_output)) {
3747 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3752 $partsofdirinoriginalfile = explode(
'/', $original_file);
3753 if (!empty($partsofdirinoriginalfile[1])) {
3754 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3755 if (($partofdirinoriginalfile && $fuser->hasRight($tmpmodule, $partofdirinoriginalfile,
'read')) || preg_match(
'/^specimen/i', $original_file)) {
3759 if ($fuser->hasRight($tmpmodule, $read) || preg_match(
'/^specimen/i', $original_file)) {
3762 $original_file = $conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3764 if (empty($conf->$modulepart->dir_output)) {
3765 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
'). The module for this modulepart value may not be activated.');
3770 $partsofdirinoriginalfile = explode(
'/', $original_file);
3771 if (!empty($partsofdirinoriginalfile[1])) {
3772 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3773 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3777 if (($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) || ($fuser->hasRight($modulepart,
'all', $lire) || $fuser->hasRight($modulepart,
'all', $read))) {
3781 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3782 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3784 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3788 $parameters = array(
3789 'modulepart' => $modulepart,
3790 'original_file' => $original_file,
3791 'entity' => $entity,
3796 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3798 if (!empty($hookmanager->resArray[
'original_file'])) {
3799 $original_file = $hookmanager->resArray[
'original_file'];
3801 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3802 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3804 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3805 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3811 'accessallowed' => ($accessallowed ? 1 : 0),
3812 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3813 'original_file' => $original_file