38 return preg_replace(
'/^.*\/([^\/]+)$/',
'$1', rtrim($pathfile,
'/'));
61 function dol_dir_list($path, $types =
"all", $recursive = 0, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename =
"", $donotfollowsymlinks = 0, $nbsecondsold = 0)
63 global $db, $hookmanager;
66 if ($recursive <= 1) {
67 dol_syslog(
"files.lib.php::dol_dir_list path=".$path.
" types=".$types.
" recursive=".$recursive.
" filter=".$filter.
" excludefilter=".json_encode($excludefilter));
71 $loaddate = ($mode == 1 || $mode == 2 || $nbsecondsold) ?
true :
false;
72 $loadsize = ($mode == 1 || $mode == 3) ?
true :
false;
73 $loadperm = ($mode == 1 || $mode == 4) ?
true :
false;
76 $path = preg_replace(
'/([\\/]+)$/i',
'', $path);
83 if (is_object($hookmanager) && !$nohook) {
84 $hookmanager->resArray = array();
86 $hookmanager->initHooks(array(
'fileslib'));
91 'recursive' => $recursive,
93 'excludefilter' => $excludefilter,
94 'sortcriteria' => $sortcriteria,
95 'sortorder' => $sortorder,
96 'loaddate' => $loaddate,
97 'loadsize' => $loadsize,
100 $reshook = $hookmanager->executeHooks(
'getDirList', $parameters, $object);
104 if (empty($reshook)) {
105 if (!is_dir($newpath)) {
109 if ($dir = opendir($newpath)) {
113 while (
false !== ($file = readdir($dir))) {
115 $file = utf8_encode($file);
117 $fullpathfile = ($newpath ? $newpath.
'/' :
'').$file;
122 $excludefilterarray = array(
'^\.');
123 if (is_array($excludefilter)) {
124 $excludefilterarray = array_merge($excludefilterarray, $excludefilter);
125 } elseif ($excludefilter) {
126 $excludefilterarray[] = $excludefilter;
129 foreach ($excludefilterarray as $filt) {
130 if (preg_match(
'/'.$filt.
'/i', $file) || preg_match(
'/'.$filt.
'/i', $fullpathfile)) {
140 if ($isdir && (($types ==
"directories") || ($types ==
"all") || $recursive > 0)) {
142 if (($types ==
"directories") || ($types ==
"all")) {
143 if ($loaddate || $sortcriteria ==
'date') {
146 if ($loadsize || $sortcriteria ==
'size') {
149 if ($loadperm || $sortcriteria ==
'perm') {
153 if (!$filter || preg_match(
'/'.$filter.
'/i', $file)) {
155 preg_match(
'/([^\/]+)\/[^\/]+$/', $path.
'/'.$file, $reg);
156 $level1name = (isset($reg[1]) ? $reg[1] :
'');
157 $file_list[] = array(
160 "level1name" => $level1name,
161 "relativename" => ($relativename ? $relativename.
'/' :
'').$file,
162 "fullname" => $path.
'/'.$file,
172 if ($recursive > 0) {
173 if (empty($donotfollowsymlinks) || !is_link($path.
"/".$file)) {
175 $file_list = array_merge($file_list,
dol_dir_list($path.
"/".$file, $types, $recursive + 1, $filter, $excludefilter, $sortcriteria, $sortorder, $mode, $nohook, ($relativename !=
'' ? $relativename.
'/' :
'').$file, $donotfollowsymlinks, $nbsecondsold));
178 } elseif (!$isdir && (($types ==
"files") || ($types ==
"all"))) {
180 if ($loaddate || $sortcriteria ==
'date') {
183 if ($loadsize || $sortcriteria ==
'size') {
187 if (!$filter || preg_match(
'/'.$filter.
'/i', $file)) {
188 if (empty($nbsecondsold) || $filedate <= ($now - $nbsecondsold)) {
189 preg_match(
'/([^\/]+)\/[^\/]+$/', $path.
'/'.$file, $reg);
190 $level1name = (isset($reg[1]) ? $reg[1] :
'');
191 $file_list[] = array(
194 "level1name" => $level1name,
195 "relativename" => ($relativename ? $relativename.
'/' :
'').$file,
196 "fullname" => $path.
'/'.$file,
209 if (!empty($sortcriteria) && $sortorder) {
210 $file_list =
dol_sort_array($file_list, $sortcriteria, ($sortorder == SORT_ASC ?
'asc' :
'desc'));
215 if (is_object($hookmanager) && is_array($hookmanager->resArray)) {
216 $file_list = array_merge($file_list, $hookmanager->resArray);
236 function dol_dir_list_in_database($path, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0)
240 $sql =
" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams,";
241 $sql .=
" date_c, tms as date_m, fk_user_c, fk_user_m, acl, position, share";
243 $sql .=
", description";
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_files";
246 $sql .=
" WHERE entity = ".$conf->entity;
247 if (preg_match(
'/%$/', $path)) {
248 $sql .=
" AND filepath LIKE '".$db->escape($path).
"'";
250 $sql .=
" AND filepath = '".$db->escape($path).
"'";
253 $resql = $db->query($sql);
255 $file_list = array();
256 $num = $db->num_rows(
$resql);
259 $obj = $db->fetch_object(
$resql);
262 preg_match(
'/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename, $reg);
263 $level1name = (isset($reg[1]) ? $reg[1] :
'');
264 $file_list[] = array(
265 "rowid" => $obj->rowid,
266 "label" => $obj->label,
267 "name" => $obj->filename,
268 "path" => DOL_DATA_ROOT.
'/'.$obj->filepath,
269 "level1name" => $level1name,
270 "fullname" => DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename,
271 "fullpath_orig" => $obj->fullpath_orig,
272 "date_c" => $db->jdate($obj->date_c),
273 "date_m" => $db->jdate($obj->date_m),
275 "keywords" => $obj->keywords,
276 "cover" => $obj->cover,
277 "position" => (
int) $obj->position,
279 "share" => $obj->share,
280 "description" => ($mode ? $obj->description :
'')
287 if (!empty($sortcriteria)) {
289 foreach ($file_list as $key => $row) {
290 $myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] :
'');
294 array_multisort($myarray, $sortorder, $file_list);
316 global $conf, $db, $user;
322 if ($modulepart ==
'produit' &&
getDolGlobalInt(
'PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
324 if (!empty($object->id)) {
326 $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";
328 $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";
331 $relativedirold = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dirold);
332 $relativedirold = preg_replace(
'/^[\\/]/',
'', $relativedirold);
334 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($relativedirold,
'',
null,
'name', SORT_ASC));
343 foreach ($filearray as $key => $val) {
344 $tmpfilename = preg_replace(
'/\.noexe$/',
'', $filearray[$key][
'name']);
347 foreach ($filearrayindatabase as $key2 => $val2) {
348 if (($filearrayindatabase[$key2][
'path'] == $filearray[$key][
'path']) && ($filearrayindatabase[$key2][
'name'] == $tmpfilename)) {
349 $filearray[$key][
'position_name'] = ($filearrayindatabase[$key2][
'position'] ? $filearrayindatabase[$key2][
'position'] :
'0').
'_'.$filearrayindatabase[$key2][
'name'];
350 $filearray[$key][
'position'] = $filearrayindatabase[$key2][
'position'];
351 $filearray[$key][
'cover'] = $filearrayindatabase[$key2][
'cover'];
352 $filearray[$key][
'acl'] = $filearrayindatabase[$key2][
'acl'];
353 $filearray[$key][
'rowid'] = $filearrayindatabase[$key2][
'rowid'];
354 $filearray[$key][
'label'] = $filearrayindatabase[$key2][
'label'];
355 $filearray[$key][
'share'] = $filearrayindatabase[$key2][
'share'];
362 $filearray[$key][
'position'] =
'999999';
363 $filearray[$key][
'cover'] = 0;
364 $filearray[$key][
'acl'] =
'';
366 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'fullname']);
368 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filename)) {
369 dol_syslog(
"list_of_documents We found a file called '".$filearray[$key][
'name'].
"' not indexed into database. We add it");
370 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
374 $filename = basename($rel_filename);
375 $rel_dir = dirname($rel_filename);
376 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
377 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
379 $ecmfile->filepath = $rel_dir;
380 $ecmfile->filename = $filename;
381 $ecmfile->label = md5_file(
dol_osencode($filearray[$key][
'fullname']));
382 $ecmfile->fullpath_orig = $filearray[$key][
'fullname'];
383 $ecmfile->gen_or_uploaded =
'unknown';
384 $ecmfile->description =
'';
385 $ecmfile->keywords =
'';
386 $result = $ecmfile->create($user);
390 $filearray[$key][
'rowid'] = $result;
393 $filearray[$key][
'rowid'] = 0;
413 $sortorder = strtoupper($sortorder);
415 if ($sortorder ==
'ASC') {
423 if ($sortfield ==
'name') {
424 if ($a->name == $b->name) {
427 return ($a->name < $b->name) ? $retup : $retdown;
429 if ($sortfield ==
'date') {
430 if ($a->date == $b->date) {
433 return ($a->date < $b->date) ? $retup : $retdown;
435 if ($sortfield ==
'size') {
436 if ($a->size == $b->size) {
439 return ($a->size < $b->size) ? $retup : $retdown;
453 if (is_dir($newfolder)) {
468 if (!is_readable($dir)) {
471 return (count(scandir($dir)) == 2);
483 return is_file($newpathoffile);
495 return is_link($newpathoffile);
506 $tmpprot = array(
'file',
'http',
'https',
'ftp',
'zlib',
'data',
'ssh',
'ssh2',
'ogg',
'expect');
507 foreach ($tmpprot as $prot) {
508 if (preg_match(
'/^'.$prot.
':/i', $url)) {
524 if (is_dir($newfolder)) {
525 $handle = opendir($newfolder);
526 $folder_content =
'';
527 while ((gettype($name = readdir($handle)) !=
"boolean")) {
528 $name_array[] = $name;
530 foreach ($name_array as $temp) {
531 $folder_content .= $temp;
536 if ($folder_content ==
"...") {
559 $fp = fopen($newfile,
'r');
564 if (!$line ===
false) {
587 return filesize($newpathoffile);
599 return @filemtime($newpathoffile);
611 return fileperms($newpathoffile);
626 function dolReplaceInFile($srcfile, $arrayreplacement, $destfile =
'', $newmask = 0, $indexdatabase = 0, $arrayreplacementisregex = 0)
630 dol_syslog(
"files.lib.php::dolReplaceInFile srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" indexdatabase=".$indexdatabase.
" arrayreplacementisregex=".$arrayreplacementisregex);
632 if (empty($srcfile)) {
635 if (empty($destfile)) {
636 $destfile = $srcfile;
640 if (($destfile != $srcfile) && $destexists) {
646 dol_syslog(
"files.lib.php::dolReplaceInFile failed to read src file", LOG_WARNING);
650 $tmpdestfile = $destfile.
'.tmp';
655 $newdirdestfile = dirname($newpathofdestfile);
657 if ($destexists && !is_writable($newpathofdestfile)) {
658 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
661 if (!is_writable($newdirdestfile)) {
662 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
669 $content = file_get_contents($newpathofsrcfile,
'r');
671 if (empty($arrayreplacementisregex)) {
674 foreach ($arrayreplacement as $key => $value) {
675 $content = preg_replace($key, $value, $content);
679 file_put_contents($newpathoftmpdestfile, $content);
680 @chmod($newpathoftmpdestfile, octdec($newmask));
683 $result =
dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
685 dol_syslog(
"files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
688 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
689 $newmask = $conf->global->MAIN_UMASK;
691 if (empty($newmask)) {
692 dol_syslog(
"Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
696 @chmod($newpathofdestfile, octdec($newmask));
712 function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
716 dol_syslog(
"files.lib.php::dol_copy srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
718 if (empty($srcfile) || empty($destfile)) {
723 if (!$overwriteifexists && $destexists) {
729 $newdirdestfile = dirname($newpathofdestfile);
731 if ($destexists && !is_writable($newpathofdestfile)) {
732 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
735 if (!is_writable($newdirdestfile)) {
736 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
740 $result = @copy($newpathofsrcfile, $newpathofdestfile);
743 dol_syslog(
"files.lib.php::dol_copy failed to copy", LOG_WARNING);
746 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
747 $newmask = $conf->global->MAIN_UMASK;
749 if (empty($newmask)) {
750 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
754 @chmod($newpathofdestfile, octdec($newmask));
772 function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement =
null, $excludesubdir = 0, $excludefileext =
null)
778 dol_syslog(
"files.lib.php::dolCopyDir srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
780 if (empty($srcfile) || empty($destfile)) {
790 $dirmaskdec = octdec($newmask);
791 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
792 $dirmaskdec = octdec($conf->global->MAIN_UMASK);
794 $dirmaskdec |= octdec(
'0200');
795 dol_mkdir($destfile,
'', decoct($dirmaskdec));
802 if (is_dir($ossrcfile)) {
803 $dir_handle = opendir($ossrcfile);
804 while ($file = readdir($dir_handle)) {
805 if ($file !=
"." && $file !=
".." && !is_link($ossrcfile.
"/".$file)) {
806 if (is_dir($ossrcfile.
"/".$file)) {
807 if (empty($excludesubdir) || ($excludesubdir == 2 && strlen($file) == 2)) {
810 if (is_array($arrayreplacement)) {
811 foreach ($arrayreplacement as $key => $val) {
812 $newfile = str_replace($key, $val, $newfile);
816 $tmpresult =
dolCopyDir($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists, $arrayreplacement, $excludesubdir, $excludefileext);
821 if (is_array($excludefileext)) {
822 $extension = pathinfo($file, PATHINFO_EXTENSION);
823 if (in_array($extension, $excludefileext)) {
830 if (is_array($arrayreplacement)) {
831 foreach ($arrayreplacement as $key => $val) {
832 $newfile = str_replace($key, $val, $newfile);
835 $tmpresult =
dol_copy($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists);
838 if ($result > 0 && $tmpresult >= 0) {
841 $result = $tmpresult;
848 closedir($dir_handle);
874 function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1)
876 global $user, $db, $conf;
879 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
884 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
888 if ($overwriteifexists || !$destexists) {
893 $testvirusarray = array();
896 if (count($testvirusarray)) {
897 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
902 $result = @rename($newpathofsrcfile, $newpathofdestfile);
905 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
908 $result = @rename($newpathofsrcfile, $newpathofdestfile);
910 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
915 if ($result && $indexdatabase) {
917 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
918 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
919 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
920 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
921 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
924 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
925 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
928 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
929 if ($resultecmtarget > 0) {
930 $ecmfiletarget->delete($user);
934 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
935 if ($resultecm > 0) {
936 $filename = basename($rel_filetorenameafter);
937 $rel_dir = dirname($rel_filetorenameafter);
938 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
939 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
941 $ecmfile->filepath = $rel_dir;
942 $ecmfile->filename = $filename;
944 $resultecm = $ecmfile->update($user);
945 } elseif ($resultecm == 0) {
946 $filename = basename($rel_filetorenameafter);
947 $rel_dir = dirname($rel_filetorenameafter);
948 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
949 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
951 $ecmfile->filepath = $rel_dir;
952 $ecmfile->filename = $filename;
954 $ecmfile->fullpath_orig = $srcfile;
955 $ecmfile->gen_or_uploaded =
'unknown';
956 $ecmfile->description =
'';
957 $ecmfile->keywords =
'';
958 $resultecm = $ecmfile->create($user);
959 if ($resultecm < 0) {
962 } elseif ($resultecm < 0) {
966 if ($resultecm > 0) {
974 if (empty($newmask)) {
975 $newmask = empty($conf->global->MAIN_UMASK) ?
'0755' : $conf->global->MAIN_UMASK;
977 $newmaskdec = octdec($newmask);
981 @chmod($newpathofdestfile, $newmaskdec);
998 function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase = 1, $renamedircontent = 1)
1001 global $user, $db, $conf;
1004 dol_syslog(
"files.lib.php::dol_move_dir srcdir=".$srcdir.
" destdir=".$destdir.
" overwritifexists=".$overwriteifexists.
" indexdatabase=".$indexdatabase.
" renamedircontent=".$renamedircontent);
1006 $srcbasename = basename($srcdir);
1010 dol_syslog(
"files.lib.php::dol_move_dir srcdir does not exists. we ignore the move request.");
1014 if ($overwriteifexists || !$destexists) {
1018 $result = @rename($newpathofsrcdir, $newpathofdestdir);
1020 if ($result && $renamedircontent) {
1021 if (file_exists($newpathofdestdir)) {
1022 $destbasename = basename($newpathofdestdir);
1024 if (!empty($files) && is_array($files)) {
1025 foreach ($files as $key => $file) {
1026 if (!file_exists($file[
"fullname"]))
continue;
1027 $filepath = $file[
"path"];
1028 $oldname = $file[
"name"];
1030 $newname = str_replace($srcbasename, $destbasename, $oldname);
1031 if (!empty($newname) && $newname !== $oldname) {
1032 if ($file[
"type"] ==
"dir") {
1033 $res =
dol_move_dir($filepath.
'/'.$oldname, $filepath.
'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent);
1035 $res =
dol_move($filepath.
'/'.$oldname, $filepath.
'/'.$newname);
1062 return trim(basename($filename),
".\x00..\x20");
1076 if (!empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) {
1077 if (!class_exists(
'AntiVir')) {
1078 require_once DOL_DOCUMENT_ROOT.
'/core/class/antivir.class.php';
1081 $result = $antivir->dol_avscan_file($src_file);
1083 $reterrors = $antivir->errors;
1111 function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles =
'addedfile', $upload_dir =
'')
1113 global $conf, $db, $user, $langs;
1114 global $object, $hookmanager;
1117 $file_name = $dest_file;
1120 if (empty($nohook)) {
1121 $reshook = $hookmanager->initHooks(array(
'fileslib'));
1123 $parameters = array(
'dest_file' => $dest_file,
'src_file' => $src_file,
'file_name' => $file_name,
'varfiles' => $varfiles,
'allowoverwrite' => $allowoverwrite);
1124 $reshook = $hookmanager->executeHooks(
'moveUploadedFile', $parameters, $object);
1127 if (empty($reshook)) {
1129 if ($uploaderrorcode) {
1130 switch ($uploaderrorcode) {
1131 case UPLOAD_ERR_INI_SIZE:
1132 return 'ErrorFileSizeTooLarge';
1133 case UPLOAD_ERR_FORM_SIZE:
1134 return 'ErrorFileSizeTooLarge';
1135 case UPLOAD_ERR_PARTIAL:
1136 return 'ErrorPartialFile';
1137 case UPLOAD_ERR_NO_TMP_DIR:
1138 return 'ErrorNoTmpDir';
1139 case UPLOAD_ERR_CANT_WRITE:
1140 return 'ErrorFailedToWriteInDir';
1141 case UPLOAD_ERR_EXTENSION:
1142 return 'ErrorUploadBlockedByAddon';
1149 if (empty($disablevirusscan) && file_exists($src_file)) {
1151 if (count($checkvirusarray)) {
1152 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.join(
',', $checkvirusarray), LOG_WARNING);
1153 return 'ErrorFileIsInfectedWithAVirus: '.join(
',', $checkvirusarray);
1162 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
1163 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
1164 $publicmediasdirwithslash .=
'/';
1167 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) {
1168 $file_name .=
'.noexe';
1175 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
1176 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
1182 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
1183 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
1189 $errmsg = join(
',', $hookmanager->errors);
1190 if (empty($errmsg)) {
1191 $errmsg =
'ErrorReturnedBySomeHooks';
1194 } elseif (empty($reshook)) {
1200 if (!is_writable(dirname($file_name_osencoded))) {
1201 dol_syslog(
"Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded).
" is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1202 return 'ErrorDirNotWritable';
1206 if (!$allowoverwrite) {
1207 if (file_exists($file_name_osencoded)) {
1208 dol_syslog(
"Files.lib::dol_move_uploaded_file File ".$file_name.
" already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
1209 return 'ErrorFileAlreadyExists';
1212 if (is_dir($file_name_osencoded)) {
1213 dol_syslog(
"Files.lib::dol_move_uploaded_file A directory with name ".$file_name.
" already exists. Return 'ErrorDirWithFileNameAlreadyExists'", LOG_WARNING);
1214 return 'ErrorDirWithFileNameAlreadyExists';
1219 $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1221 if (!empty($conf->global->MAIN_UMASK)) {
1222 @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1224 dol_syslog(
"Files.lib::dol_move_uploaded_file Success to move ".$src_file.
" to ".$file_name.
" - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
1225 return $successcode;
1227 dol_syslog(
"Files.lib::dol_move_uploaded_file Failed to move ".$src_file.
" to ".$file_name, LOG_ERR);
1232 return $successcode;
1250 function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0, $object =
null, $allowdotdot =
false, $indexdatabase = 1, $nolog = 0)
1252 global $db, $conf, $user, $langs;
1253 global $hookmanager;
1256 $langs->loadLangs(array(
'other',
'errors'));
1258 if (empty($nolog)) {
1259 dol_syslog(
"dol_delete_file file=".$file.
" disableglob=".$disableglob.
" nophperrors=".$nophperrors.
" nohook=".$nohook);
1264 if ((!$allowdotdot && preg_match(
'/\.\./', $file)) || preg_match(
'/[<>|]/', $file)) {
1265 dol_syslog(
"Refused to delete file ".$file, LOG_WARNING);
1270 if (empty($nohook)) {
1271 $hookmanager->initHooks(array(
'fileslib'));
1273 $parameters = array(
1275 'disableglob'=> $disableglob,
1276 'nophperrors' => $nophperrors
1278 $reshook = $hookmanager->executeHooks(
'deleteFile', $parameters, $object);
1281 if (empty($nohook) && $reshook != 0) {
1289 if (empty($disableglob) && !empty($file_osencoded)) {
1291 $globencoded = str_replace(
'[',
'\[', $file_osencoded);
1292 $globencoded = str_replace(
']',
'\]', $globencoded);
1293 $listofdir = glob($globencoded);
1294 if (!empty($listofdir) && is_array($listofdir)) {
1295 foreach ($listofdir as $filename) {
1297 $ok = @unlink($filename);
1299 $ok = unlink($filename);
1303 if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
1304 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);
1305 @chmod(dirname($filename), fileperms(dirname($filename)) | 0200);
1308 $ok = @unlink($filename);
1310 $ok = unlink($filename);
1315 if (empty($nolog)) {
1316 dol_syslog(
"Removed file ".$filename, LOG_DEBUG);
1320 $rel_filetodelete = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filename);
1321 if (!preg_match(
'/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1322 if (is_object($db) && $indexdatabase) {
1323 $rel_filetodelete = preg_replace(
'/^[\\/]/',
'', $rel_filetodelete);
1324 $rel_filetodelete = preg_replace(
'/\.noexe$/',
'', $rel_filetodelete);
1326 dol_syslog(
"Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1327 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1329 $result = $ecmfile->fetch(0,
'', $rel_filetodelete);
1330 if ($result >= 0 && $ecmfile->id > 0) {
1331 $result = $ecmfile->delete($user);
1339 dol_syslog(
"Failed to remove file ".$filename, LOG_WARNING);
1345 dol_syslog(
"No files to delete found", LOG_DEBUG);
1350 $ok = @unlink($file_osencoded);
1352 $ok = unlink($file_osencoded);
1355 if (empty($nolog)) {
1356 dol_syslog(
"Removed file ".$file_osencoded, LOG_DEBUG);
1359 dol_syslog(
"Failed to remove file ".$file_osencoded, LOG_WARNING);
1380 if (preg_match(
'/\.\./', $dir) || preg_match(
'/[<>|]/', $dir)) {
1381 dol_syslog(
"Refused to delete dir ".$dir.
' (contains invalid char sequence)', LOG_WARNING);
1386 return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1401 function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0, $indexdatabase = 1, $nolog = 0)
1403 if (empty($nolog)) {
1404 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1408 if ($handle = opendir(
"$dir_osencoded")) {
1409 while (
false !== ($item = readdir($handle))) {
1411 $item = utf8_encode($item);
1414 if ($item !=
"." && $item !=
"..") {
1418 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0,
null,
false, $indexdatabase, $nolog);
1430 if (empty($onlysub)) {
1455 global $langs, $conf;
1458 $element = $object->element;
1460 if ($object->element ==
'order_supplier') {
1461 $dir = $conf->fournisseur->commande->dir_output;
1462 } elseif ($object->element ==
'invoice_supplier') {
1463 $dir = $conf->fournisseur->facture->dir_output;
1464 } elseif ($object->element ==
'project') {
1465 $dir = $conf->project->dir_output;
1466 } elseif ($object->element ==
'shipping') {
1467 $dir = $conf->expedition->dir_output.
'/sending';
1468 } elseif ($object->element ==
'delivery') {
1469 $dir = $conf->expedition->dir_output.
'/receipt';
1470 } elseif ($object->element ==
'fichinter') {
1471 $dir = $conf->ficheinter->dir_output;
1473 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1477 return 'ErrorObjectNoSupportedByFunction';
1481 $dir = $dir.
"/".$refsan;
1482 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1483 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1484 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1487 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1489 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1493 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1495 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1500 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1502 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1506 $multiple = $filepreviewold.
".";
1507 for ($i = 0; $i < 20; $i++) {
1508 $preview = $multiple.$i;
1510 if (file_exists($preview) && is_writable($preview)) {
1512 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1535 if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) {
1540 $element = $object->element;
1542 if ($object->element ==
'order_supplier') {
1543 $dir = $conf->fournisseur->dir_output.
'/commande';
1544 } elseif ($object->element ==
'invoice_supplier') {
1545 $dir = $conf->fournisseur->dir_output.
'/facture';
1546 } elseif ($object->element ==
'project') {
1547 $dir = $conf->project->dir_output;
1548 } elseif ($object->element ==
'shipping') {
1549 $dir = $conf->expedition->dir_output.
'/sending';
1550 } elseif ($object->element ==
'delivery') {
1551 $dir = $conf->expedition->dir_output.
'/receipt';
1552 } elseif ($object->element ==
'fichinter') {
1553 $dir = $conf->ficheinter->dir_output;
1555 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1559 $object->fetch_thirdparty();
1562 $dir = $dir.
"/".$objectref;
1563 $file = $dir.
"/".$objectref.
".meta";
1565 if (!is_dir($dir)) {
1570 if (is_countable($object->lines) && count($object->lines) > 0) {
1571 $nblines = count($object->lines);
1573 $client = $object->thirdparty->name.
" ".$object->thirdparty->address.
" ".$object->thirdparty->zip.
" ".$object->thirdparty->town;
1574 $meta =
"REFERENCE=\"".$object->ref.
"\"
1576 NB_ITEMS=\"" . $nblines.
"\"
1577 CLIENT=\"" . $client.
"\"
1578 AMOUNT_EXCL_TAX=\"" . $object->total_ht.
"\"
1579 AMOUNT=\"" . $object->total_ttc.
"\"\n";
1581 for ($i = 0; $i < $nblines; $i++) {
1583 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".$object->lines[$i]->qty.
"\"
1584 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".$object->lines[$i]->total_ht.
"\"
1585 ITEM_" . $i.
"_VAT=\"".$object->lines[$i]->tva_tx.
"\"
1586 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br($object->lines[$i]->desc)).
"\"
1591 $fp = fopen($file,
"w");
1594 if (!empty($conf->global->MAIN_UMASK)) {
1595 @chmod($file, octdec($conf->global->MAIN_UMASK));
1600 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING);
1618 $listofpaths = array();
1619 $listofnames = array();
1620 $listofmimes = array();
1624 foreach ($listoffiles as $key => $val) {
1625 $listofpaths[] = $val[
'fullname'];
1626 $listofnames[] = $val[
'name'];
1630 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1631 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
1632 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
1633 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
1654 function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1, $object =
null)
1657 global $db, $user, $conf, $langs;
1661 if (!empty($_FILES[$varfiles])) {
1662 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' donotupdatesession='.$donotupdatesession.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1663 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
1664 if (is_array($_FILES[$varfiles][
"name"]) && count($_FILES[$varfiles][
"name"]) > $maxfilesinform) {
1665 $langs->load(
"errors");
1666 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
1672 $TFile = $_FILES[$varfiles];
1673 if (!is_array($TFile[
'name'])) {
1674 foreach ($TFile as $key => &$val) {
1679 $nbfile = count($TFile[
'name']);
1681 for ($i = 0; $i < $nbfile; $i++) {
1682 if (empty($TFile[
'name'][$i])) {
1687 $destfull = $upload_dir.
"/".$TFile[
'name'][$i];
1688 $destfile = $TFile[
'name'][$i];
1689 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1691 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1692 $destfull = $upload_dir.
"/".preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask);
1693 $destfile = preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask);
1696 $filenameto = basename($destfile);
1697 if (preg_match(
'/^\./', $filenameto)) {
1698 $langs->load(
"errors");
1699 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
1704 $info = pathinfo($destfull);
1705 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1706 $info = pathinfo($destfile);
1708 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1716 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
1718 if (is_numeric($resupload) && $resupload > 0) {
1719 global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini;
1721 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
1724 if ($generatethumbs) {
1730 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
1733 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
1738 if (empty($donotupdatesession)) {
1739 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1741 $formmail->trackid = $trackid;
1742 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
1746 if ($donotupdatesession == 1) {
1748 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false && !empty($conf->global->PRODUCT_ALLOW_EXTERNAL_DOWNLOAD)) $sharefile = 1;
1749 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile, $object);
1751 if ($allowoverwrite) {
1754 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
1761 $langs->load(
"errors");
1762 if ($resupload < 0) {
1764 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
1765 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"),
null,
'errors');
1777 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
1780 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
1781 $linkObject =
new Link($db);
1782 $linkObject->entity = $conf->entity;
1783 $linkObject->url = $link;
1784 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
1785 $linkObject->objectid =
GETPOST(
'objectid',
'int');
1786 $linkObject->label =
GETPOST(
'label',
'alpha');
1787 $res = $linkObject->create($user);
1788 $langs->load(
'link');
1795 $langs->load(
"errors");
1796 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
1816 global $db, $user, $conf, $langs, $_FILES;
1818 $keytodelete = $filenb;
1821 $listofpaths = array();
1822 $listofnames = array();
1823 $listofmimes = array();
1824 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1825 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
1826 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
1828 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
1829 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
1831 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
1832 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
1835 if ($keytodelete >= 0) {
1836 $pathtodelete = $listofpaths[$keytodelete];
1837 $filetodelete = $listofnames[$keytodelete];
1838 if (empty($donotdeletefile)) {
1844 if (empty($donotdeletefile)) {
1845 $langs->load(
"other");
1846 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
1848 if (empty($donotupdatesession)) {
1849 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1851 $formmail->trackid = $trackid;
1852 $formmail->remove_attached_files($keytodelete);
1874 global $db, $user, $conf;
1878 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
1880 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
1881 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
1882 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1883 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1885 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1887 $ecmfile->filepath = $rel_dir;
1888 $ecmfile->filename = $filename;
1889 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
1890 $ecmfile->fullpath_orig = $fullpathorig;
1891 $ecmfile->gen_or_uploaded = $mode;
1892 $ecmfile->description =
'';
1893 $ecmfile->keywords =
'';
1895 if (is_object($object) && $object->id > 0) {
1896 $ecmfile->src_object_id = $object->id;
1897 if (isset($object->table_element)) {
1898 $ecmfile->src_object_type = $object->table_element;
1900 dol_syslog(
'Error: object ' . get_class($object) .
' has no table_element attribute.');
1903 if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description;
1904 if (isset($object->src_object_keywords)) $ecmfile->keywords = $object->src_object_keywords;
1907 if (!empty($conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE)) {
1912 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1916 $result = $ecmfile->create($user);
1935 global $conf, $db, $user;
1940 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
1946 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
1948 $filename = basename($file);
1949 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1950 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1953 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
1954 $sql .=
' WHERE entity = '.$conf->entity;
1955 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
1957 $sql .=
" AND filename = '".$db->escape($file).
"'";
1960 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
1963 $resql = $db->query($sql);
1966 dol_syslog(__METHOD__.
' '.$db->lasterror(), LOG_ERR);
1994 if (class_exists(
'Imagick')) {
1995 $image =
new Imagick();
1997 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
1999 $ret = $image->readImage($filetoconvert);
2001 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
2002 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);
2006 $ret = $image->setImageFormat($ext);
2008 if (empty($fileoutput)) {
2009 $fileoutput = $fileinput.
".".$ext;
2012 $count = $image->getNumberImages();
2014 if (!
dol_is_file($fileoutput) || is_writeable($fileoutput)) {
2016 $ret = $image->writeImages($fileoutput,
true);
2021 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2051 function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring =
null)
2058 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2061 if ($mode ==
'gz') {
2063 $compressdata = gzencode($data, 9);
2064 } elseif ($mode ==
'bz') {
2066 $compressdata = bzcompress($data, 9);
2067 } elseif ($mode ==
'zstd') {
2069 $compressdata = zstd_compress($data, 9);
2070 } elseif ($mode ==
'zip') {
2071 if (class_exists(
'ZipArchive') && !empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS)) {
2074 $rootPath = realpath($inputfile);
2076 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2077 $zip =
new ZipArchive;
2079 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2080 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2084 $errormsg = $errorstring;
2091 $files =
new RecursiveIteratorIterator(
2092 new RecursiveDirectoryIterator($rootPath),
2093 RecursiveIteratorIterator::LEAVES_ONLY
2096 foreach ($files as $name => $file) {
2098 if (!$file->isDir()) {
2100 $filePath = $file->getPath();
2101 $fileName = $file->getFilename();
2102 $fileFullRealPath = $file->getRealPath();
2105 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2108 $zip->addFile($fileFullRealPath, $relativePath);
2115 dol_syslog(
"dol_compress_file success - ".count($zip->numFiles).
" files");
2119 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2122 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2123 $archive =
new PclZip($outputfile);
2124 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2126 if ($result === 0) {
2128 $errormsg = $archive->errorInfo(
true);
2130 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2131 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2132 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2136 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2137 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2140 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2146 if ($foundhandler) {
2147 $fp = fopen($outputfile,
"w");
2148 fwrite($fp, $compressdata);
2152 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2156 $errormsg = $errorstring;
2160 global $langs, $errormsg;
2161 $langs->load(
"errors");
2162 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2164 $errorstring =
"Failed to open file ".$outputfile;
2180 global $conf, $langs, $db;
2182 $fileinfo = pathinfo($inputfile);
2183 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2185 if ($fileinfo[
"extension"] ==
"zip") {
2186 if (defined(
'ODTPHP_PATHTOPCLZIP') && empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS)) {
2187 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2188 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2189 $archive =
new PclZip($inputfile);
2195 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2197 if (!is_array($result) && $result <= 0) {
2198 return array(
'error'=>$archive->errorInfo(
true));
2203 foreach ($result as $key => $val) {
2204 if ($val[
'status'] ==
'path_creation_fail') {
2205 $langs->load(
"errors");
2207 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2215 return array(
'error'=>$errmsg);
2220 if (class_exists(
'ZipArchive')) {
2221 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2222 $zip =
new ZipArchive;
2223 $res = $zip->open($inputfile);
2224 if ($res ===
true) {
2230 for ($i = 0; $i < $zip->numFiles; $i++) {
2231 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2232 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2235 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2241 return array(
'error'=>
'ErrUnzipFails');
2245 return array(
'error'=>
'ErrNoZipEngine');
2246 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2247 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2248 $utils =
new Utils($db);
2255 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2256 if ($extension ==
"tar") {
2259 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2260 if ($resarray[
"result"] != 0) {
2261 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2265 if ($fileinfo[
"extension"] ==
"gz") {
2267 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2269 } elseif ($fileinfo[
"extension"] ==
"zst") {
2272 return array(
'error'=>
'ErrorBadFileExtension');
2275 $cmd .=
' > '.$outputfilename;
2277 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0,
null, 1, $outputfilename.
'.err');
2278 if ($resarray[
"result"] != 0) {
2279 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2280 if ($errfilecontent) {
2281 $resarray[
"error"] .=
" - ".$errfilecontent;
2285 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2288 return array(
'error'=>
'ErrorBadFileExtension');
2304 function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'', $newmask = 0)
2310 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2312 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2313 global $langs, $errormsg;
2314 $langs->load(
"errors");
2315 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2320 if ($mode ==
'gz') {
2322 } elseif ($mode ==
'bz') {
2324 } elseif ($mode ==
'zip') {
2338 if (class_exists(
'ZipArchive')) {
2342 $zip =
new ZipArchive();
2343 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2345 global $langs, $errormsg;
2346 $langs->load(
"errors");
2347 $errormsg = $langs->trans(
"ErrorFailedToWriteInFile", $outputfile);
2354 $files =
new RecursiveIteratorIterator(
2355 new RecursiveDirectoryIterator($inputdir),
2356 RecursiveIteratorIterator::LEAVES_ONLY
2360 foreach ($files as $name => $file) {
2362 if (!$file->isDir()) {
2364 $filePath = $file->getPath();
2365 $fileName = $file->getFilename();
2366 $fileFullRealPath = $file->getRealPath();
2369 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2372 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2374 $zip->addFile($fileFullRealPath, $relativePath);
2382 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
2383 $newmask = $conf->global->MAIN_UMASK;
2385 if (empty($newmask)) {
2386 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
2390 @chmod($outputfile, octdec($newmask));
2396 if (!$foundhandler) {
2397 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2403 global $langs, $errormsg;
2404 $langs->load(
"errors");
2405 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2407 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile).
' - '.$e->getMessage();
2424 function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook =
false, $mode =
'')
2426 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2427 return $tmparray[0];
2445 global $conf, $db, $user, $hookmanager;
2446 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2449 if (!is_object($fuser)) {
2453 if (empty($modulepart)) {
2454 return 'ErrorBadParameter';
2456 if (empty($entity)) {
2464 if ($modulepart ==
'users') {
2465 $modulepart =
'user';
2467 if ($modulepart ==
'tva') {
2468 $modulepart =
'tax-vat';
2472 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2476 $sqlprotectagainstexternals =
'';
2480 if (empty($refname)) {
2481 $refname = basename(dirname($original_file).
"/");
2482 if ($refname ==
'thumbs') {
2484 $refname = basename(dirname(dirname($original_file)).
"/");
2491 $download =
'download';
2492 if ($mode ==
'write') {
2495 $download =
'upload';
2499 if ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2500 if (empty($entity) || empty($conf->medias->multidir_output[$entity])) {
2501 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2504 $original_file = $conf->medias->multidir_output[$entity].
'/'.$original_file;
2505 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2507 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.log$/', basename($original_file)));
2508 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2509 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2511 $accessallowed = $user->admin;
2512 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2513 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2515 $accessallowed = ($fuser->rights->website->write && preg_match(
'/\.jpg$/i', basename($original_file)));
2516 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2517 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2520 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2523 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2524 $original_file = $dirins.
'/'.$original_file;
2525 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
2528 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
2529 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
2532 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2535 $original_file = $conf->user->dir_output.
'/'.$original_file;
2536 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
2539 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
2540 } elseif ($modulepart ==
'memberphoto' && !empty($conf->adherent->dir_output)) {
2543 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2546 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
2547 } elseif ($modulepart ==
'apercufacture' && !empty($conf->facture->multidir_output[$entity])) {
2549 if ($fuser->rights->facture->{$lire}) {
2552 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2553 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
2555 if ($fuser->rights->propal->{$lire}) {
2558 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2559 } elseif ($modulepart ==
'apercucommande' && !empty($conf->commande->multidir_output[$entity])) {
2561 if ($fuser->rights->commande->{$lire}) {
2564 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2565 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->dir_output)) {
2567 if ($fuser->rights->ficheinter->{$lire}) {
2570 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2571 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contrat->multidir_output[$entity])) {
2573 if ($fuser->rights->contrat->{$lire}) {
2576 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2577 } elseif (($modulepart ==
'apercusupplier_proposal' || $modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
2579 if ($fuser->rights->supplier_proposal->{$lire}) {
2582 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
2583 } elseif (($modulepart ==
'apercusupplier_order' || $modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
2585 if ($fuser->rights->fournisseur->commande->{$lire}) {
2588 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2589 } elseif (($modulepart ==
'apercusupplier_invoice' || $modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
2591 if ($fuser->rights->fournisseur->facture->{$lire}) {
2594 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2595 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
2596 if ($fuser->rights->holiday->{$read} || !empty($fuser->rights->holiday->readall) || preg_match(
'/^specimen/i', $original_file)) {
2599 if ($refname && empty($fuser->rights->holiday->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2600 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
2601 $tmpholiday =
new Holiday($db);
2602 $tmpholiday->fetch(
'', $refname);
2603 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
2606 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
2607 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
2608 if ($fuser->rights->expensereport->{$lire} || !empty($fuser->rights->expensereport->readall) || preg_match(
'/^specimen/i', $original_file)) {
2611 if ($refname && empty($fuser->rights->expensereport->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2612 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
2614 $tmpexpensereport->fetch(
'', $refname);
2615 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
2618 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2619 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
2621 if ($fuser->rights->expensereport->{$lire}) {
2624 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2625 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
2627 if ($fuser->rights->propal->{$lire}) {
2630 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
2631 } elseif ($modulepart ==
'orderstats' && !empty($conf->commande->dir_temp)) {
2633 if ($fuser->rights->commande->{$lire}) {
2636 $original_file = $conf->commande->dir_temp.
'/'.$original_file;
2637 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2638 if ($fuser->rights->fournisseur->commande->{$lire}) {
2641 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
2642 } elseif ($modulepart ==
'billstats' && !empty($conf->facture->dir_temp)) {
2644 if ($fuser->rights->facture->{$lire}) {
2647 $original_file = $conf->facture->dir_temp.
'/'.$original_file;
2648 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2649 if ($fuser->rights->fournisseur->facture->{$lire}) {
2652 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
2653 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
2655 if ($fuser->rights->expedition->{$lire}) {
2658 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
2659 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
2661 if ($fuser->rights->deplacement->{$lire}) {
2664 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
2665 } elseif ($modulepart ==
'memberstats' && !empty($conf->adherent->dir_temp)) {
2667 if ($fuser->rights->adherent->{$lire}) {
2670 $original_file = $conf->adherent->dir_temp.
'/'.$original_file;
2671 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
2673 if ($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) {
2676 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
2677 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
2679 if ($fuser->rights->tax->charges->{$lire}) {
2682 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
2683 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
2684 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2686 if ($fuser->rights->agenda->myactions->{$read}) {
2689 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2690 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2692 $tmpobject->fetch((
int) $refname);
2693 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
2694 if ($user->socid && $tmpobject->socid) {
2699 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2700 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
2702 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
2703 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2705 if ($fuser->rights->categorie->{$lire} || $fuser->rights->takepos->run) {
2708 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
2709 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
2711 if ($fuser->rights->prelevement->bons->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2714 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
2715 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
2718 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
2719 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
2722 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
2723 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
2726 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
2727 } elseif ($modulepart ==
'barcode') {
2732 $original_file =
'';
2733 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
2736 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
2737 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
2740 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
2741 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
2744 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
2745 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
2747 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2748 if ($fuser->id == (
int) $refname) {
2751 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
2754 $original_file = $conf->user->dir_output.
'/'.$original_file;
2755 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
2757 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2758 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2760 if ($fuser->rights->societe->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2763 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
2764 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
2765 } elseif ($modulepart ==
'contact' && !empty($conf->societe->multidir_output[$entity])) {
2767 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2768 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2770 if ($fuser->rights->societe->{$lire}) {
2773 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
2774 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->facture->multidir_output[$entity])) {
2776 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2779 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2780 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
2781 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
2783 if ($fuser->rights->propal->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2786 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2787 } elseif ($modulepart ==
'massfilesarea_orders') {
2788 if ($fuser->rights->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2791 $original_file = $conf->commande->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2792 } elseif ($modulepart ==
'massfilesarea_sendings') {
2793 if ($fuser->rights->expedition->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2796 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
2797 } elseif ($modulepart ==
'massfilesarea_invoices') {
2798 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2801 $original_file = $conf->facture->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2802 } elseif ($modulepart ==
'massfilesarea_expensereport') {
2803 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2806 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2807 } elseif ($modulepart ==
'massfilesarea_interventions') {
2808 if ($fuser->rights->ficheinter->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2811 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2812 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
2813 if ($fuser->rights->supplier_proposal->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2816 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2817 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
2818 if ($fuser->rights->fournisseur->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2821 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2822 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
2823 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2826 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2827 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contrat->dir_output)) {
2828 if ($fuser->rights->contrat->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2831 $original_file = $conf->contrat->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2832 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->dir_output)) {
2834 if ($fuser->rights->ficheinter->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2837 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2838 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2839 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
2841 if ($fuser->rights->deplacement->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2844 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
2846 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && !empty($conf->propal->multidir_output[$entity])) {
2848 if ($fuser->rights->propal->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2851 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2852 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
2853 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->commande->multidir_output[$entity])) {
2855 if ($fuser->rights->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2858 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2859 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
2860 } elseif ($modulepart ==
'project' && !empty($conf->project->dir_output)) {
2862 if ($fuser->rights->projet->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2865 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2866 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
2867 $tmpproject =
new Project($db);
2868 $tmpproject->fetch(
'', $refname);
2869 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
2872 $original_file = $conf->project->dir_output.
'/'.$original_file;
2873 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
2874 } elseif ($modulepart ==
'project_task' && !empty($conf->project->dir_output)) {
2875 if ($fuser->rights->projet->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2878 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2879 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
2880 $tmptask =
new Task($db);
2881 $tmptask->fetch(
'', $refname);
2882 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
2885 $original_file = $conf->project->dir_output.
'/'.$original_file;
2886 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
2887 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
2889 if ($fuser->rights->fournisseur->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2892 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2893 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2894 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
2896 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2899 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2900 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2901 } elseif ($modulepart ==
'supplier_payment') {
2903 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2906 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
2907 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2908 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->facture->dir_output)) {
2910 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2913 if ($fuser->socid > 0) {
2914 $original_file = $conf->facture->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
2916 $original_file = $conf->facture->dir_output.
'/payments/'.$original_file;
2918 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
2920 if ($fuser->rights->accounting->bind->write || preg_match(
'/^specimen/i', $original_file)) {
2923 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
2924 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty($conf->expedition->dir_output)) {
2926 if ($fuser->rights->expedition->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2929 $original_file = $conf->expedition->dir_output.
"/".(strpos(
'sending/', $original_file) === 0 ?
'' :
'sending/').$original_file;
2931 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
2933 if ($fuser->rights->expedition->delivery->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2936 $original_file = $conf->expedition->dir_output.
"/".(strpos(
'receipt/', $original_file) === 0 ?
'' :
'receipt/').$original_file;
2937 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2939 if ($fuser->rights->agenda->myactions->{$read} || preg_match(
'/^specimen/i', $original_file)) {
2942 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2943 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
2945 if ($fuser->rights->agenda->allactions->{$read} || preg_match(
'/^specimen/i', $original_file)) {
2948 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
2949 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
2951 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
2952 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2954 if (($fuser->rights->produit->{$lire} || $fuser->rights->service->{$lire}) || preg_match(
'/^specimen/i', $original_file)) {
2958 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
2960 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
2962 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
2964 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
2965 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2967 if (($fuser->rights->produit->{$lire} ) || preg_match(
'/^specimen/i', $original_file)) {
2971 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
2973 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
2975 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
2976 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2978 if (($fuser->rights->stock->{$lire} || $fuser->rights->stock->movement->{$lire} || $fuser->rights->stock->mouvement->{$lire}) || preg_match(
'/^specimen/i', $original_file)) {
2982 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
2984 } elseif ($modulepart ==
'contract' && !empty($conf->contrat->multidir_output[$entity])) {
2986 if ($fuser->rights->contrat->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2989 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2990 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
2991 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
2993 if ($fuser->rights->don->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2996 $original_file = $conf->don->dir_output.
'/'.$original_file;
2997 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
2999 if ($fuser->rights->resource->{$read} || preg_match(
'/^specimen/i', $original_file)) {
3002 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3003 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3005 if ($fuser->rights->banque->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3009 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3010 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3012 if ($fuser->rights->banque->{$lire}) {
3015 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3016 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3019 $accessallowed = $user->rights->export->lire;
3020 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3021 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3023 $accessallowed = $user->rights->import->run;
3024 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3025 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3027 $accessallowed = $user->rights->recruitment->recruitmentjobposition->read;
3028 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3029 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3032 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3033 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3035 if ($fuser->admin) {
3038 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3039 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3041 if ($fuser->admin) {
3044 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3045 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3049 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3052 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3053 } elseif ($modulepart ==
'member' && !empty($conf->adherent->dir_output)) {
3055 if ($fuser->rights->adherent->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3058 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
3059 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3062 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3072 if (preg_match(
'/^specimen/i', $original_file)) {
3075 if ($fuser->admin) {
3079 $tmpmodulepart = explode(
'-', $modulepart);
3080 if (!empty($tmpmodulepart[1])) {
3081 $modulepart = $tmpmodulepart[0];
3082 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3087 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3088 if (empty($conf->{$reg[1]}->dir_temp)) {
3089 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3092 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3095 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3096 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3097 if (empty($conf->{$reg[1]}->dir_temp)) {
3098 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3101 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3104 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$original_file;
3105 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3106 if (empty($conf->{$reg[1]}->dir_output)) {
3107 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3110 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3113 $original_file = $conf->{$reg[1]}->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3114 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3115 if (empty($conf->{$reg[1]}->dir_output)) {
3116 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3119 if ($fuser->rights->{$reg[1]}->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3122 $original_file = $conf->{$reg[1]}->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3124 if (empty($conf->$modulepart->dir_output)) {
3125 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.');
3130 $partsofdirinoriginalfile = explode(
'/', $original_file);
3131 if (!empty($partsofdirinoriginalfile[1])) {
3132 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3133 if ($partofdirinoriginalfile && !empty($fuser->rights->$modulepart->$partofdirinoriginalfile) && ($fuser->rights->$modulepart->$partofdirinoriginalfile->{$lire} || $fuser->rights->$modulepart->$partofdirinoriginalfile->{$read})) {
3137 if (!empty($fuser->rights->$modulepart->{$lire}) || !empty($fuser->rights->$modulepart->{$read})) {
3141 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3142 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3144 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3148 $parameters = array(
3149 'modulepart' => $modulepart,
3150 'original_file' => $original_file,
3151 'entity' => $entity,
3156 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters, $object);
3158 if (!empty($hookmanager->resArray[
'original_file'])) {
3159 $original_file = $hookmanager->resArray[
'original_file'];
3161 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3162 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3164 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3165 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3171 'accessallowed' => ($accessallowed ? 1 : 0),
3172 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3173 'original_file' => $original_file
3192 $cachefile = $directory.$filename;
3193 file_put_contents($cachefile, serialize($object), LOCK_EX);
3194 @chmod($cachefile, 0644);
3208 $cachefile = $directory.$filename;
3209 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3222 $cachefile = $directory.$filename;
3223 $object = unserialize(file_get_contents($cachefile));
3239 function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3243 $exclude =
'install';
3245 foreach ($dir->md5file as $file) {
3246 $filename = $path.$file[
'name'];
3247 $file_list[
'insignature'][] = $filename;
3248 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3249 $expectedmd5 = (string) $file;
3253 if (!file_exists($pathref.
'/'.$filename)) {
3254 $file_list[
'missing'][] = array(
'filename'=>$filename,
'expectedmd5'=>$expectedmd5,
'expectedsize'=>$expectedsize);
3256 $md5_local = md5_file($pathref.
'/'.$filename);
3258 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3259 $checksumconcat[] = $expectedmd5;
3261 if ($md5_local != $expectedmd5) {
3262 $file_list[
'updated'][] = array(
'filename'=>$filename,
'expectedmd5'=>$expectedmd5,
'expectedsize'=>$expectedsize,
'md5'=>(
string) $md5_local);
3264 $checksumconcat[] = $md5_local;
3269 foreach ($dir->dir as $subdir) {
3270 getFilesUpdated($file_list, $subdir, $path.$subdir[
'name'].
'/', $pathref, $checksumconcat);
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 utility methods.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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.
dolCheckVirus($src_file)
Check virus into a file.
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)
Copy a file to another file.
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='')
Make control on an uploaded file from an GUI page and move it to 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_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
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...
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
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_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode='')
Return file(s) into a directory (by default most recent)
dol_is_url($url)
Return if path is an URL.
dol_filecache($directory, $filename, $object)
Store object in file.
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_is_file($pathoffile)
Return if path is a file.
dol_count_nb_of_line($file)
Count number of lines in a file.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask=0, $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_unescapefile($filename)
Unescape a file submitted by upload.
dol_dir_list($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.
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).
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null)
Copy a dir to another dir.
deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded')
Delete files into database index using search criterias.
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_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_cache_refresh($directory, $filename, $cachetime)
Test if Refresh needed.
dol_delete_preview($object)
Delete all preview files linked to object instance.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
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.
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.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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...
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
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).
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.