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][
'keywords'] = $filearrayindatabase[$key2][
'keywords'];
353 $filearray[$key][
'acl'] = $filearrayindatabase[$key2][
'acl'];
354 $filearray[$key][
'rowid'] = $filearrayindatabase[$key2][
'rowid'];
355 $filearray[$key][
'label'] = $filearrayindatabase[$key2][
'label'];
356 $filearray[$key][
'share'] = $filearrayindatabase[$key2][
'share'];
363 $filearray[$key][
'position'] =
'999999';
364 $filearray[$key][
'cover'] = 0;
365 $filearray[$key][
'acl'] =
'';
367 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'fullname']);
369 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filename)) {
370 dol_syslog(
"list_of_documents We found a file called '".$filearray[$key][
'name'].
"' not indexed into database. We add it");
371 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
375 $filename = basename($rel_filename);
376 $rel_dir = dirname($rel_filename);
377 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
378 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
380 $ecmfile->filepath = $rel_dir;
381 $ecmfile->filename = $filename;
382 $ecmfile->label = md5_file(
dol_osencode($filearray[$key][
'fullname']));
383 $ecmfile->fullpath_orig = $filearray[$key][
'fullname'];
384 $ecmfile->gen_or_uploaded =
'unknown';
385 $ecmfile->description =
'';
386 $ecmfile->keywords =
'';
387 $result = $ecmfile->create($user);
391 $filearray[$key][
'rowid'] = $result;
394 $filearray[$key][
'rowid'] = 0;
414 $sortorder = strtoupper($sortorder);
416 if ($sortorder ==
'ASC') {
424 if ($sortfield ==
'name') {
425 if ($a->name == $b->name) {
428 return ($a->name < $b->name) ? $retup : $retdown;
430 if ($sortfield ==
'date') {
431 if ($a->date == $b->date) {
434 return ($a->date < $b->date) ? $retup : $retdown;
436 if ($sortfield ==
'size') {
437 if ($a->size == $b->size) {
440 return ($a->size < $b->size) ? $retup : $retdown;
454 if (is_dir($newfolder)) {
469 if (!is_readable($dir)) {
472 return (count(scandir($dir)) == 2);
484 return is_file($newpathoffile);
496 return is_link($newpathoffile);
507 $tmpprot = array(
'file',
'http',
'https',
'ftp',
'zlib',
'data',
'ssh',
'ssh2',
'ogg',
'expect');
508 foreach ($tmpprot as $prot) {
509 if (preg_match(
'/^'.$prot.
':/i', $url)) {
525 if (is_dir($newfolder)) {
526 $handle = opendir($newfolder);
527 $folder_content =
'';
528 while ((gettype($name = readdir($handle)) !=
"boolean")) {
529 $name_array[] = $name;
531 foreach ($name_array as $temp) {
532 $folder_content .= $temp;
537 if ($folder_content ==
"...") {
560 $fp = fopen($newfile,
'r');
565 if (!$line ===
false) {
588 return filesize($newpathoffile);
600 return @filemtime($newpathoffile);
612 return fileperms($newpathoffile);
627 function dolReplaceInFile($srcfile, $arrayreplacement, $destfile =
'', $newmask = 0, $indexdatabase = 0, $arrayreplacementisregex = 0)
631 dol_syslog(
"files.lib.php::dolReplaceInFile srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" indexdatabase=".$indexdatabase.
" arrayreplacementisregex=".$arrayreplacementisregex);
633 if (empty($srcfile)) {
636 if (empty($destfile)) {
637 $destfile = $srcfile;
641 if (($destfile != $srcfile) && $destexists) {
647 dol_syslog(
"files.lib.php::dolReplaceInFile failed to read src file", LOG_WARNING);
651 $tmpdestfile = $destfile.
'.tmp';
656 $newdirdestfile = dirname($newpathofdestfile);
658 if ($destexists && !is_writable($newpathofdestfile)) {
659 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
662 if (!is_writable($newdirdestfile)) {
663 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
670 $content = file_get_contents($newpathofsrcfile,
'r');
672 if (empty($arrayreplacementisregex)) {
675 foreach ($arrayreplacement as $key => $value) {
676 $content = preg_replace($key, $value, $content);
680 file_put_contents($newpathoftmpdestfile, $content);
681 @chmod($newpathoftmpdestfile, octdec($newmask));
684 $result =
dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
686 dol_syslog(
"files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
689 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
690 $newmask = $conf->global->MAIN_UMASK;
692 if (empty($newmask)) {
693 dol_syslog(
"Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
697 @chmod($newpathofdestfile, octdec($newmask));
713 function dol_copy($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1)
717 dol_syslog(
"files.lib.php::dol_copy srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
719 if (empty($srcfile) || empty($destfile)) {
724 if (!$overwriteifexists && $destexists) {
730 $newdirdestfile = dirname($newpathofdestfile);
732 if ($destexists && !is_writable($newpathofdestfile)) {
733 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
736 if (!is_writable($newdirdestfile)) {
737 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
741 $result = @copy($newpathofsrcfile, $newpathofdestfile);
744 dol_syslog(
"files.lib.php::dol_copy failed to copy", LOG_WARNING);
747 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
748 $newmask = $conf->global->MAIN_UMASK;
750 if (empty($newmask)) {
751 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
755 @chmod($newpathofdestfile, octdec($newmask));
773 function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement =
null, $excludesubdir = 0, $excludefileext =
null)
779 dol_syslog(
"files.lib.php::dolCopyDir srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
781 if (empty($srcfile) || empty($destfile)) {
791 $dirmaskdec = octdec($newmask);
792 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
793 $dirmaskdec = octdec($conf->global->MAIN_UMASK);
795 $dirmaskdec |= octdec(
'0200');
796 dol_mkdir($destfile,
'', decoct($dirmaskdec));
803 if (is_dir($ossrcfile)) {
804 $dir_handle = opendir($ossrcfile);
805 while ($file = readdir($dir_handle)) {
806 if ($file !=
"." && $file !=
".." && !is_link($ossrcfile.
"/".$file)) {
807 if (is_dir($ossrcfile.
"/".$file)) {
808 if (empty($excludesubdir) || ($excludesubdir == 2 && strlen($file) == 2)) {
811 if (is_array($arrayreplacement)) {
812 foreach ($arrayreplacement as $key => $val) {
813 $newfile = str_replace($key, $val, $newfile);
817 $tmpresult =
dolCopyDir($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists, $arrayreplacement, $excludesubdir, $excludefileext);
822 if (is_array($excludefileext)) {
823 $extension = pathinfo($file, PATHINFO_EXTENSION);
824 if (in_array($extension, $excludefileext)) {
831 if (is_array($arrayreplacement)) {
832 foreach ($arrayreplacement as $key => $val) {
833 $newfile = str_replace($key, $val, $newfile);
836 $tmpresult =
dol_copy($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists);
839 if ($result > 0 && $tmpresult >= 0) {
842 $result = $tmpresult;
849 closedir($dir_handle);
875 function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1)
877 global $user, $db, $conf;
880 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
885 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
889 if ($overwriteifexists || !$destexists) {
894 $testvirusarray = array();
897 if (count($testvirusarray)) {
898 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
903 $result = @rename($newpathofsrcfile, $newpathofdestfile);
906 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
909 $result = @rename($newpathofsrcfile, $newpathofdestfile);
911 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
916 if ($result && $indexdatabase) {
918 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
919 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
920 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
921 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
922 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
925 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
926 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
929 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
930 if ($resultecmtarget > 0) {
931 $ecmfiletarget->delete($user);
935 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
936 if ($resultecm > 0) {
937 $filename = basename($rel_filetorenameafter);
938 $rel_dir = dirname($rel_filetorenameafter);
939 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
940 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
942 $ecmfile->filepath = $rel_dir;
943 $ecmfile->filename = $filename;
945 $resultecm = $ecmfile->update($user);
946 } elseif ($resultecm == 0) {
947 $filename = basename($rel_filetorenameafter);
948 $rel_dir = dirname($rel_filetorenameafter);
949 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
950 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
952 $ecmfile->filepath = $rel_dir;
953 $ecmfile->filename = $filename;
955 $ecmfile->fullpath_orig = $srcfile;
956 $ecmfile->gen_or_uploaded =
'unknown';
957 $ecmfile->description =
'';
958 $ecmfile->keywords =
'';
959 $resultecm = $ecmfile->create($user);
960 if ($resultecm < 0) {
963 } elseif ($resultecm < 0) {
967 if ($resultecm > 0) {
975 if (empty($newmask)) {
976 $newmask = empty($conf->global->MAIN_UMASK) ?
'0755' : $conf->global->MAIN_UMASK;
978 $newmaskdec = octdec($newmask);
982 @chmod($newpathofdestfile, $newmaskdec);
999 function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase = 1, $renamedircontent = 1)
1002 global $user, $db, $conf;
1005 dol_syslog(
"files.lib.php::dol_move_dir srcdir=".$srcdir.
" destdir=".$destdir.
" overwritifexists=".$overwriteifexists.
" indexdatabase=".$indexdatabase.
" renamedircontent=".$renamedircontent);
1007 $srcbasename = basename($srcdir);
1011 dol_syslog(
"files.lib.php::dol_move_dir srcdir does not exists. we ignore the move request.");
1015 if ($overwriteifexists || !$destexists) {
1019 $result = @rename($newpathofsrcdir, $newpathofdestdir);
1021 if ($result && $renamedircontent) {
1022 if (file_exists($newpathofdestdir)) {
1023 $destbasename = basename($newpathofdestdir);
1025 if (!empty($files) && is_array($files)) {
1026 foreach ($files as $key => $file) {
1027 if (!file_exists($file[
"fullname"]))
continue;
1028 $filepath = $file[
"path"];
1029 $oldname = $file[
"name"];
1031 $newname = str_replace($srcbasename, $destbasename, $oldname);
1032 if (!empty($newname) && $newname !== $oldname) {
1033 if ($file[
"type"] ==
"dir") {
1034 $res =
dol_move_dir($filepath.
'/'.$oldname, $filepath.
'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent);
1036 $res =
dol_move($filepath.
'/'.$oldname, $filepath.
'/'.$newname, 0, $overwriteifexists, 0, $indexdatabase);
1063 return trim(basename($filename),
".\x00..\x20");
1077 if (!empty($conf->global->MAIN_ANTIVIRUS_COMMAND)) {
1078 if (!class_exists(
'AntiVir')) {
1079 require_once DOL_DOCUMENT_ROOT.
'/core/class/antivir.class.php';
1082 $result = $antivir->dol_avscan_file($src_file);
1084 $reterrors = $antivir->errors;
1112 function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles =
'addedfile', $upload_dir =
'')
1114 global $conf, $db, $user, $langs;
1115 global $object, $hookmanager;
1118 $file_name = $dest_file;
1121 if (empty($nohook)) {
1122 $reshook = $hookmanager->initHooks(array(
'fileslib'));
1124 $parameters = array(
'dest_file' => $dest_file,
'src_file' => $src_file,
'file_name' => $file_name,
'varfiles' => $varfiles,
'allowoverwrite' => $allowoverwrite);
1125 $reshook = $hookmanager->executeHooks(
'moveUploadedFile', $parameters, $object);
1128 if (empty($reshook)) {
1130 if ($uploaderrorcode) {
1131 switch ($uploaderrorcode) {
1132 case UPLOAD_ERR_INI_SIZE:
1133 return 'ErrorFileSizeTooLarge';
1134 case UPLOAD_ERR_FORM_SIZE:
1135 return 'ErrorFileSizeTooLarge';
1136 case UPLOAD_ERR_PARTIAL:
1137 return 'ErrorPartialFile';
1138 case UPLOAD_ERR_NO_TMP_DIR:
1139 return 'ErrorNoTmpDir';
1140 case UPLOAD_ERR_CANT_WRITE:
1141 return 'ErrorFailedToWriteInDir';
1142 case UPLOAD_ERR_EXTENSION:
1143 return 'ErrorUploadBlockedByAddon';
1150 if (empty($disablevirusscan) && file_exists($src_file)) {
1152 if (count($checkvirusarray)) {
1153 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.join(
',', $checkvirusarray), LOG_WARNING);
1154 return 'ErrorFileIsInfectedWithAVirus: '.join(
',', $checkvirusarray);
1163 $publicmediasdirwithslash = $conf->medias->multidir_output[$conf->entity];
1164 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
1165 $publicmediasdirwithslash .=
'/';
1168 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0) {
1169 $file_name .=
'.noexe';
1176 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
1177 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
1183 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
1184 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
1190 $errmsg = join(
',', $hookmanager->errors);
1191 if (empty($errmsg)) {
1192 $errmsg =
'ErrorReturnedBySomeHooks';
1195 } elseif (empty($reshook)) {
1201 if (!is_writable(dirname($file_name_osencoded))) {
1202 dol_syslog(
"Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded).
" is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1203 return 'ErrorDirNotWritable';
1207 if (!$allowoverwrite) {
1208 if (file_exists($file_name_osencoded)) {
1209 dol_syslog(
"Files.lib::dol_move_uploaded_file File ".$file_name.
" already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
1210 return 'ErrorFileAlreadyExists';
1213 if (is_dir($file_name_osencoded)) {
1214 dol_syslog(
"Files.lib::dol_move_uploaded_file A directory with name ".$file_name.
" already exists. Return 'ErrorDirWithFileNameAlreadyExists'", LOG_WARNING);
1215 return 'ErrorDirWithFileNameAlreadyExists';
1220 $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1222 if (!empty($conf->global->MAIN_UMASK)) {
1223 @chmod($file_name_osencoded, octdec($conf->global->MAIN_UMASK));
1225 dol_syslog(
"Files.lib::dol_move_uploaded_file Success to move ".$src_file.
" to ".$file_name.
" - Umask=".$conf->global->MAIN_UMASK, LOG_DEBUG);
1226 return $successcode;
1228 dol_syslog(
"Files.lib::dol_move_uploaded_file Failed to move ".$src_file.
" to ".$file_name, LOG_ERR);
1233 return $successcode;
1251 function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0, $object =
null, $allowdotdot =
false, $indexdatabase = 1, $nolog = 0)
1253 global $db, $conf, $user, $langs;
1254 global $hookmanager;
1257 $langs->loadLangs(array(
'other',
'errors'));
1259 if (empty($nolog)) {
1260 dol_syslog(
"dol_delete_file file=".$file.
" disableglob=".$disableglob.
" nophperrors=".$nophperrors.
" nohook=".$nohook);
1265 if ((!$allowdotdot && preg_match(
'/\.\./', $file)) || preg_match(
'/[<>|]/', $file)) {
1266 dol_syslog(
"Refused to delete file ".$file, LOG_WARNING);
1271 if (empty($nohook)) {
1272 $hookmanager->initHooks(array(
'fileslib'));
1274 $parameters = array(
1276 'disableglob'=> $disableglob,
1277 'nophperrors' => $nophperrors
1279 $reshook = $hookmanager->executeHooks(
'deleteFile', $parameters, $object);
1282 if (empty($nohook) && $reshook != 0) {
1290 if (empty($disableglob) && !empty($file_osencoded)) {
1292 $globencoded = str_replace(
'[',
'\[', $file_osencoded);
1293 $globencoded = str_replace(
']',
'\]', $globencoded);
1294 $listofdir = glob($globencoded);
1295 if (!empty($listofdir) && is_array($listofdir)) {
1296 foreach ($listofdir as $filename) {
1298 $ok = @unlink($filename);
1300 $ok = unlink($filename);
1304 if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
1305 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);
1306 @chmod(dirname($filename), fileperms(dirname($filename)) | 0200);
1309 $ok = @unlink($filename);
1311 $ok = unlink($filename);
1316 if (empty($nolog)) {
1317 dol_syslog(
"Removed file ".$filename, LOG_DEBUG);
1321 $rel_filetodelete = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filename);
1322 if (!preg_match(
'/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1323 if (is_object($db) && $indexdatabase) {
1324 $rel_filetodelete = preg_replace(
'/^[\\/]/',
'', $rel_filetodelete);
1325 $rel_filetodelete = preg_replace(
'/\.noexe$/',
'', $rel_filetodelete);
1327 dol_syslog(
"Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1328 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1330 $result = $ecmfile->fetch(0,
'', $rel_filetodelete);
1331 if ($result >= 0 && $ecmfile->id > 0) {
1332 $result = $ecmfile->delete($user);
1340 dol_syslog(
"Failed to remove file ".$filename, LOG_WARNING);
1346 dol_syslog(
"No files to delete found", LOG_DEBUG);
1351 $ok = @unlink($file_osencoded);
1353 $ok = unlink($file_osencoded);
1356 if (empty($nolog)) {
1357 dol_syslog(
"Removed file ".$file_osencoded, LOG_DEBUG);
1360 dol_syslog(
"Failed to remove file ".$file_osencoded, LOG_WARNING);
1381 if (preg_match(
'/\.\./', $dir) || preg_match(
'/[<>|]/', $dir)) {
1382 dol_syslog(
"Refused to delete dir ".$dir.
' (contains invalid char sequence)', LOG_WARNING);
1387 return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1402 function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0, $indexdatabase = 1, $nolog = 0)
1404 if (empty($nolog)) {
1405 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1409 if ($handle = opendir(
"$dir_osencoded")) {
1410 while (
false !== ($item = readdir($handle))) {
1412 $item = utf8_encode($item);
1415 if ($item !=
"." && $item !=
"..") {
1419 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0,
null,
false, $indexdatabase, $nolog);
1431 if (empty($onlysub)) {
1456 global $langs, $conf;
1459 $element = $object->element;
1461 if ($object->element ==
'order_supplier') {
1462 $dir = $conf->fournisseur->commande->dir_output;
1463 } elseif ($object->element ==
'invoice_supplier') {
1464 $dir = $conf->fournisseur->facture->dir_output;
1465 } elseif ($object->element ==
'project') {
1466 $dir = $conf->project->dir_output;
1467 } elseif ($object->element ==
'shipping') {
1468 $dir = $conf->expedition->dir_output.
'/sending';
1469 } elseif ($object->element ==
'delivery') {
1470 $dir = $conf->expedition->dir_output.
'/receipt';
1471 } elseif ($object->element ==
'fichinter') {
1472 $dir = $conf->ficheinter->dir_output;
1474 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1478 return 'ErrorObjectNoSupportedByFunction';
1482 $dir = $dir.
"/".$refsan;
1483 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1484 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1485 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1488 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1490 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1494 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1496 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1501 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1503 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1507 $multiple = $filepreviewold.
".";
1508 for ($i = 0; $i < 20; $i++) {
1509 $preview = $multiple.$i;
1511 if (file_exists($preview) && is_writable($preview)) {
1513 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1536 if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) {
1541 $element = $object->element;
1543 if ($object->element ==
'order_supplier') {
1544 $dir = $conf->fournisseur->dir_output.
'/commande';
1545 } elseif ($object->element ==
'invoice_supplier') {
1546 $dir = $conf->fournisseur->dir_output.
'/facture';
1547 } elseif ($object->element ==
'project') {
1548 $dir = $conf->project->dir_output;
1549 } elseif ($object->element ==
'shipping') {
1550 $dir = $conf->expedition->dir_output.
'/sending';
1551 } elseif ($object->element ==
'delivery') {
1552 $dir = $conf->expedition->dir_output.
'/receipt';
1553 } elseif ($object->element ==
'fichinter') {
1554 $dir = $conf->ficheinter->dir_output;
1556 $dir = empty($conf->$element->dir_output) ?
'' : $conf->$element->dir_output;
1560 $object->fetch_thirdparty();
1563 $dir = $dir.
"/".$objectref;
1564 $file = $dir.
"/".$objectref.
".meta";
1566 if (!is_dir($dir)) {
1571 $nblines = count($object->lines);
1572 $client = $object->thirdparty->name.
" ".$object->thirdparty->address.
" ".$object->thirdparty->zip.
" ".$object->thirdparty->town;
1573 $meta =
"REFERENCE=\"".$object->ref.
"\"
1575 NB_ITEMS=\"" . $nblines.
"\"
1576 CLIENT=\"" . $client.
"\"
1577 AMOUNT_EXCL_TAX=\"" . $object->total_ht.
"\"
1578 AMOUNT=\"" . $object->total_ttc.
"\"\n";
1580 for ($i = 0; $i < $nblines; $i++) {
1582 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".$object->lines[$i]->qty.
"\"
1583 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".$object->lines[$i]->total_ht.
"\"
1584 ITEM_" . $i.
"_VAT=\"".$object->lines[$i]->tva_tx.
"\"
1585 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br($object->lines[$i]->desc)).
"\"
1590 $fp = fopen($file,
"w");
1593 if (!empty($conf->global->MAIN_UMASK)) {
1594 @chmod($file, octdec($conf->global->MAIN_UMASK));
1599 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.$object->element, LOG_WARNING);
1617 $listofpaths = array();
1618 $listofnames = array();
1619 $listofmimes = array();
1623 foreach ($listoffiles as $key => $val) {
1624 $listofpaths[] = $val[
'fullname'];
1625 $listofnames[] = $val[
'name'];
1629 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1630 $_SESSION[
"listofpaths".$keytoavoidconflict] = join(
';', $listofpaths);
1631 $_SESSION[
"listofnames".$keytoavoidconflict] = join(
';', $listofnames);
1632 $_SESSION[
"listofmimes".$keytoavoidconflict] = join(
';', $listofmimes);
1653 function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1, $object =
null)
1655 global $db, $user, $conf, $langs;
1659 if (!empty($_FILES[$varfiles])) {
1660 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' donotupdatesession='.$donotupdatesession.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1661 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
1662 if (is_array($_FILES[$varfiles][
"name"]) && count($_FILES[$varfiles][
"name"]) > $maxfilesinform) {
1663 $langs->load(
"errors");
1664 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
1670 $TFile = $_FILES[$varfiles];
1671 if (!is_array($TFile[
'name'])) {
1672 foreach ($TFile as $key => &$val) {
1677 $nbfile = count($TFile[
'name']);
1679 for ($i = 0; $i < $nbfile; $i++) {
1680 if (empty($TFile[
'name'][$i])) {
1685 $destfull = $upload_dir.
"/".$TFile[
'name'][$i];
1686 $destfile = $TFile[
'name'][$i];
1687 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1689 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1690 $destfull = $upload_dir.
"/".preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask);
1691 $destfile = preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask);
1694 $filenameto = basename($destfile);
1695 if (preg_match(
'/^\./', $filenameto)) {
1696 $langs->load(
"errors");
1697 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
1702 $info = pathinfo($destfull);
1703 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1704 $info = pathinfo($destfile);
1706 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1714 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
1716 if (is_numeric($resupload) && $resupload > 0) {
1717 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
1720 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
1721 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
1722 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
1723 $maxheightmini = $tmparraysize[
'maxheightmini'];
1728 if ($generatethumbs) {
1734 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
1737 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
1742 if (empty($donotupdatesession)) {
1743 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1745 $formmail->trackid = $trackid;
1746 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
1750 if ($donotupdatesession == 1) {
1752 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false && !empty($conf->global->PRODUCT_ALLOW_EXTERNAL_DOWNLOAD)) $sharefile = 1;
1753 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile, $object);
1755 if ($allowoverwrite) {
1758 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
'',
'warnings');
1765 $langs->load(
"errors");
1766 if ($resupload < 0) {
1768 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
1769 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"),
null,
'errors');
1781 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
1784 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
1785 $linkObject =
new Link($db);
1786 $linkObject->entity = $conf->entity;
1787 $linkObject->url = $link;
1788 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
1789 $linkObject->objectid =
GETPOST(
'objectid',
'int');
1790 $linkObject->label =
GETPOST(
'label',
'alpha');
1791 $res = $linkObject->create($user);
1792 $langs->load(
'link');
1799 $langs->load(
"errors");
1800 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
1820 global $db, $user, $conf, $langs, $_FILES;
1822 $keytodelete = $filenb;
1825 $listofpaths = array();
1826 $listofnames = array();
1827 $listofmimes = array();
1828 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1829 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
1830 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
1832 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
1833 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
1835 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
1836 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
1839 if ($keytodelete >= 0) {
1840 $pathtodelete = $listofpaths[$keytodelete];
1841 $filetodelete = $listofnames[$keytodelete];
1842 if (empty($donotdeletefile)) {
1848 if (empty($donotdeletefile)) {
1849 $langs->load(
"other");
1850 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
1852 if (empty($donotupdatesession)) {
1853 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
1855 $formmail->trackid = $trackid;
1856 $formmail->remove_attached_files($keytodelete);
1878 global $db, $user, $conf;
1882 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
1884 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
1885 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
1886 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1887 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1889 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1891 $ecmfile->filepath = $rel_dir;
1892 $ecmfile->filename = $filename;
1893 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
1894 $ecmfile->fullpath_orig = $fullpathorig;
1895 $ecmfile->gen_or_uploaded = $mode;
1896 $ecmfile->description =
'';
1897 $ecmfile->keywords =
'';
1899 if (is_object($object) && $object->id > 0) {
1900 $ecmfile->src_object_id = $object->id;
1901 if (isset($object->table_element)) {
1902 $ecmfile->src_object_type = $object->table_element;
1904 dol_syslog(
'Error: object ' . get_class($object) .
' has no table_element attribute.');
1907 if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description;
1908 if (isset($object->src_object_keywords)) $ecmfile->keywords = $object->src_object_keywords;
1911 if (!empty($conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE)) {
1916 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1920 $result = $ecmfile->create($user);
1939 global $conf, $db, $user;
1944 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
1950 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
1952 $filename = basename($file);
1953 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1954 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1957 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
1958 $sql .=
' WHERE entity = '.$conf->entity;
1959 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
1961 $sql .=
" AND filename = '".$db->escape($file).
"'";
1964 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
1967 $resql = $db->query($sql);
1970 dol_syslog(__METHOD__.
' '.$db->lasterror(), LOG_ERR);
1999 if (class_exists(
'Imagick')) {
2000 $image =
new Imagick();
2002 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
2004 $ret = $image->readImage($filetoconvert);
2006 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
2007 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);
2011 $ret = $image->setImageFormat($ext);
2013 if (empty($fileoutput)) {
2014 $fileoutput = $fileinput.
".".$ext;
2017 $count = $image->getNumberImages();
2019 if (!
dol_is_file($fileoutput) || is_writeable($fileoutput)) {
2021 $ret = $image->writeImages($fileoutput,
true);
2026 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2056 function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring =
null)
2063 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2066 if ($mode ==
'gz') {
2068 $compressdata = gzencode($data, 9);
2069 } elseif ($mode ==
'bz') {
2071 $compressdata = bzcompress($data, 9);
2072 } elseif ($mode ==
'zstd') {
2074 $compressdata = zstd_compress($data, 9);
2075 } elseif ($mode ==
'zip') {
2076 if (class_exists(
'ZipArchive') && !empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS)) {
2079 $rootPath = realpath($inputfile);
2081 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2082 $zip =
new ZipArchive;
2084 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2085 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2089 $errormsg = $errorstring;
2096 $files =
new RecursiveIteratorIterator(
2097 new RecursiveDirectoryIterator($rootPath),
2098 RecursiveIteratorIterator::LEAVES_ONLY
2101 foreach ($files as $name => $file) {
2103 if (!$file->isDir()) {
2105 $filePath = $file->getPath();
2106 $fileName = $file->getFilename();
2107 $fileFullRealPath = $file->getRealPath();
2110 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2113 $zip->addFile($fileFullRealPath, $relativePath);
2120 dol_syslog(
"dol_compress_file success - ".count($zip->numFiles).
" files");
2124 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2127 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2128 $archive =
new PclZip($outputfile);
2129 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2131 if ($result === 0) {
2133 $errormsg = $archive->errorInfo(
true);
2135 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2136 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2137 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2141 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2142 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2145 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2151 if ($foundhandler) {
2152 $fp = fopen($outputfile,
"w");
2153 fwrite($fp, $compressdata);
2157 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2161 $errormsg = $errorstring;
2165 global $langs, $errormsg;
2166 $langs->load(
"errors");
2167 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2169 $errorstring =
"Failed to open file ".$outputfile;
2185 global $conf, $langs, $db;
2187 $fileinfo = pathinfo($inputfile);
2188 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2190 if ($fileinfo[
"extension"] ==
"zip") {
2191 if (defined(
'ODTPHP_PATHTOPCLZIP') && empty($conf->global->MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS)) {
2192 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2193 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2194 $archive =
new PclZip($inputfile);
2200 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2202 if (!is_array($result) && $result <= 0) {
2203 return array(
'error'=>$archive->errorInfo(
true));
2208 foreach ($result as $key => $val) {
2209 if ($val[
'status'] ==
'path_creation_fail') {
2210 $langs->load(
"errors");
2212 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2220 return array(
'error'=>$errmsg);
2225 if (class_exists(
'ZipArchive')) {
2226 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2227 $zip =
new ZipArchive;
2228 $res = $zip->open($inputfile);
2229 if ($res ===
true) {
2235 for ($i = 0; $i < $zip->numFiles; $i++) {
2236 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2237 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2240 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2246 return array(
'error'=>
'ErrUnzipFails');
2250 return array(
'error'=>
'ErrNoZipEngine');
2251 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2252 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2253 $utils =
new Utils($db);
2260 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2261 if ($extension ==
"tar") {
2264 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2265 if ($resarray[
"result"] != 0) {
2266 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2270 if ($fileinfo[
"extension"] ==
"gz") {
2272 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2274 } elseif ($fileinfo[
"extension"] ==
"zst") {
2277 return array(
'error'=>
'ErrorBadFileExtension');
2280 $cmd .=
' > '.$outputfilename;
2282 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0,
null, 1, $outputfilename.
'.err');
2283 if ($resarray[
"result"] != 0) {
2284 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2285 if ($errfilecontent) {
2286 $resarray[
"error"] .=
" - ".$errfilecontent;
2290 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2293 return array(
'error'=>
'ErrorBadFileExtension');
2309 function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'', $newmask = 0)
2315 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2317 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2318 global $langs, $errormsg;
2319 $langs->load(
"errors");
2320 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2325 if ($mode ==
'gz') {
2327 } elseif ($mode ==
'bz') {
2329 } elseif ($mode ==
'zip') {
2343 if (class_exists(
'ZipArchive')) {
2347 $zip =
new ZipArchive();
2348 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2350 global $langs, $errormsg;
2351 $langs->load(
"errors");
2352 $errormsg = $langs->trans(
"ErrorFailedToWriteInFile", $outputfile);
2359 $files =
new RecursiveIteratorIterator(
2360 new RecursiveDirectoryIterator($inputdir),
2361 RecursiveIteratorIterator::LEAVES_ONLY
2365 foreach ($files as $name => $file) {
2367 if (!$file->isDir()) {
2369 $filePath = $file->getPath();
2370 $fileName = $file->getFilename();
2371 $fileFullRealPath = $file->getRealPath();
2374 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2377 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2379 $zip->addFile($fileFullRealPath, $relativePath);
2387 if (empty($newmask) && !empty($conf->global->MAIN_UMASK)) {
2388 $newmask = $conf->global->MAIN_UMASK;
2390 if (empty($newmask)) {
2391 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
2395 @chmod($outputfile, octdec($newmask));
2401 if (!$foundhandler) {
2402 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2408 global $langs, $errormsg;
2409 $langs->load(
"errors");
2410 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2412 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile).
' - '.$e->getMessage();
2429 function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook =
false, $mode =
'')
2431 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2432 return isset($tmparray[0])?$tmparray[0]:
null;
2450 global $conf, $db, $user, $hookmanager;
2451 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2454 if (!is_object($fuser)) {
2458 if (empty($modulepart)) {
2459 return 'ErrorBadParameter';
2461 if (empty($entity)) {
2469 if ($modulepart ==
'users') {
2470 $modulepart =
'user';
2472 if ($modulepart ==
'tva') {
2473 $modulepart =
'tax-vat';
2477 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2481 $sqlprotectagainstexternals =
'';
2485 if (empty($refname)) {
2486 $refname = basename(dirname($original_file).
"/");
2487 if ($refname ==
'thumbs' || $refname ==
'temp') {
2489 $refname = basename(dirname(dirname($original_file)).
"/");
2496 $download =
'download';
2497 if ($mode ==
'write') {
2500 $download =
'upload';
2504 if ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2505 if (empty($entity) || empty($conf->medias->multidir_output[$entity])) {
2506 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2509 $original_file = $conf->medias->multidir_output[$entity].
'/'.$original_file;
2510 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2512 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
2513 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2514 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2516 $accessallowed = $user->admin;
2517 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2518 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2520 $accessallowed = ($fuser->rights->website->write && preg_match(
'/\.jpg$/i', basename($original_file)));
2521 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2522 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2525 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2528 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2529 $original_file = $dirins.
'/'.$original_file;
2530 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
2533 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
2534 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
2537 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2540 $original_file = $conf->user->dir_output.
'/'.$original_file;
2541 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
2544 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
2545 } elseif ($modulepart ==
'memberphoto' && !empty($conf->adherent->dir_output)) {
2548 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2551 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
2552 } elseif ($modulepart ==
'apercufacture' && !empty($conf->facture->multidir_output[$entity])) {
2554 if ($fuser->hasRight(
'facture', $lire)) {
2557 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2558 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
2560 if ($fuser->hasRight(
'propal', $lire)) {
2563 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2564 } elseif ($modulepart ==
'apercucommande' && !empty($conf->commande->multidir_output[$entity])) {
2566 if ($fuser->hasRight(
'commande', $lire)) {
2569 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2570 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->dir_output)) {
2572 if ($fuser->hasRight(
'ficheinter', $lire)) {
2575 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2576 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contrat->multidir_output[$entity])) {
2578 if ($fuser->hasRight(
'contrat', $lire)) {
2581 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2582 } elseif (($modulepart ==
'apercusupplier_proposal' || $modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
2584 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
2587 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
2588 } elseif (($modulepart ==
'apercusupplier_order' || $modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
2590 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2593 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2594 } elseif (($modulepart ==
'apercusupplier_invoice' || $modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
2596 if ($fuser->hasRight(
'fournisseur', $lire)) {
2599 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2600 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
2601 if ($fuser->hasRight(
'holiday', $read) || !empty($fuser->rights->holiday->readall) || preg_match(
'/^specimen/i', $original_file)) {
2604 if ($refname && empty($fuser->rights->holiday->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2605 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
2606 $tmpholiday =
new Holiday($db);
2607 $tmpholiday->fetch(
'', $refname);
2608 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
2611 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
2612 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
2613 if ($fuser->hasRight(
'expensereport', $lire) || !empty($fuser->rights->expensereport->readall) || preg_match(
'/^specimen/i', $original_file)) {
2616 if ($refname && empty($fuser->rights->expensereport->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2617 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
2619 $tmpexpensereport->fetch(
'', $refname);
2620 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
2623 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2624 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
2626 if ($fuser->hasRight(
'expensereport', $lire)) {
2629 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2630 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
2632 if ($fuser->hasRight(
'propal', $lire)) {
2635 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
2636 } elseif ($modulepart ==
'orderstats' && !empty($conf->commande->dir_temp)) {
2638 if ($fuser->hasRight(
'commande', $lire)) {
2641 $original_file = $conf->commande->dir_temp.
'/'.$original_file;
2642 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2643 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2646 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
2647 } elseif ($modulepart ==
'billstats' && !empty($conf->facture->dir_temp)) {
2649 if ($fuser->hasRight(
'facture', $lire)) {
2652 $original_file = $conf->facture->dir_temp.
'/'.$original_file;
2653 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2654 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
2657 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
2658 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
2660 if ($fuser->hasRight(
'expedition', $lire)) {
2663 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
2664 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
2666 if ($fuser->hasRight(
'deplacement', $lire)) {
2669 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
2670 } elseif ($modulepart ==
'memberstats' && !empty($conf->adherent->dir_temp)) {
2672 if ($fuser->hasRight(
'adherent', $lire)) {
2675 $original_file = $conf->adherent->dir_temp.
'/'.$original_file;
2676 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
2678 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
2681 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
2682 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
2684 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
2687 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
2688 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
2689 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2691 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
2694 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2695 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2697 $tmpobject->fetch((
int) $refname);
2698 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
2699 if ($user->socid && $tmpobject->socid) {
2704 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2705 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
2707 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
2708 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2710 if ($fuser->rights->categorie->{$lire} || $fuser->rights->takepos->run) {
2713 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
2714 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
2716 if ($fuser->rights->prelevement->bons->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2719 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
2720 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
2723 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
2724 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
2727 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
2728 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
2731 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
2732 } elseif ($modulepart ==
'barcode') {
2737 $original_file =
'';
2738 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
2741 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
2742 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
2745 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
2746 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
2749 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
2750 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
2752 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2753 if ($fuser->id == (
int) $refname) {
2756 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
2759 $original_file = $conf->user->dir_output.
'/'.$original_file;
2760 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
2762 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2763 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2765 if ($fuser->rights->societe->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2768 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
2769 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
2770 } elseif ($modulepart ==
'contact' && !empty($conf->societe->multidir_output[$entity])) {
2772 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2773 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2775 if ($fuser->hasRight(
'societe', $lire)) {
2778 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
2779 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->facture->multidir_output[$entity])) {
2781 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2784 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2785 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
2786 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
2788 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2791 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2792 } elseif ($modulepart ==
'massfilesarea_orders') {
2793 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2796 $original_file = $conf->commande->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2797 } elseif ($modulepart ==
'massfilesarea_sendings') {
2798 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2801 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
2802 } elseif ($modulepart ==
'massfilesarea_invoices') {
2803 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2806 $original_file = $conf->facture->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2807 } elseif ($modulepart ==
'massfilesarea_expensereport') {
2808 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2811 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2812 } elseif ($modulepart ==
'massfilesarea_interventions') {
2813 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2816 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2817 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
2818 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2821 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2822 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
2823 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2826 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2827 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
2828 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2831 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2832 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contrat->dir_output)) {
2833 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2836 $original_file = $conf->contrat->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2837 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->dir_output)) {
2839 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2842 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2843 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2844 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
2846 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2849 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
2851 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset($conf->propal->multidir_output[$entity])) {
2853 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2856 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2857 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
2858 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->commande->multidir_output[$entity])) {
2860 if ($fuser->rights->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2863 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2864 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
2865 } elseif ($modulepart ==
'project' && !empty($conf->project->multidir_output[$entity])) {
2867 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2870 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2871 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
2872 $tmpproject =
new Project($db);
2873 $tmpproject->fetch(
'', $refname);
2874 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
2877 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
2878 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
2879 } elseif ($modulepart ==
'project_task' && !empty($conf->project->multidir_output[$entity])) {
2880 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2883 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2884 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
2885 $tmptask =
new Task($db);
2886 $tmptask->fetch(
'', $refname);
2887 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
2890 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
2891 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
2892 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
2894 if ($fuser->rights->fournisseur->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2897 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2898 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2899 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
2901 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2904 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2905 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2906 } elseif ($modulepart ==
'supplier_payment') {
2908 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2911 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
2912 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2913 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->facture->dir_output)) {
2915 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2918 if ($fuser->socid > 0) {
2919 $original_file = $conf->facture->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
2921 $original_file = $conf->facture->dir_output.
'/payments/'.$original_file;
2923 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
2925 if ($fuser->rights->accounting->bind->write || preg_match(
'/^specimen/i', $original_file)) {
2928 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
2929 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty($conf->expedition->dir_output)) {
2931 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2934 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
2936 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
2938 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2941 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
2942 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2944 if ($fuser->hasRight(
'agenda',
'myactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
2947 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2948 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
2950 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
2953 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
2954 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
2956 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
2957 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2959 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
2963 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
2965 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
2967 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
2969 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
2970 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2972 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
2976 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
2978 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
2980 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
2981 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2983 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
2987 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
2989 } elseif ($modulepart ==
'contract' && !empty($conf->contrat->multidir_output[$entity])) {
2991 if ($fuser->rights->contrat->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2994 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2995 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
2996 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
2998 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3001 $original_file = $conf->don->dir_output.
'/'.$original_file;
3002 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
3004 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3007 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3008 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3010 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3014 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3015 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3017 if ($fuser->hasRight(
'banque', $lire)) {
3020 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3021 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3024 $accessallowed = $user->rights->export->lire;
3025 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3026 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3028 $accessallowed = $user->rights->import->run;
3029 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3030 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3032 $accessallowed = $user->rights->recruitment->recruitmentjobposition->read;
3033 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3034 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3037 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3038 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3040 if ($fuser->admin) {
3043 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3044 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3046 if ($fuser->admin) {
3049 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3050 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3054 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3057 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3058 } elseif ($modulepart ==
'member' && !empty($conf->adherent->dir_output)) {
3060 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3063 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
3064 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3067 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3077 if (preg_match(
'/^specimen/i', $original_file)) {
3080 if ($fuser->admin) {
3084 $tmpmodulepart = explode(
'-', $modulepart);
3085 if (!empty($tmpmodulepart[1])) {
3086 $modulepart = $tmpmodulepart[0];
3087 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3092 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3093 if (empty($conf->{$reg[1]}->dir_temp)) {
3094 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3097 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3100 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3101 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3102 if (empty($conf->{$reg[1]}->dir_temp)) {
3103 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3106 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3109 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$original_file;
3110 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3111 if (empty($conf->{$reg[1]}->dir_output)) {
3112 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3115 if ($fuser->rights->{$reg[1]}->{$lire} || $fuser->rights->{$reg[1]}->{$read} || ($fuser->rights->{$reg[1]}->{$download})) {
3118 $original_file = $conf->{$reg[1]}->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3119 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3120 if (empty($conf->{$reg[1]}->dir_output)) {
3121 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3124 if ($fuser->rights->{$reg[1]}->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3127 $original_file = $conf->{$reg[1]}->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3129 if (empty($conf->$modulepart->dir_output)) {
3130 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.');
3135 $partsofdirinoriginalfile = explode(
'/', $original_file);
3136 if (!empty($partsofdirinoriginalfile[1])) {
3137 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3138 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3142 if (!empty($fuser->rights->$modulepart->{$lire}) || !empty($fuser->rights->$modulepart->{$read})) {
3146 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3147 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3149 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3153 $parameters = array(
3154 'modulepart' => $modulepart,
3155 'original_file' => $original_file,
3156 'entity' => $entity,
3161 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters, $object);
3163 if (!empty($hookmanager->resArray[
'original_file'])) {
3164 $original_file = $hookmanager->resArray[
'original_file'];
3166 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3167 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3169 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3170 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3176 'accessallowed' => ($accessallowed ? 1 : 0),
3177 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3178 'original_file' => $original_file
3197 $cachefile = $directory.$filename;
3198 file_put_contents($cachefile, serialize($object), LOCK_EX);
3199 @chmod($cachefile, 0644);
3213 $cachefile = $directory.$filename;
3214 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3227 $cachefile = $directory.$filename;
3228 $object = unserialize(file_get_contents($cachefile));
3240 return preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'\//',
'', $pathfile);
3255 function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3259 $exclude =
'install';
3261 foreach ($dir->md5file as $file) {
3262 $filename = $path.$file[
'name'];
3263 $file_list[
'insignature'][] = $filename;
3264 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3265 $expectedmd5 = (string) $file;
3269 if (!file_exists($pathref.
'/'.$filename)) {
3270 $file_list[
'missing'][] = array(
'filename'=>$filename,
'expectedmd5'=>$expectedmd5,
'expectedsize'=>$expectedsize);
3272 $md5_local = md5_file($pathref.
'/'.$filename);
3274 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3275 $checksumconcat[] = $expectedmd5;
3277 if ($md5_local != $expectedmd5) {
3278 $file_list[
'updated'][] = array(
'filename'=>$filename,
'expectedmd5'=>$expectedmd5,
'expectedsize'=>$expectedsize,
'md5'=>(
string) $md5_local);
3280 $checksumconcat[] = $md5_local;
3285 foreach ($dir->dir as $subdir) {
3286 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.
dirbasename($pathfile)
Return the relative dirname (relative to DOL_DATA_ROOT) of a full path string.
dol_is_link($pathoffile)
Return if path is a symbolic link.
dol_compare_file($a, $b)
Fast compare of 2 files identified by their properties ->name, ->date and ->size.
dol_meta_create($object)
Create a meta file with document file into same directory.
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).
getDefaultImageSizes()
Return default values for image sizes.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
checkUserAccessToObject($user, array $featuresarray, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='', $dbt_select='rowid', $parenttableforentity='')
Check that access by a given user to an object is ok.