66function 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)
71 if ($recursive <= 1) {
76 if (!empty($filter) && !is_array($filter)) {
77 if (strlen($filter) > 25000) {
78 dol_syslog(
"Value for filter is too large", LOG_ERR);
82 if ((
int) preg_match(
'/(?:^|[^\\\\])\//', $filter) > 0) {
83 $excludefilter_ok =
false;
84 $error_info .=
" error='filter_has_unescaped_slash'";
85 dol_syslog(
"'$filter' has unescaped '/'", LOG_ERR);
91 $excludefilter_ok =
true;
92 $exclude_array = ($excludefilter ===
null || $excludefilter ===
'') ? array() : (is_array($excludefilter) ? $excludefilter : array($excludefilter));
93 foreach ($exclude_array as $f) {
95 if ((
int) preg_match(
'/(?:^|[^\\\\])\//', $f) > 0) {
96 $excludefilter_ok =
false;
97 $error_info .=
" error='excludefilter_has_unescaped_slash'";
102 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);
104 if (!$filter_ok || !$excludefilter_ok) {
110 $exclude_array = ($excludefilter ===
null || $excludefilter ===
'') ? array() : (is_array($excludefilter) ? $excludefilter : array($excludefilter));
114 $excludefilterarray = array_merge(array(
'^\.'), $exclude_array);
116 $loaddate = ($mode == 1 || $mode == 2 || $nbsecondsold != 0 || $sortcriteria ==
'date');
117 $loadsize = ($mode == 1 || $mode == 3 || $sortcriteria ==
'size');
118 $loadperm = ($mode == 1 || $mode == 4 || $sortcriteria ==
'perm');
122 $file_list = array();
125 $utf8_path = preg_replace(
'/([\\/]+)$/',
'', $utf8_path);
127 if (preg_match(
'/\*/', $utf8_path)) {
128 $utf8_path_array = glob($utf8_path, GLOB_ONLYDIR);
131 $utf8_path_array = array($utf8_path);
134 foreach ($utf8_path_array as $utf8_path_cursor) {
136 if (!$nohook && $hookmanager instanceof
HookManager) {
137 $hookmanager->resArray = array();
139 $hookmanager->initHooks(array(
'fileslib'));
144 'recursive' => $recursive,
146 'excludefilter' => $exclude_array,
147 'sortcriteria' => $sortcriteria,
148 'sortorder' => $sortorder,
149 'loaddate' => $loaddate,
150 'loadsize' => $loadsize,
153 $reshook = $hookmanager->executeHooks(
'getDirList', $parameters,
$object);
157 if (empty($reshook)) {
158 if (!is_dir($os_path)) {
162 if (($dir = opendir($os_path)) ===
false) {
170 while (
false !== ($os_file = readdir($dir))) {
171 $os_fullpathfile = ($os_path ? $os_path.
'/' :
'').$os_file;
174 $utf8_file = mb_convert_encoding($os_file,
'UTF-8',
'ISO-8859-1');
176 $utf8_file = $os_file;
179 $utf8_fullpathfile = $utf8_path_cursor.
"/".$utf8_file;
183 foreach ($excludefilterarray as $filt) {
184 if (preg_match(
'/'.$filt.
'/i', $utf8_file) || preg_match(
'/'.$filt.
'/i', $utf8_fullpathfile)) {
192 $isdir = is_dir($os_fullpathfile);
196 if (($types ==
"directories") || ($types ==
"all")) {
197 if ($loaddate || $sortcriteria ==
'date') {
200 if ($loadsize || $sortcriteria ==
'size') {
203 if ($loadperm || $sortcriteria ==
'perm') {
207 $qualifiedforfilter = 0;
208 if (empty($filter)) {
209 $qualifiedforfilter = 1;
211 $testpregmatch =
false;
212 if (is_array($filter)) {
213 $chunks = array_chunk($filter, 500);
214 foreach ($chunks as $chunk) {
215 $testpregmatch = preg_match(
'/'.implode(
'|', $chunk).
'/i', $utf8_file);
216 if ($testpregmatch) {
221 $testpregmatch = preg_match(
'/'.$filter.
'/i', $utf8_file);
223 if ($testpregmatch) {
224 $qualifiedforfilter = 1;
228 if ($qualifiedforfilter) {
230 preg_match(
'/([^\/]+)\/[^\/]+$/', $utf8_fullpathfile, $reg);
231 $level1name = (isset($reg[1]) ? $reg[1] :
'');
232 $file_list[] = array(
233 "name" => $utf8_file,
234 "path" => $utf8_path,
235 "level1name" => $level1name,
236 "relativename" => ($relativename ? $relativename.
'/' :
'').$utf8_file,
237 "fullname" => $utf8_fullpathfile,
247 if ($recursive > 0) {
248 if (empty($donotfollowsymlinks) || !is_link($os_fullpathfile)) {
250 $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));
253 } elseif (in_array($types, array(
"files",
"all"))) {
255 if ($loaddate || $sortcriteria ==
'date') {
258 if ($loadsize || $sortcriteria ==
'size') {
262 $qualifiedforfilter = 0;
263 if (empty($filter)) {
264 $qualifiedforfilter = 1;
266 $testpregmatch =
false;
267 if (is_array($filter)) {
268 $chunks = array_chunk($filter, 500);
269 foreach ($chunks as $chunk) {
270 $testpregmatch = preg_match(
'/'.implode(
'|', $chunk).
'/i', $utf8_file);
271 if ($testpregmatch) {
276 $testpregmatch = preg_match(
'/'.$filter.
'/i', $utf8_file);
278 if ($testpregmatch) {
279 $qualifiedforfilter = 1;
283 if ($qualifiedforfilter) {
284 if (empty($nbsecondsold) || $filedate <= ($now - $nbsecondsold)) {
285 preg_match(
'/([^\/]+)\/[^\/]+$/', $utf8_fullpathfile, $reg);
286 $level1name = (isset($reg[1]) ? $reg[1] :
'');
287 $file_list[] = array(
288 "name" => $utf8_file,
289 "path" => $utf8_path,
290 "level1name" => $level1name,
291 "relativename" => ($relativename ? $relativename.
'/' :
'').$utf8_file,
292 "fullname" => $utf8_fullpathfile,
307 if (!empty($sortcriteria) && $sortorder) {
308 $file_list =
dol_sort_array($file_list, $sortcriteria, ($sortorder == SORT_ASC ?
'asc' :
'desc'));
311 if ($hookmanager instanceof
HookManager && is_array($hookmanager->resArray)) {
312 $file_list = array_merge($file_list, $hookmanager->resArray);
1162function dol_move($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array(), $entity =
null)
1167 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
1172 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
1176 if ($overwriteifexists || !$destexists) {
1181 $testvirusarray = array();
1184 $testvirusarray =
dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
1185 if (count($testvirusarray)) {
1186 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1192 if (count($testvirusarray)) {
1193 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1198 global $dolibarr_main_restrict_os_commands;
1199 if (!empty($dolibarr_main_restrict_os_commands)) {
1200 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1201 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1202 if (in_array(basename($destfile), $arrayofallowedcommand)) {
1205 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);
1210 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1213 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
1216 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1218 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1223 if ($result && $indexdatabase) {
1225 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1226 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1227 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1228 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1229 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1232 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1233 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1235 $ecmfiletarget =
new EcmFiles($db);
1236 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter,
'',
'',
'', 0, $entity);
1237 if ($resultecmtarget > 0) {
1238 $ecmfiletarget->delete($user);
1242 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore,
'',
'',
'', 0, $entity);
1243 if ($resultecm > 0) {
1244 $filename = basename($rel_filetorenameafter);
1245 $rel_dir = dirname($rel_filetorenameafter);
1246 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1247 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1249 $ecmfile->filepath = $rel_dir;
1250 $ecmfile->filename = $filename;
1252 $resultecm = $ecmfile->update($user);
1253 } elseif ($resultecm == 0) {
1254 $filename = basename($rel_filetorenameafter);
1255 $rel_dir = dirname($rel_filetorenameafter);
1256 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1257 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1259 $ecmfile->filepath = $rel_dir;
1260 $ecmfile->filename = $filename;
1262 $ecmfile->fullpath_orig = basename($srcfile);
1263 if (!empty($moreinfo) && !empty($moreinfo[
'gen_or_uploaded'])) {
1264 $ecmfile->gen_or_uploaded = $moreinfo[
'gen_or_uploaded'];
1266 $ecmfile->gen_or_uploaded =
'unknown';
1268 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1269 $ecmfile->description = $moreinfo[
'description'];
1271 $ecmfile->description =
'';
1273 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1274 $ecmfile->keywords = $moreinfo[
'keywords'];
1276 $ecmfile->keywords =
'';
1278 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1279 $ecmfile->note_private = $moreinfo[
'note_private'];
1281 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1282 $ecmfile->note_public = $moreinfo[
'note_public'];
1284 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1285 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1287 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1288 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1290 if (!empty($moreinfo) && !empty($moreinfo[
'agenda_id'])) {
1291 $ecmfile->agenda_id = $moreinfo[
'agenda_id'];
1293 if (!empty($moreinfo) && !empty($moreinfo[
'position'])) {
1294 $ecmfile->position = $moreinfo[
'position'];
1296 if (!empty($moreinfo) && !empty($moreinfo[
'cover'])) {
1297 $ecmfile->cover = $moreinfo[
'cover'];
1299 if (!empty($moreinfo) && !empty($moreinfo[
'share'])) {
1300 $ecmfile->share = $moreinfo[
'share'];
1302 if (! empty($entity)) {
1303 $ecmfile->entity = $entity;
1306 $resultecm = $ecmfile->create($user);
1307 if ($resultecm < 0) {
1308 setEventMessages($ecmfile->error, $ecmfile->errors,
'warnings');
1310 if (!empty($moreinfo) && !empty($moreinfo[
'array_options']) && is_array($moreinfo[
'array_options'])) {
1311 $ecmfile->array_options = $moreinfo[
'array_options'];
1312 $resultecm = $ecmfile->insertExtraFields();
1313 if ($resultecm < 0) {
1314 setEventMessages($ecmfile->error, $ecmfile->errors,
'warnings');
1318 } elseif ($resultecm < 0) {
1319 setEventMessages($ecmfile->error, $ecmfile->errors,
'warnings');
1322 if ($resultecm > 0) {
1330 if (empty($newmask)) {
1337 dolChmod($newpathofdestfile, $newmask);
2121function dol_add_file_process($upload_dir, $allowoverwrite = 0, $updatesessionordb = 0, $keyforsourcefile =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1,
$object =
null, $forceFullTextIndexation =
'', $mode = 0)
2123 global $db, $user,
$conf, $langs;
2129 $_FILES = array($keyforsourcefile => array());
2130 $_FILES[$keyforsourcefile][
'tmp_name'] = $keyforsourcefile;
2131 $_FILES[$keyforsourcefile][
'name'] = $keyforsourcefile;
2135 if (!empty($_FILES[$keyforsourcefile])) {
2136 dol_syslog(
'dol_add_file_process varfiles = '.$keyforsourcefile.
' upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' updatesessionordb='.$updatesessionordb.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
2137 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
2138 if (is_array($_FILES[$keyforsourcefile][
"name"]) && count($_FILES[$keyforsourcefile][
"name"]) > $maxfilesinform) {
2139 $langs->load(
"errors");
2140 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
2148 $TFile = $_FILES[$keyforsourcefile];
2150 if (!is_array($TFile[
'name'])) {
2151 foreach ($TFile as $key => &$val) {
2156 $nbfile = count($TFile[
'name']);
2158 for ($i = 0; $i < $nbfile; $i++) {
2159 if (empty($TFile[
'name'][$i])) {
2164 $destfile = trim($TFile[
'name'][$i]);
2165 $destfull = $upload_dir.
"/".$destfile;
2166 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
2168 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
2169 $destfile = trim(preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask));
2170 $destfull = $upload_dir.
"/".$destfile;
2173 $filenameto = basename($destfile);
2174 if (preg_match(
'/^\./', $filenameto)) {
2175 $langs->load(
"errors");
2176 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
2180 $info = pathinfo($destfull);
2181 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
2182 $info = pathinfo($destfile);
2183 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
2186 $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';
2187 $fileextensionrestriction =
getDolGlobalString(
"MAIN_FILE_EXTENSION_UPLOAD_RESTRICTION", $defaultexecutableextensions);
2188 if (!empty($fileextensionrestriction)) {
2189 $arrayofregexextension = explode(
",", $fileextensionrestriction);
2191 foreach ($arrayofregexextension as $fileextension) {
2192 if (preg_match(
'/\.'.preg_quote(trim($fileextension),
'/').
'$/i', $destfull)) {
2193 $langs->load(
"errors");
2194 setEventMessages($langs->trans(
"ErrorFilenameExtensionNotAllowed", $filenameto),
null,
'errors');
2206 global $dolibarr_main_restrict_os_commands;
2207 if (!empty($dolibarr_main_restrict_os_commands)) {
2208 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
2209 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
2210 if (in_array($destfile, $arrayofallowedcommand)) {
2211 $langs->load(
"errors");
2212 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
2218 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $keyforsourcefile, $upload_dir, $mode);
2220 if (is_numeric($resupload) && $resupload > 0) {
2221 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2224 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
2225 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
2226 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
2227 $maxheightmini = $tmparraysize[
'maxheightmini'];
2232 if ($generatethumbs) {
2238 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
2241 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
2246 if (empty($updatesessionordb)) {
2247 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2249 $formmail->trackid = $trackid;
2250 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
2254 if ($updatesessionordb == 1) {
2256 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false &&
getDolGlobalString(
'PRODUCT_ALLOW_EXTERNAL_DOWNLOAD')) {
2261 if ($allowoverwrite) {
2265 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile,
$object, $forceFullTextIndexation);
2267 if ($allowoverwrite) {
2270 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
2277 $langs->load(
"errors");
2278 if (is_numeric($resupload) && $resupload < 0) {
2279 setEventMessages($langs->trans(
"ErrorFileNotUploaded"),
null,
'errors');
2281 setEventMessages($langs->trans($resupload),
null,
'errors');
2287 setEventMessages($langs->trans(
"FileTransferComplete"),
null,
'mesgs');
2290 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
2293 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2294 $linkObject =
new Link($db);
2295 $linkObject->entity =
$conf->entity;
2296 $linkObject->url = $link;
2297 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
2298 $linkObject->objectid =
GETPOSTINT(
'objectid');
2299 $linkObject->label =
GETPOST(
'label',
'alpha');
2300 $res = $linkObject->create($user);
2303 setEventMessages($langs->trans(
"LinkComplete"),
null,
'mesgs');
2305 setEventMessages($langs->trans(
"ErrorFileNotLinked"),
null,
'errors');
2308 $langs->load(
"errors");
2309 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
3081 global
$conf, $db, $user, $hookmanager;
3082 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
3085 if (!is_object($fuser)) {
3089 if (empty($modulepart)) {
3090 return 'ErrorBadParameter';
3093 $originalmodulepart = $modulepart;
3095 if (empty($entity)) {
3108 if ($modulepart ==
'facture') {
3109 $modulepart =
'invoice';
3110 } elseif ($modulepart ==
'users') {
3111 $modulepart =
'user';
3112 } elseif ($modulepart ==
'tva') {
3113 $modulepart =
'tax-vat';
3114 } elseif ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
3116 $modulepart =
'delivery';
3117 } elseif ($modulepart ==
'propale') {
3118 $modulepart =
'propal';
3123 if (preg_match(
'/(\w+)@(\w+)$/', $modulepart, $reg)) {
3124 $modulepart = $reg[2];
3128 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
3132 $sqlprotectagainstexternals =
'';
3134 $checksecureaccesshook =
false;
3137 if (empty($refname)) {
3138 $refname = basename(dirname($original_file).
"/");
3139 if ($refname ==
'thumbs' || $refname ==
'temp') {
3141 $refname = basename(dirname(dirname($original_file)).
"/");
3148 $download =
'download';
3149 if ($mode ==
'write') {
3152 $download =
'upload';
3153 } elseif ($mode ==
'delete') {
3154 $lire =
'supprimer';
3156 $download =
'upload';
3160 if ($modulepart ==
'common') {
3163 $original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/'.$original_file;
3164 } elseif ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
3166 if (empty($entity)) {
3170 if ($mode ==
'write') {
3171 if ($fuser->hasRight(
'website',
'write')) {
3177 $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;
3178 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
3180 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
3181 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
3182 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
3183 $accessallowed = $user->admin;
3184 $relative_file = $original_file;
3185 $ent = ($entity > 0 ? $entity :
$conf->entity);
3186 $path_with_entity = $dolibarr_main_data_root .
'/' . $ent .
'/doctemplates/' . $relative_file;
3187 if ($ent > 1 && file_exists(
dol_osencode($path_with_entity))) {
3188 $original_file = $path_with_entity;
3190 $original_file = $dolibarr_main_data_root .
'/doctemplates/' . $relative_file;
3192 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
3194 $accessallowed = ($fuser->hasRight(
'website',
'write') && preg_match(
'/\.jpg$/i', basename($original_file)));
3195 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
3196 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
3199 $tmp = explode(
',', $dolibarr_main_document_root_alt);
3202 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
3203 $original_file = $dirins.
'/'.$original_file;
3204 } elseif ($modulepart ==
'mycompany' && !empty(
$conf->mycompany->dir_output)) {
3207 $original_file =
$conf->mycompany->dir_output.
'/'.$original_file;
3208 } elseif ($modulepart ==
'userphoto' && !empty(
$conf->user->dir_output)) {
3211 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
3215 if ($mode !=
'read' && empty($fuser->admin) && !$fuser->hasRight(
'user',
'user', $lire) && !((
int) $original_file == $fuser->id && $fuser->hasRight(
'user',
'self', $lire))) {
3218 $original_file =
$conf->user->dir_output.
'/'.$original_file;
3219 } elseif ($modulepart ==
'userphotopublic' && !empty(
$conf->user->dir_output)) {
3224 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
3225 if ((
int) $reg[1]) {
3226 $tmpobject =
new User($db);
3227 $tmpobject->fetch((
int) $reg[1],
'',
'', 1);
3229 $securekey =
GETPOST(
'securekey',
'alpha', 1);
3231 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
3232 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
3233 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
3234 if (hash_equals($encodedsecurekey, (
string) $securekey)) {
3243 $original_file =
$conf->user->dir_output.
'/'.$original_file;
3244 } elseif (($modulepart ==
'companylogo') && !empty(
$conf->mycompany->dir_output)) {
3247 $original_file =
$conf->mycompany->dir_output.
'/logos/'.$original_file;
3248 } elseif ($modulepart ==
'memberphoto' && !empty(
$conf->member->dir_output)) {
3252 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
3256 if (preg_match(
'/^MEM\d\d\d\d-\d\d\d\d\/photos\//', $original_file)) {
3259 $original_file =
$conf->member->dir_output.
'/'.$original_file;
3260 } elseif ($modulepart ==
'apercufacture' && !empty(
$conf->invoice->multidir_output[$entity])) {
3262 if ($fuser->hasRight(
'facture', $lire)) {
3265 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
3266 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3267 } elseif ($modulepart ==
'apercupropal' && !empty(
$conf->propal->multidir_output[$entity])) {
3269 if ($fuser->hasRight(
'propal', $lire)) {
3272 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
3273 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3274 } elseif ($modulepart ==
'apercucommande' && !empty(
$conf->order->multidir_output[$entity])) {
3276 if ($fuser->hasRight(
'commande', $lire)) {
3279 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
3280 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3281 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty(
$conf->ficheinter->multidir_output[$entity])) {
3283 if ($fuser->hasRight(
'ficheinter', $lire)) {
3286 $original_file =
$conf->ficheinter->multidir_output[$entity].
'/'.$original_file;
3287 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".((int) $entity);
3288 } elseif (($modulepart ==
'apercucontract') && !empty(
$conf->contract->multidir_output[$entity])) {
3290 if ($fuser->hasRight(
'contrat', $lire)) {
3293 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
3294 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3295 } elseif (($modulepart ==
'apercusupplier_proposal') && !empty(
$conf->supplier_proposal->dir_output)) {
3297 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
3300 $original_file =
$conf->supplier_proposal->dir_output.
'/'.$original_file;
3301 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"supplier_proposal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'supplier_proposal').
")";
3302 } elseif (($modulepart ==
'apercusupplier_order') && !empty(
$conf->fournisseur->commande->dir_output)) {
3304 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3307 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3308 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity = ".((int)
$conf->entity);
3309 } elseif (($modulepart ==
'apercusupplier_invoice') && !empty(
$conf->fournisseur->facture->dir_output)) {
3311 if ($fuser->hasRight(
'fournisseur', $lire)) {
3314 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3315 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".((int)
$conf->entity);
3316 } elseif (($modulepart ==
'holiday') && !empty(
$conf->holiday->dir_output)) {
3317 if ($fuser->hasRight(
'holiday', $read) || ($mode ==
'read' && $fuser->hasRight(
'holiday',
'readall')) || preg_match(
'/^specimen/i', $original_file)) {
3320 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3321 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
3322 $tmpholiday =
new Holiday($db);
3323 $tmpholiday->fetch(0, $refname);
3324 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
3327 $original_file =
$conf->holiday->dir_output.
'/'.$original_file;
3328 } elseif (($modulepart ==
'salaries') && !empty(
$conf->salaries->dir_output)) {
3330 if ($fuser->hasRight(
'salaries', $read) || ($mode ==
'read' && $fuser->hasRight(
'salaries',
'readall')) || preg_match(
'/^specimen/i', $original_file)) {
3336 if ($refname && !$fuser->hasRight(
'salaries',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3337 include_once DOL_DOCUMENT_ROOT.
'/salaries/class/salary.class.php';
3338 $tmpsalary =
new Salary($db);
3339 $tmpsalary->fetch((
int) $refname);
3344 $accessallowed = ($tmpsalary->fk_user > 0 && in_array($tmpsalary->fk_user, $fuser->getAllChildIds(1))) ? 1 : 0;
3347 $original_file =
$conf->salaries->dir_output.
'/'.$original_file;
3348 } elseif (($modulepart ==
'expensereport') && !empty(
$conf->expensereport->dir_output)) {
3349 if ($fuser->hasRight(
'expensereport', $lire) || ($mode ==
'read' && $fuser->hasRight(
'expensereport',
'readall')) || preg_match(
'/^specimen/i', $original_file)) {
3352 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3353 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
3355 $tmpexpensereport->fetch(0, $refname);
3356 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
3359 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3360 } elseif (($modulepart ==
'apercuexpensereport') && !empty(
$conf->expensereport->dir_output)) {
3362 if ($fuser->hasRight(
'expensereport', $lire)) {
3365 if ($fuser->socid > 0) {
3369 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3370 } elseif ($modulepart ==
'propalstats' && !empty(
$conf->propal->multidir_temp[$entity])) {
3372 if ($fuser->hasRight(
'propal', $lire)) {
3375 $original_file =
$conf->propal->multidir_temp[$entity].
'/'.$original_file;
3376 } elseif ($modulepart ==
'contractstats' && !empty(
$conf->contract->dir_temp)) {
3378 if ($fuser->hasRight(
'contrat', $lire)) {
3381 $original_file =
$conf->contract->dir_temp.
'/'.$original_file;
3382 } elseif ($modulepart ==
'orderstats' && !empty(
$conf->order->dir_temp)) {
3384 if ($fuser->hasRight(
'commande', $lire)) {
3387 $original_file =
$conf->order->dir_temp.
'/'.$original_file;
3388 } elseif ($modulepart ==
'orderstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3389 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3392 $original_file =
$conf->fournisseur->commande->dir_temp.
'/'.$original_file;
3393 } elseif ($modulepart ==
'billstats' && !empty(
$conf->invoice->dir_temp)) {
3395 if ($fuser->hasRight(
'facture', $lire)) {
3398 $original_file =
$conf->invoice->dir_temp.
'/'.$original_file;
3399 } elseif ($modulepart ==
'billstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3400 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
3403 $original_file =
$conf->fournisseur->facture->dir_temp.
'/'.$original_file;
3404 } elseif ($modulepart ==
'expeditionstats' && !empty(
$conf->expedition->dir_temp)) {
3406 if ($fuser->hasRight(
'expedition', $lire)) {
3409 $original_file =
$conf->expedition->dir_temp.
'/'.$original_file;
3410 } elseif ($modulepart ==
'memberstats' && !empty(
$conf->member->dir_temp)) {
3412 if ($fuser->hasRight(
'adherent', $lire)) {
3415 $original_file =
$conf->member->dir_temp.
'/'.$original_file;
3416 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty(
$conf->product->dir_temp)) {
3418 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
3421 $original_file = (!empty(
$conf->product->multidir_temp[$entity]) ?
$conf->product->multidir_temp[$entity] :
$conf->service->multidir_temp[$entity]).
'/'.$original_file;
3422 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty(
$conf->tax->dir_output)) {
3424 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
3427 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
3428 $original_file =
$conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
3429 } elseif (($modulepart ==
'actions' || $modulepart ==
'actioncomm') && !empty(
$conf->agenda->dir_output)) {
3431 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3434 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3435 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3437 $tmpobject->fetch((
int) $refname);
3438 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3439 if ($user->socid && $tmpobject->socid) {
3444 $original_file =
$conf->agenda->dir_output.
'/'.$original_file;
3445 } elseif ($modulepart ==
'category' && !empty(
$conf->categorie->multidir_output[$entity])) {
3447 if (empty($entity) || empty(
$conf->categorie->multidir_output[$entity])) {
3448 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3450 if ($fuser->hasRight(
"categorie", $lire) || ($mode ==
'read' && $fuser->hasRight(
"takepos",
"run"))) {
3453 $original_file =
$conf->categorie->multidir_output[$entity].
'/'.$original_file;
3454 } elseif ($modulepart ==
'prelevement' && !empty(
$conf->prelevement->dir_output)) {
3456 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3459 $original_file =
$conf->prelevement->dir_output.
'/'.$original_file;
3460 } elseif ($modulepart ==
'graph_stock' && !empty(
$conf->stock->dir_temp)) {
3463 $original_file =
$conf->stock->dir_temp.
'/'.$original_file;
3464 } elseif ($modulepart ==
'graph_fourn' && !empty(
$conf->fournisseur->dir_temp)) {
3467 $original_file =
$conf->fournisseur->dir_temp.
'/'.$original_file;
3468 } elseif ($modulepart ==
'graph_product' && !empty(
$conf->product->dir_temp)) {
3471 $original_file =
$conf->product->multidir_temp[$entity].
'/'.$original_file;
3472 } elseif ($modulepart ==
'barcode') {
3477 $original_file =
'';
3478 } elseif ($modulepart ==
'iconmailing' && !empty(
$conf->mailing->dir_temp)) {
3481 $original_file =
$conf->mailing->dir_temp.
'/'.$original_file;
3482 } elseif ($modulepart ==
'scanner_user_temp' && !empty(
$conf->scanner->dir_temp)) {
3485 $original_file =
$conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3486 } elseif ($modulepart ==
'fckeditor' && !empty(
$conf->fckeditor->dir_output)) {
3489 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3490 } elseif ($modulepart ==
'user' && !empty(
$conf->user->dir_output)) {
3492 $canreaduser = (!empty($fuser->admin) || $fuser->hasRight(
'user',
'user', $lire));
3493 if ($fuser->id == (
int) $refname) {
3496 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3499 $original_file =
$conf->user->dir_output.
'/'.$original_file;
3500 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty(
$conf->societe->multidir_output[$entity])) {
3502 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3503 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3505 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3508 $original_file =
$conf->societe->multidir_output[$entity].
'/'.$original_file;
3509 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid = ".((int) $refname).
" AND entity IN (".
getEntity(
'societe').
")";
3510 } elseif (($modulepart ==
'contact' || $modulepart ==
'socpeople') && !empty(
$conf->societe->multidir_output[$entity])) {
3512 $checksecureaccesshook =
true;
3513 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3514 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3516 if ($fuser->hasRight(
'societe',
'contact', $lire)) {
3519 $original_file =
$conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3520 $sqlprotectagainstexternals =
"SELECT fk_soc FROM ".MAIN_DB_PREFIX.
"socpeople WHERE rowid = ".((int) $refname).
" AND entity IN (".
getEntity(
'contact').
")";
3521 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty(
$conf->invoice->multidir_output[$entity])) {
3523 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3526 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
3527 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3528 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty(
$conf->propal->multidir_output[$entity])) {
3530 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3533 $original_file =
$conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3534 } elseif ($modulepart ==
'massfilesarea_orders') {
3535 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3538 $original_file =
$conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3539 } elseif ($modulepart ==
'massfilesarea_sendings') {
3540 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3543 $original_file =
$conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3544 } elseif ($modulepart ==
'massfilesarea_receipts') {
3545 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3548 $original_file =
$conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3549 } elseif ($modulepart ==
'massfilesarea_invoices') {
3550 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3553 $original_file =
$conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3554 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3555 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3558 $original_file =
$conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3559 } elseif ($modulepart ==
'massfilesarea_interventions') {
3560 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3563 $original_file =
$conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3564 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty(
$conf->supplier_proposal->dir_output)) {
3565 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3568 $original_file =
$conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3569 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3570 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3573 $original_file =
$conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3574 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3575 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3578 $original_file =
$conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3579 } elseif ($modulepart ==
'massfilesarea_contract' && !empty(
$conf->contract->dir_output)) {
3580 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3583 $original_file =
$conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3584 } elseif ($modulepart ==
'massfilesarea_stock' && !empty(
$conf->stock->dir_output)) {
3585 if ($fuser->hasRight(
'stock', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3588 $original_file =
$conf->stock->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3589 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty(
$conf->ficheinter->multidir_output[$entity])) {
3591 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3594 $original_file =
$conf->ficheinter->multidir_output[$entity].
'/'.$original_file;
3595 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".((int)
$conf->entity);
3596 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset(
$conf->propal->multidir_output[$entity])) {
3598 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3601 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
3602 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3603 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty(
$conf->order->multidir_output[$entity])) {
3605 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3608 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
3609 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3610 } elseif ($modulepart ==
'project' && !empty(
$conf->project->multidir_output[$entity])) {
3612 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3615 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3616 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3617 $tmpproject =
new Project($db);
3618 $tmpproject->fetch(0, $refname);
3619 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3622 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3623 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3624 } elseif ($modulepart ==
'project_task' && !empty(
$conf->project->multidir_output[$entity])) {
3625 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3628 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3629 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3630 $tmptask =
new Task($db);
3631 $tmptask->fetch(0, $refname);
3632 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3635 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3636 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3637 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier' || $modulepart ==
'supplier_order') && !empty(
$conf->fournisseur->commande->dir_output)) {
3639 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3642 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3643 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity = ".((int)
$conf->entity);
3644 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier' || $modulepart ==
'supplier_invoice') && !empty(
$conf->fournisseur->facture->dir_output)) {
3646 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3649 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3650 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".((int)
$conf->entity);
3651 } elseif ($modulepart ==
'supplier_payment') {
3653 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3656 $original_file = preg_replace(
"/payment\//",
"", $original_file);
3657 $original_file =
$conf->fournisseur->payment->dir_output.
'/'.$original_file;
3658 $sqlprotectagainstexternals =
"SELECT f.fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfourn as p";
3659 $sqlprotectagainstexternals .=
" INNER JOIN ".MAIN_DB_PREFIX.
"paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid";
3660 $sqlprotectagainstexternals .=
" INNER JOIN ".MAIN_DB_PREFIX.
"facture_fourn as f ON pf.fk_facturefourn = f.rowid";
3661 $sqlprotectagainstexternals .=
" WHERE p.ref = '".$db->escape($refname).
"' AND p.entity=".((int)
$conf->entity);
3662 } elseif ($modulepart ==
'payment') {
3664 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3667 $original_file =
$conf->compta->payment->dir_output.
'/'.$original_file;
3668 } elseif ($modulepart ==
'facture_paiement' && !empty(
$conf->invoice->dir_output)) {
3670 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3673 if ($fuser->socid > 0) {
3674 $original_file =
$conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3676 $original_file =
$conf->invoice->dir_output.
'/payments/'.$original_file;
3683 } elseif ($modulepart ==
'accounting' && !empty(
$conf->accounting->dir_output)) {
3685 if ($fuser->hasRight(
'accounting',
'bind',
'write') || $fuser->hasRight(
'accounting',
'mouvements',
'export') || preg_match(
'/^specimen/i', $original_file)) {
3688 $original_file =
$conf->accounting->dir_output.
'/'.$original_file;
3689 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment' || $modulepart ==
'shipping') && !empty(
$conf->expedition->dir_output)) {
3691 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3694 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3696 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty(
$conf->expedition->dir_output)) {
3698 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3701 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3702 } elseif ($modulepart ==
'actionsreport' && !empty(
$conf->agenda->dir_temp)) {
3704 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3707 $original_file =
$conf->agenda->dir_temp.
"/".$original_file;
3708 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3710 $checksecureaccesshook =
true;
3711 if (empty($entity) || (empty(
$conf->product->multidir_output[$entity]) && empty(
$conf->service->multidir_output[$entity]))) {
3712 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3714 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3718 $original_file =
$conf->product->multidir_output[$entity].
'/'.$original_file;
3720 $original_file =
$conf->service->multidir_output[$entity].
'/'.$original_file;
3722 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3724 if (empty($entity) || (empty(
$conf->productbatch->multidir_output[$entity]))) {
3725 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3727 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3731 $original_file =
$conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3733 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3735 if (empty($entity) || empty(
$conf->stock->multidir_output[$entity])) {
3736 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3738 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3742 $original_file =
$conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3744 } elseif ($modulepart ==
'inventory') {
3746 if (empty($entity) || empty(
$conf->stock->multidir_output[$entity])) {
3747 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3749 if ($fuser->hasRight(
'stock', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3753 $original_file =
$conf->stock->multidir_output[$entity].
'/inventory/'.$original_file;
3755 } elseif ($modulepart ==
'entrepot') {
3757 if (empty($entity) || empty(
$conf->stock->multidir_output[$entity])) {
3758 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3760 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3764 $original_file =
$conf->stock->multidir_output[$entity].
'/'.$original_file;
3766 } elseif ($modulepart ==
'contract' && !empty(
$conf->contract->multidir_output[$entity])) {
3768 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3771 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
3772 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3773 } elseif ($modulepart ==
'donation' && !empty(
$conf->don->dir_output)) {
3775 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3778 $original_file =
$conf->don->dir_output.
'/'.$original_file;
3779 } elseif ($modulepart ==
'dolresource' && !empty(
$conf->resource->dir_output)) {
3781 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3784 $original_file =
$conf->resource->dir_output.
'/'.$original_file;
3785 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty(
$conf->bank->dir_output)) {
3787 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3790 $original_file =
$conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3791 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty(
$conf->bank->dir_output)) {
3794 if ($fuser->hasRight(
'banque', ($mode ==
'read' ?
'lire' :
'modifier'))) {
3797 $original_file =
$conf->bank->dir_output.
'/'.$original_file;
3798 } elseif ($modulepart ==
'export' && !empty(
$conf->export->dir_temp)) {
3801 $accessallowed = $fuser->hasRight(
'export', $lire);
3802 $original_file =
$conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3803 } elseif ($modulepart ==
'import' && !empty(
$conf->import->dir_temp)) {
3805 $accessallowed = $user->hasRight(
'import',
'run');
3806 $original_file =
$conf->import->dir_temp.
'/'.$original_file;
3807 } elseif ($modulepart ==
'recruitment' && !empty(
$conf->recruitment->dir_output)) {
3809 $accessallowed = $fuser->hasRight(
'recruitment',
'recruitmentjobposition', $read);
3810 $original_file =
$conf->recruitment->dir_output.
'/'.$original_file;
3811 } elseif ($modulepart ==
'hrm' && !empty(
$conf->hrm->dir_output)) {
3813 $accessallowed = $fuser->hasRight(
'hrm',
'all', $read);
3814 $original_file =
$conf->hrm->dir_output.
'/'.$original_file;
3815 } elseif ($modulepart ==
'editor' && !empty(
$conf->fckeditor->dir_output)) {
3818 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3819 } elseif ($modulepart ==
'systemtools' && !empty(
$conf->admin->dir_output)) {
3821 if ($fuser->admin) {
3824 $original_file =
$conf->admin->dir_output.
'/'.$original_file;
3825 } elseif ($modulepart ==
'admin_temp' && !empty(
$conf->admin->dir_temp)) {
3827 if ($fuser->admin) {
3830 $original_file =
$conf->admin->dir_temp.
'/'.$original_file;
3831 } elseif ($modulepart ==
'bittorrent' && !empty(
$conf->bittorrent->dir_output)) {
3835 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3838 $original_file =
$conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3839 } elseif ($modulepart ==
'member' && !empty(
$conf->member->dir_output)) {
3841 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3844 $original_file =
$conf->member->dir_output.
'/'.$original_file;
3845 } elseif ($modulepart ==
'ticket' && !empty(
$conf->ticket->multidir_output[$entity])) {
3847 if ($fuser->hasRight(
'ticket', $read)) {
3850 if (!isset($_SESSION[
'email_customer'])) {
3852 $sqlprotectagainstexternals =
"SELECT fk_soc FROM ".MAIN_DB_PREFIX.
"ticket WHERE ref='".$db->escape($refname).
"' AND entity=".((int)
$conf->entity);
3854 $email_split = explode(
'@', $_SESSION[
'email_customer']);
3856 $sqlprotectagainstexternals =
'SELECT t.rowid, t.fk_soc FROM '.MAIN_DB_PREFIX.
'ticket t';
3857 $sqlprotectagainstexternals .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'element_contact ec ON ec.element_id = t.rowid';
3858 $sqlprotectagainstexternals .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'socpeople c ON c.rowid = ec.fk_socpeople';
3859 $sqlprotectagainstexternals .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_contact tc ON tc.element = "ticket" AND tc.rowid = ec.fk_c_type_contact';
3860 $sqlprotectagainstexternals .=
" WHERE t.ref LIKE '".$db->escape($refname).
"'";
3861 $sqlprotectagainstexternals .=
' AND (';
3862 $sqlprotectagainstexternals .=
' (';
3863 $sqlprotectagainstexternals .=
' tc.rowid IS NOT NULL';
3864 $sqlprotectagainstexternals .=
" AND c.email = '".$db->escape($email_split[0]).
'@'.$db->sanitize($email_split[1]).
"'";
3865 $sqlprotectagainstexternals .=
' )';
3866 $sqlprotectagainstexternals .=
" OR t.origin_email = '".$db->escape($email_split[0]).
'@'.$db->sanitize($email_split[1]).
"'";
3867 $sqlprotectagainstexternals .=
' )';
3869 $original_file =
$conf->ticket->multidir_output[$entity].
'/'.$original_file;
3877 $checksecureaccesshook =
true;
3880 if (preg_match(
'/^specimen/i', $original_file)) {
3883 if ($fuser->admin) {
3888 $tmpmodulepart = explode(
'-', $modulepart);
3889 if (!empty($tmpmodulepart[1])) {
3890 $modulepart = $tmpmodulepart[0];
3891 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3896 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3897 $tmpmodule = $reg[1];
3898 if (empty(
$conf->$tmpmodule->dir_temp)) {
3899 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3902 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3905 $original_file =
$conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3906 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3907 $tmpmodule = $reg[1];
3908 if (empty(
$conf->$tmpmodule->dir_temp)) {
3909 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3912 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3915 $original_file =
$conf->$tmpmodule->dir_temp.
'/'.$original_file;
3916 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3917 $tmpmodule = $reg[1];
3918 if (empty(
$conf->$tmpmodule->dir_output)) {
3919 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3922 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3925 $original_file =
$conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3926 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3927 $tmpmodule = $reg[1];
3928 if (empty(
$conf->$tmpmodule->dir_output)) {
3929 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3934 $partsofdirinoriginalfile = explode(
'/', $original_file);
3935 if (!empty($partsofdirinoriginalfile[1])) {
3936 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3937 if (($partofdirinoriginalfile && $fuser->hasRight($tmpmodule, $partofdirinoriginalfile,
'read')) || preg_match(
'/^specimen/i', $original_file)) {
3941 if ($fuser->hasRight($tmpmodule, $read) || preg_match(
'/^specimen/i', $original_file)) {
3944 $original_file =
$conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3947 if (empty(
$conf->$modulepart->dir_output)) {
3948 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.');
3953 $partsofdirinoriginalfile = explode(
'/', $original_file);
3954 if (!empty($partsofdirinoriginalfile[1])) {
3955 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3956 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile, $lire) || $fuser->hasRight($modulepart, $partofdirinoriginalfile, $read))) {
3960 if (($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) || ($fuser->hasRight($modulepart,
'all', $lire) || $fuser->hasRight($modulepart,
'all', $read))) {
3966 if (preg_match(
'/^(\w+)@(\w+)$/', $originalmodulepart, $regs)) {
3967 $subdir = $regs[1].
'/';
3970 if (is_array(
$conf->$modulepart->multidir_output) && !empty(
$conf->$modulepart->multidir_output[$entity])) {
3971 $original_file =
$conf->$modulepart->multidir_output[$entity].
'/'.$subdir.$original_file;
3973 $original_file =
$conf->$modulepart->dir_output.
'/'.$subdir.$original_file;
3983 if ($checksecureaccesshook) {
3984 $parameters = array(
3985 'modulepart' => $modulepart,
3986 'original_file' => $original_file,
3987 'entity' => $entity,
3992 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3995 } elseif ($reshook > 0) {
3996 if (!empty($hookmanager->resArray[
'original_file'])) {
3997 $original_file = $hookmanager->resArray[
'original_file'];
4000 if (array_key_exists(
'accessallowed', $hookmanager->resArray)) {
4001 $accessallowed = ($hookmanager->resArray[
'accessallowed'] ? 1 : 0);
4003 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
4004 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
4012 if ($mode !=
'read' && empty($fuser->admin)) {
4013 if (in_array($modulepart, array(
'mycompany',
'companylogo',
'graph_stock',
'graph_fourn',
'graph_product',
'barcode',
'iconmailing',
'fckeditor',
'editor',
'bittorrent'))) {
4016 if ($modulepart ==
'memberphoto' && !$fuser->hasRight(
'adherent', $lire)) {
4022 'accessallowed' => ($accessallowed ? 1 : 0),
4023 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
4024 'original_file' => $original_file