40 return preg_replace(
'/^.*\/([^\/]+)$/',
'$1', rtrim($pathfile,
'/'));
63function dol_dir_list($utf8_path, $types =
"all", $recursive = 0, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0, $nohook = 0, $relativename =
"", $donotfollowsymlinks = 0, $nbsecondsold = 0)
65 global $db, $hookmanager;
68 if ($recursive <= 1) {
73 $exclude_array = ($excludefilter ===
null || $excludefilter ===
'') ? array() : (is_array($excludefilter) ? $excludefilter : array($excludefilter));
74 foreach ((array($filter) + $exclude_array) as $f) {
76 if ((
int) preg_match(
'/(?:^|[^\\\\])\//', $f) > 0) {
78 $error_info .=
" error='$f unescaped_slash'";
82 dol_syslog(
"files.lib.php::dol_dir_list path=".$utf8_path.
" types=".$types.
" recursive=".$recursive.
" filter=".$filter.
" excludefilter=".json_encode($excludefilter).$error_info);
90 $exclude_array = ($excludefilter ===
null || $excludefilter ===
'') ? array() : (is_array($excludefilter) ? $excludefilter : array($excludefilter));
94 $excludefilterarray = array_merge(array(
'^\.'), $exclude_array);
96 $loaddate = ($mode == 1 || $mode == 2 || $nbsecondsold != 0 || $sortcriteria ==
'date');
97 $loadsize = ($mode == 1 || $mode == 3 || $sortcriteria ==
'size');
98 $loadperm = ($mode == 1 || $mode == 4 || $sortcriteria ==
'perm');
101 $utf8_path = preg_replace(
'/([\\/]+)$/',
'', $utf8_path);
106 $file_list = array();
108 if (!$nohook && $hookmanager instanceof
HookManager) {
109 $hookmanager->resArray = array();
111 $hookmanager->initHooks(array(
'fileslib'));
116 'recursive' => $recursive,
118 'excludefilter' => $exclude_array,
119 'sortcriteria' => $sortcriteria,
120 'sortorder' => $sortorder,
121 'loaddate' => $loaddate,
122 'loadsize' => $loadsize,
125 $reshook = $hookmanager->executeHooks(
'getDirList', $parameters,
$object);
129 if (empty($reshook)) {
130 if (!is_dir($os_path)) {
134 if (($dir = opendir($os_path)) ===
false) {
141 while (
false !== ($os_file = readdir($dir))) {
142 $os_fullpathfile = ($os_path ? $os_path.
'/' :
'').$os_file;
145 $utf8_file = mb_convert_encoding($os_file,
'UTF-8',
'ISO-8859-1');
147 $utf8_file = $os_file;
152 $utf8_fullpathfile =
"$utf8_path/$utf8_file";
155 foreach ($excludefilterarray as $filt) {
156 if (preg_match(
'/'.$filt.
'/i', $utf8_file) || preg_match(
'/'.$filt.
'/i', $utf8_fullpathfile)) {
164 $isdir = is_dir($os_fullpathfile);
168 if (($types ==
"directories") || ($types ==
"all")) {
169 if ($loaddate || $sortcriteria ==
'date') {
172 if ($loadsize || $sortcriteria ==
'size') {
175 if ($loadperm || $sortcriteria ==
'perm') {
179 if (!$filter || preg_match(
'/'.$filter.
'/i', $utf8_file)) {
181 preg_match(
'/([^\/]+)\/[^\/]+$/', $utf8_fullpathfile, $reg);
182 $level1name = (isset($reg[1]) ? $reg[1] :
'');
183 $file_list[] = array(
184 "name" => $utf8_file,
185 "path" => $utf8_path,
186 "level1name" => $level1name,
187 "relativename" => ($relativename ? $relativename.
'/' :
'').$utf8_file,
188 "fullname" => $utf8_fullpathfile,
198 if ($recursive > 0) {
199 if (empty($donotfollowsymlinks) || !is_link($os_fullpathfile)) {
201 $file_list = array_merge($file_list,
dol_dir_list($utf8_fullpathfile, $types, $recursive + 1, $filter, $exclude_array, $sortcriteria, $sortorder, $mode, $nohook, ($relativename !=
'' ? $relativename.
'/' :
'').$utf8_file, $donotfollowsymlinks, $nbsecondsold));
204 } elseif (in_array($types, array(
"files",
"all"))) {
206 if ($loaddate || $sortcriteria ==
'date') {
209 if ($loadsize || $sortcriteria ==
'size') {
213 if (!$filter || preg_match(
'/'.$filter.
'/i', $utf8_file)) {
214 if (empty($nbsecondsold) || $filedate <= ($now - $nbsecondsold)) {
215 preg_match(
'/([^\/]+)\/[^\/]+$/', $utf8_fullpathfile, $reg);
216 $level1name = (isset($reg[1]) ? $reg[1] :
'');
217 $file_list[] = array(
218 "name" => $utf8_file,
219 "path" => $utf8_path,
220 "level1name" => $level1name,
221 "relativename" => ($relativename ? $relativename.
'/' :
'').$utf8_file,
222 "fullname" => $utf8_fullpathfile,
235 if (!empty($sortcriteria) && $sortorder) {
236 $file_list =
dol_sort_array($file_list, $sortcriteria, ($sortorder == SORT_ASC ?
'asc' :
'desc'));
241 if ($hookmanager instanceof
HookManager && is_array($hookmanager->resArray)) {
242 $file_list = array_merge($file_list, $hookmanager->resArray);
265function dol_dir_list_in_database($path, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0, $sqlfilters =
"",
$object =
null)
273 $sql =
" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams,";
274 $sql .=
" date_c, tms as date_m, fk_user_c, fk_user_m, acl, position, share";
276 $sql .=
", description";
278 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_files";
280 $sql .=
" WHERE entity = ".((int)
$object->entity);
282 $sql .=
" WHERE entity = ".((int)
$conf->entity);
284 if (preg_match(
'/%$/', $path)) {
285 $sql .=
" AND (filepath LIKE '".$db->escape($path).
"' OR filepath = '".$db->escape(preg_replace(
'/\/%$/',
'', $path)).
"')";
287 $sql .=
" AND filepath = '".$db->escape($path).
"'";
298 $resql = $db->query($sql);
300 $file_list = array();
301 $num = $db->num_rows($resql);
304 $obj = $db->fetch_object($resql);
307 preg_match(
'/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename, $reg);
308 $level1name = (isset($reg[1]) ? $reg[1] :
'');
309 $file_list[] = array(
310 "rowid" => $obj->rowid,
311 "label" => $obj->label,
312 "name" => $obj->filename,
313 "path" => DOL_DATA_ROOT.
'/'.$obj->filepath,
314 "level1name" => $level1name,
315 "fullname" => DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename,
316 "fullpath_orig" => $obj->fullpath_orig,
317 "date_c" => $db->jdate($obj->date_c),
318 "date_m" => $db->jdate($obj->date_m),
320 "keywords" => $obj->keywords,
321 "cover" => $obj->cover,
322 "position" => (
int) $obj->position,
324 "share" => $obj->share,
325 "description" => ($mode ? $obj->description :
'')
332 if (!empty($sortcriteria)) {
334 foreach ($file_list as $key => $row) {
335 $myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] :
'');
339 array_multisort($myarray, $sortorder, SORT_REGULAR, $file_list);
362 global
$conf, $db, $user;
372 if ($modulepart ==
'produit' &&
getDolGlobalInt(
'PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
375 if (isModEnabled(
"product")) {
376 $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";
378 $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";
381 $relativedirold = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dirold);
382 $relativedirold = preg_replace(
'/^[\\/]/',
'', $relativedirold);
384 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($relativedirold,
'',
null,
'name', SORT_ASC));
386 } elseif ($modulepart ==
'ticket') {
387 foreach ($filearray as $key => $val) {
388 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'path']);
389 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
390 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
391 if ($rel_dir != $relativedir) {
392 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($rel_dir,
'',
null,
'name', SORT_ASC));
402 foreach ($filearray as $key => $val) {
403 $tmpfilename = preg_replace(
'/\.noexe$/',
'', $filearray[$key][
'name']);
406 foreach ($filearrayindatabase as $key2 => $val2) {
407 if (($filearrayindatabase[$key2][
'path'] == $filearray[$key][
'path']) && ($filearrayindatabase[$key2][
'name'] == $tmpfilename)) {
408 $filearray[$key][
'position_name'] = ($filearrayindatabase[$key2][
'position'] ? $filearrayindatabase[$key2][
'position'] :
'0').
'_'.$filearrayindatabase[$key2][
'name'];
409 $filearray[$key][
'position'] = $filearrayindatabase[$key2][
'position'];
410 $filearray[$key][
'cover'] = $filearrayindatabase[$key2][
'cover'];
411 $filearray[$key][
'keywords'] = $filearrayindatabase[$key2][
'keywords'];
412 $filearray[$key][
'acl'] = $filearrayindatabase[$key2][
'acl'];
413 $filearray[$key][
'rowid'] = $filearrayindatabase[$key2][
'rowid'];
414 $filearray[$key][
'label'] = $filearrayindatabase[$key2][
'label'];
415 $filearray[$key][
'share'] = $filearrayindatabase[$key2][
'share'];
422 $filearray[$key][
'position'] =
'999999';
423 $filearray[$key][
'cover'] = 0;
424 $filearray[$key][
'acl'] =
'';
425 $filearray[$key][
'share'] = 0;
427 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'fullname']);
429 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filename)) {
430 dol_syslog(
"list_of_documents We found a file called '".$filearray[$key][
'name'].
"' not indexed into database. We add it");
431 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
435 $filename = basename($rel_filename);
436 $rel_dir = dirname($rel_filename);
437 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
438 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
440 $ecmfile->filepath = $rel_dir;
441 $ecmfile->filename = $filename;
442 $ecmfile->label = md5_file(
dol_osencode($filearray[$key][
'fullname']));
443 $ecmfile->fullpath_orig = $filearray[$key][
'fullname'];
444 $ecmfile->gen_or_uploaded =
'unknown';
445 $ecmfile->description =
'';
446 $ecmfile->keywords =
'';
447 $result = $ecmfile->create($user);
451 $filearray[$key][
'rowid'] = $result;
454 $filearray[$key][
'rowid'] = 0;
471 global $sortorder, $sortfield;
473 $sortorder = strtoupper($sortorder);
475 if ($sortorder ==
'ASC') {
483 if ($sortfield ==
'name') {
484 if ($a->name == $b->name) {
487 return ($a->name < $b->name) ? $retup : $retdown;
489 if ($sortfield ==
'date') {
490 if ($a->date == $b->date) {
493 return ($a->date < $b->date) ? $retup : $retdown;
495 if ($sortfield ==
'size') {
496 if ($a->size == $b->size) {
499 return ($a->size < $b->size) ? $retup : $retdown;
515 if (is_dir($newfolder)) {
530 if (!is_readable($dir)) {
533 return (count(scandir($dir)) == 2);
545 return is_file($newpathoffile);
557 return is_link($newpathoffile);
569 return is_writable($newfolderorfile);
582 $prots = array(
'file',
'http',
'https',
'ftp',
'zlib',
'data',
'ssh',
'ssh2',
'ogg',
'expect');
583 return false !== preg_match(
'/^('.implode(
'|', $prots).
'):/i', $uri);
595 if (is_dir($newfolder)) {
596 $handle = opendir($newfolder);
597 $folder_content =
'';
599 while ((gettype($name = readdir($handle)) !=
"boolean")) {
600 $name_array[] = $name;
602 foreach ($name_array as $temp) {
603 $folder_content .= $temp;
608 if ($folder_content ==
"...") {
631 $fp = fopen($newfile,
'r');
638 if ($line !==
false) {
661 return filesize($newpathoffile);
673 return @filemtime($newpathoffile);
685 return fileperms($newpathoffile);
700function dolReplaceInFile($srcfile, $arrayreplacement, $destfile =
'', $newmask =
'0', $indexdatabase = 0, $arrayreplacementisregex = 0)
702 dol_syslog(
"files.lib.php::dolReplaceInFile srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" indexdatabase=".$indexdatabase.
" arrayreplacementisregex=".$arrayreplacementisregex);
704 if (empty($srcfile)) {
707 if (empty($destfile)) {
708 $destfile = $srcfile;
712 $srcfile = preg_replace(
'/\.\.\/?/',
'', $srcfile);
713 $destfile = preg_replace(
'/\.\.\/?/',
'', $destfile);
716 if (($destfile != $srcfile) && $destexists) {
722 dol_syslog(
"files.lib.php::dolReplaceInFile failed to read src file", LOG_WARNING);
726 $tmpdestfile = $destfile.
'.tmp';
731 $newdirdestfile = dirname($newpathofdestfile);
733 if ($destexists && !is_writable($newpathofdestfile)) {
734 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
737 if (!is_writable($newdirdestfile)) {
738 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
745 $content = file_get_contents($newpathofsrcfile);
747 if (empty($arrayreplacementisregex)) {
750 foreach ($arrayreplacement as $key => $value) {
751 $content = preg_replace($key, $value, $content);
755 file_put_contents($newpathoftmpdestfile, $content);
756 dolChmod($newpathoftmpdestfile, $newmask);
759 $result =
dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
761 dol_syslog(
"files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
767 if (empty($newmask)) {
768 dol_syslog(
"Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
772 dolChmod($newpathofdestfile, $newmask);
790function dol_copy($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 0)
794 dol_syslog(
"files.lib.php::dol_copy srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
796 if (empty($srcfile) || empty($destfile)) {
801 if (!$overwriteifexists && $destexists) {
807 $newdirdestfile = dirname($newpathofdestfile);
809 if ($destexists && !is_writable($newpathofdestfile)) {
810 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
813 if (!is_writable($newdirdestfile)) {
814 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
819 $testvirusarray = array();
822 if (count($testvirusarray)) {
823 dol_syslog(
"files.lib.php::dol_copy canceled because a virus was found into source file. we ignore the copy request.", LOG_WARNING);
829 $result = @copy($newpathofsrcfile, $newpathofdestfile);
832 dol_syslog(
"files.lib.php::dol_copy failed to copy", LOG_WARNING);
838 if (empty($newmask)) {
839 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
843 dolChmod($newpathofdestfile, $newmask);
845 if ($result && $indexdatabase) {
847 $rel_filetocopyafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $newpathofdestfile);
848 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetocopyafter)) {
849 $rel_filetocopyafter = preg_replace(
'/^[\\/]/',
'', $rel_filetocopyafter);
852 dol_syslog(
"Try to copy also entries in database for: ".$rel_filetocopyafter, LOG_DEBUG);
853 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
856 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetocopyafter);
857 if ($resultecmtarget > 0) {
858 dol_syslog(
"ECM dest file found, remove it", LOG_DEBUG);
859 $ecmfiletarget->delete($user);
861 dol_syslog(
"ECM dest file not found, create it", LOG_DEBUG);
865 $resultecm = $ecmSrcfile->fetch(0,
'', $srcfile);
869 dol_syslog(
"Fetch src file error", LOG_DEBUG);
873 $filename = basename($rel_filetocopyafter);
874 $rel_dir = dirname($rel_filetocopyafter);
875 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
876 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
878 $ecmfile->filepath = $rel_dir;
879 $ecmfile->filename = $filename;
881 $ecmfile->fullpath_orig = $srcfile;
882 $ecmfile->gen_or_uploaded =
'copy';
883 $ecmfile->description = $ecmSrcfile->description;
884 $ecmfile->keywords = $ecmSrcfile->keywords;
885 $resultecm = $ecmfile->create($user);
886 if ($resultecm < 0) {
890 dol_syslog(
"Create ECM file error", LOG_DEBUG);
894 if ($resultecm > 0) {
902 return (
int) $result;
919function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement =
null, $excludesubdir = 0, $excludefileext =
null, $excludearchivefiles = 0)
923 dol_syslog(
"files.lib.php::dolCopyDir srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
925 if (empty($srcfile) || empty($destfile)) {
936 $dirmaskdec = octdec($newmask);
940 $dirmaskdec |= octdec(
'0200');
942 $result =
dol_mkdir($destfile,
'', decoct($dirmaskdec));
954 if (is_dir($ossrcfile)) {
955 $dir_handle = opendir($ossrcfile);
957 while ($file = readdir($dir_handle)) {
958 if ($file !=
"." && $file !=
".." && !is_link($ossrcfile.
"/".$file)) {
959 if (is_dir($ossrcfile.
"/".$file)) {
960 if (empty($excludesubdir) || ($excludesubdir == 2 && strlen($file) == 2)) {
963 if (is_array($arrayreplacement)) {
964 foreach ($arrayreplacement as $key => $val) {
965 $newfile = str_replace($key, $val, $newfile);
969 $tmpresult =
dolCopyDir($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists, $arrayreplacement, $excludesubdir, $excludefileext, $excludearchivefiles);
974 if (is_array($excludefileext)) {
975 $extension = pathinfo($file, PATHINFO_EXTENSION);
976 if (in_array($extension, $excludefileext)) {
982 if ($excludearchivefiles == 1) {
983 $extension = pathinfo($file, PATHINFO_EXTENSION);
984 if (preg_match(
'/^[v|d]\d+$/', $extension)) {
990 if (is_array($arrayreplacement)) {
991 foreach ($arrayreplacement as $key => $val) {
992 $newfile = str_replace($key, $val, $newfile);
995 $tmpresult =
dol_copy($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists);
998 if ($result > 0 && $tmpresult >= 0) {
1001 $result = $tmpresult;
1008 closedir($dir_handle);
1014 return (
int) $result;
1036function dol_move($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array(), $entity = 0)
1041 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
1046 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
1050 if ($overwriteifexists || !$destexists) {
1055 $testvirusarray = array();
1058 $testvirusarray =
dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
1059 if (count($testvirusarray)) {
1060 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1066 if (count($testvirusarray)) {
1067 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1072 global $dolibarr_main_restrict_os_commands;
1073 if (!empty($dolibarr_main_restrict_os_commands)) {
1074 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1075 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1076 if (in_array(basename($destfile), $arrayofallowedcommand)) {
1079 dol_syslog(
"files.lib.php::dol_move canceled because target filename ".basename($destfile).
" is using a reserved command name. we ignore the move request.", LOG_WARNING);
1084 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1087 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
1090 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1092 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1097 if ($result && $indexdatabase) {
1099 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1100 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1101 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1102 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1103 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1106 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1107 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1109 $ecmfiletarget =
new EcmFiles($db);
1110 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter,
'',
'',
'', 0, $entity);
1111 if ($resultecmtarget > 0) {
1112 $ecmfiletarget->delete($user);
1116 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore,
'',
'',
'', 0, $entity);
1117 if ($resultecm > 0) {
1118 $filename = basename($rel_filetorenameafter);
1119 $rel_dir = dirname($rel_filetorenameafter);
1120 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1121 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1123 $ecmfile->filepath = $rel_dir;
1124 $ecmfile->filename = $filename;
1126 $resultecm = $ecmfile->update($user);
1127 } elseif ($resultecm == 0) {
1128 $filename = basename($rel_filetorenameafter);
1129 $rel_dir = dirname($rel_filetorenameafter);
1130 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1131 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1133 $ecmfile->filepath = $rel_dir;
1134 $ecmfile->filename = $filename;
1136 $ecmfile->fullpath_orig = basename($srcfile);
1137 if (!empty($moreinfo) && !empty($moreinfo[
'gen_or_uploaded'])) {
1138 $ecmfile->gen_or_uploaded = $moreinfo[
'gen_or_uploaded'];
1140 $ecmfile->gen_or_uploaded =
'uploaded';
1142 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1143 $ecmfile->description = $moreinfo[
'description'];
1145 $ecmfile->description =
'';
1147 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1148 $ecmfile->keywords = $moreinfo[
'keywords'];
1150 $ecmfile->keywords =
'';
1152 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1153 $ecmfile->note_private = $moreinfo[
'note_private'];
1155 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1156 $ecmfile->note_public = $moreinfo[
'note_public'];
1158 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1159 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1161 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1162 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1164 if (!empty($moreinfo) && !empty($moreinfo[
'position'])) {
1165 $ecmfile->position = $moreinfo[
'position'];
1167 if (!empty($moreinfo) && !empty($moreinfo[
'cover'])) {
1168 $ecmfile->cover = $moreinfo[
'cover'];
1170 if (! empty($entity)) {
1171 $ecmfile->entity = $entity;
1174 $resultecm = $ecmfile->create($user);
1175 if ($resultecm < 0) {
1178 if (!empty($moreinfo) && !empty($moreinfo[
'array_options']) && is_array($moreinfo[
'array_options'])) {
1179 $ecmfile->array_options = $moreinfo[
'array_options'];
1180 $resultecm = $ecmfile->insertExtraFields();
1181 if ($resultecm < 0) {
1186 } elseif ($resultecm < 0) {
1190 if ($resultecm > 0) {
1198 if (empty($newmask)) {
1205 dolChmod($newpathofdestfile, $newmask);
1221function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase = 1, $renamedircontent = 1)
1225 dol_syslog(
"files.lib.php::dol_move_dir srcdir=".$srcdir.
" destdir=".$destdir.
" overwritifexists=".$overwriteifexists.
" indexdatabase=".$indexdatabase.
" renamedircontent=".$renamedircontent);
1227 $srcbasename = basename($srcdir);
1231 dol_syslog(
"files.lib.php::dol_move_dir srcdir does not exists. Move fails");
1235 if ($overwriteifexists || !$destexists) {
1242 if ($overwriteifexists) {
1243 if (strtoupper(substr(PHP_OS, 0, 3)) ===
'WIN') {
1244 if (is_dir($newpathofdestdir)) {
1245 @rmdir($newpathofdestdir);
1250 $result = @rename($newpathofsrcdir, $newpathofdestdir);
1253 if ($result && $renamedircontent) {
1254 if (file_exists($newpathofdestdir)) {
1255 $destbasename = basename($newpathofdestdir);
1257 if (!empty($files) && is_array($files)) {
1258 foreach ($files as $key => $file) {
1259 if (!file_exists($file[
"fullname"])) {
1262 $filepath = $file[
"path"];
1263 $oldname = $file[
"name"];
1265 $newname = str_replace($srcbasename, $destbasename, $oldname);
1266 if (!empty($newname) && $newname !== $oldname) {
1267 if ($file[
"type"] ==
"dir") {
1268 $res =
dol_move_dir($filepath.
'/'.$oldname, $filepath.
'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent);
1270 $res =
dol_move($filepath.
'/'.$oldname, $filepath.
'/'.$newname,
'0', $overwriteifexists, 0, $indexdatabase);
1297 return trim(basename($filename),
".\x00..\x20");
1313 if (!empty($reterrors)) {
1318 if (!class_exists(
'AntiVir')) {
1319 require_once DOL_DOCUMENT_ROOT.
'/core/class/antivir.class.php';
1322 $result = $antivir->dol_avscan_file($src_file);
1324 $reterrors = $antivir->errors;
1340 if (preg_match(
'/\.pdf$/i', $dest_file)) {
1342 dol_syslog(
"dolCheckOnFileName Check that pdf does not contains js code");
1344 $tmp = file_get_contents(trim($src_file));
1345 if (preg_match(
'/[\n\s]+\/JavaScript[\n\s]+/m', $tmp)) {
1346 return array(
'File is a PDF with javascript inside');
1349 dol_syslog(
"dolCheckOnFileName Check js into pdf disabled");
1377function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles =
'addedfile', $upload_dir =
'')
1383 $file_name = $dest_file;
1386 if (empty($nohook)) {
1387 $reshook = $hookmanager->initHooks(array(
'fileslib'));
1389 $parameters = array(
'dest_file' => $dest_file,
'src_file' => $src_file,
'file_name' => $file_name,
'varfiles' => $varfiles,
'allowoverwrite' => $allowoverwrite);
1390 $reshook = $hookmanager->executeHooks(
'moveUploadedFile', $parameters,
$object);
1393 if (empty($reshook)) {
1395 if ($uploaderrorcode) {
1396 switch ($uploaderrorcode) {
1397 case UPLOAD_ERR_INI_SIZE:
1398 return 'ErrorFileSizeTooLarge';
1399 case UPLOAD_ERR_FORM_SIZE:
1400 return 'ErrorFileSizeTooLarge';
1401 case UPLOAD_ERR_PARTIAL:
1402 return 'ErrorPartialFile';
1403 case UPLOAD_ERR_NO_TMP_DIR:
1404 return 'ErrorNoTmpDir';
1405 case UPLOAD_ERR_CANT_WRITE:
1406 return 'ErrorFailedToWriteInDir';
1407 case UPLOAD_ERR_EXTENSION:
1408 return 'ErrorUploadBlockedByAddon';
1416 if (empty($disablevirusscan) && file_exists($src_file)) {
1418 if (count($checkvirusarray)) {
1419 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.implode(
',', $checkvirusarray), LOG_WARNING);
1420 return 'ErrorFileIsInfectedWithAVirus: '.implode(
',', $checkvirusarray);
1429 $publicmediasdirwithslash =
$conf->medias->multidir_output[
$conf->entity];
1430 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
1431 $publicmediasdirwithslash .=
'/';
1434 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0 || !
getDolGlobalInt(
"MAIN_DOCUMENT_DISABLE_NOEXE_IN_MEDIAS_DIR")) {
1435 $file_name .=
'.noexe';
1442 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
1443 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
1449 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
1450 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
1456 $errmsg = implode(
',', $hookmanager->errors);
1457 if (empty($errmsg)) {
1458 $errmsg =
'ErrorReturnedBySomeHooks';
1461 } elseif (empty($reshook)) {
1467 if (!is_writable(dirname($file_name_osencoded))) {
1468 dol_syslog(
"Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded).
" is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1469 return 'ErrorDirNotWritable';
1473 if (!$allowoverwrite) {
1474 if (file_exists($file_name_osencoded)) {
1475 dol_syslog(
"Files.lib::dol_move_uploaded_file File ".$file_name.
" already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
1476 return 'ErrorFileAlreadyExists';
1479 if (is_dir($file_name_osencoded)) {
1480 dol_syslog(
"Files.lib::dol_move_uploaded_file A directory with name ".$file_name.
" already exists. Return 'ErrorDirWithFileNameAlreadyExists'", LOG_WARNING);
1481 return 'ErrorDirWithFileNameAlreadyExists';
1486 $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1489 dol_syslog(
"Files.lib::dol_move_uploaded_file Success to move ".$src_file.
" to ".$file_name.
" - Umask=" .
getDolGlobalString(
'MAIN_UMASK'), LOG_DEBUG);
1490 return $successcode;
1492 dol_syslog(
"Files.lib::dol_move_uploaded_file Failed to move ".$src_file.
" to ".$file_name, LOG_ERR);
1497 return $successcode;
1515function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0,
$object =
null, $allowdotdot =
false, $indexdatabase = 1, $nolog = 0)
1518 global $hookmanager;
1520 if (empty($nolog)) {
1521 dol_syslog(
"dol_delete_file file=".$file.
" disableglob=".$disableglob.
" nophperrors=".$nophperrors.
" nohook=".$nohook);
1526 if ((!$allowdotdot && preg_match(
'/\.\./', $file)) || preg_match(
'/[<>|]/', $file)) {
1527 dol_syslog(
"Refused to delete file ".$file, LOG_WARNING);
1532 if (empty($nohook) && !empty($hookmanager)) {
1533 $hookmanager->initHooks(array(
'fileslib'));
1535 $parameters = array(
1537 'disableglob' => $disableglob,
1538 'nophperrors' => $nophperrors
1540 $reshook = $hookmanager->executeHooks(
'deleteFile', $parameters,
$object);
1543 if (empty($nohook) && $reshook != 0) {
1551 if (empty($disableglob) && !empty($file_osencoded)) {
1553 $globencoded = str_replace(
'[',
'\[', $file_osencoded);
1554 $globencoded = str_replace(
']',
'\]', $globencoded);
1555 $listofdir = glob($globencoded);
1557 if (!empty($listofdir) && is_array($listofdir)) {
1558 foreach ($listofdir as $filename) {
1560 $ok = @unlink($filename);
1562 $ok = unlink($filename);
1566 if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
1567 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);
1568 dolChmod(dirname($filename), decoct(fileperms(dirname($filename)) | 0200));
1571 $ok = @unlink($filename);
1573 $ok = unlink($filename);
1578 if (empty($nolog)) {
1579 dol_syslog(
"Removed file ".$filename, LOG_DEBUG);
1583 $rel_filetodelete = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filename);
1584 if (!preg_match(
'/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1585 if (is_object($db) && $indexdatabase) {
1586 $rel_filetodelete = preg_replace(
'/^[\\/]/',
'', $rel_filetodelete);
1587 $rel_filetodelete = preg_replace(
'/\.noexe$/',
'', $rel_filetodelete);
1589 dol_syslog(
"Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1590 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1592 $result = $ecmfile->fetch(0,
'', $rel_filetodelete,
'',
'',
'', 0,
$object->entity ?? 0);
1593 if ($result >= 0 && $ecmfile->id > 0) {
1594 $result = $ecmfile->delete($user);
1602 dol_syslog(
"Failed to remove file ".$filename, LOG_WARNING);
1609 dol_syslog(
"No files to delete found", LOG_DEBUG);
1614 $ok = @unlink($file_osencoded);
1616 $ok = unlink($file_osencoded);
1619 if (empty($nolog)) {
1620 dol_syslog(
"Removed file ".$file_osencoded, LOG_DEBUG);
1623 dol_syslog(
"Failed to remove file ".$file_osencoded, LOG_WARNING);
1644 if (preg_match(
'/\.\./', $dir) || preg_match(
'/[<>|]/', $dir)) {
1645 dol_syslog(
"Refused to delete dir ".$dir.
' (contains invalid char sequence)', LOG_WARNING);
1650 return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1666function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0, $indexdatabase = 1, $nolog = 0, $level = 0)
1668 if (empty($nolog) || empty($level)) {
1669 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1671 if ($level > 1000) {
1672 dol_syslog(
"functions.lib:dol_delete_dir_recursive too many depth", LOG_WARNING);
1677 if ($handle = opendir(
"$dir_osencoded")) {
1678 while (
false !== ($item = readdir($handle))) {
1680 $item = mb_convert_encoding($item,
'UTF-8',
'ISO-8859-1');
1683 if ($item !=
"." && $item !=
"..") {
1685 $count =
dol_delete_dir_recursive(
"$dir/$item", $count, $nophperrors, 0, $countdeleted, $indexdatabase, $nolog, ($level + 1));
1687 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0,
null,
false, $indexdatabase, $nolog);
1699 if (empty($onlysub)) {
1724 global $langs,
$conf;
1729 if (
$object->element ==
'order_supplier') {
1730 $dir =
$conf->fournisseur->commande->dir_output;
1731 } elseif (
$object->element ==
'invoice_supplier') {
1732 $dir =
$conf->fournisseur->facture->dir_output;
1733 } elseif (
$object->element ==
'project') {
1734 $dir =
$conf->project->dir_output;
1735 } elseif (
$object->element ==
'shipping') {
1736 $dir =
$conf->expedition->dir_output.
'/sending';
1737 } elseif (
$object->element ==
'delivery') {
1738 $dir =
$conf->expedition->dir_output.
'/receipt';
1739 } elseif (
$object->element ==
'fichinter') {
1740 $dir =
$conf->ficheinter->dir_output;
1742 $dir = empty(
$conf->$element->dir_output) ?
'' :
$conf->$element->dir_output;
1746 $object->error = $langs->trans(
'ErrorObjectNoSupportedByFunction');
1751 $dir = $dir.
"/".$refsan;
1752 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1753 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1754 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1757 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1759 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1763 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1765 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1770 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1772 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1776 $multiple = $filepreviewold.
".";
1777 for ($i = 0; $i < 20; $i++) {
1778 $preview = $multiple.$i;
1780 if (file_exists($preview) && is_writable($preview)) {
1782 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1812 if (
$object->element ==
'order_supplier') {
1813 $dir =
$conf->fournisseur->dir_output.
'/commande';
1814 } elseif (
$object->element ==
'invoice_supplier') {
1815 $dir =
$conf->fournisseur->dir_output.
'/facture';
1816 } elseif (
$object->element ==
'project') {
1817 $dir =
$conf->project->dir_output;
1818 } elseif (
$object->element ==
'shipping') {
1819 $dir =
$conf->expedition->dir_output.
'/sending';
1820 } elseif (
$object->element ==
'delivery') {
1821 $dir =
$conf->expedition->dir_output.
'/receipt';
1822 } elseif (
$object->element ==
'fichinter') {
1823 $dir =
$conf->ficheinter->dir_output;
1825 $dir = empty(
$conf->$element->dir_output) ?
'' :
$conf->$element->dir_output;
1832 $dir = $dir.
"/".$objectref;
1833 $file = $dir.
"/".$objectref.
".meta";
1835 if (!is_dir($dir)) {
1842 $nblines = count(
$object->lines);
1847 $meta =
"REFERENCE=\"".$object->ref.
"\"
1849 NB_ITEMS=\"" . $nblines.
"\"
1850 CLIENT=\"" . $client.
"\"
1851 AMOUNT_EXCL_TAX=\"" .
$object->total_ht.
"\"
1852 AMOUNT=\"" .
$object->total_ttc.
"\"\n";
1854 for ($i = 0; $i < $nblines; $i++) {
1856 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".
$object->lines[$i]->qty.
"\"
1857 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".
$object->lines[$i]->total_ht.
"\"
1858 ITEM_" . $i.
"_VAT=\"".
$object->lines[$i]->tva_tx.
"\"
1859 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br(
$object->lines[$i]->desc)).
"\"
1864 $fp = fopen($file,
"w");
1872 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.
$object->element, LOG_WARNING);
1890 $listofpaths = array();
1891 $listofnames = array();
1892 $listofmimes = array();
1896 foreach ($listoffiles as $key => $val) {
1897 $listofpaths[] = $val[
'fullname'];
1898 $listofnames[] = $val[
'name'];
1902 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1903 $_SESSION[
"listofpaths".$keytoavoidconflict] = implode(
';', $listofpaths);
1904 $_SESSION[
"listofnames".$keytoavoidconflict] = implode(
';', $listofnames);
1905 $_SESSION[
"listofmimes".$keytoavoidconflict] = implode(
';', $listofmimes);
1927function dol_add_file_process($upload_dir, $allowoverwrite = 0, $updatesessionordb = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1,
$object =
null, $forceFullTextIndexation =
'')
1929 global $db, $user,
$conf, $langs;
1933 if (!empty($_FILES[$varfiles])) {
1934 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' updatesessionordb='.$updatesessionordb.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1935 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
1936 if (is_array($_FILES[$varfiles][
"name"]) && count($_FILES[$varfiles][
"name"]) > $maxfilesinform) {
1937 $langs->load(
"errors");
1938 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
1946 $TFile = $_FILES[$varfiles];
1948 if (!is_array($TFile[
'name'])) {
1949 foreach ($TFile as $key => &$val) {
1954 $nbfile = count($TFile[
'name']);
1956 for ($i = 0; $i < $nbfile; $i++) {
1957 if (empty($TFile[
'name'][$i])) {
1962 $destfile = trim($TFile[
'name'][$i]);
1963 $destfull = $upload_dir.
"/".$destfile;
1964 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1966 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1967 $destfile = trim(preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask));
1968 $destfull = $upload_dir.
"/".$destfile;
1971 $filenameto = basename($destfile);
1972 if (preg_match(
'/^\./', $filenameto)) {
1973 $langs->load(
"errors");
1974 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
1978 $info = pathinfo($destfull);
1979 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1980 $info = pathinfo($destfile);
1981 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1989 global $dolibarr_main_restrict_os_commands;
1990 if (!empty($dolibarr_main_restrict_os_commands)) {
1991 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1992 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1993 if (in_array($destfile, $arrayofallowedcommand)) {
1994 $langs->load(
"errors");
1995 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
2001 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
2003 if (is_numeric($resupload) && $resupload > 0) {
2004 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2007 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
2008 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
2009 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
2010 $maxheightmini = $tmparraysize[
'maxheightmini'];
2015 if ($generatethumbs) {
2021 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
2024 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
2029 if (empty($updatesessionordb)) {
2030 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2032 $formmail->trackid = $trackid;
2033 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
2037 if ($updatesessionordb == 1) {
2039 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false &&
getDolGlobalString(
'PRODUCT_ALLOW_EXTERNAL_DOWNLOAD')) {
2044 if ($allowoverwrite) {
2048 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile,
$object, $forceFullTextIndexation);
2050 if ($allowoverwrite) {
2053 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
2060 $langs->load(
"errors");
2061 if (is_numeric($resupload) && $resupload < 0) {
2063 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
2064 if (preg_match(
'/File is a PDF with javascript inside/', $resupload)) {
2065 setEventMessages($langs->trans(
"ErrorFileIsAnInfectedPDFWithJSInside"),
null,
'errors');
2079 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
2082 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2083 $linkObject =
new Link($db);
2084 $linkObject->entity =
$conf->entity;
2085 $linkObject->url = $link;
2086 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
2087 $linkObject->objectid =
GETPOSTINT(
'objectid');
2088 $linkObject->label =
GETPOST(
'label',
'alpha');
2089 $res = $linkObject->create($user);
2097 $langs->load(
"errors");
2098 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
2118 global $db, $user,
$conf, $langs, $_FILES;
2120 $keytodelete = $filenb;
2123 $listofpaths = array();
2124 $listofnames = array();
2125 $listofmimes = array();
2126 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
2127 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
2128 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
2130 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
2131 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
2133 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
2134 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
2137 if ($keytodelete >= 0) {
2138 $pathtodelete = $listofpaths[$keytodelete];
2139 $filetodelete = $listofnames[$keytodelete];
2140 if (empty($donotdeletefile)) {
2146 if (empty($donotdeletefile)) {
2147 $langs->load(
"other");
2148 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
2150 if (empty($donotupdatesession)) {
2151 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2153 $formmail->trackid = $trackid;
2154 $formmail->remove_attached_files($keytodelete);
2177 global $db, $user,
$conf;
2182 dol_syslog(
"addFileIntoDatabaseIndex dir=".$dir.
" file=".$file, LOG_DEBUG);
2184 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2186 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
2187 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
2188 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2189 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2191 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
2193 $ecmfile->filepath = $rel_dir;
2194 $ecmfile->filename = $filename;
2195 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
2196 $ecmfile->fullpath_orig = $fullpathorig;
2197 $ecmfile->gen_or_uploaded = $mode;
2198 $ecmfile->description =
'';
2199 $ecmfile->keywords =
'';
2202 $ecmfile->src_object_id =
$object->id;
2203 if (isset(
$object->table_element)) {
2204 $ecmfile->src_object_type =
$object->table_element;
2206 dol_syslog(
'Error: object ' . get_class(
$object) .
' has no table_element attribute.');
2209 if (isset(
$object->src_object_description)) {
2210 $ecmfile->description =
$object->src_object_description;
2212 if (isset(
$object->src_object_keywords)) {
2213 $ecmfile->keywords =
$object->src_object_keywords;
2216 $ecmfile->entity =
$object->entity;
2225 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2231 if (empty($useFullTextIndexation) && $forceFullTextIndexation ==
'1') {
2233 $useFullTextIndexation =
'pdftotext';
2235 $useFullTextIndexation =
'docling';
2240 if ($useFullTextIndexation) {
2241 $ecmfile->filepath = $rel_dir;
2242 $ecmfile->filename = $filename;
2244 $filetoprocess = $dir.
'/'.$ecmfile->filename;
2246 $textforfulltextindex =
'';
2249 if (preg_match(
'/\.pdf/i', $filename)) {
2255 if (preg_match(
'/pdftotext/i', $useFullTextIndexation)) {
2256 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2257 $utils =
new Utils($db);
2258 $outputfile =
$conf->admin->dir_temp.
'/tmppdftotext.'.$user->id.
'.out';
2262 $cmd =
getDolGlobalString(
'MAIN_SAVE_FILE_CONTENT_AS_TEXT_PDFTOTEXT',
'pdftotext').
" -htmlmeta '".escapeshellcmd($filetoprocess).
"' - ";
2263 $resultexec = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2265 if (!$resultexec[
'error']) {
2266 $txt = $resultexec[
'output'];
2268 if (preg_match(
'/<meta name="Keywords" content="([^\/]+)"\s*\/>/i', $txt, $matches)) {
2269 $keywords = $matches[1];
2271 if (preg_match(
'/<pre>(.*)<\/pre>/si', $txt, $matches)) {
2281 if (preg_match(
'/docling/i', $useFullTextIndexation)) {
2282 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2283 $utils =
new Utils($db);
2284 $outputfile =
$conf->admin->dir_temp.
'/tmpdocling.'.$user->id.
'.out';
2288 $cmd =
getDolGlobalString(
'MAIN_SAVE_FILE_CONTENT_AS_TEXT_DOCLING',
'docling').
" --from pdf --to text '".escapeshellcmd($filetoprocess).
"'";
2289 $resultexec = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2291 if (!$resultexec[
'error']) {
2292 $txt = $resultexec[
'output'];
2300 $textforfulltextindex = $txt;
2309 $ecmfile->description =
'File content generated by '.$cmd;
2311 $ecmfile->content = $textforfulltextindex;
2312 $ecmfile->keywords = $keywords;
2316 $result = $ecmfile->create($user);
2342 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
2346 dol_syslog(
"deleteFilesIntoDatabaseIndex dir=".$dir.
" file=".$file, LOG_DEBUG);
2350 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2352 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
2353 $filename = basename($file);
2354 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2355 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2358 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
2360 $sql .=
' WHERE entity = ' . ((int)
$object->entity);
2362 $sql .=
' WHERE entity = ' . ((int)
$conf->entity);
2364 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
2366 $sql .=
" AND filename = '".$db->escape($file).
"'";
2369 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
2372 $resql = $db->query($sql);
2375 dol_syslog(__FUNCTION__.
' '.$db->lasterror(), LOG_ERR);
2404 if (class_exists(
'Imagick')) {
2405 $image =
new Imagick();
2407 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
2409 $ret = $image->readImage($filetoconvert);
2411 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
2412 dol_syslog(
"Failed to read image using Imagick (Try to install package 'apt-get install php-imagick ghostscript' and check there is no policy to disable ".$ext.
" conversion in /etc/ImageMagick*/policy.xml): ".$e->getMessage(), LOG_WARNING);
2416 $ret = $image->setImageFormat($ext);
2418 if (empty($fileoutput)) {
2419 $fileoutput = $fileinput.
".".$ext;
2422 $count = $image->getNumberImages();
2424 if (!
dol_is_file($fileoutput) || is_writable($fileoutput)) {
2426 $ret = $image->writeImages($fileoutput,
true);
2431 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2461function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring =
null)
2467 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2470 $compressdata =
null;
2471 if ($mode ==
'gz' && function_exists(
'gzencode')) {
2473 $compressdata = gzencode($data, 9);
2474 } elseif ($mode ==
'bz' && function_exists(
'bzcompress')) {
2476 $compressdata = bzcompress($data, 9);
2477 } elseif ($mode ==
'zstd' && function_exists(
'zstd_compress')) {
2479 $compressdata = zstd_compress($data, 9);
2480 } elseif ($mode ==
'zip') {
2481 if (class_exists(
'ZipArchive') &&
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS')) {
2484 $rootPath = realpath($inputfile);
2486 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2487 $zip =
new ZipArchive();
2489 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2490 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2494 $errormsg = $errorstring;
2501 $files =
new RecursiveIteratorIterator(
2502 new RecursiveDirectoryIterator($rootPath, FilesystemIterator::UNIX_PATHS),
2503 RecursiveIteratorIterator::LEAVES_ONLY
2505 '@phan-var-force SplFileInfo[] $files';
2507 foreach ($files as $name => $file) {
2509 if (!$file->isDir()) {
2511 $filePath = $file->getPath();
2512 $fileName = $file->getFilename();
2513 $fileFullRealPath = $file->getRealPath();
2516 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2519 $zip->addFile($fileFullRealPath, $relativePath);
2526 dol_syslog(
"dol_compress_file success - ".$zip->numFiles.
" files");
2530 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2533 include_once ODTPHP_PATHTOPCLZIP.
'pclzip.lib.php';
2534 $archive =
new PclZip($outputfile);
2536 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2538 if ($result === 0) {
2540 $errormsg = $archive->errorInfo(
true);
2542 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2543 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2544 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2548 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2549 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2552 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2558 if ($foundhandler && is_string($compressdata)) {
2559 $fp = fopen($outputfile,
"w");
2560 fwrite($fp, $compressdata);
2564 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2568 $errormsg = $errorstring;
2572 global $langs, $errormsg;
2573 $langs->load(
"errors");
2574 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2576 $errorstring =
"Failed to open file ".$outputfile;
2594 $fileinfo = pathinfo($inputfile);
2595 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2597 if ($fileinfo[
"extension"] ==
"zip") {
2598 if (defined(
'ODTPHP_PATHTOPCLZIP') && !
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS')) {
2599 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2600 include_once ODTPHP_PATHTOPCLZIP.
'pclzip.lib.php';
2601 $archive =
new PclZip($inputfile);
2608 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2610 return array(
'error' => $e->getMessage());
2613 if (!is_array($result) && $result <= 0) {
2614 return array(
'error' => $archive->errorInfo(
true));
2619 foreach ($result as $key => $val) {
2620 if ($val[
'status'] ==
'path_creation_fail') {
2621 $langs->load(
"errors");
2623 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2626 if ($val[
'status'] ==
'write_protected') {
2627 $langs->load(
"errors");
2629 $errmsg = $langs->trans(
"ErrorFailToCreateFile", $val[
'filename']);
2637 return array(
'error' => $errmsg);
2642 if (class_exists(
'ZipArchive')) {
2643 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2644 $zip =
new ZipArchive();
2645 $res = $zip->open($inputfile);
2646 if ($res ===
true) {
2652 for ($i = 0; $i < $zip->numFiles; $i++) {
2653 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2654 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2657 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2663 return array(
'error' =>
'ErrUnzipFails');
2667 return array(
'error' =>
'ErrNoZipEngine');
2668 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2669 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2670 $utils =
new Utils($db);
2677 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2678 if ($extension ==
"tar") {
2681 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2682 if ($resarray[
"result"] != 0) {
2683 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2687 if ($fileinfo[
"extension"] ==
"gz") {
2689 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2691 } elseif ($fileinfo[
"extension"] ==
"zst") {
2694 return array(
'error' =>
'ErrorBadFileExtension');
2697 $cmd .=
' > '.$outputfilename;
2699 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0,
null, 1, $outputfilename.
'.err');
2700 if ($resarray[
"result"] != 0) {
2701 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2702 if ($errfilecontent) {
2703 $resarray[
"error"] .=
" - ".$errfilecontent;
2707 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2710 return array(
'error' =>
'ErrorBadFileExtension');
2726function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'', $newmask =
'0')
2730 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2732 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2733 global $langs, $errormsg;
2734 $langs->load(
"errors");
2735 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2740 if ($mode ==
'gz') {
2742 } elseif ($mode ==
'bz') {
2744 } elseif ($mode ==
'zip') {
2758 if (class_exists(
'ZipArchive')) {
2762 $zip =
new ZipArchive();
2763 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2764 if ($result !==
true) {
2765 global $langs, $errormsg;
2766 $langs->load(
"errors");
2767 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile);
2774 $files =
new RecursiveIteratorIterator(
2775 new RecursiveDirectoryIterator($inputdir, FilesystemIterator::UNIX_PATHS),
2776 RecursiveIteratorIterator::LEAVES_ONLY
2778 '@phan-var-force SplFileInfo[] $files';
2781 foreach ($files as $name => $file) {
2783 if (!$file->isDir()) {
2785 $filePath = $file->getPath();
2786 $fileName = $file->getFilename();
2787 $fileFullRealPath = $file->getRealPath();
2790 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2793 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2795 $zip->addFile($fileFullRealPath, $relativePath);
2806 if (empty($newmask)) {
2807 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
2817 if (!$foundhandler) {
2818 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2824 global $langs, $errormsg;
2825 $langs->load(
"errors");
2826 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2828 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile).
' - '.$e->getMessage();
2845function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook = 0, $mode = 0)
2847 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2848 return isset($tmparray[0]) ? $tmparray[0] :
null;
2866 global
$conf, $db, $user, $hookmanager;
2867 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2870 if (!is_object($fuser)) {
2874 if (empty($modulepart)) {
2875 return 'ErrorBadParameter';
2877 if (empty($entity)) {
2878 if (!isModEnabled(
'multicompany')) {
2885 if ($modulepart ==
'facture') {
2886 $modulepart =
'invoice';
2887 } elseif ($modulepart ==
'users') {
2888 $modulepart =
'user';
2889 } elseif ($modulepart ==
'tva') {
2890 $modulepart =
'tax-vat';
2891 } elseif ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
2893 $modulepart =
'delivery';
2894 } elseif ($modulepart ==
'propale') {
2895 $modulepart =
'propal';
2899 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2903 $sqlprotectagainstexternals =
'';
2907 if (empty($refname)) {
2908 $refname = basename(dirname($original_file).
"/");
2909 if ($refname ==
'thumbs' || $refname ==
'temp') {
2911 $refname = basename(dirname(dirname($original_file)).
"/");
2918 $download =
'download';
2919 if ($mode ==
'write') {
2922 $download =
'upload';
2926 if ($modulepart ==
'common') {
2929 $original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/'.$original_file;
2930 } elseif ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2935 if (empty($entity)) {
2939 $original_file = (empty(
$conf->medias->multidir_output[$entity]) ? (empty(
$conf->medias->dir_output) ? DOL_DATA_ROOT.
'/medias' :
$conf->medias->dir_output) :
$conf->medias->multidir_output[$entity]).
'/'.$original_file;
2940 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2942 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
2943 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2944 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2946 $accessallowed = $user->admin;
2947 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2948 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2950 $accessallowed = ($fuser->hasRight(
'website',
'write') && preg_match(
'/\.jpg$/i', basename($original_file)));
2951 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2952 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2955 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2958 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2959 $original_file = $dirins.
'/'.$original_file;
2960 } elseif ($modulepart ==
'mycompany' && !empty(
$conf->mycompany->dir_output)) {
2963 $original_file =
$conf->mycompany->dir_output.
'/'.$original_file;
2964 } elseif ($modulepart ==
'userphoto' && !empty(
$conf->user->dir_output)) {
2967 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2970 $original_file =
$conf->user->dir_output.
'/'.$original_file;
2971 } elseif ($modulepart ==
'userphotopublic' && !empty(
$conf->user->dir_output)) {
2976 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
2978 $tmpobject =
new User($db);
2979 $tmpobject->fetch($reg[1],
'',
'', 1);
2981 $securekey =
GETPOST(
'securekey',
'alpha', 1);
2983 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
2984 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
2985 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
2986 if ($encodedsecurekey == $securekey) {
2995 $original_file =
$conf->user->dir_output.
'/'.$original_file;
2996 } elseif (($modulepart ==
'companylogo') && !empty(
$conf->mycompany->dir_output)) {
2999 $original_file =
$conf->mycompany->dir_output.
'/logos/'.$original_file;
3000 } elseif ($modulepart ==
'memberphoto' && !empty(
$conf->member->dir_output)) {
3003 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
3006 $original_file =
$conf->member->dir_output.
'/'.$original_file;
3007 } elseif ($modulepart ==
'apercufacture' && !empty(
$conf->invoice->multidir_output[$entity])) {
3009 if ($fuser->hasRight(
'facture', $lire)) {
3012 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
3013 } elseif ($modulepart ==
'apercupropal' && !empty(
$conf->propal->multidir_output[$entity])) {
3015 if ($fuser->hasRight(
'propal', $lire)) {
3018 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
3019 } elseif ($modulepart ==
'apercucommande' && !empty(
$conf->order->multidir_output[$entity])) {
3021 if ($fuser->hasRight(
'commande', $lire)) {
3024 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
3025 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty(
$conf->ficheinter->dir_output)) {
3027 if ($fuser->hasRight(
'ficheinter', $lire)) {
3030 $original_file =
$conf->ficheinter->dir_output.
'/'.$original_file;
3031 } elseif (($modulepart ==
'apercucontract') && !empty(
$conf->contract->multidir_output[$entity])) {
3033 if ($fuser->hasRight(
'contrat', $lire)) {
3036 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
3037 } elseif (($modulepart ==
'apercusupplier_proposal') && !empty(
$conf->supplier_proposal->dir_output)) {
3039 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
3042 $original_file =
$conf->supplier_proposal->dir_output.
'/'.$original_file;
3043 } elseif (($modulepart ==
'apercusupplier_order') && !empty(
$conf->fournisseur->commande->dir_output)) {
3045 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3048 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3049 } elseif (($modulepart ==
'apercusupplier_invoice') && !empty(
$conf->fournisseur->facture->dir_output)) {
3051 if ($fuser->hasRight(
'fournisseur', $lire)) {
3054 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3055 } elseif (($modulepart ==
'holiday') && !empty(
$conf->holiday->dir_output)) {
3056 if ($fuser->hasRight(
'holiday', $read) || $fuser->hasRight(
'holiday',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3059 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3060 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
3061 $tmpholiday =
new Holiday($db);
3062 $tmpholiday->fetch(0, $refname);
3063 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
3066 $original_file =
$conf->holiday->dir_output.
'/'.$original_file;
3067 } elseif (($modulepart ==
'expensereport') && !empty(
$conf->expensereport->dir_output)) {
3068 if ($fuser->hasRight(
'expensereport', $lire) || $fuser->hasRight(
'expensereport',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3071 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3072 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
3074 $tmpexpensereport->fetch(0, $refname);
3075 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
3078 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3079 } elseif (($modulepart ==
'apercuexpensereport') && !empty(
$conf->expensereport->dir_output)) {
3081 if ($fuser->hasRight(
'expensereport', $lire)) {
3084 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3085 } elseif ($modulepart ==
'propalstats' && !empty(
$conf->propal->multidir_temp[$entity])) {
3087 if ($fuser->hasRight(
'propal', $lire)) {
3090 $original_file =
$conf->propal->multidir_temp[$entity].
'/'.$original_file;
3091 } elseif ($modulepart ==
'orderstats' && !empty(
$conf->order->dir_temp)) {
3093 if ($fuser->hasRight(
'commande', $lire)) {
3096 $original_file =
$conf->order->dir_temp.
'/'.$original_file;
3097 } elseif ($modulepart ==
'orderstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3098 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3101 $original_file =
$conf->fournisseur->commande->dir_temp.
'/'.$original_file;
3102 } elseif ($modulepart ==
'billstats' && !empty(
$conf->invoice->dir_temp)) {
3104 if ($fuser->hasRight(
'facture', $lire)) {
3107 $original_file =
$conf->invoice->dir_temp.
'/'.$original_file;
3108 } elseif ($modulepart ==
'billstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3109 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
3112 $original_file =
$conf->fournisseur->facture->dir_temp.
'/'.$original_file;
3113 } elseif ($modulepart ==
'expeditionstats' && !empty(
$conf->expedition->dir_temp)) {
3115 if ($fuser->hasRight(
'expedition', $lire)) {
3118 $original_file =
$conf->expedition->dir_temp.
'/'.$original_file;
3119 } elseif ($modulepart ==
'tripsexpensesstats' && !empty(
$conf->deplacement->dir_temp)) {
3121 if ($fuser->hasRight(
'deplacement', $lire)) {
3124 $original_file =
$conf->deplacement->dir_temp.
'/'.$original_file;
3125 } elseif ($modulepart ==
'memberstats' && !empty(
$conf->member->dir_temp)) {
3127 if ($fuser->hasRight(
'adherent', $lire)) {
3130 $original_file =
$conf->member->dir_temp.
'/'.$original_file;
3131 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty(
$conf->product->dir_temp)) {
3133 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
3136 $original_file = (!empty(
$conf->product->multidir_temp[$entity]) ?
$conf->product->multidir_temp[$entity] :
$conf->service->multidir_temp[$entity]).
'/'.$original_file;
3137 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty(
$conf->tax->dir_output)) {
3139 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
3142 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
3143 $original_file =
$conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
3144 } elseif ($modulepart ==
'actions' && !empty(
$conf->agenda->dir_output)) {
3146 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3149 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3150 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3152 $tmpobject->fetch((
int) $refname);
3153 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3154 if ($user->socid && $tmpobject->socid) {
3159 $original_file =
$conf->agenda->dir_output.
'/'.$original_file;
3160 } elseif ($modulepart ==
'category' && !empty(
$conf->categorie->multidir_output[$entity])) {
3162 if (empty($entity) || empty(
$conf->categorie->multidir_output[$entity])) {
3163 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3165 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
3168 $original_file =
$conf->categorie->multidir_output[$entity].
'/'.$original_file;
3169 } elseif ($modulepart ==
'prelevement' && !empty(
$conf->prelevement->dir_output)) {
3171 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3174 $original_file =
$conf->prelevement->dir_output.
'/'.$original_file;
3175 } elseif ($modulepart ==
'graph_stock' && !empty(
$conf->stock->dir_temp)) {
3178 $original_file =
$conf->stock->dir_temp.
'/'.$original_file;
3179 } elseif ($modulepart ==
'graph_fourn' && !empty(
$conf->fournisseur->dir_temp)) {
3182 $original_file =
$conf->fournisseur->dir_temp.
'/'.$original_file;
3183 } elseif ($modulepart ==
'graph_product' && !empty(
$conf->product->dir_temp)) {
3186 $original_file =
$conf->product->multidir_temp[$entity].
'/'.$original_file;
3187 } elseif ($modulepart ==
'barcode') {
3192 $original_file =
'';
3193 } elseif ($modulepart ==
'iconmailing' && !empty(
$conf->mailing->dir_temp)) {
3196 $original_file =
$conf->mailing->dir_temp.
'/'.$original_file;
3197 } elseif ($modulepart ==
'scanner_user_temp' && !empty(
$conf->scanner->dir_temp)) {
3200 $original_file =
$conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3201 } elseif ($modulepart ==
'fckeditor' && !empty(
$conf->fckeditor->dir_output)) {
3204 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3205 } elseif ($modulepart ==
'user' && !empty(
$conf->user->dir_output)) {
3207 $canreaduser = (!empty($fuser->admin) || $fuser->hasRight(
'user',
'user', $lire));
3208 if ($fuser->id == (
int) $refname) {
3211 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3214 $original_file =
$conf->user->dir_output.
'/'.$original_file;
3215 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty(
$conf->societe->multidir_output[$entity])) {
3217 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3218 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3220 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3223 $original_file =
$conf->societe->multidir_output[$entity].
'/'.$original_file;
3224 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
3225 } elseif ($modulepart ==
'contact' && !empty(
$conf->societe->multidir_output[$entity])) {
3227 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3228 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3230 if ($fuser->hasRight(
'societe', $lire)) {
3233 $original_file =
$conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3234 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty(
$conf->invoice->multidir_output[$entity])) {
3236 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3239 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
3240 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3241 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty(
$conf->propal->multidir_output[$entity])) {
3243 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3246 $original_file =
$conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3247 } elseif ($modulepart ==
'massfilesarea_orders') {
3248 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3251 $original_file =
$conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3252 } elseif ($modulepart ==
'massfilesarea_sendings') {
3253 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3256 $original_file =
$conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3257 } elseif ($modulepart ==
'massfilesarea_receipts') {
3258 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3261 $original_file =
$conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3262 } elseif ($modulepart ==
'massfilesarea_invoices') {
3263 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3266 $original_file =
$conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3267 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3268 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3271 $original_file =
$conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3272 } elseif ($modulepart ==
'massfilesarea_interventions') {
3273 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3276 $original_file =
$conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3277 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty(
$conf->supplier_proposal->dir_output)) {
3278 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3281 $original_file =
$conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3282 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3283 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3286 $original_file =
$conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3287 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3288 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3291 $original_file =
$conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3292 } elseif ($modulepart ==
'massfilesarea_contract' && !empty(
$conf->contract->dir_output)) {
3293 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3296 $original_file =
$conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3297 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty(
$conf->ficheinter->dir_output)) {
3299 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3302 $original_file =
$conf->ficheinter->dir_output.
'/'.$original_file;
3303 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3304 } elseif ($modulepart ==
'deplacement' && !empty(
$conf->deplacement->dir_output)) {
3306 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3309 $original_file =
$conf->deplacement->dir_output.
'/'.$original_file;
3311 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset(
$conf->propal->multidir_output[$entity])) {
3313 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3316 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
3317 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3318 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty(
$conf->order->multidir_output[$entity])) {
3320 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3323 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
3324 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3325 } elseif ($modulepart ==
'project' && !empty(
$conf->project->multidir_output[$entity])) {
3327 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3330 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3331 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3332 $tmpproject =
new Project($db);
3333 $tmpproject->fetch(0, $refname);
3334 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3337 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3338 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3339 } elseif ($modulepart ==
'project_task' && !empty(
$conf->project->multidir_output[$entity])) {
3340 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3343 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3344 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3345 $tmptask =
new Task($db);
3346 $tmptask->fetch(0, $refname);
3347 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3350 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3351 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3352 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty(
$conf->fournisseur->commande->dir_output)) {
3354 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3357 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3358 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3359 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty(
$conf->fournisseur->facture->dir_output)) {
3361 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3364 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3365 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3366 } elseif ($modulepart ==
'supplier_payment') {
3368 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3371 $original_file =
$conf->fournisseur->payment->dir_output.
'/'.$original_file;
3372 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3373 } elseif ($modulepart ==
'payment') {
3375 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3378 $original_file =
$conf->compta->payment->dir_output.
'/'.$original_file;
3379 } elseif ($modulepart ==
'facture_paiement' && !empty(
$conf->invoice->dir_output)) {
3381 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3384 if ($fuser->socid > 0) {
3385 $original_file =
$conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3387 $original_file =
$conf->invoice->dir_output.
'/payments/'.$original_file;
3389 } elseif ($modulepart ==
'export_compta' && !empty(
$conf->accounting->dir_output)) {
3391 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3394 $original_file =
$conf->accounting->dir_output.
'/'.$original_file;
3395 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty(
$conf->expedition->dir_output)) {
3397 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3400 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3402 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty(
$conf->expedition->dir_output)) {
3404 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3407 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3408 } elseif ($modulepart ==
'actionsreport' && !empty(
$conf->agenda->dir_temp)) {
3410 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3413 $original_file =
$conf->agenda->dir_temp.
"/".$original_file;
3414 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3416 if (empty($entity) || (empty(
$conf->product->multidir_output[$entity]) && empty(
$conf->service->multidir_output[$entity]))) {
3417 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3419 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3422 if (isModEnabled(
"product")) {
3423 $original_file =
$conf->product->multidir_output[$entity].
'/'.$original_file;
3424 } elseif (isModEnabled(
"service")) {
3425 $original_file =
$conf->service->multidir_output[$entity].
'/'.$original_file;
3427 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3429 if (empty($entity) || (empty(
$conf->productbatch->multidir_output[$entity]))) {
3430 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3432 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3435 if (isModEnabled(
'productbatch')) {
3436 $original_file =
$conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3438 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3440 if (empty($entity) || empty(
$conf->stock->multidir_output[$entity])) {
3441 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3443 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3446 if (isModEnabled(
'stock')) {
3447 $original_file =
$conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3449 } elseif ($modulepart ==
'contract' && !empty(
$conf->contract->multidir_output[$entity])) {
3451 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3454 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
3455 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3456 } elseif ($modulepart ==
'donation' && !empty(
$conf->don->dir_output)) {
3458 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3461 $original_file =
$conf->don->dir_output.
'/'.$original_file;
3462 } elseif ($modulepart ==
'dolresource' && !empty(
$conf->resource->dir_output)) {
3464 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3467 $original_file =
$conf->resource->dir_output.
'/'.$original_file;
3468 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty(
$conf->bank->dir_output)) {
3470 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3473 $original_file =
$conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3474 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty(
$conf->bank->dir_output)) {
3476 if ($fuser->hasRight(
'banque', $lire)) {
3479 $original_file =
$conf->bank->dir_output.
'/'.$original_file;
3480 } elseif ($modulepart ==
'export' && !empty(
$conf->export->dir_temp)) {
3483 $accessallowed = $user->hasRight(
'export',
'lire');
3484 $original_file =
$conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3485 } elseif ($modulepart ==
'import' && !empty(
$conf->import->dir_temp)) {
3487 $accessallowed = $user->hasRight(
'import',
'run');
3488 $original_file =
$conf->import->dir_temp.
'/'.$original_file;
3489 } elseif ($modulepart ==
'recruitment' && !empty(
$conf->recruitment->dir_output)) {
3491 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3492 $original_file =
$conf->recruitment->dir_output.
'/'.$original_file;
3493 } elseif ($modulepart ==
'hrm' && !empty(
$conf->hrm->dir_output)) {
3495 $accessallowed = $user->hasRight(
'hrm',
'all',
'read');
3496 $original_file =
$conf->hrm->dir_output.
'/'.$original_file;
3497 } elseif ($modulepart ==
'editor' && !empty(
$conf->fckeditor->dir_output)) {
3500 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3501 } elseif ($modulepart ==
'systemtools' && !empty(
$conf->admin->dir_output)) {
3503 if ($fuser->admin) {
3506 $original_file =
$conf->admin->dir_output.
'/'.$original_file;
3507 } elseif ($modulepart ==
'admin_temp' && !empty(
$conf->admin->dir_temp)) {
3509 if ($fuser->admin) {
3512 $original_file =
$conf->admin->dir_temp.
'/'.$original_file;
3513 } elseif ($modulepart ==
'bittorrent' && !empty(
$conf->bittorrent->dir_output)) {
3517 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3520 $original_file =
$conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3521 } elseif ($modulepart ==
'member' && !empty(
$conf->member->dir_output)) {
3523 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3526 $original_file =
$conf->member->dir_output.
'/'.$original_file;
3536 if (preg_match(
'/^specimen/i', $original_file)) {
3539 if ($fuser->admin) {
3543 $tmpmodulepart = explode(
'-', $modulepart);
3544 if (!empty($tmpmodulepart[1])) {
3545 $modulepart = $tmpmodulepart[0];
3546 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3551 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3552 $tmpmodule = $reg[1];
3553 if (empty(
$conf->$tmpmodule->dir_temp)) {
3554 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3557 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3560 $original_file =
$conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3561 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3562 $tmpmodule = $reg[1];
3563 if (empty(
$conf->$tmpmodule->dir_temp)) {
3564 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3567 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3570 $original_file =
$conf->$tmpmodule->dir_temp.
'/'.$original_file;
3571 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3572 $tmpmodule = $reg[1];
3573 if (empty(
$conf->$tmpmodule->dir_output)) {
3574 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3577 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3580 $original_file =
$conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3581 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3582 $tmpmodule = $reg[1];
3583 if (empty(
$conf->$tmpmodule->dir_output)) {
3584 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3587 if ($fuser->hasRight($tmpmodule, $lire) || preg_match(
'/^specimen/i', $original_file)) {
3590 $original_file =
$conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3592 if (empty(
$conf->$modulepart->dir_output)) {
3593 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
'). The module for this modulepart value may not be activated.');
3598 $partsofdirinoriginalfile = explode(
'/', $original_file);
3599 if (!empty($partsofdirinoriginalfile[1])) {
3600 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3601 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3605 if (($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) || ($fuser->hasRight($modulepart,
'all', $lire) || $fuser->hasRight($modulepart,
'all', $read))) {
3609 if (is_array(
$conf->$modulepart->multidir_output) && !empty(
$conf->$modulepart->multidir_output[$entity])) {
3610 $original_file =
$conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3612 $original_file =
$conf->$modulepart->dir_output.
'/'.$original_file;
3616 $parameters = array(
3617 'modulepart' => $modulepart,
3618 'original_file' => $original_file,
3619 'entity' => $entity,
3624 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3626 if (!empty($hookmanager->resArray[
'original_file'])) {
3627 $original_file = $hookmanager->resArray[
'original_file'];
3629 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3630 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3632 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3633 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3639 'accessallowed' => ($accessallowed ? 1 : 0),
3640 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3641 'original_file' => $original_file
3660 dol_syslog(
"Failed to create the cache directory ".$directory, LOG_WARNING);
3663 $cachefile = $directory.$filename;
3665 file_put_contents($cachefile, serialize(
$object), LOCK_EX);
3681 $cachefile = $directory.$filename;
3682 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3695 $cachefile = $directory.$filename;
3696 $object = unserialize(file_get_contents($cachefile));
3708 return preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'\//',
'', $pathfile);
3723function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3727 $exclude =
'install';
3729 foreach ($dir->md5file as $file) {
3730 $filename = $path.$file[
'name'];
3731 $file_list[
'insignature'][] = $filename;
3732 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3733 $expectedmd5 = (string) $file;
3735 if (!file_exists($pathref.
'/'.$filename)) {
3736 $file_list[
'missing'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize);
3738 $md5_local = md5_file($pathref.
'/'.$filename);
3740 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3741 $checksumconcat[] = $expectedmd5;
3743 if ($md5_local != $expectedmd5) {
3744 $file_list[
'updated'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize,
'md5' => (
string) $md5_local);
3746 $checksumconcat[] = $md5_local;
3751 foreach ($dir->dir as $subdir) {
3752 getFilesUpdated($file_list, $subdir, $path.$subdir[
'name'].
'/', $pathref, $checksumconcat);
3770 $out .=
'<div id="'.$htmlname.
'Message" class="dragDropAreaMessage hidden"><span>'.
img_picto(
"",
'download').
'<br>'.$langs->trans(
"DropFileToAddItToObject").
'</span></div>';
3771 $out .=
"\n<!-- JS CODE TO ENABLE DRAG AND DROP OF FILE -->\n";
3774 jQuery(document).ready(function() {
3775 var enterTargetDragDrop = null;
3777 $("#'.$htmlname.
'").addClass("cssDragDropArea");
3779 $(".cssDragDropArea").on("dragenter", function(ev, ui) {
3780 var dataTransfer = ev.originalEvent.dataTransfer;
3781 var dataTypes = dataTransfer.types;
3782 //console.log(dataTransfer);
3783 //console.log(dataTypes);
3785 if (!dataTypes || ($.inArray(\'Files\', dataTypes) === -1)) {
3786 // The element dragged is not a file, so we avoid the "dragenter"
3787 ev.preventDefault();
3791 // Entering drop area. Highlight area
3792 console.log("dragAndDropFileUpload: We add class highlightDragDropArea")
3793 enterTargetDragDrop = ev.target;
3794 $(this).addClass("highlightDragDropArea");
3795 $("#'.$htmlname.
'Message").removeClass("hidden");
3796 ev.preventDefault();
3799 $(".cssDragDropArea").on("dragleave", function(ev) {
3800 // Going out of drop area. Remove Highlight
3801 if (enterTargetDragDrop == ev.target){
3802 console.log("dragAndDropFileUpload: We remove class highlightDragDropArea")
3803 $("#'.$htmlname.
'Message").addClass("hidden");
3804 $(this).removeClass("highlightDragDropArea");
3808 $(".cssDragDropArea").on("dragover", function(ev) {
3809 ev.preventDefault();
3813 $(".cssDragDropArea").on("drop", function(e) {
3816 fd = new FormData();
3820 fd.append("action", "linkit");
3822 var dataTransfer = e.originalEvent.dataTransfer;
3824 if (dataTransfer.files && dataTransfer.files.length){
3825 var droppedFiles = e.originalEvent.dataTransfer.files;
3826 $.each(droppedFiles, function(index,file){
3827 fd.append("files[]", file,file.name)
3830 $(".cssDragDropArea").removeClass("highlightDragDropArea");
3831 counterdragdrop = 0;
3833 url: "'.DOL_URL_ROOT.
'/core/ajax/fileupload.php",
3838 success:function() {
3839 console.log("Uploaded.", arguments);
3840 /* arguments[0] is the json string of files */
3841 /* arguments[1] is the value for variable "success", can be 0 or 1 */
3842 let listoffiles = JSON.parse(arguments[0]);
3843 console.log(listoffiles);
3845 for (let i = 0; i < listoffiles.length; i++) {
3846 console.log(listoffiles[i].error);
3847 if (listoffiles[i].error) {
3851 console.log(nboferror);
3852 if (nboferror > 0) {
3853 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorOnAtLeastOneFileUpload:warnings";
3855 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=UploadFileDragDropSuccess:mesgs";
3859 console.log("Error Uploading.", arguments)
3860 if (arguments[0].status == 403) {
3861 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadPermissionDenied:errors";
3863 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadFileDragDropPermissionDenied:errors";
3869 $out .=
"</script>\n";
3883function archiveOrBackupFile($srcfile, $max_versions = 5, $archivedir =
'', $suffix =
"v", $moveorcopy =
'move')
3885 $base_file_pattern = ($archivedir ? $archivedir : dirname($srcfile)).
'/'.basename($srcfile).
".".$suffix;
3886 $files_in_directory = glob($base_file_pattern .
"*");
3889 $files_with_timestamps = [];
3890 foreach ($files_in_directory as $file) {
3891 $files_with_timestamps[] = [
3893 'timestamp' => filemtime($file)
3899 while (count($files_with_timestamps) > 0) {
3900 $latest_file =
null;
3901 $latest_index =
null;
3904 foreach ($files_with_timestamps as $index => $file_info) {
3905 if ($latest_file ===
null || (is_array($latest_file) && $file_info[
'timestamp'] > $latest_file[
'timestamp'])) {
3906 $latest_file = $file_info;
3907 $latest_index = $index;
3912 if ($latest_file !==
null) {
3913 $sorted_files[] = $latest_file[
'file'];
3914 unset($files_with_timestamps[$latest_index]);
3919 if (count($sorted_files) >= $max_versions) {
3920 $oldest_files = array_slice($sorted_files, $max_versions - 1);
3921 foreach ($oldest_files as $oldest_file) {
3927 $new_backup = $srcfile .
".v" . $timestamp;
3930 if ($moveorcopy ==
'move') {
3931 $result =
dol_move($srcfile, $new_backup,
'0', 1, 0, 0);
3933 $result =
dol_copy($srcfile, $new_backup,
'0', 1, 0, 0);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage agenda events (actions)
Class to manage ECM files.
Class to manage Trips and Expenses.
Class of the module paid holiday.
Class to manage projects.
Class to manage Dolibarr users.
Class to manage utility methods.
dirbasename($pathfile)
Return the relative dirname (relative to DOL_DATA_ROOT) of a full path string.
dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $sqlfilters="", $object=null)
Scan a directory and return a list of files/directories.
dol_is_link($pathoffile)
Return if path is a symbolic link.
dol_compare_file($a, $b)
Fast compare of 2 files identified by their properties ->name, ->date and ->size.
dol_meta_create($object)
Create a meta file with document file into same directory.
dol_is_url($uri)
Return if path is an URI (the name of the method is misleading).
dol_basename($pathfile)
Make a basename working with all page code (default PHP basenamed fails with cyrillic).
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path='', $pathref='', &$checksumconcat=array())
Function to get list of updated or modified files.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=0)
Move a file into another name.
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir, $object=null)
Complete $filearray with data from database.
archiveOrBackupFile($srcfile, $max_versions=5, $archivedir='', $suffix="v", $moveorcopy='move')
Manage backup versions for a given file, ensuring only a maximum number of versions are kept.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory into another name.
addFileIntoDatabaseIndex($dir, $file, $fullpathorig='', $mode='uploaded', $setsharekey=0, $object=null, $forceFullTextIndexation='')
Add a file into database index.
dol_fileperm($pathoffile)
Return permissions of a file.
dol_is_writable($folderorfile)
Test if directory or filename is writable.
dol_delete_dir($dir, $nophperrors=0)
Remove a directory (not recursive, so content must be empty).
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_init_file_process($pathtoscan='', $trackid='')
Scan a directory and init $_SESSION to manage uploaded files with list of all found files.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
dol_filecache($directory, $filename, $object)
Store object in file.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dragAndDropFileUpload($htmlname)
Function to manage the drag and drop of a file.
dol_is_file($pathoffile)
Return if path is a file.
dol_count_nb_of_line($file)
Count number of lines in a file.
dolCheckVirus($src_file, $dest_file='')
Check virus into a file.
dol_unescapefile($filename)
Unescape a file submitted by upload.
dol_dir_is_emtpy($folder)
Test if a folder is empty.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='')
Get and save an upload file (for example after submitting a new file a mail form).
dolCheckOnFileName($src_file, $dest_file='')
Check virus into a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_readcachefile($directory, $filename)
Read object from cachefile.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png) $', '^\.'), $nohook=0, $mode=0)
Return file(s) into a directory (by default most recent)
dol_is_dir($folder)
Test if filename is a directory.
dol_cache_refresh($directory, $filename, $cachetime)
Test if Refresh needed.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask='0', $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_delete_preview($object)
Delete all preview files linked to object instance.
dol_is_dir_empty($dir)
Return if path is empty.
deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded', $object=null)
Delete files into database index using search criteria.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
currentToken()
Return the value of token currently saved into session with name 'token'.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_string_nounprintableascii($str, $removetabcrlf=1)
Clean a string from all non printable ASCII chars (0x00-0x1F and 0x7F).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isAFileWithExecutableContent($filename)
Return if a file can contains executable content.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
vignette($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
if(!defined( 'IMAGETYPE_WEBP')) getDefaultImageSizes()
Return default values for image sizes.
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
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.