38 return preg_replace(
'/^.*\/([^\/]+)$/',
'$1', rtrim($pathfile,
'/'));
60 function dol_dir_list($path, $types =
"all", $recursive = 0, $filter =
"", $excludefilter = null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename =
"", $donotfollowsymlinks = 0)
62 global $db, $hookmanager;
65 if ($recursive <= 1) {
66 dol_syslog(
"files.lib.php::dol_dir_list path=".$path.
" types=".$types.
" recursive=".$recursive.
" filter=".$filter.
" excludefilter=".json_encode($excludefilter));
70 $loaddate = ($mode == 1 || $mode == 2) ?
true:
false;
71 $loadsize = ($mode == 1 || $mode == 3) ?
true:
false;
72 $loadperm = ($mode == 1 || $mode == 4) ?
true:
false;
75 $path = preg_replace(
'/([\\/]+)$/i',
'', $path);
81 if (is_object($hookmanager) && !$nohook) {
82 $hookmanager->resArray = array();
84 $hookmanager->initHooks(array(
'fileslib'));
89 'recursive' => $recursive,
91 'excludefilter' => $excludefilter,
92 'sortcriteria' => $sortcriteria,
93 'sortorder' => $sortorder,
94 'loaddate' => $loaddate,
95 'loadsize' => $loadsize,
98 $reshook = $hookmanager->executeHooks(
'getDirList', $parameters, $object);
102 if (empty($reshook)) {
103 if (!is_dir($newpath)) {
107 if ($dir = opendir($newpath)) {
111 while (
false !== ($file = readdir($dir))) {
113 $file = utf8_encode($file);
115 $fullpathfile = ($newpath ? $newpath.
'/' :
'').$file;
120 $excludefilterarray = array(
'^\.');
121 if (is_array($excludefilter)) {
122 $excludefilterarray = array_merge($excludefilterarray, $excludefilter);
123 } elseif ($excludefilter) {
124 $excludefilterarray[] = $excludefilter;
127 foreach ($excludefilterarray as $filt) {
128 if (preg_match(
'/'.$filt.
'/i', $file) || preg_match(
'/'.$filt.
'/i', $fullpathfile)) {
138 if ($isdir && (($types ==
"directories") || ($types ==
"all") || $recursive > 0)) {
140 if (($types ==
"directories") || ($types ==
"all")) {
141 if ($loaddate || $sortcriteria ==
'date') {
144 if ($loadsize || $sortcriteria ==
'size') {
147 if ($loadperm || $sortcriteria ==
'perm') {
151 if (!$filter || preg_match(
'/'.$filter.
'/i', $file)) {
153 preg_match(
'/([^\/]+)\/[^\/]+$/', $path.
'/'.$file, $reg);
154 $level1name = (isset($reg[1]) ? $reg[1] :
'');
155 $file_list[] = array(
158 "level1name" => $level1name,
159 "relativename" => ($relativename ? $relativename.
'/' :
'').$file,
160 "fullname" => $path.
'/'.$file,
170 if ($recursive > 0) {
171 if (empty($donotfollowsymlinks) || !is_link($path.
"/".$file)) {
173 $file_list = array_merge($file_list,
dol_dir_list($path.
"/".$file, $types, $recursive + 1, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename !=
'' ? $relativename.
'/' :
'').$file, $donotfollowsymlinks));
176 } elseif (!$isdir && (($types ==
"files") || ($types ==
"all"))) {
178 if ($loaddate || $sortcriteria ==
'date') {
181 if ($loadsize || $sortcriteria ==
'size') {
185 if (!$filter || preg_match(
'/'.$filter.
'/i', $file)) {
186 preg_match(
'/([^\/]+)\/[^\/]+$/', $path.
'/'.$file, $reg);
187 $level1name = (isset($reg[1]) ? $reg[1] :
'');
188 $file_list[] = array(
191 "level1name" => $level1name,
192 "relativename" => ($relativename ? $relativename.
'/' :
'').$file,
193 "fullname" => $path.
'/'.$file,
205 if (!empty($sortcriteria) && $sortorder) {
206 $file_list =
dol_sort_array($file_list, $sortcriteria, ($sortorder == SORT_ASC ?
'asc' :
'desc'));
211 if (is_object($hookmanager) && is_array($hookmanager->resArray)) {
212 $file_list = array_merge($file_list, $hookmanager->resArray);
232 function dol_dir_list_in_database($path, $filter =
"", $excludefilter = null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0)
236 $sql =
" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams,";
237 $sql .=
" date_c, tms as date_m, fk_user_c, fk_user_m, acl, position, share";
239 $sql .=
", description";
241 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_files";
242 $sql .=
" WHERE entity = ".$conf->entity;
243 if (preg_match(
'/%$/', $path)) {
244 $sql .=
" AND filepath LIKE '".$db->escape($path).
"'";
246 $sql .=
" AND filepath = '".$db->escape($path).
"'";
249 $resql = $db->query($sql);
251 $file_list = array();
252 $num = $db->num_rows(
$resql);
255 $obj = $db->fetch_object(
$resql);
258 preg_match(
'/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename, $reg);
259 $level1name = (isset($reg[1]) ? $reg[1] :
'');
260 $file_list[] = array(
261 "rowid" => $obj->rowid,
262 "label" => $obj->label,
263 "name" => $obj->filename,
264 "path" => DOL_DATA_ROOT.
'/'.$obj->filepath,
265 "level1name" => $level1name,
266 "fullname" => DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename,
267 "fullpath_orig" => $obj->fullpath_orig,
268 "date_c" => $db->jdate($obj->date_c),
269 "date_m" => $db->jdate($obj->date_m),
271 "keywords" => $obj->keywords,
272 "cover" => $obj->cover,
273 "position" => (int) $obj->position,
275 "share" => $obj->share,
276 "description" => ($mode ? $obj->description :
'')
283 if (!empty($sortcriteria)) {
285 foreach ($file_list as $key => $row) {
286 $myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] :
'');
290 array_multisort($myarray, $sortorder, $file_list);
312 global $conf, $db, $user;
318 if ($modulepart ==
'produit' && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
320 if (!empty($object->id)) {
321 if (!empty($conf->product->enabled)) {
322 $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";
324 $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";
327 $relativedirold = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dirold);
328 $relativedirold = preg_replace(
'/^[\\/]/',
'', $relativedirold);
330 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($relativedirold,
'', null,
'name', SORT_ASC));
339 foreach ($filearray as $key => $val) {
340 $tmpfilename = preg_replace(
'/\.noexe$/',
'', $filearray[$key][
'name']);
343 foreach ($filearrayindatabase as $key2 => $val2) {
344 if (($filearrayindatabase[$key2][
'path'] == $filearray[$key][
'path']) && ($filearrayindatabase[$key2][
'name'] == $tmpfilename)) {
345 $filearray[$key][
'position_name'] = ($filearrayindatabase[$key2][
'position'] ? $filearrayindatabase[$key2][
'position'] :
'0').
'_'.$filearrayindatabase[$key2][
'name'];
346 $filearray[$key][
'position'] = $filearrayindatabase[$key2][
'position'];
347 $filearray[$key][
'cover'] = $filearrayindatabase[$key2][
'cover'];
348 $filearray[$key][
'acl'] = $filearrayindatabase[$key2][
'acl'];
349 $filearray[$key][
'rowid'] = $filearrayindatabase[$key2][
'rowid'];
350 $filearray[$key][
'label'] = $filearrayindatabase[$key2][
'label'];
351 $filearray[$key][
'share'] = $filearrayindatabase[$key2][
'share'];
358 $filearray[$key][
'position'] =
'999999';
359 $filearray[$key][
'cover'] = 0;
360 $filearray[$key][
'acl'] =
'';
362 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'fullname']);
364 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filename)) {
365 dol_syslog(
"list_of_documents We found a file called '".$filearray[$key][
'name'].
"' not indexed into database. We add it");
366 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
370 $filename = basename($rel_filename);
371 $rel_dir = dirname($rel_filename);
372 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
373 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
375 $ecmfile->filepath = $rel_dir;
376 $ecmfile->filename = $filename;
377 $ecmfile->label = md5_file(
dol_osencode($filearray[$key][
'fullname']));
378 $ecmfile->fullpath_orig = $filearray[$key][
'fullname'];
379 $ecmfile->gen_or_uploaded =
'unknown';
380 $ecmfile->description =
'';
381 $ecmfile->keywords =
'';
382 $result = $ecmfile->create($user);
386 $filearray[$key][
'rowid'] = $result;
389 $filearray[$key][
'rowid'] = 0;
409 $sortorder = strtoupper($sortorder);
411 if ($sortorder ==
'ASC') {
419 if ($sortfield ==
'name') {
420 if ($a->name == $b->name) {
423 return ($a->name < $b->name) ? $retup : $retdown;
425 if ($sortfield ==
'date') {
426 if ($a->date == $b->date) {
429 return ($a->date < $b->date) ? $retup : $retdown;
431 if ($sortfield ==
'size') {
432 if ($a->size == $b->size) {
435 return ($a->size < $b->size) ? $retup : $retdown;
449 if (is_dir($newfolder)) {
464 if (!is_readable($dir)) {
467 return (count(scandir($dir)) == 2);
479 return is_file($newpathoffile);
491 return is_link($newpathoffile);
502 $tmpprot = array(
'file',
'http',
'https',
'ftp',
'zlib',
'data',
'ssh',
'ssh2',
'ogg',
'expect');
503 foreach ($tmpprot as $prot) {
504 if (preg_match(
'/^'.$prot.
':/i', $url)) {
520 if (is_dir($newfolder)) {
521 $handle = opendir($newfolder);
522 $folder_content =
'';
523 while ((gettype($name = readdir($handle)) !=
"boolean")) {
524 $name_array[] = $name;
526 foreach ($name_array as $temp) {
527 $folder_content .= $temp;
532 if ($folder_content ==
"...") {
555 $fp = fopen($newfile,
'r');
560 if (!$line ===
false) {
583 return filesize($newpathoffile);
595 return @filemtime($newpathoffile);
607 return fileperms($newpathoffile);
622 function dolReplaceInFile($srcfile, $arrayreplacement, $destfile =
'', $newmask = 0, $indexdatabase = 0, $arrayreplacementisregex = 0)
626 dol_syslog(
"files.lib.php::dolReplaceInFile srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" indexdatabase=".$indexdatabase.
" arrayreplacementisregex=".$arrayreplacementisregex);
628 if (empty($srcfile)) {
631 if (empty($destfile)) {
632 $destfile = $srcfile;
636 if (($destfile != $srcfile) && $destexists) {
640 $tmpdestfile = $destfile.
'.tmp';
645 $newdirdestfile = dirname($newpathofdestfile);
647 if ($destexists && !is_writable($newpathofdestfile)) {
648 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
651 if (!is_writable($newdirdestfile)) {
652 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
659 $content = file_get_contents($newpathofsrcfile,
'r');
661 if (empty($arrayreplacementisregex)) {
664 foreach ($arrayreplacement as $key => $value) {
665 $content = preg_replace($key, $value, $content);
669 file_put_contents($newpathoftmpdestfile, $content);
670 @chmod($newpathoftmpdestfile, octdec($newmask));
673 $result =
dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
675 dol_syslog(
"files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
678 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
679 $newmask = $conf->global->MAIN_UMASK;
681 if (empty($newmask)) {
682 dol_syslog(
"Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
686 @chmod($newpathofdestfile, octdec($newmask));
702 function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
706 dol_syslog(
"files.lib.php::dol_copy srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
708 if (empty($srcfile) || empty($destfile)) {
713 if (!$overwriteifexists && $destexists) {
719 $newdirdestfile = dirname($newpathofdestfile);
721 if ($destexists && !is_writable($newpathofdestfile)) {
722 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
725 if (!is_writable($newdirdestfile)) {
726 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
730 $result = @copy($newpathofsrcfile, $newpathofdestfile);
733 dol_syslog(
"files.lib.php::dol_copy failed to copy", LOG_WARNING);
736 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
737 $newmask = $conf->global->MAIN_UMASK;
739 if (empty($newmask)) {
740 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
744 @chmod($newpathofdestfile, octdec($newmask));
761 function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement = null, $excludesubdir = 0)
767 dol_syslog(
"files.lib.php::dolCopyDir srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
769 if (empty($srcfile) || empty($destfile)) {
779 $dirmaskdec = octdec($newmask);
780 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
781 $dirmaskdec = octdec($conf->global->MAIN_UMASK);
783 $dirmaskdec |= octdec(
'0200');
784 dol_mkdir($destfile,
'', decoct($dirmaskdec));
791 if (is_dir($ossrcfile)) {
792 $dir_handle = opendir($ossrcfile);
793 while ($file = readdir($dir_handle)) {
794 if ($file !=
"." && $file !=
".." && !is_link($ossrcfile.
"/".$file)) {
795 if (is_dir($ossrcfile.
"/".$file)) {
796 if (empty($excludesubdir) || ($excludesubdir == 2 && strlen($file) == 2)) {
799 if (is_array($arrayreplacement)) {
800 foreach ($arrayreplacement as $key => $val) {
801 $newfile = str_replace($key, $val, $newfile);
805 $tmpresult =
dolCopyDir($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists, $arrayreplacement, $excludesubdir);
810 if (is_array($arrayreplacement)) {
811 foreach ($arrayreplacement as $key => $val) {
812 $newfile = str_replace($key, $val, $newfile);
815 $tmpresult =
dol_copy($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists);
818 if ($result > 0 && $tmpresult >= 0) {
821 $result = $tmpresult;
828 closedir($dir_handle);
854 function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1)
856 global $user, $db, $conf;
859 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
864 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
868 if ($overwriteifexists || !$destexists) {
873 $testvirusarray = array();
876 if (count($testvirusarray)) {
877 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
882 $result = @rename($newpathofsrcfile, $newpathofdestfile);
885 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
888 $result = @rename($newpathofsrcfile, $newpathofdestfile);
890 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
895 if ($result && $indexdatabase) {
897 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
898 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
899 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
900 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
901 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
904 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
905 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
908 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
909 if ($resultecmtarget > 0) {
910 $ecmfiletarget->delete($user);
914 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
915 if ($resultecm > 0) {
916 $filename = basename($rel_filetorenameafter);
917 $rel_dir = dirname($rel_filetorenameafter);
918 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
919 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
921 $ecmfile->filepath = $rel_dir;
922 $ecmfile->filename = $filename;
924 $resultecm = $ecmfile->update($user);
925 } elseif ($resultecm == 0) {
926 $filename = basename($rel_filetorenameafter);
927 $rel_dir = dirname($rel_filetorenameafter);
928 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
929 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
931 $ecmfile->filepath = $rel_dir;
932 $ecmfile->filename = $filename;
934 $ecmfile->fullpath_orig = $srcfile;
935 $ecmfile->gen_or_uploaded =
'unknown';
936 $ecmfile->description =
'';
937 $ecmfile->keywords =
'';
938 $resultecm = $ecmfile->create($user);
939 if ($resultecm < 0) {
942 } elseif ($resultecm < 0) {
946 if ($resultecm > 0) {
954 if (empty($newmask)) {
955 $newmask = empty($conf->global->MAIN_UMASK) ?
'0755' : $conf->global->MAIN_UMASK;
957 $newmaskdec = octdec($newmask);
961 @chmod($newpathofdestfile, $newmaskdec);
978 function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase = 1, $renamedircontent = 1)
981 global $user, $db, $conf;
984 dol_syslog(
"files.lib.php::dol_move_dir srcdir=".$srcdir.
" destdir=".$destdir.
" overwritifexists=".$overwriteifexists.
" indexdatabase=".$indexdatabase.
" renamedircontent=".$renamedircontent);
986 $srcbasename = basename($srcdir);
990 dol_syslog(
"files.lib.php::dol_move_dir srcdir does not exists. we ignore the move request.");
994 if ($overwriteifexists || !$destexists) {
998 $result = @rename($newpathofsrcdir, $newpathofdestdir);
1000 if ($result && $renamedircontent) {
1001 if (file_exists($newpathofdestdir)) {
1002 $destbasename = basename($newpathofdestdir);
1004 if (!empty($files) && is_array($files)) {
1005 foreach ($files as $key => $file) {
1006 if (!file_exists($file[
"fullname"]))
continue;
1007 $filepath = $file[
"path"];
1008 $oldname = $file[
"name"];
1010 $newname = str_replace($srcbasename, $destbasename, $oldname);
1011 if (!empty($newname) && $newname !== $oldname) {
1012 if ($file[
"type"] ==
"dir") {
1013 $res =
dol_move_dir($filepath.
'/'.$oldname, $filepath.
'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent);
1015 $res =
dol_move($filepath.
'/'.$oldname, $filepath.
'/'.$newname);
1042 return trim(basename($filename),
".\x00..\x20");
1056 if (!empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) {
1057 if (!class_exists(
'AntiVir')) {
1058 require_once DOL_DOCUMENT_ROOT.
'/core/class/antivir.class.php';
1061 $result = $antivir->dol_avscan_file($src_file);
1063 $reterrors = $antivir->errors;
1091 function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles =
'addedfile', $upload_dir =
'')
1093 global $conf, $db, $user, $langs;
1094 global $object, $hookmanager;
1097 $file_name = $dest_file;
1100 if (empty($nohook)) {
1101 $reshook = $hookmanager->initHooks(array(
'fileslib'));
1103 $parameters = array(
'dest_file' => $dest_file,
'src_file' => $src_file,
'file_name' => $file_name,
'varfiles' => $varfiles,
'allowoverwrite' => $allowoverwrite);
1104 $reshook = $hookmanager->executeHooks(
'moveUploadedFile', $parameters, $object);
1107 if (empty($reshook)) {
1109 if ($uploaderrorcode) {
1110 switch ($uploaderrorcode) {
1111 case UPLOAD_ERR_INI_SIZE:
1112 return 'ErrorFileSizeTooLarge';
1113 case UPLOAD_ERR_FORM_SIZE:
1114 return 'ErrorFileSizeTooLarge';
1115 case UPLOAD_ERR_PARTIAL:
1116 return 'ErrorPartialFile';
1117 case UPLOAD_ERR_NO_TMP_DIR:
1118 return 'ErrorNoTmpDir';
1119 case UPLOAD_ERR_CANT_WRITE:
1120 return 'ErrorFailedToWriteInDir';
1121 case UPLOAD_ERR_EXTENSION:
1122 return 'ErrorUploadBlockedByAddon';
1129 if (empty($disablevirusscan) && file_exists($src_file)) {
1131 if (count($checkvirusarray)) {
1132 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.join(
',', $checkvirusarray), LOG_WARNING);
1133 return 'ErrorFileIsInfectedWithAVirus: '.join(
',', $checkvirusarray);
1142 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
1143 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
1144 $publicmediasdirwithslash .=
'/';
1147 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) {
1148 $file_name .=
'.noexe';
1155 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
1156 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
1162 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
1163 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
1169 $errmsg = join(
',', $hookmanager->errors);
1170 if (empty($errmsg)) {
1171 $errmsg =
'ErrorReturnedBySomeHooks';
1174 } elseif (empty($reshook)) {
1180 if (!is_writable(dirname($file_name_osencoded))) {
1181 dol_syslog(
"Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded).
" is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1182 return 'ErrorDirNotWritable';
1186 if (!$allowoverwrite) {
1187 if (file_exists($file_name_osencoded)) {
1188 dol_syslog(
"Files.lib::dol_move_uploaded_file File ".$file_name.
" already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
1189 return 'ErrorFileAlreadyExists';
1192 if (is_dir($file_name_osencoded)) {
1193 dol_syslog(
"Files.lib::dol_move_uploaded_file A directory with name ".$file_name.
" already exists. Return 'ErrorDirWithFileNameAlreadyExists'", LOG_WARNING);
1194 return 'ErrorDirWithFileNameAlreadyExists';
1199 $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1201 if (!empty($conf->global->MAIN_UMASK)) {
1202 @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1204 dol_syslog(
"Files.lib::dol_move_uploaded_file Success to move ".$src_file.
" to ".$file_name.
" - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
1205 return $successcode;
1207 dol_syslog(
"Files.lib::dol_move_uploaded_file Failed to move ".$src_file.
" to ".$file_name, LOG_ERR);
1212 return $successcode;
1230 function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0, $object = null, $allowdotdot =
false, $indexdatabase = 1, $nolog = 0)
1232 global $db, $conf, $user, $langs;
1233 global $hookmanager;
1236 $langs->loadLangs(array(
'other',
'errors'));
1238 if (empty($nolog)) {
1239 dol_syslog(
"dol_delete_file file=".$file.
" disableglob=".$disableglob.
" nophperrors=".$nophperrors.
" nohook=".$nohook);
1244 if ((!$allowdotdot && preg_match(
'/\.\./', $file)) || preg_match(
'/[<>|]/', $file)) {
1245 dol_syslog(
"Refused to delete file ".$file, LOG_WARNING);
1250 if (empty($nohook)) {
1251 $hookmanager->initHooks(array(
'fileslib'));
1253 $parameters = array(
1256 'disableglob'=> $disableglob,
1257 'nophperrors' => $nophperrors
1259 $reshook = $hookmanager->executeHooks(
'deleteFile', $parameters, $object);
1262 if (empty($nohook) && $reshook != 0) {
1270 if (empty($disableglob) && !empty($file_osencoded)) {
1272 $globencoded = str_replace(
'[',
'\[', $file_osencoded);
1273 $globencoded = str_replace(
']',
'\]', $globencoded);
1274 $listofdir = glob($globencoded);
1275 if (!empty($listofdir) && is_array($listofdir)) {
1276 foreach ($listofdir as $filename) {
1278 $ok = @unlink($filename);
1280 $ok = unlink($filename);
1284 if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
1285 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);
1286 @chmod(dirname($filename), fileperms(dirname($filename)) | 0200);
1289 $ok = @unlink($filename);
1291 $ok = unlink($filename);
1296 if (empty($nolog)) {
1297 dol_syslog(
"Removed file ".$filename, LOG_DEBUG);
1301 $rel_filetodelete = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filename);
1302 if (!preg_match(
'/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1303 if (is_object($db) && $indexdatabase) {
1304 $rel_filetodelete = preg_replace(
'/^[\\/]/',
'', $rel_filetodelete);
1305 $rel_filetodelete = preg_replace(
'/\.noexe$/',
'', $rel_filetodelete);
1307 dol_syslog(
"Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1308 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1310 $result = $ecmfile->fetch(0,
'', $rel_filetodelete);
1311 if ($result >= 0 && $ecmfile->id > 0) {
1312 $result = $ecmfile->delete($user);
1320 dol_syslog(
"Failed to remove file ".$filename, LOG_WARNING);
1326 dol_syslog(
"No files to delete found", LOG_DEBUG);
1331 $ok = @unlink($file_osencoded);
1333 $ok = unlink($file_osencoded);
1336 if (empty($nolog)) {
1337 dol_syslog(
"Removed file ".$file_osencoded, LOG_DEBUG);
1340 dol_syslog(
"Failed to remove file ".$file_osencoded, LOG_WARNING);
1361 if (preg_match(
'/\.\./', $dir) || preg_match(
'/[<>|]/', $dir)) {
1362 dol_syslog(
"Refused to delete dir ".$dir, LOG_WARNING);
1367 return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1382 function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0, $indexdatabase = 1, $nolog = 0)
1384 if (empty($nolog)) {
1385 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1389 if ($handle = opendir(
"$dir_osencoded")) {
1390 while (
false !== ($item = readdir($handle))) {
1392 $item = utf8_encode($item);
1395 if ($item !=
"." && $item !=
"..") {
1399 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0, null,
false, $indexdatabase, $nolog);
1411 if (empty($onlysub)) {
1436 global $langs, $conf;
1439 $element = $object->element;
1441 if ($object->element ==
'order_supplier') {
1442 $dir = $conf->fournisseur->commande->dir_output;
1443 } elseif ($object->element ==
'invoice_supplier') {
1444 $dir = $conf->fournisseur->facture->dir_output;
1445 } elseif ($object->element ==
'project') {
1446 $dir = $conf->project->dir_output;
1447 } elseif ($object->element ==
'shipping') {
1448 $dir = $conf->expedition->dir_output.
'/sending';
1449 } elseif ($object->element ==
'delivery') {
1450 $dir = $conf->expedition->dir_output.
'/receipt';
1451 } elseif ($object->element ==
'fichinter') {
1452 $dir = $conf->ficheinter->dir_output;
1454 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1458 return 'ErrorObjectNoSupportedByFunction';
1462 $dir = $dir.
"/".$refsan;
1463 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1464 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1465 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1468 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1470 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1474 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1476 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1481 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1483 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1487 $multiple = $filepreviewold.
".";
1488 for ($i = 0; $i < 20; $i++) {
1489 $preview = $multiple.$i;
1491 if (file_exists($preview) && is_writable($preview)) {
1493 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1516 if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) {
1521 $element = $object->element;
1523 if ($object->element ==
'order_supplier') {
1524 $dir = $conf->fournisseur->dir_output.
'/commande';
1525 } elseif ($object->element ==
'invoice_supplier') {
1526 $dir = $conf->fournisseur->dir_output.
'/facture';
1527 } elseif ($object->element ==
'project') {
1528 $dir = $conf->project->dir_output;
1529 } elseif ($object->element ==
'shipping') {
1530 $dir = $conf->expedition->dir_output.
'/sending';
1531 } elseif ($object->element ==
'delivery') {
1532 $dir = $conf->expedition->dir_output.
'/receipt';
1533 } elseif ($object->element ==
'fichinter') {
1534 $dir = $conf->ficheinter->dir_output;
1536 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1540 $object->fetch_thirdparty();
1543 $dir = $dir.
"/".$objectref;
1544 $file = $dir.
"/".$objectref.
".meta";
1546 if (!is_dir($dir)) {
1551 $nblines = count($object->lines);
1552 $client = $object->thirdparty->name.
" ".$object->thirdparty->address.
" ".$object->thirdparty->zip.
" ".$object->thirdparty->town;
1553 $meta =
"REFERENCE=\"".$object->ref.
"\"
1555 NB_ITEMS=\"" . $nblines.
"\"
1556 CLIENT=\"" . $client.
"\"
1557 AMOUNT_EXCL_TAX=\"" . $object->total_ht.
"\"
1558 AMOUNT=\"" . $object->total_ttc.
"\"\n";
1560 for ($i = 0; $i < $nblines; $i++) {
1562 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".$object->lines[$i]->qty.
"\"
1563 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".$object->lines[$i]->total_ht.
"\"
1564 ITEM_" . $i.
"_VAT=\"".$object->lines[$i]->tva_tx.
"\"
1565 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br($object->lines[$i]->desc)).
"\"
1570 $fp = fopen($file,
"w");
1573 if (!empty($conf->global->MAIN_UMASK)) {
1574 @chmod($file, octdec($conf->global->MAIN_UMASK));
1579 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING);
1597 $listofpaths = array();
1598 $listofnames = array();
1599 $listofmimes = array();
1603 foreach ($listoffiles as $key => $val) {
1604 $listofpaths[] = $val[
'fullname'];
1605 $listofnames[] = $val[
'name'];
1609 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1610 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
1611 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
1612 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
1633 function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link = null, $trackid =
'', $generatethumbs = 1, $object = null)
1635 global $db, $user, $conf, $langs;
1639 if (!empty($_FILES[$varfiles])) {
1640 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' donotupdatesession='.$donotupdatesession.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1645 $TFile = $_FILES[$varfiles];
1646 if (!is_array($TFile[
'name'])) {
1647 foreach ($TFile as $key => &$val) {
1652 $nbfile = count($TFile[
'name']);
1654 for ($i = 0; $i < $nbfile; $i++) {
1655 if (empty($TFile[
'name'][$i])) {
1660 $destfull = $upload_dir.
"/".$TFile[
'name'][$i];
1661 $destfile = $TFile[
'name'][$i];
1662 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1664 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1665 $destfull = $upload_dir.
"/".preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask);
1666 $destfile = preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask);
1669 $filenameto = basename($destfile);
1670 if (preg_match(
'/^\./', $filenameto)) {
1671 $langs->load(
"errors");
1672 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto), null,
'errors');
1677 $info = pathinfo($destfull);
1678 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1679 $info = pathinfo($destfile);
1681 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1689 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
1691 if (is_numeric($resupload) && $resupload > 0) {
1692 global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
1694 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
1697 if ($generatethumbs) {
1703 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
1706 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
1711 if (empty($donotupdatesession)) {
1712 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1714 $formmail->trackid = $trackid;
1715 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
1719 if ($donotupdatesession == 1) {
1720 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', 0, $object);
1722 if ($allowoverwrite) {
1725 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
'',
'warnings');
1732 $langs->load(
"errors");
1733 if ($resupload < 0) {
1735 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
1736 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"), null,
'errors');
1748 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir), null,
'errors');
1751 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
1752 $linkObject =
new Link($db);
1753 $linkObject->entity = $conf->entity;
1754 $linkObject->url = $link;
1755 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
1756 $linkObject->objectid =
GETPOST(
'objectid',
'int');
1757 $linkObject->label =
GETPOST(
'label',
'alpha');
1758 $res = $linkObject->create($user);
1759 $langs->load(
'link');
1766 $langs->load(
"errors");
1767 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")), null,
'errors');
1787 global $db, $user, $conf, $langs, $_FILES;
1789 $keytodelete = $filenb;
1792 $listofpaths = array();
1793 $listofnames = array();
1794 $listofmimes = array();
1795 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1796 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
1797 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
1799 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
1800 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
1802 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
1803 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
1806 if ($keytodelete >= 0) {
1807 $pathtodelete = $listofpaths[$keytodelete];
1808 $filetodelete = $listofnames[$keytodelete];
1809 if (empty($donotdeletefile)) {
1815 if (empty($donotdeletefile)) {
1816 $langs->load(
"other");
1817 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete), null,
'mesgs');
1819 if (empty($donotupdatesession)) {
1820 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1822 $formmail->trackid = $trackid;
1823 $formmail->remove_attached_files($keytodelete);
1845 global $db, $user, $conf;
1849 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
1851 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
1852 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
1853 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1854 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1856 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1858 $ecmfile->filepath = $rel_dir;
1859 $ecmfile->filename = $filename;
1860 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
1861 $ecmfile->fullpath_orig = $fullpathorig;
1862 $ecmfile->gen_or_uploaded = $mode;
1863 $ecmfile->description =
'';
1864 $ecmfile->keywords =
'';
1866 if (is_object($object) && $object->id > 0) {
1867 $ecmfile->src_object_id = $object->id;
1868 if (isset($object->table_element)) {
1869 $ecmfile->src_object_type = $object->table_element;
1871 dol_syslog(
'Error: object ' . get_class($object) .
' has no table_element attribute.');
1874 if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description;
1875 if (isset($object->src_object_keywords)) $ecmfile->keywords = $object->src_object_keywords;
1878 if (!empty($conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE)) {
1883 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1887 $result = $ecmfile->create($user);
1906 global $conf, $db, $user;
1911 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
1917 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
1919 $filename = basename($file);
1920 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1921 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1924 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
1925 $sql .=
' WHERE entity = '.$conf->entity;
1926 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
1928 $sql .=
" AND filename = '".$db->escape($file).
"'";
1931 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
1934 $resql = $db->query($sql);
1937 dol_syslog(__METHOD__.
' '.$db->lasterror(), LOG_ERR);
1966 if (class_exists(
'Imagick')) {
1967 $image =
new Imagick();
1969 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
1971 $ret = $image->readImage($filetoconvert);
1973 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
1974 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.
" convertion in /etc/ImageMagick*/policy.xml): ".$e->getMessage(), LOG_WARNING);
1978 $ret = $image->setImageFormat($ext);
1980 if (empty($fileoutput)) {
1981 $fileoutput = $fileinput.
".".$ext;
1984 $count = $image->getNumberImages();
1986 if (!
dol_is_file($fileoutput) || is_writeable($fileoutput)) {
1988 $ret = $image->writeImages($fileoutput,
true);
1993 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2022 function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring = null)
2029 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2032 if ($mode ==
'gz') {
2034 $compressdata = gzencode($data, 9);
2035 } elseif ($mode ==
'bz') {
2037 $compressdata = bzcompress($data, 9);
2038 } elseif ($mode ==
'zstd') {
2040 $compressdata = zstd_compress($data, 9);
2041 } elseif ($mode ==
'zip') {
2042 if (class_exists(
'ZipArchive') && !empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS)) {
2045 $rootPath = realpath($inputfile);
2047 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2048 $zip =
new ZipArchive;
2050 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2051 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2055 $errormsg = $errorstring;
2062 $files =
new RecursiveIteratorIterator(
2063 new RecursiveDirectoryIterator($rootPath),
2064 RecursiveIteratorIterator::LEAVES_ONLY
2067 foreach ($files as $name => $file) {
2069 if (!$file->isDir()) {
2071 $filePath = $file->getPath();
2072 $fileName = $file->getFilename();
2073 $fileFullRealPath = $file->getRealPath();
2076 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2079 $zip->addFile($fileFullRealPath, $relativePath);
2086 dol_syslog(
"dol_compress_file success - ".count($zip->numFiles).
" files");
2090 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2093 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2094 $archive =
new PclZip($outputfile);
2095 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2097 if ($result === 0) {
2099 $errormsg = $archive->errorInfo(
true);
2101 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2102 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2103 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2107 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2108 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2111 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2117 if ($foundhandler) {
2118 $fp = fopen($outputfile,
"w");
2119 fwrite($fp, $compressdata);
2123 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2127 $errormsg = $errorstring;
2131 global $langs, $errormsg;
2132 $langs->load(
"errors");
2133 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2135 $errorstring =
"Failed to open file ".$outputfile;
2150 global $conf, $langs, $db;
2152 $fileinfo = pathinfo($inputfile);
2153 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2155 if ($fileinfo[
"extension"] ==
"zip") {
2156 if (defined(
'ODTPHP_PATHTOPCLZIP') && empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS)) {
2157 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2158 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2159 $archive =
new PclZip($inputfile);
2165 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2167 if (!is_array($result) && $result <= 0) {
2168 return array(
'error'=>$archive->errorInfo(
true));
2173 foreach ($result as $key => $val) {
2174 if ($val[
'status'] ==
'path_creation_fail') {
2175 $langs->load(
"errors");
2177 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2185 return array(
'error'=>$errmsg);
2190 if (class_exists(
'ZipArchive')) {
2191 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2192 $zip =
new ZipArchive;
2193 $res = $zip->open($inputfile);
2194 if ($res ===
true) {
2200 for ($i = 0; $i < $zip->numFiles; $i++) {
2201 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2202 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2205 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2211 return array(
'error'=>
'ErrUnzipFails');
2215 return array(
'error'=>
'ErrNoZipEngine');
2216 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2217 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2218 $utils =
new Utils($db);
2225 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2226 if ($extension ==
"tar") {
2229 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2230 if ($resarray[
"result"] != 0) {
2231 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2235 if ($fileinfo[
"extension"] ==
"gz") {
2237 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2239 } elseif ($fileinfo[
"extension"] ==
"zst") {
2242 return array(
'error'=>
'ErrorBadFileExtension');
2245 $cmd .=
' > '.$outputfilename;
2247 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, null, 1, $outputfilename.
'.err');
2248 if ($resarray[
"result"] != 0) {
2249 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2250 if ($errfilecontent) {
2251 $resarray[
"error"] .=
" - ".$errfilecontent;
2255 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2258 return array(
'error'=>
'ErrorBadFileExtension');
2272 function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'')
2276 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2278 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2279 global $langs, $errormsg;
2280 $langs->load(
"errors");
2281 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2286 if ($mode ==
'gz') {
2288 } elseif ($mode ==
'bz') {
2290 } elseif ($mode ==
'zip') {
2303 if (class_exists(
'ZipArchive')) {
2307 $zip =
new ZipArchive();
2308 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2310 global $langs, $errormsg;
2311 $langs->load(
"errors");
2312 $errormsg = $langs->trans(
"ErrorFailedToWriteInFile", $outputfile);
2319 $files =
new RecursiveIteratorIterator(
2320 new RecursiveDirectoryIterator($inputdir),
2321 RecursiveIteratorIterator::LEAVES_ONLY
2325 foreach ($files as $name => $file) {
2327 if (!$file->isDir()) {
2329 $filePath = $file->getPath();
2330 $fileName = $file->getFilename();
2331 $fileFullRealPath = $file->getRealPath();
2334 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2337 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2339 $zip->addFile($fileFullRealPath, $relativePath);
2351 if (!$foundhandler) {
2352 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2358 global $langs, $errormsg;
2359 $langs->load(
"errors");
2360 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2362 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2379 function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook =
false, $mode =
'')
2381 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2382 return $tmparray[0];
2400 global $conf, $db, $user, $hookmanager;
2401 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2404 if (!is_object($fuser)) {
2408 if (empty($modulepart)) {
2409 return 'ErrorBadParameter';
2411 if (empty($entity)) {
2412 if (empty($conf->multicompany->enabled)) {
2419 if ($modulepart ==
'users') {
2420 $modulepart =
'user';
2422 if ($modulepart ==
'tva') {
2423 $modulepart =
'tax-vat';
2427 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2431 $sqlprotectagainstexternals =
'';
2435 if (empty($refname)) {
2436 $refname = basename(dirname($original_file).
"/");
2437 if ($refname ==
'thumbs') {
2439 $refname = basename(dirname(dirname($original_file)).
"/");
2446 $download =
'download';
2447 if ($mode ==
'write') {
2450 $download =
'upload';
2454 if ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2455 if (empty($entity) || empty($conf->medias->multidir_output[$entity])) {
2456 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2459 $original_file = $conf->medias->multidir_output[$entity].
'/'.$original_file;
2460 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2462 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.log$/', basename($original_file)));
2463 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2464 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2466 $accessallowed = $user->admin;
2467 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2468 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2470 $accessallowed = ($fuser->rights->website->write && preg_match(
'/\.jpg$/i', basename($original_file)));
2471 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2472 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2475 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2478 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2479 $original_file = $dirins.
'/'.$original_file;
2480 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
2483 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
2484 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
2487 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2490 $original_file = $conf->user->dir_output.
'/'.$original_file;
2491 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
2494 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
2495 } elseif ($modulepart ==
'memberphoto' && !empty($conf->adherent->dir_output)) {
2498 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2501 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
2502 } elseif ($modulepart ==
'apercufacture' && !empty($conf->facture->multidir_output[$entity])) {
2504 if ($fuser->rights->facture->{$lire}) {
2507 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2508 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
2510 if ($fuser->rights->propale->{$lire}) {
2513 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2514 } elseif ($modulepart ==
'apercucommande' && !empty($conf->commande->multidir_output[$entity])) {
2516 if ($fuser->rights->commande->{$lire}) {
2519 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2520 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->dir_output)) {
2522 if ($fuser->rights->ficheinter->{$lire}) {
2525 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2526 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contrat->multidir_output[$entity])) {
2528 if ($fuser->rights->contrat->{$lire}) {
2531 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2532 } elseif (($modulepart ==
'apercusupplier_proposal' || $modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
2534 if ($fuser->rights->supplier_proposal->{$lire}) {
2537 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
2538 } elseif (($modulepart ==
'apercusupplier_order' || $modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
2540 if ($fuser->rights->fournisseur->commande->{$lire}) {
2543 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2544 } elseif (($modulepart ==
'apercusupplier_invoice' || $modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
2546 if ($fuser->rights->fournisseur->facture->{$lire}) {
2549 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2550 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
2551 if ($fuser->rights->holiday->{$read} || !empty($fuser->rights->holiday->readall) || preg_match(
'/^specimen/i', $original_file)) {
2554 if ($refname && empty($fuser->rights->holiday->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2555 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
2556 $tmpholiday =
new Holiday($db);
2557 $tmpholiday->fetch(
'', $refname);
2558 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
2561 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
2562 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
2563 if ($fuser->rights->expensereport->{$lire} || !empty($fuser->rights->expensereport->readall) || preg_match(
'/^specimen/i', $original_file)) {
2566 if ($refname && empty($fuser->rights->expensereport->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2567 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
2569 $tmpexpensereport->fetch(
'', $refname);
2570 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
2573 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2574 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
2576 if ($fuser->rights->expensereport->{$lire}) {
2579 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2580 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
2582 if ($fuser->rights->propale->{$lire}) {
2585 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
2586 } elseif ($modulepart ==
'orderstats' && !empty($conf->commande->dir_temp)) {
2588 if ($fuser->rights->commande->{$lire}) {
2591 $original_file = $conf->commande->dir_temp.
'/'.$original_file;
2592 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2593 if ($fuser->rights->fournisseur->commande->{$lire}) {
2596 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
2597 } elseif ($modulepart ==
'billstats' && !empty($conf->facture->dir_temp)) {
2599 if ($fuser->rights->facture->{$lire}) {
2602 $original_file = $conf->facture->dir_temp.
'/'.$original_file;
2603 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2604 if ($fuser->rights->fournisseur->facture->{$lire}) {
2607 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
2608 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
2610 if ($fuser->rights->expedition->{$lire}) {
2613 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
2614 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
2616 if ($fuser->rights->deplacement->{$lire}) {
2619 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
2620 } elseif ($modulepart ==
'memberstats' && !empty($conf->adherent->dir_temp)) {
2622 if ($fuser->rights->adherent->{$lire}) {
2625 $original_file = $conf->adherent->dir_temp.
'/'.$original_file;
2626 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
2628 if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) {
2631 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
2632 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
2634 if ($fuser->rights->tax->charges->{$lire}) {
2637 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
2638 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
2639 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2641 if ($fuser->rights->agenda->myactions->{$read}) {
2644 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2645 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2647 $tmpobject->fetch((
int) $refname);
2648 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
2649 if ($user->socid && $tmpobject->socid) {
2654 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2655 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
2657 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
2658 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2660 if ($fuser->rights->categorie->{$lire} || $fuser->rights->takepos->run) {
2663 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
2664 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
2666 if ($fuser->rights->prelevement->bons->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2669 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
2670 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
2673 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
2674 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
2677 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
2678 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
2681 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
2682 } elseif ($modulepart ==
'barcode') {
2687 $original_file =
'';
2688 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
2691 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
2692 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
2695 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
2696 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
2699 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
2700 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
2702 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2703 if ($fuser->id == (
int) $refname) {
2706 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
2709 $original_file = $conf->user->dir_output.
'/'.$original_file;
2710 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
2712 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2713 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2715 if ($fuser->rights->societe->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2718 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
2719 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
2720 } elseif ($modulepart ==
'contact' && !empty($conf->societe->multidir_output[$entity])) {
2722 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2723 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2725 if ($fuser->rights->societe->{$lire}) {
2728 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
2729 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->facture->multidir_output[$entity])) {
2731 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2734 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2735 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
2736 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
2738 if ($fuser->rights->propal->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2741 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2742 } elseif ($modulepart ==
'massfilesarea_orders') {
2743 if ($fuser->rights->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2746 $original_file = $conf->commande->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2747 } elseif ($modulepart ==
'massfilesarea_sendings') {
2748 if ($fuser->rights->expedition->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2751 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
2752 } elseif ($modulepart ==
'massfilesarea_invoices') {
2753 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2756 $original_file = $conf->facture->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2757 } elseif ($modulepart ==
'massfilesarea_expensereport') {
2758 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2761 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2762 } elseif ($modulepart ==
'massfilesarea_interventions') {
2763 if ($fuser->rights->ficheinter->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2766 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2767 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
2768 if ($fuser->rights->supplier_proposal->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2771 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2772 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
2773 if ($fuser->rights->fournisseur->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2776 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2777 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
2778 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2781 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2782 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contrat->dir_output)) {
2783 if ($fuser->rights->contrat->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2786 $original_file = $conf->contrat->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2787 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->dir_output)) {
2789 if ($fuser->rights->ficheinter->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2792 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2793 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2794 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
2796 if ($fuser->rights->deplacement->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2799 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
2801 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && !empty($conf->propal->multidir_output[$entity])) {
2803 if ($fuser->rights->propale->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2806 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2807 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
2808 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->commande->multidir_output[$entity])) {
2810 if ($fuser->rights->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2813 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2814 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
2815 } elseif ($modulepart ==
'project' && !empty($conf->project->dir_output)) {
2817 if ($fuser->rights->projet->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2820 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2821 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
2822 $tmpproject =
new Project($db);
2823 $tmpproject->fetch(
'', $refname);
2824 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
2827 $original_file = $conf->project->dir_output.
'/'.$original_file;
2828 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
2829 } elseif ($modulepart ==
'project_task' && !empty($conf->project->dir_output)) {
2830 if ($fuser->rights->projet->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2833 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2834 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
2835 $tmptask =
new Task($db);
2836 $tmptask->fetch(
'', $refname);
2837 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
2840 $original_file = $conf->project->dir_output.
'/'.$original_file;
2841 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
2842 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
2844 if ($fuser->rights->fournisseur->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2847 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2848 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2849 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
2851 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2854 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2855 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2856 } elseif ($modulepart ==
'supplier_payment') {
2858 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2861 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
2862 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2863 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->facture->dir_output)) {
2865 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2868 if ($fuser->socid > 0) {
2869 $original_file = $conf->facture->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
2871 $original_file = $conf->facture->dir_output.
'/payments/'.$original_file;
2873 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
2875 if ($fuser->rights->accounting->bind->write || preg_match(
'/^specimen/i', $original_file)) {
2878 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
2879 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty($conf->expedition->dir_output)) {
2881 if ($fuser->rights->expedition->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2884 $original_file = $conf->expedition->dir_output.
"/".(strpos(
'sending/', $original_file) === 0 ?
'' :
'sending/').$original_file;
2886 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
2888 if ($fuser->rights->expedition->delivery->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2891 $original_file = $conf->expedition->dir_output.
"/".(strpos(
'receipt/', $original_file) === 0 ?
'' :
'receipt/').$original_file;
2892 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2894 if ($fuser->rights->agenda->myactions->{$read} || preg_match(
'/^specimen/i', $original_file)) {
2897 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2898 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
2900 if ($fuser->rights->agenda->allactions->{$read} || preg_match(
'/^specimen/i', $original_file)) {
2903 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
2904 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
2906 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
2907 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2909 if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match(
'/^specimen/i', $original_file)) {
2912 if (!empty($conf->product->enabled)) {
2913 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
2914 } elseif (!empty($conf->service->enabled)) {
2915 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
2917 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
2919 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
2920 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2922 if (($fuser->rights->produit->{$lire} ) || preg_match(
'/^specimen/i', $original_file)) {
2925 if (!empty($conf->productbatch->enabled)) {
2926 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
2928 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
2930 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
2931 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2933 if (($fuser->rights->stock->{$lire} || $fuser->rights->stock->movement->{$lire} || $fuser->rights->stock->mouvement->{$lire}) || preg_match(
'/^specimen/i', $original_file)) {
2936 if (!empty($conf->stock->enabled)) {
2937 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
2939 } elseif ($modulepart ==
'contract' && !empty($conf->contrat->multidir_output[$entity])) {
2941 if ($fuser->rights->contrat->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2944 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2945 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
2946 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
2948 if ($fuser->rights->don->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2951 $original_file = $conf->don->dir_output.
'/'.$original_file;
2952 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
2954 if ($fuser->rights->resource->{$read} || preg_match(
'/^specimen/i', $original_file)) {
2957 $original_file = $conf->resource->dir_output.
'/'.$original_file;
2958 } elseif ($modulepart ==
'remisecheque' && !empty($conf->bank->dir_output)) {
2960 if ($fuser->rights->banque->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2964 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
2965 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
2967 if ($fuser->rights->banque->{$lire}) {
2970 $original_file = $conf->bank->dir_output.
'/'.$original_file;
2971 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
2974 $accessallowed = $user->rights->export->lire;
2975 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
2976 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
2978 $accessallowed = $user->rights->import->run;
2979 $original_file = $conf->import->dir_temp.
'/'.$original_file;
2980 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
2982 $accessallowed = $user->rights->recruitment->recruitmentjobposition->read;
2983 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
2984 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
2987 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
2988 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
2990 if ($fuser->admin) {
2993 $original_file = $conf->admin->dir_output.
'/'.$original_file;
2994 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
2996 if ($fuser->admin) {
2999 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3000 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3004 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3007 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3008 } elseif ($modulepart ==
'member' && !empty($conf->adherent->dir_output)) {
3010 if ($fuser->rights->adherent->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3013 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
3014 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3017 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3027 if (preg_match(
'/^specimen/i', $original_file)) {
3030 if ($fuser->admin) {
3034 $tmpmodulepart = explode(
'-', $modulepart);
3035 if (!empty($tmpmodulepart[1])) {
3036 $modulepart = $tmpmodulepart[0];
3037 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3042 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3043 if (empty($conf->{$reg[1]}->dir_temp)) {
3044 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3047 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3050 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3051 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3052 if (empty($conf->{$reg[1]}->dir_temp)) {
3053 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3056 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3059 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$original_file;
3060 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3061 if (empty($conf->{$reg[1]}->dir_output)) {
3062 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3065 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3068 $original_file = $conf->{$reg[1]}->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3069 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3070 if (empty($conf->{$reg[1]}->dir_output)) {
3071 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3074 if ($fuser->rights->{$reg[1]}->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3077 $original_file = $conf->{$reg[1]}->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3079 if (empty($conf->$modulepart->dir_output)) {
3080 dol_print_error(
'',
'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.');
3085 $partsofdirinoriginalfile = explode(
'/', $original_file);
3086 if (!empty($partsofdirinoriginalfile[1])) {
3087 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3088 if ($partofdirinoriginalfile && !empty($fuser->rights->$modulepart->$partofdirinoriginalfile) && ($fuser->rights->$modulepart->$partofdirinoriginalfile->{$lire} || $fuser->rights->$modulepart->$partofdirinoriginalfile->{$read})) {
3092 if (!empty($fuser->rights->$modulepart->{$lire}) || !empty($fuser->rights->$modulepart->{$read})) {
3096 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3097 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3099 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3103 $parameters = array(
3104 'modulepart' => $modulepart,
3105 'original_file' => $original_file,
3106 'entity' => $entity,
3111 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters, $object);
3113 if (!empty($hookmanager->resArray[
'original_file'])) {
3114 $original_file = $hookmanager->resArray[
'original_file'];
3116 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3117 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3119 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3120 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3126 'accessallowed' => ($accessallowed ? 1 : 0),
3127 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3128 'original_file' => $original_file
3147 $cachefile = $directory.$filename;
3148 file_put_contents($cachefile, serialize($object), LOCK_EX);
3149 @chmod($cachefile, 0644);
3163 $cachefile = $directory.$filename;
3164 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3177 $cachefile = $directory.$filename;
3178 $object = unserialize(file_get_contents($cachefile));
3194 function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3198 $exclude =
'install';
3200 foreach ($dir->md5file as $file) {
3201 $filename = $path.$file[
'name'];
3202 $file_list[
'insignature'][] = $filename;
3203 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3204 $expectedmd5 = (string) $file;
3208 if (!file_exists($pathref.
'/'.$filename)) {
3209 $file_list[
'missing'][] = array(
'filename'=>$filename,
'expectedmd5'=>$expectedmd5,
'expectedsize'=>$expectedsize);
3211 $md5_local = md5_file($pathref.
'/'.$filename);
3213 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3214 $checksumconcat[] = $expectedmd5;
3216 if ($md5_local != $expectedmd5) {
3217 $file_list[
'updated'][] = array(
'filename'=>$filename,
'expectedmd5'=>$expectedmd5,
'expectedsize'=>$expectedsize,
'md5'=>(
string) $md5_local);
3219 $checksumconcat[] = $md5_local;
3224 foreach ($dir->dir as $subdir) {
3225 getFilesUpdated($file_list, $subdir, $path.$subdir[
'name'].
'/', $pathref, $checksumconcat);
dol_convert_file($fileinput, $ext= 'png', $fileoutput= '', $page= '')
Convert an image file or a PDF into another image format.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage utility methods.
dol_compare_file($a, $b)
Fast compare of 2 files identified by their properties ->name, ->date and ->size. ...
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Class of the module paid holiday.
dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
Copy a file to another file.
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)...
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0)
Copy a dir to another dir.
dol_sanitizePathName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a path name.
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path= '', $pathref= '', &$checksumconcat=array())
Function to get list of updated or modified files.
dol_unescapefile($filename)
Unescape a file submitted by upload.
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.
dol_cache_refresh($directory, $filename, $cachetime)
Test if Refresh needed.
deleteFilesIntoDatabaseIndex($dir, $file, $mode= 'uploaded')
Delete files into database index using search criterias.
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
Class to manage agenda events (actions)
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
Complete $filearray with data from database.
dol_now($mode= 'auto')
Return date for now.
dol_delete_preview($object)
Delete all preview files linked to object instance.
dol_filesize($pathoffile)
Return size of a file.
dol_is_dir($folder)
Test if filename is a directory.
dolCheckVirus($src_file)
Check virus into a file.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
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_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
dol_fileperm($pathoffile)
Return permissions of a file.
dol_is_url($url)
Return if path is an URL.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser= '', $refname= '', $mode= 'read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
Class to manage projects.
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
utf8_check($str)
Check if a string is in UTF8.
dol_count_nb_of_line($file)
Count number of lines in a file.
Class to manage Trips and Expenses.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles= 'addedfile', $upload_dir= '')
Make control on an uploaded file from an GUI page and move it to final destination.
dol_is_file($pathoffile)
Return if path is a file.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid= '')
Remove an uploaded file (for example after submitting a new file a mail form).
dolReplaceInFile($srcfile, $arrayreplacement, $destfile= '', $newmask=0, $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_init_file_process($pathtoscan= '', $trackid= '')
Scan a directory and init $_SESSION to manage uploaded files with list of all found files...
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_filemtime($pathoffile)
Return time of a file.
dol_most_recent_file($dir, $regexfilter= '', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode= '')
Return file(s) into a directory (by default most recent)
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
addFileIntoDatabaseIndex($dir, $file, $fullpathorig= '', $mode= 'uploaded', $setsharekey=0, $object=null)
Add a file into database index.
dol_readcachefile($directory, $filename)
Read object from cachefile.
dol_is_link($pathoffile)
Return if path is a symbolic link.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=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_dir_is_emtpy($folder)
Test if a folder is empty.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
Class to manage ECM files.
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_meta_create($object)
Create a meta file with document file into same directory.
dol_filecache($directory, $filename, $object)
Store object in file.
dol_is_dir_empty($dir)
Return if path is empty.