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';
514 if (in_array($features, [
'commandedet',
'propaldet',
'facturedet',
'supplier_proposaldet',
'evaluationdet',
'skilldet',
'deliverydet',
'contratdet'])) {
515 $features = substr($features, 0, -3);
516 } elseif (in_array($features, [
'stocktransferline',
'inventoryline',
'bomline',
'expensereport_det',
'facture_fourn_det'])) {
517 $features = substr($features, 0, -4);
518 } elseif ($features ==
'commandefournisseurdispatch') {
519 $features =
'commandefournisseur';
520 } elseif ($features ==
'invoice_supplier_det_rec') {
521 $features =
'invoice_supplier_rec';
534 $parameters = array(
'features' => $features,
'originalfeatures' => $originalfeatures,
'objectid' => $objectid,
'dbt_select' => $dbt_select,
'idtype' => $dbt_select,
'isdraft' => $isdraft);
535 if (!empty($hookmanager)) {
536 $reshook = $hookmanager->executeHooks(
'restrictedArea', $parameters);
538 if (isset($hookmanager->resArray[
'result'])) {
539 if ($hookmanager->resArray[
'result'] == 0) {
553 $featuresarray = array($features);
554 if (preg_match(
'/&/', $features)) {
555 $featuresarray = explode(
"&", $features);
556 } elseif (preg_match(
'/\|/', $features)) {
557 $featuresarray = explode(
"|", $features);
561 if (!empty($feature2)) {
562 $feature2 = explode(
"|", $feature2);
570 foreach ($featuresarray as $feature) {
571 $featureforlistofmodule = $feature;
572 if ($featureforlistofmodule ==
'produit') {
573 $featureforlistofmodule =
'product';
575 if ($featureforlistofmodule ==
'supplier_proposal') {
576 $featureforlistofmodule =
'supplierproposal';
578 if (!empty($user->socid) &&
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL') && !in_array($featureforlistofmodule, $listofmodules)) {
584 if ($feature ==
'societe' && (empty($feature2) || !in_array(
'contact', $feature2))) {
585 if (!$user->hasRight(
'societe',
'lire') && !$user->hasRight(
'fournisseur',
'lire')) {
589 } elseif (($feature ==
'societe' && (!empty($feature2) && in_array(
'contact', $feature2))) || $feature ==
'contact') {
590 if (!$user->hasRight(
'societe',
'contact',
'lire')) {
594 } elseif ($feature ==
'produit|service') {
595 if (!$user->hasRight(
'produit',
'lire') && !$user->hasRight(
'service',
'lire')) {
599 } elseif ($feature ==
'prelevement') {
600 if (!$user->hasRight(
'prelevement',
'bons',
'lire')) {
604 } elseif ($feature ==
'cheque') {
605 if (!$user->hasRight(
'banque',
'cheque')) {
609 } elseif ($feature ==
'projet') {
610 if (!$user->hasRight(
'projet',
'lire') && !$user->hasRight(
'projet',
'all',
'lire')) {
614 } elseif ($feature ==
'payment') {
615 if (!$user->hasRight(
'facture',
'lire')) {
619 } elseif ($feature ==
'payment_supplier') {
620 if (!$user->hasRight(
'fournisseur',
'facture',
'lire')) {
624 } elseif ($feature ==
'payment_sc') {
625 if (!$user->hasRight(
'tax',
'charges',
'lire')) {
629 } elseif (!empty($feature2)) {
631 foreach ($feature2 as $subfeature) {
632 if ($subfeature ==
'user' && $user->id == $objectid) {
635 if ($subfeature ==
'fiscalyear' && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
640 if (!empty($subfeature) && !$user->hasRight($feature, $subfeature,
'lire') && !$user->hasRight($feature, $subfeature,
'read')) {
642 } elseif (empty($subfeature) && !$user->hasRight($feature,
'lire') && !$user->hasRight($feature,
'read')) {
653 } elseif (!empty($feature) && ($feature !=
'user' && $feature !=
'usergroup')) {
654 if (!$user->hasRight($feature,
'lire')
655 && !$user->hasRight($feature,
'read')
656 && !$user->hasRight($feature,
'run')) {
664 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
680 $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));
681 $wemustcheckpermissionfordeletedraft = ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete');
683 if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
684 foreach ($featuresarray as $feature) {
685 if ($feature ==
'contact') {
686 if (!$user->hasRight(
'societe',
'contact',
'creer')) {
690 } elseif ($feature ==
'produit|service') {
691 if (!$user->hasRight(
'produit',
'creer') && !$user->hasRight(
'service',
'creer')) {
695 } elseif ($feature ==
'prelevement') {
696 if (!$user->hasRight(
'prelevement',
'bons',
'creer')) {
700 } elseif ($feature ==
'commande_fournisseur') {
701 if (!$user->hasRight(
'fournisseur',
'commande',
'creer') || !$user->hasRight(
'supplier_order',
'creer')) {
705 } elseif ($feature ==
'banque') {
706 if (!$user->hasRight(
'banque',
'modifier')) {
710 } elseif ($feature ==
'cheque') {
711 if (!$user->hasRight(
'banque',
'cheque')) {
715 } elseif ($feature ==
'import') {
716 if (!$user->hasRight(
'import',
'run')) {
720 } elseif ($feature ==
'ecm') {
721 if (!$user->hasRight(
'ecm',
'upload')) {
725 } elseif ($feature ==
'modulebuilder') {
726 if (!$user->hasRight(
'modulebuilder',
'run')) {
730 } elseif (!empty($feature2)) {
731 foreach ($feature2 as $subfeature) {
732 if ($subfeature ==
'user' && $user->id == $objectid && $user->hasRight(
'user',
'self',
'creer')) {
735 if ($subfeature ==
'user' && $user->id == $objectid && $user->hasRight(
'user',
'self',
'password')) {
738 if ($subfeature ==
'user' && $user->id != $objectid && $user->hasRight(
'user',
'user',
'password')) {
742 if (!$user->hasRight($feature, $subfeature,
'creer')
743 && !$user->hasRight($feature, $subfeature,
'write')
744 && !$user->hasRight($feature, $subfeature,
'create')) {
753 } elseif (!empty($feature)) {
755 if (!$user->hasRight($feature,
'creer')
756 && !$user->hasRight($feature,
'write')
757 && !$user->hasRight($feature,
'create')) {
765 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
769 if ($wemustcheckpermissionforcreate && !$createok) {
781 if (
GETPOST(
'action',
'aZ09') ==
'confirm_create_user' &&
GETPOST(
"confirm",
'aZ09') ==
'yes') {
782 if (!$user->hasRight(
'user',
'user',
'creer')) {
786 if (!$createuserok) {
799 if ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete') {
800 foreach ($featuresarray as $feature) {
801 if ($feature ==
'bookmark') {
802 if (!$user->hasRight(
'bookmark',
'supprimer')) {
803 if ($user->id !=
$object->fk_user || !$user->hasRight(
'bookmark',
'creer')) {
807 } elseif ($feature ==
'contact') {
808 if (!$user->hasRight(
'societe',
'contact',
'supprimer')) {
811 } elseif ($feature ==
'produit|service') {
812 if (!$user->hasRight(
'produit',
'supprimer') && !$user->hasRight(
'service',
'supprimer')) {
815 } elseif ($feature ==
'commande_fournisseur') {
816 if (!$user->hasRight(
'fournisseur',
'commande',
'supprimer')) {
819 } elseif ($feature ==
'payment_supplier') {
820 if (!$user->hasRight(
'fournisseur',
'facture',
'creer')) {
823 } elseif ($feature ==
'payment') {
824 if (!$user->hasRight(
'facture',
'paiement')) {
827 } elseif ($feature ==
'payment_sc') {
828 if (!$user->hasRight(
'tax',
'charges',
'creer')) {
831 } elseif ($feature ==
'banque') {
832 if (!$user->hasRight(
'banque',
'modifier')) {
835 } elseif ($feature ==
'cheque') {
836 if (!$user->hasRight(
'banque',
'cheque')) {
839 } elseif ($feature ==
'ecm') {
840 if (!$user->hasRight(
'ecm',
'upload')) {
843 } elseif ($feature ==
'ftp') {
844 if (!$user->hasRight(
'ftp',
'write')) {
847 } elseif ($feature ==
'salaries') {
848 if (!$user->hasRight(
'salaries',
'delete')) {
851 } elseif ($feature ==
'adherent') {
852 if (!$user->hasRight(
'adherent',
'supprimer')) {
855 } elseif ($feature ==
'paymentbybanktransfer') {
856 if (!$user->hasRight(
'paymentbybanktransfer',
'create')) {
859 } elseif ($feature ==
'prelevement') {
860 if (!$user->hasRight(
'prelevement',
'bons',
'creer')) {
863 } elseif (!empty($feature2)) {
864 foreach ($feature2 as $subfeature) {
865 if (!$user->hasRight($feature, $subfeature,
'supprimer') && !$user->hasRight($feature, $subfeature,
'delete')) {
872 } elseif (!empty($feature)) {
874 if (!$user->hasRight($feature,
'supprimer')
875 && !$user->hasRight($feature,
'delete')
876 && !$user->hasRight($feature,
'run')) {
883 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
887 if (!$deleteok && !($isdraft && $createok)) {
899 if (!empty($objectid) && $objectid > 0) {
901 $params = array(
'objectid' => $objectid,
'features' => implode(
',', $featuresarray),
'features2' => $feature2);
932function checkUserAccessToObject($user, array $featuresarray,
$object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'', $dbt_select =
'rowid', $parenttableforentity =
'')
941 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', $objectid);
948 $params = explode(
'&', $tableandshare);
949 $dbtablename = (!empty($params[0]) ? $params[0] :
'');
950 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
952 foreach ($featuresarray as $feature) {
958 if ($feature ==
'societe' && !empty($feature2) && is_array($feature2) && in_array(
'contact', $feature2)) {
959 $feature =
'contact';
962 if ($feature ==
'member') {
963 $feature =
'adherent';
965 if ($feature ==
'project') {
968 if ($feature ==
'task') {
969 $feature =
'projet_task';
971 if ($feature ==
'eventorganization') {
973 $dbtablename =
'actioncomm';
975 if ($feature ==
'payment_sc' && empty($parenttableforentity)) {
977 $parenttableforentity =
'';
978 $dbtablename =
"chargesociales";
979 $feature =
"chargesociales";
980 $objectid =
$object->fk_charge;
983 $checkonentitydone = 0;
986 $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');
987 $checksoc = array(
'societe');
988 $checkparentsoc = array(
'agenda',
'contact',
'contrat');
989 $checkproject = array(
'projet',
'project');
990 $checktask = array(
'projet_task');
991 $checkhierarchy = array(
'expensereport',
'holiday');
992 $checkuser = array(
'bookmark');
993 $nocheck = array(
'barcode',
'stock');
998 if (empty($dbtablename)) {
999 $dbtablename = $feature;
1000 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
1004 if ($dbt_select !=
'rowid' && $dbt_select !=
'id') {
1005 $objectid =
"'".$objectid.
"'";
1008 if (in_array($feature, $check) && $objectid > 0) {
1009 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1010 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1011 if (($feature ==
'user' || $feature ==
'usergroup') && isModEnabled(
'multicompany')) {
1013 if (
$conf->entity == 1 && $user->admin && !$user->entity) {
1014 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1015 $sql .=
" AND dbt.entity IS NOT NULL";
1017 $sql .=
",".MAIN_DB_PREFIX.
"usergroup_user as ug";
1018 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1019 $sql .=
" AND ((ug.fk_user = dbt.rowid";
1020 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1021 $sql .=
" OR dbt.entity = 0)";
1024 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1025 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1029 if ($parenttableforentity && preg_match(
'/(.*)@(.*)/', $parenttableforentity, $reg)) {
1030 $sql .=
", ".MAIN_DB_PREFIX.$reg[2].
" as dbtp";
1031 $sql .=
" WHERE dbt.".$reg[1].
" = dbtp.rowid AND dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1032 $sql .=
" AND dbtp.entity IN (".getEntity($sharedelement, 1).
")";
1034 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1035 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1038 $checkonentitydone = 1;
1040 if (in_array($feature, $checksoc) && $objectid > 0) {
1042 if ($user->socid > 0) {
1043 if ($user->socid != $objectid) {
1046 } elseif (isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir'))) {
1048 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
1049 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
1050 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s)";
1051 $sql .=
" WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).
")";
1052 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
1054 $userschilds = $user->getAllChildIds();
1055 $sql .=
" OR sc.fk_user IN (".$db->sanitize(implode(
',', $userschilds)).
")";
1058 $sql .=
" AND sc.fk_soc = s.rowid";
1059 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
1060 } elseif (isModEnabled(
'multicompany')) {
1062 $sql =
"SELECT COUNT(s.rowid) as nb";
1063 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
1064 $sql .=
" WHERE s.rowid IN (".$db->sanitize($objectid, 1).
")";
1065 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
1068 $checkonentitydone = 1;
1070 if (in_array($feature, $checkparentsoc) && $objectid > 0) {
1072 if ($user->socid > 0) {
1073 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1074 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1075 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1076 $sql .=
" AND dbt.fk_soc = ".((int) $user->socid);
1077 } elseif (isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir'))) {
1079 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1080 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1081 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1082 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1083 $sql .=
" AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)";
1084 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1085 } elseif (isModEnabled(
'multicompany')) {
1087 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1088 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1089 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1090 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1093 $checkonentitydone = 1;
1095 if (in_array($feature, $checkproject) && $objectid > 0) {
1096 if (isModEnabled(
'project') && !$user->hasRight(
'projet',
'all',
'lire')) {
1097 $projectid = $objectid;
1099 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1100 $projectstatic =
new Project($db);
1101 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1103 $tmparray = explode(
',', $tmps);
1104 if (!in_array($projectid, $tmparray)) {
1108 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1109 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1110 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1111 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1113 $checkonentitydone = 1;
1115 if (in_array($feature, $checktask) && $objectid > 0) {
1116 if (isModEnabled(
'project') && !$user->hasRight(
'projet',
'all',
'lire')) {
1117 $task =
new Task($db);
1118 $task->fetch($objectid);
1119 $projectid = $task->fk_project;
1121 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1122 $projectstatic =
new Project($db);
1123 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1125 $tmparray = explode(
',', $tmps);
1126 if (!in_array($projectid, $tmparray)) {
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.entity IN (".getEntity($sharedelement, 1).
")";
1136 $checkonentitydone = 1;
1140 if (!$checkonentitydone && !in_array($feature, $nocheck) && $objectid > 0) {
1142 if ($user->socid > 0) {
1143 if (empty($dbt_keyfield)) {
1144 dol_print_error(
null,
'Param dbt_keyfield is required but not defined');
1146 $sql =
"SELECT COUNT(dbt.".$dbt_keyfield.
") as nb";
1147 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1148 $sql .=
" WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).
")";
1149 $sql .=
" AND dbt.".$dbt_keyfield.
" = ".((int) $user->socid);
1150 } elseif (isModEnabled(
"societe") && !$user->hasRight(
'societe',
'client',
'voir')) {
1152 if ($feature !=
'ticket') {
1153 if (empty($dbt_keyfield)) {
1154 dol_print_error(
null,
'Param dbt_keyfield is required but not defined');
1156 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
1157 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1158 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
1159 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1160 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1161 $sql .=
" AND sc.fk_soc = dbt.".$dbt_keyfield;
1162 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
1164 $userschilds = $user->getAllChildIds();
1165 foreach ($userschilds as $key => $value) {
1166 $sql .=
' OR sc.fk_user = '.((int) $value);
1172 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1173 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1174 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = dbt.".$dbt_keyfield.
" AND sc.fk_user = ".((int) $user->id);
1175 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1176 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1177 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
" OR sc.fk_user IS NULL)";
1179 } elseif (isModEnabled(
'multicompany')) {
1181 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1182 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1183 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1184 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1189 if ($feature ===
'agenda' && $objectid > 0) {
1191 if ($objectid > 0 && !$user->hasRight(
'agenda',
'allactions',
'read')) {
1192 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1194 $action->fetch($objectid);
1195 if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
1203 if (in_array($feature, $checkhierarchy) && is_object(
$object) && $objectid > 0) {
1204 $childids = $user->getAllChildIds(1);
1206 if ($feature ==
'holiday') {
1207 $useridtocheck =
$object->fk_user;
1208 if (!$user->hasRight(
'holiday',
'readall') && !in_array($useridtocheck, $childids) && !in_array(
$object->fk_validator, $childids)) {
1212 if ($feature ==
'expensereport') {
1213 $useridtocheck =
$object->fk_user_author;
1214 if (!$user->hasRight(
'expensereport',
'readall')) {
1215 if (!in_array($useridtocheck, $childids)) {
1224 if (in_array($feature, $checkuser) && is_object(
$object) && $objectid > 0) {
1225 $useridtocheck =
$object->fk_user;
1226 if (!empty($useridtocheck) && $useridtocheck > 0 && $useridtocheck != $user->id && empty($user->admin)) {
1232 $resql = $db->query($sql);
1234 $obj = $db->fetch_object($resql);
1235 if (!$obj || $obj->nb < count(explode(
',', $objectid))) {
1239 dol_syslog(
"Bad forged sql in checkUserAccessToObject", LOG_WARNING);
1287function accessforbidden($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
1289 global
$conf, $db, $user, $langs, $hookmanager;
1292 if (!is_object($langs)) {
1293 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
1295 $langs->setDefaultLang();
1298 $langs->loadLangs(array(
"main",
"errors"));
1300 if ($printheader && !defined(
'NOHEADERNOFOOTER')) {
1301 if (function_exists(
"llxHeader")) {
1303 } elseif (function_exists(
"llxHeaderVierge")) {
1306 print
'<div style="padding: 20px">';
1308 print
'<div class="error">';
1309 if (empty($message)) {
1310 print $langs->trans(
"ErrorForbidden");
1312 print $langs->trans($message);
1316 if (empty($showonlymessage)) {
1317 if (empty($hookmanager)) {
1318 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
1321 $hookmanager->initHooks(array(
'main'));
1324 $parameters = array(
'message' => $message,
'params' => $params);
1325 $reshook = $hookmanager->executeHooks(
'getAccessForbiddenMessage', $parameters,
$object, $action);
1326 print $hookmanager->resPrint;
1327 if (empty($reshook)) {
1328 $langs->loadLangs(array(
"errors"));
1330 print $langs->trans(
"CurrentLogin").
': <span class="error">'.$user->login.
'</span><br>';
1331 print $langs->trans(
"ErrorForbidden2", $langs->transnoentitiesnoconv(
"Home"), $langs->transnoentitiesnoconv(
"Users"));
1332 print $langs->trans(
"ErrorForbidden4");
1334 print $langs->trans(
"ErrorForbidden3");
1338 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.