40 if (is_numeric($key) && $key ==
'1') {
41 $output_tab = array();
43 for ($i = 0; $i < $strlength; $i++) {
44 $output_tab[$i] = chr(ord(substr($chain, $i, 1)) + 17);
46 $chain = implode(
"", $output_tab);
50 for ($i = 0; $i < $strlength; $i++) {
51 $keychar = substr($key, ($i % strlen($key)) - 1, 1);
52 $result .= chr(ord(substr($chain, $i, 1)) + (ord($keychar) - 65));
57 return base64_encode($chain);
71 $chain = base64_decode($chain);
73 if (is_numeric($key) && $key ==
'1') {
74 $output_tab = array();
76 for ($i = 0; $i < $strlength; $i++) {
77 $output_tab[$i] = chr(ord(substr($chain, $i, 1)) - 17);
80 $chain = implode(
"", $output_tab);
84 for ($i = 0; $i < $strlength; $i++) {
85 $keychar = substr($key, ($i % strlen($key)) - 1, 1);
86 $result .= chr(ord(substr($chain, $i, 1)) - (ord($keychar) - 65));
102 if (function_exists(
'random_bytes')) {
103 return bin2hex(random_bytes((
int) floor($length / 2)));
106 return bin2hex(openssl_random_pseudo_bytes((
int) floor($length / 2)));
120 function dolEncrypt($chain, $key =
'', $ciphering =
'AES-256-CTR', $forceseed =
'')
122 global $dolibarr_main_instance_unique_id;
123 global $dolibarr_disable_dolcrypt_for_debug;
125 if ($chain ===
'' || is_null($chain)) {
130 if (preg_match(
'/^dolcrypt:([^:]+):(.+)$/', $chain, $reg)) {
136 $key = $dolibarr_main_instance_unique_id;
138 if (empty($ciphering)) {
139 $ciphering =
'AES-256-CTR';
144 if (function_exists(
'openssl_encrypt') && empty($dolibarr_disable_dolcrypt_for_debug)) {
146 if (function_exists(
'openssl_cipher_iv_length')) {
147 $ivlen = openssl_cipher_iv_length($ciphering);
149 if ($ivlen ===
false || $ivlen < 1 || $ivlen > 32) {
152 if (empty($forceseed)) {
155 $ivseed =
dol_substr(md5($forceseed), 0, $ivlen,
'ascii', 1);
158 $newchain = openssl_encrypt($chain, $ciphering, $key, 0, $ivseed);
159 return 'dolcrypt:'.$ciphering.
':'.$ivseed.
':'.$newchain;
176 global $dolibarr_main_instance_unique_id;
178 if ($chain ===
'' || is_null($chain)) {
183 $key = $dolibarr_main_instance_unique_id;
187 if (preg_match(
'/^dolcrypt:([^:]+):(.+)$/', $chain, $reg)) {
188 $ciphering = $reg[1];
189 if (function_exists(
'openssl_decrypt')) {
190 $tmpexplode = explode(
':', $reg[2]);
191 if (!empty($tmpexplode[1]) && is_string($tmpexplode[0])) {
192 $newchain = openssl_decrypt($tmpexplode[1], $ciphering, $key, 0, $tmpexplode[0]);
194 $newchain = openssl_decrypt($tmpexplode[0], $ciphering, $key, 0,
null);
197 $newchain =
'Error function openssl_decrypt() not available';
220 if (($type ==
'0' || $type ==
'auto') && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO ==
'password_hash' && function_exists(
'password_hash')) {
221 return password_hash($chain, PASSWORD_DEFAULT);
225 if (!empty($conf->global->MAIN_SECURITY_SALT) && $type !=
'4' && $type !==
'openldap') {
226 $chain = $conf->global->MAIN_SECURITY_SALT.$chain;
229 if ($type ==
'1' || $type ==
'sha1') {
231 } elseif ($type ==
'2' || $type ==
'sha1md5') {
232 return sha1(md5($chain));
233 } elseif ($type ==
'3' || $type ==
'md5') {
235 } elseif ($type ==
'4' || $type ==
'openldap') {
237 } elseif ($type ==
'5' || $type ==
'sha256') {
238 return hash(
'sha256', $chain);
239 } elseif ($type ==
'6' || $type ==
'password_hash') {
240 return password_hash($chain, PASSWORD_DEFAULT);
241 } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO ==
'sha1') {
243 } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO ==
'sha1md5') {
244 return sha1(md5($chain));
267 if ($type ==
'0' && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO ==
'password_hash' && function_exists(
'password_verify')) {
268 if (! empty($hash[0]) && $hash[0] ==
'$') {
269 return password_verify($chain, $hash);
279 return dol_hash($chain, $type) == $hash;
295 $salt = substr(sha1(time()), 0, 8);
297 if ($type ===
'md5') {
298 return '{MD5}' . base64_encode(hash(
"md5", $password,
true));
299 } elseif ($type ===
'md5frommd5') {
300 return '{MD5}' . base64_encode(hex2bin($password));
301 } elseif ($type ===
'smd5') {
302 return "{SMD5}" . base64_encode(hash(
"md5", $password . $salt,
true) . $salt);
303 } elseif ($type ===
'sha') {
304 return '{SHA}' . base64_encode(hash(
"sha1", $password,
true));
305 } elseif ($type ===
'ssha') {
306 return "{SSHA}" . base64_encode(hash(
"sha1", $password . $salt,
true) . $salt);
307 } elseif ($type ===
'sha256') {
308 return "{SHA256}" . base64_encode(hash(
"sha256", $password,
true));
309 } elseif ($type ===
'ssha256') {
310 return "{SSHA256}" . base64_encode(hash(
"sha256", $password . $salt,
true) . $salt);
311 } elseif ($type ===
'sha384') {
312 return "{SHA384}" . base64_encode(hash(
"sha384", $password,
true));
313 } elseif ($type ===
'ssha384') {
314 return "{SSHA384}" . base64_encode(hash(
"sha384", $password . $salt,
true) . $salt);
315 } elseif ($type ===
'sha512') {
316 return "{SHA512}" . base64_encode(hash(
"sha512", $password,
true));
317 } elseif ($type ===
'ssha512') {
318 return "{SSHA512}" . base64_encode(hash(
"sha512", $password . $salt,
true) . $salt);
319 } elseif ($type ===
'crypt') {
320 return '{CRYPT}' . crypt($password, $salt);
321 } elseif ($type ===
'clear') {
322 return '{CLEAR}' . $password;
346 function restrictedArea(
User $user, $features, $object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'fk_soc', $dbt_select =
'rowid', $isdraft = 0, $mode = 0)
351 if (is_object($object)) {
352 $objectid = $object->id;
356 if ($objectid ==
"-1") {
360 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', $objectid);
368 $parentfortableentity =
'';
371 $originalfeatures = $features;
372 if ($features ==
'facturerec') {
373 $features =
'facture';
375 if ($features ==
'mo') {
378 if ($features ==
'member') {
379 $features =
'adherent';
381 if ($features ==
'subscription') {
382 $features =
'adherent';
383 $feature2 =
'cotisation';
385 if ($features ==
'websitepage') {
386 $features =
'website';
387 $tableandshare =
'website_page';
388 $parentfortableentity =
'fk_website@website';
390 if ($features ==
'project') {
391 $features =
'projet';
393 if ($features ==
'product') {
394 $features =
'produit';
398 $parameters = array(
'features'=>$features,
'originalfeatures'=>$originalfeatures,
'objectid'=>$objectid,
'dbt_select'=>$dbt_select,
'idtype'=>$dbt_select,
'isdraft'=>$isdraft);
399 $reshook = $hookmanager->executeHooks(
'restrictedArea', $parameters);
401 if (isset($hookmanager->resArray[
'result'])) {
402 if ($hookmanager->resArray[
'result'] == 0) {
415 $featuresarray = array($features);
416 if (preg_match(
'/&/', $features)) {
417 $featuresarray = explode(
"&", $features);
418 } elseif (preg_match(
'/\|/', $features)) {
419 $featuresarray = explode(
"|", $features);
423 if (!empty($feature2)) {
424 $feature2 = explode(
"|", $feature2);
427 $listofmodules = explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
432 foreach ($featuresarray as $feature) {
433 $featureforlistofmodule = $feature;
434 if ($featureforlistofmodule ==
'produit') {
435 $featureforlistofmodule =
'product';
437 if ($featureforlistofmodule ==
'supplier_proposal') {
438 $featureforlistofmodule =
'supplierproposal';
440 if (!empty($user->socid) && !empty($conf->global->MAIN_MODULES_FOR_EXTERNAL) && !in_array($featureforlistofmodule, $listofmodules)) {
446 if ($feature ==
'societe') {
447 if (!$user->hasRight(
'societe',
'lire') && !$user->hasRight(
'fournisseur',
'lire')) {
451 } elseif ($feature ==
'contact') {
452 if (empty($user->rights->societe->contact->lire)) {
456 } elseif ($feature ==
'produit|service') {
457 if (empty($user->rights->produit->lire) && empty($user->rights->service->lire)) {
461 } elseif ($feature ==
'prelevement') {
462 if (empty($user->rights->prelevement->bons->lire)) {
466 } elseif ($feature ==
'cheque') {
467 if (empty($user->rights->banque->cheque)) {
471 } elseif ($feature ==
'projet') {
472 if (empty($user->rights->projet->lire) && empty($user->rights->projet->all->lire)) {
476 } elseif ($feature ==
'payment') {
477 if (empty($user->rights->facture->lire)) {
481 } elseif ($feature ==
'payment_supplier') {
482 if (empty($user->rights->fournisseur->facture->lire)) {
486 } elseif ($feature ==
'payment_sc') {
487 if (empty($user->rights->tax->charges->lire)) {
491 } elseif (!empty($feature2)) {
493 foreach ($feature2 as $subfeature) {
494 if ($subfeature ==
'user' && $user->id == $objectid) {
497 if (!empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) {
499 } elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) {
510 } elseif (!empty($feature) && ($feature !=
'user' && $feature !=
'usergroup')) {
511 if (empty($user->rights->$feature->lire)
512 && empty($user->rights->$feature->read)
513 && empty($user->rights->$feature->run)) {
521 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
537 $wemustcheckpermissionforcreate = (
GETPOST(
'sendit',
'alpha') ||
GETPOST(
'linkit',
'alpha') || in_array(
GETPOST(
'action',
'aZ09'), array(
'create',
'update',
'add_element_resource',
'confirm_deletebank',
'confirm_delete_linked_resource')) ||
GETPOST(
'roworder',
'alpha', 2));
538 $wemustcheckpermissionfordeletedraft = ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete');
540 if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
541 foreach ($featuresarray as $feature) {
542 if ($feature ==
'contact') {
543 if (empty($user->rights->societe->contact->creer)) {
547 } elseif ($feature ==
'produit|service') {
548 if (empty($user->rights->produit->creer) && empty($user->rights->service->creer)) {
552 } elseif ($feature ==
'prelevement') {
553 if (!$user->rights->prelevement->bons->creer) {
557 } elseif ($feature ==
'commande_fournisseur') {
558 if (empty($user->rights->fournisseur->commande->creer) || empty($user->rights->supplier_order->creer)) {
562 } elseif ($feature ==
'banque') {
563 if (empty($user->rights->banque->modifier)) {
567 } elseif ($feature ==
'cheque') {
568 if (empty($user->rights->banque->cheque)) {
572 } elseif ($feature ==
'import') {
573 if (empty($user->rights->import->run)) {
577 } elseif ($feature ==
'ecm') {
578 if (!$user->rights->ecm->upload) {
582 } elseif (!empty($feature2)) {
583 foreach ($feature2 as $subfeature) {
584 if ($subfeature ==
'user' && $user->id == $objectid && $user->rights->user->self->creer) {
587 if ($subfeature ==
'user' && $user->id == $objectid && $user->rights->user->self->password) {
590 if ($subfeature ==
'user' && $user->id != $objectid && $user->rights->user->user->password) {
594 if (empty($user->rights->$feature->$subfeature->creer)
595 && empty($user->rights->$feature->$subfeature->write)
596 && empty($user->rights->$feature->$subfeature->create)) {
605 } elseif (!empty($feature)) {
607 if (empty($user->rights->$feature->creer)
608 && empty($user->rights->$feature->write)
609 && empty($user->rights->$feature->create)) {
617 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
621 if ($wemustcheckpermissionforcreate && !$createok) {
633 if (
GETPOST(
'action',
'aZ09') ==
'confirm_create_user' &&
GETPOST(
"confirm",
'aZ09') ==
'yes') {
634 if (!$user->rights->user->user->creer) {
638 if (!$createuserok) {
651 if ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete') {
652 foreach ($featuresarray as $feature) {
653 if ($feature ==
'bookmark') {
654 if (!$user->rights->bookmark->supprimer) {
655 if ($user->id != $object->fk_user || empty($user->rights->bookmark->creer)) {
659 } elseif ($feature ==
'contact') {
660 if (!$user->rights->societe->contact->supprimer) {
663 } elseif ($feature ==
'produit|service') {
664 if (!$user->rights->produit->supprimer && !$user->rights->service->supprimer) {
667 } elseif ($feature ==
'commande_fournisseur') {
668 if (!$user->rights->fournisseur->commande->supprimer) {
671 } elseif ($feature ==
'payment_supplier') {
672 if (!$user->rights->fournisseur->facture->creer) {
675 } elseif ($feature ==
'payment') {
676 if (!$user->rights->facture->paiement) {
679 } elseif ($feature ==
'payment_sc') {
680 if (!$user->rights->tax->charges->creer) {
683 } elseif ($feature ==
'banque') {
684 if (empty($user->rights->banque->modifier)) {
687 } elseif ($feature ==
'cheque') {
688 if (empty($user->rights->banque->cheque)) {
691 } elseif ($feature ==
'ecm') {
692 if (!$user->rights->ecm->upload) {
695 } elseif ($feature ==
'ftp') {
696 if (!$user->rights->ftp->write) {
699 } elseif ($feature ==
'salaries') {
700 if (!$user->rights->salaries->delete) {
703 } elseif ($feature ==
'adherent') {
704 if (empty($user->rights->adherent->supprimer)) {
707 } elseif ($feature ==
'paymentbybanktransfer') {
708 if (empty($user->rights->paymentbybanktransfer->create)) {
711 } elseif ($feature ==
'prelevement') {
712 if (empty($user->rights->prelevement->bons->creer)) {
715 } elseif (!empty($feature2)) {
716 foreach ($feature2 as $subfeature) {
717 if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) {
724 } elseif (!empty($feature)) {
726 if (empty($user->rights->$feature->supprimer)
727 && empty($user->rights->$feature->delete)
728 && empty($user->rights->$feature->run)) {
735 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
739 if (!$deleteok && !($isdraft && $createok)) {
751 if (!empty($objectid) && $objectid > 0) {
752 $ok =
checkUserAccessToObject($user, $featuresarray, $object, $tableandshare, $feature2, $dbt_keyfield, $dbt_select, $parentfortableentity);
753 $params = array(
'objectid' => $objectid,
'features' => join(
',', $featuresarray),
'features2' => $feature2);
784 function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'', $dbt_select =
'rowid', $parenttableforentity =
'')
788 if (is_object($object)) {
789 $objectid = $object->id;
793 $objectid = preg_replace(
'/[^0-9\.\,]/',
'', $objectid);
800 $params = explode(
'&', $tableandshare);
801 $dbtablename = (!empty($params[0]) ? $params[0] :
'');
802 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
804 foreach ($featuresarray as $feature) {
810 if ($feature ==
'member') {
811 $feature =
'adherent';
813 if ($feature ==
'project') {
816 if ($feature ==
'task') {
817 $feature =
'projet_task';
820 if ($feature ==
'payment_sc') {
821 $feature =
"chargesociales";
823 $checkonentitydone = 0;
826 $check = array(
'adherent',
'banque',
'bom',
'don',
'mrp',
'user',
'usergroup',
'payment',
'payment_supplier',
'product',
'produit',
'service',
'produit|service',
'categorie',
'resource',
'expensereport',
'holiday',
'salaries',
'website',
'recruitment',
'chargesociales');
827 $checksoc = array(
'societe');
828 $checkother = array(
'contact',
'agenda',
'contrat');
829 $checkproject = array(
'projet',
'project');
830 $checktask = array(
'projet_task');
831 $checkhierarchy = array(
'expensereport',
'holiday');
832 $checkuser = array(
'bookmark');
833 $nocheck = array(
'barcode',
'stock');
838 if (empty($dbtablename)) {
839 $dbtablename = $feature;
840 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
844 if ($dbt_select !=
'rowid' && $dbt_select !=
'id') {
845 $objectid =
"'".$objectid.
"'";
849 if (in_array($feature, $check) && $objectid > 0) {
850 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
851 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
852 if (($feature ==
'user' || $feature ==
'usergroup') &&
isModEnabled(
'multicompany')) {
853 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
854 if ($conf->entity == 1 && $user->admin && !$user->entity) {
855 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
856 $sql .=
" AND dbt.entity IS NOT NULL";
858 $sql .=
",".MAIN_DB_PREFIX.
"usergroup_user as ug";
859 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
860 $sql .=
" AND ((ug.fk_user = dbt.rowid";
861 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
862 $sql .=
" OR dbt.entity = 0)";
865 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
866 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
870 if ($parenttableforentity && preg_match(
'/(.*)@(.*)/', $parenttableforentity, $reg)) {
871 $sql .=
", ".MAIN_DB_PREFIX.$reg[2].
" as dbtp";
872 $sql .=
" WHERE dbt.".$reg[1].
" = dbtp.rowid AND dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
873 $sql .=
" AND dbtp.entity IN (".getEntity($sharedelement, 1).
")";
875 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
876 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
879 $checkonentitydone = 1;
881 if (in_array($feature, $checksoc) && $objectid > 0) {
883 if ($user->socid > 0) {
884 if ($user->socid != $objectid) {
887 } elseif (
isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && empty($user->rights->societe->client->voir))) {
889 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
890 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
891 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s)";
892 $sql .=
" WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).
")";
893 $sql .=
" AND sc.fk_user = ".((int) $user->id);
894 $sql .=
" AND sc.fk_soc = s.rowid";
895 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
898 $sql =
"SELECT COUNT(s.rowid) as nb";
899 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
900 $sql .=
" WHERE s.rowid IN (".$db->sanitize($objectid, 1).
")";
901 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
904 $checkonentitydone = 1;
906 if (in_array($feature, $checkother) && $objectid > 0) {
908 if ($user->socid > 0) {
909 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
910 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
911 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
912 $sql .=
" AND dbt.fk_soc = ".((int) $user->socid);
913 } elseif (
isModEnabled(
"societe") && ($user->hasRight(
'societe',
'lire') && empty($user->rights->societe->client->voir))) {
915 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
916 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
917 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
918 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
919 $sql .=
" AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)";
920 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
923 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
924 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
925 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
926 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
929 $checkonentitydone = 1;
931 if (in_array($feature, $checkproject) && $objectid > 0) {
932 if (
isModEnabled(
'project') && empty($user->rights->projet->all->lire)) {
933 $projectid = $objectid;
935 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
936 $projectstatic =
new Project($db);
937 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
939 $tmparray = explode(
',', $tmps);
940 if (!in_array($projectid, $tmparray)) {
944 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
945 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
946 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
947 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
950 $checkonentitydone = 1;
952 if (in_array($feature, $checktask) && $objectid > 0) {
953 if (
isModEnabled(
'project') && empty($user->rights->projet->all->lire)) {
954 $task =
new Task($db);
955 $task->fetch($objectid);
956 $projectid = $task->fk_project;
958 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
959 $projectstatic =
new Project($db);
960 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
962 $tmparray = explode(
',', $tmps);
963 if (!in_array($projectid, $tmparray)) {
967 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
968 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
969 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
970 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
973 $checkonentitydone = 1;
975 if (!$checkonentitydone && !in_array($feature, $nocheck) && $objectid > 0) {
977 if ($user->socid > 0) {
978 if (empty($dbt_keyfield)) {
981 $sql =
"SELECT COUNT(dbt.".$dbt_keyfield.
") as nb";
982 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
983 $sql .=
" WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).
")";
984 $sql .=
" AND dbt.".$dbt_keyfield.
" = ".((int) $user->socid);
985 } elseif (
isModEnabled(
"societe") && empty($user->rights->societe->client->voir)) {
987 if ($feature !=
'ticket') {
988 if (empty($dbt_keyfield)) {
991 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
992 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
993 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
994 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
995 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
996 $sql .=
" AND sc.fk_soc = dbt.".$dbt_keyfield;
997 $sql .=
" AND sc.fk_user = ".((int) $user->id);
1000 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1001 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1002 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = dbt.".$dbt_keyfield.
" AND sc.fk_user = ".((int) $user->id);
1003 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1004 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1005 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
" OR sc.fk_user IS NULL)";
1009 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
1010 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
1011 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
1012 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
1018 if ($feature ===
'agenda' && $objectid > 0) {
1020 if ($objectid > 0 && empty($user->rights->agenda->allactions->read)) {
1021 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1023 $action->fetch($objectid);
1024 if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
1032 if (in_array($feature, $checkhierarchy) && is_object($object) && $objectid > 0) {
1033 $childids = $user->getAllChildIds(1);
1035 if ($feature ==
'holiday') {
1036 $useridtocheck = $object->fk_user;
1037 if (!in_array($useridtocheck, $childids)) {
1040 $useridtocheck = $object->fk_validator;
1041 if (!in_array($useridtocheck, $childids)) {
1045 if ($feature ==
'expensereport') {
1046 $useridtocheck = $object->fk_user_author;
1047 if (!$user->rights->expensereport->readall) {
1048 if (!in_array($useridtocheck, $childids)) {
1057 if (in_array($feature, $checkuser) && is_object($object) && $objectid > 0) {
1058 $useridtocheck = $object->fk_user;
1059 if (!empty($useridtocheck) && $useridtocheck > 0 && $useridtocheck != $user->id && empty($user->admin)) {
1065 $resql = $db->query($sql);
1067 $obj = $db->fetch_object(
$resql);
1068 if (!$obj || $obj->nb < count(explode(
',', $objectid))) {
1072 dol_syslog(
"Bad forged sql in checkUserAccessToObject", LOG_WARNING);
1096 http_response_code($http_response_code);
1098 if ($stringalreadysanitized) {
1101 print htmlentities($message);
1120 function accessforbidden($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params =
null)
1122 global $conf, $db, $user, $langs, $hookmanager;
1124 if (!is_object($langs)) {
1125 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
1127 $langs->setDefaultLang();
1130 $langs->load(
"errors");
1133 if (function_exists(
"llxHeader")) {
1135 } elseif (function_exists(
"llxHeaderVierge")) {
1139 print
'<div class="error">';
1140 if (empty($message)) {
1141 print $langs->trans(
"ErrorForbidden");
1143 print $langs->trans($message);
1147 if (empty($showonlymessage)) {
1148 global $action, $object;
1149 if (empty($hookmanager)) {
1152 $hookmanager->initHooks(array(
'main'));
1154 $parameters = array(
'message'=>$message,
'params'=>$params);
1155 $reshook = $hookmanager->executeHooks(
'getAccessForbiddenMessage', $parameters, $object, $action);
1156 print $hookmanager->resPrint;
1157 if (empty($reshook)) {
1158 $langs->loadLangs(array(
"errors"));
1160 print $langs->trans(
"CurrentLogin").
': <span class="error">'.$user->login.
'</span><br>';
1161 print $langs->trans(
"ErrorForbidden2", $langs->transnoentitiesnoconv(
"Home"), $langs->transnoentitiesnoconv(
"Users"));
1162 print $langs->trans(
"ErrorForbidden4");
1164 print $langs->trans(
"ErrorForbidden3");
1168 if ($printfooter && function_exists(
"llxFooter")) {
1186 $max = $conf->global->MAIN_UPLOAD_DOC;
1187 $maxphp = @ini_get(
'upload_max_filesize');
1188 if (preg_match(
'/k$/i', $maxphp)) {
1189 $maxphp = preg_replace(
'/k$/i',
'', $maxphp);
1190 $maxphp = $maxphp * 1;
1192 if (preg_match(
'/m$/i', $maxphp)) {
1193 $maxphp = preg_replace(
'/m$/i',
'', $maxphp);
1194 $maxphp = $maxphp * 1024;
1196 if (preg_match(
'/g$/i', $maxphp)) {
1197 $maxphp = preg_replace(
'/g$/i',
'', $maxphp);
1198 $maxphp = $maxphp * 1024 * 1024;
1200 if (preg_match(
'/t$/i', $maxphp)) {
1201 $maxphp = preg_replace(
'/t$/i',
'', $maxphp);
1202 $maxphp = $maxphp * 1024 * 1024 * 1024;
1204 $maxphp2 = @ini_get(
'post_max_size');
1205 if (preg_match(
'/k$/i', $maxphp2)) {
1206 $maxphp2 = preg_replace(
'/k$/i',
'', $maxphp2);
1207 $maxphp2 = $maxphp2 * 1;
1209 if (preg_match(
'/m$/i', $maxphp2)) {
1210 $maxphp2 = preg_replace(
'/m$/i',
'', $maxphp2);
1211 $maxphp2 = $maxphp2 * 1024;
1213 if (preg_match(
'/g$/i', $maxphp2)) {
1214 $maxphp2 = preg_replace(
'/g$/i',
'', $maxphp2);
1215 $maxphp2 = $maxphp2 * 1024 * 1024;
1217 if (preg_match(
'/t$/i', $maxphp2)) {
1218 $maxphp2 = preg_replace(
'/t$/i',
'', $maxphp2);
1219 $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
1223 $maxphptoshow = $maxphptoshowparam =
'';
1225 $maxmin = min($maxmin, $maxphp);
1226 $maxphptoshow = $maxphp;
1227 $maxphptoshowparam =
'upload_max_filesize';
1230 $maxmin = min($maxmin, $maxphp2);
1231 if ($maxphp2 < $maxphp) {
1232 $maxphptoshow = $maxphp2;
1233 $maxphptoshowparam =
'post_max_size';
1239 return array(
'max'=>$max,
'maxmin'=>$maxmin,
'maxphptoshow'=>$maxphptoshow,
'maxphptoshowparam'=>$maxphptoshowparam);