429function restrictedArea(
User $user, $features,
$object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'fk_soc', $dbt_select =
'rowid', $isdraft = 0, $mode = 0)
439 if ($objectid ==
"-1") {
443 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', (
string) $objectid);
452 $parentfortableentity =
'';
456 $originalfeatures = $features;
457 if ($features ==
'agenda') {
458 $tableandshare =
'actioncomm&societe';
459 $feature2 =
'myactions|allactions';
462 if ($features ==
'bank') {
463 $features =
'banque';
465 if ($features ==
'facturerec') {
466 $features =
'facture';
468 if ($features ==
'supplier_invoicerec') {
469 $features =
'fournisseur';
470 $feature2 =
'facture';
472 if ($features ==
'mo') {
475 if ($features ==
'member') {
476 $features =
'adherent';
478 if ($features ==
'subscription') {
479 $features =
'adherent';
480 $feature2 =
'cotisation';
482 if ($features ==
'website' && is_object(
$object) &&
$object->element ==
'websitepage') {
483 $parentfortableentity =
'fk_website@website';
485 if ($features ==
'project') {
486 $features =
'projet';
488 if ($features ==
'product') {
489 $features =
'produit';
491 if ($features ==
'productbatch') {
492 $features =
'produit';
494 if ($features ==
'tax') {
495 $feature2 =
'charges';
497 if ($features ==
'workstation') {
498 $feature2 =
'workstation';
500 if ($features ==
'fournisseur') {
501 $features =
'fournisseur';
502 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
503 $feature2 =
'facture';
504 } elseif (is_object(
$object) &&
$object->element ==
'order_supplier') {
505 $feature2 =
'commande';
508 if ($features ==
'payment_sc') {
509 $tableandshare =
'paiementcharge';
510 $parentfortableentity =
'fk_charge@chargesociales';
515 if (in_array($features, [
'commandedet',
'propaldet',
'facturedet',
'supplier_proposaldet',
'evaluationdet',
'skilldet',
'deliverydet',
'contratdet'])) {
516 $features = substr($features, 0, -3);
517 } elseif (in_array($features, [
'stocktransferline',
'inventoryline',
'bomline',
'expensereport_det',
'facture_fourn_det'])) {
518 $features = substr($features, 0, -4);
519 } elseif ($features ==
'commandefournisseurdispatch') {
520 $features =
'commandefournisseur';
521 } elseif ($features ==
'invoice_supplier_det_rec') {
522 $features =
'invoice_supplier_rec';
524 if ($features ==
'evaluation') {
526 $feature2 =
'evaluation';
540 $parameters = array(
'features' => $features,
'originalfeatures' => $originalfeatures,
'objectid' => $objectid,
'dbt_select' => $dbt_select,
'idtype' => $dbt_select,
'isdraft' => $isdraft);
541 if (!empty($hookmanager)) {
542 $reshook = $hookmanager->executeHooks(
'restrictedArea', $parameters);
544 if (isset($hookmanager->resArray[
'result'])) {
545 if ($hookmanager->resArray[
'result'] == 0) {
559 $featuresarray = array($features);
560 if (preg_match(
'/&/', $features)) {
561 $featuresarray = explode(
"&", $features);
562 } elseif (preg_match(
'/\|/', $features)) {
563 $featuresarray = explode(
"|", $features);
567 if (!empty($feature2)) {
568 $feature2 = explode(
"|", $feature2);
576 foreach ($featuresarray as $feature) {
577 $featureforlistofmodule = $feature;
578 if ($featureforlistofmodule ==
'produit') {
579 $featureforlistofmodule =
'product';
581 if ($featureforlistofmodule ==
'supplier_proposal') {
582 $featureforlistofmodule =
'supplierproposal';
584 if (!empty($user->socid) &&
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL') && !in_array($featureforlistofmodule, $listofmodules)) {
590 if ($feature ==
'societe' && (empty($feature2) || !in_array(
'contact', $feature2))) {
591 if (!$user->hasRight(
'societe',
'lire') && !$user->hasRight(
'fournisseur',
'lire')) {
595 } elseif (($feature ==
'societe' && (!empty($feature2) && in_array(
'contact', $feature2))) || $feature ==
'contact') {
596 if (!$user->hasRight(
'societe',
'contact',
'lire')) {
600 } elseif ($feature ==
'produit|service') {
601 if (!$user->hasRight(
'produit',
'lire') && !$user->hasRight(
'service',
'lire')) {
605 } elseif ($feature ==
'prelevement') {
606 if (!$user->hasRight(
'prelevement',
'bons',
'lire')) {
610 } elseif ($feature ==
'cheque') {
611 if (!$user->hasRight(
'banque',
'cheque')) {
615 } elseif ($feature ==
'projet') {
616 if (!$user->hasRight(
'projet',
'lire') && !$user->hasRight(
'projet',
'all',
'lire')) {
620 } elseif ($feature ==
'payment') {
621 if (!$user->hasRight(
'facture',
'lire')) {
625 } elseif ($feature ==
'payment_supplier') {
626 if (!$user->hasRight(
'fournisseur',
'facture',
'lire')) {
630 } elseif ($feature ==
'payment_sc') {
631 if (!$user->hasRight(
'tax',
'charges',
'lire')) {
635 } elseif (!empty($feature2)) {
637 foreach ($feature2 as $subfeature) {
638 if ($subfeature ==
'user' && $user->id == $objectid) {
641 if ($subfeature ==
'fiscalyear' && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
646 if (!empty($subfeature) && !$user->hasRight($feature, $subfeature,
'lire') && !$user->hasRight($feature, $subfeature,
'read')) {
648 } elseif (empty($subfeature) && !$user->hasRight($feature,
'lire') && !$user->hasRight($feature,
'read')) {
659 } elseif (!empty($feature) && ($feature !=
'user' && $feature !=
'usergroup')) {
660 if (!$user->hasRight($feature,
'lire')
661 && !$user->hasRight($feature,
'read')
662 && !$user->hasRight($feature,
'run')) {
670 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
686 $wemustcheckpermissionforcreate = (
GETPOST(
'sendit',
'alpha') ||
GETPOST(
'linkit',
'alpha') || in_array(
GETPOST(
'action',
'aZ09'), array(
'create',
'update',
'set',
'upload',
'add_element_resource',
'confirm_deletebank',
'confirm_delete_linked_resource')) ||
GETPOST(
'roworder',
'alpha', 2));
687 $wemustcheckpermissionfordeletedraft = ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete');
689 if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
690 foreach ($featuresarray as $feature) {
691 if ($feature ==
'contact') {
692 if (!$user->hasRight(
'societe',
'contact',
'creer')) {
696 } elseif ($feature ==
'produit|service') {
697 if (!$user->hasRight(
'produit',
'creer') && !$user->hasRight(
'service',
'creer')) {
701 } elseif ($feature ==
'prelevement') {
702 if (!$user->hasRight(
'prelevement',
'bons',
'creer')) {
706 } elseif ($feature ==
'commande_fournisseur') {
707 if (!$user->hasRight(
'fournisseur',
'commande',
'creer') || !$user->hasRight(
'supplier_order',
'creer')) {
711 } elseif ($feature ==
'banque') {
712 if (!$user->hasRight(
'banque',
'modifier')) {
716 } elseif ($feature ==
'cheque') {
717 if (!$user->hasRight(
'banque',
'cheque')) {
721 } elseif ($feature ==
'import') {
722 if (!$user->hasRight(
'import',
'run')) {
726 } elseif ($feature ==
'ecm') {
727 if (!$user->hasRight(
'ecm',
'upload')) {
731 } elseif ($feature ==
'modulebuilder') {
732 if (!$user->hasRight(
'modulebuilder',
'run')) {
736 } elseif (!empty($feature2)) {
737 foreach ($feature2 as $subfeature) {
738 if ($subfeature ==
'user' && $user->id == $objectid && $user->hasRight(
'user',
'self',
'creer')) {
741 if ($subfeature ==
'user' && $user->id == $objectid && $user->hasRight(
'user',
'self',
'password')) {
744 if ($subfeature ==
'user' && $user->id != $objectid && $user->hasRight(
'user',
'user',
'password')) {
748 if (!$user->hasRight($feature, $subfeature,
'creer')
749 && !$user->hasRight($feature, $subfeature,
'write')
750 && !$user->hasRight($feature, $subfeature,
'create')) {
759 } elseif (!empty($feature)) {
761 if (!$user->hasRight($feature,
'creer')
762 && !$user->hasRight($feature,
'write')
763 && !$user->hasRight($feature,
'create')) {
771 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
775 if ($wemustcheckpermissionforcreate && !$createok) {
787 if (
GETPOST(
'action',
'aZ09') ==
'confirm_create_user' &&
GETPOST(
"confirm",
'aZ09') ==
'yes') {
788 if (!$user->hasRight(
'user',
'user',
'creer')) {
792 if (!$createuserok) {
805 if ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete') {
806 foreach ($featuresarray as $feature) {
807 if ($feature ==
'bookmark') {
808 if (!$user->hasRight(
'bookmark',
'supprimer')) {
809 if ($user->id !=
$object->fk_user || !$user->hasRight(
'bookmark',
'creer')) {
813 } elseif ($feature ==
'contact') {
814 if (!$user->hasRight(
'societe',
'contact',
'supprimer')) {
817 } elseif ($feature ==
'produit|service') {
818 if (!$user->hasRight(
'produit',
'supprimer') && !$user->hasRight(
'service',
'supprimer')) {
821 } elseif ($feature ==
'commande_fournisseur') {
822 if (!$user->hasRight(
'fournisseur',
'commande',
'supprimer')) {
825 } elseif ($feature ==
'payment_supplier') {
826 if (!$user->hasRight(
'fournisseur',
'facture',
'creer')) {
829 } elseif ($feature ==
'payment') {
830 if (!$user->hasRight(
'facture',
'paiement')) {
833 } elseif ($feature ==
'payment_sc') {
834 if (!$user->hasRight(
'tax',
'charges',
'creer')) {
837 } elseif ($feature ==
'banque') {
838 if (!$user->hasRight(
'banque',
'modifier')) {
841 } elseif ($feature ==
'cheque') {
842 if (!$user->hasRight(
'banque',
'cheque')) {
845 } elseif ($feature ==
'ecm') {
846 if (!$user->hasRight(
'ecm',
'upload')) {
849 } elseif ($feature ==
'ftp') {
850 if (!$user->hasRight(
'ftp',
'write')) {
853 } elseif ($feature ==
'salaries') {
854 if (!$user->hasRight(
'salaries',
'delete')) {
857 } elseif ($feature ==
'adherent') {
858 if (!$user->hasRight(
'adherent',
'supprimer')) {
861 } elseif ($feature ==
'paymentbybanktransfer') {
862 if (!$user->hasRight(
'paymentbybanktransfer',
'create')) {
865 } elseif ($feature ==
'prelevement') {
866 if (!$user->hasRight(
'prelevement',
'bons',
'creer')) {
869 } elseif (!empty($feature2)) {
870 foreach ($feature2 as $subfeature) {
871 if (!$user->hasRight($feature, $subfeature,
'supprimer') && !$user->hasRight($feature, $subfeature,
'delete')) {
878 } elseif (!empty($feature)) {
880 if (!$user->hasRight($feature,
'supprimer')
881 && !$user->hasRight($feature,
'delete')
882 && !$user->hasRight($feature,
'run')) {
889 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
893 if (!$deleteok && !($isdraft && $createok)) {
905 if (!empty($objectid) && $objectid > 0) {
907 $params = array(
'objectid' => $objectid,
'features' => implode(
',', $featuresarray),
'features2' => $feature2);
938function checkUserAccessToObject($user, array $featuresarray,
$object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'', $dbt_select =
'rowid', $parenttableforentity =
'')
947 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', $objectid);
954 $params = explode(
'&', $tableandshare);
955 $dbtablename = (!empty($params[0]) ? $params[0] :
'');
956 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
958 foreach ($featuresarray as $feature) {
964 if ($feature ==
'societe' && !empty($feature2) && is_array($feature2) && in_array(
'contact', $feature2)) {
965 $feature =
'contact';
968 if ($feature ==
'member') {
969 $feature =
'adherent';
971 if ($feature ==
'project') {
974 if ($feature ==
'projet' && !empty($feature2) && is_array($feature2) && !empty(array_intersect(array(
'project_task',
'projet_task'), $feature2))) {
975 $feature =
'project_task';
977 if ($feature ==
'task' || $feature ==
'projet_task') {
978 $feature =
'project_task';
979 $dbtablename =
'projet_task';
981 if ($feature ==
'eventorganization') {
983 $dbtablename =
'actioncomm';
985 if ($feature ==
'payment_sc' && empty($parenttableforentity)) {
987 $parenttableforentity =
'';
988 $dbtablename =
"chargesociales";
989 $feature =
"chargesociales";
990 $objectid =
$object->fk_charge;
993 $checkonentitydone = 0;
996 $check = array(
'adherent',
'banque',
'bom',
'don',
'mrp',
'user',
'usergroup',
'payment',
'payment_supplier',
'payment_sc',
'product',
'produit',
'service',
'produit|service',
'categorie',
'resource',
'expensereport',
'holiday',
'salaries',
'website',
'recruitment',
'chargesociales',
'knowledgemanagement',
'stock');
997 $checksoc = array(
'societe');
998 $checkparentsoc = array(
'agenda',
'contact',
'contrat');
999 $checkproject = array(
'projet',
'project');
1000 $checktask = array(
'projet_task',
'project_task');
1001 $checkhierarchy = array(
'expensereport',
'holiday',
'hrm');
1002 $checkuser = array(
'bookmark');
1003 $nocheck = array(
'barcode');
1008 if (empty($dbtablename)) {
1009 $dbtablename = $feature;
1010 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
1014 if ($dbt_select !=
'rowid' && $dbt_select !=
'id') {
1015 $objectid =
"'".$objectid.
"'";
1018 if (in_array($feature, $check) && $objectid > 0) {
1019 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1020 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1021 if (($feature ==
'user' || $feature ==
'usergroup') && isModEnabled(
'multicompany')) {
1023 if (
$conf->entity == 1 && $user->admin && !$user->entity) {
1024 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1025 $sql .=
" AND dbt.entity IS NOT NULL";
1027 $sql .=
",".MAIN_DB_PREFIX.
"usergroup_user as ug";
1028 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1029 $sql .=
" AND ((ug.fk_user = dbt.rowid";
1030 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1031 $sql .=
" OR dbt.entity = 0)";
1034 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1035 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1039 if ($parenttableforentity && preg_match(
'/(.*)@(.*)/', $parenttableforentity, $reg)) {
1040 $sql .=
", ".MAIN_DB_PREFIX.$reg[2].
" as dbtp";
1041 $sql .=
" WHERE dbt.".$reg[1].
" = dbtp.rowid AND dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1042 $sql .=
" AND dbtp.entity IN (".getEntity($sharedelement, 1).
")";
1044 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1045 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1048 $checkonentitydone = 1;
1050 if (in_array($feature, $checksoc) && $objectid > 0) {
1052 if ($user->socid > 0) {
1053 if ($user->socid != $objectid) {
1056 } elseif (isModEnabled(
'societe') && !$user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir')) {
1057 dol_syslog(
"security.lib.php::checkUserAccessToObject Deny access due: (isModEnabled('societe') && !user->hasRight('societe', 'lire') && !user->hasRight('societe', 'client', 'voir'))", LOG_DEBUG);
1059 } elseif (isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir'))) {
1061 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
1062 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
1063 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s)";
1064 $sql .=
" WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).
")";
1065 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
1067 $userschilds = $user->getAllChildIds();
1068 if (!empty($userschilds)) $sql .=
" OR sc.fk_user IN (".$db->sanitize(implode(
',', $userschilds)).
")";
1071 $sql .=
" AND sc.fk_soc = s.rowid";
1072 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
1073 } elseif (isModEnabled(
'multicompany')) {
1075 $sql =
"SELECT COUNT(s.rowid) as nb";
1076 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
1077 $sql .=
" WHERE s.rowid IN (".$db->sanitize($objectid, 1).
")";
1078 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
1081 $checkonentitydone = 1;
1083 if (in_array($feature, $checkparentsoc) && $objectid > 0) {
1085 if ($user->socid > 0) {
1086 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1087 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1088 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1089 $sql .=
" AND dbt.fk_soc = ".((int) $user->socid);
1090 } elseif (isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir'))) {
1092 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1093 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1094 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1095 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1096 $sql .=
" AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)";
1097 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1098 } elseif (isModEnabled(
'multicompany')) {
1100 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1101 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1102 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1103 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1106 $checkonentitydone = 1;
1108 if (in_array($feature, $checkproject) && $objectid > 0) {
1109 if (isModEnabled(
'project') && !$user->hasRight(
'projet',
'all',
'lire')) {
1110 $projectid = $objectid;
1112 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1113 $projectstatic =
new Project($db);
1114 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1116 $tmparray = explode(
',', $tmps);
1117 if (!in_array($projectid, $tmparray)) {
1121 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1122 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1123 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1124 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1126 $checkonentitydone = 1;
1128 if (in_array($feature, $checktask) && (
int) $objectid > 0) {
1129 if (isModEnabled(
'project') && !$user->hasRight(
'projet',
'all',
'lire')) {
1130 $task =
new Task($db);
1131 $task->fetch((
int) $objectid);
1132 $projectid = $task->fk_project;
1134 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1135 $projectstatic =
new Project($db);
1136 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1138 $tmparray = explode(
',', $tmps);
1139 if (!in_array($projectid, $tmparray)) {
1143 $sharedelement =
'project';
1144 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1145 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1146 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1147 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1150 $checkonentitydone = 1;
1154 if (!$checkonentitydone && !in_array($feature, $nocheck) && $objectid > 0) {
1156 if ($user->socid > 0) {
1157 if (empty($dbt_keyfield)) {
1158 dol_print_error(
null,
'Param dbt_keyfield is required but not defined');
1160 $sql =
"SELECT COUNT(dbt.".$dbt_keyfield.
") as nb";
1161 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1162 $sql .=
" WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).
")";
1163 $sql .=
" AND dbt.".$dbt_keyfield.
" = ".((int) $user->socid);
1164 } elseif (isModEnabled(
"societe") && !$user->hasRight(
'societe',
'client',
'voir')) {
1166 if ($feature !=
'ticket') {
1167 if (empty($dbt_keyfield)) {
1168 dol_print_error(
null,
'Param dbt_keyfield is required but not defined');
1170 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
1171 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1172 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
1173 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1174 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1175 $sql .=
" AND sc.fk_soc = dbt.".$dbt_keyfield;
1176 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
1178 $userschilds = $user->getAllChildIds();
1179 if (!empty($userschilds)) $sql .=
" OR sc.fk_user IN (".$db->sanitize(implode(
',', $userschilds)).
")";
1184 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1185 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1186 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = dbt.".$dbt_keyfield.
" AND sc.fk_user = ".((int) $user->id);
1187 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1188 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1189 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
" OR sc.fk_user IS NULL)";
1191 } elseif (isModEnabled(
'multicompany')) {
1193 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1194 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1195 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1196 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1201 if ($feature ===
'agenda' && ((
int) $objectid) > 0) {
1203 if ( !$user->hasRight(
'agenda',
'allactions',
'read')) {
1204 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1206 $action->fetch((
int) $objectid);
1207 if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
1215 if (in_array($feature, $checkhierarchy) && is_object(
$object) && $objectid > 0) {
1216 $childids = $user->getAllChildIds(1);
1218 if ($feature ==
'holiday') {
1219 $useridtocheck =
$object->fk_user;
1220 if (!$user->hasRight(
'holiday',
'readall') && !in_array($useridtocheck, $childids) && !in_array(
$object->fk_validator, $childids)) {
1224 if ($feature ==
'expensereport') {
1225 $useridtocheck =
$object->fk_user_author;
1226 if (!$user->hasRight(
'expensereport',
'readall')) {
1227 if (!in_array($useridtocheck, $childids)) {
1232 if ($feature ==
'hrm' && in_array(
'evaluation', $feature2)) {
1233 $useridtocheck =
$object->fk_user;
1235 if ($user->hasRight(
'hrm',
'evaluation',
'readall')) {
1239 if (!$user->hasRight(
'hrm',
'evaluation',
'read')) {
1244 return in_array($useridtocheck, $childids);
1250 if (in_array($feature, $checkuser) && is_object(
$object) && $objectid > 0) {
1251 $useridtocheck =
$object->fk_user;
1252 if (!empty($useridtocheck) && $useridtocheck > 0 && $useridtocheck != $user->id && empty($user->admin)) {
1258 $resql = $db->query($sql);
1260 $obj = $db->fetch_object($resql);
1261 if (!$obj || $obj->nb < count(explode(
',', $objectid))) {
1265 dol_syslog(
"Bad forged sql in security.lib.php::checkUserAccessToObject", LOG_WARNING);
1271 dol_syslog(
"security.lib.php::checkUserAccessToObject::return True", LOG_DEBUG);
1314function accessforbidden($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
1316 global
$conf, $db, $user, $langs, $hookmanager;
1319 if (!is_object($langs)) {
1320 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
1322 $langs->setDefaultLang();
1325 $langs->loadLangs(array(
"main",
"errors"));
1327 if ($printheader && !defined(
'NOHEADERNOFOOTER')) {
1328 if (function_exists(
"llxHeader")) {
1330 } elseif (function_exists(
"llxHeaderVierge")) {
1333 print
'<div style="padding: 20px">';
1335 print
'<div class="error">';
1336 if (empty($message)) {
1337 print $langs->trans(
"ErrorForbidden");
1339 print $langs->trans($message);
1343 if (empty($showonlymessage)) {
1344 if (empty($hookmanager)) {
1345 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
1348 $hookmanager->initHooks(array(
'main'));
1351 $parameters = array(
'message' => $message,
'params' => $params);
1352 $reshook = $hookmanager->executeHooks(
'getAccessForbiddenMessage', $parameters,
$object, $action);
1353 print $hookmanager->resPrint;
1354 if (empty($reshook)) {
1355 $langs->loadLangs(array(
"errors"));
1357 print $langs->trans(
"CurrentLogin").
': <span class="error">'.$user->login.
'</span><br>';
1358 print $langs->trans(
"ErrorForbidden2", $langs->transnoentitiesnoconv(
"Home"), $langs->transnoentitiesnoconv(
"Users"));
1359 print $langs->trans(
"ErrorForbidden4");
1361 print $langs->trans(
"ErrorForbidden3");
1365 if ($printfooter && !defined(
'NOHEADERNOFOOTER') && function_exists(
"llxFooter")) {
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.