183function restrictedArea(
User $user, $features,
$object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'fk_soc', $dbt_select =
'rowid', $isdraft = 0, $nodie = 0, $mode =
'')
193 if ($objectid ==
"-1") {
197 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', (
string) $objectid);
206 $parentfortableentity =
'';
208 $originalfeatures = $features;
211 if ($features ==
'agenda') {
212 $tableandshare =
'actioncomm&societe';
213 $feature2 =
'myactions|allactions';
215 } elseif ($features ==
'bank') {
216 $features =
'banque';
217 } elseif ($features ==
'remisecheque') {
218 $features =
'banque';
219 } elseif ($features ==
'facturerec') {
220 $features =
'facture';
221 } elseif ($features ==
'supplier_invoicerec') {
222 $features =
'fournisseur';
223 $feature2 =
'facture';
224 } elseif ($features ==
'company') {
225 $features =
'societe';
226 } elseif ($features ==
'mo') {
228 } elseif ($features ==
'member') {
229 $features =
'adherent';
230 } elseif ($features ==
'subscription') {
231 $features =
'adherent';
232 $feature2 =
'cotisation';
233 $tableandshare =
'subscription&adherent';
234 $parentfortableentity =
'fk_adherent@adherent';
235 } elseif ($features ==
'website' && is_object(
$object) &&
$object->element ==
'websitepage') {
236 $parentfortableentity =
'fk_website@website';
237 } elseif ($features ==
'project') {
238 $features =
'projet';
239 } elseif ($features ==
'project_task') {
240 $features =
'projet';
241 $objectid = (int)
$object->fk_project;
243 } elseif (is_object(
$object) && ($features ==
'conferenceorbooth@eventorganization' || ($features ==
'eventorganization' &&
$object->element ==
'conferenceorbooth'))) {
246 if (!empty($user->socid) || empty(
$object->fk_project)) {
253 $features =
'projet';
254 $tableandshare =
'projet&project';
255 $objectid = (int)
$object->fk_project;
257 } elseif ($features ==
'product') {
258 $features =
'produit';
259 } elseif ($features ==
'productbatch') {
260 $features =
'produit';
261 } elseif ($features ==
'tax') {
262 $feature2 =
'charges';
263 } elseif ($features ==
'workstation') {
264 $feature2 =
'workstation';
265 } elseif ($features ==
'hrm' && is_object(
$object) && in_array(
$object->element, array(
'job',
'position',
'skill'))) {
267 } elseif ($features ==
'recruitment' && is_object(
$object) && in_array(
$object->element, array(
'recruitmentjobposition',
'recruitmentcandidature'))) {
271 if (empty($feature2)) {
272 $feature2 =
'recruitmentjobposition';
274 if (empty($tableandshare)) {
275 $tableandshare =
$object->table_element;
277 } elseif ($features ==
'stocktransfer' && is_object(
$object) &&
$object->element ==
'stocktransfer') {
278 $feature2 =
'stocktransfer';
279 } elseif (in_array($features, array(
'fournisseur',
'commande_fournisseur',
'facture_fournisseur',
'order_supplier',
'invoice_supplier'))) {
280 $features =
'fournisseur';
281 if (is_object(
$object) &&
$object->element ==
'invoice_supplier') {
282 $feature2 =
'facture';
283 } elseif (is_object(
$object) &&
$object->element ==
'order_supplier') {
284 $feature2 =
'commande';
286 } elseif ($features ==
'payment_sc') {
287 $tableandshare =
'paiementcharge';
288 $parentfortableentity =
'fk_charge@chargesociales';
289 } elseif ($features ==
'payment_vat') {
290 $tableandshare =
'payment_vat';
291 $parentfortableentity =
'fk_tva@tva';
292 } elseif ($features ==
'payment_donation') {
293 $tableandshare =
'payment_donation';
294 $parentfortableentity =
'fk_donation@don';
299 if (in_array($features, [
'commandedet',
'propaldet',
'facturedet',
'supplier_proposaldet',
'evaluationdet',
'skilldet',
'deliverydet',
'contratdet'])) {
300 $features = substr($features, 0, -3);
301 } elseif (in_array($features, [
'stocktransferline',
'inventoryline',
'bomline',
'expensereport_det',
'facture_fourn_det'])) {
302 $features = substr($features, 0, -4);
303 } elseif ($features ==
'commandefournisseurdispatch') {
304 $features =
'commandefournisseur';
305 } elseif ($features ==
'invoice_supplier_det_rec') {
306 $features =
'invoice_supplier_rec';
308 if ($features ==
'evaluation') {
310 $feature2 =
'evaluation';
318 if (is_object(
$object) && in_array(
$object->element, array(
'project_task',
'task'))
319 && (empty($features) || in_array($features, array(
'projet',
'project')))
320 && empty($feature2)) {
321 $features =
'projet';
322 $feature2 =
'project_task';
323 if (empty($tableandshare)) {
324 $tableandshare =
'projet_task';
332 if (empty($features) || trim((
string) $features) ===
'') {
333 dol_syslog(
'restrictedArea() called with an empty features parameter, we refuse the access', LOG_WARNING);
345 'features' => $features,
346 'feature2' => $feature2,
347 'originalfeatures' => $originalfeatures,
348 'tableandshare' => $tableandshare,
350 'objectid' => $objectid,
351 'dbt_keyfield' => $dbt_keyfield,
352 'dbt_select' => $dbt_select,
353 'idtype' => $dbt_select,
354 'isdraft' => $isdraft,
358 if (!empty($hookmanager)) {
359 $reshook = $hookmanager->executeHooks(
'restrictedArea', $parameters);
361 if (isset($hookmanager->resArray[
'result'])) {
362 if ($hookmanager->resArray[
'result'] == 0) {
376 $featuresarray = array($features);
377 if (preg_match(
'/&/', $features)) {
378 $featuresarray = explode(
"&", $features);
379 } elseif (preg_match(
'/\|/', $features)) {
380 $featuresarray = explode(
"|", $features);
384 if (!empty($feature2)) {
385 $feature2 = explode(
"|", $feature2);
395 foreach ($featuresarray as $feature) {
396 $featureforlistofmodule = $feature;
397 if ($featureforlistofmodule ==
'produit') {
398 $featureforlistofmodule =
'product';
400 if ($featureforlistofmodule ==
'supplier_proposal') {
401 $featureforlistofmodule =
'supplierproposal';
403 if (!empty($user->socid) &&
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL') && !in_array($featureforlistofmodule, $listofmodules)) {
409 if (in_array($feature, array(
'societe',
'company')) && (empty($feature2) || !in_array(
'contact', $feature2))) {
410 if (!$user->hasRight(
'societe',
'lire') && !$user->hasRight(
'fournisseur',
'lire')) {
414 } elseif ((in_array($feature, array(
'societe',
'company')) && (!empty($feature2) && in_array(
'contact', $feature2))) || $feature ==
'contact') {
415 if (!$user->hasRight(
'societe',
'contact',
'lire')) {
419 } elseif ($feature ==
'produit|service') {
420 if (!$user->hasRight(
'produit',
'lire') && !$user->hasRight(
'service',
'lire')) {
424 } elseif ($feature ==
'produit') {
430 if (!$user->hasRight(
'produit',
'lire') && !$user->hasRight(
'service',
'lire')) {
434 } elseif (
$object->type == 0 && !$user->hasRight(
'produit',
'lire')) {
437 } elseif (
$object->type == 1 && !$user->hasRight(
'service',
'lire')) {
441 } elseif ($feature ==
'prelevement') {
442 if (!$user->hasRight(
'prelevement',
'bons',
'lire')) {
446 } elseif ($feature ==
'cheque') {
447 if (!$user->hasRight(
'banque',
'cheque')) {
451 } elseif ($feature ==
'projet') {
452 if (!$user->hasRight(
'projet',
'lire') && !$user->hasRight(
'projet',
'all',
'lire')) {
456 } elseif ($feature ==
'payment') {
457 if (!$user->hasRight(
'facture',
'lire')) {
461 } elseif ($feature ==
'payment_supplier') {
462 if (!$user->hasRight(
'fournisseur',
'facture',
'lire')) {
466 } elseif ($feature ==
'payment_sc') {
467 if (!$user->hasRight(
'tax',
'charges',
'lire')) {
471 } elseif ($feature ==
'payment_vat') {
472 if (!$user->hasRight(
'tax',
'charges',
'lire')) {
476 } elseif ($feature ==
'payment_donation') {
477 if (!$user->hasRight(
'don',
'lire')) {
481 } elseif ($feature ==
'webhook') {
482 if (empty($user->admin)) {
486 } elseif (!empty($feature2)) {
488 foreach ($feature2 as $subfeature) {
489 if ($subfeature ==
'user' && $user->id == $objectid) {
492 if ($subfeature ==
'fiscalyear' && $user->hasRight(
'accounting',
'fiscalyear',
'write')) {
497 if (!empty($subfeature) && !$user->hasRight($feature, $subfeature,
'lire') && !$user->hasRight($feature, $subfeature,
'read')) {
499 } elseif (empty($subfeature) && !$user->hasRight($feature,
'lire') && !$user->hasRight($feature,
'read')) {
510 } elseif (!empty($feature) && ($feature !=
'user' && $feature !=
'usergroup')) {
511 if (!$user->hasRight($feature,
'lire')
512 && !$user->hasRight($feature,
'read')
513 && !$user->hasRight($feature,
'run')) {
521 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
537 if ($mode ==
'read') {
538 $wemustcheckpermissionforcreate = 0;
539 $wemustcheckpermissionfordeletedraft = 0;
540 $wemustcheckpermissionfordelete = 0;
541 } elseif ($mode ==
'write') {
542 $wemustcheckpermissionforcreate = 1;
543 $wemustcheckpermissionfordeletedraft = 1;
544 $wemustcheckpermissionfordelete = 0;
545 } elseif ($mode ==
'delete') {
546 $wemustcheckpermissionforcreate = 0;
547 $wemustcheckpermissionfordeletedraft = 0;
548 $wemustcheckpermissionfordelete = 1;
551 $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));
552 $wemustcheckpermissionfordeletedraft = ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete');
553 $wemustcheckpermissionfordelete = ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete');
558 if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
559 foreach ($featuresarray as $feature) {
560 if ($feature ==
'contact') {
561 if (!$user->hasRight(
'societe',
'contact',
'creer')) {
565 } elseif ($feature ==
'produit|service') {
566 if (!$user->hasRight(
'produit',
'creer') && !$user->hasRight(
'service',
'creer')) {
570 } elseif ($feature ==
'prelevement') {
571 if (!$user->hasRight(
'prelevement',
'bons',
'creer')) {
575 } elseif ($feature ==
'commande_fournisseur') {
576 if (!$user->hasRight(
'fournisseur',
'commande',
'creer') || !$user->hasRight(
'supplier_order',
'creer')) {
580 } elseif ($feature ==
'banque') {
581 if (!$user->hasRight(
'banque',
'modifier')) {
585 } elseif ($feature ==
'cheque') {
586 if (!$user->hasRight(
'banque',
'cheque')) {
590 } elseif ($feature ==
'import') {
591 if (!$user->hasRight(
'import',
'run')) {
595 } elseif ($feature ==
'ecm') {
596 if (!$user->hasRight(
'ecm',
'upload')) {
600 } elseif ($feature ==
'modulebuilder') {
601 if (!$user->hasRight(
'modulebuilder',
'run')) {
605 } elseif ($feature ==
'payment') {
606 if (!$user->hasRight(
'facture',
'paiement')) {
610 } elseif ($feature ==
'payment_supplier') {
611 if (!$user->hasRight(
'fournisseur',
'facture',
'creer')) {
615 } elseif ($feature ==
'webhook') {
616 if (empty($user->admin)) {
620 } elseif (!empty($feature2)) {
621 foreach ($feature2 as $subfeature) {
622 if ($subfeature ==
'user' && $user->id == $objectid && $user->hasRight(
'user',
'self',
'creer')) {
625 if ($subfeature ==
'user' && $user->id == $objectid && $user->hasRight(
'user',
'self',
'password')) {
628 if ($subfeature ==
'user' && $user->id != $objectid && $user->hasRight(
'user',
'user',
'password')) {
632 if (!$user->hasRight($feature, $subfeature,
'creer')
633 && !$user->hasRight($feature, $subfeature,
'write')
634 && !$user->hasRight($feature, $subfeature,
'create')) {
643 } elseif (!empty($feature)) {
645 if (!$user->hasRight($feature,
'creer')
646 && !$user->hasRight($feature,
'write')
647 && !$user->hasRight($feature,
'create')) {
655 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
659 if ($wemustcheckpermissionforcreate && !$createok) {
671 if (
GETPOST(
'action',
'aZ09') ==
'confirm_create_user' &&
GETPOST(
"confirm",
'aZ09') ==
'yes') {
672 if (!$user->hasRight(
'user',
'user',
'creer')) {
676 if (!$createuserok) {
689 if ($wemustcheckpermissionfordelete) {
690 foreach ($featuresarray as $feature) {
691 if ($feature ==
'bookmark') {
692 if (!$user->hasRight(
'bookmark',
'supprimer')) {
693 if ($user->id !=
$object->fk_user || !$user->hasRight(
'bookmark',
'creer')) {
697 } elseif ($feature ==
'contact') {
698 if (!$user->hasRight(
'societe',
'contact',
'supprimer')) {
701 } elseif ($feature ==
'produit|service') {
702 if (!$user->hasRight(
'produit',
'supprimer') && !$user->hasRight(
'service',
'supprimer')) {
705 } elseif ($feature ==
'commande_fournisseur') {
706 if (!$user->hasRight(
'fournisseur',
'commande',
'supprimer')) {
709 } elseif ($feature ==
'payment_supplier') {
710 if (!$user->hasRight(
'fournisseur',
'facture',
'creer')) {
713 } elseif ($feature ==
'payment') {
714 if (!$user->hasRight(
'facture',
'paiement')) {
717 } elseif ($feature ==
'payment_sc') {
718 if (!$user->hasRight(
'tax',
'charges',
'creer')) {
721 } elseif ($feature ==
'banque') {
722 if (!$user->hasRight(
'banque',
'modifier')) {
725 } elseif ($feature ==
'cheque') {
726 if (!$user->hasRight(
'banque',
'cheque')) {
729 } elseif ($feature ==
'ecm') {
730 if (!$user->hasRight(
'ecm',
'upload')) {
733 } elseif ($feature ==
'ftp') {
734 if (!$user->hasRight(
'ftp',
'write')) {
737 } elseif ($feature ==
'salaries') {
738 if (!$user->hasRight(
'salaries',
'delete')) {
741 } elseif ($feature ==
'adherent') {
742 if (!$user->hasRight(
'adherent',
'supprimer')) {
745 } elseif ($feature ==
'paymentbybanktransfer') {
746 if (!$user->hasRight(
'paymentbybanktransfer',
'create')) {
749 } elseif ($feature ==
'prelevement') {
750 if (!$user->hasRight(
'prelevement',
'bons',
'creer')) {
753 } elseif (!empty($feature2)) {
754 foreach ($feature2 as $subfeature) {
755 if (!$user->hasRight($feature, $subfeature,
'supprimer') && !$user->hasRight($feature, $subfeature,
'delete')) {
762 } elseif (!empty($feature)) {
764 if (!$user->hasRight($feature,
'supprimer')
765 && !$user->hasRight($feature,
'delete')
766 && !$user->hasRight($feature,
'run')) {
773 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
777 if (!$deleteok && !($isdraft && $createok)) {
789 if (!empty($objectid) && $objectid > 0) {
791 $params = array(
'objectid' => $objectid,
'features' => implode(
',', $featuresarray),
'features2' => $feature2);
822 $modulepartlinkedtothirdparty = array(
823 'societe' => array(
'societe',
'societe'),
824 'company' => array(
'societe',
'societe'),
825 'thirdparty' => array(
'societe',
'societe'),
826 'contact' => array(
'contact',
'contact'),
827 'socpeople' => array(
'contact',
'contact'),
828 'facture' => array(
'facture',
'facture'),
829 'invoice' => array(
'facture',
'facture'),
830 'propal' => array(
'propal',
'propal'),
831 'propale' => array(
'propal',
'propal'),
832 'proposal' => array(
'propal',
'propal'),
833 'commande' => array(
'commande',
'commande'),
834 'order' => array(
'commande',
'commande'),
835 'commande_fournisseur' => array(
'order_supplier',
'order_supplier'),
836 'order_supplier' => array(
'order_supplier',
'order_supplier'),
837 'supplier_order' => array(
'order_supplier',
'order_supplier'),
838 'facture_fournisseur' => array(
'invoice_supplier',
'invoice_supplier'),
839 'invoice_supplier' => array(
'invoice_supplier',
'invoice_supplier'),
840 'supplier_invoice' => array(
'invoice_supplier',
'invoice_supplier'),
841 'contract' => array(
'contrat',
'contrat'),
842 'contrat' => array(
'contrat',
'contrat'),
843 'fichinter' => array(
'fichinter',
'ficheinter'),
844 'ficheinter' => array(
'fichinter',
'ficheinter'),
845 'intervention' => array(
'fichinter',
'ficheinter'),
846 'ticket' => array(
'ticket',
'ticket'),
847 'expedition' => array(
'expedition',
'expedition'),
848 'shipment' => array(
'expedition',
'expedition'),
849 'shipping' => array(
'expedition',
'expedition'),
850 'reception' => array(
'reception',
'reception'),
851 'supplier_proposal' => array(
'supplier_proposal',
'supplier_proposal'),
852 'project' => array(
'project',
'project'),
853 'projet' => array(
'project',
'project'),
854 'project_task' => array(
'project',
'project'),
857 $modulepartwithid = array(
'societe',
'company',
'thirdparty',
'contact',
'socpeople');
859 $modulepartwithfirstdirasref = array(
'project',
'projet',
'project_task');
862 if ($modulepart ==
'expedition' && strpos($original_file,
'receipt/') === 0) {
863 $modulepart =
'delivery';
866 if (strpos($modulepart,
'apercu') === 0) {
871 $refname = basename(dirname($original_file).
"/");
872 if ($refname ==
'thumbs' || $refname ==
'temp') {
873 $refname = basename(dirname(dirname($original_file)).
"/");
876 if (empty($modulepartlinkedtothirdparty[$modulepart])) {
877 $object = fetchObjectByElement(0, $modulepart, $refname);
881 $tmparray = explode(
'/', ltrim($original_file,
'/'));
882 if (count($tmparray) > 2 && ($user->hasRight($modulepart, $tmparray[0], $mode))) {
883 $feature2 = $tmparray[0];
892 if (in_array($modulepart, $modulepartwithid)) {
893 $tmparray = explode(
'/', ltrim($original_file,
'/'));
894 $object = fetchObjectByElement((
int) $tmparray[0], $modulepartlinkedtothirdparty[$modulepart][0]);
895 } elseif (in_array($modulepart, $modulepartwithfirstdirasref)) {
896 $tmparray = explode(
'/', ltrim($original_file,
'/'));
897 $object = fetchObjectByElement(0, $modulepartlinkedtothirdparty[$modulepart][0], (count($tmparray) > 1 ? $tmparray[0] :
''));
899 $object = fetchObjectByElement(0, $modulepartlinkedtothirdparty[$modulepart][0], $refname);
908 if (($user->socid > 0 || !$user->hasRight(
'societe',
'client',
'voir')) && !preg_match(
'/^specimen/i', basename($original_file))) {
909 dol_syslog(
"checkUserAccessToDocumentObject no object found for modulepart=".$modulepart.
" original_file=".$original_file.
", access refused to user restricted to some thirdparties", LOG_WARNING);
931function checkUserAccessToObject($user, array $featuresarray,
$object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'', $dbt_select =
'rowid', $parenttableforentity =
'')
940 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', (
string) $objectid);
947 $params = explode(
'&', $tableandshare);
948 $dbtablename = (!empty($params[0]) ? $params[0] :
'');
949 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
950 $tablegivenbycaller = !empty($params[0]);
952 foreach ($featuresarray as $feature) {
958 if ($feature ==
'bom') {
959 $feature =
'bom_bom';
961 if ($feature ==
'societe' && !empty($feature2) && is_array($feature2) && in_array(
'contact', $feature2)) {
962 $feature =
'contact';
965 if ($feature ==
'member') {
966 $feature =
'adherent';
968 if ($feature ==
'category') {
969 $feature =
'categorie';
971 if ($feature ==
'bank') {
974 if (!$tablegivenbycaller && $feature ==
'contract') {
975 $dbtablename =
'contrat';
977 if (!$tablegivenbycaller && $feature ==
'mrp') {
978 $dbtablename =
'mrp_mo';
980 if (!$tablegivenbycaller && ($feature ==
'order_supplier' || ($feature ==
'fournisseur' && is_object(
$object) &&
$object->element ==
'order_supplier'))) {
981 $dbtablename =
'commande_fournisseur';
983 if (!$tablegivenbycaller && ($feature ==
'invoice_supplier' || ($feature ==
'fournisseur' && is_object(
$object) &&
$object->element ==
'invoice_supplier'))) {
984 $dbtablename =
'facture_fourn';
986 if (!$tablegivenbycaller && $feature ==
'produit') {
987 $dbtablename =
'product';
989 if (!$tablegivenbycaller && $feature ==
'ficheinter') {
990 $dbtablename =
'fichinter';
992 if (!$tablegivenbycaller && $feature ==
'banque') {
994 $dbtablename =
'bank_account';
996 if ($feature ==
'project') {
999 if ($feature ==
'projet' && !empty($feature2) && is_array($feature2) && !empty(array_intersect(array(
'project_task',
'projet_task'), $feature2))) {
1000 $feature =
'project_task';
1002 if (!$tablegivenbycaller && $feature ==
'stock') {
1003 $dbtablename =
'entrepot';
1005 if ($feature ==
'task' || $feature ==
'projet_task') {
1006 $feature =
'project_task';
1007 $dbtablename =
'projet_task';
1009 if ($feature ==
'eventorganization') {
1010 $feature =
'agenda';
1011 $dbtablename =
'actioncomm';
1013 if ($feature ==
'payment_sc' && empty($parenttableforentity)) {
1015 $parenttableforentity =
'';
1016 $dbtablename =
"chargesociales";
1017 $feature =
"chargesociales";
1018 $objectid = (string)
$object->fk_charge;
1020 if (!$tablegivenbycaller && $feature ==
'workstation') {
1021 $dbtablename =
'workstation_workstation';
1024 $checkonentityready = 0;
1029 $check = array(
'adherent',
'banque',
'bom',
'don',
'mrp',
'user',
'usergroup',
'payment',
'payment_supplier',
'payment_sc',
'payment_vat',
'payment_donation',
'product',
'produit',
'service',
'produit|service',
'categorie',
'resource',
'expensereport',
'holiday',
'salaries',
'website',
'recruitment',
'chargesociales',
'knowledgemanagement',
'stock',
'stockmovement',
'workstation');
1031 $checksoc = array(
'societe');
1033 $checkparentsoc = array(
'agenda',
'contact',
'contrat',
'ticket',
'stocktransfer');
1035 $checkproject = array(
'projet',
'project');
1037 $checktask = array(
'projet_task',
'project_task');
1039 $checkhierarchy = array(
'expensereport',
'holiday',
'hrm');
1041 $checkuser = array(
'bookmark');
1043 $nocheck = array(
'barcode',
'webhook');
1048 if (empty($dbtablename)) {
1049 $dbtablename = $feature;
1050 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
1058 if (!empty($objectid) && in_array($dbtablename, array(
'asset',
'loan',
'localtax',
'paiement',
'paiementfourn',
'pos_cash_fence',
'tva',
'workstation_workstation',
'hrm_job',
'hrm_job_user',
'hrm_skill'))) {
1062 if (!empty($user->socid)) {
1065 if (in_array($dbtablename, array(
'hrm_job',
'hrm_job_user',
'hrm_skill'))) {
1071 $nocheck[] = $feature;
1073 $check[] = $feature;
1079 if ($dbt_select !=
'rowid' && $dbt_select !=
'id') {
1080 $objectid =
"'".$objectid.
"'";
1086 if (in_array($feature, $check) && !empty($objectid)) {
1087 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_select).
") as nb";
1088 $sql .=
" FROM ".MAIN_DB_PREFIX.$db->sanitize($dbtablename).
" as dbt";
1089 if (($feature ==
'user' || $feature ==
'usergroup') &&
isModEnabled(
'multicompany')) {
1091 if (
$conf->entity == 1 && $user->admin && !$user->entity) {
1092 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1093 $sql .=
" AND dbt.entity IS NOT NULL";
1095 $sql .=
",".MAIN_DB_PREFIX.
"usergroup_user as ug";
1096 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1097 $sql .=
" AND ((ug.fk_user = dbt.rowid";
1098 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
1099 $sql .=
" OR dbt.entity = 0)";
1102 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1103 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1107 if ($parenttableforentity && preg_match(
'/(.*)@(.*)/', $parenttableforentity, $reg)) {
1108 $sql .=
", ".MAIN_DB_PREFIX.$db->sanitize($reg[2]).
" as dbtp";
1109 $sql .=
" WHERE dbt.".$db->sanitize($reg[1]).
" = dbtp.rowid AND dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1110 $sql .=
" AND dbtp.entity IN (".getEntity($sharedelement, 1).
")";
1112 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1113 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1116 $checkonentityready = 1;
1120 if (in_array($feature, $checksoc) && !empty($objectid)) {
1122 if ($user->socid > 0) {
1123 if ((
string) $user->socid != $objectid) {
1126 } elseif (
isModEnabled(
'societe') && !$user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir')) {
1127 dol_syslog(
"security.lib.php::checkUserAccessToObject Deny access due: (isModEnabled('societe') && !user->hasRight('societe', 'lire') && !user->hasRight('societe', 'client', 'voir'))", LOG_DEBUG);
1129 } elseif (
isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir'))) {
1131 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
1132 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
1133 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s)";
1134 $sql .=
" WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).
")";
1135 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
1137 $userschilds = $user->getAllChildIds();
1138 if (!empty($userschilds)) {
1139 $sql .=
" OR sc.fk_user IN (".$db->sanitize(implode(
',', $userschilds)).
")";
1143 $sql .=
" AND sc.fk_soc = s.rowid";
1144 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
1147 $sql =
"SELECT COUNT(s.rowid) as nb";
1148 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
1149 $sql .=
" WHERE s.rowid IN (".$db->sanitize($objectid, 1).
")";
1150 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
1153 $checkonentityready = 1;
1156 if (in_array($feature, $checkparentsoc) && !empty($objectid)) {
1157 if ($user->socid > 0) {
1159 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_select).
") as nb";
1160 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1161 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1162 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1163 $sql .=
" AND dbt.fk_soc = ".((int) $user->socid);
1164 } elseif (
isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && !$user->hasRight(
'societe',
'client',
'voir'))) {
1166 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_select).
") as nb";
1167 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1168 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1169 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1170 $sql .=
" AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)";
1171 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1174 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_select).
") as nb";
1175 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1176 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1177 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1180 $checkonentityready = 1;
1183 if (in_array($feature, $checkproject) && !empty($objectid)) {
1184 if (
isModEnabled(
'project') && !$user->hasRight(
'projet',
'all',
'lire')) {
1185 $projectid = $objectid;
1187 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1188 $projectstatic =
new Project($db);
1189 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1191 $tmparray = explode(
',', $tmps);
1192 if (!in_array($projectid, $tmparray)) {
1196 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_select).
") as nb";
1197 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1198 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1199 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1201 $checkonentityready = 1;
1204 if (in_array($feature, $checktask) && !empty($objectid)) {
1205 if (
isModEnabled(
'project') && !$user->hasRight(
'projet',
'all',
'lire')) {
1206 if (preg_match(
'/,/', $objectid)) {
1209 $task =
new Task($db);
1210 $task->fetch((
int) $objectid);
1211 $projectid = $task->fk_project;
1213 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1214 $projectstatic =
new Project($db);
1215 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1217 $tmparray = explode(
',', $tmps);
1218 if (!in_array($projectid, $tmparray)) {
1222 $sharedelement =
'project';
1223 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_select).
") as nb";
1224 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1225 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1226 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1229 $checkonentityready = 1;
1233 if (!$checkonentityready && !in_array($feature, $nocheck) && !empty($objectid)) {
1235 if ($user->socid > 0) {
1236 if (empty($dbt_keyfield)) {
1237 dol_print_error(
null,
'Param dbt_keyfield is required but not defined');
1239 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_keyfield).
") as nb";
1240 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1241 $sql .=
" WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).
")";
1242 $sql .=
" AND dbt.".$db->sanitize($dbt_keyfield).
" = ".((int) $user->socid);
1243 } elseif (
isModEnabled(
"societe") && !$user->hasRight(
'societe',
'client',
'voir')) {
1245 if (empty($dbt_keyfield)) {
1246 dol_print_error(
null,
'Param dbt_keyfield is required but not defined');
1248 if ($feature !=
'ticket') {
1249 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
1250 $sql .=
" FROM ".MAIN_DB_PREFIX.$db->sanitize($dbtablename).
" as dbt";
1251 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
1252 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1253 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1254 $sql .=
" AND sc.fk_soc = dbt.".$db->sanitize($dbt_keyfield);
1255 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
1257 $userschilds = $user->getAllChildIds();
1258 if (!empty($userschilds)) {
1259 $sql .=
" OR sc.fk_user IN (".$db->sanitize(implode(
',', $userschilds)).
")";
1265 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_select).
") as nb";
1266 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1267 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = dbt.".$db->sanitize($dbt_keyfield).
" AND sc.fk_user = ".((int) $user->id);
1268 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1269 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1270 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
" OR dbt.".$dbt_keyfield.
" IS NULL OR dbt.".$dbt_keyfield.
" = 0)";
1272 } elseif (
isModEnabled(
'multicompany') && (!empty(
$object->ismultientitymanaged) || !isset(
$object->ismultientitymanaged))) {
1274 $sql =
"SELECT COUNT(dbt.".$db->sanitize($dbt_select).
") as nb";
1275 $sql .=
" FROM ".MAIN_DB_PREFIX.$db->sanitize($dbtablename).
" as dbt";
1276 $sql .=
" WHERE dbt.".$db->sanitize($dbt_select).
" IN (".$db->sanitize($objectid, 1).
")";
1277 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1282 if ($feature ===
'agenda' && !empty($objectid)) {
1284 if (!$user->hasRight(
'agenda',
'allactions',
'read')) {
1285 if (preg_match(
'/,/', $objectid)) {
1289 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1291 $action->fetch((
int) $objectid);
1292 if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
1300 if (in_array($feature, $checkhierarchy) && is_object(
$object) && !empty($objectid)) {
1301 $childids = $user->getAllChildIds(1);
1303 if ($feature ==
'holiday') {
1304 $useridtocheck =
$object->fk_user;
1305 if (!$user->hasRight(
'holiday',
'readall') && !in_array($useridtocheck, $childids) && !in_array(
$object->fk_validator, $childids)) {
1309 if ($feature ==
'expensereport') {
1310 $useridtocheck =
$object->fk_user_author;
1311 if (!$user->hasRight(
'expensereport',
'readall')) {
1312 if (!in_array($useridtocheck, $childids) && !($user->hasRight(
'expensereport',
'approve') &&
$object->fk_user_validator == $user->id)) {
1317 if ($feature ==
'hrm' && in_array(
'evaluation', $feature2)) {
1318 $useridtocheck =
$object->fk_user;
1320 if ($user->hasRight(
'hrm',
'evaluation',
'readall')) {
1324 if (!$user->hasRight(
'hrm',
'evaluation',
'read')) {
1329 return in_array($useridtocheck, $childids);
1335 if (in_array($feature, $checkuser) && is_object(
$object) && !empty($objectid)) {
1336 $useridtocheck =
$object->fk_user;
1337 if (!empty($useridtocheck) && $useridtocheck > 0 && $useridtocheck != $user->id && empty($user->admin)) {
1343 if ($feature ==
'contact' && in_array($dbtablename, array(
'socpeople',
'contact')) && !empty($objectid)) {
1344 $sqlpriv =
"SELECT COUNT(dbt.rowid) as nb";
1345 $sqlpriv .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as dbt";
1346 $sqlpriv .=
" WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).
")";
1347 $sqlpriv .=
" AND dbt.priv = 1 AND (dbt.fk_user_creat IS NULL OR dbt.fk_user_creat <> ".((int) $user->id).
")";
1348 $resqlpriv = $db->query($sqlpriv);
1352 $objpriv = $db->fetch_object($resqlpriv);
1353 if ($objpriv && $objpriv->nb > 0) {
1359 $resql = $db->query($sql);
1361 $obj = $db->fetch_object($resql);
1362 if (!$obj || $obj->nb < count(explode(
',', $objectid))) {
1366 dol_syslog(
"Bad forged sql in security.lib.php::checkUserAccessToObject", LOG_WARNING);
1372 dol_syslog(
"security.lib.php::checkUserAccessToObject::return True", LOG_DEBUG);
1393 $sharedelement =
$object->element;
1402 case 'supplier_proposal':
1406 case 'order_supplier':
1407 case 'invoice_supplier':
1418 $feature =
'agenda';
1421 $feature =
'projet';
1423 case 'project_task':
1424 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1425 $feature =
'project_task';
1428 $feature =
'adherent';
1433 case 'chargesociales':
1434 $feature =
'chargesociales';
1435 $sharedelement =
'tax';
1437 case 'bank_account':
1438 $feature =
'banque';
1441 $feature =
'categorie';
1444 $feature =
'resource';
1446 case 'knowledgerecord':
1447 $feature =
'knowledgemanagement';
1449 case 'expensereport':
1455 foreach ($ids as
$id) {
1456 if ((
int)
$id > 0) {
1457 $sanitizedids[] = (int)
$id;
1460 if (empty($sanitizedids)) {
1463 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"expensereport as t";
1464 $sql .=
" WHERE t.rowid IN (".$db->sanitize(implode(
',', $sanitizedids)).
")";
1465 $sql .=
" AND (t.entity NOT IN (".getEntity(
'expensereport', 1).
")";
1466 if (!$user->hasRight(
'expensereport',
'readall')) {
1467 $sql .=
" OR t.fk_user_author NOT IN (".$db->sanitize(implode(
',', $user->getAllChildIds(1))).
")";
1470 $resql = $db->query($sql);
1472 dol_syslog(__FUNCTION__.
" ".$db->lasterror(), LOG_ERR);
1473 return $sanitizedids;
1476 while ($obj = $db->fetch_object($resql)) {
1477 $refusedids[] = (int) $obj->rowid;
1486 foreach ($ids as
$id) {
1487 if ((
int)
$id > 0) {
1488 $sanitizedids[] = (int)
$id;
1491 if (empty($sanitizedids)) {
1494 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"holiday as t";
1495 $sql .=
" WHERE t.rowid IN (".$db->sanitize(implode(
',', $sanitizedids)).
")";
1496 $sql .=
" AND (t.entity NOT IN (".getEntity(
'holiday', 1).
")";
1497 if (!$user->hasRight(
'holiday',
'readall')) {
1498 $sql .=
" OR (t.fk_user NOT IN (".$db->sanitize(implode(
',', $user->getAllChildIds(1))).
")";
1499 if ($user->hasRight(
'holiday',
'approve') && !
getDolGlobalString(
'HOLIDAY_CAN_APPROVE_ONLY_THE_SUBORDINATES')) {
1500 $sql .=
" AND t.fk_validator <> ".((int) $user->id);
1505 $resql = $db->query($sql);
1507 dol_syslog(__FUNCTION__.
" ".$db->lasterror(), LOG_ERR);
1508 return $sanitizedids;
1511 while ($obj = $db->fetch_object($resql)) {
1512 $refusedids[] = (int) $obj->rowid;
1521 foreach ($ids as
$id) {
1522 if ((
int)
$id > 0) {
1523 $sanitizedids[] = (int)
$id;
1526 if (empty($sanitizedids)) {
1529 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"salary as t";
1530 $sql .=
" WHERE t.rowid IN (".$db->sanitize(implode(
',', $sanitizedids)).
")";
1531 $sql .=
" AND (t.entity NOT IN (".getEntity(
'salary', 1).
")";
1532 if (!$user->hasRight(
'salaries',
'readall')) {
1533 if ($user->hasRight(
'salaries',
'read') && $user->hasRight(
'salaries',
'readchild')) {
1534 $sql .=
" OR t.fk_user IS NULL OR t.fk_user NOT IN (".$db->sanitize(implode(
',', $user->getAllChildIds(1))).
")";
1535 } elseif ($user->hasRight(
'salaries',
'read')) {
1536 $sql .=
" OR t.fk_user IS NULL OR t.fk_user <> ".((int) $user->id);
1538 $sql .=
" OR 1 = 1";
1542 $resql = $db->query($sql);
1544 dol_syslog(__FUNCTION__.
" ".$db->lasterror(), LOG_ERR);
1545 return $sanitizedids;
1548 while ($obj = $db->fetch_object($resql)) {
1549 $refusedids[] = (int) $obj->rowid;
1554 if (empty($feature)) {
1557 if (empty(
$object->table_element) || empty(
$object->ismultientitymanaged)) {
1562 foreach ($ids as
$id) {
1563 if ((
int)
$id > 0) {
1564 $sanitizedids[] = (int)
$id;
1567 if (empty($sanitizedids)) {
1570 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.$db->sanitize(
$object->table_element).
" as t";
1571 if (is_numeric(
$object->ismultientitymanaged)) {
1572 $sql .=
" WHERE t.entity NOT IN (".getEntity(
$object->element, 1).
")";
1575 $tmparray = explode(
'@',
$object->ismultientitymanaged);
1576 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.$db->sanitize($tmparray[1]).
" as tp ON t.".$db->sanitize($tmparray[0]).
" = tp.rowid";
1577 $sql .=
" WHERE (tp.rowid IS NULL OR tp.entity NOT IN (".getEntity(
$object->element, 1).
"))";
1579 $sql .=
" AND t.rowid IN (".$db->sanitize(implode(
',', $sanitizedids)).
")";
1580 $resql = $db->query($sql);
1582 dol_syslog(__FUNCTION__.
" ".$db->lasterror(), LOG_ERR);
1583 return $sanitizedids;
1586 while ($obj = $db->fetch_object($resql)) {
1587 $refusedids[] = (int) $obj->rowid;
1594 foreach ($ids as
$id) {
1600 $refusedids[] =
$id;