40 return preg_replace(
'/^.*\/([^\/]+)$/',
'$1', rtrim($pathfile,
'/'));
63 function 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)
65 global $db, $hookmanager;
68 if ($recursive <= 1) {
73 $exclude_array = ($excludefilter ===
null || $excludefilter ===
'') ? array() : (is_array($excludefilter) ? $excludefilter : array($excludefilter));
74 foreach ((array($filter) + $exclude_array) as $f) {
76 if ((
int) preg_match(
'/(?:^|[^\\\\])\//', $f) > 0) {
78 $error_info .=
" error='$f unescaped_slash'";
82 dol_syslog(
"files.lib.php::dol_dir_list path=".$utf8_path.
" types=".$types.
" recursive=".$recursive.
" filter=".$filter.
" excludefilter=".json_encode($excludefilter).$error_info);
90 $exclude_array = ($excludefilter ===
null || $excludefilter ===
'') ? array() : (is_array($excludefilter) ? $excludefilter : array($excludefilter));
94 $excludefilterarray = array_merge(array(
'^\.'), $exclude_array);
96 $loaddate = ($mode == 1 || $mode == 2 || $nbsecondsold != 0 || $sortcriteria ==
'date');
97 $loadsize = ($mode == 1 || $mode == 3 || $sortcriteria ==
'size');
98 $loadperm = ($mode == 1 || $mode == 4 || $sortcriteria ==
'perm');
101 $utf8_path = preg_replace(
'/([\\/]+)$/',
'', $utf8_path);
106 $file_list = array();
108 if (!$nohook && $hookmanager instanceof
HookManager) {
109 $hookmanager->resArray = array();
111 $hookmanager->initHooks(array(
'fileslib'));
116 'recursive' => $recursive,
118 'excludefilter' => $exclude_array,
119 'sortcriteria' => $sortcriteria,
120 'sortorder' => $sortorder,
121 'loaddate' => $loaddate,
122 'loadsize' => $loadsize,
125 $reshook = $hookmanager->executeHooks(
'getDirList', $parameters,
$object);
129 if (empty($reshook)) {
130 if (!is_dir($os_path)) {
134 if (($dir = opendir($os_path)) ===
false) {
141 while (
false !== ($os_file = readdir($dir))) {
142 $os_fullpathfile = ($os_path ? $os_path.
'/' :
'').$os_file;
145 $utf8_file = mb_convert_encoding($os_file,
'UTF-8',
'ISO-8859-1');
147 $utf8_file = $os_file;
152 $utf8_fullpathfile =
"$utf8_path/$utf8_file";
155 foreach ($excludefilterarray as $filt) {
156 if (preg_match(
'/'.$filt.
'/i', $utf8_file) || preg_match(
'/'.$filt.
'/i', $utf8_fullpathfile)) {
164 $isdir = is_dir($os_fullpathfile);
168 if (($types ==
"directories") || ($types ==
"all")) {
169 if ($loaddate || $sortcriteria ==
'date') {
172 if ($loadsize || $sortcriteria ==
'size') {
175 if ($loadperm || $sortcriteria ==
'perm') {
179 if (!$filter || preg_match(
'/'.$filter.
'/i', $utf8_file)) {
181 preg_match(
'/([^\/]+)\/[^\/]+$/', $utf8_fullpathfile, $reg);
182 $level1name = (isset($reg[1]) ? $reg[1] :
'');
183 $file_list[] = array(
184 "name" => $utf8_file,
185 "path" => $utf8_path,
186 "level1name" => $level1name,
187 "relativename" => ($relativename ? $relativename.
'/' :
'').$utf8_file,
188 "fullname" => $utf8_fullpathfile,
198 if ($recursive > 0) {
199 if (empty($donotfollowsymlinks) || !is_link($os_fullpathfile)) {
201 $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));
204 } elseif (in_array($types, array(
"files",
"all"))) {
206 if ($loaddate || $sortcriteria ==
'date') {
209 if ($loadsize || $sortcriteria ==
'size') {
213 if (!$filter || preg_match(
'/'.$filter.
'/i', $utf8_file)) {
214 if (empty($nbsecondsold) || $filedate <= ($now - $nbsecondsold)) {
215 preg_match(
'/([^\/]+)\/[^\/]+$/', $utf8_fullpathfile, $reg);
216 $level1name = (isset($reg[1]) ? $reg[1] :
'');
217 $file_list[] = array(
218 "name" => $utf8_file,
219 "path" => $utf8_path,
220 "level1name" => $level1name,
221 "relativename" => ($relativename ? $relativename.
'/' :
'').$utf8_file,
222 "fullname" => $utf8_fullpathfile,
235 if (!empty($sortcriteria) && $sortorder) {
236 $file_list =
dol_sort_array($file_list, $sortcriteria, ($sortorder == SORT_ASC ?
'asc' :
'desc'));
241 if ($hookmanager instanceof
HookManager && is_array($hookmanager->resArray)) {
242 $file_list = array_merge($file_list, $hookmanager->resArray);
262 function dol_dir_list_in_database($path, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0)
267 $sql =
" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams,";
268 $sql .=
" date_c, tms as date_m, fk_user_c, fk_user_m, acl, position, share";
270 $sql .=
", description";
272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_files";
273 $sql .=
" WHERE entity = ".$conf->entity;
274 if (preg_match(
'/%$/', $path)) {
275 $sql .=
" AND filepath LIKE '".$db->escape($path).
"'";
277 $sql .=
" AND filepath = '".$db->escape($path).
"'";
280 $resql = $db->query(
$sql);
282 $file_list = array();
283 $num = $db->num_rows($resql);
286 $obj = $db->fetch_object($resql);
289 preg_match(
'/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename, $reg);
290 $level1name = (isset($reg[1]) ? $reg[1] :
'');
291 $file_list[] = array(
292 "rowid" => $obj->rowid,
293 "label" => $obj->label,
294 "name" => $obj->filename,
295 "path" => DOL_DATA_ROOT.
'/'.$obj->filepath,
296 "level1name" => $level1name,
297 "fullname" => DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename,
298 "fullpath_orig" => $obj->fullpath_orig,
299 "date_c" => $db->jdate($obj->date_c),
300 "date_m" => $db->jdate($obj->date_m),
302 "keywords" => $obj->keywords,
303 "cover" => $obj->cover,
304 "position" => (
int) $obj->position,
306 "share" => $obj->share,
307 "description" => ($mode ? $obj->description :
'')
314 if (!empty($sortcriteria)) {
316 foreach ($file_list as $key => $row) {
317 $myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] :
'');
321 array_multisort($myarray, $sortorder, SORT_REGULAR, $file_list);
343 global $conf, $db, $user;
349 if ($modulepart ==
'produit' &&
getDolGlobalInt(
'PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
353 $upload_dirold = $conf->product->multidir_output[
$object->entity].
'/'.substr(substr(
"000".
$object->id, -2), 1, 1).
'/'.substr(substr(
"000".
$object->id, -2), 0, 1).
'/'.
$object->id.
"/photos";
355 $upload_dirold = $conf->service->multidir_output[
$object->entity].
'/'.substr(substr(
"000".
$object->id, -2), 1, 1).
'/'.substr(substr(
"000".
$object->id, -2), 0, 1).
'/'.
$object->id.
"/photos";
358 $relativedirold = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dirold);
359 $relativedirold = preg_replace(
'/^[\\/]/',
'', $relativedirold);
361 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($relativedirold,
'',
null,
'name', SORT_ASC));
363 } elseif ($modulepart ==
'ticket') {
364 foreach ($filearray as $key => $val) {
365 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'path']);
366 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
367 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
368 if ($rel_dir != $relativedir) {
369 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($rel_dir,
'',
null,
'name', SORT_ASC));
379 foreach ($filearray as $key => $val) {
380 $tmpfilename = preg_replace(
'/\.noexe$/',
'', $filearray[$key][
'name']);
383 foreach ($filearrayindatabase as $key2 => $val2) {
384 if (($filearrayindatabase[$key2][
'path'] == $filearray[$key][
'path']) && ($filearrayindatabase[$key2][
'name'] == $tmpfilename)) {
385 $filearray[$key][
'position_name'] = ($filearrayindatabase[$key2][
'position'] ? $filearrayindatabase[$key2][
'position'] :
'0').
'_'.$filearrayindatabase[$key2][
'name'];
386 $filearray[$key][
'position'] = $filearrayindatabase[$key2][
'position'];
387 $filearray[$key][
'cover'] = $filearrayindatabase[$key2][
'cover'];
388 $filearray[$key][
'keywords'] = $filearrayindatabase[$key2][
'keywords'];
389 $filearray[$key][
'acl'] = $filearrayindatabase[$key2][
'acl'];
390 $filearray[$key][
'rowid'] = $filearrayindatabase[$key2][
'rowid'];
391 $filearray[$key][
'label'] = $filearrayindatabase[$key2][
'label'];
392 $filearray[$key][
'share'] = $filearrayindatabase[$key2][
'share'];
399 $filearray[$key][
'position'] =
'999999';
400 $filearray[$key][
'cover'] = 0;
401 $filearray[$key][
'acl'] =
'';
402 $filearray[$key][
'share'] = 0;
404 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'fullname']);
406 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filename)) {
407 dol_syslog(
"list_of_documents We found a file called '".$filearray[$key][
'name'].
"' not indexed into database. We add it");
408 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
412 $filename = basename($rel_filename);
413 $rel_dir = dirname($rel_filename);
414 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
415 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
417 $ecmfile->filepath = $rel_dir;
418 $ecmfile->filename = $filename;
419 $ecmfile->label = md5_file(
dol_osencode($filearray[$key][
'fullname']));
420 $ecmfile->fullpath_orig = $filearray[$key][
'fullname'];
421 $ecmfile->gen_or_uploaded =
'unknown';
422 $ecmfile->description =
'';
423 $ecmfile->keywords =
'';
424 $result = $ecmfile->create($user);
428 $filearray[$key][
'rowid'] = $result;
431 $filearray[$key][
'rowid'] = 0;
448 global $sortorder, $sortfield;
450 $sortorder = strtoupper($sortorder);
452 if ($sortorder ==
'ASC') {
460 if ($sortfield ==
'name') {
461 if ($a->name == $b->name) {
464 return ($a->name < $b->name) ? $retup : $retdown;
466 if ($sortfield ==
'date') {
467 if ($a->date == $b->date) {
470 return ($a->date < $b->date) ? $retup : $retdown;
472 if ($sortfield ==
'size') {
473 if ($a->size == $b->size) {
476 return ($a->size < $b->size) ? $retup : $retdown;
492 if (is_dir($newfolder)) {
507 if (!is_readable($dir)) {
510 return (count(scandir($dir)) == 2);
522 return is_file($newpathoffile);
534 return is_link($newpathoffile);
546 return is_writable($newfolderorfile);
559 $prots = array(
'file',
'http',
'https',
'ftp',
'zlib',
'data',
'ssh',
'ssh2',
'ogg',
'expect');
560 return false !== preg_match(
'/^('.implode(
'|', $prots).
'):/i', $uri);
572 if (is_dir($newfolder)) {
573 $handle = opendir($newfolder);
574 $folder_content =
'';
576 while ((gettype($name = readdir($handle)) !=
"boolean")) {
577 $name_array[] = $name;
579 foreach ($name_array as $temp) {
580 $folder_content .= $temp;
585 if ($folder_content ==
"...") {
608 $fp = fopen($newfile,
'r');
615 if ($line !==
false) {
638 return filesize($newpathoffile);
650 return @filemtime($newpathoffile);
662 return fileperms($newpathoffile);
677 function dolReplaceInFile($srcfile, $arrayreplacement, $destfile =
'', $newmask =
'0', $indexdatabase = 0, $arrayreplacementisregex = 0)
679 dol_syslog(
"files.lib.php::dolReplaceInFile srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" indexdatabase=".$indexdatabase.
" arrayreplacementisregex=".$arrayreplacementisregex);
681 if (empty($srcfile)) {
684 if (empty($destfile)) {
685 $destfile = $srcfile;
689 $srcfile = preg_replace(
'/\.\.\/?/',
'', $srcfile);
690 $destfile = preg_replace(
'/\.\.\/?/',
'', $destfile);
693 if (($destfile != $srcfile) && $destexists) {
699 dol_syslog(
"files.lib.php::dolReplaceInFile failed to read src file", LOG_WARNING);
703 $tmpdestfile = $destfile.
'.tmp';
708 $newdirdestfile = dirname($newpathofdestfile);
710 if ($destexists && !is_writable($newpathofdestfile)) {
711 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
714 if (!is_writable($newdirdestfile)) {
715 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
722 $content = file_get_contents($newpathofsrcfile);
724 if (empty($arrayreplacementisregex)) {
727 foreach ($arrayreplacement as $key => $value) {
728 $content = preg_replace($key, $value, $content);
732 file_put_contents($newpathoftmpdestfile, $content);
733 dolChmod($newpathoftmpdestfile, $newmask);
736 $result =
dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
738 dol_syslog(
"files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
744 if (empty($newmask)) {
745 dol_syslog(
"Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
749 dolChmod($newpathofdestfile, $newmask);
767 function dol_copy($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 0)
771 dol_syslog(
"files.lib.php::dol_copy srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
773 if (empty($srcfile) || empty($destfile)) {
778 if (!$overwriteifexists && $destexists) {
784 $newdirdestfile = dirname($newpathofdestfile);
786 if ($destexists && !is_writable($newpathofdestfile)) {
787 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
790 if (!is_writable($newdirdestfile)) {
791 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
796 $testvirusarray = array();
799 if (count($testvirusarray)) {
800 dol_syslog(
"files.lib.php::dol_copy canceled because a virus was found into source file. we ignore the copy request.", LOG_WARNING);
806 $result = @copy($newpathofsrcfile, $newpathofdestfile);
809 dol_syslog(
"files.lib.php::dol_copy failed to copy", LOG_WARNING);
815 if (empty($newmask)) {
816 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
820 dolChmod($newpathofdestfile, $newmask);
822 if ($result && $indexdatabase) {
824 $rel_filetocopyafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $newpathofdestfile);
825 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetocopyafter)) {
826 $rel_filetocopyafter = preg_replace(
'/^[\\/]/',
'', $rel_filetocopyafter);
829 dol_syslog(
"Try to copy also entries in database for: ".$rel_filetocopyafter, LOG_DEBUG);
830 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
833 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetocopyafter);
834 if ($resultecmtarget > 0) {
835 dol_syslog(
"ECM dest file found, remove it", LOG_DEBUG);
836 $ecmfiletarget->delete($user);
838 dol_syslog(
"ECM dest file not found, create it", LOG_DEBUG);
842 $resultecm = $ecmSrcfile->fetch(0,
'', $srcfile);
846 dol_syslog(
"Fetch src file error", LOG_DEBUG);
850 $filename = basename($rel_filetocopyafter);
851 $rel_dir = dirname($rel_filetocopyafter);
852 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
853 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
855 $ecmfile->filepath = $rel_dir;
856 $ecmfile->filename = $filename;
858 $ecmfile->fullpath_orig = $srcfile;
859 $ecmfile->gen_or_uploaded =
'copy';
860 $ecmfile->description = $ecmSrcfile->description;
861 $ecmfile->keywords = $ecmSrcfile->keywords;
862 $resultecm = $ecmfile->create($user);
863 if ($resultecm < 0) {
867 dol_syslog(
"Create ECM file error", LOG_DEBUG);
871 if ($resultecm > 0) {
879 return (
int) $result;
896 function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement =
null, $excludesubdir = 0, $excludefileext =
null, $excludearchivefiles = 0)
900 dol_syslog(
"files.lib.php::dolCopyDir srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
902 if (empty($srcfile) || empty($destfile)) {
913 $dirmaskdec = octdec($newmask);
917 $dirmaskdec |= octdec(
'0200');
919 $result =
dol_mkdir($destfile,
'', decoct($dirmaskdec));
931 if (is_dir($ossrcfile)) {
932 $dir_handle = opendir($ossrcfile);
933 while ($file = readdir($dir_handle)) {
934 if ($file !=
"." && $file !=
".." && !is_link($ossrcfile.
"/".$file)) {
935 if (is_dir($ossrcfile.
"/".$file)) {
936 if (empty($excludesubdir) || ($excludesubdir == 2 && strlen($file) == 2)) {
939 if (is_array($arrayreplacement)) {
940 foreach ($arrayreplacement as $key => $val) {
941 $newfile = str_replace($key, $val, $newfile);
945 $tmpresult =
dolCopyDir($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists, $arrayreplacement, $excludesubdir, $excludefileext, $excludearchivefiles);
950 if (is_array($excludefileext)) {
951 $extension = pathinfo($file, PATHINFO_EXTENSION);
952 if (in_array($extension, $excludefileext)) {
958 if ($excludearchivefiles == 1) {
959 $extension = pathinfo($file, PATHINFO_EXTENSION);
960 if (preg_match(
'/^[v|d]\d+$/', $extension)) {
966 if (is_array($arrayreplacement)) {
967 foreach ($arrayreplacement as $key => $val) {
968 $newfile = str_replace($key, $val, $newfile);
971 $tmpresult =
dol_copy($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists);
974 if ($result > 0 && $tmpresult >= 0) {
977 $result = $tmpresult;
984 closedir($dir_handle);
990 return (
int) $result;
1011 function dol_move($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array())
1013 global $user, $db, $conf;
1016 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
1021 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
1025 if ($overwriteifexists || !$destexists) {
1030 $testvirusarray = array();
1033 $testvirusarray =
dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
1034 if (count($testvirusarray)) {
1035 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1041 if (count($testvirusarray)) {
1042 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1047 global $dolibarr_main_restrict_os_commands;
1048 if (!empty($dolibarr_main_restrict_os_commands)) {
1049 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1050 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1051 if (in_array(basename($destfile), $arrayofallowedcommand)) {
1054 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);
1059 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1062 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
1065 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1067 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1072 if ($result && $indexdatabase) {
1074 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1075 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1076 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1077 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1078 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1081 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1082 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1084 $ecmfiletarget =
new EcmFiles($db);
1085 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
1086 if ($resultecmtarget > 0) {
1087 $ecmfiletarget->delete($user);
1091 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
1092 if ($resultecm > 0) {
1093 $filename = basename($rel_filetorenameafter);
1094 $rel_dir = dirname($rel_filetorenameafter);
1095 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1096 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1098 $ecmfile->filepath = $rel_dir;
1099 $ecmfile->filename = $filename;
1101 $resultecm = $ecmfile->update($user);
1102 } elseif ($resultecm == 0) {
1103 $filename = basename($rel_filetorenameafter);
1104 $rel_dir = dirname($rel_filetorenameafter);
1105 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1106 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1108 $ecmfile->filepath = $rel_dir;
1109 $ecmfile->filename = $filename;
1111 $ecmfile->fullpath_orig = basename($srcfile);
1112 $ecmfile->gen_or_uploaded =
'uploaded';
1113 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1114 $ecmfile->description = $moreinfo[
'description'];
1116 $ecmfile->description =
'';
1118 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1119 $ecmfile->keywords = $moreinfo[
'keywords'];
1121 $ecmfile->keywords =
'';
1123 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1124 $ecmfile->note_private = $moreinfo[
'note_private'];
1126 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1127 $ecmfile->note_public = $moreinfo[
'note_public'];
1129 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1130 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1132 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1133 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1136 $resultecm = $ecmfile->create($user);
1137 if ($resultecm < 0) {
1140 } elseif ($resultecm < 0) {
1144 if ($resultecm > 0) {
1152 if (empty($newmask)) {
1159 dolChmod($newpathofdestfile, $newmask);
1175 function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase = 1, $renamedircontent = 1)
1179 dol_syslog(
"files.lib.php::dol_move_dir srcdir=".$srcdir.
" destdir=".$destdir.
" overwritifexists=".$overwriteifexists.
" indexdatabase=".$indexdatabase.
" renamedircontent=".$renamedircontent);
1181 $srcbasename = basename($srcdir);
1185 dol_syslog(
"files.lib.php::dol_move_dir srcdir does not exists. we ignore the move request.");
1189 if ($overwriteifexists || !$destexists) {
1193 $result = @rename($newpathofsrcdir, $newpathofdestdir);
1196 if ($result && $renamedircontent) {
1197 if (file_exists($newpathofdestdir)) {
1198 $destbasename = basename($newpathofdestdir);
1200 if (!empty($files) && is_array($files)) {
1201 foreach ($files as $key => $file) {
1202 if (!file_exists($file[
"fullname"])) {
1205 $filepath = $file[
"path"];
1206 $oldname = $file[
"name"];
1208 $newname = str_replace($srcbasename, $destbasename, $oldname);
1209 if (!empty($newname) && $newname !== $oldname) {
1210 if ($file[
"type"] ==
"dir") {
1211 $res =
dol_move_dir($filepath.
'/'.$oldname, $filepath.
'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent);
1213 $res =
dol_move($filepath.
'/'.$oldname, $filepath.
'/'.$newname, 0, $overwriteifexists, 0, $indexdatabase);
1240 return trim(basename($filename),
".\x00..\x20");
1256 if (!empty($reterrors)) {
1261 if (!class_exists(
'AntiVir')) {
1262 require_once DOL_DOCUMENT_ROOT.
'/core/class/antivir.class.php';
1265 $result = $antivir->dol_avscan_file($src_file);
1267 $reterrors = $antivir->errors;
1283 if (preg_match(
'/\.pdf$/i', $dest_file)) {
1285 dol_syslog(
"dolCheckOnFileName Check that pdf does not contains js code");
1287 $tmp = file_get_contents(trim($src_file));
1288 if (preg_match(
'/[\n\s]+\/JavaScript[\n\s]+/m', $tmp)) {
1289 return array(
'File is a PDF with javascript inside');
1292 dol_syslog(
"dolCheckOnFileName Check js into pdf disabled");
1320 function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles =
'addedfile', $upload_dir =
'')
1326 $file_name = $dest_file;
1329 if (empty($nohook)) {
1330 $reshook = $hookmanager->initHooks(array(
'fileslib'));
1332 $parameters = array(
'dest_file' => $dest_file,
'src_file' => $src_file,
'file_name' => $file_name,
'varfiles' => $varfiles,
'allowoverwrite' => $allowoverwrite);
1333 $reshook = $hookmanager->executeHooks(
'moveUploadedFile', $parameters,
$object);
1336 if (empty($reshook)) {
1338 if ($uploaderrorcode) {
1339 switch ($uploaderrorcode) {
1340 case UPLOAD_ERR_INI_SIZE:
1341 return 'ErrorFileSizeTooLarge';
1342 case UPLOAD_ERR_FORM_SIZE:
1343 return 'ErrorFileSizeTooLarge';
1344 case UPLOAD_ERR_PARTIAL:
1345 return 'ErrorPartialFile';
1346 case UPLOAD_ERR_NO_TMP_DIR:
1347 return 'ErrorNoTmpDir';
1348 case UPLOAD_ERR_CANT_WRITE:
1349 return 'ErrorFailedToWriteInDir';
1350 case UPLOAD_ERR_EXTENSION:
1351 return 'ErrorUploadBlockedByAddon';
1359 if (empty($disablevirusscan) && file_exists($src_file)) {
1361 if (count($checkvirusarray)) {
1362 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.implode(
',', $checkvirusarray), LOG_WARNING);
1363 return 'ErrorFileIsInfectedWithAVirus: '.implode(
',', $checkvirusarray);
1372 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
1373 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
1374 $publicmediasdirwithslash .=
'/';
1377 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0 || !
getDolGlobalInt(
"MAIN_DOCUMENT_DISABLE_NOEXE_IN_MEDIAS_DIR")) {
1378 $file_name .=
'.noexe';
1385 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
1386 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
1392 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
1393 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
1399 $errmsg = implode(
',', $hookmanager->errors);
1400 if (empty($errmsg)) {
1401 $errmsg =
'ErrorReturnedBySomeHooks';
1404 } elseif (empty($reshook)) {
1410 if (!is_writable(dirname($file_name_osencoded))) {
1411 dol_syslog(
"Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded).
" is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1412 return 'ErrorDirNotWritable';
1416 if (!$allowoverwrite) {
1417 if (file_exists($file_name_osencoded)) {
1418 dol_syslog(
"Files.lib::dol_move_uploaded_file File ".$file_name.
" already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
1419 return 'ErrorFileAlreadyExists';
1422 if (is_dir($file_name_osencoded)) {
1423 dol_syslog(
"Files.lib::dol_move_uploaded_file A directory with name ".$file_name.
" already exists. Return 'ErrorDirWithFileNameAlreadyExists'", LOG_WARNING);
1424 return 'ErrorDirWithFileNameAlreadyExists';
1429 $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1432 dol_syslog(
"Files.lib::dol_move_uploaded_file Success to move ".$src_file.
" to ".$file_name.
" - Umask=" .
getDolGlobalString(
'MAIN_UMASK'), LOG_DEBUG);
1433 return $successcode;
1435 dol_syslog(
"Files.lib::dol_move_uploaded_file Failed to move ".$src_file.
" to ".$file_name, LOG_ERR);
1440 return $successcode;
1458 function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0,
$object =
null, $allowdotdot =
false, $indexdatabase = 1, $nolog = 0)
1460 global $db, $user, $langs;
1461 global $hookmanager;
1464 $langs->loadLangs(array(
'other',
'errors'));
1466 if (empty($nolog)) {
1467 dol_syslog(
"dol_delete_file file=".$file.
" disableglob=".$disableglob.
" nophperrors=".$nophperrors.
" nohook=".$nohook);
1472 if ((!$allowdotdot && preg_match(
'/\.\./', $file)) || preg_match(
'/[<>|]/', $file)) {
1473 dol_syslog(
"Refused to delete file ".$file, LOG_WARNING);
1478 if (empty($nohook) && !empty($hookmanager)) {
1479 $hookmanager->initHooks(array(
'fileslib'));
1481 $parameters = array(
1483 'disableglob' => $disableglob,
1484 'nophperrors' => $nophperrors
1486 $reshook = $hookmanager->executeHooks(
'deleteFile', $parameters,
$object);
1489 if (empty($nohook) && $reshook != 0) {
1497 if (empty($disableglob) && !empty($file_osencoded)) {
1499 $globencoded = str_replace(
'[',
'\[', $file_osencoded);
1500 $globencoded = str_replace(
']',
'\]', $globencoded);
1501 $listofdir = glob($globencoded);
1502 if (!empty($listofdir) && is_array($listofdir)) {
1503 foreach ($listofdir as $filename) {
1505 $ok = @unlink($filename);
1507 $ok = unlink($filename);
1511 if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
1512 dol_syslog(
"Error in deletion, but parent directory exists with no permission to write, we try to change permission on parent directory and retry...", LOG_DEBUG);
1513 dolChmod(dirname($filename), decoct(fileperms(dirname($filename)) | 0200));
1516 $ok = @unlink($filename);
1518 $ok = unlink($filename);
1523 if (empty($nolog)) {
1524 dol_syslog(
"Removed file ".$filename, LOG_DEBUG);
1528 $rel_filetodelete = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filename);
1529 if (!preg_match(
'/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1530 if (is_object($db) && $indexdatabase) {
1531 $rel_filetodelete = preg_replace(
'/^[\\/]/',
'', $rel_filetodelete);
1532 $rel_filetodelete = preg_replace(
'/\.noexe$/',
'', $rel_filetodelete);
1534 dol_syslog(
"Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1535 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1537 $result = $ecmfile->fetch(0,
'', $rel_filetodelete);
1538 if ($result >= 0 && $ecmfile->id > 0) {
1539 $result = $ecmfile->delete($user);
1547 dol_syslog(
"Failed to remove file ".$filename, LOG_WARNING);
1553 dol_syslog(
"No files to delete found", LOG_DEBUG);
1558 $ok = @unlink($file_osencoded);
1560 $ok = unlink($file_osencoded);
1563 if (empty($nolog)) {
1564 dol_syslog(
"Removed file ".$file_osencoded, LOG_DEBUG);
1567 dol_syslog(
"Failed to remove file ".$file_osencoded, LOG_WARNING);
1588 if (preg_match(
'/\.\./', $dir) || preg_match(
'/[<>|]/', $dir)) {
1589 dol_syslog(
"Refused to delete dir ".$dir.
' (contains invalid char sequence)', LOG_WARNING);
1594 return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1609 function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0, $indexdatabase = 1, $nolog = 0)
1611 if (empty($nolog)) {
1612 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1616 if ($handle = opendir(
"$dir_osencoded")) {
1617 while (
false !== ($item = readdir($handle))) {
1619 $item = mb_convert_encoding($item,
'UTF-8',
'ISO-8859-1');
1622 if ($item !=
"." && $item !=
"..") {
1626 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0,
null,
false, $indexdatabase, $nolog);
1638 if (empty($onlysub)) {
1663 global $langs, $conf;
1668 if (
$object->element ==
'order_supplier') {
1669 $dir = $conf->fournisseur->commande->dir_output;
1670 } elseif (
$object->element ==
'invoice_supplier') {
1671 $dir = $conf->fournisseur->facture->dir_output;
1672 } elseif (
$object->element ==
'project') {
1673 $dir = $conf->project->dir_output;
1674 } elseif (
$object->element ==
'shipping') {
1675 $dir = $conf->expedition->dir_output.
'/sending';
1676 } elseif (
$object->element ==
'delivery') {
1677 $dir = $conf->expedition->dir_output.
'/receipt';
1678 } elseif (
$object->element ==
'fichinter') {
1679 $dir = $conf->ficheinter->dir_output;
1681 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1685 $object->error = $langs->trans(
'ErrorObjectNoSupportedByFunction');
1690 $dir = $dir.
"/".$refsan;
1691 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1692 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1693 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1696 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1698 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1702 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1704 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1709 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1711 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1715 $multiple = $filepreviewold.
".";
1716 for ($i = 0; $i < 20; $i++) {
1717 $preview = $multiple.$i;
1719 if (file_exists($preview) && is_writable($preview)) {
1721 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1751 if (
$object->element ==
'order_supplier') {
1752 $dir = $conf->fournisseur->dir_output.
'/commande';
1753 } elseif (
$object->element ==
'invoice_supplier') {
1754 $dir = $conf->fournisseur->dir_output.
'/facture';
1755 } elseif (
$object->element ==
'project') {
1756 $dir = $conf->project->dir_output;
1757 } elseif (
$object->element ==
'shipping') {
1758 $dir = $conf->expedition->dir_output.
'/sending';
1759 } elseif (
$object->element ==
'delivery') {
1760 $dir = $conf->expedition->dir_output.
'/receipt';
1761 } elseif (
$object->element ==
'fichinter') {
1762 $dir = $conf->ficheinter->dir_output;
1764 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1771 $dir = $dir.
"/".$objectref;
1772 $file = $dir.
"/".$objectref.
".meta";
1774 if (!is_dir($dir)) {
1780 $nblines = count(
$object->lines);
1783 $meta =
"REFERENCE=\"".$object->ref.
"\"
1785 NB_ITEMS=\"" . $nblines.
"\"
1786 CLIENT=\"" . $client.
"\"
1787 AMOUNT_EXCL_TAX=\"" .
$object->total_ht.
"\"
1788 AMOUNT=\"" .
$object->total_ttc.
"\"\n";
1790 for ($i = 0; $i < $nblines; $i++) {
1792 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".
$object->lines[$i]->qty.
"\"
1793 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".
$object->lines[$i]->total_ht.
"\"
1794 ITEM_" . $i.
"_VAT=\"".
$object->lines[$i]->tva_tx.
"\"
1795 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br(
$object->lines[$i]->desc)).
"\"
1800 $fp = fopen($file,
"w");
1808 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.
$object->element, LOG_WARNING);
1826 $listofpaths = array();
1827 $listofnames = array();
1828 $listofmimes = array();
1832 foreach ($listoffiles as $key => $val) {
1833 $listofpaths[] = $val[
'fullname'];
1834 $listofnames[] = $val[
'name'];
1838 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1839 $_SESSION[
"listofpaths".$keytoavoidconflict] = implode(
';', $listofpaths);
1840 $_SESSION[
"listofnames".$keytoavoidconflict] = implode(
';', $listofnames);
1841 $_SESSION[
"listofmimes".$keytoavoidconflict] = implode(
';', $listofmimes);
1862 function dol_add_file_process($upload_dir, $allowoverwrite = 0, $updatesessionordb = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1,
$object =
null)
1864 global $db, $user, $conf, $langs;
1868 if (!empty($_FILES[$varfiles])) {
1869 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' donotupdatesession='.$updatesessionordb.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1870 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
1871 if (is_array($_FILES[$varfiles][
"name"]) && count($_FILES[$varfiles][
"name"]) > $maxfilesinform) {
1872 $langs->load(
"errors");
1873 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
1879 $TFile = $_FILES[$varfiles];
1881 if (!is_array($TFile[
'name'])) {
1882 foreach ($TFile as $key => &$val) {
1887 $nbfile = count($TFile[
'name']);
1889 for ($i = 0; $i < $nbfile; $i++) {
1890 if (empty($TFile[
'name'][$i])) {
1895 $destfile = trim($TFile[
'name'][$i]);
1896 $destfull = $upload_dir.
"/".$destfile;
1897 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1899 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1900 $destfile = trim(preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask));
1901 $destfull = $upload_dir.
"/".$destfile;
1904 $filenameto = basename($destfile);
1905 if (preg_match(
'/^\./', $filenameto)) {
1906 $langs->load(
"errors");
1907 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
1911 $info = pathinfo($destfull);
1912 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1913 $info = pathinfo($destfile);
1914 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1922 global $dolibarr_main_restrict_os_commands;
1923 if (!empty($dolibarr_main_restrict_os_commands)) {
1924 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1925 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1926 if (in_array($destfile, $arrayofallowedcommand)) {
1927 $langs->load(
"errors");
1928 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
1934 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
1936 if (is_numeric($resupload) && $resupload > 0) {
1937 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
1940 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
1941 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
1942 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
1943 $maxheightmini = $tmparraysize[
'maxheightmini'];
1948 if ($generatethumbs) {
1954 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
1957 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
1962 if (empty($updatesessionordb)) {
1963 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1965 $formmail->trackid = $trackid;
1966 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
1970 if ($updatesessionordb == 1) {
1972 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false &&
getDolGlobalString(
'PRODUCT_ALLOW_EXTERNAL_DOWNLOAD')) {
1975 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile,
$object);
1977 if ($allowoverwrite) {
1980 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
1987 $langs->load(
"errors");
1988 if (is_numeric($resupload) && $resupload < 0) {
1990 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
1991 if (preg_match(
'/File is a PDF with javascript inside/', $resupload)) {
1992 setEventMessages($langs->trans(
"ErrorFileIsAnInfectedPDFWithJSInside"),
null,
'errors');
1994 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"),
null,
'errors');
2006 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
2009 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2010 $linkObject =
new Link($db);
2011 $linkObject->entity = $conf->entity;
2012 $linkObject->url = $link;
2013 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
2014 $linkObject->objectid =
GETPOSTINT(
'objectid');
2015 $linkObject->label =
GETPOST(
'label',
'alpha');
2016 $res = $linkObject->create($user);
2024 $langs->load(
"errors");
2025 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
2045 global $db, $user, $conf, $langs, $_FILES;
2047 $keytodelete = $filenb;
2050 $listofpaths = array();
2051 $listofnames = array();
2052 $listofmimes = array();
2053 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
2054 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
2055 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
2057 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
2058 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
2060 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
2061 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
2064 if ($keytodelete >= 0) {
2065 $pathtodelete = $listofpaths[$keytodelete];
2066 $filetodelete = $listofnames[$keytodelete];
2067 if (empty($donotdeletefile)) {
2073 if (empty($donotdeletefile)) {
2074 $langs->load(
"other");
2075 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
2077 if (empty($donotupdatesession)) {
2078 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2080 $formmail->trackid = $trackid;
2081 $formmail->remove_attached_files($keytodelete);
2103 global $db, $user, $conf;
2107 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2109 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
2110 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
2111 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2112 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2114 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
2116 $ecmfile->filepath = $rel_dir;
2117 $ecmfile->filename = $filename;
2118 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
2119 $ecmfile->fullpath_orig = $fullpathorig;
2120 $ecmfile->gen_or_uploaded = $mode;
2121 $ecmfile->description =
'';
2122 $ecmfile->keywords =
'';
2125 $ecmfile->src_object_id =
$object->id;
2126 if (isset(
$object->table_element)) {
2127 $ecmfile->src_object_type =
$object->table_element;
2129 dol_syslog(
'Error: object ' . get_class(
$object) .
' has no table_element attribute.');
2132 if (isset(
$object->src_object_description)) {
2133 $ecmfile->description =
$object->src_object_description;
2135 if (isset(
$object->src_object_keywords)) {
2136 $ecmfile->keywords =
$object->src_object_keywords;
2145 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2152 if ($useFullTextIndexation) {
2153 $ecmfile->filepath = $rel_dir;
2154 $ecmfile->filename = $filename;
2156 $filetoprocess = $dir.
'/'.$ecmfile->filename;
2158 $textforfulltextindex =
'';
2160 if (preg_match(
'/\.pdf/i', $filename)) {
2165 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2166 $utils =
new Utils($db);
2167 $outputfile = $conf->admin->dir_temp.
'/tmppdttotext.'.$user->id.
'.out';
2171 $cmd =
getDolGlobalString(
'MAIN_USE_FULL_TEXT_INDEXATION_PDFTOTEXT',
'pdftotext').
" -htmlmeta '".escapeshellcmd($filetoprocess).
"' - ";
2172 $result = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2174 if (!$result[
'error']) {
2175 $txt = $result[
'output'];
2177 if (preg_match(
'/<meta name="Keywords" content="([^\/]+)"\s*\/>/i', $txt, $matches)) {
2178 $keywords = $matches[1];
2180 if (preg_match(
'/<pre>(.*)<\/pre>/si', $txt, $matches)) {
2186 $ecmfile->description = $textforfulltextindex;
2187 $ecmfile->keywords = $keywords;
2190 $result = $ecmfile->create($user);
2209 global $conf, $db, $user;
2214 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
2220 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2222 $filename = basename($file);
2223 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2224 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2227 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
2228 $sql .=
' WHERE entity = '.$conf->entity;
2229 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
2231 $sql .=
" AND filename = '".$db->escape($file).
"'";
2234 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
2237 $resql = $db->query(
$sql);
2240 dol_syslog(__FUNCTION__.
' '.$db->lasterror(), LOG_ERR);
2268 if (class_exists(
'Imagick')) {
2269 $image =
new Imagick();
2271 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
2273 $ret = $image->readImage($filetoconvert);
2275 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
2276 dol_syslog(
"Failed to read image using Imagick (Try to install package 'apt-get install php-imagick ghostscript' and check there is no policy to disable ".$ext.
" conversion in /etc/ImageMagick*/policy.xml): ".$e->getMessage(), LOG_WARNING);
2280 $ret = $image->setImageFormat($ext);
2282 if (empty($fileoutput)) {
2283 $fileoutput = $fileinput.
".".$ext;
2286 $count = $image->getNumberImages();
2288 if (!
dol_is_file($fileoutput) || is_writable($fileoutput)) {
2290 $ret = $image->writeImages($fileoutput,
true);
2295 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2325 function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring =
null)
2331 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2334 if ($mode ==
'gz' && function_exists(
'gzencode')) {
2336 $compressdata = gzencode($data, 9);
2337 } elseif ($mode ==
'bz' && function_exists(
'bzcompress')) {
2339 $compressdata = bzcompress($data, 9);
2340 } elseif ($mode ==
'zstd' && function_exists(
'zstd_compress')) {
2342 $compressdata = zstd_compress($data, 9);
2343 } elseif ($mode ==
'zip') {
2344 if (class_exists(
'ZipArchive') &&
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS')) {
2347 $rootPath = realpath($inputfile);
2349 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2350 $zip =
new ZipArchive();
2352 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2353 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2357 $errormsg = $errorstring;
2364 $files =
new RecursiveIteratorIterator(
2365 new RecursiveDirectoryIterator($rootPath, FilesystemIterator::UNIX_PATHS),
2366 RecursiveIteratorIterator::LEAVES_ONLY
2369 foreach ($files as $name => $file) {
2371 if (!$file->isDir()) {
2373 $filePath = $file->getPath();
2374 $fileName = $file->getFilename();
2375 $fileFullRealPath = $file->getRealPath();
2378 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2381 $zip->addFile($fileFullRealPath, $relativePath);
2388 dol_syslog(
"dol_compress_file success - ".$zip->numFiles.
" files");
2392 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2395 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2396 $archive =
new PclZip($outputfile);
2398 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2400 if ($result === 0) {
2402 $errormsg = $archive->errorInfo(
true);
2404 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2405 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2406 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2410 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2411 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2414 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2420 if ($foundhandler) {
2421 $fp = fopen($outputfile,
"w");
2422 fwrite($fp, $compressdata);
2426 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2430 $errormsg = $errorstring;
2434 global $langs, $errormsg;
2435 $langs->load(
"errors");
2436 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2438 $errorstring =
"Failed to open file ".$outputfile;
2456 $fileinfo = pathinfo($inputfile);
2457 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2459 if ($fileinfo[
"extension"] ==
"zip") {
2460 if (defined(
'ODTPHP_PATHTOPCLZIP') && !
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS')) {
2461 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2462 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2463 $archive =
new PclZip($inputfile);
2470 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2472 return array(
'error' => $e->getMessage());
2475 if (!is_array($result) && $result <= 0) {
2476 return array(
'error' => $archive->errorInfo(
true));
2481 foreach ($result as $key => $val) {
2482 if ($val[
'status'] ==
'path_creation_fail') {
2483 $langs->load(
"errors");
2485 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2488 if ($val[
'status'] ==
'write_protected') {
2489 $langs->load(
"errors");
2491 $errmsg = $langs->trans(
"ErrorFailToCreateFile", $val[
'filename']);
2499 return array(
'error' => $errmsg);
2504 if (class_exists(
'ZipArchive')) {
2505 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2506 $zip =
new ZipArchive();
2507 $res = $zip->open($inputfile);
2508 if ($res ===
true) {
2514 for ($i = 0; $i < $zip->numFiles; $i++) {
2515 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2516 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2519 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2525 return array(
'error' =>
'ErrUnzipFails');
2529 return array(
'error' =>
'ErrNoZipEngine');
2530 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2531 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2532 $utils =
new Utils($db);
2539 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2540 if ($extension ==
"tar") {
2543 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2544 if ($resarray[
"result"] != 0) {
2545 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2549 if ($fileinfo[
"extension"] ==
"gz") {
2551 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2553 } elseif ($fileinfo[
"extension"] ==
"zst") {
2556 return array(
'error' =>
'ErrorBadFileExtension');
2559 $cmd .=
' > '.$outputfilename;
2561 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0,
null, 1, $outputfilename.
'.err');
2562 if ($resarray[
"result"] != 0) {
2563 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2564 if ($errfilecontent) {
2565 $resarray[
"error"] .=
" - ".$errfilecontent;
2569 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2572 return array(
'error' =>
'ErrorBadFileExtension');
2588 function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'', $newmask =
'0')
2592 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2594 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2595 global $langs, $errormsg;
2596 $langs->load(
"errors");
2597 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2602 if ($mode ==
'gz') {
2604 } elseif ($mode ==
'bz') {
2606 } elseif ($mode ==
'zip') {
2620 if (class_exists(
'ZipArchive')) {
2624 $zip =
new ZipArchive();
2625 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2626 if ($result !==
true) {
2627 global $langs, $errormsg;
2628 $langs->load(
"errors");
2629 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile);
2636 $files =
new RecursiveIteratorIterator(
2637 new RecursiveDirectoryIterator($inputdir, FilesystemIterator::UNIX_PATHS),
2638 RecursiveIteratorIterator::LEAVES_ONLY
2642 foreach ($files as $name => $file) {
2644 if (!$file->isDir()) {
2646 $filePath = $file->getPath();
2647 $fileName = $file->getFilename();
2648 $fileFullRealPath = $file->getRealPath();
2651 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2654 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2656 $zip->addFile($fileFullRealPath, $relativePath);
2667 if (empty($newmask)) {
2668 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
2678 if (!$foundhandler) {
2679 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2685 global $langs, $errormsg;
2686 $langs->load(
"errors");
2687 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2689 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile).
' - '.$e->getMessage();
2706 function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook = 0, $mode = 0)
2708 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2709 return isset($tmparray[0]) ? $tmparray[0] :
null;
2727 global $conf, $db, $user, $hookmanager;
2728 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2731 if (!is_object($fuser)) {
2735 if (empty($modulepart)) {
2736 return 'ErrorBadParameter';
2738 if (empty($entity)) {
2746 if ($modulepart ==
'facture') {
2747 $modulepart =
'invoice';
2748 } elseif ($modulepart ==
'users') {
2749 $modulepart =
'user';
2750 } elseif ($modulepart ==
'tva') {
2751 $modulepart =
'tax-vat';
2752 } elseif ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
2754 $modulepart =
'delivery';
2758 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2762 $sqlprotectagainstexternals =
'';
2766 if (empty($refname)) {
2767 $refname = basename(dirname($original_file).
"/");
2768 if ($refname ==
'thumbs' || $refname ==
'temp') {
2770 $refname = basename(dirname(dirname($original_file)).
"/");
2777 $download =
'download';
2778 if ($mode ==
'write') {
2781 $download =
'upload';
2785 if ($modulepart ==
'common') {
2788 $original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/'.$original_file;
2789 } elseif ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2790 if (empty($entity) || empty($conf->medias->multidir_output[$entity])) {
2791 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
2794 $original_file = $conf->medias->multidir_output[$entity].
'/'.$original_file;
2795 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2797 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
2798 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2799 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2801 $accessallowed = $user->admin;
2802 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2803 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2805 $accessallowed = ($fuser->hasRight(
'website',
'write') && preg_match(
'/\.jpg$/i', basename($original_file)));
2806 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2807 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2810 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2813 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2814 $original_file = $dirins.
'/'.$original_file;
2815 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
2818 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
2819 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
2822 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2825 $original_file = $conf->user->dir_output.
'/'.$original_file;
2826 } elseif ($modulepart ==
'userphotopublic' && !empty($conf->user->dir_output)) {
2831 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
2833 $tmpobject =
new User($db);
2834 $tmpobject->fetch($reg[1],
'',
'', 1);
2836 $securekey =
GETPOST(
'securekey',
'alpha', 1);
2838 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
2839 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
2840 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
2841 if ($encodedsecurekey == $securekey) {
2850 $original_file = $conf->user->dir_output.
'/'.$original_file;
2851 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
2854 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
2855 } elseif ($modulepart ==
'memberphoto' && !empty($conf->member->dir_output)) {
2858 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2861 $original_file = $conf->member->dir_output.
'/'.$original_file;
2862 } elseif ($modulepart ==
'apercufacture' && !empty($conf->invoice->multidir_output[$entity])) {
2864 if ($fuser->hasRight(
'facture', $lire)) {
2867 $original_file = $conf->invoice->multidir_output[$entity].
'/'.$original_file;
2868 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
2870 if ($fuser->hasRight(
'propal', $lire)) {
2873 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2874 } elseif ($modulepart ==
'apercucommande' && !empty($conf->order->multidir_output[$entity])) {
2876 if ($fuser->hasRight(
'commande', $lire)) {
2879 $original_file = $conf->order->multidir_output[$entity].
'/'.$original_file;
2880 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->dir_output)) {
2882 if ($fuser->hasRight(
'ficheinter', $lire)) {
2885 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2886 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contract->multidir_output[$entity])) {
2888 if ($fuser->hasRight(
'contrat', $lire)) {
2891 $original_file = $conf->contract->multidir_output[$entity].
'/'.$original_file;
2892 } elseif (($modulepart ==
'apercusupplier_proposal' || $modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
2894 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
2897 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
2898 } elseif (($modulepart ==
'apercusupplier_order' || $modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
2900 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2903 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2904 } elseif (($modulepart ==
'apercusupplier_invoice' || $modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
2906 if ($fuser->hasRight(
'fournisseur', $lire)) {
2909 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2910 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
2911 if ($fuser->hasRight(
'holiday', $read) || $fuser->hasRight(
'holiday',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
2914 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
2915 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
2916 $tmpholiday =
new Holiday($db);
2917 $tmpholiday->fetch(
'', $refname);
2918 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
2921 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
2922 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
2923 if ($fuser->hasRight(
'expensereport', $lire) || $fuser->hasRight(
'expensereport',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
2926 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
2927 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
2929 $tmpexpensereport->fetch(
'', $refname);
2930 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
2933 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2934 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
2936 if ($fuser->hasRight(
'expensereport', $lire)) {
2939 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2940 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
2942 if ($fuser->hasRight(
'propal', $lire)) {
2945 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
2946 } elseif ($modulepart ==
'orderstats' && !empty($conf->order->dir_temp)) {
2948 if ($fuser->hasRight(
'commande', $lire)) {
2951 $original_file = $conf->order->dir_temp.
'/'.$original_file;
2952 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2953 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2956 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
2957 } elseif ($modulepart ==
'billstats' && !empty($conf->invoice->dir_temp)) {
2959 if ($fuser->hasRight(
'facture', $lire)) {
2962 $original_file = $conf->invoice->dir_temp.
'/'.$original_file;
2963 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2964 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
2967 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
2968 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
2970 if ($fuser->hasRight(
'expedition', $lire)) {
2973 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
2974 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
2976 if ($fuser->hasRight(
'deplacement', $lire)) {
2979 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
2980 } elseif ($modulepart ==
'memberstats' && !empty($conf->member->dir_temp)) {
2982 if ($fuser->hasRight(
'adherent', $lire)) {
2985 $original_file = $conf->member->dir_temp.
'/'.$original_file;
2986 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
2988 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
2991 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
2992 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
2994 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
2997 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
2998 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
2999 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
3001 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3004 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3005 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3007 $tmpobject->fetch((
int) $refname);
3008 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3009 if ($user->socid && $tmpobject->socid) {
3014 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
3015 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
3017 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
3018 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3020 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
3023 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
3024 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
3026 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3029 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
3030 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
3033 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
3034 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
3037 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
3038 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
3041 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
3042 } elseif ($modulepart ==
'barcode') {
3047 $original_file =
'';
3048 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
3051 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
3052 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3055 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3056 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
3059 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3060 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
3062 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
3063 if ($fuser->id == (
int) $refname) {
3066 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3069 $original_file = $conf->user->dir_output.
'/'.$original_file;
3070 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
3072 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
3073 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3075 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3078 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
3079 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
3080 } elseif ($modulepart ==
'contact' && !empty($conf->societe->multidir_output[$entity])) {
3082 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
3083 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3085 if ($fuser->hasRight(
'societe', $lire)) {
3088 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3089 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->invoice->multidir_output[$entity])) {
3091 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3094 $original_file = $conf->invoice->multidir_output[$entity].
'/'.$original_file;
3095 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3096 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
3098 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3101 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3102 } elseif ($modulepart ==
'massfilesarea_orders') {
3103 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3106 $original_file = $conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3107 } elseif ($modulepart ==
'massfilesarea_sendings') {
3108 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3111 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3112 } elseif ($modulepart ==
'massfilesarea_receipts') {
3113 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3116 $original_file = $conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3117 } elseif ($modulepart ==
'massfilesarea_invoices') {
3118 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3121 $original_file = $conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3122 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3123 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3126 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3127 } elseif ($modulepart ==
'massfilesarea_interventions') {
3128 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3131 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3132 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
3133 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3136 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3137 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3138 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3141 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3142 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3143 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3146 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3147 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contract->dir_output)) {
3148 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3151 $original_file = $conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3152 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->dir_output)) {
3154 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3157 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
3158 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3159 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
3161 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3164 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
3166 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset($conf->propal->multidir_output[$entity])) {
3168 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3171 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3172 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3173 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->order->multidir_output[$entity])) {
3175 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3178 $original_file = $conf->order->multidir_output[$entity].
'/'.$original_file;
3179 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3180 } elseif ($modulepart ==
'project' && !empty($conf->project->multidir_output[$entity])) {
3182 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3185 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3186 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3187 $tmpproject =
new Project($db);
3188 $tmpproject->fetch(
'', $refname);
3189 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3192 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3193 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3194 } elseif ($modulepart ==
'project_task' && !empty($conf->project->multidir_output[$entity])) {
3195 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3198 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3199 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3200 $tmptask =
new Task($db);
3201 $tmptask->fetch(
'', $refname);
3202 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3205 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3206 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3207 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
3209 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3212 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3213 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3214 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
3216 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3219 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3220 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3221 } elseif ($modulepart ==
'supplier_payment') {
3223 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3226 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
3227 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3228 } elseif ($modulepart ==
'payment') {
3230 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3233 $original_file = $conf->compta->payment->dir_output.
'/'.$original_file;
3234 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->invoice->dir_output)) {
3236 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3239 if ($fuser->socid > 0) {
3240 $original_file = $conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3242 $original_file = $conf->invoice->dir_output.
'/payments/'.$original_file;
3244 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
3246 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3249 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
3250 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty($conf->expedition->dir_output)) {
3252 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3255 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3257 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
3259 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3262 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3263 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
3265 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3268 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
3269 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3271 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
3272 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3274 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3278 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
3280 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
3282 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3284 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
3285 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3287 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3291 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3293 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3295 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3296 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3298 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3302 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3304 } elseif ($modulepart ==
'contract' && !empty($conf->contract->multidir_output[$entity])) {
3306 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3309 $original_file = $conf->contract->multidir_output[$entity].
'/'.$original_file;
3310 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3311 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
3313 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3316 $original_file = $conf->don->dir_output.
'/'.$original_file;
3317 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
3319 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3322 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3323 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3325 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3328 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3329 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3331 if ($fuser->hasRight(
'banque', $lire)) {
3334 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3335 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3338 $accessallowed = $user->hasRight(
'export',
'lire');
3339 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3340 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3342 $accessallowed = $user->hasRight(
'import',
'run');
3343 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3344 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3346 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3347 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3348 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3351 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3352 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3354 if ($fuser->admin) {
3357 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3358 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3360 if ($fuser->admin) {
3363 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3364 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3368 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3371 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3372 } elseif ($modulepart ==
'member' && !empty($conf->member->dir_output)) {
3374 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3377 $original_file = $conf->member->dir_output.
'/'.$original_file;
3387 if (preg_match(
'/^specimen/i', $original_file)) {
3390 if ($fuser->admin) {
3394 $tmpmodulepart = explode(
'-', $modulepart);
3395 if (!empty($tmpmodulepart[1])) {
3396 $modulepart = $tmpmodulepart[0];
3397 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3402 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3403 $tmpmodule = $reg[1];
3404 if (empty($conf->$tmpmodule->dir_temp)) {
3405 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3408 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3411 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3412 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3413 $tmpmodule = $reg[1];
3414 if (empty($conf->$tmpmodule->dir_temp)) {
3415 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3418 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3421 $original_file = $conf->$tmpmodule->dir_temp.
'/'.$original_file;
3422 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3423 $tmpmodule = $reg[1];
3424 if (empty($conf->$tmpmodule->dir_output)) {
3425 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3428 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3431 $original_file = $conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3432 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3433 $tmpmodule = $reg[1];
3434 if (empty($conf->$tmpmodule->dir_output)) {
3435 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3438 if ($fuser->hasRight($tmpmodule, $lire) || preg_match(
'/^specimen/i', $original_file)) {
3441 $original_file = $conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3443 if (empty($conf->$modulepart->dir_output)) {
3444 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.');
3449 $partsofdirinoriginalfile = explode(
'/', $original_file);
3450 if (!empty($partsofdirinoriginalfile[1])) {
3451 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3452 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3456 if ($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) {
3460 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3461 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3463 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3467 $parameters = array(
3468 'modulepart' => $modulepart,
3469 'original_file' => $original_file,
3470 'entity' => $entity,
3475 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3477 if (!empty($hookmanager->resArray[
'original_file'])) {
3478 $original_file = $hookmanager->resArray[
'original_file'];
3480 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3481 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3483 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3484 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3490 'accessallowed' => ($accessallowed ? 1 : 0),
3491 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3492 'original_file' => $original_file
3511 dol_syslog(
"Failed to create the cache directory ".$directory, LOG_WARNING);
3514 $cachefile = $directory.$filename;
3516 file_put_contents($cachefile, serialize(
$object), LOCK_EX);
3532 $cachefile = $directory.$filename;
3533 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3546 $cachefile = $directory.$filename;
3547 $object = unserialize(file_get_contents($cachefile));
3559 return preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'\//',
'', $pathfile);
3574 function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3578 $exclude =
'install';
3580 foreach ($dir->md5file as $file) {
3581 $filename = $path.$file[
'name'];
3582 $file_list[
'insignature'][] = $filename;
3583 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3584 $expectedmd5 = (string) $file;
3586 if (!file_exists($pathref.
'/'.$filename)) {
3587 $file_list[
'missing'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize);
3589 $md5_local = md5_file($pathref.
'/'.$filename);
3591 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3592 $checksumconcat[] = $expectedmd5;
3594 if ($md5_local != $expectedmd5) {
3595 $file_list[
'updated'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize,
'md5' => (
string) $md5_local);
3597 $checksumconcat[] = $md5_local;
3602 foreach ($dir->dir as $subdir) {
3603 getFilesUpdated($file_list, $subdir, $path.$subdir[
'name'].
'/', $pathref, $checksumconcat);
3621 $out .=
'<div id="'.$htmlname.
'Message" class="dragDropAreaMessage hidden"><span>'.
img_picto(
"",
'download').
'<br>'.$langs->trans(
"DropFileToAddItToObject").
'</span></div>';
3622 $out .=
"\n<!-- JS CODE TO ENABLE DRAG AND DROP OF FILE -->\n";
3625 jQuery(document).ready(function() {
3626 var enterTargetDragDrop = null;
3628 $("#'.$htmlname.
'").addClass("cssDragDropArea");
3630 $(".cssDragDropArea").on("dragenter", function(ev, ui) {
3631 var dataTransfer = ev.originalEvent.dataTransfer;
3632 var dataTypes = dataTransfer.types;
3633 //console.log(dataTransfer);
3634 //console.log(dataTypes);
3636 if (!dataTypes || ($.inArray(\'Files\', dataTypes) === -1)) {
3637 // The element dragged is not a file, so we avoid the "dragenter"
3638 ev.preventDefault();
3642 // Entering drop area. Highlight area
3643 console.log("dragAndDropFileUpload: We add class highlightDragDropArea")
3644 enterTargetDragDrop = ev.target;
3645 $(this).addClass("highlightDragDropArea");
3646 $("#'.$htmlname.
'Message").removeClass("hidden");
3647 ev.preventDefault();
3650 $(".cssDragDropArea").on("dragleave", function(ev) {
3651 // Going out of drop area. Remove Highlight
3652 if (enterTargetDragDrop == ev.target){
3653 console.log("dragAndDropFileUpload: We remove class highlightDragDropArea")
3654 $("#'.$htmlname.
'Message").addClass("hidden");
3655 $(this).removeClass("highlightDragDropArea");
3659 $(".cssDragDropArea").on("dragover", function(ev) {
3660 ev.preventDefault();
3664 $(".cssDragDropArea").on("drop", function(e) {
3667 fd = new FormData();
3671 fd.append("action", "linkit");
3673 var dataTransfer = e.originalEvent.dataTransfer;
3675 if (dataTransfer.files && dataTransfer.files.length){
3676 var droppedFiles = e.originalEvent.dataTransfer.files;
3677 $.each(droppedFiles, function(index,file){
3678 fd.append("files[]", file,file.name)
3681 $(".cssDragDropArea").removeClass("highlightDragDropArea");
3682 counterdragdrop = 0;
3684 url: "'.DOL_URL_ROOT.
'/core/ajax/fileupload.php",
3689 success:function() {
3690 console.log("Uploaded.", arguments);
3691 /* arguments[0] is the json string of files */
3692 /* arguments[1] is the value for variable "success", can be 0 or 1 */
3693 let listoffiles = JSON.parse(arguments[0]);
3694 console.log(listoffiles);
3696 for (let i = 0; i < listoffiles.length; i++) {
3697 console.log(listoffiles[i].error);
3698 if (listoffiles[i].error) {
3702 console.log(nboferror);
3703 if (nboferror > 0) {
3704 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorOnAtLeastOneFileUpload:warnings";
3706 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=UploadFileDragDropSuccess:mesgs";
3710 console.log("Error Uploading.", arguments)
3711 if (arguments[0].status == 403) {
3712 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadPermissionDenied:errors";
3714 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadFileDragDropPermissionDenied:errors";
3720 $out .=
"</script>\n";
3734 function archiveOrBackupFile($filetpl, $max_versions = 5, $archivedir =
'', $suffix =
"v", $moveorcopy =
'move')
3736 $base_file_pattern = ($archivedir ? $archivedir : dirname($filetpl)).
'/'.basename($filetpl).
".".$suffix;
3737 $files_in_directory = glob($base_file_pattern .
"*");
3740 $files_with_timestamps = [];
3741 foreach ($files_in_directory as $file) {
3742 $files_with_timestamps[] = [
3744 'timestamp' => filemtime($file)
3750 while (count($files_with_timestamps) > 0) {
3751 $latest_file =
null;
3752 $latest_index =
null;
3755 foreach ($files_with_timestamps as $index => $file_info) {
3756 if ($latest_file ===
null || (is_array($latest_file) && $file_info[
'timestamp'] > $latest_file[
'timestamp'])) {
3757 $latest_file = $file_info;
3758 $latest_index = $index;
3763 if ($latest_file !==
null) {
3764 $sorted_files[] = $latest_file[
'file'];
3765 unset($files_with_timestamps[$latest_index]);
3770 if (count($sorted_files) >= $max_versions) {
3771 $oldest_files = array_slice($sorted_files, $max_versions - 1);
3772 foreach ($oldest_files as $oldest_file) {
3778 $new_backup = $filetpl .
".v" . $timestamp;
3781 if ($moveorcopy ==
'move') {
3782 $result =
dol_move($filetpl, $new_backup,
'0', 1, 0, 0);
3784 $result =
dol_copy($filetpl, $new_backup,
'0', 1, 0, 0);
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage agenda events (actions)
Class to manage ECM files.
Class to manage Trips and Expenses.
Class of the module paid holiday.
Class to manage projects.
Class to manage Dolibarr users.
Class to manage utility methods.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
dirbasename($pathfile)
Return the relative dirname (relative to DOL_DATA_ROOT) of a full path string.
dol_is_link($pathoffile)
Return if path is a symbolic link.
dol_compare_file($a, $b)
Fast compare of 2 files identified by their properties ->name, ->date and ->size.
dol_meta_create($object)
Create a meta file with document file into same directory.
dol_is_url($uri)
Return if path is an URI (the name of the method is misleading).
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path='', $pathref='', &$checksumconcat=array())
Function to get list of updated or modified files.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
archiveOrBackupFile($filetpl, $max_versions=5, $archivedir='', $suffix="v", $moveorcopy='move')
Manage backup versions for a given file, ensuring only a maximum number of versions are kept.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
dol_fileperm($pathoffile)
Return permissions of a file.
dol_is_writable($folderorfile)
Test if directory or filename is writable.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_init_file_process($pathtoscan='', $trackid='')
Scan a directory and init $_SESSION to manage uploaded files with list of all found files.
addFileIntoDatabaseIndex($dir, $file, $fullpathorig='', $mode='uploaded', $setsharekey=0, $object=null)
Add a file into database index.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
dol_filecache($directory, $filename, $object)
Store object in file.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0)
Scan a directory and return a list of files/directories.
dragAndDropFileUpload($htmlname)
Function to manage the drag and drop of a file.
dol_is_file($pathoffile)
Return if path is a file.
dol_count_nb_of_line($file)
Count number of lines in a file.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=0, $mode=0)
Return file(s) into a directory (by default most recent)
dolCheckVirus($src_file, $dest_file='')
Check virus into a file.
dol_unescapefile($filename)
Unescape a file submitted by upload.
dol_dir_is_emtpy($folder)
Test if a folder is empty.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
dolCheckOnFileName($src_file, $dest_file='')
Check virus into a file.
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)
Scan a directory and return a list of files/directories.
deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded')
Delete files into database index using search criteria.
dol_readcachefile($directory, $filename)
Read object from cachefile.
dol_is_dir($folder)
Test if filename is a directory.
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
Complete $filearray with data from database.
dol_cache_refresh($directory, $filename, $cachetime)
Test if Refresh needed.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask='0', $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_delete_preview($object)
Delete all preview files linked to object instance.
dol_is_dir_empty($dir)
Return if path is empty.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
currentToken()
Return the value of token currently saved into session with name 'token'.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
vignette($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
if(!defined('IMAGETYPE_WEBP')) getDefaultImageSizes()
Return default values for image sizes.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
checkUserAccessToObject($user, array $featuresarray, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='', $dbt_select='rowid', $parenttableforentity='')
Check that access by a given user to an object is ok.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.