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);
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)) {
3090 if ($mode !=
'read' && empty($fuser->admin) && !$fuser->hasRight(
'user',
'user', $lire) && !((
int) $original_file == $fuser->id && $fuser->hasRight(
'user',
'self', $lire))) {
3093 $original_file = $conf->user->dir_output.
'/'.$original_file;
3094 } elseif ($modulepart ==
'userphotopublic' && !empty($conf->user->dir_output)) {
3099 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
3100 if ((
int) $reg[1]) {
3101 $tmpobject =
new User($db);
3102 $tmpobject->fetch((
int) $reg[1],
'',
'', 1);
3104 $securekey =
GETPOST(
'securekey',
'alpha', 1);
3106 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
3107 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
3108 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
3109 if (hash_equals($encodedsecurekey, (
string) $securekey)) {
3118 $original_file = $conf->user->dir_output.
'/'.$original_file;
3119 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
3122 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
3123 } elseif ($modulepart ==
'memberphoto' && !empty($conf->member->dir_output)) {
3127 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
3131 if (preg_match(
'/^MEM\d\d\d\d-\d\d\d\d\/photos\//', $original_file)) {
3134 $original_file = $conf->member->dir_output.
'/'.$original_file;
3135 } elseif ($modulepart ==
'apercufacture' && !empty($conf->invoice->multidir_output[$entity])) {
3137 if ($fuser->hasRight(
'facture', $lire)) {
3140 $original_file = $conf->invoice->multidir_output[$entity].
'/'.$original_file;
3141 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3142 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
3144 if ($fuser->hasRight(
'propal', $lire)) {
3147 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3148 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3149 } elseif ($modulepart ==
'apercucommande' && !empty($conf->order->multidir_output[$entity])) {
3151 if ($fuser->hasRight(
'commande', $lire)) {
3154 $original_file = $conf->order->multidir_output[$entity].
'/'.$original_file;
3155 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3156 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->multidir_output[$entity])) {
3158 if ($fuser->hasRight(
'ficheinter', $lire)) {
3161 $original_file = $conf->ficheinter->multidir_output[$entity].
'/'.$original_file;
3162 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".((int) $entity);
3163 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contract->multidir_output[$entity])) {
3165 if ($fuser->hasRight(
'contrat', $lire)) {
3168 $original_file = $conf->contract->multidir_output[$entity].
'/'.$original_file;
3169 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3170 } elseif (($modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
3172 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
3175 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
3176 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"supplier_proposal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'supplier_proposal').
")";
3177 } elseif (($modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
3179 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3182 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3183 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity = ".((int) $conf->entity);
3184 } elseif (($modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
3186 if ($fuser->hasRight(
'fournisseur', $lire)) {
3189 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3190 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".((int) $conf->entity);
3191 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
3192 if ($fuser->hasRight(
'holiday', $read) || ($mode ==
'read' && $fuser->hasRight(
'holiday',
'readall')) || preg_match(
'/^specimen/i', $original_file)) {
3195 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3196 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
3197 $tmpholiday =
new Holiday($db);
3198 $tmpholiday->fetch(0, $refname);
3199 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
3202 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
3203 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
3204 if ($fuser->hasRight(
'expensereport', $lire) || ($mode ==
'read' && $fuser->hasRight(
'expensereport',
'readall')) || preg_match(
'/^specimen/i', $original_file)) {
3207 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3208 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
3210 $tmpexpensereport->fetch(0, $refname);
3211 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
3214 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
3215 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
3217 if ($fuser->hasRight(
'expensereport', $lire)) {
3220 if ($fuser->socid > 0) {
3224 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
3225 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
3227 if ($fuser->hasRight(
'propal', $lire)) {
3230 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
3231 } elseif ($modulepart ==
'orderstats' && !empty($conf->order->dir_temp)) {
3233 if ($fuser->hasRight(
'commande', $lire)) {
3236 $original_file = $conf->order->dir_temp.
'/'.$original_file;
3237 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
3238 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3241 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
3242 } elseif ($modulepart ==
'billstats' && !empty($conf->invoice->dir_temp)) {
3244 if ($fuser->hasRight(
'facture', $lire)) {
3247 $original_file = $conf->invoice->dir_temp.
'/'.$original_file;
3248 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
3249 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
3252 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
3253 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
3255 if ($fuser->hasRight(
'expedition', $lire)) {
3258 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
3259 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
3261 if ($fuser->hasRight(
'deplacement', $lire)) {
3264 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
3265 } elseif ($modulepart ==
'memberstats' && !empty($conf->member->dir_temp)) {
3267 if ($fuser->hasRight(
'adherent', $lire)) {
3270 $original_file = $conf->member->dir_temp.
'/'.$original_file;
3271 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
3273 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
3276 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
3277 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
3279 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
3282 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
3283 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
3284 } elseif (($modulepart ==
'actions' || $modulepart ==
'actioncomm') && !empty($conf->agenda->dir_output)) {
3286 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3289 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3290 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3292 $tmpobject->fetch((
int) $refname);
3293 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3294 if ($user->socid && $tmpobject->socid) {
3299 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
3300 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
3302 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
3303 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3305 if ($fuser->hasRight(
"categorie", $lire) || ($mode ==
'read' && $fuser->hasRight(
"takepos",
"run"))) {
3308 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
3309 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
3311 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3314 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
3315 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
3318 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
3319 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
3322 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
3323 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
3326 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
3327 } elseif ($modulepart ==
'barcode') {
3332 $original_file =
'';
3333 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
3336 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
3337 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3340 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3341 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
3344 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3345 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
3347 $canreaduser = (!empty($fuser->admin) || $fuser->hasRight(
'user',
'user', $lire));
3348 if ($fuser->id == (
int) $refname) {
3351 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3354 $original_file = $conf->user->dir_output.
'/'.$original_file;
3355 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
3357 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
3358 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3360 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3363 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
3364 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
3365 } elseif (($modulepart ==
'contact' || $modulepart ==
'socpeople') && !empty($conf->societe->multidir_output[$entity])) {
3367 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
3368 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3370 if ($fuser->hasRight(
'societe', $lire)) {
3373 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3374 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->invoice->multidir_output[$entity])) {
3376 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3379 $original_file = $conf->invoice->multidir_output[$entity].
'/'.$original_file;
3380 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3381 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
3383 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3386 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3387 } elseif ($modulepart ==
'massfilesarea_orders') {
3388 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3391 $original_file = $conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3392 } elseif ($modulepart ==
'massfilesarea_sendings') {
3393 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3396 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3397 } elseif ($modulepart ==
'massfilesarea_receipts') {
3398 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3401 $original_file = $conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3402 } elseif ($modulepart ==
'massfilesarea_invoices') {
3403 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3406 $original_file = $conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3407 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3408 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3411 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3412 } elseif ($modulepart ==
'massfilesarea_interventions') {
3413 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3416 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3417 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
3418 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3421 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3422 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3423 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3426 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3427 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3428 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3431 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3432 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contract->dir_output)) {
3433 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3436 $original_file = $conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3437 } elseif ($modulepart ==
'massfilesarea_stock' && !empty($conf->stock->dir_output)) {
3438 if ($fuser->hasRight(
'stock', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3441 $original_file = $conf->stock->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3442 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->multidir_output[$entity])) {
3444 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3447 $original_file = $conf->ficheinter->multidir_output[$entity].
'/'.$original_file;
3448 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".((int) $entity);
3449 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
3451 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3454 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
3456 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset($conf->propal->multidir_output[$entity])) {
3458 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3461 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3462 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3463 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->order->multidir_output[$entity])) {
3465 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3468 $original_file = $conf->order->multidir_output[$entity].
'/'.$original_file;
3469 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3470 } elseif ($modulepart ==
'project' && !empty($conf->project->multidir_output[$entity])) {
3472 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3475 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3476 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3477 $tmpproject =
new Project($db);
3478 $tmpproject->fetch(0, $refname);
3479 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3482 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3483 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3484 } elseif ($modulepart ==
'project_task' && !empty($conf->project->multidir_output[$entity])) {
3485 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3488 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3489 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3490 $tmptask =
new Task($db);
3491 $tmptask->fetch(0, $refname);
3492 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3495 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3496 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3497 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier' || $modulepart ==
'supplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
3499 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3502 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3503 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3504 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier' || $modulepart ==
'supplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
3506 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3509 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3510 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3511 } elseif ($modulepart ==
'supplier_payment') {
3513 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3516 $original_file = preg_replace(
"/payment\//",
"", $original_file);
3517 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
3518 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3519 } elseif ($modulepart ==
'payment') {
3521 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3524 $original_file = $conf->compta->payment->dir_output.
'/'.$original_file;
3525 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->invoice->dir_output)) {
3527 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3530 if ($fuser->socid > 0) {
3531 $original_file = $conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3533 $original_file = $conf->invoice->dir_output.
'/payments/'.$original_file;
3535 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
3537 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3540 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
3541 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment' || $modulepart ==
'shipping') && !empty($conf->expedition->dir_output)) {
3543 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3546 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3548 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
3550 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3553 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3554 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
3556 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3559 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
3560 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3562 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
3563 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3565 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3569 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
3571 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
3573 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3575 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
3576 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3578 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3582 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3584 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3586 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3587 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3589 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3593 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3595 } elseif ($modulepart ==
'entrepot') {
3597 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3598 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3600 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3604 $original_file = $conf->stock->multidir_output[$entity].
'/'.$original_file;
3606 } elseif ($modulepart ==
'contract' && !empty($conf->contract->multidir_output[$entity])) {
3608 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3611 $original_file = $conf->contract->multidir_output[$entity].
'/'.$original_file;
3612 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3613 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
3615 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3618 $original_file = $conf->don->dir_output.
'/'.$original_file;
3619 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
3621 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3624 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3625 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3627 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3630 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3631 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3634 if ($fuser->hasRight(
'banque', ($mode ==
'read' ?
'lire' :
'modifier'))) {
3637 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3638 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3641 $accessallowed = $fuser->hasRight(
'export', $lire);
3642 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3643 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3645 $accessallowed = $user->hasRight(
'import',
'run');
3646 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3647 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3649 $accessallowed = $fuser->hasRight(
'recruitment',
'recruitmentjobposition', $read);
3650 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3651 } elseif ($modulepart ==
'hrm' && !empty($conf->hrm->dir_output)) {
3653 $accessallowed = $fuser->hasRight(
'hrm',
'all', $read);
3654 $original_file = $conf->hrm->dir_output.
'/'.$original_file;
3655 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3658 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3659 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3661 if ($fuser->admin) {
3664 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3665 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3667 if ($fuser->admin) {
3670 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3671 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3675 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3678 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3679 } elseif ($modulepart ==
'member' && !empty($conf->member->dir_output)) {
3681 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3684 $original_file = $conf->member->dir_output.
'/'.$original_file;
3685 } elseif ($modulepart ==
'ticket' && !empty($conf->ticket->multidir_output[$entity])) {
3687 if ($fuser->hasRight(
'ticket', $read)) {
3690 if (!isset($_SESSION[
'email_customer'])) {
3691 $sqlprotectagainstexternals =
'';
3693 $email_split = explode(
'@', $_SESSION[
'email_customer']);
3695 $sqlprotectagainstexternals =
'SELECT t.rowid, t.fk_soc FROM '.MAIN_DB_PREFIX.
'ticket t';
3696 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'element_contact ec ON ec.element_id = t.rowid';
3697 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'socpeople c ON c.rowid = ec.fk_socpeople';
3698 $sqlprotectagainstexternals.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_contact tc ON tc.element = "ticket" AND tc.rowid = ec.fk_c_type_contact';
3699 $sqlprotectagainstexternals.=
' WHERE t.ref LIKE "'.$db->sanitize($refname).
'"';
3700 $sqlprotectagainstexternals.=
' AND (';
3701 $sqlprotectagainstexternals.=
' (';
3702 $sqlprotectagainstexternals.=
' tc.rowid IS NOT NULL';
3703 $sqlprotectagainstexternals.=
' AND c.email = "'.$db->sanitize($email_split[0]).
'@'.$db->sanitize($email_split[1]).
'"';
3704 $sqlprotectagainstexternals.=
' )';
3705 $sqlprotectagainstexternals.=
' OR t.origin_email = "'.$db->sanitize($email_split[0]).
'@'.$db->sanitize($email_split[1]).
'"';
3706 $sqlprotectagainstexternals.=
' )';
3708 $original_file = $conf->ticket->multidir_output[$entity].
'/'.$original_file;
3718 if (preg_match(
'/^specimen/i', $original_file)) {
3721 if ($fuser->admin) {
3725 $tmpmodulepart = explode(
'-', $modulepart);
3726 if (!empty($tmpmodulepart[1])) {
3727 $modulepart = $tmpmodulepart[0];
3728 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3733 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3734 $tmpmodule = $reg[1];
3735 if (empty($conf->$tmpmodule->dir_temp)) {
3736 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3739 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3742 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3743 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3744 $tmpmodule = $reg[1];
3745 if (empty($conf->$tmpmodule->dir_temp)) {
3746 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3749 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3752 $original_file = $conf->$tmpmodule->dir_temp.
'/'.$original_file;
3753 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3754 $tmpmodule = $reg[1];
3755 if (empty($conf->$tmpmodule->dir_output)) {
3756 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3759 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3762 $original_file = $conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3763 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3764 $tmpmodule = $reg[1];
3765 if (empty($conf->$tmpmodule->dir_output)) {
3766 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3771 $partsofdirinoriginalfile = explode(
'/', $original_file);
3772 if (!empty($partsofdirinoriginalfile[1])) {
3773 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3774 if (($partofdirinoriginalfile && $fuser->hasRight($tmpmodule, $partofdirinoriginalfile,
'read')) || preg_match(
'/^specimen/i', $original_file)) {
3778 if ($fuser->hasRight($tmpmodule, $read) || preg_match(
'/^specimen/i', $original_file)) {
3781 $original_file = $conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3783 if (empty($conf->$modulepart->dir_output)) {
3784 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.');
3789 $partsofdirinoriginalfile = explode(
'/', $original_file);
3790 if (!empty($partsofdirinoriginalfile[1])) {
3791 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3792 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile, $lire) || $fuser->hasRight($modulepart, $partofdirinoriginalfile, $read))) {
3796 if (($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) || ($fuser->hasRight($modulepart,
'all', $lire) || $fuser->hasRight($modulepart,
'all', $read))) {
3800 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3801 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3803 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3807 $parameters = array(
3808 'modulepart' => $modulepart,
3809 'original_file' => $original_file,
3810 'entity' => $entity,
3815 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3817 if (!empty($hookmanager->resArray[
'original_file'])) {
3818 $original_file = $hookmanager->resArray[
'original_file'];
3820 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3821 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3823 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3824 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3832 if ($mode !=
'read' && empty($fuser->admin)) {
3833 if (in_array($modulepart, array(
'mycompany',
'companylogo',
'graph_stock',
'graph_fourn',
'graph_product',
'barcode',
'iconmailing',
'fckeditor',
'editor',
'bittorrent'))) {
3836 if ($modulepart ==
'memberphoto' && !$fuser->hasRight(
'adherent', $lire)) {
3842 'accessallowed' => ($accessallowed ? 1 : 0),
3843 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3844 'original_file' => $original_file