949function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array())
951 global $user, $db, $conf;
954 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
959 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
963 if ($overwriteifexists || !$destexists) {
968 $testvirusarray = array();
971 if (count($testvirusarray)) {
972 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
977 global $dolibarr_main_restrict_os_commands;
978 if (!empty($dolibarr_main_restrict_os_commands)) {
979 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
980 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
981 if (in_array(basename($destfile), $arrayofallowedcommand)) {
984 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);
989 $result = @rename($newpathofsrcfile, $newpathofdestfile);
992 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
995 $result = @rename($newpathofsrcfile, $newpathofdestfile);
997 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1002 if ($result && $indexdatabase) {
1004 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1005 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1006 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1007 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1008 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1011 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1012 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1014 $ecmfiletarget =
new EcmFiles($db);
1015 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
1016 if ($resultecmtarget > 0) {
1017 $ecmfiletarget->delete($user);
1021 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
1022 if ($resultecm > 0) {
1023 $filename = basename($rel_filetorenameafter);
1024 $rel_dir = dirname($rel_filetorenameafter);
1025 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1026 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1028 $ecmfile->filepath = $rel_dir;
1029 $ecmfile->filename = $filename;
1031 $resultecm = $ecmfile->update($user);
1032 } elseif ($resultecm == 0) {
1033 $filename = basename($rel_filetorenameafter);
1034 $rel_dir = dirname($rel_filetorenameafter);
1035 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1036 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1038 $ecmfile->filepath = $rel_dir;
1039 $ecmfile->filename = $filename;
1041 $ecmfile->fullpath_orig = basename($srcfile);
1042 $ecmfile->gen_or_uploaded =
'uploaded';
1043 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1044 $ecmfile->description = $moreinfo[
'description'];
1046 $ecmfile->description =
'';
1048 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1049 $ecmfile->keywords = $moreinfo[
'keywords'];
1051 $ecmfile->keywords =
'';
1053 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1054 $ecmfile->note_private = $moreinfo[
'note_private'];
1056 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1057 $ecmfile->note_public = $moreinfo[
'note_public'];
1059 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1060 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1062 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1063 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1066 $resultecm = $ecmfile->create($user);
1067 if ($resultecm < 0) {
1070 } elseif ($resultecm < 0) {
1074 if ($resultecm > 0) {
1082 if (empty($newmask)) {
1089 dolChmod($newpathofdestfile, $newmask);
2574 global $conf, $db, $user, $hookmanager;
2575 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2578 if (!is_object($fuser)) {
2582 if (empty($modulepart)) {
2583 return 'ErrorBadParameter';
2585 if (empty($entity)) {
2586 if (!isModEnabled(
'multicompany')) {
2593 if ($modulepart ==
'users') {
2594 $modulepart =
'user';
2596 if ($modulepart ==
'tva') {
2597 $modulepart =
'tax-vat';
2600 if ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
2601 $modulepart =
'delivery';
2605 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2609 $sqlprotectagainstexternals =
'';
2613 if (empty($refname)) {
2614 $refname = basename(dirname($original_file).
"/");
2615 if ($refname ==
'thumbs' || $refname ==
'temp') {
2617 $refname = basename(dirname(dirname($original_file)).
"/");
2624 $download =
'download';
2625 if ($mode ==
'write') {
2628 $download =
'upload';
2632 if ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2633 if (empty($entity) || empty($conf->medias->multidir_output[$entity])) {
2634 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2637 $original_file = $conf->medias->multidir_output[$entity].
'/'.$original_file;
2638 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2640 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
2641 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2642 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2644 $accessallowed = $user->admin;
2645 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2646 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2648 $accessallowed = ($fuser->rights->website->write && preg_match(
'/\.jpg$/i', basename($original_file)));
2649 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2650 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2653 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2656 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2657 $original_file = $dirins.
'/'.$original_file;
2658 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
2661 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
2662 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
2665 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2668 $original_file = $conf->user->dir_output.
'/'.$original_file;
2669 } elseif ($modulepart ==
'userphotopublic' && !empty($conf->user->dir_output)) {
2674 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
2676 $tmpobject =
new User($db);
2677 $tmpobject->fetch($reg[1],
'',
'', 1);
2679 $securekey =
GETPOST(
'securekey',
'alpha', 1);
2681 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
2682 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
2683 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
2684 if ($encodedsecurekey == $securekey) {
2693 $original_file = $conf->user->dir_output.
'/'.$original_file;
2694 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
2697 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
2698 } elseif ($modulepart ==
'memberphoto' && !empty($conf->adherent->dir_output)) {
2701 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2704 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
2705 } elseif ($modulepart ==
'apercufacture' && !empty($conf->facture->multidir_output[$entity])) {
2707 if ($fuser->hasRight(
'facture', $lire)) {
2710 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2711 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
2713 if ($fuser->hasRight(
'propal', $lire)) {
2716 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2717 } elseif ($modulepart ==
'apercucommande' && !empty($conf->commande->multidir_output[$entity])) {
2719 if ($fuser->hasRight(
'commande', $lire)) {
2722 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2723 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->dir_output)) {
2725 if ($fuser->hasRight(
'ficheinter', $lire)) {
2728 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2729 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contrat->multidir_output[$entity])) {
2731 if ($fuser->hasRight(
'contrat', $lire)) {
2734 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2735 } elseif (($modulepart ==
'apercusupplier_proposal' || $modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
2737 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
2740 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
2741 } elseif (($modulepart ==
'apercusupplier_order' || $modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
2743 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2746 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2747 } elseif (($modulepart ==
'apercusupplier_invoice' || $modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
2749 if ($fuser->hasRight(
'fournisseur', $lire)) {
2752 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2753 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
2754 if ($fuser->hasRight(
'holiday', $read) || $fuser->hasRight(
'holiday',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
2757 if ($refname && !$fuser->hasRight(
'holiday',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
2758 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
2759 $tmpholiday =
new Holiday($db);
2760 $tmpholiday->fetch(
'', $refname);
2761 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
2764 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
2765 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
2766 if ($fuser->hasRight(
'expensereport', $lire) || $fuser->hasRight(
'expensereport',
'readall') || preg_match(
'/^specimen/i', $original_file)) {
2769 if ($refname && !$fuser->hasRight(
'expensereport',
'readall') && !preg_match(
'/^specimen/i', $original_file)) {
2770 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
2772 $tmpexpensereport->fetch(
'', $refname);
2773 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
2776 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2777 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
2779 if ($fuser->hasRight(
'expensereport', $lire)) {
2782 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2783 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
2785 if ($fuser->hasRight(
'propal', $lire)) {
2788 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
2789 } elseif ($modulepart ==
'orderstats' && !empty($conf->commande->dir_temp)) {
2791 if ($fuser->hasRight(
'commande', $lire)) {
2794 $original_file = $conf->commande->dir_temp.
'/'.$original_file;
2795 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2796 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2799 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
2800 } elseif ($modulepart ==
'billstats' && !empty($conf->facture->dir_temp)) {
2802 if ($fuser->hasRight(
'facture', $lire)) {
2805 $original_file = $conf->facture->dir_temp.
'/'.$original_file;
2806 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2807 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
2810 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
2811 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
2813 if ($fuser->hasRight(
'expedition', $lire)) {
2816 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
2817 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
2819 if ($fuser->hasRight(
'deplacement', $lire)) {
2822 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
2823 } elseif ($modulepart ==
'memberstats' && !empty($conf->adherent->dir_temp)) {
2825 if ($fuser->hasRight(
'adherent', $lire)) {
2828 $original_file = $conf->adherent->dir_temp.
'/'.$original_file;
2829 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
2831 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
2834 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
2835 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
2837 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
2840 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
2841 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
2842 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2844 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
2847 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2848 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2850 $tmpobject->fetch((
int) $refname);
2851 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
2852 if ($user->socid && $tmpobject->socid) {
2857 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2858 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
2860 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
2861 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2863 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
2866 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
2867 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
2869 if ($fuser->hasRight(
'prelevement',
'bons', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2872 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
2873 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
2876 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
2877 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
2880 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
2881 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
2884 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
2885 } elseif ($modulepart ==
'barcode') {
2890 $original_file =
'';
2891 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
2894 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
2895 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
2898 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
2899 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
2902 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
2903 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
2905 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2906 if ($fuser->id == (
int) $refname) {
2909 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
2912 $original_file = $conf->user->dir_output.
'/'.$original_file;
2913 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
2915 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2916 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2918 if ($fuser->hasRight(
'societe', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2921 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
2922 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
2923 } elseif ($modulepart ==
'contact' && !empty($conf->societe->multidir_output[$entity])) {
2925 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2926 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2928 if ($fuser->hasRight(
'societe', $lire)) {
2931 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
2932 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->facture->multidir_output[$entity])) {
2934 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2937 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2938 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
2939 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
2941 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2944 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2945 } elseif ($modulepart ==
'massfilesarea_orders') {
2946 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2949 $original_file = $conf->commande->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2950 } elseif ($modulepart ==
'massfilesarea_sendings') {
2951 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2954 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
2955 } elseif ($modulepart ==
'massfilesarea_invoices') {
2956 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2959 $original_file = $conf->facture->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2960 } elseif ($modulepart ==
'massfilesarea_expensereport') {
2961 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2964 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2965 } elseif ($modulepart ==
'massfilesarea_interventions') {
2966 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2969 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2970 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
2971 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2974 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2975 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
2976 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2979 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2980 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
2981 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2984 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2985 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contrat->dir_output)) {
2986 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2989 $original_file = $conf->contrat->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2990 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->dir_output)) {
2992 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2995 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2996 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2997 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
2999 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3002 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
3004 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset($conf->propal->multidir_output[$entity])) {
3006 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3009 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3010 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3011 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->commande->multidir_output[$entity])) {
3013 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3016 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
3017 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3018 } elseif ($modulepart ==
'project' && !empty($conf->project->multidir_output[$entity])) {
3020 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3023 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3024 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3025 $tmpproject =
new Project($db);
3026 $tmpproject->fetch(
'', $refname);
3027 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3030 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3031 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3032 } elseif ($modulepart ==
'project_task' && !empty($conf->project->multidir_output[$entity])) {
3033 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3036 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3037 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3038 $tmptask =
new Task($db);
3039 $tmptask->fetch(
'', $refname);
3040 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3043 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3044 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3045 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
3047 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3050 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3051 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3052 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
3054 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3057 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3058 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3059 } elseif ($modulepart ==
'supplier_payment') {
3061 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3064 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
3065 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3066 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->facture->dir_output)) {
3068 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3071 if ($fuser->socid > 0) {
3072 $original_file = $conf->facture->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3074 $original_file = $conf->facture->dir_output.
'/payments/'.$original_file;
3076 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
3078 if ($fuser->hasRight(
'accounting',
'bind',
'write') || preg_match(
'/^specimen/i', $original_file)) {
3081 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
3082 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty($conf->expedition->dir_output)) {
3084 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3087 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3089 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
3091 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3094 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3095 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
3097 if ($fuser->hasRight(
'agenda',
'myactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3100 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
3101 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
3103 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3106 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
3107 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3109 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
3110 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
3112 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3115 if (isModEnabled(
"product")) {
3116 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
3117 } elseif (isModEnabled(
"service")) {
3118 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
3120 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3122 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
3123 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
3125 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3128 if (isModEnabled(
'productbatch')) {
3129 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3131 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3133 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3134 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
3136 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3139 if (isModEnabled(
'stock')) {
3140 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3142 } elseif ($modulepart ==
'contract' && !empty($conf->contrat->multidir_output[$entity])) {
3144 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3147 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
3148 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3149 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
3151 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3154 $original_file = $conf->don->dir_output.
'/'.$original_file;
3155 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
3157 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3160 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3161 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3163 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3167 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3168 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3170 if ($fuser->hasRight(
'banque', $lire)) {
3173 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3174 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3177 $accessallowed = $user->rights->export->lire;
3178 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3179 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3181 $accessallowed = $user->rights->import->run;
3182 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3183 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3185 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3186 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3187 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3190 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3191 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3193 if ($fuser->admin) {
3196 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3197 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3199 if ($fuser->admin) {
3202 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3203 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3207 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3210 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3211 } elseif ($modulepart ==
'member' && !empty($conf->adherent->dir_output)) {
3213 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3216 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
3217 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3220 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3230 if (preg_match(
'/^specimen/i', $original_file)) {
3233 if ($fuser->admin) {
3237 $tmpmodulepart = explode(
'-', $modulepart);
3238 if (!empty($tmpmodulepart[1])) {
3239 $modulepart = $tmpmodulepart[0];
3240 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3245 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3246 $tmpmodule = $reg[1];
3247 if (empty($conf->$tmpmodule->dir_temp)) {
3248 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3251 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3254 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3255 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3256 $tmpmodule = $reg[1];
3257 if (empty($conf->$tmpmodule->dir_temp)) {
3258 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3261 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3264 $original_file = $conf->$tmpmodule->dir_temp.
'/'.$original_file;
3265 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3266 $tmpmodule = $reg[1];
3267 if (empty($conf->$tmpmodule->dir_output)) {
3268 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3271 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3274 $original_file = $conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3275 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3276 $tmpmodule = $reg[1];
3277 if (empty($conf->$tmpmodule->dir_output)) {
3278 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3281 if ($fuser->hasRight($tmpmodule, $lire) || preg_match(
'/^specimen/i', $original_file)) {
3284 $original_file = $conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3286 if (empty($conf->$modulepart->dir_output)) {
3287 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
'). The module for this modulepart value may not be activated.');
3292 $partsofdirinoriginalfile = explode(
'/', $original_file);
3293 if (!empty($partsofdirinoriginalfile[1])) {
3294 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3295 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3299 if ($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) {
3303 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3304 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3306 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3310 $parameters = array(
3311 'modulepart' => $modulepart,
3312 'original_file' => $original_file,
3313 'entity' => $entity,
3318 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters, $object);
3320 if (!empty($hookmanager->resArray[
'original_file'])) {
3321 $original_file = $hookmanager->resArray[
'original_file'];
3323 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3324 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3326 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3327 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3333 'accessallowed' => ($accessallowed ? 1 : 0),
3334 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3335 'original_file' => $original_file