948function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array())
950 global $user, $db, $conf;
953 dol_syslog(
"files.lib.php::dol_move srcfile=".$srcfile.
" destfile=".$destfile.
" newmask=".$newmask.
" overwritifexists=".$overwriteifexists);
958 dol_syslog(
"files.lib.php::dol_move srcfile does not exists. we ignore the move request.");
962 if ($overwriteifexists || !$destexists) {
967 $testvirusarray = array();
970 if (count($testvirusarray)) {
971 dol_syslog(
"files.lib.php::dol_move canceled because a virus was found into source file. we ignore the move request.", LOG_WARNING);
976 global $dolibarr_main_restrict_os_commands;
977 if (!empty($dolibarr_main_restrict_os_commands)) {
978 $arrayofallowedcommand = explode(
',', $dolibarr_main_restrict_os_commands);
979 $arrayofallowedcommand = array_map(
'trim', $arrayofallowedcommand);
980 if (in_array(basename($destfile), $arrayofallowedcommand)) {
983 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);
988 $result = @rename($newpathofsrcfile, $newpathofdestfile);
991 dol_syslog(
"files.lib.php::dol_move Failed. We try to delete target first and move after.", LOG_WARNING);
994 $result = @rename($newpathofsrcfile, $newpathofdestfile);
996 dol_syslog(
"files.lib.php::dol_move Failed.", LOG_WARNING);
1001 if ($result && $indexdatabase) {
1003 $rel_filetorenamebefore = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $srcfile);
1004 $rel_filetorenameafter = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destfile);
1005 if (!preg_match(
'/([\\/]temp[\\/]|[\\/]thumbs|\.meta$)/', $rel_filetorenameafter)) {
1006 $rel_filetorenamebefore = preg_replace(
'/^[\\/]/',
'', $rel_filetorenamebefore);
1007 $rel_filetorenameafter = preg_replace(
'/^[\\/]/',
'', $rel_filetorenameafter);
1010 dol_syslog(
"Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore.
" after = ".$rel_filetorenameafter, LOG_DEBUG);
1011 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1013 $ecmfiletarget =
new EcmFiles($db);
1014 $resultecmtarget = $ecmfiletarget->fetch(0,
'', $rel_filetorenameafter);
1015 if ($resultecmtarget > 0) {
1016 $ecmfiletarget->delete($user);
1020 $resultecm = $ecmfile->fetch(0,
'', $rel_filetorenamebefore);
1021 if ($resultecm > 0) {
1022 $filename = basename($rel_filetorenameafter);
1023 $rel_dir = dirname($rel_filetorenameafter);
1024 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1025 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1027 $ecmfile->filepath = $rel_dir;
1028 $ecmfile->filename = $filename;
1030 $resultecm = $ecmfile->update($user);
1031 } elseif ($resultecm == 0) {
1032 $filename = basename($rel_filetorenameafter);
1033 $rel_dir = dirname($rel_filetorenameafter);
1034 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
1035 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
1037 $ecmfile->filepath = $rel_dir;
1038 $ecmfile->filename = $filename;
1040 $ecmfile->fullpath_orig = $srcfile;
1041 $ecmfile->gen_or_uploaded =
'uploaded';
1042 if (!empty($moreinfo) && !empty($moreinfo[
'description'])) {
1043 $ecmfile->description = $moreinfo[
'description'];
1045 $ecmfile->description =
'';
1047 if (!empty($moreinfo) && !empty($moreinfo[
'keywords'])) {
1048 $ecmfile->keywords = $moreinfo[
'keywords'];
1050 $ecmfile->keywords =
'';
1052 if (!empty($moreinfo) && !empty($moreinfo[
'note_private'])) {
1053 $ecmfile->note_private = $moreinfo[
'note_private'];
1055 if (!empty($moreinfo) && !empty($moreinfo[
'note_public'])) {
1056 $ecmfile->note_public = $moreinfo[
'note_public'];
1058 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_type'])) {
1059 $ecmfile->src_object_type = $moreinfo[
'src_object_type'];
1061 if (!empty($moreinfo) && !empty($moreinfo[
'src_object_id'])) {
1062 $ecmfile->src_object_id = $moreinfo[
'src_object_id'];
1065 $resultecm = $ecmfile->create($user);
1066 if ($resultecm < 0) {
1069 } elseif ($resultecm < 0) {
1073 if ($resultecm > 0) {
1081 if (empty($newmask)) {
1082 $newmask = empty($conf->global->MAIN_UMASK) ?
'0755' : $conf->global->MAIN_UMASK;
1088 dolChmod($newpathofdestfile, $newmask);
2567 global $conf, $db, $user, $hookmanager;
2568 global $dolibarr_main_data_root, $dolibarr_main_document_root_alt;
2571 if (!is_object($fuser)) {
2575 if (empty($modulepart)) {
2576 return 'ErrorBadParameter';
2578 if (empty($entity)) {
2579 if (!isModEnabled(
'multicompany')) {
2586 if ($modulepart ==
'users') {
2587 $modulepart =
'user';
2589 if ($modulepart ==
'tva') {
2590 $modulepart =
'tax-vat';
2593 if ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
2594 $modulepart =
'delivery';
2598 dol_syslog(
'dol_check_secure_access_document modulepart='.$modulepart.
' original_file='.$original_file.
' entity='.$entity);
2602 $sqlprotectagainstexternals =
'';
2606 if (empty($refname)) {
2607 $refname = basename(dirname($original_file).
"/");
2608 if ($refname ==
'thumbs' || $refname ==
'temp') {
2610 $refname = basename(dirname(dirname($original_file)).
"/");
2617 $download =
'download';
2618 if ($mode ==
'write') {
2621 $download =
'upload';
2625 if ($modulepart ==
'medias' && !empty($dolibarr_main_data_root)) {
2626 if (empty($entity) || empty($conf->medias->multidir_output[$entity])) {
2627 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2630 $original_file = $conf->medias->multidir_output[$entity].
'/'.$original_file;
2631 } elseif ($modulepart ==
'logs' && !empty($dolibarr_main_data_root)) {
2633 $accessallowed = ($user->admin && basename($original_file) == $original_file && preg_match(
'/^dolibarr.*\.(log|json)$/', basename($original_file)));
2634 $original_file = $dolibarr_main_data_root.
'/'.$original_file;
2635 } elseif ($modulepart ==
'doctemplates' && !empty($dolibarr_main_data_root)) {
2637 $accessallowed = $user->admin;
2638 $original_file = $dolibarr_main_data_root.
'/doctemplates/'.$original_file;
2639 } elseif ($modulepart ==
'doctemplateswebsite' && !empty($dolibarr_main_data_root)) {
2641 $accessallowed = ($fuser->rights->website->write && preg_match(
'/\.jpg$/i', basename($original_file)));
2642 $original_file = $dolibarr_main_data_root.
'/doctemplates/websites/'.$original_file;
2643 } elseif ($modulepart ==
'packages' && !empty($dolibarr_main_data_root)) {
2646 $tmp = explode(
',', $dolibarr_main_document_root_alt);
2649 $accessallowed = ($user->admin && preg_match(
'/^module_.*\.zip$/', basename($original_file)));
2650 $original_file = $dirins.
'/'.$original_file;
2651 } elseif ($modulepart ==
'mycompany' && !empty($conf->mycompany->dir_output)) {
2654 $original_file = $conf->mycompany->dir_output.
'/'.$original_file;
2655 } elseif ($modulepart ==
'userphoto' && !empty($conf->user->dir_output)) {
2658 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2661 $original_file = $conf->user->dir_output.
'/'.$original_file;
2662 } elseif ($modulepart ==
'userphotopublic' && !empty($conf->user->dir_output)) {
2666 if (preg_match(
'/^(\d+)\/photos\//', $original_file, $reg)) {
2668 $tmpobject =
new User($db);
2669 $tmpobject->fetch($reg[1],
'',
'', 1);
2671 $securekey =
GETPOST(
'securekey',
'alpha', 1);
2673 global $dolibarr_main_cookie_cryptkey, $dolibarr_main_instance_unique_id;
2674 $valuetouse = $dolibarr_main_instance_unique_id ? $dolibarr_main_instance_unique_id : $dolibarr_main_cookie_cryptkey;
2675 $encodedsecurekey =
dol_hash($valuetouse.
'uservirtualcard'.$tmpobject->id.
'-'.$tmpobject->login,
'md5');
2676 if ($encodedsecurekey == $securekey) {
2685 $original_file = $conf->user->dir_output.
'/'.$original_file;
2686 } elseif (($modulepart ==
'companylogo') && !empty($conf->mycompany->dir_output)) {
2689 $original_file = $conf->mycompany->dir_output.
'/logos/'.$original_file;
2690 } elseif ($modulepart ==
'memberphoto' && !empty($conf->adherent->dir_output)) {
2693 if (preg_match(
'/^\d+\/photos\//', $original_file)) {
2696 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
2697 } elseif ($modulepart ==
'apercufacture' && !empty($conf->facture->multidir_output[$entity])) {
2699 if ($fuser->hasRight(
'facture', $lire)) {
2702 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2703 } elseif ($modulepart ==
'apercupropal' && !empty($conf->propal->multidir_output[$entity])) {
2705 if ($fuser->hasRight(
'propal', $lire)) {
2708 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
2709 } elseif ($modulepart ==
'apercucommande' && !empty($conf->commande->multidir_output[$entity])) {
2711 if ($fuser->hasRight(
'commande', $lire)) {
2714 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
2715 } elseif (($modulepart ==
'apercufichinter' || $modulepart ==
'apercuficheinter') && !empty($conf->ficheinter->dir_output)) {
2717 if ($fuser->hasRight(
'ficheinter', $lire)) {
2720 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2721 } elseif (($modulepart ==
'apercucontract') && !empty($conf->contrat->multidir_output[$entity])) {
2723 if ($fuser->hasRight(
'contrat', $lire)) {
2726 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
2727 } elseif (($modulepart ==
'apercusupplier_proposal' || $modulepart ==
'apercusupplier_proposal') && !empty($conf->supplier_proposal->dir_output)) {
2729 if ($fuser->hasRight(
'supplier_proposal', $lire)) {
2732 $original_file = $conf->supplier_proposal->dir_output.
'/'.$original_file;
2733 } elseif (($modulepart ==
'apercusupplier_order' || $modulepart ==
'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) {
2735 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2738 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
2739 } elseif (($modulepart ==
'apercusupplier_invoice' || $modulepart ==
'apercusupplier_invoice') && !empty($conf->fournisseur->facture->dir_output)) {
2741 if ($fuser->hasRight(
'fournisseur', $lire)) {
2744 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
2745 } elseif (($modulepart ==
'holiday') && !empty($conf->holiday->dir_output)) {
2746 if ($fuser->hasRight(
'holiday', $read) || !empty($fuser->rights->holiday->readall) || preg_match(
'/^specimen/i', $original_file)) {
2749 if ($refname && empty($fuser->rights->holiday->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2750 include_once DOL_DOCUMENT_ROOT.
'/holiday/class/holiday.class.php';
2751 $tmpholiday =
new Holiday($db);
2752 $tmpholiday->fetch(
'', $refname);
2753 $accessallowed =
checkUserAccessToObject($user, array(
'holiday'), $tmpholiday,
'holiday',
'',
'',
'rowid',
'');
2756 $original_file = $conf->holiday->dir_output.
'/'.$original_file;
2757 } elseif (($modulepart ==
'expensereport') && !empty($conf->expensereport->dir_output)) {
2758 if ($fuser->hasRight(
'expensereport', $lire) || !empty($fuser->rights->expensereport->readall) || preg_match(
'/^specimen/i', $original_file)) {
2761 if ($refname && empty($fuser->rights->expensereport->readall) && !preg_match(
'/^specimen/i', $original_file)) {
2762 include_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
2764 $tmpexpensereport->fetch(
'', $refname);
2765 $accessallowed =
checkUserAccessToObject($user, array(
'expensereport'), $tmpexpensereport,
'expensereport',
'',
'',
'rowid',
'');
2768 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2769 } elseif (($modulepart ==
'apercuexpensereport') && !empty($conf->expensereport->dir_output)) {
2771 if ($fuser->hasRight(
'expensereport', $lire)) {
2774 $original_file = $conf->expensereport->dir_output.
'/'.$original_file;
2775 } elseif ($modulepart ==
'propalstats' && !empty($conf->propal->multidir_temp[$entity])) {
2777 if ($fuser->hasRight(
'propal', $lire)) {
2780 $original_file = $conf->propal->multidir_temp[$entity].
'/'.$original_file;
2781 } elseif ($modulepart ==
'orderstats' && !empty($conf->commande->dir_temp)) {
2783 if ($fuser->hasRight(
'commande', $lire)) {
2786 $original_file = $conf->commande->dir_temp.
'/'.$original_file;
2787 } elseif ($modulepart ==
'orderstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2788 if ($fuser->hasRight(
'fournisseur',
'commande', $lire)) {
2791 $original_file = $conf->fournisseur->commande->dir_temp.
'/'.$original_file;
2792 } elseif ($modulepart ==
'billstats' && !empty($conf->facture->dir_temp)) {
2794 if ($fuser->hasRight(
'facture', $lire)) {
2797 $original_file = $conf->facture->dir_temp.
'/'.$original_file;
2798 } elseif ($modulepart ==
'billstatssupplier' && !empty($conf->fournisseur->dir_output)) {
2799 if ($fuser->hasRight(
'fournisseur',
'facture', $lire)) {
2802 $original_file = $conf->fournisseur->facture->dir_temp.
'/'.$original_file;
2803 } elseif ($modulepart ==
'expeditionstats' && !empty($conf->expedition->dir_temp)) {
2805 if ($fuser->hasRight(
'expedition', $lire)) {
2808 $original_file = $conf->expedition->dir_temp.
'/'.$original_file;
2809 } elseif ($modulepart ==
'tripsexpensesstats' && !empty($conf->deplacement->dir_temp)) {
2811 if ($fuser->hasRight(
'deplacement', $lire)) {
2814 $original_file = $conf->deplacement->dir_temp.
'/'.$original_file;
2815 } elseif ($modulepart ==
'memberstats' && !empty($conf->adherent->dir_temp)) {
2817 if ($fuser->hasRight(
'adherent', $lire)) {
2820 $original_file = $conf->adherent->dir_temp.
'/'.$original_file;
2821 } elseif (preg_match(
'/^productstats_/i', $modulepart) && !empty($conf->product->dir_temp)) {
2823 if ($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) {
2826 $original_file = (!empty($conf->product->multidir_temp[$entity]) ? $conf->product->multidir_temp[$entity] : $conf->service->multidir_temp[$entity]).
'/'.$original_file;
2827 } elseif (in_array($modulepart, array(
'tax',
'tax-vat',
'tva')) && !empty($conf->tax->dir_output)) {
2829 if ($fuser->hasRight(
'tax',
'charges', $lire)) {
2832 $modulepartsuffix = str_replace(
'tax-',
'', $modulepart);
2833 $original_file = $conf->tax->dir_output.
'/'.($modulepartsuffix !=
'tax' ? $modulepartsuffix.
'/' :
'').$original_file;
2834 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
2836 if ($fuser->hasRight(
'agenda',
'myactions', $read)) {
2839 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
2840 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
2842 $tmpobject->fetch((
int) $refname);
2843 $accessallowed =
checkUserAccessToObject($user, array(
'agenda'), $tmpobject->id,
'actioncomm&societe',
'myactions|allactions',
'fk_soc',
'id',
'');
2844 if ($user->socid && $tmpobject->socid) {
2849 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
2850 } elseif ($modulepart ==
'category' && !empty($conf->categorie->multidir_output[$entity])) {
2852 if (empty($entity) || empty($conf->categorie->multidir_output[$entity])) {
2853 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2855 if ($fuser->hasRight(
"categorie", $lire) || $fuser->hasRight(
"takepos",
"run")) {
2858 $original_file = $conf->categorie->multidir_output[$entity].
'/'.$original_file;
2859 } elseif ($modulepart ==
'prelevement' && !empty($conf->prelevement->dir_output)) {
2861 if ($fuser->rights->prelevement->bons->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2864 $original_file = $conf->prelevement->dir_output.
'/'.$original_file;
2865 } elseif ($modulepart ==
'graph_stock' && !empty($conf->stock->dir_temp)) {
2868 $original_file = $conf->stock->dir_temp.
'/'.$original_file;
2869 } elseif ($modulepart ==
'graph_fourn' && !empty($conf->fournisseur->dir_temp)) {
2872 $original_file = $conf->fournisseur->dir_temp.
'/'.$original_file;
2873 } elseif ($modulepart ==
'graph_product' && !empty($conf->product->dir_temp)) {
2876 $original_file = $conf->product->multidir_temp[$entity].
'/'.$original_file;
2877 } elseif ($modulepart ==
'barcode') {
2882 $original_file =
'';
2883 } elseif ($modulepart ==
'iconmailing' && !empty($conf->mailing->dir_temp)) {
2886 $original_file = $conf->mailing->dir_temp.
'/'.$original_file;
2887 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
2890 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
2891 } elseif ($modulepart ==
'fckeditor' && !empty($conf->fckeditor->dir_output)) {
2894 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
2895 } elseif ($modulepart ==
'user' && !empty($conf->user->dir_output)) {
2897 $canreaduser = (!empty($fuser->admin) || $fuser->rights->user->user->{$lire});
2898 if ($fuser->id == (
int) $refname) {
2901 if ($canreaduser || preg_match(
'/^specimen/i', $original_file)) {
2904 $original_file = $conf->user->dir_output.
'/'.$original_file;
2905 } elseif (($modulepart ==
'company' || $modulepart ==
'societe' || $modulepart ==
'thirdparty') && !empty($conf->societe->multidir_output[$entity])) {
2907 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2908 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2910 if ($fuser->rights->societe->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
2913 $original_file = $conf->societe->multidir_output[$entity].
'/'.$original_file;
2914 $sqlprotectagainstexternals =
"SELECT rowid as fk_soc FROM ".MAIN_DB_PREFIX.
"societe WHERE rowid='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'societe').
")";
2915 } elseif ($modulepart ==
'contact' && !empty($conf->societe->multidir_output[$entity])) {
2917 if (empty($entity) || empty($conf->societe->multidir_output[$entity])) {
2918 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
2920 if ($fuser->hasRight(
'societe', $lire)) {
2923 $original_file = $conf->societe->multidir_output[$entity].
'/contact/'.$original_file;
2924 } elseif (($modulepart ==
'facture' || $modulepart ==
'invoice') && !empty($conf->facture->multidir_output[$entity])) {
2926 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2929 $original_file = $conf->facture->multidir_output[$entity].
'/'.$original_file;
2930 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'invoice').
")";
2931 } elseif ($modulepart ==
'massfilesarea_proposals' && !empty($conf->propal->multidir_output[$entity])) {
2933 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2936 $original_file = $conf->propal->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2937 } elseif ($modulepart ==
'massfilesarea_orders') {
2938 if ($fuser->hasRight(
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2941 $original_file = $conf->commande->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2942 } elseif ($modulepart ==
'massfilesarea_sendings') {
2943 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2946 $original_file = $conf->expedition->dir_output.
'/sending/temp/massgeneration/'.$user->id.
'/'.$original_file;
2947 } elseif ($modulepart ==
'massfilesarea_invoices') {
2948 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2951 $original_file = $conf->facture->multidir_output[$entity].
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2952 } elseif ($modulepart ==
'massfilesarea_expensereport') {
2953 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2956 $original_file = $conf->expensereport->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2957 } elseif ($modulepart ==
'massfilesarea_interventions') {
2958 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2961 $original_file = $conf->ficheinter->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2962 } elseif ($modulepart ==
'massfilesarea_supplier_proposal' && !empty($conf->supplier_proposal->dir_output)) {
2963 if ($fuser->hasRight(
'supplier_proposal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2966 $original_file = $conf->supplier_proposal->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2967 } elseif ($modulepart ==
'massfilesarea_supplier_order') {
2968 if ($fuser->hasRight(
'fournisseur',
'commande', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2971 $original_file = $conf->fournisseur->commande->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2972 } elseif ($modulepart ==
'massfilesarea_supplier_invoice') {
2973 if ($fuser->hasRight(
'fournisseur',
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2976 $original_file = $conf->fournisseur->facture->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2977 } elseif ($modulepart ==
'massfilesarea_contract' && !empty($conf->contrat->dir_output)) {
2978 if ($fuser->hasRight(
'contrat', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2981 $original_file = $conf->contrat->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
2982 } elseif (($modulepart ==
'fichinter' || $modulepart ==
'ficheinter') && !empty($conf->ficheinter->dir_output)) {
2984 if ($fuser->hasRight(
'ficheinter', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2987 $original_file = $conf->ficheinter->dir_output.
'/'.$original_file;
2988 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"fichinter WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
2989 } elseif ($modulepart ==
'deplacement' && !empty($conf->deplacement->dir_output)) {
2991 if ($fuser->hasRight(
'deplacement', $lire) || preg_match(
'/^specimen/i', $original_file)) {
2994 $original_file = $conf->deplacement->dir_output.
'/'.$original_file;
2996 } elseif (($modulepart ==
'propal' || $modulepart ==
'propale') && isset($conf->propal->multidir_output[$entity])) {
2998 if ($fuser->hasRight(
'propal', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3001 $original_file = $conf->propal->multidir_output[$entity].
'/'.$original_file;
3002 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"propal WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'propal').
")";
3003 } elseif (($modulepart ==
'commande' || $modulepart ==
'order') && !empty($conf->commande->multidir_output[$entity])) {
3005 if ($fuser->rights->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3008 $original_file = $conf->commande->multidir_output[$entity].
'/'.$original_file;
3009 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'order').
")";
3010 } elseif ($modulepart ==
'project' && !empty($conf->project->multidir_output[$entity])) {
3012 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3015 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3016 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
3017 $tmpproject =
new Project($db);
3018 $tmpproject->fetch(
'', $refname);
3019 $accessallowed =
checkUserAccessToObject($user, array(
'projet'), $tmpproject->id,
'projet&project',
'',
'',
'rowid',
'');
3022 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3023 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3024 } elseif ($modulepart ==
'project_task' && !empty($conf->project->multidir_output[$entity])) {
3025 if ($fuser->hasRight(
'projet', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3028 if ($refname && !preg_match(
'/^specimen/i', $original_file)) {
3029 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
3030 $tmptask =
new Task($db);
3031 $tmptask->fetch(
'', $refname);
3032 $accessallowed =
checkUserAccessToObject($user, array(
'projet_task'), $tmptask->id,
'projet_task&project',
'',
'',
'rowid',
'');
3035 $original_file = $conf->project->multidir_output[$entity].
'/'.$original_file;
3036 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"projet WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'project').
")";
3037 } elseif (($modulepart ==
'commande_fournisseur' || $modulepart ==
'order_supplier') && !empty($conf->fournisseur->commande->dir_output)) {
3039 if ($fuser->rights->fournisseur->commande->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3042 $original_file = $conf->fournisseur->commande->dir_output.
'/'.$original_file;
3043 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3044 } elseif (($modulepart ==
'facture_fournisseur' || $modulepart ==
'invoice_supplier') && !empty($conf->fournisseur->facture->dir_output)) {
3046 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3049 $original_file = $conf->fournisseur->facture->dir_output.
'/'.$original_file;
3050 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"facture_fourn WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3051 } elseif ($modulepart ==
'supplier_payment') {
3053 if ($fuser->rights->fournisseur->facture->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3056 $original_file = $conf->fournisseur->payment->dir_output.
'/'.$original_file;
3057 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"paiementfournisseur WHERE ref='".$db->escape($refname).
"' AND entity=".$conf->entity;
3058 } elseif ($modulepart ==
'facture_paiement' && !empty($conf->facture->dir_output)) {
3060 if ($fuser->hasRight(
'facture', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3063 if ($fuser->socid > 0) {
3064 $original_file = $conf->facture->dir_output.
'/payments/private/'.$fuser->id.
'/'.$original_file;
3066 $original_file = $conf->facture->dir_output.
'/payments/'.$original_file;
3068 } elseif ($modulepart ==
'export_compta' && !empty($conf->accounting->dir_output)) {
3070 if ($fuser->rights->accounting->bind->write || preg_match(
'/^specimen/i', $original_file)) {
3073 $original_file = $conf->accounting->dir_output.
'/'.$original_file;
3074 } elseif (($modulepart ==
'expedition' || $modulepart ==
'shipment') && !empty($conf->expedition->dir_output)) {
3076 if ($fuser->hasRight(
'expedition', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3079 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'sending/') === 0 ?
'' :
'sending/').$original_file;
3081 } elseif (($modulepart ==
'livraison' || $modulepart ==
'delivery') && !empty($conf->expedition->dir_output)) {
3083 if ($fuser->hasRight(
'expedition',
'delivery', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3086 $original_file = $conf->expedition->dir_output.
"/".(strpos($original_file,
'receipt/') === 0 ?
'' :
'receipt/').$original_file;
3087 } elseif ($modulepart ==
'actions' && !empty($conf->agenda->dir_output)) {
3089 if ($fuser->hasRight(
'agenda',
'myactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3092 $original_file = $conf->agenda->dir_output.
'/'.$original_file;
3093 } elseif ($modulepart ==
'actionsreport' && !empty($conf->agenda->dir_temp)) {
3095 if ($fuser->hasRight(
'agenda',
'allactions', $read) || preg_match(
'/^specimen/i', $original_file)) {
3098 $original_file = $conf->agenda->dir_temp.
"/".$original_file;
3099 } elseif ($modulepart ==
'product' || $modulepart ==
'produit' || $modulepart ==
'service' || $modulepart ==
'produit|service') {
3101 if (empty($entity) || (empty($conf->product->multidir_output[$entity]) && empty($conf->service->multidir_output[$entity]))) {
3102 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
3104 if (($fuser->hasRight(
'produit', $lire) || $fuser->hasRight(
'service', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3107 if (isModEnabled(
"product")) {
3108 $original_file = $conf->product->multidir_output[$entity].
'/'.$original_file;
3109 } elseif (isModEnabled(
"service")) {
3110 $original_file = $conf->service->multidir_output[$entity].
'/'.$original_file;
3112 } elseif ($modulepart ==
'product_batch' || $modulepart ==
'produitlot') {
3114 if (empty($entity) || (empty($conf->productbatch->multidir_output[$entity]))) {
3115 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
3117 if (($fuser->hasRight(
'produit', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3120 if (isModEnabled(
'productbatch')) {
3121 $original_file = $conf->productbatch->multidir_output[$entity].
'/'.$original_file;
3123 } elseif ($modulepart ==
'movement' || $modulepart ==
'mouvement') {
3125 if (empty($entity) || empty($conf->stock->multidir_output[$entity])) {
3126 return array(
'accessallowed'=>0,
'error'=>
'Value entity must be provided');
3128 if (($fuser->hasRight(
'stock', $lire) || $fuser->hasRight(
'stock',
'movement', $lire) || $fuser->hasRight(
'stock',
'mouvement', $lire)) || preg_match(
'/^specimen/i', $original_file)) {
3131 if (isModEnabled(
'stock')) {
3132 $original_file = $conf->stock->multidir_output[$entity].
'/movement/'.$original_file;
3134 } elseif ($modulepart ==
'contract' && !empty($conf->contrat->multidir_output[$entity])) {
3136 if ($fuser->rights->contrat->{$lire} || preg_match(
'/^specimen/i', $original_file)) {
3139 $original_file = $conf->contrat->multidir_output[$entity].
'/'.$original_file;
3140 $sqlprotectagainstexternals =
"SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX.
"contrat WHERE ref='".$db->escape($refname).
"' AND entity IN (".
getEntity(
'contract').
")";
3141 } elseif ($modulepart ==
'donation' && !empty($conf->don->dir_output)) {
3143 if ($fuser->hasRight(
'don', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3146 $original_file = $conf->don->dir_output.
'/'.$original_file;
3147 } elseif ($modulepart ==
'dolresource' && !empty($conf->resource->dir_output)) {
3149 if ($fuser->hasRight(
'resource', $read) || preg_match(
'/^specimen/i', $original_file)) {
3152 $original_file = $conf->resource->dir_output.
'/'.$original_file;
3153 } elseif (($modulepart ==
'remisecheque' || $modulepart ==
'chequereceipt') && !empty($conf->bank->dir_output)) {
3155 if ($fuser->hasRight(
'banque', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3159 $original_file = $conf->bank->dir_output.
'/checkdeposits/'.$original_file;
3160 } elseif (($modulepart ==
'banque' || $modulepart ==
'bank') && !empty($conf->bank->dir_output)) {
3162 if ($fuser->hasRight(
'banque', $lire)) {
3165 $original_file = $conf->bank->dir_output.
'/'.$original_file;
3166 } elseif ($modulepart ==
'export' && !empty($conf->export->dir_temp)) {
3169 $accessallowed = $user->rights->export->lire;
3170 $original_file = $conf->export->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3171 } elseif ($modulepart ==
'import' && !empty($conf->import->dir_temp)) {
3173 $accessallowed = $user->rights->import->run;
3174 $original_file = $conf->import->dir_temp.
'/'.$original_file;
3175 } elseif ($modulepart ==
'recruitment' && !empty($conf->recruitment->dir_output)) {
3177 $accessallowed = $user->hasRight(
'recruitment',
'recruitmentjobposition',
'read');
3178 $original_file = $conf->recruitment->dir_output.
'/'.$original_file;
3179 } elseif ($modulepart ==
'editor' && !empty($conf->fckeditor->dir_output)) {
3182 $original_file = $conf->fckeditor->dir_output.
'/'.$original_file;
3183 } elseif ($modulepart ==
'systemtools' && !empty($conf->admin->dir_output)) {
3185 if ($fuser->admin) {
3188 $original_file = $conf->admin->dir_output.
'/'.$original_file;
3189 } elseif ($modulepart ==
'admin_temp' && !empty($conf->admin->dir_temp)) {
3191 if ($fuser->admin) {
3194 $original_file = $conf->admin->dir_temp.
'/'.$original_file;
3195 } elseif ($modulepart ==
'bittorrent' && !empty($conf->bittorrent->dir_output)) {
3199 if (
dol_mimetype($original_file) ==
'application/x-bittorrent') {
3202 $original_file = $conf->bittorrent->dir_output.
'/'.$dir.
'/'.$original_file;
3203 } elseif ($modulepart ==
'member' && !empty($conf->adherent->dir_output)) {
3205 if ($fuser->hasRight(
'adherent', $lire) || preg_match(
'/^specimen/i', $original_file)) {
3208 $original_file = $conf->adherent->dir_output.
'/'.$original_file;
3209 } elseif ($modulepart ==
'scanner_user_temp' && !empty($conf->scanner->dir_temp)) {
3212 $original_file = $conf->scanner->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3222 if (preg_match(
'/^specimen/i', $original_file)) {
3225 if ($fuser->admin) {
3229 $tmpmodulepart = explode(
'-', $modulepart);
3230 if (!empty($tmpmodulepart[1])) {
3231 $modulepart = $tmpmodulepart[0];
3232 $original_file = $tmpmodulepart[1].
'/'.$original_file;
3237 if (preg_match(
'/^([a-z]+)_user_temp$/i', $modulepart, $reg)) {
3238 $tmpmodule = $reg[1];
3239 if (empty($conf->$tmpmodule->dir_temp)) {
3240 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3243 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3246 $original_file = $conf->{$reg[1]}->dir_temp.
'/'.$fuser->id.
'/'.$original_file;
3247 } elseif (preg_match(
'/^([a-z]+)_temp$/i', $modulepart, $reg)) {
3248 $tmpmodule = $reg[1];
3249 if (empty($conf->$tmpmodule->dir_temp)) {
3250 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3253 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3256 $original_file = $conf->$tmpmodule->dir_temp.
'/'.$original_file;
3257 } elseif (preg_match(
'/^([a-z]+)_user$/i', $modulepart, $reg)) {
3258 $tmpmodule = $reg[1];
3259 if (empty($conf->$tmpmodule->dir_output)) {
3260 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3263 if ($fuser->hasRight($tmpmodule, $lire) || $fuser->hasRight($tmpmodule, $read) || $fuser->hasRight($tmpmodule, $download)) {
3266 $original_file = $conf->$tmpmodule->dir_output.
'/'.$fuser->id.
'/'.$original_file;
3267 } elseif (preg_match(
'/^massfilesarea_([a-z]+)$/i', $modulepart, $reg)) {
3268 $tmpmodule = $reg[1];
3269 if (empty($conf->$tmpmodule->dir_output)) {
3270 dol_print_error(
'',
'Error call dol_check_secure_access_document with not supported value for modulepart parameter ('.$modulepart.
')');
3273 if ($fuser->hasRight($tmpmodule, $lire) || preg_match(
'/^specimen/i', $original_file)) {
3276 $original_file = $conf->$tmpmodule->dir_output.
'/temp/massgeneration/'.$user->id.
'/'.$original_file;
3278 if (empty($conf->$modulepart->dir_output)) {
3279 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.');
3284 $partsofdirinoriginalfile = explode(
'/', $original_file);
3285 if (!empty($partsofdirinoriginalfile[1])) {
3286 $partofdirinoriginalfile = $partsofdirinoriginalfile[0];
3287 if ($partofdirinoriginalfile && ($fuser->hasRight($modulepart, $partofdirinoriginalfile,
'lire') || $fuser->hasRight($modulepart, $partofdirinoriginalfile,
'read'))) {
3291 if ($fuser->hasRight($modulepart, $lire) || $fuser->hasRight($modulepart, $read)) {
3295 if (is_array($conf->$modulepart->multidir_output) && !empty($conf->$modulepart->multidir_output[$entity])) {
3296 $original_file = $conf->$modulepart->multidir_output[$entity].
'/'.$original_file;
3298 $original_file = $conf->$modulepart->dir_output.
'/'.$original_file;
3302 $parameters = array(
3303 'modulepart' => $modulepart,
3304 'original_file' => $original_file,
3305 'entity' => $entity,
3310 $reshook = $hookmanager->executeHooks(
'checkSecureAccess', $parameters, $object);
3312 if (!empty($hookmanager->resArray[
'original_file'])) {
3313 $original_file = $hookmanager->resArray[
'original_file'];
3315 if (!empty($hookmanager->resArray[
'accessallowed'])) {
3316 $accessallowed = $hookmanager->resArray[
'accessallowed'];
3318 if (!empty($hookmanager->resArray[
'sqlprotectagainstexternals'])) {
3319 $sqlprotectagainstexternals = $hookmanager->resArray[
'sqlprotectagainstexternals'];
3325 'accessallowed' => ($accessallowed ? 1 : 0),
3326 'sqlprotectagainstexternals' => $sqlprotectagainstexternals,
3327 'original_file' => $original_file