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);
1114function dol_move($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array(), $entity =
null)
1119 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
1124 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
1128 if ($overwriteifexists || !$destexists) {
1133 $testvirusarray = array();
1136 $testvirusarray =
dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
1137 if (count($testvirusarray)) {
1138 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1144 if (count($testvirusarray)) {
1145 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1150 global $dolibarr_main_restrict_os_commands;
1151 if (!empty($dolibarr_main_restrict_os_commands)) {
1152 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1153 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1154 if (in_array(basename($destfile), $arrayofallowedcommand)) {
1157 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);
1162 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1165 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
1168 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1170 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1175 if ($result && $indexdatabase) {
1177 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1178 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1179 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1180 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1181 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1184 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1185 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1187 $ecmfiletarget =
new EcmFiles($db);
1188 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter,
'',
'',
'', 0, $entity);
1189 if ($resultecmtarget > 0) {
1190 $ecmfiletarget->delete($user);
1194 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore,
'',
'',
'', 0, $entity);
1195 if ($resultecm > 0) {
1196 $filename = basename($rel_filetorenameafter);
1197 $rel_dir = dirname($rel_filetorenameafter);
1198 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1199 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1201 $ecmfile->filepath = $rel_dir;
1202 $ecmfile->filename = $filename;
1204 $resultecm = $ecmfile->update($user);
1205 } elseif ($resultecm == 0) {
1206 $filename = basename($rel_filetorenameafter);
1207 $rel_dir = dirname($rel_filetorenameafter);
1208 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1209 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1211 $ecmfile->filepath = $rel_dir;
1212 $ecmfile->filename = $filename;
1214 $ecmfile->fullpath_orig = basename($srcfile);
1215 if (!empty($moreinfo) && !empty($moreinfo[
'gen_or_uploaded'])) {
1216 $ecmfile->gen_or_uploaded = $moreinfo[
'gen_or_uploaded'];
1218 $ecmfile->gen_or_uploaded =
'unknown';
1220 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1221 $ecmfile->description = $moreinfo[
'description'];
1223 $ecmfile->description =
'';
1225 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1226 $ecmfile->keywords = $moreinfo[
'keywords'];
1228 $ecmfile->keywords =
'';
1230 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1231 $ecmfile->note_private = $moreinfo[
'note_private'];
1233 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1234 $ecmfile->note_public = $moreinfo[
'note_public'];
1236 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1237 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1239 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1240 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1242 if (!empty($moreinfo) && !empty($moreinfo[
'position'])) {
1243 $ecmfile->position = $moreinfo[
'position'];
1245 if (!empty($moreinfo) && !empty($moreinfo[
'cover'])) {
1246 $ecmfile->cover = $moreinfo[
'cover'];
1248 if (! empty($entity)) {
1249 $ecmfile->entity = $entity;
1252 $resultecm = $ecmfile->create($user);
1253 if ($resultecm < 0) {
1256 if (!empty($moreinfo) && !empty($moreinfo[
'array_options']) && is_array($moreinfo[
'array_options'])) {
1257 $ecmfile->array_options = $moreinfo[
'array_options'];
1258 $resultecm = $ecmfile->insertExtraFields();
1259 if ($resultecm < 0) {
1264 } elseif ($resultecm < 0) {
1268 if ($resultecm > 0) {
1276 if (empty($newmask)) {
1283 dolChmod($newpathofdestfile, $newmask);
2015function dol_add_file_process($upload_dir, $allowoverwrite = 0, $updatesessionordb = 0, $keyforsourcefile =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1,
$object =
null, $forceFullTextIndexation =
'', $mode = 0)
2017 global $db, $user, $conf, $langs;
2023 $_FILES = array($keyforsourcefile => array());
2024 $_FILES[$keyforsourcefile][
'tmp_name'] = $keyforsourcefile;
2025 $_FILES[$keyforsourcefile][
'name'] = $keyforsourcefile;
2029 if (!empty($_FILES[$keyforsourcefile])) {
2030 dol_syslog(
'dol_add_file_process varfiles = '.$keyforsourcefile.
' upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' updatesessionordb='.$updatesessionordb.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
2031 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
2032 if (is_array($_FILES[$keyforsourcefile][
"name"]) && count($_FILES[$keyforsourcefile][
"name"]) > $maxfilesinform) {
2033 $langs->load(
"errors");
2034 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
2042 $TFile = $_FILES[$keyforsourcefile];
2044 if (!is_array($TFile[
'name'])) {
2045 foreach ($TFile as $key => &$val) {
2050 $nbfile = count($TFile[
'name']);
2052 for ($i = 0; $i < $nbfile; $i++) {
2053 if (empty($TFile[
'name'][$i])) {
2058 $destfile = trim($TFile[
'name'][$i]);
2059 $destfull = $upload_dir.
"/".$destfile;
2060 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
2062 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
2063 $destfile = trim(preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask));
2064 $destfull = $upload_dir.
"/".$destfile;
2067 $filenameto = basename($destfile);
2068 if (preg_match(
'/^\./', $filenameto)) {
2069 $langs->load(
"errors");
2070 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
2074 $info = pathinfo($destfull);
2075 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
2076 $info = pathinfo($destfile);
2077 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
2082 $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';
2083 $fileextensionrestriction =
getDolGlobalString(
"MAIN_FILE_EXTENSION_UPLOAD_RESTRICTION", $defaultexecutableextensions);
2084 if (!empty($fileextensionrestriction)) {
2085 $arrayofregexextension = explode(
",", $fileextensionrestriction);
2087 foreach ($arrayofregexextension as $fileextension) {
2088 if (preg_match(
'/\.'.preg_quote(trim($fileextension),
'/').
'$/i', $destfull)) {
2089 $langs->load(
"errors");
2090 setEventMessages($langs->trans(
"ErrorFilenameExtensionNotAllowed", $filenameto),
null,
'errors');
2102 global $dolibarr_main_restrict_os_commands;
2103 if (!empty($dolibarr_main_restrict_os_commands)) {
2104 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
2105 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
2106 if (in_array($destfile, $arrayofallowedcommand)) {
2107 $langs->load(
"errors");
2108 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
2114 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $keyforsourcefile, $upload_dir, $mode);
2116 if (is_numeric($resupload) && $resupload > 0) {
2117 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2120 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
2121 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
2122 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
2123 $maxheightmini = $tmparraysize[
'maxheightmini'];
2128 if ($generatethumbs) {
2134 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
2137 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
2142 if (empty($updatesessionordb)) {
2143 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2145 $formmail->trackid = $trackid;
2146 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
2150 if ($updatesessionordb == 1) {
2152 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false &&
getDolGlobalString(
'PRODUCT_ALLOW_EXTERNAL_DOWNLOAD')) {
2157 if ($allowoverwrite) {
2161 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile,
$object, $forceFullTextIndexation);
2163 if ($allowoverwrite) {
2166 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
2173 $langs->load(
"errors");
2174 if (is_numeric($resupload) && $resupload < 0) {
2176 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
2177 if (preg_match(
'/File is a PDF with javascript inside/', $resupload)) {
2178 setEventMessages($langs->trans(
"ErrorFileIsAnInfectedPDFWithJSInside"),
null,
'errors');
2192 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
2195 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2196 $linkObject =
new Link($db);
2197 $linkObject->entity = $conf->entity;
2198 $linkObject->url = $link;
2199 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
2200 $linkObject->objectid =
GETPOSTINT(
'objectid');
2201 $linkObject->label =
GETPOST(
'label',
'alpha');
2202 $res = $linkObject->create($user);
2210 $langs->load(
"errors");
2211 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
2979 global $conf, $db, $user, $hookmanager;
2980 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2983 if (!is_object($fuser)) {
2987 if (empty($modulepart)) {
2988 return 'ErrorBadParameter';
2990 if (empty($entity)) {
2998 if ($modulepart ==
'facture') {
2999 $modulepart =
'invoice';
3000 } elseif ($modulepart ==
'users') {
3001 $modulepart =
'user';
3002 } elseif ($modulepart ==
'tva') {
3003 $modulepart =
'tax-vat';
3004 } elseif ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
3006 $modulepart =
'delivery';
3007 } elseif ($modulepart ==
'propale') {
3008 $modulepart =
'propal';
3012 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
3016 $sqlprotectagainstexternals =
'';
3020 if (empty($refname)) {
3021 $refname = basename(dirname($original_file).
"/");
3022 if ($refname ==
'thumbs' || $refname ==
'temp') {
3024 $refname = basename(dirname(dirname($original_file)).
"/");
3031 $download =
'download';
3032 if ($mode ==
'write') {
3035 $download =
'upload';
3039 if ($modulepart ==
'common') {
3042 $original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/'.$original_file;
3043 } elseif ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
3048 if (empty($entity)) {
3052 $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;
3053 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
3055 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
3056 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
3057 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
3058 $accessallowed = $user->admin;
3059 $relative_file = $original_file;
3060 $ent = ($entity > 0 ? $entity : $conf->entity);
3061 $path_with_entity = $dolibarr_main_data_root .
'/' . $ent .
'/doctemplates/' . $relative_file;
3062 if ($ent > 1 && file_exists(
dol_osencode($path_with_entity))) {
3063 $original_file = $path_with_entity;
3065 $original_file = $dolibarr_main_data_root .
'/doctemplates/' . $relative_file;
3067 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
3069 $accessallowed = ($fuser->hasRight(
'website',
'write') && preg_match(
'/\.jpg$/i', basename($original_file)));
3070 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
3071 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
3074 $tmp = explode(
',', $dolibarr_main_document_root_alt);
3077 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
3078 $original_file = $dirins.
'/'.$original_file;
3079 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
3082 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
3083 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
3086 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
3089 $original_file = $conf->user->dir_output.
'/'.$original_file;
3090 } elseif ($modulepart ==
'userphotopublic' && !empty($conf->user->dir_output)) {
3095 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
3096 if ((
int) $reg[1]) {
3097 $tmpobject =
new User($db);
3098 $tmpobject->fetch((
int) $reg[1],
'',
'', 1);
3100 $securekey =
GETPOST(
'securekey',
'alpha', 1);
3102 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
3103 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
3104 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
3105 if ($encodedsecurekey == $securekey) {
3114 $original_file = $conf->user->dir_output.
'/'.$original_file;
3115 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
3118 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
3119 } elseif ($modulepart ==
'memberphoto' && !empty($conf->member->dir_output)) {
3123 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
3127 if (preg_match(
'/^MEM\d\d\d\d-\d\d\d\d\/photos\//', $original_file)) {
3130 $original_file = $conf->member->dir_output.
'/'.$original_file;
3131 } elseif ($modulepart ==
'apercufacture' && !empty($conf->invoice->multidir_output[$entity])) {
3133 if ($fuser->hasRight(
'facture', $lire)) {
3136 $original_file = $conf->invoice->multidir_output[$entity].
'/'.$original_file;
3137 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
3139 if ($fuser->hasRight(
'propal', $lire)) {
3142 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3143 } elseif ($modulepart ==
'apercucommande' && !empty($conf->order->multidir_output[$entity])) {
3145 if ($fuser->hasRight(
'commande', $lire)) {
3148 $original_file = $conf->order->multidir_output[$entity].
'/'.$original_file;
3149 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->multidir_output[$entity])) {
3151 if ($fuser->hasRight(
'ficheinter', $lire)) {
3154 $original_file = $conf->ficheinter->multidir_output[$entity].
'/'.$original_file;
3155 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contract->multidir_output[$entity])) {
3157 if ($fuser->hasRight(
'contrat', $lire)) {
3160 $original_file = $conf->contract->multidir_output[$entity].
'/'.$original_file;
3161 } elseif (($modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
3163 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
3166 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
3167 } elseif (($modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
3169 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3172 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3173 } elseif (($modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
3175 if ($fuser->hasRight(
'fournisseur', $lire)) {
3178 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3179 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
3180 if ($fuser->hasRight(
'holiday', $read) || $fuser->hasRight(
'holiday',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3183 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3184 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
3185 $tmpholiday =
new Holiday($db);
3186 $tmpholiday->fetch(0, $refname);
3187 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
3190 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
3191 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
3192 if ($fuser->hasRight(
'expensereport', $lire) || $fuser->hasRight(
'expensereport',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3195 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3196 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
3198 $tmpexpensereport->fetch(0, $refname);
3199 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
3202 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
3203 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
3205 if ($fuser->hasRight(
'expensereport', $lire)) {
3208 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
3209 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
3211 if ($fuser->hasRight(
'propal', $lire)) {
3214 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
3215 } elseif ($modulepart ==
'orderstats' && !empty($conf->order->dir_temp)) {
3217 if ($fuser->hasRight(
'commande', $lire)) {
3220 $original_file = $conf->order->dir_temp.
'/'.$original_file;
3221 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
3222 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3225 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
3226 } elseif ($modulepart ==
'billstats' && !empty($conf->invoice->dir_temp)) {
3228 if ($fuser->hasRight(
'facture', $lire)) {
3231 $original_file = $conf->invoice->dir_temp.
'/'.$original_file;
3232 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
3233 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
3236 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
3237 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
3239 if ($fuser->hasRight(
'expedition', $lire)) {
3242 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
3243 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
3245 if ($fuser->hasRight(
'deplacement', $lire)) {
3248 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
3249 } elseif ($modulepart ==
'memberstats' && !empty($conf->member->dir_temp)) {
3251 if ($fuser->hasRight(
'adherent', $lire)) {
3254 $original_file = $conf->member->dir_temp.
'/'.$original_file;
3255 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
3257 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
3260 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
3261 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
3263 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
3266 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
3267 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
3268 } elseif (($modulepart ==
'actions' || $modulepart ==
'actioncomm') && !empty($conf->agenda->dir_output)) {
3270 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3273 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3274 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3276 $tmpobject->fetch((
int) $refname);
3277 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3278 if ($user->socid && $tmpobject->socid) {
3283 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
3284 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
3286 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
3287 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3289 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
3292 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
3293 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
3295 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3298 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
3299 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
3302 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
3303 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
3306 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
3307 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
3310 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
3311 } elseif ($modulepart ==
'barcode') {
3316 $original_file =
'';
3317 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
3320 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
3321 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3324 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3325 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
3328 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3329 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
3331 $canreaduser = (!empty($fuser->admin) || $fuser->hasRight(
'user',
'user', $lire));
3332 if ($fuser->id == (
int) $refname) {
3335 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3338 $original_file = $conf->user->dir_output.
'/'.$original_file;
3339 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
3341 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
3342 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3344 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3347 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
3348 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
3349 } elseif (($modulepart ==
'contact' || $modulepart ==
'socpeople') && !empty($conf->societe->multidir_output[$entity])) {
3351 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
3352 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3354 if ($fuser->hasRight(
'societe', $lire)) {
3357 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3358 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->invoice->multidir_output[$entity])) {
3360 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3363 $original_file = $conf->invoice->multidir_output[$entity].
'/'.$original_file;
3364 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3365 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
3367 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3370 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3371 } elseif ($modulepart ==
'massfilesarea_orders') {
3372 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3375 $original_file = $conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3376 } elseif ($modulepart ==
'massfilesarea_sendings') {
3377 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3380 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3381 } elseif ($modulepart ==
'massfilesarea_receipts') {
3382 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3385 $original_file = $conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3386 } elseif ($modulepart ==
'massfilesarea_invoices') {
3387 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3390 $original_file = $conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3391 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3392 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3395 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3396 } elseif ($modulepart ==
'massfilesarea_interventions') {
3397 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3400 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3401 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
3402 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3405 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3406 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3407 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3410 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3411 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3412 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3415 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3416 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contract->dir_output)) {
3417 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3420 $original_file = $conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3421 } elseif ($modulepart ==
'massfilesarea_stock' && !empty($conf->stock->dir_output)) {
3422 if ($fuser->hasRight(
'stock', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3425 $original_file = $conf->stock->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3426 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->multidir_output[$entity])) {
3428 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3431 $original_file = $conf->ficheinter->multidir_output[$entity].
'/'.$original_file;
3432 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".((int) $entity);
3433 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
3435 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3438 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
3440 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset($conf->propal->multidir_output[$entity])) {
3442 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3445 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3446 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3447 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->order->multidir_output[$entity])) {
3449 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3452 $original_file = $conf->order->multidir_output[$entity].
'/'.$original_file;
3453 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3454 } elseif ($modulepart ==
'project' && !empty($conf->project->multidir_output[$entity])) {
3456 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3459 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3460 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3461 $tmpproject =
new Project($db);
3462 $tmpproject->fetch(0, $refname);
3463 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3466 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3467 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3468 } elseif ($modulepart ==
'project_task' && !empty($conf->project->multidir_output[$entity])) {
3469 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3472 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3473 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3474 $tmptask =
new Task($db);
3475 $tmptask->fetch(0, $refname);
3476 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3479 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3480 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3481 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
3483 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3486 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3487 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3488 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
3490 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3493 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3494 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3495 } elseif ($modulepart ==
'supplier_payment') {
3497 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3500 $original_file = preg_replace(
"/payment\//",
"", $original_file);
3501 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
3502 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3503 } elseif ($modulepart ==
'payment') {
3505 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3508 $original_file = $conf->compta->payment->dir_output.
'/'.$original_file;
3509 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->invoice->dir_output)) {
3511 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3514 if ($fuser->socid > 0) {
3515 $original_file = $conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3517 $original_file = $conf->invoice->dir_output.
'/payments/'.$original_file;
3519 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
3521 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3524 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
3525 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment' || $modulepart ==
'shipping') && !empty($conf->expedition->dir_output)) {
3527 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3530 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3532 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
3534 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3537 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3538 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
3540 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3543 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
3544 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3546 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
3547 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3549 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3553 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
3555 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
3557 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3559 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
3560 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3562 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3566 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3568 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3570 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3571 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3573 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3577 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3579 } elseif ($modulepart ==
'entrepot') {
3581 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3582 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3584 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3588 $original_file = $conf->stock->multidir_output[$entity].
'/'.$original_file;
3590 } elseif ($modulepart ==
'contract' && !empty($conf->contract->multidir_output[$entity])) {
3592 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3595 $original_file = $conf->contract->multidir_output[$entity].
'/'.$original_file;
3596 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3597 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
3599 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3602 $original_file = $conf->don->dir_output.
'/'.$original_file;
3603 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
3605 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3608 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3609 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3611 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3614 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3615 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3617 if ($fuser->hasRight(
'banque', $lire)) {
3620 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3621 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3624 $accessallowed = $user->hasRight(
'export',
'lire');
3625 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3626 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3628 $accessallowed = $user->hasRight(
'import',
'run');
3629 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3630 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3632 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3633 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3634 } elseif ($modulepart ==
'hrm' && !empty($conf->hrm->dir_output)) {
3636 $accessallowed = $user->hasRight(
'hrm',
'all',
'read');
3637 $original_file = $conf->hrm->dir_output.
'/'.$original_file;
3638 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3641 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3642 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3644 if ($fuser->admin) {
3647 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3648 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3650 if ($fuser->admin) {
3653 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3654 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3658 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3661 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3662 } elseif ($modulepart ==
'member' && !empty($conf->member->dir_output)) {
3664 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3667 $original_file = $conf->member->dir_output.
'/'.$original_file;
3668 } elseif ($modulepart ==
'ticket' && !empty($conf->ticket->multidir_output[$entity])) {
3670 if ($fuser->hasRight(
'ticket', $read)) {
3673 if (!isset($_SESSION[
'email_customer'])) {
3674 $sqlprotectagainstexternals =
'';
3676 $email_split = explode(
'@', $_SESSION[
'email_customer']);
3678 $sqlprotectagainstexternals =
'SELECT t.rowid, t.fk_soc FROM '.MAIN_DB_PREFIX.
'ticket t';
3679 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'element_contact ec ON ec.element_id = t.rowid';
3680 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'socpeople c ON c.rowid = ec.fk_socpeople';
3681 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_contact tc ON tc.element = "ticket" AND tc.rowid = ec.fk_c_type_contact';
3682 $sqlprotectagainstexternals.=
' WHERE t.ref LIKE "'.$db->sanitize($refname).
'"';
3683 $sqlprotectagainstexternals.=
' AND (';
3684 $sqlprotectagainstexternals.=
' (';
3685 $sqlprotectagainstexternals.=
' tc.rowid IS NOT NULL';
3686 $sqlprotectagainstexternals.=
' AND c.email = "'.$db->sanitize($email_split[0]).
'@'.$db->sanitize($email_split[1]).
'"';
3687 $sqlprotectagainstexternals.=
' )';
3688 $sqlprotectagainstexternals.=
' OR t.origin_email = "'.$db->sanitize($email_split[0]).
'@'.$db->sanitize($email_split[1]).
'"';
3689 $sqlprotectagainstexternals.=
' )';
3691 $original_file = $conf->ticket->multidir_output[$entity].
'/'.$original_file;
3701 if (preg_match(
'/^specimen/i', $original_file)) {
3704 if ($fuser->admin) {
3708 $tmpmodulepart = explode(
'-', $modulepart);
3709 if (!empty($tmpmodulepart[1])) {
3710 $modulepart = $tmpmodulepart[0];
3711 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3716 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3717 $tmpmodule = $reg[1];
3718 if (empty($conf->$tmpmodule->dir_temp)) {
3719 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3722 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3725 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3726 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3727 $tmpmodule = $reg[1];
3728 if (empty($conf->$tmpmodule->dir_temp)) {
3729 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3732 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3735 $original_file = $conf->$tmpmodule->dir_temp.
'/'.$original_file;
3736 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3737 $tmpmodule = $reg[1];
3738 if (empty($conf->$tmpmodule->dir_output)) {
3739 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3742 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3745 $original_file = $conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3746 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3747 $tmpmodule = $reg[1];
3748 if (empty($conf->$tmpmodule->dir_output)) {
3749 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3754 $partsofdirinoriginalfile = explode(
'/', $original_file);
3755 if (!empty($partsofdirinoriginalfile[1])) {
3756 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3757 if (($partofdirinoriginalfile && $fuser->hasRight($tmpmodule, $partofdirinoriginalfile,
'read')) || preg_match(
'/^specimen/i', $original_file)) {
3761 if ($fuser->hasRight($tmpmodule, $read) || preg_match(
'/^specimen/i', $original_file)) {
3764 $original_file = $conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3766 if (empty($conf->$modulepart->dir_output)) {
3767 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.');
3772 $partsofdirinoriginalfile = explode(
'/', $original_file);
3773 if (!empty($partsofdirinoriginalfile[1])) {
3774 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3775 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3779 if (($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) || ($fuser->hasRight($modulepart,
'all', $lire) || $fuser->hasRight($modulepart,
'all', $read))) {
3783 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3784 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3786 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3790 $parameters = array(
3791 'modulepart' => $modulepart,
3792 'original_file' => $original_file,
3793 'entity' => $entity,
3798 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3800 if (!empty($hookmanager->resArray[
'original_file'])) {
3801 $original_file = $hookmanager->resArray[
'original_file'];
3803 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3804 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3806 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3807 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3813 'accessallowed' => ($accessallowed ? 1 : 0),
3814 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3815 'original_file' => $original_file