448function restrictedArea(
User $user, $features,
$object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'fk_soc', $dbt_select =
'rowid', $isdraft = 0, $mode = 0)
458 if ($objectid ==
"-1") {
462 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', (
string) $objectid);
471 $parentfortableentity =
'';
475 $originalfeatures = $features;
476 if ($features ==
'agenda') {
477 $tableandshare =
'actioncomm&societe';
478 $feature2 =
'myactions|allactions';
481 if ($features ==
'bank') {
482 $features =
'banque';
484 if ($features ==
'facturerec') {
485 $features =
'facture';
487 if ($features ==
'supplier_invoicerec') {
488 $features =
'fournisseur';
489 $feature2 =
'facture';
491 if ($features ==
'mo') {
494 if ($features ==
'member') {
495 $features =
'adherent';
497 if ($features ==
'subscription') {
498 $features =
'adherent';
499 $feature2 =
'cotisation';
501 if ($features ==
'website' && is_object(
$object) &&
$object->element ==
'websitepage') {
502 $parentfortableentity =
'fk_website@website';
504 if ($features ==
'project') {
505 $features =
'projet';
507 if ($features ==
'product') {
508 $features =
'produit';
510 if ($features ==
'productbatch') {
511 $features =
'produit';
513 if ($features ==
'tax') {
514 $feature2 =
'charges';
516 if ($features ==
'workstation') {
517 $feature2 =
'workstation';
519 if ($features ==
'fournisseur') {
520 $features =
'fournisseur';
521 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
522 $feature2 =
'facture';
523 } elseif (is_object(
$object) &&
$object->element ==
'order_supplier') {
524 $feature2 =
'commande';
527 if ($features ==
'payment_sc') {
528 $tableandshare =
'paiementcharge';
529 $parentfortableentity =
'fk_charge@chargesociales';
534 if (in_array($features, [
'commandedet',
'propaldet',
'facturedet',
'supplier_proposaldet',
'evaluationdet',
'skilldet',
'deliverydet',
'contratdet'])) {
535 $features = substr($features, 0, -3);
536 } elseif (in_array($features, [
'stocktransferline',
'inventoryline',
'bomline',
'expensereport_det',
'facture_fourn_det'])) {
537 $features = substr($features, 0, -4);
538 } elseif ($features ==
'commandefournisseurdispatch') {
539 $features =
'commandefournisseur';
540 } elseif ($features ==
'invoice_supplier_det_rec') {
541 $features =
'invoice_supplier_rec';
543 if ($features ==
'evaluation') {
545 $feature2 =
'evaluation';
560 'features' => $features,
561 'feature2' => $feature2,
562 'originalfeatures' => $originalfeatures,
563 'tableandshare' => $tableandshare,
565 'objectid' => $objectid,
566 'dbt_keyfield' => $dbt_keyfield,
567 'dbt_select' => $dbt_select,
568 'idtype' => $dbt_select,
569 'isdraft' => $isdraft,
572 if (!empty($hookmanager)) {
573 $reshook = $hookmanager->executeHooks(
'restrictedArea', $parameters);
575 if (isset($hookmanager->resArray[
'result'])) {
576 if ($hookmanager->resArray[
'result'] == 0) {
590 $featuresarray = array($features);
591 if (preg_match(
'/&/', $features)) {
592 $featuresarray = explode(
"&", $features);
593 } elseif (preg_match(
'/\|/', $features)) {
594 $featuresarray = explode(
"|", $features);
598 if (!empty($feature2)) {
599 $feature2 = explode(
"|", $feature2);
607 foreach ($featuresarray as $feature) {
608 $featureforlistofmodule = $feature;
609 if ($featureforlistofmodule ==
'produit') {
610 $featureforlistofmodule =
'product';
612 if ($featureforlistofmodule ==
'supplier_proposal') {
613 $featureforlistofmodule =
'supplierproposal';
615 if (!empty($user->socid) &&
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL') && !in_array($featureforlistofmodule, $listofmodules)) {
621 if ($feature ==
'societe' && (empty($feature2) || !in_array(
'contact', $feature2))) {
622 if (!$user->hasRight(
'societe',
'lire') && !$user->hasRight(
'fournisseur',
'lire')) {
626 } elseif (($feature ==
'societe' && (!empty($feature2) && in_array(
'contact', $feature2))) || $feature ==
'contact') {
627 if (!$user->hasRight(
'societe',
'contact',
'lire')) {
631 } elseif ($feature ==
'produit|service') {
632 if (!$user->hasRight(
'produit',
'lire') && !$user->hasRight(
'service',
'lire')) {
636 } elseif ($feature ==
'prelevement') {
637 if (!$user->hasRight(
'prelevement',
'bons',
'lire')) {
641 } elseif ($feature ==
'cheque') {
642 if (!$user->hasRight(
'banque',
'cheque')) {
646 } elseif ($feature ==
'projet') {
647 if (!$user->hasRight(
'projet',
'lire') && !$user->hasRight(
'projet',
'all',
'lire')) {
651 } elseif ($feature ==
'payment') {
652 if (!$user->hasRight(
'facture',
'lire')) {
656 } elseif ($feature ==
'payment_supplier') {
657 if (!$user->hasRight(
'fournisseur',
'facture',
'lire')) {
661 } elseif ($feature ==
'payment_sc') {
662 if (!$user->hasRight(
'tax',
'charges',
'lire')) {
666 } elseif ($feature ==
'webhook') {
667 if (empty($user->admin)) {
671 } elseif (!empty($feature2)) {
673 foreach ($feature2 as $subfeature) {
674 if ($subfeature ==
'user' && $user->id == $objectid) {
677 if ($subfeature ==
'fiscalyear' && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
682 if (!empty($subfeature) && !$user->hasRight($feature, $subfeature,
'lire') && !$user->hasRight($feature, $subfeature,
'read')) {
684 } elseif (empty($subfeature) && !$user->hasRight($feature,
'lire') && !$user->hasRight($feature,
'read')) {
695 } elseif (!empty($feature) && ($feature !=
'user' && $feature !=
'usergroup')) {
696 if (!$user->hasRight($feature,
'lire')
697 && !$user->hasRight($feature,
'read')
698 && !$user->hasRight($feature,
'run')) {
706 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
722 $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));
723 $wemustcheckpermissionfordeletedraft = ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete');
725 if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
726 foreach ($featuresarray as $feature) {
727 if ($feature ==
'contact') {
728 if (!$user->hasRight(
'societe',
'contact',
'creer')) {
732 } elseif ($feature ==
'produit|service') {
733 if (!$user->hasRight(
'produit',
'creer') && !$user->hasRight(
'service',
'creer')) {
737 } elseif ($feature ==
'prelevement') {
738 if (!$user->hasRight(
'prelevement',
'bons',
'creer')) {
742 } elseif ($feature ==
'commande_fournisseur') {
743 if (!$user->hasRight(
'fournisseur',
'commande',
'creer') || !$user->hasRight(
'supplier_order',
'creer')) {
747 } elseif ($feature ==
'banque') {
748 if (!$user->hasRight(
'banque',
'modifier')) {
752 } elseif ($feature ==
'cheque') {
753 if (!$user->hasRight(
'banque',
'cheque')) {
757 } elseif ($feature ==
'import') {
758 if (!$user->hasRight(
'import',
'run')) {
762 } elseif ($feature ==
'ecm') {
763 if (!$user->hasRight(
'ecm',
'upload')) {
767 } elseif ($feature ==
'modulebuilder') {
768 if (!$user->hasRight(
'modulebuilder',
'run')) {
772 } elseif ($feature ==
'webhook') {
773 if (empty($user->admin)) {
777 } elseif (!empty($feature2)) {
778 foreach ($feature2 as $subfeature) {
779 if ($subfeature ==
'user' && $user->id == $objectid && $user->hasRight(
'user',
'self',
'creer')) {
782 if ($subfeature ==
'user' && $user->id == $objectid && $user->hasRight(
'user',
'self',
'password')) {
785 if ($subfeature ==
'user' && $user->id != $objectid && $user->hasRight(
'user',
'user',
'password')) {
789 if (!$user->hasRight($feature, $subfeature,
'creer')
790 && !$user->hasRight($feature, $subfeature,
'write')
791 && !$user->hasRight($feature, $subfeature,
'create')) {
800 } elseif (!empty($feature)) {
802 if (!$user->hasRight($feature,
'creer')
803 && !$user->hasRight($feature,
'write')
804 && !$user->hasRight($feature,
'create')) {
812 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
816 if ($wemustcheckpermissionforcreate && !$createok) {
828 if (
GETPOST(
'action',
'aZ09') ==
'confirm_create_user' &&
GETPOST(
"confirm",
'aZ09') ==
'yes') {
829 if (!$user->hasRight(
'user',
'user',
'creer')) {
833 if (!$createuserok) {
846 if ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete') {
847 foreach ($featuresarray as $feature) {
848 if ($feature ==
'bookmark') {
849 if (!$user->hasRight(
'bookmark',
'supprimer')) {
850 if ($user->id !=
$object->fk_user || !$user->hasRight(
'bookmark',
'creer')) {
854 } elseif ($feature ==
'contact') {
855 if (!$user->hasRight(
'societe',
'contact',
'supprimer')) {
858 } elseif ($feature ==
'produit|service') {
859 if (!$user->hasRight(
'produit',
'supprimer') && !$user->hasRight(
'service',
'supprimer')) {
862 } elseif ($feature ==
'commande_fournisseur') {
863 if (!$user->hasRight(
'fournisseur',
'commande',
'supprimer')) {
866 } elseif ($feature ==
'payment_supplier') {
867 if (!$user->hasRight(
'fournisseur',
'facture',
'creer')) {
870 } elseif ($feature ==
'payment') {
871 if (!$user->hasRight(
'facture',
'paiement')) {
874 } elseif ($feature ==
'payment_sc') {
875 if (!$user->hasRight(
'tax',
'charges',
'creer')) {
878 } elseif ($feature ==
'banque') {
879 if (!$user->hasRight(
'banque',
'modifier')) {
882 } elseif ($feature ==
'cheque') {
883 if (!$user->hasRight(
'banque',
'cheque')) {
886 } elseif ($feature ==
'ecm') {
887 if (!$user->hasRight(
'ecm',
'upload')) {
890 } elseif ($feature ==
'ftp') {
891 if (!$user->hasRight(
'ftp',
'write')) {
894 } elseif ($feature ==
'salaries') {
895 if (!$user->hasRight(
'salaries',
'delete')) {
898 } elseif ($feature ==
'adherent') {
899 if (!$user->hasRight(
'adherent',
'supprimer')) {
902 } elseif ($feature ==
'paymentbybanktransfer') {
903 if (!$user->hasRight(
'paymentbybanktransfer',
'create')) {
906 } elseif ($feature ==
'prelevement') {
907 if (!$user->hasRight(
'prelevement',
'bons',
'creer')) {
910 } elseif (!empty($feature2)) {
911 foreach ($feature2 as $subfeature) {
912 if (!$user->hasRight($feature, $subfeature,
'supprimer') && !$user->hasRight($feature, $subfeature,
'delete')) {
919 } elseif (!empty($feature)) {
921 if (!$user->hasRight($feature,
'supprimer')
922 && !$user->hasRight($feature,
'delete')
923 && !$user->hasRight($feature,
'run')) {
930 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
934 if (!$deleteok && !($isdraft && $createok)) {
946 if (!empty($objectid) && $objectid > 0) {
948 $params = array(
'objectid' => $objectid,
'features' => implode(
',', $featuresarray),
'features2' => $feature2);
979function checkUserAccessToObject($user, array $featuresarray,
$object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'', $dbt_select =
'rowid', $parenttableforentity =
'')
988 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', $objectid);
995 $params = explode(
'&', $tableandshare);
996 $dbtablename = (!empty($params[0]) ? $params[0] :
'');
997 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
999 foreach ($featuresarray as $feature) {
1005 if ($feature ==
'societe' && !empty($feature2) && is_array($feature2) && in_array(
'contact', $feature2)) {
1006 $feature =
'contact';
1009 if ($feature ==
'member') {
1010 $feature =
'adherent';
1012 if ($feature ==
'category') {
1013 $feature =
'categorie';
1015 if ($feature ==
'project') {
1016 $feature =
'projet';
1018 if ($feature ==
'projet' && !empty($feature2) && is_array($feature2) && !empty(array_intersect(array(
'project_task',
'projet_task'), $feature2))) {
1019 $feature =
'project_task';
1021 if ($feature ==
'task' || $feature ==
'projet_task') {
1022 $feature =
'project_task';
1023 $dbtablename =
'projet_task';
1025 if ($feature ==
'eventorganization') {
1026 $feature =
'agenda';
1027 $dbtablename =
'actioncomm';
1029 if ($feature ==
'payment_sc' && empty($parenttableforentity)) {
1031 $parenttableforentity =
'';
1032 $dbtablename =
"chargesociales";
1033 $feature =
"chargesociales";
1034 $objectid =
$object->fk_charge;
1037 $checkonentitydone = 0;
1040 $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');
1041 $checksoc = array(
'societe');
1042 $checkparentsoc = array(
'agenda',
'contact',
'contrat');
1043 $checkproject = array(
'projet',
'project');
1044 $checktask = array(
'projet_task',
'project_task');
1045 $checkhierarchy = array(
'expensereport',
'holiday',
'hrm');
1046 $checkuser = array(
'bookmark');
1047 $nocheck = array(
'barcode',
'webhook');
1052 if (empty($dbtablename)) {
1053 $dbtablename = $feature;
1054 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
1058 if ($dbt_select !=
'rowid' && $dbt_select !=
'id') {
1059 $objectid =
"'".$objectid.
"'";
1062 if (in_array($feature, $check) && $objectid > 0) {
1063 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1064 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1065 if (($feature ==
'user' || $feature ==
'usergroup') &&
isModEnabled(
'multicompany')) {
1067 if ($conf->entity == 1 && $user->admin && !$user->entity) {
1068 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1069 $sql .=
" AND dbt.entity IS NOT NULL";
1071 $sql .=
",".MAIN_DB_PREFIX.
"usergroup_user as ug";
1072 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1073 $sql .=
" AND ((ug.fk_user = dbt.rowid";
1074 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1075 $sql .=
" OR dbt.entity = 0)";
1078 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1079 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1083 if ($parenttableforentity && preg_match(
'/(.*)@(.*)/', $parenttableforentity, $reg)) {
1084 $sql .=
", ".MAIN_DB_PREFIX.$reg[2].
" as dbtp";
1085 $sql .=
" WHERE dbt.".$reg[1].
" = dbtp.rowid AND dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1086 $sql .=
" AND dbtp.entity IN (".getEntity($sharedelement, 1).
")";
1088 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1089 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1092 $checkonentitydone = 1;
1094 if (in_array($feature, $checksoc) && $objectid > 0) {
1096 if ($user->socid > 0) {
1097 if ($user->socid != $objectid) {
1100 } elseif (
isModEnabled(
'societe') && !$user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir')) {
1101 dol_syslog(
"security.lib.php::checkUserAccessToObject Deny access due: (isModEnabled('societe') && !user->hasRight('societe', 'lire') && !user->hasRight('societe', 'client', 'voir'))", LOG_DEBUG);
1103 } elseif (
isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir'))) {
1105 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
1106 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
1107 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s)";
1108 $sql .=
" WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).
")";
1109 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
1111 $userschilds = $user->getAllChildIds();
1112 if (!empty($userschilds)) $sql .=
" OR sc.fk_user IN (".$db->sanitize(implode(
',', $userschilds)).
")";
1115 $sql .=
" AND sc.fk_soc = s.rowid";
1116 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
1119 $sql =
"SELECT COUNT(s.rowid) as nb";
1120 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
1121 $sql .=
" WHERE s.rowid IN (".$db->sanitize($objectid, 1).
")";
1122 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
1125 $checkonentitydone = 1;
1127 if (in_array($feature, $checkparentsoc) && $objectid > 0) {
1129 if ($user->socid > 0) {
1130 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1131 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1132 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1133 $sql .=
" AND dbt.fk_soc = ".((int) $user->socid);
1134 } elseif (
isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir'))) {
1136 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1137 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1138 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1139 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1140 $sql .=
" AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)";
1141 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
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;
1152 if (in_array($feature, $checkproject) && $objectid > 0) {
1153 if (
isModEnabled(
'project') && !$user->hasRight(
'projet',
'all',
'lire')) {
1154 $projectid = $objectid;
1156 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1157 $projectstatic =
new Project($db);
1158 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1160 $tmparray = explode(
',', $tmps);
1161 if (!in_array($projectid, $tmparray)) {
1165 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1166 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1167 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1168 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1170 $checkonentitydone = 1;
1172 if (in_array($feature, $checktask) && (
int) $objectid > 0) {
1173 if (
isModEnabled(
'project') && !$user->hasRight(
'projet',
'all',
'lire')) {
1174 $task =
new Task($db);
1175 $task->fetch((
int) $objectid);
1176 $projectid = $task->fk_project;
1178 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1179 $projectstatic =
new Project($db);
1180 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1182 $tmparray = explode(
',', $tmps);
1183 if (!in_array($projectid, $tmparray)) {
1187 $sharedelement =
'project';
1188 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1189 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1190 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1191 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1194 $checkonentitydone = 1;
1198 if (!$checkonentitydone && !in_array($feature, $nocheck) && $objectid > 0) {
1200 if ($user->socid > 0) {
1201 if (empty($dbt_keyfield)) {
1202 dol_print_error(
null,
'Param dbt_keyfield is required but not defined');
1204 $sql =
"SELECT COUNT(dbt.".$dbt_keyfield.
") as nb";
1205 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1206 $sql .=
" WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).
")";
1207 $sql .=
" AND dbt.".$dbt_keyfield.
" = ".((int) $user->socid);
1208 } elseif (
isModEnabled(
"societe") && !$user->hasRight(
'societe',
'client',
'voir')) {
1210 if (empty($dbt_keyfield)) {
1211 dol_print_error(
null,
'Param dbt_keyfield is required but not defined');
1213 if ($feature !=
'ticket') {
1214 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
1215 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1216 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
1217 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1218 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1219 $sql .=
" AND sc.fk_soc = dbt.".$dbt_keyfield;
1220 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
1222 $userschilds = $user->getAllChildIds();
1223 if (!empty($userschilds)) $sql .=
" OR sc.fk_user IN (".$db->sanitize(implode(
',', $userschilds)).
")";
1228 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1229 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1230 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = dbt.".$dbt_keyfield.
" AND sc.fk_user = ".((int) $user->id);
1231 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1232 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1233 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
" OR dbt.".$dbt_keyfield.
" IS NULL OR dbt.".$dbt_keyfield.
" = 0)";
1237 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1238 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1239 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1240 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1245 if ($feature ===
'agenda' && ((
int) $objectid) > 0) {
1247 if ( !$user->hasRight(
'agenda',
'allactions',
'read')) {
1248 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1250 $action->fetch((
int) $objectid);
1251 if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
1259 if (in_array($feature, $checkhierarchy) && is_object(
$object) && $objectid > 0) {
1260 $childids = $user->getAllChildIds(1);
1262 if ($feature ==
'holiday') {
1263 $useridtocheck =
$object->fk_user;
1264 if (!$user->hasRight(
'holiday',
'readall') && !in_array($useridtocheck, $childids) && !in_array(
$object->fk_validator, $childids)) {
1268 if ($feature ==
'expensereport') {
1269 $useridtocheck =
$object->fk_user_author;
1270 if (!$user->hasRight(
'expensereport',
'readall')) {
1271 if (!in_array($useridtocheck, $childids)) {
1276 if ($feature ==
'hrm' && in_array(
'evaluation', $feature2)) {
1277 $useridtocheck =
$object->fk_user;
1279 if ($user->hasRight(
'hrm',
'evaluation',
'readall')) {
1283 if (!$user->hasRight(
'hrm',
'evaluation',
'read')) {
1288 return in_array($useridtocheck, $childids);
1294 if (in_array($feature, $checkuser) && is_object(
$object) && $objectid > 0) {
1295 $useridtocheck =
$object->fk_user;
1296 if (!empty($useridtocheck) && $useridtocheck > 0 && $useridtocheck != $user->id && empty($user->admin)) {
1302 $resql = $db->query($sql);
1304 $obj = $db->fetch_object($resql);
1305 if (!$obj || $obj->nb < count(explode(
',', $objectid))) {
1309 dol_syslog(
"Bad forged sql in security.lib.php::checkUserAccessToObject", LOG_WARNING);
1315 dol_syslog(
"security.lib.php::checkUserAccessToObject::return True", LOG_DEBUG);
1358function accessforbidden($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
1360 global $conf, $db, $user, $langs, $hookmanager;
1363 if (!is_object($langs)) {
1364 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
1366 $langs->setDefaultLang();
1369 $langs->loadLangs(array(
"main",
"errors"));
1371 if ($printheader && !defined(
'NOHEADERNOFOOTER')) {
1372 if (function_exists(
"llxHeader")) {
1374 } elseif (function_exists(
"llxHeaderVierge")) {
1377 print
'<div style="padding: 20px">';
1379 print
'<div class="error">';
1380 if (empty($message)) {
1381 print $langs->trans(
"ErrorForbidden");
1383 print $langs->trans($message);
1387 if (empty($showonlymessage)) {
1388 if (empty($hookmanager)) {
1389 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
1392 $hookmanager->initHooks(array(
'main'));
1395 $parameters = array(
'message' => $message,
'params' => $params);
1396 $reshook = $hookmanager->executeHooks(
'getAccessForbiddenMessage', $parameters,
$object, $action);
1397 print $hookmanager->resPrint;
1398 if (empty($reshook)) {
1399 $langs->loadLangs(array(
"errors"));
1401 print $langs->trans(
"CurrentLogin").
': <span class="error">'.$user->login.
'</span><br>';
1402 print $langs->trans(
"ErrorForbidden2", $langs->transnoentitiesnoconv(
"Home"), $langs->transnoentitiesnoconv(
"Users"));
1403 print $langs->trans(
"ErrorForbidden4");
1405 print $langs->trans(
"ErrorForbidden3");
1409 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.