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);
264function dol_dir_list_in_database($path, $filter =
"", $excludefilter =
null, $sortcriteria =
"name", $sortorder = SORT_ASC, $mode = 0, $sqlfilters =
"")
269 $sql =
" SELECT rowid, label, entity, filename, filepath, fullpath_orig, keywords, cover, gen_or_uploaded, extraparams,";
270 $sql .=
" date_c, tms as date_m, fk_user_c, fk_user_m, acl, position, share";
272 $sql .=
", description";
274 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ecm_files";
275 $sql .=
" WHERE entity = ".$conf->entity;
276 if (preg_match(
'/%$/', $path)) {
277 $sql .=
" AND filepath LIKE '".$db->escape($path).
"'";
279 $sql .=
" AND filepath = '".$db->escape($path).
"'";
290 $resql = $db->query($sql);
292 $file_list = array();
293 $num = $db->num_rows($resql);
296 $obj = $db->fetch_object($resql);
299 preg_match(
'/([^\/]+)\/[^\/]+$/', DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename, $reg);
300 $level1name = (isset($reg[1]) ? $reg[1] :
'');
301 $file_list[] = array(
302 "rowid" => $obj->rowid,
303 "label" => $obj->label,
304 "name" => $obj->filename,
305 "path" => DOL_DATA_ROOT.
'/'.$obj->filepath,
306 "level1name" => $level1name,
307 "fullname" => DOL_DATA_ROOT.
'/'.$obj->filepath.
'/'.$obj->filename,
308 "fullpath_orig" => $obj->fullpath_orig,
309 "date_c" => $db->jdate($obj->date_c),
310 "date_m" => $db->jdate($obj->date_m),
312 "keywords" => $obj->keywords,
313 "cover" => $obj->cover,
314 "position" => (
int) $obj->position,
316 "share" => $obj->share,
317 "description" => ($mode ? $obj->description :
'')
324 if (!empty($sortcriteria)) {
326 foreach ($file_list as $key => $row) {
327 $myarray[$key] = (isset($row[$sortcriteria]) ? $row[$sortcriteria] :
'');
331 array_multisort($myarray, $sortorder, SORT_REGULAR, $file_list);
353 global
$conf, $db, $user;
359 if ($modulepart ==
'produit' &&
getDolGlobalInt(
'PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
362 if (isModEnabled(
"product")) {
363 $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";
365 $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";
368 $relativedirold = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dirold);
369 $relativedirold = preg_replace(
'/^[\\/]/',
'', $relativedirold);
371 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($relativedirold,
'',
null,
'name', SORT_ASC));
373 } elseif ($modulepart ==
'ticket') {
374 foreach ($filearray as $key => $val) {
375 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'path']);
376 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
377 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
378 if ($rel_dir != $relativedir) {
379 $filearrayindatabase = array_merge($filearrayindatabase,
dol_dir_list_in_database($rel_dir,
'',
null,
'name', SORT_ASC));
389 foreach ($filearray as $key => $val) {
390 $tmpfilename = preg_replace(
'/\.noexe$/',
'', $filearray[$key][
'name']);
393 foreach ($filearrayindatabase as $key2 => $val2) {
394 if (($filearrayindatabase[$key2][
'path'] == $filearray[$key][
'path']) && ($filearrayindatabase[$key2][
'name'] == $tmpfilename)) {
395 $filearray[$key][
'position_name'] = ($filearrayindatabase[$key2][
'position'] ? $filearrayindatabase[$key2][
'position'] :
'0').
'_'.$filearrayindatabase[$key2][
'name'];
396 $filearray[$key][
'position'] = $filearrayindatabase[$key2][
'position'];
397 $filearray[$key][
'cover'] = $filearrayindatabase[$key2][
'cover'];
398 $filearray[$key][
'keywords'] = $filearrayindatabase[$key2][
'keywords'];
399 $filearray[$key][
'acl'] = $filearrayindatabase[$key2][
'acl'];
400 $filearray[$key][
'rowid'] = $filearrayindatabase[$key2][
'rowid'];
401 $filearray[$key][
'label'] = $filearrayindatabase[$key2][
'label'];
402 $filearray[$key][
'share'] = $filearrayindatabase[$key2][
'share'];
409 $filearray[$key][
'position'] =
'999999';
410 $filearray[$key][
'cover'] = 0;
411 $filearray[$key][
'acl'] =
'';
412 $filearray[$key][
'share'] = 0;
414 $rel_filename = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filearray[$key][
'fullname']);
416 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filename)) {
417 dol_syslog(
"list_of_documents We found a file called '".$filearray[$key][
'name'].
"' not indexed into database. We add it");
418 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
422 $filename = basename($rel_filename);
423 $rel_dir = dirname($rel_filename);
424 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
425 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
427 $ecmfile->filepath = $rel_dir;
428 $ecmfile->filename = $filename;
429 $ecmfile->label = md5_file(
dol_osencode($filearray[$key][
'fullname']));
430 $ecmfile->fullpath_orig = $filearray[$key][
'fullname'];
431 $ecmfile->gen_or_uploaded =
'unknown';
432 $ecmfile->description =
'';
433 $ecmfile->keywords =
'';
434 $result = $ecmfile->create($user);
438 $filearray[$key][
'rowid'] = $result;
441 $filearray[$key][
'rowid'] = 0;
458 global $sortorder, $sortfield;
460 $sortorder = strtoupper($sortorder);
462 if ($sortorder ==
'ASC') {
470 if ($sortfield ==
'name') {
471 if ($a->name == $b->name) {
474 return ($a->name < $b->name) ? $retup : $retdown;
476 if ($sortfield ==
'date') {
477 if ($a->date == $b->date) {
480 return ($a->date < $b->date) ? $retup : $retdown;
482 if ($sortfield ==
'size') {
483 if ($a->size == $b->size) {
486 return ($a->size < $b->size) ? $retup : $retdown;
502 if (is_dir($newfolder)) {
517 if (!is_readable($dir)) {
520 return (count(scandir($dir)) == 2);
532 return is_file($newpathoffile);
544 return is_link($newpathoffile);
556 return is_writable($newfolderorfile);
569 $prots = array(
'file',
'http',
'https',
'ftp',
'zlib',
'data',
'ssh',
'ssh2',
'ogg',
'expect');
570 return false !== preg_match(
'/^('.implode(
'|', $prots).
'):/i', $uri);
582 if (is_dir($newfolder)) {
583 $handle = opendir($newfolder);
584 $folder_content =
'';
586 while ((gettype($name = readdir($handle)) !=
"boolean")) {
587 $name_array[] = $name;
589 foreach ($name_array as $temp) {
590 $folder_content .= $temp;
595 if ($folder_content ==
"...") {
618 $fp = fopen($newfile,
'r');
625 if ($line !==
false) {
648 return filesize($newpathoffile);
660 return @filemtime($newpathoffile);
672 return fileperms($newpathoffile);
687function dolReplaceInFile($srcfile, $arrayreplacement, $destfile =
'', $newmask =
'0', $indexdatabase = 0, $arrayreplacementisregex = 0)
689 dol_syslog(
"files.lib.php::dolReplaceInFile srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" indexdatabase=".$indexdatabase.
" arrayreplacementisregex=".$arrayreplacementisregex);
691 if (empty($srcfile)) {
694 if (empty($destfile)) {
695 $destfile = $srcfile;
699 $srcfile = preg_replace(
'/\.\.\/?/',
'', $srcfile);
700 $destfile = preg_replace(
'/\.\.\/?/',
'', $destfile);
703 if (($destfile != $srcfile) && $destexists) {
709 dol_syslog(
"files.lib.php::dolReplaceInFile failed to read src file", LOG_WARNING);
713 $tmpdestfile = $destfile.
'.tmp';
718 $newdirdestfile = dirname($newpathofdestfile);
720 if ($destexists && !is_writable($newpathofdestfile)) {
721 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to overwrite target file", LOG_WARNING);
724 if (!is_writable($newdirdestfile)) {
725 dol_syslog(
"files.lib.php::dolReplaceInFile failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
732 $content = file_get_contents($newpathofsrcfile);
734 if (empty($arrayreplacementisregex)) {
737 foreach ($arrayreplacement as $key => $value) {
738 $content = preg_replace($key, $value, $content);
742 file_put_contents($newpathoftmpdestfile, $content);
743 dolChmod($newpathoftmpdestfile, $newmask);
746 $result =
dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase);
748 dol_syslog(
"files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING);
754 if (empty($newmask)) {
755 dol_syslog(
"Warning: dolReplaceInFile called with empty value for newmask and no default value defined", LOG_WARNING);
759 dolChmod($newpathofdestfile, $newmask);
777function dol_copy($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 0)
781 dol_syslog(
"files.lib.php::dol_copy srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
783 if (empty($srcfile) || empty($destfile)) {
788 if (!$overwriteifexists && $destexists) {
794 $newdirdestfile = dirname($newpathofdestfile);
796 if ($destexists && !is_writable($newpathofdestfile)) {
797 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to overwrite target file", LOG_WARNING);
800 if (!is_writable($newdirdestfile)) {
801 dol_syslog(
"files.lib.php::dol_copy failed Permission denied to write into target directory ".$newdirdestfile, LOG_WARNING);
806 $testvirusarray = array();
809 if (count($testvirusarray)) {
810 dol_syslog(
"files.lib.php::dol_copy canceled because a virus was found into source file. we ignore the copy request.", LOG_WARNING);
816 $result = @copy($newpathofsrcfile, $newpathofdestfile);
819 dol_syslog(
"files.lib.php::dol_copy failed to copy", LOG_WARNING);
825 if (empty($newmask)) {
826 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
830 dolChmod($newpathofdestfile, $newmask);
832 if ($result && $indexdatabase) {
834 $rel_filetocopyafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $newpathofdestfile);
835 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetocopyafter)) {
836 $rel_filetocopyafter = preg_replace(
'/^[\\/]/',
'', $rel_filetocopyafter);
839 dol_syslog(
"Try to copy also entries in database for: ".$rel_filetocopyafter, LOG_DEBUG);
840 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
843 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetocopyafter);
844 if ($resultecmtarget > 0) {
845 dol_syslog(
"ECM dest file found, remove it", LOG_DEBUG);
846 $ecmfiletarget->delete($user);
848 dol_syslog(
"ECM dest file not found, create it", LOG_DEBUG);
852 $resultecm = $ecmSrcfile->fetch(0,
'', $srcfile);
856 dol_syslog(
"Fetch src file error", LOG_DEBUG);
860 $filename = basename($rel_filetocopyafter);
861 $rel_dir = dirname($rel_filetocopyafter);
862 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
863 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
865 $ecmfile->filepath = $rel_dir;
866 $ecmfile->filename = $filename;
868 $ecmfile->fullpath_orig = $srcfile;
869 $ecmfile->gen_or_uploaded =
'copy';
870 $ecmfile->description = $ecmSrcfile->description;
871 $ecmfile->keywords = $ecmSrcfile->keywords;
872 $resultecm = $ecmfile->create($user);
873 if ($resultecm < 0) {
877 dol_syslog(
"Create ECM file error", LOG_DEBUG);
881 if ($resultecm > 0) {
889 return (
int) $result;
906function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement =
null, $excludesubdir = 0, $excludefileext =
null, $excludearchivefiles = 0)
910 dol_syslog(
"files.lib.php::dolCopyDir srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwriteifexists=".$overwriteifexists);
912 if (empty($srcfile) || empty($destfile)) {
923 $dirmaskdec = octdec($newmask);
927 $dirmaskdec |= octdec(
'0200');
929 $result =
dol_mkdir($destfile,
'', decoct($dirmaskdec));
941 if (is_dir($ossrcfile)) {
942 $dir_handle = opendir($ossrcfile);
944 while ($file = readdir($dir_handle)) {
945 if ($file !=
"." && $file !=
".." && !is_link($ossrcfile.
"/".$file)) {
946 if (is_dir($ossrcfile.
"/".$file)) {
947 if (empty($excludesubdir) || ($excludesubdir == 2 && strlen($file) == 2)) {
950 if (is_array($arrayreplacement)) {
951 foreach ($arrayreplacement as $key => $val) {
952 $newfile = str_replace($key, $val, $newfile);
956 $tmpresult =
dolCopyDir($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists, $arrayreplacement, $excludesubdir, $excludefileext, $excludearchivefiles);
961 if (is_array($excludefileext)) {
962 $extension = pathinfo($file, PATHINFO_EXTENSION);
963 if (in_array($extension, $excludefileext)) {
969 if ($excludearchivefiles == 1) {
970 $extension = pathinfo($file, PATHINFO_EXTENSION);
971 if (preg_match(
'/^[v|d]\d+$/', $extension)) {
977 if (is_array($arrayreplacement)) {
978 foreach ($arrayreplacement as $key => $val) {
979 $newfile = str_replace($key, $val, $newfile);
982 $tmpresult =
dol_copy($srcfile.
"/".$file, $destfile.
"/".$newfile, $newmask, $overwriteifexists);
985 if ($result > 0 && $tmpresult >= 0) {
988 $result = $tmpresult;
995 closedir($dir_handle);
1001 return (
int) $result;
1022function dol_move($srcfile, $destfile, $newmask =
'0', $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array())
1027 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
1032 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
1036 if ($overwriteifexists || !$destexists) {
1041 $testvirusarray = array();
1044 $testvirusarray =
dolCheckVirus($newpathofsrcfile, $newpathofdestfile);
1045 if (count($testvirusarray)) {
1046 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1052 if (count($testvirusarray)) {
1053 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. We ignore the move request.", LOG_WARNING);
1058 global $dolibarr_main_restrict_os_commands;
1059 if (!empty($dolibarr_main_restrict_os_commands)) {
1060 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1061 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1062 if (in_array(basename($destfile), $arrayofallowedcommand)) {
1065 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);
1070 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1073 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
1076 $result = @rename($newpathofsrcfile, $newpathofdestfile);
1078 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1083 if ($result && $indexdatabase) {
1085 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1086 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1087 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1088 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1089 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1092 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1093 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1095 $ecmfiletarget =
new EcmFiles($db);
1096 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
1097 if ($resultecmtarget > 0) {
1098 $ecmfiletarget->delete($user);
1102 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
1103 if ($resultecm > 0) {
1104 $filename = basename($rel_filetorenameafter);
1105 $rel_dir = dirname($rel_filetorenameafter);
1106 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1107 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1109 $ecmfile->filepath = $rel_dir;
1110 $ecmfile->filename = $filename;
1112 $resultecm = $ecmfile->update($user);
1113 } elseif ($resultecm == 0) {
1114 $filename = basename($rel_filetorenameafter);
1115 $rel_dir = dirname($rel_filetorenameafter);
1116 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1117 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1119 $ecmfile->filepath = $rel_dir;
1120 $ecmfile->filename = $filename;
1122 $ecmfile->fullpath_orig = basename($srcfile);
1123 if (!empty($moreinfo) && !empty($moreinfo[
'gen_or_uploaded'])) {
1124 $ecmfile->gen_or_uploaded = $moreinfo[
'gen_or_uploaded'];
1126 $ecmfile->gen_or_uploaded =
'uploaded';
1128 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1129 $ecmfile->description = $moreinfo[
'description'];
1131 $ecmfile->description =
'';
1133 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1134 $ecmfile->keywords = $moreinfo[
'keywords'];
1136 $ecmfile->keywords =
'';
1138 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1139 $ecmfile->note_private = $moreinfo[
'note_private'];
1141 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1142 $ecmfile->note_public = $moreinfo[
'note_public'];
1144 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1145 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1147 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1148 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1150 if (!empty($moreinfo) && !empty($moreinfo[
'position'])) {
1151 $ecmfile->position = $moreinfo[
'position'];
1153 if (!empty($moreinfo) && !empty($moreinfo[
'cover'])) {
1154 $ecmfile->cover = $moreinfo[
'cover'];
1157 $resultecm = $ecmfile->create($user);
1158 if ($resultecm < 0) {
1161 if (!empty($moreinfo) && !empty($moreinfo[
'array_options']) && is_array($moreinfo[
'array_options'])) {
1162 $ecmfile->array_options = $moreinfo[
'array_options'];
1163 $resultecm = $ecmfile->insertExtraFields();
1164 if ($resultecm < 0) {
1169 } elseif ($resultecm < 0) {
1173 if ($resultecm > 0) {
1181 if (empty($newmask)) {
1188 dolChmod($newpathofdestfile, $newmask);
1204function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase = 1, $renamedircontent = 1)
1208 dol_syslog(
"files.lib.php::dol_move_dir srcdir=".$srcdir.
" destdir=".$destdir.
" overwritifexists=".$overwriteifexists.
" indexdatabase=".$indexdatabase.
" renamedircontent=".$renamedircontent);
1210 $srcbasename = basename($srcdir);
1214 dol_syslog(
"files.lib.php::dol_move_dir srcdir does not exists. Move fails");
1218 if ($overwriteifexists || !$destexists) {
1225 if ($overwriteifexists) {
1226 if (strtoupper(substr(PHP_OS, 0, 3)) ===
'WIN') {
1227 if (is_dir($newpathofdestdir)) {
1228 @rmdir($newpathofdestdir);
1233 $result = @rename($newpathofsrcdir, $newpathofdestdir);
1236 if ($result && $renamedircontent) {
1237 if (file_exists($newpathofdestdir)) {
1238 $destbasename = basename($newpathofdestdir);
1240 if (!empty($files) && is_array($files)) {
1241 foreach ($files as $key => $file) {
1242 if (!file_exists($file[
"fullname"])) {
1245 $filepath = $file[
"path"];
1246 $oldname = $file[
"name"];
1248 $newname = str_replace($srcbasename, $destbasename, $oldname);
1249 if (!empty($newname) && $newname !== $oldname) {
1250 if ($file[
"type"] ==
"dir") {
1251 $res =
dol_move_dir($filepath.
'/'.$oldname, $filepath.
'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent);
1253 $res =
dol_move($filepath.
'/'.$oldname, $filepath.
'/'.$newname,
'0', $overwriteifexists, 0, $indexdatabase);
1280 return trim(basename($filename),
".\x00..\x20");
1296 if (!empty($reterrors)) {
1301 if (!class_exists(
'AntiVir')) {
1302 require_once DOL_DOCUMENT_ROOT.
'/core/class/antivir.class.php';
1305 $result = $antivir->dol_avscan_file($src_file);
1307 $reterrors = $antivir->errors;
1323 if (preg_match(
'/\.pdf$/i', $dest_file)) {
1325 dol_syslog(
"dolCheckOnFileName Check that pdf does not contains js code");
1327 $tmp = file_get_contents(trim($src_file));
1328 if (preg_match(
'/[\n\s]+\/JavaScript[\n\s]+/m', $tmp)) {
1329 return array(
'File is a PDF with javascript inside');
1332 dol_syslog(
"dolCheckOnFileName Check js into pdf disabled");
1360function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan = 0, $uploaderrorcode = 0, $nohook = 0, $varfiles =
'addedfile', $upload_dir =
'')
1366 $file_name = $dest_file;
1369 if (empty($nohook)) {
1370 $reshook = $hookmanager->initHooks(array(
'fileslib'));
1372 $parameters = array(
'dest_file' => $dest_file,
'src_file' => $src_file,
'file_name' => $file_name,
'varfiles' => $varfiles,
'allowoverwrite' => $allowoverwrite);
1373 $reshook = $hookmanager->executeHooks(
'moveUploadedFile', $parameters,
$object);
1376 if (empty($reshook)) {
1378 if ($uploaderrorcode) {
1379 switch ($uploaderrorcode) {
1380 case UPLOAD_ERR_INI_SIZE:
1381 return 'ErrorFileSizeTooLarge';
1382 case UPLOAD_ERR_FORM_SIZE:
1383 return 'ErrorFileSizeTooLarge';
1384 case UPLOAD_ERR_PARTIAL:
1385 return 'ErrorPartialFile';
1386 case UPLOAD_ERR_NO_TMP_DIR:
1387 return 'ErrorNoTmpDir';
1388 case UPLOAD_ERR_CANT_WRITE:
1389 return 'ErrorFailedToWriteInDir';
1390 case UPLOAD_ERR_EXTENSION:
1391 return 'ErrorUploadBlockedByAddon';
1399 if (empty($disablevirusscan) && file_exists($src_file)) {
1401 if (count($checkvirusarray)) {
1402 dol_syslog(
'Files.lib::dol_move_uploaded_file File "'.$src_file.
'" (target name "'.$dest_file.
'") KO with antivirus: errors='.implode(
',', $checkvirusarray), LOG_WARNING);
1403 return 'ErrorFileIsInfectedWithAVirus: '.implode(
',', $checkvirusarray);
1412 $publicmediasdirwithslash =
$conf->medias->multidir_output[
$conf->entity];
1413 if (!preg_match(
'/\/$/', $publicmediasdirwithslash)) {
1414 $publicmediasdirwithslash .=
'/';
1417 if (strpos($upload_dir, $publicmediasdirwithslash) !== 0 || !
getDolGlobalInt(
"MAIN_DOCUMENT_DISABLE_NOEXE_IN_MEDIAS_DIR")) {
1418 $file_name .=
'.noexe';
1425 if (preg_match(
'/^\./', basename($src_file)) || preg_match(
'/\.\./', $src_file) || preg_match(
'/[<>|]/', $src_file)) {
1426 dol_syslog(
"Refused to deliver file ".$src_file, LOG_WARNING);
1432 if (preg_match(
'/^\./', basename($dest_file)) || preg_match(
'/\.\./', $dest_file) || preg_match(
'/[<>|]/', $dest_file)) {
1433 dol_syslog(
"Refused to deliver file ".$dest_file, LOG_WARNING);
1439 $errmsg = implode(
',', $hookmanager->errors);
1440 if (empty($errmsg)) {
1441 $errmsg =
'ErrorReturnedBySomeHooks';
1444 } elseif (empty($reshook)) {
1450 if (!is_writable(dirname($file_name_osencoded))) {
1451 dol_syslog(
"Files.lib::dol_move_uploaded_file Dir ".dirname($file_name_osencoded).
" is not writable. Return 'ErrorDirNotWritable'", LOG_WARNING);
1452 return 'ErrorDirNotWritable';
1456 if (!$allowoverwrite) {
1457 if (file_exists($file_name_osencoded)) {
1458 dol_syslog(
"Files.lib::dol_move_uploaded_file File ".$file_name.
" already exists. Return 'ErrorFileAlreadyExists'", LOG_WARNING);
1459 return 'ErrorFileAlreadyExists';
1462 if (is_dir($file_name_osencoded)) {
1463 dol_syslog(
"Files.lib::dol_move_uploaded_file A directory with name ".$file_name.
" already exists. Return 'ErrorDirWithFileNameAlreadyExists'", LOG_WARNING);
1464 return 'ErrorDirWithFileNameAlreadyExists';
1469 $return = move_uploaded_file($src_file_osencoded, $file_name_osencoded);
1472 dol_syslog(
"Files.lib::dol_move_uploaded_file Success to move ".$src_file.
" to ".$file_name.
" - Umask=" .
getDolGlobalString(
'MAIN_UMASK'), LOG_DEBUG);
1473 return $successcode;
1475 dol_syslog(
"Files.lib::dol_move_uploaded_file Failed to move ".$src_file.
" to ".$file_name, LOG_ERR);
1480 return $successcode;
1498function dol_delete_file($file, $disableglob = 0, $nophperrors = 0, $nohook = 0,
$object =
null, $allowdotdot =
false, $indexdatabase = 1, $nolog = 0)
1501 global $hookmanager;
1503 if (empty($nolog)) {
1504 dol_syslog(
"dol_delete_file file=".$file.
" disableglob=".$disableglob.
" nophperrors=".$nophperrors.
" nohook=".$nohook);
1509 if ((!$allowdotdot && preg_match(
'/\.\./', $file)) || preg_match(
'/[<>|]/', $file)) {
1510 dol_syslog(
"Refused to delete file ".$file, LOG_WARNING);
1515 if (empty($nohook) && !empty($hookmanager)) {
1516 $hookmanager->initHooks(array(
'fileslib'));
1518 $parameters = array(
1520 'disableglob' => $disableglob,
1521 'nophperrors' => $nophperrors
1523 $reshook = $hookmanager->executeHooks(
'deleteFile', $parameters,
$object);
1526 if (empty($nohook) && $reshook != 0) {
1534 if (empty($disableglob) && !empty($file_osencoded)) {
1536 $globencoded = str_replace(
'[',
'\[', $file_osencoded);
1537 $globencoded = str_replace(
']',
'\]', $globencoded);
1538 $listofdir = glob($globencoded);
1540 if (!empty($listofdir) && is_array($listofdir)) {
1541 foreach ($listofdir as $filename) {
1543 $ok = @unlink($filename);
1545 $ok = unlink($filename);
1549 if (!$ok && file_exists(dirname($filename)) && !(fileperms(dirname($filename)) & 0200)) {
1550 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);
1551 dolChmod(dirname($filename), decoct(fileperms(dirname($filename)) | 0200));
1554 $ok = @unlink($filename);
1556 $ok = unlink($filename);
1561 if (empty($nolog)) {
1562 dol_syslog(
"Removed file ".$filename, LOG_DEBUG);
1566 $rel_filetodelete = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $filename);
1567 if (!preg_match(
'/(\/temp\/|\/thumbs\/|\.meta$)/', $rel_filetodelete)) {
1568 if (is_object($db) && $indexdatabase) {
1569 $rel_filetodelete = preg_replace(
'/^[\\/]/',
'', $rel_filetodelete);
1570 $rel_filetodelete = preg_replace(
'/\.noexe$/',
'', $rel_filetodelete);
1572 dol_syslog(
"Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG);
1573 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1575 $result = $ecmfile->fetch(0,
'', $rel_filetodelete);
1576 if ($result >= 0 && $ecmfile->id > 0) {
1577 $result = $ecmfile->delete($user);
1585 dol_syslog(
"Failed to remove file ".$filename, LOG_WARNING);
1591 dol_syslog(
"No files to delete found", LOG_DEBUG);
1596 $ok = @unlink($file_osencoded);
1598 $ok = unlink($file_osencoded);
1601 if (empty($nolog)) {
1602 dol_syslog(
"Removed file ".$file_osencoded, LOG_DEBUG);
1605 dol_syslog(
"Failed to remove file ".$file_osencoded, LOG_WARNING);
1626 if (preg_match(
'/\.\./', $dir) || preg_match(
'/[<>|]/', $dir)) {
1627 dol_syslog(
"Refused to delete dir ".$dir.
' (contains invalid char sequence)', LOG_WARNING);
1632 return ($nophperrors ? @rmdir($dir_osencoded) : rmdir($dir_osencoded));
1649 if (empty($nolog)) {
1650 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1654 if ($handle = opendir(
"$dir_osencoded")) {
1655 while (
false !== ($item = readdir($handle))) {
1657 $item = mb_convert_encoding($item,
'UTF-8',
'ISO-8859-1');
1660 if ($item !=
"." && $item !=
"..") {
1664 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0,
null,
false, $indexdatabase, $nolog);
1676 if (empty($onlysub)) {
1701 global $langs,
$conf;
1706 if (
$object->element ==
'order_supplier') {
1707 $dir =
$conf->fournisseur->commande->dir_output;
1708 } elseif (
$object->element ==
'invoice_supplier') {
1709 $dir =
$conf->fournisseur->facture->dir_output;
1710 } elseif (
$object->element ==
'project') {
1711 $dir =
$conf->project->dir_output;
1712 } elseif (
$object->element ==
'shipping') {
1713 $dir =
$conf->expedition->dir_output.
'/sending';
1714 } elseif (
$object->element ==
'delivery') {
1715 $dir =
$conf->expedition->dir_output.
'/receipt';
1716 } elseif (
$object->element ==
'fichinter') {
1717 $dir =
$conf->ficheinter->dir_output;
1719 $dir = empty(
$conf->$element->dir_output) ?
'' :
$conf->$element->dir_output;
1723 $object->error = $langs->trans(
'ErrorObjectNoSupportedByFunction');
1728 $dir = $dir.
"/".$refsan;
1729 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1730 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1731 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1734 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1736 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1740 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1742 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1747 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1749 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1753 $multiple = $filepreviewold.
".";
1754 for ($i = 0; $i < 20; $i++) {
1755 $preview = $multiple.$i;
1757 if (file_exists($preview) && is_writable($preview)) {
1759 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1789 if (
$object->element ==
'order_supplier') {
1790 $dir =
$conf->fournisseur->dir_output.
'/commande';
1791 } elseif (
$object->element ==
'invoice_supplier') {
1792 $dir =
$conf->fournisseur->dir_output.
'/facture';
1793 } elseif (
$object->element ==
'project') {
1794 $dir =
$conf->project->dir_output;
1795 } elseif (
$object->element ==
'shipping') {
1796 $dir =
$conf->expedition->dir_output.
'/sending';
1797 } elseif (
$object->element ==
'delivery') {
1798 $dir =
$conf->expedition->dir_output.
'/receipt';
1799 } elseif (
$object->element ==
'fichinter') {
1800 $dir =
$conf->ficheinter->dir_output;
1802 $dir = empty(
$conf->$element->dir_output) ?
'' :
$conf->$element->dir_output;
1809 $dir = $dir.
"/".$objectref;
1810 $file = $dir.
"/".$objectref.
".meta";
1812 if (!is_dir($dir)) {
1819 $nblines = count(
$object->lines);
1824 $meta =
"REFERENCE=\"".$object->ref.
"\"
1826 NB_ITEMS=\"" . $nblines.
"\"
1827 CLIENT=\"" . $client.
"\"
1828 AMOUNT_EXCL_TAX=\"" .
$object->total_ht.
"\"
1829 AMOUNT=\"" .
$object->total_ttc.
"\"\n";
1831 for ($i = 0; $i < $nblines; $i++) {
1833 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".
$object->lines[$i]->qty.
"\"
1834 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".
$object->lines[$i]->total_ht.
"\"
1835 ITEM_" . $i.
"_VAT=\"".
$object->lines[$i]->tva_tx.
"\"
1836 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br(
$object->lines[$i]->desc)).
"\"
1841 $fp = fopen($file,
"w");
1849 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.
$object->element, LOG_WARNING);
1867 $listofpaths = array();
1868 $listofnames = array();
1869 $listofmimes = array();
1873 foreach ($listoffiles as $key => $val) {
1874 $listofpaths[] = $val[
'fullname'];
1875 $listofnames[] = $val[
'name'];
1879 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1880 $_SESSION[
"listofpaths".$keytoavoidconflict] = implode(
';', $listofpaths);
1881 $_SESSION[
"listofnames".$keytoavoidconflict] = implode(
';', $listofnames);
1882 $_SESSION[
"listofmimes".$keytoavoidconflict] = implode(
';', $listofmimes);
1904function dol_add_file_process($upload_dir, $allowoverwrite = 0, $updatesessionordb = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1,
$object =
null, $forceFullTestIndexation =
'')
1906 global $db, $user,
$conf, $langs;
1910 if (!empty($_FILES[$varfiles])) {
1911 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' donotupdatesession='.$updatesessionordb.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1912 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
1913 if (is_array($_FILES[$varfiles][
"name"]) && count($_FILES[$varfiles][
"name"]) > $maxfilesinform) {
1914 $langs->load(
"errors");
1915 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
1921 $TFile = $_FILES[$varfiles];
1923 if (!is_array($TFile[
'name'])) {
1924 foreach ($TFile as $key => &$val) {
1929 $nbfile = count($TFile[
'name']);
1931 for ($i = 0; $i < $nbfile; $i++) {
1932 if (empty($TFile[
'name'][$i])) {
1937 $destfile = trim($TFile[
'name'][$i]);
1938 $destfull = $upload_dir.
"/".$destfile;
1939 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1941 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1942 $destfile = trim(preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask));
1943 $destfull = $upload_dir.
"/".$destfile;
1946 $filenameto = basename($destfile);
1947 if (preg_match(
'/^\./', $filenameto)) {
1948 $langs->load(
"errors");
1949 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
1953 $info = pathinfo($destfull);
1954 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1955 $info = pathinfo($destfile);
1956 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1964 global $dolibarr_main_restrict_os_commands;
1965 if (!empty($dolibarr_main_restrict_os_commands)) {
1966 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1967 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1968 if (in_array($destfile, $arrayofallowedcommand)) {
1969 $langs->load(
"errors");
1970 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
1976 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
1978 if (is_numeric($resupload) && $resupload > 0) {
1979 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
1982 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
1983 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
1984 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
1985 $maxheightmini = $tmparraysize[
'maxheightmini'];
1990 if ($generatethumbs) {
1996 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
1999 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
2004 if (empty($updatesessionordb)) {
2005 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2007 $formmail->trackid = $trackid;
2008 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
2012 if ($updatesessionordb == 1) {
2014 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false &&
getDolGlobalString(
'PRODUCT_ALLOW_EXTERNAL_DOWNLOAD')) {
2017 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile,
$object);
2019 if ($allowoverwrite) {
2022 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
2029 $langs->load(
"errors");
2030 if (is_numeric($resupload) && $resupload < 0) {
2032 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
2033 if (preg_match(
'/File is a PDF with javascript inside/', $resupload)) {
2034 setEventMessages($langs->trans(
"ErrorFileIsAnInfectedPDFWithJSInside"),
null,
'errors');
2036 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"),
null,
'errors');
2048 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
2051 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2052 $linkObject =
new Link($db);
2053 $linkObject->entity =
$conf->entity;
2054 $linkObject->url = $link;
2055 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
2056 $linkObject->objectid =
GETPOSTINT(
'objectid');
2057 $linkObject->label =
GETPOST(
'label',
'alpha');
2058 $res = $linkObject->create($user);
2066 $langs->load(
"errors");
2067 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
2087 global $db, $user,
$conf, $langs, $_FILES;
2089 $keytodelete = $filenb;
2092 $listofpaths = array();
2093 $listofnames = array();
2094 $listofmimes = array();
2095 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
2096 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
2097 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
2099 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
2100 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
2102 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
2103 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
2106 if ($keytodelete >= 0) {
2107 $pathtodelete = $listofpaths[$keytodelete];
2108 $filetodelete = $listofnames[$keytodelete];
2109 if (empty($donotdeletefile)) {
2115 if (empty($donotdeletefile)) {
2116 $langs->load(
"other");
2117 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
2119 if (empty($donotupdatesession)) {
2120 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2122 $formmail->trackid = $trackid;
2123 $formmail->remove_attached_files($keytodelete);
2146 global $db, $user,
$conf;
2151 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2153 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
2154 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
2155 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2156 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2158 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
2160 $ecmfile->filepath = $rel_dir;
2161 $ecmfile->filename = $filename;
2162 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
2163 $ecmfile->fullpath_orig = $fullpathorig;
2164 $ecmfile->gen_or_uploaded = $mode;
2165 $ecmfile->description =
'';
2166 $ecmfile->keywords =
'';
2169 $ecmfile->src_object_id =
$object->id;
2170 if (isset(
$object->table_element)) {
2171 $ecmfile->src_object_type =
$object->table_element;
2173 dol_syslog(
'Error: object ' . get_class(
$object) .
' has no table_element attribute.');
2176 if (isset(
$object->src_object_description)) {
2177 $ecmfile->description =
$object->src_object_description;
2179 if (isset(
$object->src_object_keywords)) {
2180 $ecmfile->keywords =
$object->src_object_keywords;
2189 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2195 if (empty($useFullTextIndexation) && $forceFullTextIndexation ==
'1') {
2197 $useFullTextIndexation =
'pdftotext';
2199 $useFullTextIndexation =
'docling';
2204 if ($useFullTextIndexation) {
2205 $ecmfile->filepath = $rel_dir;
2206 $ecmfile->filename = $filename;
2208 $filetoprocess = $dir.
'/'.$ecmfile->filename;
2210 $textforfulltextindex =
'';
2213 if (preg_match(
'/\.pdf/i', $filename)) {
2219 if (preg_match(
'/pdftotext/i', $useFullTextIndexation)) {
2220 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2221 $utils =
new Utils($db);
2222 $outputfile =
$conf->admin->dir_temp.
'/tmppdftotext.'.$user->id.
'.out';
2226 $cmd =
getDolGlobalString(
'MAIN_SAVE_FILE_CONTENT_AS_TEXT_PDFTOTEXT',
'pdftotext').
" -htmlmeta '".escapeshellcmd($filetoprocess).
"' - ";
2227 $resultexec = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2229 if (!$resultexec[
'error']) {
2230 $txt = $resultexec[
'output'];
2232 if (preg_match(
'/<meta name="Keywords" content="([^\/]+)"\s*\/>/i', $txt, $matches)) {
2233 $keywords = $matches[1];
2235 if (preg_match(
'/<pre>(.*)<\/pre>/si', $txt, $matches)) {
2245 if (preg_match(
'/docling/i', $useFullTextIndexation)) {
2246 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2247 $utils =
new Utils($db);
2248 $outputfile =
$conf->admin->dir_temp.
'/tmpdocling.'.$user->id.
'.out';
2252 $cmd =
getDolGlobalString(
'MAIN_SAVE_FILE_CONTENT_AS_TEXT_DOCLING',
'docling').
" --from pdf --to text '".escapeshellcmd($filetoprocess).
"'";
2253 $resultexec = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2255 if (!$resultexec[
'error']) {
2256 $txt = $resultexec[
'output'];
2264 $textforfulltextindex = $txt;
2273 $ecmfile->description =
'File content generated by '.$cmd;
2275 $ecmfile->content = $textforfulltextindex;
2276 $ecmfile->keywords = $keywords;
2280 $result = $ecmfile->create($user);
2300 global
$conf, $db, $user;
2305 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
2311 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2313 $filename = basename($file);
2314 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2315 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2318 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
2319 $sql .=
' WHERE entity = '.$conf->entity;
2320 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
2322 $sql .=
" AND filename = '".$db->escape($file).
"'";
2325 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
2328 $resql = $db->query($sql);
2331 dol_syslog(__FUNCTION__.
' '.$db->lasterror(), LOG_ERR);
2359 if (class_exists(
'Imagick')) {
2360 $image =
new Imagick();
2362 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
2364 $ret = $image->readImage($filetoconvert);
2366 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
2367 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);
2371 $ret = $image->setImageFormat($ext);
2373 if (empty($fileoutput)) {
2374 $fileoutput = $fileinput.
".".$ext;
2377 $count = $image->getNumberImages();
2379 if (!
dol_is_file($fileoutput) || is_writable($fileoutput)) {
2381 $ret = $image->writeImages($fileoutput,
true);
2386 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2416function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring =
null)
2422 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2425 $compressdata =
null;
2426 if ($mode ==
'gz' && function_exists(
'gzencode')) {
2428 $compressdata = gzencode($data, 9);
2429 } elseif ($mode ==
'bz' && function_exists(
'bzcompress')) {
2431 $compressdata = bzcompress($data, 9);
2432 } elseif ($mode ==
'zstd' && function_exists(
'zstd_compress')) {
2434 $compressdata = zstd_compress($data, 9);
2435 } elseif ($mode ==
'zip') {
2436 if (class_exists(
'ZipArchive') &&
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS')) {
2439 $rootPath = realpath($inputfile);
2441 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2442 $zip =
new ZipArchive();
2444 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2445 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2449 $errormsg = $errorstring;
2456 $files =
new RecursiveIteratorIterator(
2457 new RecursiveDirectoryIterator($rootPath, FilesystemIterator::UNIX_PATHS),
2458 RecursiveIteratorIterator::LEAVES_ONLY
2460 '@phan-var-force SplFileInfo[] $files';
2462 foreach ($files as $name => $file) {
2464 if (!$file->isDir()) {
2466 $filePath = $file->getPath();
2467 $fileName = $file->getFilename();
2468 $fileFullRealPath = $file->getRealPath();
2471 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2474 $zip->addFile($fileFullRealPath, $relativePath);
2481 dol_syslog(
"dol_compress_file success - ".$zip->numFiles.
" files");
2485 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2488 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2489 $archive =
new PclZip($outputfile);
2491 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2493 if ($result === 0) {
2495 $errormsg = $archive->errorInfo(
true);
2497 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2498 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2499 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2503 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2504 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2507 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2513 if ($foundhandler && is_string($compressdata)) {
2514 $fp = fopen($outputfile,
"w");
2515 fwrite($fp, $compressdata);
2519 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2523 $errormsg = $errorstring;
2527 global $langs, $errormsg;
2528 $langs->load(
"errors");
2529 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2531 $errorstring =
"Failed to open file ".$outputfile;
2549 $fileinfo = pathinfo($inputfile);
2550 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2552 if ($fileinfo[
"extension"] ==
"zip") {
2553 if (defined(
'ODTPHP_PATHTOPCLZIP') && !
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS')) {
2554 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2555 include_once ODTPHP_PATHTOPCLZIP.
'/pclzip.lib.php';
2556 $archive =
new PclZip($inputfile);
2563 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2565 return array(
'error' => $e->getMessage());
2568 if (!is_array($result) && $result <= 0) {
2569 return array(
'error' => $archive->errorInfo(
true));
2574 foreach ($result as $key => $val) {
2575 if ($val[
'status'] ==
'path_creation_fail') {
2576 $langs->load(
"errors");
2578 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2581 if ($val[
'status'] ==
'write_protected') {
2582 $langs->load(
"errors");
2584 $errmsg = $langs->trans(
"ErrorFailToCreateFile", $val[
'filename']);
2592 return array(
'error' => $errmsg);
2597 if (class_exists(
'ZipArchive')) {
2598 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2599 $zip =
new ZipArchive();
2600 $res = $zip->open($inputfile);
2601 if ($res ===
true) {
2607 for ($i = 0; $i < $zip->numFiles; $i++) {
2608 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2609 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2612 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2618 return array(
'error' =>
'ErrUnzipFails');
2622 return array(
'error' =>
'ErrNoZipEngine');
2623 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2624 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2625 $utils =
new Utils($db);
2632 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2633 if ($extension ==
"tar") {
2636 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2637 if ($resarray[
"result"] != 0) {
2638 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2642 if ($fileinfo[
"extension"] ==
"gz") {
2644 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2646 } elseif ($fileinfo[
"extension"] ==
"zst") {
2649 return array(
'error' =>
'ErrorBadFileExtension');
2652 $cmd .=
' > '.$outputfilename;
2654 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0,
null, 1, $outputfilename.
'.err');
2655 if ($resarray[
"result"] != 0) {
2656 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2657 if ($errfilecontent) {
2658 $resarray[
"error"] .=
" - ".$errfilecontent;
2662 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2665 return array(
'error' =>
'ErrorBadFileExtension');
2681function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'', $newmask =
'0')
2685 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2687 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2688 global $langs, $errormsg;
2689 $langs->load(
"errors");
2690 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2695 if ($mode ==
'gz') {
2697 } elseif ($mode ==
'bz') {
2699 } elseif ($mode ==
'zip') {
2713 if (class_exists(
'ZipArchive')) {
2717 $zip =
new ZipArchive();
2718 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2719 if ($result !==
true) {
2720 global $langs, $errormsg;
2721 $langs->load(
"errors");
2722 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile);
2729 $files =
new RecursiveIteratorIterator(
2730 new RecursiveDirectoryIterator($inputdir, FilesystemIterator::UNIX_PATHS),
2731 RecursiveIteratorIterator::LEAVES_ONLY
2733 '@phan-var-force SplFileInfo[] $files';
2736 foreach ($files as $name => $file) {
2738 if (!$file->isDir()) {
2740 $filePath = $file->getPath();
2741 $fileName = $file->getFilename();
2742 $fileFullRealPath = $file->getRealPath();
2745 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2748 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2750 $zip->addFile($fileFullRealPath, $relativePath);
2761 if (empty($newmask)) {
2762 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
2772 if (!$foundhandler) {
2773 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2779 global $langs, $errormsg;
2780 $langs->load(
"errors");
2781 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2783 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile).
' - '.$e->getMessage();
2800function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook = 0, $mode = 0)
2802 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2803 return isset($tmparray[0]) ? $tmparray[0] :
null;
2821 global
$conf, $db, $user, $hookmanager;
2822 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2825 if (!is_object($fuser)) {
2829 if (empty($modulepart)) {
2830 return 'ErrorBadParameter';
2832 if (empty($entity)) {
2833 if (!isModEnabled(
'multicompany')) {
2840 if ($modulepart ==
'facture') {
2841 $modulepart =
'invoice';
2842 } elseif ($modulepart ==
'users') {
2843 $modulepart =
'user';
2844 } elseif ($modulepart ==
'tva') {
2845 $modulepart =
'tax-vat';
2846 } elseif ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
2848 $modulepart =
'delivery';
2852 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2856 $sqlprotectagainstexternals =
'';
2860 if (empty($refname)) {
2861 $refname = basename(dirname($original_file).
"/");
2862 if ($refname ==
'thumbs' || $refname ==
'temp') {
2864 $refname = basename(dirname(dirname($original_file)).
"/");
2871 $download =
'download';
2872 if ($mode ==
'write') {
2875 $download =
'upload';
2879 if ($modulepart ==
'common') {
2882 $original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/'.$original_file;
2883 } elseif ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2888 if (empty($entity)) {
2892 $original_file = (empty(
$conf->medias->multidir_output[$entity]) ?
$conf->medias->dir_output :
$conf->medias->multidir_output[$entity]).
'/'.$original_file;
2893 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2895 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
2896 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2897 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2899 $accessallowed = $user->admin;
2900 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2901 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2903 $accessallowed = ($fuser->hasRight(
'website',
'write') && preg_match(
'/\.jpg$/i', basename($original_file)));
2904 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2905 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2908 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2911 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2912 $original_file = $dirins.
'/'.$original_file;
2913 } elseif ($modulepart ==
'mycompany' && !empty(
$conf->mycompany->dir_output)) {
2916 $original_file =
$conf->mycompany->dir_output.
'/'.$original_file;
2917 } elseif ($modulepart ==
'userphoto' && !empty(
$conf->user->dir_output)) {
2920 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2923 $original_file =
$conf->user->dir_output.
'/'.$original_file;
2924 } elseif ($modulepart ==
'userphotopublic' && !empty(
$conf->user->dir_output)) {
2929 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
2931 $tmpobject =
new User($db);
2932 $tmpobject->fetch($reg[1],
'',
'', 1);
2934 $securekey =
GETPOST(
'securekey',
'alpha', 1);
2936 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
2937 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
2938 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
2939 if ($encodedsecurekey == $securekey) {
2948 $original_file =
$conf->user->dir_output.
'/'.$original_file;
2949 } elseif (($modulepart ==
'companylogo') && !empty(
$conf->mycompany->dir_output)) {
2952 $original_file =
$conf->mycompany->dir_output.
'/logos/'.$original_file;
2953 } elseif ($modulepart ==
'memberphoto' && !empty(
$conf->member->dir_output)) {
2956 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2959 $original_file =
$conf->member->dir_output.
'/'.$original_file;
2960 } elseif ($modulepart ==
'apercufacture' && !empty(
$conf->invoice->multidir_output[$entity])) {
2962 if ($fuser->hasRight(
'facture', $lire)) {
2965 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
2966 } elseif ($modulepart ==
'apercupropal' && !empty(
$conf->propal->multidir_output[$entity])) {
2968 if ($fuser->hasRight(
'propal', $lire)) {
2971 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
2972 } elseif ($modulepart ==
'apercucommande' && !empty(
$conf->order->multidir_output[$entity])) {
2974 if ($fuser->hasRight(
'commande', $lire)) {
2977 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
2978 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty(
$conf->ficheinter->dir_output)) {
2980 if ($fuser->hasRight(
'ficheinter', $lire)) {
2983 $original_file =
$conf->ficheinter->dir_output.
'/'.$original_file;
2984 } elseif (($modulepart ==
'apercucontract') && !empty(
$conf->contract->multidir_output[$entity])) {
2986 if ($fuser->hasRight(
'contrat', $lire)) {
2989 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
2990 } elseif (($modulepart ==
'apercusupplier_proposal') && !empty(
$conf->supplier_proposal->dir_output)) {
2992 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
2995 $original_file =
$conf->supplier_proposal->dir_output.
'/'.$original_file;
2996 } elseif (($modulepart ==
'apercusupplier_order') && !empty(
$conf->fournisseur->commande->dir_output)) {
2998 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3001 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3002 } elseif (($modulepart ==
'apercusupplier_invoice') && !empty(
$conf->fournisseur->facture->dir_output)) {
3004 if ($fuser->hasRight(
'fournisseur', $lire)) {
3007 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3008 } elseif (($modulepart ==
'holiday') && !empty(
$conf->holiday->dir_output)) {
3009 if ($fuser->hasRight(
'holiday', $read) || $fuser->hasRight(
'holiday',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3012 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3013 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
3014 $tmpholiday =
new Holiday($db);
3015 $tmpholiday->fetch(0, $refname);
3016 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
3019 $original_file =
$conf->holiday->dir_output.
'/'.$original_file;
3020 } elseif (($modulepart ==
'expensereport') && !empty(
$conf->expensereport->dir_output)) {
3021 if ($fuser->hasRight(
'expensereport', $lire) || $fuser->hasRight(
'expensereport',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3024 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3025 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
3027 $tmpexpensereport->fetch(0, $refname);
3028 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
3031 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3032 } elseif (($modulepart ==
'apercuexpensereport') && !empty(
$conf->expensereport->dir_output)) {
3034 if ($fuser->hasRight(
'expensereport', $lire)) {
3037 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3038 } elseif ($modulepart ==
'propalstats' && !empty(
$conf->propal->multidir_temp[$entity])) {
3040 if ($fuser->hasRight(
'propal', $lire)) {
3043 $original_file =
$conf->propal->multidir_temp[$entity].
'/'.$original_file;
3044 } elseif ($modulepart ==
'orderstats' && !empty(
$conf->order->dir_temp)) {
3046 if ($fuser->hasRight(
'commande', $lire)) {
3049 $original_file =
$conf->order->dir_temp.
'/'.$original_file;
3050 } elseif ($modulepart ==
'orderstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3051 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3054 $original_file =
$conf->fournisseur->commande->dir_temp.
'/'.$original_file;
3055 } elseif ($modulepart ==
'billstats' && !empty(
$conf->invoice->dir_temp)) {
3057 if ($fuser->hasRight(
'facture', $lire)) {
3060 $original_file =
$conf->invoice->dir_temp.
'/'.$original_file;
3061 } elseif ($modulepart ==
'billstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3062 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
3065 $original_file =
$conf->fournisseur->facture->dir_temp.
'/'.$original_file;
3066 } elseif ($modulepart ==
'expeditionstats' && !empty(
$conf->expedition->dir_temp)) {
3068 if ($fuser->hasRight(
'expedition', $lire)) {
3071 $original_file =
$conf->expedition->dir_temp.
'/'.$original_file;
3072 } elseif ($modulepart ==
'tripsexpensesstats' && !empty(
$conf->deplacement->dir_temp)) {
3074 if ($fuser->hasRight(
'deplacement', $lire)) {
3077 $original_file =
$conf->deplacement->dir_temp.
'/'.$original_file;
3078 } elseif ($modulepart ==
'memberstats' && !empty(
$conf->member->dir_temp)) {
3080 if ($fuser->hasRight(
'adherent', $lire)) {
3083 $original_file =
$conf->member->dir_temp.
'/'.$original_file;
3084 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty(
$conf->product->dir_temp)) {
3086 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
3089 $original_file = (!empty(
$conf->product->multidir_temp[$entity]) ?
$conf->product->multidir_temp[$entity] :
$conf->service->multidir_temp[$entity]).
'/'.$original_file;
3090 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty(
$conf->tax->dir_output)) {
3092 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
3095 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
3096 $original_file =
$conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
3097 } elseif ($modulepart ==
'actions' && !empty(
$conf->agenda->dir_output)) {
3099 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3102 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3103 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3105 $tmpobject->fetch((
int) $refname);
3106 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3107 if ($user->socid && $tmpobject->socid) {
3112 $original_file =
$conf->agenda->dir_output.
'/'.$original_file;
3113 } elseif ($modulepart ==
'category' && !empty(
$conf->categorie->multidir_output[$entity])) {
3115 if (empty($entity) || empty(
$conf->categorie->multidir_output[$entity])) {
3116 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3118 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
3121 $original_file =
$conf->categorie->multidir_output[$entity].
'/'.$original_file;
3122 } elseif ($modulepart ==
'prelevement' && !empty(
$conf->prelevement->dir_output)) {
3124 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3127 $original_file =
$conf->prelevement->dir_output.
'/'.$original_file;
3128 } elseif ($modulepart ==
'graph_stock' && !empty(
$conf->stock->dir_temp)) {
3131 $original_file =
$conf->stock->dir_temp.
'/'.$original_file;
3132 } elseif ($modulepart ==
'graph_fourn' && !empty(
$conf->fournisseur->dir_temp)) {
3135 $original_file =
$conf->fournisseur->dir_temp.
'/'.$original_file;
3136 } elseif ($modulepart ==
'graph_product' && !empty(
$conf->product->dir_temp)) {
3139 $original_file =
$conf->product->multidir_temp[$entity].
'/'.$original_file;
3140 } elseif ($modulepart ==
'barcode') {
3145 $original_file =
'';
3146 } elseif ($modulepart ==
'iconmailing' && !empty(
$conf->mailing->dir_temp)) {
3149 $original_file =
$conf->mailing->dir_temp.
'/'.$original_file;
3150 } elseif ($modulepart ==
'scanner_user_temp' && !empty(
$conf->scanner->dir_temp)) {
3153 $original_file =
$conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3154 } elseif ($modulepart ==
'fckeditor' && !empty(
$conf->fckeditor->dir_output)) {
3157 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3158 } elseif ($modulepart ==
'user' && !empty(
$conf->user->dir_output)) {
3160 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
3161 if ($fuser->id == (
int) $refname) {
3164 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3167 $original_file =
$conf->user->dir_output.
'/'.$original_file;
3168 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty(
$conf->societe->multidir_output[$entity])) {
3170 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3171 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3173 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3176 $original_file =
$conf->societe->multidir_output[$entity].
'/'.$original_file;
3177 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
3178 } elseif ($modulepart ==
'contact' && !empty(
$conf->societe->multidir_output[$entity])) {
3180 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3181 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3183 if ($fuser->hasRight(
'societe', $lire)) {
3186 $original_file =
$conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3187 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty(
$conf->invoice->multidir_output[$entity])) {
3189 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3192 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
3193 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3194 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty(
$conf->propal->multidir_output[$entity])) {
3196 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3199 $original_file =
$conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3200 } elseif ($modulepart ==
'massfilesarea_orders') {
3201 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3204 $original_file =
$conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3205 } elseif ($modulepart ==
'massfilesarea_sendings') {
3206 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3209 $original_file =
$conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3210 } elseif ($modulepart ==
'massfilesarea_receipts') {
3211 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3214 $original_file =
$conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3215 } elseif ($modulepart ==
'massfilesarea_invoices') {
3216 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3219 $original_file =
$conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3220 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3221 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3224 $original_file =
$conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3225 } elseif ($modulepart ==
'massfilesarea_interventions') {
3226 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3229 $original_file =
$conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3230 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty(
$conf->supplier_proposal->dir_output)) {
3231 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3234 $original_file =
$conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3235 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3236 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3239 $original_file =
$conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3240 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3241 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3244 $original_file =
$conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3245 } elseif ($modulepart ==
'massfilesarea_contract' && !empty(
$conf->contract->dir_output)) {
3246 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3249 $original_file =
$conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3250 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty(
$conf->ficheinter->dir_output)) {
3252 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3255 $original_file =
$conf->ficheinter->dir_output.
'/'.$original_file;
3256 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3257 } elseif ($modulepart ==
'deplacement' && !empty(
$conf->deplacement->dir_output)) {
3259 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3262 $original_file =
$conf->deplacement->dir_output.
'/'.$original_file;
3264 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset(
$conf->propal->multidir_output[$entity])) {
3266 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3269 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
3270 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3271 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty(
$conf->order->multidir_output[$entity])) {
3273 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3276 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
3277 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3278 } elseif ($modulepart ==
'project' && !empty(
$conf->project->multidir_output[$entity])) {
3280 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3283 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3284 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3285 $tmpproject =
new Project($db);
3286 $tmpproject->fetch(0, $refname);
3287 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3290 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3291 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3292 } elseif ($modulepart ==
'project_task' && !empty(
$conf->project->multidir_output[$entity])) {
3293 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3296 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3297 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3298 $tmptask =
new Task($db);
3299 $tmptask->fetch(0, $refname);
3300 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3303 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3304 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3305 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty(
$conf->fournisseur->commande->dir_output)) {
3307 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3310 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3311 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3312 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty(
$conf->fournisseur->facture->dir_output)) {
3314 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3317 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3318 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3319 } elseif ($modulepart ==
'supplier_payment') {
3321 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3324 $original_file =
$conf->fournisseur->payment->dir_output.
'/'.$original_file;
3325 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3326 } elseif ($modulepart ==
'payment') {
3328 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3331 $original_file =
$conf->compta->payment->dir_output.
'/'.$original_file;
3332 } elseif ($modulepart ==
'facture_paiement' && !empty(
$conf->invoice->dir_output)) {
3334 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3337 if ($fuser->socid > 0) {
3338 $original_file =
$conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3340 $original_file =
$conf->invoice->dir_output.
'/payments/'.$original_file;
3342 } elseif ($modulepart ==
'export_compta' && !empty(
$conf->accounting->dir_output)) {
3344 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3347 $original_file =
$conf->accounting->dir_output.
'/'.$original_file;
3348 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty(
$conf->expedition->dir_output)) {
3350 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3353 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3355 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty(
$conf->expedition->dir_output)) {
3357 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3360 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3361 } elseif ($modulepart ==
'actionsreport' && !empty(
$conf->agenda->dir_temp)) {
3363 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3366 $original_file =
$conf->agenda->dir_temp.
"/".$original_file;
3367 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3369 if (empty($entity) || (empty(
$conf->product->multidir_output[$entity]) && empty(
$conf->service->multidir_output[$entity]))) {
3370 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3372 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3375 if (isModEnabled(
"product")) {
3376 $original_file =
$conf->product->multidir_output[$entity].
'/'.$original_file;
3377 } elseif (isModEnabled(
"service")) {
3378 $original_file =
$conf->service->multidir_output[$entity].
'/'.$original_file;
3380 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3382 if (empty($entity) || (empty(
$conf->productbatch->multidir_output[$entity]))) {
3383 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3385 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3388 if (isModEnabled(
'productbatch')) {
3389 $original_file =
$conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3391 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3393 if (empty($entity) || empty(
$conf->stock->multidir_output[$entity])) {
3394 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3396 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3399 if (isModEnabled(
'stock')) {
3400 $original_file =
$conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3402 } elseif ($modulepart ==
'contract' && !empty(
$conf->contract->multidir_output[$entity])) {
3404 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3407 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
3408 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3409 } elseif ($modulepart ==
'donation' && !empty(
$conf->don->dir_output)) {
3411 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3414 $original_file =
$conf->don->dir_output.
'/'.$original_file;
3415 } elseif ($modulepart ==
'dolresource' && !empty(
$conf->resource->dir_output)) {
3417 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3420 $original_file =
$conf->resource->dir_output.
'/'.$original_file;
3421 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty(
$conf->bank->dir_output)) {
3423 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3426 $original_file =
$conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3427 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty(
$conf->bank->dir_output)) {
3429 if ($fuser->hasRight(
'banque', $lire)) {
3432 $original_file =
$conf->bank->dir_output.
'/'.$original_file;
3433 } elseif ($modulepart ==
'export' && !empty(
$conf->export->dir_temp)) {
3436 $accessallowed = $user->hasRight(
'export',
'lire');
3437 $original_file =
$conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3438 } elseif ($modulepart ==
'import' && !empty(
$conf->import->dir_temp)) {
3440 $accessallowed = $user->hasRight(
'import',
'run');
3441 $original_file =
$conf->import->dir_temp.
'/'.$original_file;
3442 } elseif ($modulepart ==
'recruitment' && !empty(
$conf->recruitment->dir_output)) {
3444 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3445 $original_file =
$conf->recruitment->dir_output.
'/'.$original_file;
3446 } elseif ($modulepart ==
'editor' && !empty(
$conf->fckeditor->dir_output)) {
3449 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3450 } elseif ($modulepart ==
'systemtools' && !empty(
$conf->admin->dir_output)) {
3452 if ($fuser->admin) {
3455 $original_file =
$conf->admin->dir_output.
'/'.$original_file;
3456 } elseif ($modulepart ==
'admin_temp' && !empty(
$conf->admin->dir_temp)) {
3458 if ($fuser->admin) {
3461 $original_file =
$conf->admin->dir_temp.
'/'.$original_file;
3462 } elseif ($modulepart ==
'bittorrent' && !empty(
$conf->bittorrent->dir_output)) {
3466 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3469 $original_file =
$conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3470 } elseif ($modulepart ==
'member' && !empty(
$conf->member->dir_output)) {
3472 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3475 $original_file =
$conf->member->dir_output.
'/'.$original_file;
3485 if (preg_match(
'/^specimen/i', $original_file)) {
3488 if ($fuser->admin) {
3492 $tmpmodulepart = explode(
'-', $modulepart);
3493 if (!empty($tmpmodulepart[1])) {
3494 $modulepart = $tmpmodulepart[0];
3495 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3500 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3501 $tmpmodule = $reg[1];
3502 if (empty(
$conf->$tmpmodule->dir_temp)) {
3503 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3506 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3509 $original_file =
$conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3510 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3511 $tmpmodule = $reg[1];
3512 if (empty(
$conf->$tmpmodule->dir_temp)) {
3513 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3516 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3519 $original_file =
$conf->$tmpmodule->dir_temp.
'/'.$original_file;
3520 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3521 $tmpmodule = $reg[1];
3522 if (empty(
$conf->$tmpmodule->dir_output)) {
3523 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3526 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3529 $original_file =
$conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3530 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3531 $tmpmodule = $reg[1];
3532 if (empty(
$conf->$tmpmodule->dir_output)) {
3533 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3536 if ($fuser->hasRight($tmpmodule, $lire) || preg_match(
'/^specimen/i', $original_file)) {
3539 $original_file =
$conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3541 if (empty(
$conf->$modulepart->dir_output)) {
3542 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.');
3547 $partsofdirinoriginalfile = explode(
'/', $original_file);
3548 if (!empty($partsofdirinoriginalfile[1])) {
3549 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3550 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3554 if ($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) {
3558 if (is_array(
$conf->$modulepart->multidir_output) && !empty(
$conf->$modulepart->multidir_output[$entity])) {
3559 $original_file =
$conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3561 $original_file =
$conf->$modulepart->dir_output.
'/'.$original_file;
3565 $parameters = array(
3566 'modulepart' => $modulepart,
3567 'original_file' => $original_file,
3568 'entity' => $entity,
3573 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3575 if (!empty($hookmanager->resArray[
'original_file'])) {
3576 $original_file = $hookmanager->resArray[
'original_file'];
3578 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3579 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3581 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3582 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3588 'accessallowed' => ($accessallowed ? 1 : 0),
3589 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3590 'original_file' => $original_file
3609 dol_syslog(
"Failed to create the cache directory ".$directory, LOG_WARNING);
3612 $cachefile = $directory.$filename;
3614 file_put_contents($cachefile, serialize(
$object), LOCK_EX);
3630 $cachefile = $directory.$filename;
3631 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3644 $cachefile = $directory.$filename;
3645 $object = unserialize(file_get_contents($cachefile));
3657 return preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'\//',
'', $pathfile);
3672function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3676 $exclude =
'install';
3678 foreach ($dir->md5file as $file) {
3679 $filename = $path.$file[
'name'];
3680 $file_list[
'insignature'][] = $filename;
3681 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3682 $expectedmd5 = (string) $file;
3684 if (!file_exists($pathref.
'/'.$filename)) {
3685 $file_list[
'missing'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize);
3687 $md5_local = md5_file($pathref.
'/'.$filename);
3689 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3690 $checksumconcat[] = $expectedmd5;
3692 if ($md5_local != $expectedmd5) {
3693 $file_list[
'updated'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize,
'md5' => (
string) $md5_local);
3695 $checksumconcat[] = $md5_local;
3700 foreach ($dir->dir as $subdir) {
3701 getFilesUpdated($file_list, $subdir, $path.$subdir[
'name'].
'/', $pathref, $checksumconcat);
3719 $out .=
'<div id="'.$htmlname.
'Message" class="dragDropAreaMessage hidden"><span>'.
img_picto(
"",
'download').
'<br>'.$langs->trans(
"DropFileToAddItToObject").
'</span></div>';
3720 $out .=
"\n<!-- JS CODE TO ENABLE DRAG AND DROP OF FILE -->\n";
3723 jQuery(document).ready(function() {
3724 var enterTargetDragDrop = null;
3726 $("#'.$htmlname.
'").addClass("cssDragDropArea");
3728 $(".cssDragDropArea").on("dragenter", function(ev, ui) {
3729 var dataTransfer = ev.originalEvent.dataTransfer;
3730 var dataTypes = dataTransfer.types;
3731 //console.log(dataTransfer);
3732 //console.log(dataTypes);
3734 if (!dataTypes || ($.inArray(\'Files\', dataTypes) === -1)) {
3735 // The element dragged is not a file, so we avoid the "dragenter"
3736 ev.preventDefault();
3740 // Entering drop area. Highlight area
3741 console.log("dragAndDropFileUpload: We add class highlightDragDropArea")
3742 enterTargetDragDrop = ev.target;
3743 $(this).addClass("highlightDragDropArea");
3744 $("#'.$htmlname.
'Message").removeClass("hidden");
3745 ev.preventDefault();
3748 $(".cssDragDropArea").on("dragleave", function(ev) {
3749 // Going out of drop area. Remove Highlight
3750 if (enterTargetDragDrop == ev.target){
3751 console.log("dragAndDropFileUpload: We remove class highlightDragDropArea")
3752 $("#'.$htmlname.
'Message").addClass("hidden");
3753 $(this).removeClass("highlightDragDropArea");
3757 $(".cssDragDropArea").on("dragover", function(ev) {
3758 ev.preventDefault();
3762 $(".cssDragDropArea").on("drop", function(e) {
3765 fd = new FormData();
3769 fd.append("action", "linkit");
3771 var dataTransfer = e.originalEvent.dataTransfer;
3773 if (dataTransfer.files && dataTransfer.files.length){
3774 var droppedFiles = e.originalEvent.dataTransfer.files;
3775 $.each(droppedFiles, function(index,file){
3776 fd.append("files[]", file,file.name)
3779 $(".cssDragDropArea").removeClass("highlightDragDropArea");
3780 counterdragdrop = 0;
3782 url: "'.DOL_URL_ROOT.
'/core/ajax/fileupload.php",
3787 success:function() {
3788 console.log("Uploaded.", arguments);
3789 /* arguments[0] is the json string of files */
3790 /* arguments[1] is the value for variable "success", can be 0 or 1 */
3791 let listoffiles = JSON.parse(arguments[0]);
3792 console.log(listoffiles);
3794 for (let i = 0; i < listoffiles.length; i++) {
3795 console.log(listoffiles[i].error);
3796 if (listoffiles[i].error) {
3800 console.log(nboferror);
3801 if (nboferror > 0) {
3802 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorOnAtLeastOneFileUpload:warnings";
3804 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=UploadFileDragDropSuccess:mesgs";
3808 console.log("Error Uploading.", arguments)
3809 if (arguments[0].status == 403) {
3810 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadPermissionDenied:errors";
3812 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadFileDragDropPermissionDenied:errors";
3818 $out .=
"</script>\n";
3832function archiveOrBackupFile($srcfile, $max_versions = 5, $archivedir =
'', $suffix =
"v", $moveorcopy =
'move')
3834 $base_file_pattern = ($archivedir ? $archivedir : dirname($srcfile)).
'/'.basename($srcfile).
".".$suffix;
3835 $files_in_directory = glob($base_file_pattern .
"*");
3838 $files_with_timestamps = [];
3839 foreach ($files_in_directory as $file) {
3840 $files_with_timestamps[] = [
3842 'timestamp' => filemtime($file)
3848 while (count($files_with_timestamps) > 0) {
3849 $latest_file =
null;
3850 $latest_index =
null;
3853 foreach ($files_with_timestamps as $index => $file_info) {
3854 if ($latest_file ===
null || (is_array($latest_file) && $file_info[
'timestamp'] > $latest_file[
'timestamp'])) {
3855 $latest_file = $file_info;
3856 $latest_index = $index;
3861 if ($latest_file !==
null) {
3862 $sorted_files[] = $latest_file[
'file'];
3863 unset($files_with_timestamps[$latest_index]);
3868 if (count($sorted_files) >= $max_versions) {
3869 $oldest_files = array_slice($sorted_files, $max_versions - 1);
3870 foreach ($oldest_files as $oldest_file) {
3876 $new_backup = $srcfile .
".v" . $timestamp;
3879 if ($moveorcopy ==
'move') {
3880 $result =
dol_move($srcfile, $new_backup,
'0', 1, 0, 0);
3882 $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_is_link($pathoffile)
Return if path is a symbolic link.
dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $sqlfilters="")
Scan a directory and return a list of files/directories.
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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
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_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.
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
Complete $filearray with data from database.
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.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
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.
checkUserAccessToObject($user, array $featuresarray, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='', $dbt_select='rowid', $parenttableforentity='')
Check that access by a given user to an object is ok.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.