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;
1035function dol_move($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array())
1040 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
1045 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
1049 if ($overwriteifexists || !$destexists) {
1054 $testvirusarray = array();
1057 $testvirusarray =
dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
1058 if (count($testvirusarray)) {
1059 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1065 if (count($testvirusarray)) {
1066 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1071 global $dolibarr_main_restrict_os_commands;
1072 if (!empty($dolibarr_main_restrict_os_commands)) {
1073 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1074 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1075 if (in_array(basename($destfile), $arrayofallowedcommand)) {
1078 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);
1083 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1086 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
1089 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1091 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1096 if ($result && $indexdatabase) {
1098 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1099 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1100 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1101 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1102 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1105 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1106 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1108 $ecmfiletarget =
new EcmFiles($db);
1109 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
1110 if ($resultecmtarget > 0) {
1111 $ecmfiletarget->delete($user);
1115 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
1116 if ($resultecm > 0) {
1117 $filename = basename($rel_filetorenameafter);
1118 $rel_dir = dirname($rel_filetorenameafter);
1119 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1120 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1122 $ecmfile->filepath = $rel_dir;
1123 $ecmfile->filename = $filename;
1125 $resultecm = $ecmfile->update($user);
1126 } elseif ($resultecm == 0) {
1127 $filename = basename($rel_filetorenameafter);
1128 $rel_dir = dirname($rel_filetorenameafter);
1129 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1130 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1132 $ecmfile->filepath = $rel_dir;
1133 $ecmfile->filename = $filename;
1135 $ecmfile->fullpath_orig = basename($srcfile);
1136 if (!empty($moreinfo) && !empty($moreinfo[
'gen_or_uploaded'])) {
1137 $ecmfile->gen_or_uploaded = $moreinfo[
'gen_or_uploaded'];
1139 $ecmfile->gen_or_uploaded =
'uploaded';
1141 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1142 $ecmfile->description = $moreinfo[
'description'];
1144 $ecmfile->description =
'';
1146 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1147 $ecmfile->keywords = $moreinfo[
'keywords'];
1149 $ecmfile->keywords =
'';
1151 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1152 $ecmfile->note_private = $moreinfo[
'note_private'];
1154 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1155 $ecmfile->note_public = $moreinfo[
'note_public'];
1157 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1158 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1160 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1161 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1163 if (!empty($moreinfo) && !empty($moreinfo[
'position'])) {
1164 $ecmfile->position = $moreinfo[
'position'];
1166 if (!empty($moreinfo) && !empty($moreinfo[
'cover'])) {
1167 $ecmfile->cover = $moreinfo[
'cover'];
1170 $resultecm = $ecmfile->create($user);
1171 if ($resultecm < 0) {
1174 if (!empty($moreinfo) && !empty($moreinfo[
'array_options']) && is_array($moreinfo[
'array_options'])) {
1175 $ecmfile->array_options = $moreinfo[
'array_options'];
1176 $resultecm = $ecmfile->insertExtraFields();
1177 if ($resultecm < 0) {
1182 } elseif ($resultecm < 0) {
1186 if ($resultecm > 0) {
1194 if (empty($newmask)) {
1201 dolChmod($newpathofdestfile, $newmask);
1217function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase = 1, $renamedircontent = 1)
1221 dol_syslog(
"files.lib.php::dol_move_dir srcdir=".$srcdir.
" destdir=".$destdir.
" overwritifexists=".$overwriteifexists.
" indexdatabase=".$indexdatabase.
" renamedircontent=".$renamedircontent);
1223 $srcbasename = basename($srcdir);
1227 dol_syslog(
"files.lib.php::dol_move_dir srcdir does not exists. Move fails");
1231 if ($overwriteifexists || !$destexists) {
1238 if ($overwriteifexists) {
1239 if (strtoupper(substr(PHP_OS, 0, 3)) ===
'WIN') {
1240 if (is_dir($newpathofdestdir)) {
1241 @rmdir($newpathofdestdir);
1246 $result = @rename($newpathofsrcdir, $newpathofdestdir);
1249 if ($result && $renamedircontent) {
1250 if (file_exists($newpathofdestdir)) {
1251 $destbasename = basename($newpathofdestdir);
1253 if (!empty($files) && is_array($files)) {
1254 foreach ($files as $key => $file) {
1255 if (!file_exists($file[
"fullname"])) {
1258 $filepath = $file[
"path"];
1259 $oldname = $file[
"name"];
1261 $newname = str_replace($srcbasename, $destbasename, $oldname);
1262 if (!empty($newname) && $newname !== $oldname) {
1263 if ($file[
"type"] ==
"dir") {
1264 $res =
dol_move_dir($filepath.
'/'.$oldname, $filepath.
'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent);
1266 $res =
dol_move($filepath.
'/'.$oldname, $filepath.
'/'.$newname,
'0', $overwriteifexists, 0, $indexdatabase);
1293 return trim(basename($filename),
".\x00..\x20");
1309 if (!empty($reterrors)) {
1314 if (!class_exists(
'AntiVir')) {
1315 require_once DOL_DOCUMENT_ROOT.
'/core/class/antivir.class.php';
1318 $result = $antivir->dol_avscan_file($src_file);
1320 $reterrors = $antivir->errors;
1336 if (preg_match(
'/\.pdf$/i', $dest_file)) {
1338 dol_syslog(
"dolCheckOnFileName Check that pdf does not contains js code");
1340 $tmp = file_get_contents(trim($src_file));
1341 if (preg_match(
'/[\n\s]+\/JavaScript[\n\s]+/m', $tmp)) {
1342 return array(
'File is a PDF with javascript inside');
1345 dol_syslog(
"dolCheckOnFileName Check js into pdf disabled");
1373function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles =
'addedfile', $upload_dir =
'')
1379 $file_name = $dest_file;
1382 if (empty($nohook)) {
1383 $reshook = $hookmanager->initHooks(array(
'fileslib'));
1385 $parameters = array(
'dest_file' => $dest_file,
'src_file' => $src_file,
'file_name' => $file_name,
'varfiles' => $varfiles,
'allowoverwrite' => $allowoverwrite);
1386 $reshook = $hookmanager->executeHooks(
'moveUploadedFile', $parameters,
$object);
1389 if (empty($reshook)) {
1391 if ($uploaderrorcode) {
1392 switch ($uploaderrorcode) {
1393 case UPLOAD_ERR_INI_SIZE:
1394 return 'ErrorFileSizeTooLarge';
1395 case UPLOAD_ERR_FORM_SIZE:
1396 return 'ErrorFileSizeTooLarge';
1397 case UPLOAD_ERR_PARTIAL:
1398 return 'ErrorPartialFile';
1399 case UPLOAD_ERR_NO_TMP_DIR:
1400 return 'ErrorNoTmpDir';
1401 case UPLOAD_ERR_CANT_WRITE:
1402 return 'ErrorFailedToWriteInDir';
1403 case UPLOAD_ERR_EXTENSION:
1404 return 'ErrorUploadBlockedByAddon';
1412 if (empty($disablevirusscan) && file_exists($src_file)) {
1414 if (count($checkvirusarray)) {
1415 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.implode(
',', $checkvirusarray), LOG_WARNING);
1416 return 'ErrorFileIsInfectedWithAVirus: '.implode(
',', $checkvirusarray);
1425 $publicmediasdirwithslash =
$conf->medias->multidir_output[
$conf->entity];
1426 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
1427 $publicmediasdirwithslash .=
'/';
1430 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0 || !
getDolGlobalInt(
"MAIN_DOCUMENT_DISABLE_NOEXE_IN_MEDIAS_DIR")) {
1431 $file_name .=
'.noexe';
1438 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
1439 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
1445 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
1446 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
1452 $errmsg = implode(
',', $hookmanager->errors);
1453 if (empty($errmsg)) {
1454 $errmsg =
'ErrorReturnedBySomeHooks';
1457 } elseif (empty($reshook)) {
1463 if (!is_writable(dirname($file_name_osencoded))) {
1464 dol_syslog(
"Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded).
" is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1465 return 'ErrorDirNotWritable';
1469 if (!$allowoverwrite) {
1470 if (file_exists($file_name_osencoded)) {
1471 dol_syslog(
"Files.lib::dol_move_uploaded_file File ".$file_name.
" already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
1472 return 'ErrorFileAlreadyExists';
1475 if (is_dir($file_name_osencoded)) {
1476 dol_syslog(
"Files.lib::dol_move_uploaded_file A directory with name ".$file_name.
" already exists. Return 'ErrorDirWithFileNameAlreadyExists'", LOG_WARNING);
1477 return 'ErrorDirWithFileNameAlreadyExists';
1482 $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1485 dol_syslog(
"Files.lib::dol_move_uploaded_file Success to move ".$src_file.
" to ".$file_name.
" - Umask=" .
getDolGlobalString(
'MAIN_UMASK'), LOG_DEBUG);
1486 return $successcode;
1488 dol_syslog(
"Files.lib::dol_move_uploaded_file Failed to move ".$src_file.
" to ".$file_name, LOG_ERR);
1493 return $successcode;
1511function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0,
$object =
null, $allowdotdot =
false, $indexdatabase = 1, $nolog = 0)
1514 global $hookmanager;
1516 if (empty($nolog)) {
1517 dol_syslog(
"dol_delete_file file=".$file.
" disableglob=".$disableglob.
" nophperrors=".$nophperrors.
" nohook=".$nohook);
1522 if ((!$allowdotdot && preg_match(
'/\.\./', $file)) || preg_match(
'/[<>|]/', $file)) {
1523 dol_syslog(
"Refused to delete file ".$file, LOG_WARNING);
1528 if (empty($nohook) && !empty($hookmanager)) {
1529 $hookmanager->initHooks(array(
'fileslib'));
1531 $parameters = array(
1533 'disableglob' => $disableglob,
1534 'nophperrors' => $nophperrors
1536 $reshook = $hookmanager->executeHooks(
'deleteFile', $parameters,
$object);
1539 if (empty($nohook) && $reshook != 0) {
1547 if (empty($disableglob) && !empty($file_osencoded)) {
1549 $globencoded = str_replace(
'[',
'\[', $file_osencoded);
1550 $globencoded = str_replace(
']',
'\]', $globencoded);
1551 $listofdir = glob($globencoded);
1553 if (!empty($listofdir) && is_array($listofdir)) {
1554 foreach ($listofdir as $filename) {
1556 $ok = @unlink($filename);
1558 $ok = unlink($filename);
1562 if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
1563 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);
1564 dolChmod(dirname($filename), decoct(fileperms(dirname($filename)) | 0200));
1567 $ok = @unlink($filename);
1569 $ok = unlink($filename);
1574 if (empty($nolog)) {
1575 dol_syslog(
"Removed file ".$filename, LOG_DEBUG);
1579 $rel_filetodelete = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filename);
1580 if (!preg_match(
'/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1581 if (is_object($db) && $indexdatabase) {
1582 $rel_filetodelete = preg_replace(
'/^[\\/]/',
'', $rel_filetodelete);
1583 $rel_filetodelete = preg_replace(
'/\.noexe$/',
'', $rel_filetodelete);
1585 dol_syslog(
"Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1586 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1588 $result = $ecmfile->fetch(0,
'', $rel_filetodelete);
1589 if ($result >= 0 && $ecmfile->id > 0) {
1590 $result = $ecmfile->delete($user);
1598 dol_syslog(
"Failed to remove file ".$filename, LOG_WARNING);
1605 dol_syslog(
"No files to delete found", LOG_DEBUG);
1610 $ok = @unlink($file_osencoded);
1612 $ok = unlink($file_osencoded);
1615 if (empty($nolog)) {
1616 dol_syslog(
"Removed file ".$file_osencoded, LOG_DEBUG);
1619 dol_syslog(
"Failed to remove file ".$file_osencoded, LOG_WARNING);
1640 if (preg_match(
'/\.\./', $dir) || preg_match(
'/[<>|]/', $dir)) {
1641 dol_syslog(
"Refused to delete dir ".$dir.
' (contains invalid char sequence)', LOG_WARNING);
1646 return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1662function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0, $indexdatabase = 1, $nolog = 0, $level = 0)
1664 if (empty($nolog) || empty($level)) {
1665 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1667 if ($level > 1000) {
1668 dol_syslog(
"functions.lib:dol_delete_dir_recursive too many depth", LOG_WARNING);
1673 if ($handle = opendir(
"$dir_osencoded")) {
1674 while (
false !== ($item = readdir($handle))) {
1676 $item = mb_convert_encoding($item,
'UTF-8',
'ISO-8859-1');
1679 if ($item !=
"." && $item !=
"..") {
1681 $count =
dol_delete_dir_recursive(
"$dir/$item", $count, $nophperrors, 0, $countdeleted, $indexdatabase, $nolog, ($level + 1));
1683 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0,
null,
false, $indexdatabase, $nolog);
1695 if (empty($onlysub)) {
1720 global $langs,
$conf;
1725 if (
$object->element ==
'order_supplier') {
1726 $dir =
$conf->fournisseur->commande->dir_output;
1727 } elseif (
$object->element ==
'invoice_supplier') {
1728 $dir =
$conf->fournisseur->facture->dir_output;
1729 } elseif (
$object->element ==
'project') {
1730 $dir =
$conf->project->dir_output;
1731 } elseif (
$object->element ==
'shipping') {
1732 $dir =
$conf->expedition->dir_output.
'/sending';
1733 } elseif (
$object->element ==
'delivery') {
1734 $dir =
$conf->expedition->dir_output.
'/receipt';
1735 } elseif (
$object->element ==
'fichinter') {
1736 $dir =
$conf->ficheinter->dir_output;
1738 $dir = empty(
$conf->$element->dir_output) ?
'' :
$conf->$element->dir_output;
1742 $object->error = $langs->trans(
'ErrorObjectNoSupportedByFunction');
1747 $dir = $dir.
"/".$refsan;
1748 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1749 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1750 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1753 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1755 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1759 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1761 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1766 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1768 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1772 $multiple = $filepreviewold.
".";
1773 for ($i = 0; $i < 20; $i++) {
1774 $preview = $multiple.$i;
1776 if (file_exists($preview) && is_writable($preview)) {
1778 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1808 if (
$object->element ==
'order_supplier') {
1809 $dir =
$conf->fournisseur->dir_output.
'/commande';
1810 } elseif (
$object->element ==
'invoice_supplier') {
1811 $dir =
$conf->fournisseur->dir_output.
'/facture';
1812 } elseif (
$object->element ==
'project') {
1813 $dir =
$conf->project->dir_output;
1814 } elseif (
$object->element ==
'shipping') {
1815 $dir =
$conf->expedition->dir_output.
'/sending';
1816 } elseif (
$object->element ==
'delivery') {
1817 $dir =
$conf->expedition->dir_output.
'/receipt';
1818 } elseif (
$object->element ==
'fichinter') {
1819 $dir =
$conf->ficheinter->dir_output;
1821 $dir = empty(
$conf->$element->dir_output) ?
'' :
$conf->$element->dir_output;
1828 $dir = $dir.
"/".$objectref;
1829 $file = $dir.
"/".$objectref.
".meta";
1831 if (!is_dir($dir)) {
1838 $nblines = count(
$object->lines);
1843 $meta =
"REFERENCE=\"".$object->ref.
"\"
1845 NB_ITEMS=\"" . $nblines.
"\"
1846 CLIENT=\"" . $client.
"\"
1847 AMOUNT_EXCL_TAX=\"" .
$object->total_ht.
"\"
1848 AMOUNT=\"" .
$object->total_ttc.
"\"\n";
1850 for ($i = 0; $i < $nblines; $i++) {
1852 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".
$object->lines[$i]->qty.
"\"
1853 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".
$object->lines[$i]->total_ht.
"\"
1854 ITEM_" . $i.
"_VAT=\"".
$object->lines[$i]->tva_tx.
"\"
1855 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br(
$object->lines[$i]->desc)).
"\"
1860 $fp = fopen($file,
"w");
1868 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.
$object->element, LOG_WARNING);
1886 $listofpaths = array();
1887 $listofnames = array();
1888 $listofmimes = array();
1892 foreach ($listoffiles as $key => $val) {
1893 $listofpaths[] = $val[
'fullname'];
1894 $listofnames[] = $val[
'name'];
1898 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1899 $_SESSION[
"listofpaths".$keytoavoidconflict] = implode(
';', $listofpaths);
1900 $_SESSION[
"listofnames".$keytoavoidconflict] = implode(
';', $listofnames);
1901 $_SESSION[
"listofmimes".$keytoavoidconflict] = implode(
';', $listofmimes);
1923function dol_add_file_process($upload_dir, $allowoverwrite = 0, $updatesessionordb = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1,
$object =
null, $forceFullTestIndexation =
'')
1925 global $db, $user,
$conf, $langs;
1929 if (!empty($_FILES[$varfiles])) {
1930 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' updatesessionordb='.$updatesessionordb.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1931 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
1932 if (is_array($_FILES[$varfiles][
"name"]) && count($_FILES[$varfiles][
"name"]) > $maxfilesinform) {
1933 $langs->load(
"errors");
1934 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
1942 $TFile = $_FILES[$varfiles];
1944 if (!is_array($TFile[
'name'])) {
1945 foreach ($TFile as $key => &$val) {
1950 $nbfile = count($TFile[
'name']);
1952 for ($i = 0; $i < $nbfile; $i++) {
1953 if (empty($TFile[
'name'][$i])) {
1958 $destfile = trim($TFile[
'name'][$i]);
1959 $destfull = $upload_dir.
"/".$destfile;
1960 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1962 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1963 $destfile = trim(preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask));
1964 $destfull = $upload_dir.
"/".$destfile;
1967 $filenameto = basename($destfile);
1968 if (preg_match(
'/^\./', $filenameto)) {
1969 $langs->load(
"errors");
1970 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
1974 $info = pathinfo($destfull);
1975 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1976 $info = pathinfo($destfile);
1977 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1985 global $dolibarr_main_restrict_os_commands;
1986 if (!empty($dolibarr_main_restrict_os_commands)) {
1987 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1988 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1989 if (in_array($destfile, $arrayofallowedcommand)) {
1990 $langs->load(
"errors");
1991 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
1997 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
1999 if (is_numeric($resupload) && $resupload > 0) {
2000 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2003 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
2004 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
2005 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
2006 $maxheightmini = $tmparraysize[
'maxheightmini'];
2011 if ($generatethumbs) {
2017 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
2020 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
2025 if (empty($updatesessionordb)) {
2026 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2028 $formmail->trackid = $trackid;
2029 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
2033 if ($updatesessionordb == 1) {
2035 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false &&
getDolGlobalString(
'PRODUCT_ALLOW_EXTERNAL_DOWNLOAD')) {
2040 if ($allowoverwrite) {
2044 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile,
$object);
2046 if ($allowoverwrite) {
2049 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
2056 $langs->load(
"errors");
2057 if (is_numeric($resupload) && $resupload < 0) {
2059 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
2060 if (preg_match(
'/File is a PDF with javascript inside/', $resupload)) {
2061 setEventMessages($langs->trans(
"ErrorFileIsAnInfectedPDFWithJSInside"),
null,
'errors');
2075 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
2078 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2079 $linkObject =
new Link($db);
2080 $linkObject->entity =
$conf->entity;
2081 $linkObject->url = $link;
2082 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
2083 $linkObject->objectid =
GETPOSTINT(
'objectid');
2084 $linkObject->label =
GETPOST(
'label',
'alpha');
2085 $res = $linkObject->create($user);
2093 $langs->load(
"errors");
2094 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
2114 global $db, $user,
$conf, $langs, $_FILES;
2116 $keytodelete = $filenb;
2119 $listofpaths = array();
2120 $listofnames = array();
2121 $listofmimes = array();
2122 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
2123 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
2124 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
2126 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
2127 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
2129 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
2130 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
2133 if ($keytodelete >= 0) {
2134 $pathtodelete = $listofpaths[$keytodelete];
2135 $filetodelete = $listofnames[$keytodelete];
2136 if (empty($donotdeletefile)) {
2142 if (empty($donotdeletefile)) {
2143 $langs->load(
"other");
2144 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
2146 if (empty($donotupdatesession)) {
2147 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2149 $formmail->trackid = $trackid;
2150 $formmail->remove_attached_files($keytodelete);
2173 global $db, $user,
$conf;
2178 dol_syslog(
"addFileIntoDatabaseIndex dir=".$dir.
" file=".$file, LOG_DEBUG);
2180 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2182 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
2183 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
2184 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2185 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2187 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
2189 $ecmfile->filepath = $rel_dir;
2190 $ecmfile->filename = $filename;
2191 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
2192 $ecmfile->fullpath_orig = $fullpathorig;
2193 $ecmfile->gen_or_uploaded = $mode;
2194 $ecmfile->description =
'';
2195 $ecmfile->keywords =
'';
2198 $ecmfile->src_object_id =
$object->id;
2199 if (isset(
$object->table_element)) {
2200 $ecmfile->src_object_type =
$object->table_element;
2202 dol_syslog(
'Error: object ' . get_class(
$object) .
' has no table_element attribute.');
2205 if (isset(
$object->src_object_description)) {
2206 $ecmfile->description =
$object->src_object_description;
2208 if (isset(
$object->src_object_keywords)) {
2209 $ecmfile->keywords =
$object->src_object_keywords;
2218 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2224 if (empty($useFullTextIndexation) && $forceFullTextIndexation ==
'1') {
2226 $useFullTextIndexation =
'pdftotext';
2228 $useFullTextIndexation =
'docling';
2233 if ($useFullTextIndexation) {
2234 $ecmfile->filepath = $rel_dir;
2235 $ecmfile->filename = $filename;
2237 $filetoprocess = $dir.
'/'.$ecmfile->filename;
2239 $textforfulltextindex =
'';
2242 if (preg_match(
'/\.pdf/i', $filename)) {
2248 if (preg_match(
'/pdftotext/i', $useFullTextIndexation)) {
2249 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2250 $utils =
new Utils($db);
2251 $outputfile =
$conf->admin->dir_temp.
'/tmppdftotext.'.$user->id.
'.out';
2255 $cmd =
getDolGlobalString(
'MAIN_SAVE_FILE_CONTENT_AS_TEXT_PDFTOTEXT',
'pdftotext').
" -htmlmeta '".escapeshellcmd($filetoprocess).
"' - ";
2256 $resultexec = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2258 if (!$resultexec[
'error']) {
2259 $txt = $resultexec[
'output'];
2261 if (preg_match(
'/<meta name="Keywords" content="([^\/]+)"\s*\/>/i', $txt, $matches)) {
2262 $keywords = $matches[1];
2264 if (preg_match(
'/<pre>(.*)<\/pre>/si', $txt, $matches)) {
2274 if (preg_match(
'/docling/i', $useFullTextIndexation)) {
2275 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2276 $utils =
new Utils($db);
2277 $outputfile =
$conf->admin->dir_temp.
'/tmpdocling.'.$user->id.
'.out';
2281 $cmd =
getDolGlobalString(
'MAIN_SAVE_FILE_CONTENT_AS_TEXT_DOCLING',
'docling').
" --from pdf --to text '".escapeshellcmd($filetoprocess).
"'";
2282 $resultexec = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2284 if (!$resultexec[
'error']) {
2285 $txt = $resultexec[
'output'];
2293 $textforfulltextindex = $txt;
2302 $ecmfile->description =
'File content generated by '.$cmd;
2304 $ecmfile->content = $textforfulltextindex;
2305 $ecmfile->keywords = $keywords;
2309 $result = $ecmfile->create($user);
2334 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
2338 dol_syslog(
"deleteFilesIntoDatabaseIndex dir=".$dir.
" file=".$file, LOG_DEBUG);
2342 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2344 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
2345 $filename = basename($file);
2346 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2347 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2350 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
2351 $sql .=
' WHERE entity = '.((int)
$conf->entity);
2352 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
2354 $sql .=
" AND filename = '".$db->escape($file).
"'";
2357 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
2360 $resql = $db->query($sql);
2363 dol_syslog(__FUNCTION__.
' '.$db->lasterror(), LOG_ERR);
2392 if (class_exists(
'Imagick')) {
2393 $image =
new Imagick();
2395 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
2397 $ret = $image->readImage($filetoconvert);
2399 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
2400 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);
2404 $ret = $image->setImageFormat($ext);
2406 if (empty($fileoutput)) {
2407 $fileoutput = $fileinput.
".".$ext;
2410 $count = $image->getNumberImages();
2412 if (!
dol_is_file($fileoutput) || is_writable($fileoutput)) {
2414 $ret = $image->writeImages($fileoutput,
true);
2419 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2449function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring =
null)
2455 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2458 $compressdata =
null;
2459 if ($mode ==
'gz' && function_exists(
'gzencode')) {
2461 $compressdata = gzencode($data, 9);
2462 } elseif ($mode ==
'bz' && function_exists(
'bzcompress')) {
2464 $compressdata = bzcompress($data, 9);
2465 } elseif ($mode ==
'zstd' && function_exists(
'zstd_compress')) {
2467 $compressdata = zstd_compress($data, 9);
2468 } elseif ($mode ==
'zip') {
2469 if (class_exists(
'ZipArchive') &&
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS')) {
2472 $rootPath = realpath($inputfile);
2474 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2475 $zip =
new ZipArchive();
2477 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2478 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2482 $errormsg = $errorstring;
2489 $files =
new RecursiveIteratorIterator(
2490 new RecursiveDirectoryIterator($rootPath, FilesystemIterator::UNIX_PATHS),
2491 RecursiveIteratorIterator::LEAVES_ONLY
2493 '@phan-var-force SplFileInfo[] $files';
2495 foreach ($files as $name => $file) {
2497 if (!$file->isDir()) {
2499 $filePath = $file->getPath();
2500 $fileName = $file->getFilename();
2501 $fileFullRealPath = $file->getRealPath();
2504 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2507 $zip->addFile($fileFullRealPath, $relativePath);
2514 dol_syslog(
"dol_compress_file success - ".$zip->numFiles.
" files");
2518 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2521 include_once ODTPHP_PATHTOPCLZIP.
'pclzip.lib.php';
2522 $archive =
new PclZip($outputfile);
2524 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2526 if ($result === 0) {
2528 $errormsg = $archive->errorInfo(
true);
2530 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2531 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2532 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2536 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2537 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2540 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2546 if ($foundhandler && is_string($compressdata)) {
2547 $fp = fopen($outputfile,
"w");
2548 fwrite($fp, $compressdata);
2552 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2556 $errormsg = $errorstring;
2560 global $langs, $errormsg;
2561 $langs->load(
"errors");
2562 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2564 $errorstring =
"Failed to open file ".$outputfile;
2582 $fileinfo = pathinfo($inputfile);
2583 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2585 if ($fileinfo[
"extension"] ==
"zip") {
2586 if (defined(
'ODTPHP_PATHTOPCLZIP') && !
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS')) {
2587 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2588 include_once ODTPHP_PATHTOPCLZIP.
'pclzip.lib.php';
2589 $archive =
new PclZip($inputfile);
2596 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2598 return array(
'error' => $e->getMessage());
2601 if (!is_array($result) && $result <= 0) {
2602 return array(
'error' => $archive->errorInfo(
true));
2607 foreach ($result as $key => $val) {
2608 if ($val[
'status'] ==
'path_creation_fail') {
2609 $langs->load(
"errors");
2611 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2614 if ($val[
'status'] ==
'write_protected') {
2615 $langs->load(
"errors");
2617 $errmsg = $langs->trans(
"ErrorFailToCreateFile", $val[
'filename']);
2625 return array(
'error' => $errmsg);
2630 if (class_exists(
'ZipArchive')) {
2631 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2632 $zip =
new ZipArchive();
2633 $res = $zip->open($inputfile);
2634 if ($res ===
true) {
2640 for ($i = 0; $i < $zip->numFiles; $i++) {
2641 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2642 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2645 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2651 return array(
'error' =>
'ErrUnzipFails');
2655 return array(
'error' =>
'ErrNoZipEngine');
2656 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2657 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2658 $utils =
new Utils($db);
2665 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2666 if ($extension ==
"tar") {
2669 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2670 if ($resarray[
"result"] != 0) {
2671 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2675 if ($fileinfo[
"extension"] ==
"gz") {
2677 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2679 } elseif ($fileinfo[
"extension"] ==
"zst") {
2682 return array(
'error' =>
'ErrorBadFileExtension');
2685 $cmd .=
' > '.$outputfilename;
2687 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0,
null, 1, $outputfilename.
'.err');
2688 if ($resarray[
"result"] != 0) {
2689 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2690 if ($errfilecontent) {
2691 $resarray[
"error"] .=
" - ".$errfilecontent;
2695 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2698 return array(
'error' =>
'ErrorBadFileExtension');
2714function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'', $newmask =
'0')
2718 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2720 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2721 global $langs, $errormsg;
2722 $langs->load(
"errors");
2723 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2728 if ($mode ==
'gz') {
2730 } elseif ($mode ==
'bz') {
2732 } elseif ($mode ==
'zip') {
2746 if (class_exists(
'ZipArchive')) {
2750 $zip =
new ZipArchive();
2751 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2752 if ($result !==
true) {
2753 global $langs, $errormsg;
2754 $langs->load(
"errors");
2755 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile);
2762 $files =
new RecursiveIteratorIterator(
2763 new RecursiveDirectoryIterator($inputdir, FilesystemIterator::UNIX_PATHS),
2764 RecursiveIteratorIterator::LEAVES_ONLY
2766 '@phan-var-force SplFileInfo[] $files';
2769 foreach ($files as $name => $file) {
2771 if (!$file->isDir()) {
2773 $filePath = $file->getPath();
2774 $fileName = $file->getFilename();
2775 $fileFullRealPath = $file->getRealPath();
2778 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2781 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2783 $zip->addFile($fileFullRealPath, $relativePath);
2794 if (empty($newmask)) {
2795 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
2805 if (!$foundhandler) {
2806 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2812 global $langs, $errormsg;
2813 $langs->load(
"errors");
2814 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2816 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile).
' - '.$e->getMessage();
2833function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook = 0, $mode = 0)
2835 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2836 return isset($tmparray[0]) ? $tmparray[0] :
null;
2854 global
$conf, $db, $user, $hookmanager;
2855 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2858 if (!is_object($fuser)) {
2862 if (empty($modulepart)) {
2863 return 'ErrorBadParameter';
2865 if (empty($entity)) {
2866 if (!isModEnabled(
'multicompany')) {
2873 if ($modulepart ==
'facture') {
2874 $modulepart =
'invoice';
2875 } elseif ($modulepart ==
'users') {
2876 $modulepart =
'user';
2877 } elseif ($modulepart ==
'tva') {
2878 $modulepart =
'tax-vat';
2879 } elseif ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
2881 $modulepart =
'delivery';
2882 } elseif ($modulepart ==
'propale') {
2883 $modulepart =
'propal';
2887 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2891 $sqlprotectagainstexternals =
'';
2895 if (empty($refname)) {
2896 $refname = basename(dirname($original_file).
"/");
2897 if ($refname ==
'thumbs' || $refname ==
'temp') {
2899 $refname = basename(dirname(dirname($original_file)).
"/");
2906 $download =
'download';
2907 if ($mode ==
'write') {
2910 $download =
'upload';
2914 if ($modulepart ==
'common') {
2917 $original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/'.$original_file;
2918 } elseif ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2923 if (empty($entity)) {
2927 $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;
2928 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2930 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
2931 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2932 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2934 $accessallowed = $user->admin;
2935 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2936 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2938 $accessallowed = ($fuser->hasRight(
'website',
'write') && preg_match(
'/\.jpg$/i', basename($original_file)));
2939 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2940 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2943 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2946 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2947 $original_file = $dirins.
'/'.$original_file;
2948 } elseif ($modulepart ==
'mycompany' && !empty(
$conf->mycompany->dir_output)) {
2951 $original_file =
$conf->mycompany->dir_output.
'/'.$original_file;
2952 } elseif ($modulepart ==
'userphoto' && !empty(
$conf->user->dir_output)) {
2955 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2958 $original_file =
$conf->user->dir_output.
'/'.$original_file;
2959 } elseif ($modulepart ==
'userphotopublic' && !empty(
$conf->user->dir_output)) {
2964 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
2966 $tmpobject =
new User($db);
2967 $tmpobject->fetch($reg[1],
'',
'', 1);
2969 $securekey =
GETPOST(
'securekey',
'alpha', 1);
2971 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
2972 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
2973 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
2974 if ($encodedsecurekey == $securekey) {
2983 $original_file =
$conf->user->dir_output.
'/'.$original_file;
2984 } elseif (($modulepart ==
'companylogo') && !empty(
$conf->mycompany->dir_output)) {
2987 $original_file =
$conf->mycompany->dir_output.
'/logos/'.$original_file;
2988 } elseif ($modulepart ==
'memberphoto' && !empty(
$conf->member->dir_output)) {
2991 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2994 $original_file =
$conf->member->dir_output.
'/'.$original_file;
2995 } elseif ($modulepart ==
'apercufacture' && !empty(
$conf->invoice->multidir_output[$entity])) {
2997 if ($fuser->hasRight(
'facture', $lire)) {
3000 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
3001 } elseif ($modulepart ==
'apercupropal' && !empty(
$conf->propal->multidir_output[$entity])) {
3003 if ($fuser->hasRight(
'propal', $lire)) {
3006 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
3007 } elseif ($modulepart ==
'apercucommande' && !empty(
$conf->order->multidir_output[$entity])) {
3009 if ($fuser->hasRight(
'commande', $lire)) {
3012 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
3013 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty(
$conf->ficheinter->dir_output)) {
3015 if ($fuser->hasRight(
'ficheinter', $lire)) {
3018 $original_file =
$conf->ficheinter->dir_output.
'/'.$original_file;
3019 } elseif (($modulepart ==
'apercucontract') && !empty(
$conf->contract->multidir_output[$entity])) {
3021 if ($fuser->hasRight(
'contrat', $lire)) {
3024 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
3025 } elseif (($modulepart ==
'apercusupplier_proposal') && !empty(
$conf->supplier_proposal->dir_output)) {
3027 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
3030 $original_file =
$conf->supplier_proposal->dir_output.
'/'.$original_file;
3031 } elseif (($modulepart ==
'apercusupplier_order') && !empty(
$conf->fournisseur->commande->dir_output)) {
3033 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3036 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3037 } elseif (($modulepart ==
'apercusupplier_invoice') && !empty(
$conf->fournisseur->facture->dir_output)) {
3039 if ($fuser->hasRight(
'fournisseur', $lire)) {
3042 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3043 } elseif (($modulepart ==
'holiday') && !empty(
$conf->holiday->dir_output)) {
3044 if ($fuser->hasRight(
'holiday', $read) || $fuser->hasRight(
'holiday',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3047 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3048 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
3049 $tmpholiday =
new Holiday($db);
3050 $tmpholiday->fetch(0, $refname);
3051 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
3054 $original_file =
$conf->holiday->dir_output.
'/'.$original_file;
3055 } elseif (($modulepart ==
'expensereport') && !empty(
$conf->expensereport->dir_output)) {
3056 if ($fuser->hasRight(
'expensereport', $lire) || $fuser->hasRight(
'expensereport',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3059 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3060 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
3062 $tmpexpensereport->fetch(0, $refname);
3063 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
3066 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3067 } elseif (($modulepart ==
'apercuexpensereport') && !empty(
$conf->expensereport->dir_output)) {
3069 if ($fuser->hasRight(
'expensereport', $lire)) {
3072 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3073 } elseif ($modulepart ==
'propalstats' && !empty(
$conf->propal->multidir_temp[$entity])) {
3075 if ($fuser->hasRight(
'propal', $lire)) {
3078 $original_file =
$conf->propal->multidir_temp[$entity].
'/'.$original_file;
3079 } elseif ($modulepart ==
'orderstats' && !empty(
$conf->order->dir_temp)) {
3081 if ($fuser->hasRight(
'commande', $lire)) {
3084 $original_file =
$conf->order->dir_temp.
'/'.$original_file;
3085 } elseif ($modulepart ==
'orderstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3086 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3089 $original_file =
$conf->fournisseur->commande->dir_temp.
'/'.$original_file;
3090 } elseif ($modulepart ==
'billstats' && !empty(
$conf->invoice->dir_temp)) {
3092 if ($fuser->hasRight(
'facture', $lire)) {
3095 $original_file =
$conf->invoice->dir_temp.
'/'.$original_file;
3096 } elseif ($modulepart ==
'billstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3097 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
3100 $original_file =
$conf->fournisseur->facture->dir_temp.
'/'.$original_file;
3101 } elseif ($modulepart ==
'expeditionstats' && !empty(
$conf->expedition->dir_temp)) {
3103 if ($fuser->hasRight(
'expedition', $lire)) {
3106 $original_file =
$conf->expedition->dir_temp.
'/'.$original_file;
3107 } elseif ($modulepart ==
'tripsexpensesstats' && !empty(
$conf->deplacement->dir_temp)) {
3109 if ($fuser->hasRight(
'deplacement', $lire)) {
3112 $original_file =
$conf->deplacement->dir_temp.
'/'.$original_file;
3113 } elseif ($modulepart ==
'memberstats' && !empty(
$conf->member->dir_temp)) {
3115 if ($fuser->hasRight(
'adherent', $lire)) {
3118 $original_file =
$conf->member->dir_temp.
'/'.$original_file;
3119 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty(
$conf->product->dir_temp)) {
3121 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
3124 $original_file = (!empty(
$conf->product->multidir_temp[$entity]) ?
$conf->product->multidir_temp[$entity] :
$conf->service->multidir_temp[$entity]).
'/'.$original_file;
3125 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty(
$conf->tax->dir_output)) {
3127 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
3130 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
3131 $original_file =
$conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
3132 } elseif ($modulepart ==
'actions' && !empty(
$conf->agenda->dir_output)) {
3134 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3137 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3138 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3140 $tmpobject->fetch((
int) $refname);
3141 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3142 if ($user->socid && $tmpobject->socid) {
3147 $original_file =
$conf->agenda->dir_output.
'/'.$original_file;
3148 } elseif ($modulepart ==
'category' && !empty(
$conf->categorie->multidir_output[$entity])) {
3150 if (empty($entity) || empty(
$conf->categorie->multidir_output[$entity])) {
3151 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3153 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
3156 $original_file =
$conf->categorie->multidir_output[$entity].
'/'.$original_file;
3157 } elseif ($modulepart ==
'prelevement' && !empty(
$conf->prelevement->dir_output)) {
3159 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3162 $original_file =
$conf->prelevement->dir_output.
'/'.$original_file;
3163 } elseif ($modulepart ==
'graph_stock' && !empty(
$conf->stock->dir_temp)) {
3166 $original_file =
$conf->stock->dir_temp.
'/'.$original_file;
3167 } elseif ($modulepart ==
'graph_fourn' && !empty(
$conf->fournisseur->dir_temp)) {
3170 $original_file =
$conf->fournisseur->dir_temp.
'/'.$original_file;
3171 } elseif ($modulepart ==
'graph_product' && !empty(
$conf->product->dir_temp)) {
3174 $original_file =
$conf->product->multidir_temp[$entity].
'/'.$original_file;
3175 } elseif ($modulepart ==
'barcode') {
3180 $original_file =
'';
3181 } elseif ($modulepart ==
'iconmailing' && !empty(
$conf->mailing->dir_temp)) {
3184 $original_file =
$conf->mailing->dir_temp.
'/'.$original_file;
3185 } elseif ($modulepart ==
'scanner_user_temp' && !empty(
$conf->scanner->dir_temp)) {
3188 $original_file =
$conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3189 } elseif ($modulepart ==
'fckeditor' && !empty(
$conf->fckeditor->dir_output)) {
3192 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3193 } elseif ($modulepart ==
'user' && !empty(
$conf->user->dir_output)) {
3195 $canreaduser = (!empty($fuser->admin) || $fuser->hasRight(
'user',
'user', $lire));
3196 if ($fuser->id == (
int) $refname) {
3199 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3202 $original_file =
$conf->user->dir_output.
'/'.$original_file;
3203 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty(
$conf->societe->multidir_output[$entity])) {
3205 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3206 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3208 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3211 $original_file =
$conf->societe->multidir_output[$entity].
'/'.$original_file;
3212 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
3213 } elseif ($modulepart ==
'contact' && !empty(
$conf->societe->multidir_output[$entity])) {
3215 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3216 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3218 if ($fuser->hasRight(
'societe', $lire)) {
3221 $original_file =
$conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3222 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty(
$conf->invoice->multidir_output[$entity])) {
3224 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3227 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
3228 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3229 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty(
$conf->propal->multidir_output[$entity])) {
3231 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3234 $original_file =
$conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3235 } elseif ($modulepart ==
'massfilesarea_orders') {
3236 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3239 $original_file =
$conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3240 } elseif ($modulepart ==
'massfilesarea_sendings') {
3241 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3244 $original_file =
$conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3245 } elseif ($modulepart ==
'massfilesarea_receipts') {
3246 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3249 $original_file =
$conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3250 } elseif ($modulepart ==
'massfilesarea_invoices') {
3251 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3254 $original_file =
$conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3255 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3256 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3259 $original_file =
$conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3260 } elseif ($modulepart ==
'massfilesarea_interventions') {
3261 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3264 $original_file =
$conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3265 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty(
$conf->supplier_proposal->dir_output)) {
3266 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3269 $original_file =
$conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3270 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3271 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3274 $original_file =
$conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3275 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3276 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3279 $original_file =
$conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3280 } elseif ($modulepart ==
'massfilesarea_contract' && !empty(
$conf->contract->dir_output)) {
3281 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3284 $original_file =
$conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3285 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty(
$conf->ficheinter->dir_output)) {
3287 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3290 $original_file =
$conf->ficheinter->dir_output.
'/'.$original_file;
3291 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3292 } elseif ($modulepart ==
'deplacement' && !empty(
$conf->deplacement->dir_output)) {
3294 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3297 $original_file =
$conf->deplacement->dir_output.
'/'.$original_file;
3299 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset(
$conf->propal->multidir_output[$entity])) {
3301 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3304 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
3305 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3306 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty(
$conf->order->multidir_output[$entity])) {
3308 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3311 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
3312 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3313 } elseif ($modulepart ==
'project' && !empty(
$conf->project->multidir_output[$entity])) {
3315 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3318 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3319 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3320 $tmpproject =
new Project($db);
3321 $tmpproject->fetch(0, $refname);
3322 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3325 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3326 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3327 } elseif ($modulepart ==
'project_task' && !empty(
$conf->project->multidir_output[$entity])) {
3328 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3331 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3332 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3333 $tmptask =
new Task($db);
3334 $tmptask->fetch(0, $refname);
3335 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3338 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3339 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3340 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty(
$conf->fournisseur->commande->dir_output)) {
3342 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3345 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3346 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3347 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty(
$conf->fournisseur->facture->dir_output)) {
3349 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3352 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3353 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3354 } elseif ($modulepart ==
'supplier_payment') {
3356 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3359 $original_file =
$conf->fournisseur->payment->dir_output.
'/'.$original_file;
3360 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3361 } elseif ($modulepart ==
'payment') {
3363 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3366 $original_file =
$conf->compta->payment->dir_output.
'/'.$original_file;
3367 } elseif ($modulepart ==
'facture_paiement' && !empty(
$conf->invoice->dir_output)) {
3369 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3372 if ($fuser->socid > 0) {
3373 $original_file =
$conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3375 $original_file =
$conf->invoice->dir_output.
'/payments/'.$original_file;
3377 } elseif ($modulepart ==
'export_compta' && !empty(
$conf->accounting->dir_output)) {
3379 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3382 $original_file =
$conf->accounting->dir_output.
'/'.$original_file;
3383 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty(
$conf->expedition->dir_output)) {
3385 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3388 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3390 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty(
$conf->expedition->dir_output)) {
3392 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3395 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3396 } elseif ($modulepart ==
'actionsreport' && !empty(
$conf->agenda->dir_temp)) {
3398 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3401 $original_file =
$conf->agenda->dir_temp.
"/".$original_file;
3402 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3404 if (empty($entity) || (empty(
$conf->product->multidir_output[$entity]) && empty(
$conf->service->multidir_output[$entity]))) {
3405 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3407 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3410 if (isModEnabled(
"product")) {
3411 $original_file =
$conf->product->multidir_output[$entity].
'/'.$original_file;
3412 } elseif (isModEnabled(
"service")) {
3413 $original_file =
$conf->service->multidir_output[$entity].
'/'.$original_file;
3415 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3417 if (empty($entity) || (empty(
$conf->productbatch->multidir_output[$entity]))) {
3418 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3420 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3423 if (isModEnabled(
'productbatch')) {
3424 $original_file =
$conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3426 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3428 if (empty($entity) || empty(
$conf->stock->multidir_output[$entity])) {
3429 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3431 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3434 if (isModEnabled(
'stock')) {
3435 $original_file =
$conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3437 } elseif ($modulepart ==
'contract' && !empty(
$conf->contract->multidir_output[$entity])) {
3439 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3442 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
3443 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3444 } elseif ($modulepart ==
'donation' && !empty(
$conf->don->dir_output)) {
3446 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3449 $original_file =
$conf->don->dir_output.
'/'.$original_file;
3450 } elseif ($modulepart ==
'dolresource' && !empty(
$conf->resource->dir_output)) {
3452 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3455 $original_file =
$conf->resource->dir_output.
'/'.$original_file;
3456 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty(
$conf->bank->dir_output)) {
3458 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3461 $original_file =
$conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3462 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty(
$conf->bank->dir_output)) {
3464 if ($fuser->hasRight(
'banque', $lire)) {
3467 $original_file =
$conf->bank->dir_output.
'/'.$original_file;
3468 } elseif ($modulepart ==
'export' && !empty(
$conf->export->dir_temp)) {
3471 $accessallowed = $user->hasRight(
'export',
'lire');
3472 $original_file =
$conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3473 } elseif ($modulepart ==
'import' && !empty(
$conf->import->dir_temp)) {
3475 $accessallowed = $user->hasRight(
'import',
'run');
3476 $original_file =
$conf->import->dir_temp.
'/'.$original_file;
3477 } elseif ($modulepart ==
'recruitment' && !empty(
$conf->recruitment->dir_output)) {
3479 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3480 $original_file =
$conf->recruitment->dir_output.
'/'.$original_file;
3481 } elseif ($modulepart ==
'editor' && !empty(
$conf->fckeditor->dir_output)) {
3484 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3485 } elseif ($modulepart ==
'systemtools' && !empty(
$conf->admin->dir_output)) {
3487 if ($fuser->admin) {
3490 $original_file =
$conf->admin->dir_output.
'/'.$original_file;
3491 } elseif ($modulepart ==
'admin_temp' && !empty(
$conf->admin->dir_temp)) {
3493 if ($fuser->admin) {
3496 $original_file =
$conf->admin->dir_temp.
'/'.$original_file;
3497 } elseif ($modulepart ==
'bittorrent' && !empty(
$conf->bittorrent->dir_output)) {
3501 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3504 $original_file =
$conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3505 } elseif ($modulepart ==
'member' && !empty(
$conf->member->dir_output)) {
3507 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3510 $original_file =
$conf->member->dir_output.
'/'.$original_file;
3520 if (preg_match(
'/^specimen/i', $original_file)) {
3523 if ($fuser->admin) {
3527 $tmpmodulepart = explode(
'-', $modulepart);
3528 if (!empty($tmpmodulepart[1])) {
3529 $modulepart = $tmpmodulepart[0];
3530 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3535 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3536 $tmpmodule = $reg[1];
3537 if (empty(
$conf->$tmpmodule->dir_temp)) {
3538 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3541 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3544 $original_file =
$conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3545 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3546 $tmpmodule = $reg[1];
3547 if (empty(
$conf->$tmpmodule->dir_temp)) {
3548 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3551 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3554 $original_file =
$conf->$tmpmodule->dir_temp.
'/'.$original_file;
3555 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3556 $tmpmodule = $reg[1];
3557 if (empty(
$conf->$tmpmodule->dir_output)) {
3558 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3561 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3564 $original_file =
$conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3565 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3566 $tmpmodule = $reg[1];
3567 if (empty(
$conf->$tmpmodule->dir_output)) {
3568 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3571 if ($fuser->hasRight($tmpmodule, $lire) || preg_match(
'/^specimen/i', $original_file)) {
3574 $original_file =
$conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3576 if (empty(
$conf->$modulepart->dir_output)) {
3577 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.');
3582 $partsofdirinoriginalfile = explode(
'/', $original_file);
3583 if (!empty($partsofdirinoriginalfile[1])) {
3584 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3585 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3589 if (($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) || ($fuser->hasRight($modulepart,
'all', $lire) || $fuser->hasRight($modulepart,
'all', $read))) {
3593 if (is_array(
$conf->$modulepart->multidir_output) && !empty(
$conf->$modulepart->multidir_output[$entity])) {
3594 $original_file =
$conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3596 $original_file =
$conf->$modulepart->dir_output.
'/'.$original_file;
3600 $parameters = array(
3601 'modulepart' => $modulepart,
3602 'original_file' => $original_file,
3603 'entity' => $entity,
3608 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3610 if (!empty($hookmanager->resArray[
'original_file'])) {
3611 $original_file = $hookmanager->resArray[
'original_file'];
3613 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3614 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3616 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3617 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3623 'accessallowed' => ($accessallowed ? 1 : 0),
3624 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3625 'original_file' => $original_file
3644 dol_syslog(
"Failed to create the cache directory ".$directory, LOG_WARNING);
3647 $cachefile = $directory.$filename;
3649 file_put_contents($cachefile, serialize(
$object), LOCK_EX);
3665 $cachefile = $directory.$filename;
3666 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3679 $cachefile = $directory.$filename;
3680 $object = unserialize(file_get_contents($cachefile));
3692 return preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'\//',
'', $pathfile);
3707function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3711 $exclude =
'install';
3713 foreach ($dir->md5file as $file) {
3714 $filename = $path.$file[
'name'];
3715 $file_list[
'insignature'][] = $filename;
3716 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3717 $expectedmd5 = (string) $file;
3719 if (!file_exists($pathref.
'/'.$filename)) {
3720 $file_list[
'missing'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize);
3722 $md5_local = md5_file($pathref.
'/'.$filename);
3724 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3725 $checksumconcat[] = $expectedmd5;
3727 if ($md5_local != $expectedmd5) {
3728 $file_list[
'updated'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize,
'md5' => (
string) $md5_local);
3730 $checksumconcat[] = $md5_local;
3735 foreach ($dir->dir as $subdir) {
3736 getFilesUpdated($file_list, $subdir, $path.$subdir[
'name'].
'/', $pathref, $checksumconcat);
3754 $out .=
'<div id="'.$htmlname.
'Message" class="dragDropAreaMessage hidden"><span>'.
img_picto(
"",
'download').
'<br>'.$langs->trans(
"DropFileToAddItToObject").
'</span></div>';
3755 $out .=
"\n<!-- JS CODE TO ENABLE DRAG AND DROP OF FILE -->\n";
3758 jQuery(document).ready(function() {
3759 var enterTargetDragDrop = null;
3761 $("#'.$htmlname.
'").addClass("cssDragDropArea");
3763 $(".cssDragDropArea").on("dragenter", function(ev, ui) {
3764 var dataTransfer = ev.originalEvent.dataTransfer;
3765 var dataTypes = dataTransfer.types;
3766 //console.log(dataTransfer);
3767 //console.log(dataTypes);
3769 if (!dataTypes || ($.inArray(\'Files\', dataTypes) === -1)) {
3770 // The element dragged is not a file, so we avoid the "dragenter"
3771 ev.preventDefault();
3775 // Entering drop area. Highlight area
3776 console.log("dragAndDropFileUpload: We add class highlightDragDropArea")
3777 enterTargetDragDrop = ev.target;
3778 $(this).addClass("highlightDragDropArea");
3779 $("#'.$htmlname.
'Message").removeClass("hidden");
3780 ev.preventDefault();
3783 $(".cssDragDropArea").on("dragleave", function(ev) {
3784 // Going out of drop area. Remove Highlight
3785 if (enterTargetDragDrop == ev.target){
3786 console.log("dragAndDropFileUpload: We remove class highlightDragDropArea")
3787 $("#'.$htmlname.
'Message").addClass("hidden");
3788 $(this).removeClass("highlightDragDropArea");
3792 $(".cssDragDropArea").on("dragover", function(ev) {
3793 ev.preventDefault();
3797 $(".cssDragDropArea").on("drop", function(e) {
3800 fd = new FormData();
3804 fd.append("action", "linkit");
3806 var dataTransfer = e.originalEvent.dataTransfer;
3808 if (dataTransfer.files && dataTransfer.files.length){
3809 var droppedFiles = e.originalEvent.dataTransfer.files;
3810 $.each(droppedFiles, function(index,file){
3811 fd.append("files[]", file,file.name)
3814 $(".cssDragDropArea").removeClass("highlightDragDropArea");
3815 counterdragdrop = 0;
3817 url: "'.DOL_URL_ROOT.
'/core/ajax/fileupload.php",
3822 success:function() {
3823 console.log("Uploaded.", arguments);
3824 /* arguments[0] is the json string of files */
3825 /* arguments[1] is the value for variable "success", can be 0 or 1 */
3826 let listoffiles = JSON.parse(arguments[0]);
3827 console.log(listoffiles);
3829 for (let i = 0; i < listoffiles.length; i++) {
3830 console.log(listoffiles[i].error);
3831 if (listoffiles[i].error) {
3835 console.log(nboferror);
3836 if (nboferror > 0) {
3837 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorOnAtLeastOneFileUpload:warnings";
3839 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=UploadFileDragDropSuccess:mesgs";
3843 console.log("Error Uploading.", arguments)
3844 if (arguments[0].status == 403) {
3845 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadPermissionDenied:errors";
3847 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadFileDragDropPermissionDenied:errors";
3853 $out .=
"</script>\n";
3867function archiveOrBackupFile($srcfile, $max_versions = 5, $archivedir =
'', $suffix =
"v", $moveorcopy =
'move')
3869 $base_file_pattern = ($archivedir ? $archivedir : dirname($srcfile)).
'/'.basename($srcfile).
".".$suffix;
3870 $files_in_directory = glob($base_file_pattern .
"*");
3873 $files_with_timestamps = [];
3874 foreach ($files_in_directory as $file) {
3875 $files_with_timestamps[] = [
3877 'timestamp' => filemtime($file)
3883 while (count($files_with_timestamps) > 0) {
3884 $latest_file =
null;
3885 $latest_index =
null;
3888 foreach ($files_with_timestamps as $index => $file_info) {
3889 if ($latest_file ===
null || (is_array($latest_file) && $file_info[
'timestamp'] > $latest_file[
'timestamp'])) {
3890 $latest_file = $file_info;
3891 $latest_index = $index;
3896 if ($latest_file !==
null) {
3897 $sorted_files[] = $latest_file[
'file'];
3898 unset($files_with_timestamps[$latest_index]);
3903 if (count($sorted_files) >= $max_versions) {
3904 $oldest_files = array_slice($sorted_files, $max_versions - 1);
3905 foreach ($oldest_files as $oldest_file) {
3911 $new_backup = $srcfile .
".v" . $timestamp;
3914 if ($moveorcopy ==
'move') {
3915 $result =
dol_move($srcfile, $new_backup,
'0', 1, 0, 0);
3917 $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.
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_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTestIndexation='')
Get and save an upload file (for example after submitting a new file a mail form).
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).
dolCheckOnFileName($src_file, $dest_file='')
Check virus into a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded')
Delete files into database index using search criteria.
dol_readcachefile($directory, $filename)
Read object from cachefile.
dol_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.
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.