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));
1648function dol_delete_dir_recursive($dir, $count = 0, $nophperrors = 0, $onlysub = 0, &$countdeleted = 0, $indexdatabase = 1, $nolog = 0, $level = 0)
1650 if (empty($nolog) || empty($level)) {
1651 dol_syslog(
"functions.lib:dol_delete_dir_recursive ".$dir, LOG_DEBUG);
1653 if ($level > 1000) {
1654 dol_syslog(
"functions.lib:dol_delete_dir_recursive too many depth", LOG_WARNING);
1659 if ($handle = opendir(
"$dir_osencoded")) {
1660 while (
false !== ($item = readdir($handle))) {
1662 $item = mb_convert_encoding($item,
'UTF-8',
'ISO-8859-1');
1665 if ($item !=
"." && $item !=
"..") {
1667 $count =
dol_delete_dir_recursive(
"$dir/$item", $count, $nophperrors, 0, $countdeleted, $indexdatabase, $nolog, ($level + 1));
1669 $result =
dol_delete_file(
"$dir/$item", 1, $nophperrors, 0,
null,
false, $indexdatabase, $nolog);
1681 if (empty($onlysub)) {
1706 global $langs,
$conf;
1711 if (
$object->element ==
'order_supplier') {
1712 $dir =
$conf->fournisseur->commande->dir_output;
1713 } elseif (
$object->element ==
'invoice_supplier') {
1714 $dir =
$conf->fournisseur->facture->dir_output;
1715 } elseif (
$object->element ==
'project') {
1716 $dir =
$conf->project->dir_output;
1717 } elseif (
$object->element ==
'shipping') {
1718 $dir =
$conf->expedition->dir_output.
'/sending';
1719 } elseif (
$object->element ==
'delivery') {
1720 $dir =
$conf->expedition->dir_output.
'/receipt';
1721 } elseif (
$object->element ==
'fichinter') {
1722 $dir =
$conf->ficheinter->dir_output;
1724 $dir = empty(
$conf->$element->dir_output) ?
'' :
$conf->$element->dir_output;
1728 $object->error = $langs->trans(
'ErrorObjectNoSupportedByFunction');
1733 $dir = $dir.
"/".$refsan;
1734 $filepreviewnew = $dir.
"/".$refsan.
".pdf_preview.png";
1735 $filepreviewnewbis = $dir.
"/".$refsan.
".pdf_preview-0.png";
1736 $filepreviewold = $dir.
"/".$refsan.
".pdf.png";
1739 if (file_exists($filepreviewnew) && is_writable($filepreviewnew)) {
1741 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnew);
1745 if (file_exists($filepreviewnewbis) && is_writable($filepreviewnewbis)) {
1747 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewnewbis);
1752 if (file_exists($filepreviewold) && is_writable($filepreviewold)) {
1754 $object->error = $langs->trans(
"ErrorFailedToDeleteFile", $filepreviewold);
1758 $multiple = $filepreviewold.
".";
1759 for ($i = 0; $i < 20; $i++) {
1760 $preview = $multiple.$i;
1762 if (file_exists($preview) && is_writable($preview)) {
1764 $object->error = $langs->trans(
"ErrorFailedToOpenFile", $preview);
1794 if (
$object->element ==
'order_supplier') {
1795 $dir =
$conf->fournisseur->dir_output.
'/commande';
1796 } elseif (
$object->element ==
'invoice_supplier') {
1797 $dir =
$conf->fournisseur->dir_output.
'/facture';
1798 } elseif (
$object->element ==
'project') {
1799 $dir =
$conf->project->dir_output;
1800 } elseif (
$object->element ==
'shipping') {
1801 $dir =
$conf->expedition->dir_output.
'/sending';
1802 } elseif (
$object->element ==
'delivery') {
1803 $dir =
$conf->expedition->dir_output.
'/receipt';
1804 } elseif (
$object->element ==
'fichinter') {
1805 $dir =
$conf->ficheinter->dir_output;
1807 $dir = empty(
$conf->$element->dir_output) ?
'' :
$conf->$element->dir_output;
1814 $dir = $dir.
"/".$objectref;
1815 $file = $dir.
"/".$objectref.
".meta";
1817 if (!is_dir($dir)) {
1824 $nblines = count(
$object->lines);
1829 $meta =
"REFERENCE=\"".$object->ref.
"\"
1831 NB_ITEMS=\"" . $nblines.
"\"
1832 CLIENT=\"" . $client.
"\"
1833 AMOUNT_EXCL_TAX=\"" .
$object->total_ht.
"\"
1834 AMOUNT=\"" .
$object->total_ttc.
"\"\n";
1836 for ($i = 0; $i < $nblines; $i++) {
1838 $meta .=
"ITEM_".$i.
"_QUANTITY=\"".
$object->lines[$i]->qty.
"\"
1839 ITEM_" . $i.
"_AMOUNT_WO_TAX=\"".
$object->lines[$i]->total_ht.
"\"
1840 ITEM_" . $i.
"_VAT=\"".
$object->lines[$i]->tva_tx.
"\"
1841 ITEM_" . $i.
"_DESCRIPTION=\"".str_replace(
"\r\n",
"", nl2br(
$object->lines[$i]->desc)).
"\"
1846 $fp = fopen($file,
"w");
1854 dol_syslog(
'FailedToDetectDirInDolMetaCreateFor'.
$object->element, LOG_WARNING);
1872 $listofpaths = array();
1873 $listofnames = array();
1874 $listofmimes = array();
1878 foreach ($listoffiles as $key => $val) {
1879 $listofpaths[] = $val[
'fullname'];
1880 $listofnames[] = $val[
'name'];
1884 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
1885 $_SESSION[
"listofpaths".$keytoavoidconflict] = implode(
';', $listofpaths);
1886 $_SESSION[
"listofnames".$keytoavoidconflict] = implode(
';', $listofnames);
1887 $_SESSION[
"listofmimes".$keytoavoidconflict] = implode(
';', $listofmimes);
1909function dol_add_file_process($upload_dir, $allowoverwrite = 0, $updatesessionordb = 0, $varfiles =
'addedfile', $savingdocmask =
'', $link =
null, $trackid =
'', $generatethumbs = 1,
$object =
null, $forceFullTestIndexation =
'')
1911 global $db, $user,
$conf, $langs;
1915 if (!empty($_FILES[$varfiles])) {
1916 dol_syslog(
'dol_add_file_process upload_dir='.$upload_dir.
' allowoverwrite='.$allowoverwrite.
' donotupdatesession='.$updatesessionordb.
' savingdocmask='.$savingdocmask, LOG_DEBUG);
1917 $maxfilesinform =
getDolGlobalInt(
"MAIN_SECURITY_MAX_ATTACHMENT_ON_FORMS", 10);
1918 if (is_array($_FILES[$varfiles][
"name"]) && count($_FILES[$varfiles][
"name"]) > $maxfilesinform) {
1919 $langs->load(
"errors");
1920 setEventMessages($langs->trans(
"ErrorTooMuchFileInForm", $maxfilesinform),
null,
"errors");
1926 $TFile = $_FILES[$varfiles];
1928 if (!is_array($TFile[
'name'])) {
1929 foreach ($TFile as $key => &$val) {
1934 $nbfile = count($TFile[
'name']);
1936 for ($i = 0; $i < $nbfile; $i++) {
1937 if (empty($TFile[
'name'][$i])) {
1942 $destfile = trim($TFile[
'name'][$i]);
1943 $destfull = $upload_dir.
"/".$destfile;
1944 $destfilewithoutext = preg_replace(
'/\.[^\.]+$/',
'', $destfile);
1946 if ($savingdocmask && strpos($savingdocmask, $destfilewithoutext) !== 0) {
1947 $destfile = trim(preg_replace(
'/__file__/', $TFile[
'name'][$i], $savingdocmask));
1948 $destfull = $upload_dir.
"/".$destfile;
1951 $filenameto = basename($destfile);
1952 if (preg_match(
'/^\./', $filenameto)) {
1953 $langs->load(
"errors");
1954 setEventMessages($langs->trans(
"ErrorFilenameCantStartWithDot", $filenameto),
null,
'errors');
1958 $info = pathinfo($destfull);
1959 $destfull = $info[
'dirname'].
'/'.
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1960 $info = pathinfo($destfile);
1961 $destfile =
dol_sanitizeFileName($info[
'filename'].($info[
'extension'] !=
'' ? (
'.'.strtolower($info[
'extension'])) :
''));
1969 global $dolibarr_main_restrict_os_commands;
1970 if (!empty($dolibarr_main_restrict_os_commands)) {
1971 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
1972 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
1973 if (in_array($destfile, $arrayofallowedcommand)) {
1974 $langs->load(
"errors");
1975 setEventMessages($langs->trans(
"ErrorFilenameReserved", $destfile),
null,
'errors');
1981 $resupload =
dol_move_uploaded_file($TFile[
'tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile[
'error'][$i], 0, $varfiles, $upload_dir);
1983 if (is_numeric($resupload) && $resupload > 0) {
1984 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
1987 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
1988 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
1989 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
1990 $maxheightmini = $tmparraysize[
'maxheightmini'];
1995 if ($generatethumbs) {
2001 $imgThumbSmall =
vignette($destfull, $maxwidthsmall, $maxheightsmall,
'_small', $quality,
"thumbs");
2004 $imgThumbMini =
vignette($destfull, $maxwidthmini, $maxheightmini,
'_mini', $quality,
"thumbs");
2009 if (empty($updatesessionordb)) {
2010 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2012 $formmail->trackid = $trackid;
2013 $formmail->add_attached_files($destfull, $destfile, $TFile[
'type'][$i]);
2017 if ($updatesessionordb == 1) {
2019 if ($TFile[
'type'][$i] ==
'application/pdf' && strpos($_SERVER[
"REQUEST_URI"],
'product') !==
false &&
getDolGlobalString(
'PRODUCT_ALLOW_EXTERNAL_DOWNLOAD')) {
2022 $result =
addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ?
'.noexe' :
''), $TFile[
'name'][$i],
'uploaded', $sharefile,
$object);
2024 if ($allowoverwrite) {
2027 setEventMessages(
'WarningFailedToAddFileIntoDatabaseIndex',
null,
'warnings');
2034 $langs->load(
"errors");
2035 if (is_numeric($resupload) && $resupload < 0) {
2037 } elseif (preg_match(
'/ErrorFileIsInfectedWithAVirus/', $resupload)) {
2038 if (preg_match(
'/File is a PDF with javascript inside/', $resupload)) {
2039 setEventMessages($langs->trans(
"ErrorFileIsAnInfectedPDFWithJSInside"),
null,
'errors');
2041 setEventMessages($langs->trans(
"ErrorFileIsInfectedWithAVirus"),
null,
'errors');
2053 setEventMessages($langs->trans(
"ErrorFailedToCreateDir", $upload_dir),
null,
'errors');
2056 require_once DOL_DOCUMENT_ROOT.
'/core/class/link.class.php';
2057 $linkObject =
new Link($db);
2058 $linkObject->entity =
$conf->entity;
2059 $linkObject->url = $link;
2060 $linkObject->objecttype =
GETPOST(
'objecttype',
'alpha');
2061 $linkObject->objectid =
GETPOSTINT(
'objectid');
2062 $linkObject->label =
GETPOST(
'label',
'alpha');
2063 $res = $linkObject->create($user);
2071 $langs->load(
"errors");
2072 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"File")),
null,
'errors');
2092 global $db, $user,
$conf, $langs, $_FILES;
2094 $keytodelete = $filenb;
2097 $listofpaths = array();
2098 $listofnames = array();
2099 $listofmimes = array();
2100 $keytoavoidconflict = empty($trackid) ?
'' :
'-'.$trackid;
2101 if (!empty($_SESSION[
"listofpaths".$keytoavoidconflict])) {
2102 $listofpaths = explode(
';', $_SESSION[
"listofpaths".$keytoavoidconflict]);
2104 if (!empty($_SESSION[
"listofnames".$keytoavoidconflict])) {
2105 $listofnames = explode(
';', $_SESSION[
"listofnames".$keytoavoidconflict]);
2107 if (!empty($_SESSION[
"listofmimes".$keytoavoidconflict])) {
2108 $listofmimes = explode(
';', $_SESSION[
"listofmimes".$keytoavoidconflict]);
2111 if ($keytodelete >= 0) {
2112 $pathtodelete = $listofpaths[$keytodelete];
2113 $filetodelete = $listofnames[$keytodelete];
2114 if (empty($donotdeletefile)) {
2120 if (empty($donotdeletefile)) {
2121 $langs->load(
"other");
2122 setEventMessages($langs->trans(
"FileWasRemoved", $filetodelete),
null,
'mesgs');
2124 if (empty($donotupdatesession)) {
2125 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2127 $formmail->trackid = $trackid;
2128 $formmail->remove_attached_files($keytodelete);
2151 global $db, $user,
$conf;
2156 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2158 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
2159 $filename = basename(preg_replace(
'/\.noexe$/',
'', $file));
2160 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2161 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2163 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
2165 $ecmfile->filepath = $rel_dir;
2166 $ecmfile->filename = $filename;
2167 $ecmfile->label = md5_file(
dol_osencode($dir.
'/'.$file));
2168 $ecmfile->fullpath_orig = $fullpathorig;
2169 $ecmfile->gen_or_uploaded = $mode;
2170 $ecmfile->description =
'';
2171 $ecmfile->keywords =
'';
2174 $ecmfile->src_object_id =
$object->id;
2175 if (isset(
$object->table_element)) {
2176 $ecmfile->src_object_type =
$object->table_element;
2178 dol_syslog(
'Error: object ' . get_class(
$object) .
' has no table_element attribute.');
2181 if (isset(
$object->src_object_description)) {
2182 $ecmfile->description =
$object->src_object_description;
2184 if (isset(
$object->src_object_keywords)) {
2185 $ecmfile->keywords =
$object->src_object_keywords;
2194 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2200 if (empty($useFullTextIndexation) && $forceFullTextIndexation ==
'1') {
2202 $useFullTextIndexation =
'pdftotext';
2204 $useFullTextIndexation =
'docling';
2209 if ($useFullTextIndexation) {
2210 $ecmfile->filepath = $rel_dir;
2211 $ecmfile->filename = $filename;
2213 $filetoprocess = $dir.
'/'.$ecmfile->filename;
2215 $textforfulltextindex =
'';
2218 if (preg_match(
'/\.pdf/i', $filename)) {
2224 if (preg_match(
'/pdftotext/i', $useFullTextIndexation)) {
2225 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2226 $utils =
new Utils($db);
2227 $outputfile =
$conf->admin->dir_temp.
'/tmppdftotext.'.$user->id.
'.out';
2231 $cmd =
getDolGlobalString(
'MAIN_SAVE_FILE_CONTENT_AS_TEXT_PDFTOTEXT',
'pdftotext').
" -htmlmeta '".escapeshellcmd($filetoprocess).
"' - ";
2232 $resultexec = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2234 if (!$resultexec[
'error']) {
2235 $txt = $resultexec[
'output'];
2237 if (preg_match(
'/<meta name="Keywords" content="([^\/]+)"\s*\/>/i', $txt, $matches)) {
2238 $keywords = $matches[1];
2240 if (preg_match(
'/<pre>(.*)<\/pre>/si', $txt, $matches)) {
2250 if (preg_match(
'/docling/i', $useFullTextIndexation)) {
2251 include_once DOL_DOCUMENT_ROOT.
'/core/class/utils.class.php';
2252 $utils =
new Utils($db);
2253 $outputfile =
$conf->admin->dir_temp.
'/tmpdocling.'.$user->id.
'.out';
2257 $cmd =
getDolGlobalString(
'MAIN_SAVE_FILE_CONTENT_AS_TEXT_DOCLING',
'docling').
" --from pdf --to text '".escapeshellcmd($filetoprocess).
"'";
2258 $resultexec = $utils->executeCLI($cmd, $outputfile, 0,
null, 1);
2260 if (!$resultexec[
'error']) {
2261 $txt = $resultexec[
'output'];
2269 $textforfulltextindex = $txt;
2278 $ecmfile->description =
'File content generated by '.$cmd;
2280 $ecmfile->content = $textforfulltextindex;
2281 $ecmfile->keywords = $keywords;
2285 $result = $ecmfile->create($user);
2305 global
$conf, $db, $user;
2310 dol_syslog(
"deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
2316 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
2318 $filename = basename($file);
2319 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
2320 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
2323 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'ecm_files';
2324 $sql .=
' WHERE entity = '.$conf->entity;
2325 $sql .=
" AND filepath = '".$db->escape($rel_dir).
"'";
2327 $sql .=
" AND filename = '".$db->escape($file).
"'";
2330 $sql .=
" AND gen_or_uploaded = '".$db->escape($mode).
"'";
2333 $resql = $db->query($sql);
2336 dol_syslog(__FUNCTION__.
' '.$db->lasterror(), LOG_ERR);
2364 if (class_exists(
'Imagick')) {
2365 $image =
new Imagick();
2367 $filetoconvert = $fileinput.(($page !=
'') ?
'['.$page.
']' :
'');
2369 $ret = $image->readImage($filetoconvert);
2371 $ext = pathinfo($fileinput, PATHINFO_EXTENSION);
2372 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);
2376 $ret = $image->setImageFormat($ext);
2378 if (empty($fileoutput)) {
2379 $fileoutput = $fileinput.
".".$ext;
2382 $count = $image->getNumberImages();
2384 if (!
dol_is_file($fileoutput) || is_writable($fileoutput)) {
2386 $ret = $image->writeImages($fileoutput,
true);
2391 dol_syslog(
"Warning: Failed to write cache preview file '.$fileoutput.'. Check permission on file/dir", LOG_ERR);
2421function dol_compress_file($inputfile, $outputfile, $mode =
"gz", &$errorstring =
null)
2427 dol_syslog(
"dol_compress_file mode=".$mode.
" inputfile=".$inputfile.
" outputfile=".$outputfile);
2430 $compressdata =
null;
2431 if ($mode ==
'gz' && function_exists(
'gzencode')) {
2433 $compressdata = gzencode($data, 9);
2434 } elseif ($mode ==
'bz' && function_exists(
'bzcompress')) {
2436 $compressdata = bzcompress($data, 9);
2437 } elseif ($mode ==
'zstd' && function_exists(
'zstd_compress')) {
2439 $compressdata = zstd_compress($data, 9);
2440 } elseif ($mode ==
'zip') {
2441 if (class_exists(
'ZipArchive') &&
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_COMPRESS')) {
2444 $rootPath = realpath($inputfile);
2446 dol_syslog(
"Class ZipArchive is set so we zip using ZipArchive to zip into ".$outputfile.
' rootPath='.$rootPath);
2447 $zip =
new ZipArchive();
2449 if ($zip->open($outputfile, ZipArchive::CREATE) !==
true) {
2450 $errorstring =
"dol_compress_file failure - Failed to open file ".$outputfile.
"\n";
2454 $errormsg = $errorstring;
2461 $files =
new RecursiveIteratorIterator(
2462 new RecursiveDirectoryIterator($rootPath, FilesystemIterator::UNIX_PATHS),
2463 RecursiveIteratorIterator::LEAVES_ONLY
2465 '@phan-var-force SplFileInfo[] $files';
2467 foreach ($files as $name => $file) {
2469 if (!$file->isDir()) {
2471 $filePath = $file->getPath();
2472 $fileName = $file->getFilename();
2473 $fileFullRealPath = $file->getRealPath();
2476 $relativePath = substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($rootPath) + 1);
2479 $zip->addFile($fileFullRealPath, $relativePath);
2486 dol_syslog(
"dol_compress_file success - ".$zip->numFiles.
" files");
2490 if (defined(
'ODTPHP_PATHTOPCLZIP')) {
2493 include_once ODTPHP_PATHTOPCLZIP.
'pclzip.lib.php';
2494 $archive =
new PclZip($outputfile);
2496 $result = $archive->add($inputfile, PCLZIP_OPT_REMOVE_PATH, dirname($inputfile));
2498 if ($result === 0) {
2500 $errormsg = $archive->errorInfo(
true);
2502 if ($archive->errorCode() == PCLZIP_ERR_WRITE_OPEN_FAIL) {
2503 $errorstring =
"PCLZIP_ERR_WRITE_OPEN_FAIL";
2504 dol_syslog(
"dol_compress_file error - archive->errorCode() = PCLZIP_ERR_WRITE_OPEN_FAIL", LOG_ERR);
2508 $errorstring =
"dol_compress_file error archive->errorCode = ".$archive->errorCode().
" errormsg=".$errormsg;
2509 dol_syslog(
"dol_compress_file failure - ".$errormsg, LOG_ERR);
2512 dol_syslog(
"dol_compress_file success - ".count($result).
" files");
2518 if ($foundhandler && is_string($compressdata)) {
2519 $fp = fopen($outputfile,
"w");
2520 fwrite($fp, $compressdata);
2524 $errorstring =
"Try to zip with format ".$mode.
" with no handler for this format";
2528 $errormsg = $errorstring;
2532 global $langs, $errormsg;
2533 $langs->load(
"errors");
2534 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir");
2536 $errorstring =
"Failed to open file ".$outputfile;
2554 $fileinfo = pathinfo($inputfile);
2555 $fileinfo[
"extension"] = strtolower($fileinfo[
"extension"]);
2557 if ($fileinfo[
"extension"] ==
"zip") {
2558 if (defined(
'ODTPHP_PATHTOPCLZIP') && !
getDolGlobalString(
'MAIN_USE_ZIPARCHIVE_FOR_ZIP_UNCOMPRESS')) {
2559 dol_syslog(
"Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".ODTPHP_PATHTOPCLZIP.
", so we use Pclzip to unzip into ".$outputdir);
2560 include_once ODTPHP_PATHTOPCLZIP.
'pclzip.lib.php';
2561 $archive =
new PclZip($inputfile);
2568 $result = $archive->extract(PCLZIP_OPT_PATH, $outputdir, PCLZIP_OPT_BY_PREG,
'/^((?!\.\.).)*$/');
2570 return array(
'error' => $e->getMessage());
2573 if (!is_array($result) && $result <= 0) {
2574 return array(
'error' => $archive->errorInfo(
true));
2579 foreach ($result as $key => $val) {
2580 if ($val[
'status'] ==
'path_creation_fail') {
2581 $langs->load(
"errors");
2583 $errmsg = $langs->trans(
"ErrorFailToCreateDir", $val[
'filename']);
2586 if ($val[
'status'] ==
'write_protected') {
2587 $langs->load(
"errors");
2589 $errmsg = $langs->trans(
"ErrorFailToCreateFile", $val[
'filename']);
2597 return array(
'error' => $errmsg);
2602 if (class_exists(
'ZipArchive')) {
2603 dol_syslog(
"Class ZipArchive is set so we unzip using ZipArchive to unzip into ".$outputdir);
2604 $zip =
new ZipArchive();
2605 $res = $zip->open($inputfile);
2606 if ($res ===
true) {
2612 for ($i = 0; $i < $zip->numFiles; $i++) {
2613 if (preg_match(
'/\.\./', $zip->getNameIndex($i))) {
2614 dol_syslog(
"Warning: Try to unzip a file with a transversal path ".$zip->getNameIndex($i), LOG_WARNING);
2617 $zip->extractTo($outputdir.
'/', array($zip->getNameIndex($i)));
2623 return array(
'error' =>
'ErrUnzipFails');
2627 return array(
'error' =>
'ErrNoZipEngine');
2628 } elseif (in_array($fileinfo[
"extension"], array(
'gz',
'bz2',
'zst'))) {
2629 include_once DOL_DOCUMENT_ROOT.
"/core/class/utils.class.php";
2630 $utils =
new Utils($db);
2637 $extension = strtolower(pathinfo($fileinfo[
"filename"], PATHINFO_EXTENSION));
2638 if ($extension ==
"tar") {
2641 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0, $outputfilename.
'.err', 0);
2642 if ($resarray[
"result"] != 0) {
2643 $resarray[
"error"] .= file_get_contents($outputfilename.
'.err');
2647 if ($fileinfo[
"extension"] ==
"gz") {
2649 } elseif ($fileinfo[
"extension"] ==
"bz2") {
2651 } elseif ($fileinfo[
"extension"] ==
"zst") {
2654 return array(
'error' =>
'ErrorBadFileExtension');
2657 $cmd .=
' > '.$outputfilename;
2659 $resarray = $utils->executeCLI($cmd, $outputfilename.
'.tmp', 0,
null, 1, $outputfilename.
'.err');
2660 if ($resarray[
"result"] != 0) {
2661 $errfilecontent = @file_get_contents($outputfilename.
'.err');
2662 if ($errfilecontent) {
2663 $resarray[
"error"] .=
" - ".$errfilecontent;
2667 return $resarray[
"result"] != 0 ? array(
'error' => $resarray[
"error"]) : array();
2670 return array(
'error' =>
'ErrorBadFileExtension');
2686function dol_compress_dir($inputdir, $outputfile, $mode =
"zip", $excludefiles =
'', $rootdirinzip =
'', $newmask =
'0')
2690 dol_syslog(
"Try to zip dir ".$inputdir.
" into ".$outputfile.
" mode=".$mode);
2692 if (!
dol_is_dir(dirname($outputfile)) || !is_writable(dirname($outputfile))) {
2693 global $langs, $errormsg;
2694 $langs->load(
"errors");
2695 $errormsg = $langs->trans(
"ErrorFailedToWriteInDir", $outputfile);
2700 if ($mode ==
'gz') {
2702 } elseif ($mode ==
'bz') {
2704 } elseif ($mode ==
'zip') {
2718 if (class_exists(
'ZipArchive')) {
2722 $zip =
new ZipArchive();
2723 $result = $zip->open($outputfile, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2724 if ($result !==
true) {
2725 global $langs, $errormsg;
2726 $langs->load(
"errors");
2727 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile);
2734 $files =
new RecursiveIteratorIterator(
2735 new RecursiveDirectoryIterator($inputdir, FilesystemIterator::UNIX_PATHS),
2736 RecursiveIteratorIterator::LEAVES_ONLY
2738 '@phan-var-force SplFileInfo[] $files';
2741 foreach ($files as $name => $file) {
2743 if (!$file->isDir()) {
2745 $filePath = $file->getPath();
2746 $fileName = $file->getFilename();
2747 $fileFullRealPath = $file->getRealPath();
2750 $relativePath = ($rootdirinzip ? $rootdirinzip.
'/' :
'').substr(($filePath ? $filePath.
'/' :
'').$fileName, strlen($inputdir) + 1);
2753 if (empty($excludefiles) || !preg_match($excludefiles, $fileFullRealPath)) {
2755 $zip->addFile($fileFullRealPath, $relativePath);
2766 if (empty($newmask)) {
2767 dol_syslog(
"Warning: dol_copy called with empty value for newmask and no default value defined", LOG_WARNING);
2777 if (!$foundhandler) {
2778 dol_syslog(
"Try to zip with format ".$mode.
" with no handler for this format", LOG_ERR);
2784 global $langs, $errormsg;
2785 $langs->load(
"errors");
2786 dol_syslog(
"Failed to open file ".$outputfile, LOG_ERR);
2788 $errormsg = $langs->trans(
"ErrorFailedToBuildArchive", $outputfile).
' - '.$e->getMessage();
2805function dol_most_recent_file($dir, $regexfilter =
'', $excludefilter = array(
'(\.meta|_preview.*\.png)$',
'^\.'), $nohook = 0, $mode = 0)
2807 $tmparray =
dol_dir_list($dir,
'files', 0, $regexfilter, $excludefilter,
'date', SORT_DESC, $mode, $nohook);
2808 return isset($tmparray[0]) ? $tmparray[0] :
null;
2826 global
$conf, $db, $user, $hookmanager;
2827 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2830 if (!is_object($fuser)) {
2834 if (empty($modulepart)) {
2835 return 'ErrorBadParameter';
2837 if (empty($entity)) {
2838 if (!isModEnabled(
'multicompany')) {
2845 if ($modulepart ==
'facture') {
2846 $modulepart =
'invoice';
2847 } elseif ($modulepart ==
'users') {
2848 $modulepart =
'user';
2849 } elseif ($modulepart ==
'tva') {
2850 $modulepart =
'tax-vat';
2851 } elseif ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
2853 $modulepart =
'delivery';
2857 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2861 $sqlprotectagainstexternals =
'';
2865 if (empty($refname)) {
2866 $refname = basename(dirname($original_file).
"/");
2867 if ($refname ==
'thumbs' || $refname ==
'temp') {
2869 $refname = basename(dirname(dirname($original_file)).
"/");
2876 $download =
'download';
2877 if ($mode ==
'write') {
2880 $download =
'upload';
2884 if ($modulepart ==
'common') {
2887 $original_file = DOL_DOCUMENT_ROOT.
'/public/theme/common/'.$original_file;
2888 } elseif ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2893 if (empty($entity)) {
2897 $original_file = (empty(
$conf->medias->multidir_output[$entity]) ?
$conf->medias->dir_output :
$conf->medias->multidir_output[$entity]).
'/'.$original_file;
2898 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2900 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
2901 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2902 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2904 $accessallowed = $user->admin;
2905 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2906 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2908 $accessallowed = ($fuser->hasRight(
'website',
'write') && preg_match(
'/\.jpg$/i', basename($original_file)));
2909 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2910 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2913 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2916 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2917 $original_file = $dirins.
'/'.$original_file;
2918 } elseif ($modulepart ==
'mycompany' && !empty(
$conf->mycompany->dir_output)) {
2921 $original_file =
$conf->mycompany->dir_output.
'/'.$original_file;
2922 } elseif ($modulepart ==
'userphoto' && !empty(
$conf->user->dir_output)) {
2925 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2928 $original_file =
$conf->user->dir_output.
'/'.$original_file;
2929 } elseif ($modulepart ==
'userphotopublic' && !empty(
$conf->user->dir_output)) {
2934 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
2936 $tmpobject =
new User($db);
2937 $tmpobject->fetch($reg[1],
'',
'', 1);
2939 $securekey =
GETPOST(
'securekey',
'alpha', 1);
2941 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
2942 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
2943 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
2944 if ($encodedsecurekey == $securekey) {
2953 $original_file =
$conf->user->dir_output.
'/'.$original_file;
2954 } elseif (($modulepart ==
'companylogo') && !empty(
$conf->mycompany->dir_output)) {
2957 $original_file =
$conf->mycompany->dir_output.
'/logos/'.$original_file;
2958 } elseif ($modulepart ==
'memberphoto' && !empty(
$conf->member->dir_output)) {
2961 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2964 $original_file =
$conf->member->dir_output.
'/'.$original_file;
2965 } elseif ($modulepart ==
'apercufacture' && !empty(
$conf->invoice->multidir_output[$entity])) {
2967 if ($fuser->hasRight(
'facture', $lire)) {
2970 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
2971 } elseif ($modulepart ==
'apercupropal' && !empty(
$conf->propal->multidir_output[$entity])) {
2973 if ($fuser->hasRight(
'propal', $lire)) {
2976 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
2977 } elseif ($modulepart ==
'apercucommande' && !empty(
$conf->order->multidir_output[$entity])) {
2979 if ($fuser->hasRight(
'commande', $lire)) {
2982 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
2983 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty(
$conf->ficheinter->dir_output)) {
2985 if ($fuser->hasRight(
'ficheinter', $lire)) {
2988 $original_file =
$conf->ficheinter->dir_output.
'/'.$original_file;
2989 } elseif (($modulepart ==
'apercucontract') && !empty(
$conf->contract->multidir_output[$entity])) {
2991 if ($fuser->hasRight(
'contrat', $lire)) {
2994 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
2995 } elseif (($modulepart ==
'apercusupplier_proposal') && !empty(
$conf->supplier_proposal->dir_output)) {
2997 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
3000 $original_file =
$conf->supplier_proposal->dir_output.
'/'.$original_file;
3001 } elseif (($modulepart ==
'apercusupplier_order') && !empty(
$conf->fournisseur->commande->dir_output)) {
3003 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3006 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3007 } elseif (($modulepart ==
'apercusupplier_invoice') && !empty(
$conf->fournisseur->facture->dir_output)) {
3009 if ($fuser->hasRight(
'fournisseur', $lire)) {
3012 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3013 } elseif (($modulepart ==
'holiday') && !empty(
$conf->holiday->dir_output)) {
3014 if ($fuser->hasRight(
'holiday', $read) || $fuser->hasRight(
'holiday',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3017 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3018 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
3019 $tmpholiday =
new Holiday($db);
3020 $tmpholiday->fetch(0, $refname);
3021 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
3024 $original_file =
$conf->holiday->dir_output.
'/'.$original_file;
3025 } elseif (($modulepart ==
'expensereport') && !empty(
$conf->expensereport->dir_output)) {
3026 if ($fuser->hasRight(
'expensereport', $lire) || $fuser->hasRight(
'expensereport',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
3029 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
3030 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
3032 $tmpexpensereport->fetch(0, $refname);
3033 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
3036 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3037 } elseif (($modulepart ==
'apercuexpensereport') && !empty(
$conf->expensereport->dir_output)) {
3039 if ($fuser->hasRight(
'expensereport', $lire)) {
3042 $original_file =
$conf->expensereport->dir_output.
'/'.$original_file;
3043 } elseif ($modulepart ==
'propalstats' && !empty(
$conf->propal->multidir_temp[$entity])) {
3045 if ($fuser->hasRight(
'propal', $lire)) {
3048 $original_file =
$conf->propal->multidir_temp[$entity].
'/'.$original_file;
3049 } elseif ($modulepart ==
'orderstats' && !empty(
$conf->order->dir_temp)) {
3051 if ($fuser->hasRight(
'commande', $lire)) {
3054 $original_file =
$conf->order->dir_temp.
'/'.$original_file;
3055 } elseif ($modulepart ==
'orderstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3056 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
3059 $original_file =
$conf->fournisseur->commande->dir_temp.
'/'.$original_file;
3060 } elseif ($modulepart ==
'billstats' && !empty(
$conf->invoice->dir_temp)) {
3062 if ($fuser->hasRight(
'facture', $lire)) {
3065 $original_file =
$conf->invoice->dir_temp.
'/'.$original_file;
3066 } elseif ($modulepart ==
'billstatssupplier' && !empty(
$conf->fournisseur->dir_output)) {
3067 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
3070 $original_file =
$conf->fournisseur->facture->dir_temp.
'/'.$original_file;
3071 } elseif ($modulepart ==
'expeditionstats' && !empty(
$conf->expedition->dir_temp)) {
3073 if ($fuser->hasRight(
'expedition', $lire)) {
3076 $original_file =
$conf->expedition->dir_temp.
'/'.$original_file;
3077 } elseif ($modulepart ==
'tripsexpensesstats' && !empty(
$conf->deplacement->dir_temp)) {
3079 if ($fuser->hasRight(
'deplacement', $lire)) {
3082 $original_file =
$conf->deplacement->dir_temp.
'/'.$original_file;
3083 } elseif ($modulepart ==
'memberstats' && !empty(
$conf->member->dir_temp)) {
3085 if ($fuser->hasRight(
'adherent', $lire)) {
3088 $original_file =
$conf->member->dir_temp.
'/'.$original_file;
3089 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty(
$conf->product->dir_temp)) {
3091 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
3094 $original_file = (!empty(
$conf->product->multidir_temp[$entity]) ?
$conf->product->multidir_temp[$entity] :
$conf->service->multidir_temp[$entity]).
'/'.$original_file;
3095 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty(
$conf->tax->dir_output)) {
3097 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
3100 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
3101 $original_file =
$conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
3102 } elseif ($modulepart ==
'actions' && !empty(
$conf->agenda->dir_output)) {
3104 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
3107 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3108 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
3110 $tmpobject->fetch((
int) $refname);
3111 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
3112 if ($user->socid && $tmpobject->socid) {
3117 $original_file =
$conf->agenda->dir_output.
'/'.$original_file;
3118 } elseif ($modulepart ==
'category' && !empty(
$conf->categorie->multidir_output[$entity])) {
3120 if (empty($entity) || empty(
$conf->categorie->multidir_output[$entity])) {
3121 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3123 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
3126 $original_file =
$conf->categorie->multidir_output[$entity].
'/'.$original_file;
3127 } elseif ($modulepart ==
'prelevement' && !empty(
$conf->prelevement->dir_output)) {
3129 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3132 $original_file =
$conf->prelevement->dir_output.
'/'.$original_file;
3133 } elseif ($modulepart ==
'graph_stock' && !empty(
$conf->stock->dir_temp)) {
3136 $original_file =
$conf->stock->dir_temp.
'/'.$original_file;
3137 } elseif ($modulepart ==
'graph_fourn' && !empty(
$conf->fournisseur->dir_temp)) {
3140 $original_file =
$conf->fournisseur->dir_temp.
'/'.$original_file;
3141 } elseif ($modulepart ==
'graph_product' && !empty(
$conf->product->dir_temp)) {
3144 $original_file =
$conf->product->multidir_temp[$entity].
'/'.$original_file;
3145 } elseif ($modulepart ==
'barcode') {
3150 $original_file =
'';
3151 } elseif ($modulepart ==
'iconmailing' && !empty(
$conf->mailing->dir_temp)) {
3154 $original_file =
$conf->mailing->dir_temp.
'/'.$original_file;
3155 } elseif ($modulepart ==
'scanner_user_temp' && !empty(
$conf->scanner->dir_temp)) {
3158 $original_file =
$conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3159 } elseif ($modulepart ==
'fckeditor' && !empty(
$conf->fckeditor->dir_output)) {
3162 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3163 } elseif ($modulepart ==
'user' && !empty(
$conf->user->dir_output)) {
3165 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
3166 if ($fuser->id == (
int) $refname) {
3169 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
3172 $original_file =
$conf->user->dir_output.
'/'.$original_file;
3173 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty(
$conf->societe->multidir_output[$entity])) {
3175 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3176 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3178 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3181 $original_file =
$conf->societe->multidir_output[$entity].
'/'.$original_file;
3182 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
3183 } elseif ($modulepart ==
'contact' && !empty(
$conf->societe->multidir_output[$entity])) {
3185 if (empty($entity) || empty(
$conf->societe->multidir_output[$entity])) {
3186 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3188 if ($fuser->hasRight(
'societe', $lire)) {
3191 $original_file =
$conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
3192 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty(
$conf->invoice->multidir_output[$entity])) {
3194 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3197 $original_file =
$conf->invoice->multidir_output[$entity].
'/'.$original_file;
3198 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
3199 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty(
$conf->propal->multidir_output[$entity])) {
3201 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3204 $original_file =
$conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3205 } elseif ($modulepart ==
'massfilesarea_orders') {
3206 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3209 $original_file =
$conf->order->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3210 } elseif ($modulepart ==
'massfilesarea_sendings') {
3211 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3214 $original_file =
$conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
3215 } elseif ($modulepart ==
'massfilesarea_receipts') {
3216 if ($fuser->hasRight(
'reception', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3219 $original_file =
$conf->reception->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3220 } elseif ($modulepart ==
'massfilesarea_invoices') {
3221 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3224 $original_file =
$conf->invoice->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3225 } elseif ($modulepart ==
'massfilesarea_expensereport') {
3226 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3229 $original_file =
$conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3230 } elseif ($modulepart ==
'massfilesarea_interventions') {
3231 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3234 $original_file =
$conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3235 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty(
$conf->supplier_proposal->dir_output)) {
3236 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3239 $original_file =
$conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3240 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
3241 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3244 $original_file =
$conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3245 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
3246 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3249 $original_file =
$conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3250 } elseif ($modulepart ==
'massfilesarea_contract' && !empty(
$conf->contract->dir_output)) {
3251 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3254 $original_file =
$conf->contract->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3255 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty(
$conf->ficheinter->dir_output)) {
3257 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3260 $original_file =
$conf->ficheinter->dir_output.
'/'.$original_file;
3261 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3262 } elseif ($modulepart ==
'deplacement' && !empty(
$conf->deplacement->dir_output)) {
3264 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3267 $original_file =
$conf->deplacement->dir_output.
'/'.$original_file;
3269 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset(
$conf->propal->multidir_output[$entity])) {
3271 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3274 $original_file =
$conf->propal->multidir_output[$entity].
'/'.$original_file;
3275 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3276 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty(
$conf->order->multidir_output[$entity])) {
3278 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3281 $original_file =
$conf->order->multidir_output[$entity].
'/'.$original_file;
3282 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3283 } elseif ($modulepart ==
'project' && !empty(
$conf->project->multidir_output[$entity])) {
3285 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3288 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3289 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3290 $tmpproject =
new Project($db);
3291 $tmpproject->fetch(0, $refname);
3292 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3295 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3296 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3297 } elseif ($modulepart ==
'project_task' && !empty(
$conf->project->multidir_output[$entity])) {
3298 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3301 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3302 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3303 $tmptask =
new Task($db);
3304 $tmptask->fetch(0, $refname);
3305 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3308 $original_file =
$conf->project->multidir_output[$entity].
'/'.$original_file;
3309 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3310 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty(
$conf->fournisseur->commande->dir_output)) {
3312 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3315 $original_file =
$conf->fournisseur->commande->dir_output.
'/'.$original_file;
3316 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3317 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty(
$conf->fournisseur->facture->dir_output)) {
3319 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3322 $original_file =
$conf->fournisseur->facture->dir_output.
'/'.$original_file;
3323 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3324 } elseif ($modulepart ==
'supplier_payment') {
3326 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3329 $original_file =
$conf->fournisseur->payment->dir_output.
'/'.$original_file;
3330 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".
$conf->entity;
3331 } elseif ($modulepart ==
'payment') {
3333 if ($fuser->rights->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3336 $original_file =
$conf->compta->payment->dir_output.
'/'.$original_file;
3337 } elseif ($modulepart ==
'facture_paiement' && !empty(
$conf->invoice->dir_output)) {
3339 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3342 if ($fuser->socid > 0) {
3343 $original_file =
$conf->invoice->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3345 $original_file =
$conf->invoice->dir_output.
'/payments/'.$original_file;
3347 } elseif ($modulepart ==
'export_compta' && !empty(
$conf->accounting->dir_output)) {
3349 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3352 $original_file =
$conf->accounting->dir_output.
'/'.$original_file;
3353 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty(
$conf->expedition->dir_output)) {
3355 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3358 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3360 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty(
$conf->expedition->dir_output)) {
3362 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3365 $original_file =
$conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3366 } elseif ($modulepart ==
'actionsreport' && !empty(
$conf->agenda->dir_temp)) {
3368 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3371 $original_file =
$conf->agenda->dir_temp.
"/".$original_file;
3372 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3374 if (empty($entity) || (empty(
$conf->product->multidir_output[$entity]) && empty(
$conf->service->multidir_output[$entity]))) {
3375 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3377 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3380 if (isModEnabled(
"product")) {
3381 $original_file =
$conf->product->multidir_output[$entity].
'/'.$original_file;
3382 } elseif (isModEnabled(
"service")) {
3383 $original_file =
$conf->service->multidir_output[$entity].
'/'.$original_file;
3385 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3387 if (empty($entity) || (empty(
$conf->productbatch->multidir_output[$entity]))) {
3388 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3390 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3393 if (isModEnabled(
'productbatch')) {
3394 $original_file =
$conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3396 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3398 if (empty($entity) || empty(
$conf->stock->multidir_output[$entity])) {
3399 return array(
'accessallowed' => 0,
'error' =>
'Value entity must be provided');
3401 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3404 if (isModEnabled(
'stock')) {
3405 $original_file =
$conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3407 } elseif ($modulepart ==
'contract' && !empty(
$conf->contract->multidir_output[$entity])) {
3409 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3412 $original_file =
$conf->contract->multidir_output[$entity].
'/'.$original_file;
3413 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3414 } elseif ($modulepart ==
'donation' && !empty(
$conf->don->dir_output)) {
3416 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3419 $original_file =
$conf->don->dir_output.
'/'.$original_file;
3420 } elseif ($modulepart ==
'dolresource' && !empty(
$conf->resource->dir_output)) {
3422 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3425 $original_file =
$conf->resource->dir_output.
'/'.$original_file;
3426 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty(
$conf->bank->dir_output)) {
3428 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3431 $original_file =
$conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3432 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty(
$conf->bank->dir_output)) {
3434 if ($fuser->hasRight(
'banque', $lire)) {
3437 $original_file =
$conf->bank->dir_output.
'/'.$original_file;
3438 } elseif ($modulepart ==
'export' && !empty(
$conf->export->dir_temp)) {
3441 $accessallowed = $user->hasRight(
'export',
'lire');
3442 $original_file =
$conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3443 } elseif ($modulepart ==
'import' && !empty(
$conf->import->dir_temp)) {
3445 $accessallowed = $user->hasRight(
'import',
'run');
3446 $original_file =
$conf->import->dir_temp.
'/'.$original_file;
3447 } elseif ($modulepart ==
'recruitment' && !empty(
$conf->recruitment->dir_output)) {
3449 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3450 $original_file =
$conf->recruitment->dir_output.
'/'.$original_file;
3451 } elseif ($modulepart ==
'editor' && !empty(
$conf->fckeditor->dir_output)) {
3454 $original_file =
$conf->fckeditor->dir_output.
'/'.$original_file;
3455 } elseif ($modulepart ==
'systemtools' && !empty(
$conf->admin->dir_output)) {
3457 if ($fuser->admin) {
3460 $original_file =
$conf->admin->dir_output.
'/'.$original_file;
3461 } elseif ($modulepart ==
'admin_temp' && !empty(
$conf->admin->dir_temp)) {
3463 if ($fuser->admin) {
3466 $original_file =
$conf->admin->dir_temp.
'/'.$original_file;
3467 } elseif ($modulepart ==
'bittorrent' && !empty(
$conf->bittorrent->dir_output)) {
3471 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3474 $original_file =
$conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3475 } elseif ($modulepart ==
'member' && !empty(
$conf->member->dir_output)) {
3477 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3480 $original_file =
$conf->member->dir_output.
'/'.$original_file;
3490 if (preg_match(
'/^specimen/i', $original_file)) {
3493 if ($fuser->admin) {
3497 $tmpmodulepart = explode(
'-', $modulepart);
3498 if (!empty($tmpmodulepart[1])) {
3499 $modulepart = $tmpmodulepart[0];
3500 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3505 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3506 $tmpmodule = $reg[1];
3507 if (empty(
$conf->$tmpmodule->dir_temp)) {
3508 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3511 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3514 $original_file =
$conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3515 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3516 $tmpmodule = $reg[1];
3517 if (empty(
$conf->$tmpmodule->dir_temp)) {
3518 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3521 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3524 $original_file =
$conf->$tmpmodule->dir_temp.
'/'.$original_file;
3525 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3526 $tmpmodule = $reg[1];
3527 if (empty(
$conf->$tmpmodule->dir_output)) {
3528 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3531 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3534 $original_file =
$conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3535 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3536 $tmpmodule = $reg[1];
3537 if (empty(
$conf->$tmpmodule->dir_output)) {
3538 dol_print_error(
null,
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3541 if ($fuser->hasRight($tmpmodule, $lire) || preg_match(
'/^specimen/i', $original_file)) {
3544 $original_file =
$conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3546 if (empty(
$conf->$modulepart->dir_output)) {
3547 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.');
3552 $partsofdirinoriginalfile = explode(
'/', $original_file);
3553 if (!empty($partsofdirinoriginalfile[1])) {
3554 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3555 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3559 if ($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) {
3563 if (is_array(
$conf->$modulepart->multidir_output) && !empty(
$conf->$modulepart->multidir_output[$entity])) {
3564 $original_file =
$conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3566 $original_file =
$conf->$modulepart->dir_output.
'/'.$original_file;
3570 $parameters = array(
3571 'modulepart' => $modulepart,
3572 'original_file' => $original_file,
3573 'entity' => $entity,
3578 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters,
$object);
3580 if (!empty($hookmanager->resArray[
'original_file'])) {
3581 $original_file = $hookmanager->resArray[
'original_file'];
3583 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3584 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3586 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3587 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3593 'accessallowed' => ($accessallowed ? 1 : 0),
3594 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3595 'original_file' => $original_file
3614 dol_syslog(
"Failed to create the cache directory ".$directory, LOG_WARNING);
3617 $cachefile = $directory.$filename;
3619 file_put_contents($cachefile, serialize(
$object), LOCK_EX);
3635 $cachefile = $directory.$filename;
3636 $refresh = !file_exists($cachefile) || ($now - $cachetime) >
dol_filemtime($cachefile);
3649 $cachefile = $directory.$filename;
3650 $object = unserialize(file_get_contents($cachefile));
3662 return preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'\//',
'', $pathfile);
3677function getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path =
'', $pathref =
'', &$checksumconcat = array())
3681 $exclude =
'install';
3683 foreach ($dir->md5file as $file) {
3684 $filename = $path.$file[
'name'];
3685 $file_list[
'insignature'][] = $filename;
3686 $expectedsize = (empty($file[
'size']) ?
'' : $file[
'size']);
3687 $expectedmd5 = (string) $file;
3689 if (!file_exists($pathref.
'/'.$filename)) {
3690 $file_list[
'missing'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize);
3692 $md5_local = md5_file($pathref.
'/'.$filename);
3694 if ($conffile ==
'/etc/dolibarr/conf.php' && $filename ==
'/filefunc.inc.php') {
3695 $checksumconcat[] = $expectedmd5;
3697 if ($md5_local != $expectedmd5) {
3698 $file_list[
'updated'][] = array(
'filename' => $filename,
'expectedmd5' => $expectedmd5,
'expectedsize' => $expectedsize,
'md5' => (
string) $md5_local);
3700 $checksumconcat[] = $md5_local;
3705 foreach ($dir->dir as $subdir) {
3706 getFilesUpdated($file_list, $subdir, $path.$subdir[
'name'].
'/', $pathref, $checksumconcat);
3724 $out .=
'<div id="'.$htmlname.
'Message" class="dragDropAreaMessage hidden"><span>'.
img_picto(
"",
'download').
'<br>'.$langs->trans(
"DropFileToAddItToObject").
'</span></div>';
3725 $out .=
"\n<!-- JS CODE TO ENABLE DRAG AND DROP OF FILE -->\n";
3728 jQuery(document).ready(function() {
3729 var enterTargetDragDrop = null;
3731 $("#'.$htmlname.
'").addClass("cssDragDropArea");
3733 $(".cssDragDropArea").on("dragenter", function(ev, ui) {
3734 var dataTransfer = ev.originalEvent.dataTransfer;
3735 var dataTypes = dataTransfer.types;
3736 //console.log(dataTransfer);
3737 //console.log(dataTypes);
3739 if (!dataTypes || ($.inArray(\'Files\', dataTypes) === -1)) {
3740 // The element dragged is not a file, so we avoid the "dragenter"
3741 ev.preventDefault();
3745 // Entering drop area. Highlight area
3746 console.log("dragAndDropFileUpload: We add class highlightDragDropArea")
3747 enterTargetDragDrop = ev.target;
3748 $(this).addClass("highlightDragDropArea");
3749 $("#'.$htmlname.
'Message").removeClass("hidden");
3750 ev.preventDefault();
3753 $(".cssDragDropArea").on("dragleave", function(ev) {
3754 // Going out of drop area. Remove Highlight
3755 if (enterTargetDragDrop == ev.target){
3756 console.log("dragAndDropFileUpload: We remove class highlightDragDropArea")
3757 $("#'.$htmlname.
'Message").addClass("hidden");
3758 $(this).removeClass("highlightDragDropArea");
3762 $(".cssDragDropArea").on("dragover", function(ev) {
3763 ev.preventDefault();
3767 $(".cssDragDropArea").on("drop", function(e) {
3770 fd = new FormData();
3774 fd.append("action", "linkit");
3776 var dataTransfer = e.originalEvent.dataTransfer;
3778 if (dataTransfer.files && dataTransfer.files.length){
3779 var droppedFiles = e.originalEvent.dataTransfer.files;
3780 $.each(droppedFiles, function(index,file){
3781 fd.append("files[]", file,file.name)
3784 $(".cssDragDropArea").removeClass("highlightDragDropArea");
3785 counterdragdrop = 0;
3787 url: "'.DOL_URL_ROOT.
'/core/ajax/fileupload.php",
3792 success:function() {
3793 console.log("Uploaded.", arguments);
3794 /* arguments[0] is the json string of files */
3795 /* arguments[1] is the value for variable "success", can be 0 or 1 */
3796 let listoffiles = JSON.parse(arguments[0]);
3797 console.log(listoffiles);
3799 for (let i = 0; i < listoffiles.length; i++) {
3800 console.log(listoffiles[i].error);
3801 if (listoffiles[i].error) {
3805 console.log(nboferror);
3806 if (nboferror > 0) {
3807 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorOnAtLeastOneFileUpload:warnings";
3809 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=UploadFileDragDropSuccess:mesgs";
3813 console.log("Error Uploading.", arguments)
3814 if (arguments[0].status == 403) {
3815 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadPermissionDenied:errors";
3817 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?id='.
dol_escape_js(
$object->id).
'&seteventmessages=ErrorUploadFileDragDropPermissionDenied:errors";
3823 $out .=
"</script>\n";
3837function archiveOrBackupFile($srcfile, $max_versions = 5, $archivedir =
'', $suffix =
"v", $moveorcopy =
'move')
3839 $base_file_pattern = ($archivedir ? $archivedir : dirname($srcfile)).
'/'.basename($srcfile).
".".$suffix;
3840 $files_in_directory = glob($base_file_pattern .
"*");
3843 $files_with_timestamps = [];
3844 foreach ($files_in_directory as $file) {
3845 $files_with_timestamps[] = [
3847 'timestamp' => filemtime($file)
3853 while (count($files_with_timestamps) > 0) {
3854 $latest_file =
null;
3855 $latest_index =
null;
3858 foreach ($files_with_timestamps as $index => $file_info) {
3859 if ($latest_file ===
null || (is_array($latest_file) && $file_info[
'timestamp'] > $latest_file[
'timestamp'])) {
3860 $latest_file = $file_info;
3861 $latest_index = $index;
3866 if ($latest_file !==
null) {
3867 $sorted_files[] = $latest_file[
'file'];
3868 unset($files_with_timestamps[$latest_index]);
3873 if (count($sorted_files) >= $max_versions) {
3874 $oldest_files = array_slice($sorted_files, $max_versions - 1);
3875 foreach ($oldest_files as $oldest_file) {
3881 $new_backup = $srcfile .
".v" . $timestamp;
3884 if ($moveorcopy ==
'move') {
3885 $result =
dol_move($srcfile, $new_backup,
'0', 1, 0, 0);
3887 $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_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_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_uncompress($inputfile, $outputdir)
Uncompress a file.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
dol_check_secure_access_document($modulepart, $original_file, $entity, $fuser=null, $refname='', $mode='read')
Security check when accessing to a document (used by document.php, viewimage.php and webservices to g...
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTestIndexation='')
Get and save an upload file (for example after submitting a new file a mail form).
dol_init_file_process($pathtoscan='', $trackid='')
Scan a directory and init $_SESSION to manage uploaded files with list of all found files.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert an image file or a PDF into another image format.
dol_filecache($directory, $filename, $object)
Store object in file.
dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayreplacement=null, $excludesubdir=0, $excludefileext=null, $excludearchivefiles=0)
Copy a dir to another dir.
dragAndDropFileUpload($htmlname)
Function to manage the drag and drop of a file.
dol_is_file($pathoffile)
Return if path is a file.
dol_count_nb_of_line($file)
Count number of lines in a file.
dolCheckVirus($src_file, $dest_file='')
Check virus into a file.
dol_unescapefile($filename)
Unescape a file submitted by upload.
dol_dir_is_emtpy($folder)
Test if a folder is empty.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
dolCheckOnFileName($src_file, $dest_file='')
Check virus into a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded')
Delete files into database index using search criteria.
dol_readcachefile($directory, $filename)
Read object from cachefile.
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png) $', '^\.'), $nohook=0, $mode=0)
Return file(s) into a directory (by default most recent)
dol_is_dir($folder)
Test if filename is a directory.
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.