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));
109 if (($type ==
'0' || $type ==
'auto') && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO ==
'password_hash' && function_exists(
'password_hash')) {
110 return password_hash($chain, PASSWORD_DEFAULT);
114 if (!empty($conf->global->MAIN_SECURITY_SALT) && $type !=
'4' && $type !==
'openldap') {
115 $chain = $conf->global->MAIN_SECURITY_SALT.$chain;
118 if ($type ==
'1' || $type ==
'sha1') {
120 } elseif ($type ==
'2' || $type ==
'sha1md5') {
121 return sha1(md5($chain));
122 } elseif ($type ==
'3' || $type ==
'md5') {
124 } elseif ($type ==
'4' || $type ==
'openldap') {
126 } elseif ($type ==
'5' || $type ==
'sha256') {
127 return hash(
'sha256', $chain);
128 } elseif ($type ==
'6' || $type ==
'password_hash') {
129 return password_hash($chain, PASSWORD_DEFAULT);
130 } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO ==
'sha1') {
132 } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO ==
'sha1md5') {
133 return sha1(md5($chain));
155 if ($type ==
'0' && !empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO ==
'password_hash' && function_exists(
'password_verify')) {
156 if ($hash[0] ==
'$') {
157 return password_verify($chain, $hash);
158 } elseif (strlen($hash) == 32) {
160 } elseif (strlen($hash) == 40) {
167 return dol_hash($chain, $type) == $hash;
183 $salt = substr(sha1(time()), 0, 8);
185 if ($type ===
'md5') {
186 return '{MD5}' . base64_encode(hash(
"md5", $password,
true));
187 } elseif ($type ===
'md5frommd5') {
188 return '{MD5}' . base64_encode(hex2bin($password));
189 } elseif ($type ===
'smd5') {
190 return "{SMD5}" . base64_encode(hash(
"md5", $password . $salt,
true) . $salt);
191 } elseif ($type ===
'sha') {
192 return '{SHA}' . base64_encode(hash(
"sha1", $password,
true));
193 } elseif ($type ===
'ssha') {
194 return "{SSHA}" . base64_encode(hash(
"sha1", $password . $salt,
true) . $salt);
195 } elseif ($type ===
'sha256') {
196 return "{SHA256}" . base64_encode(hash(
"sha256", $password,
true));
197 } elseif ($type ===
'ssha256') {
198 return "{SSHA256}" . base64_encode(hash(
"sha256", $password . $salt,
true) . $salt);
199 } elseif ($type ===
'sha384') {
200 return "{SHA384}" . base64_encode(hash(
"sha384", $password,
true));
201 } elseif ($type ===
'ssha384') {
202 return "{SSHA384}" . base64_encode(hash(
"sha384", $password . $salt,
true) . $salt);
203 } elseif ($type ===
'sha512') {
204 return "{SHA512}" . base64_encode(hash(
"sha512", $password,
true));
205 } elseif ($type ===
'ssha512') {
206 return "{SSHA512}" . base64_encode(hash(
"sha512", $password . $salt,
true) . $salt);
207 } elseif ($type ===
'crypt') {
208 return '{CRYPT}' . crypt($password, $salt);
209 } elseif ($type ===
'clear') {
210 return '{CLEAR}' . $password;
234 function restrictedArea($user, $features, $objectid = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'fk_soc', $dbt_select =
'rowid', $isdraft = 0, $mode = 0)
239 $objectid = ((int) $objectid);
246 $parentfortableentity =
'';
249 $originalfeatures = $features;
250 if ($features ==
'facturerec') {
251 $features =
'facture';
253 if ($features ==
'mo') {
256 if ($features ==
'member') {
257 $features =
'adherent';
259 if ($features ==
'subscription') {
260 $features =
'adherent';
261 $feature2 =
'cotisation';
263 if ($features ==
'websitepage') {
264 $features =
'website';
265 $tableandshare =
'website_page';
266 $parentfortableentity =
'fk_website@website';
268 if ($features ==
'project') {
269 $features =
'projet';
271 if ($features ==
'product') {
272 $features =
'produit';
276 $parameters = array(
'features'=>$features,
'originalfeatures'=>$originalfeatures,
'objectid'=>$objectid,
'dbt_select'=>$dbt_select,
'idtype'=>$dbt_select,
'isdraft'=>$isdraft);
277 $reshook = $hookmanager->executeHooks(
'restrictedArea', $parameters);
279 if (isset($hookmanager->resArray[
'result'])) {
280 if ($hookmanager->resArray[
'result'] == 0) {
293 $featuresarray = array($features);
294 if (preg_match(
'/&/', $features)) {
295 $featuresarray = explode(
"&", $features);
296 } elseif (preg_match(
'/\|/', $features)) {
297 $featuresarray = explode(
"|", $features);
301 if (!empty($feature2)) {
302 $feature2 = explode(
"|", $feature2);
305 $listofmodules = explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
310 foreach ($featuresarray as $feature) {
311 $featureforlistofmodule = $feature;
312 if ($featureforlistofmodule ==
'produit') {
313 $featureforlistofmodule =
'product';
315 if (!empty($user->socid) && !empty($conf->global->MAIN_MODULES_FOR_EXTERNAL) && !in_array($featureforlistofmodule, $listofmodules)) {
321 if ($feature ==
'societe') {
322 if (empty($user->rights->societe->lire) && empty($user->rights->fournisseur->lire)) {
326 } elseif ($feature ==
'contact') {
327 if (empty($user->rights->societe->contact->lire)) {
331 } elseif ($feature ==
'produit|service') {
332 if (!$user->rights->produit->lire && !$user->rights->service->lire) {
336 } elseif ($feature ==
'prelevement') {
337 if (!$user->rights->prelevement->bons->lire) {
341 } elseif ($feature ==
'cheque') {
342 if (empty($user->rights->banque->cheque)) {
346 } elseif ($feature ==
'projet') {
347 if (!$user->rights->projet->lire && empty($user->rights->projet->all->lire)) {
351 } elseif ($feature ==
'payment') {
352 if (!$user->rights->facture->lire) {
356 } elseif ($feature ==
'payment_supplier') {
357 if (empty($user->rights->fournisseur->facture->lire)) {
361 } elseif (!empty($feature2)) {
363 foreach ($feature2 as $subfeature) {
364 if ($subfeature ==
'user' && $user->id == $objectid) {
367 if (!empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) {
369 } elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) {
380 } elseif (!empty($feature) && ($feature !=
'user' && $feature !=
'usergroup')) {
381 if (empty($user->rights->$feature->lire)
382 && empty($user->rights->$feature->read)
383 && empty($user->rights->$feature->run)) {
391 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
407 $wemustcheckpermissionforcreate = (
GETPOST(
'sendit',
'alpha') ||
GETPOST(
'linkit',
'alpha') || in_array(
GETPOST(
'action',
'aZ09'), array(
'create',
'update',
'add_element_resource',
'confirm_delete_linked_resource')) ||
GETPOST(
'roworder',
'alpha', 2));
408 $wemustcheckpermissionfordeletedraft = ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete');
410 if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
411 foreach ($featuresarray as $feature) {
412 if ($feature ==
'contact') {
413 if (empty($user->rights->societe->contact->creer)) {
417 } elseif ($feature ==
'produit|service') {
418 if (empty($user->rights->produit->creer) && empty($user->rights->service->creer)) {
422 } elseif ($feature ==
'prelevement') {
423 if (!$user->rights->prelevement->bons->creer) {
427 } elseif ($feature ==
'commande_fournisseur') {
428 if (empty($user->rights->fournisseur->commande->creer) || empty($user->rights->supplier_order->creer)) {
432 } elseif ($feature ==
'banque') {
433 if (empty($user->rights->banque->modifier)) {
437 } elseif ($feature ==
'cheque') {
438 if (empty($user->rights->banque->cheque)) {
442 } elseif ($feature ==
'import') {
443 if (empty($user->rights->import->run)) {
447 } elseif ($feature ==
'ecm') {
448 if (!$user->rights->ecm->upload) {
452 } elseif (!empty($feature2)) {
453 foreach ($feature2 as $subfeature) {
454 if ($subfeature ==
'user' && $user->id == $objectid && $user->rights->user->self->creer) {
457 if ($subfeature ==
'user' && $user->id == $objectid && $user->rights->user->self->password) {
460 if ($subfeature ==
'user' && $user->id != $objectid && $user->rights->user->user->password) {
464 if (empty($user->rights->$feature->$subfeature->creer)
465 && empty($user->rights->$feature->$subfeature->write)
466 && empty($user->rights->$feature->$subfeature->create)) {
475 } elseif (!empty($feature)) {
477 if (empty($user->rights->$feature->creer)
478 && empty($user->rights->$feature->write)
479 && empty($user->rights->$feature->create)) {
487 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
491 if ($wemustcheckpermissionforcreate && !$createok) {
503 if (
GETPOST(
'action',
'aZ09') ==
'confirm_create_user' &&
GETPOST(
"confirm",
'aZ09') ==
'yes') {
504 if (!$user->rights->user->user->creer) {
508 if (!$createuserok) {
521 if ((
GETPOST(
"action",
"aZ09") ==
'confirm_delete' &&
GETPOST(
"confirm",
"aZ09") ==
'yes') ||
GETPOST(
"action",
"aZ09") ==
'delete') {
522 foreach ($featuresarray as $feature) {
523 if ($feature ==
'contact') {
524 if (!$user->rights->societe->contact->supprimer) {
527 } elseif ($feature ==
'produit|service') {
528 if (!$user->rights->produit->supprimer && !$user->rights->service->supprimer) {
531 } elseif ($feature ==
'commande_fournisseur') {
532 if (!$user->rights->fournisseur->commande->supprimer) {
535 } elseif ($feature ==
'payment_supplier') {
536 if (!$user->rights->fournisseur->facture->creer) {
539 } elseif ($feature ==
'payment') {
540 if (!$user->rights->facture->paiement) {
543 } elseif ($feature ==
'banque') {
544 if (empty($user->rights->banque->modifier)) {
547 } elseif ($feature ==
'cheque') {
548 if (empty($user->rights->banque->cheque)) {
551 } elseif ($feature ==
'ecm') {
552 if (!$user->rights->ecm->upload) {
555 } elseif ($feature ==
'ftp') {
556 if (!$user->rights->ftp->write) {
559 } elseif ($feature ==
'salaries') {
560 if (!$user->rights->salaries->delete) {
563 } elseif ($feature ==
'adherent') {
564 if (empty($user->rights->adherent->supprimer)) {
567 } elseif ($feature ==
'paymentbybanktransfer') {
568 if (empty($user->rights->paymentbybanktransfer->create)) {
571 } elseif ($feature ==
'prelevement') {
572 if (empty($user->rights->prelevement->bons->creer)) {
575 } elseif (!empty($feature2)) {
576 foreach ($feature2 as $subfeature) {
577 if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) {
584 } elseif (!empty($feature)) {
586 if (empty($user->rights->$feature->supprimer)
587 && empty($user->rights->$feature->delete)
588 && empty($user->rights->$feature->run)) {
595 if (preg_match(
'/\|/', $features) && $nbko < count($featuresarray)) {
599 if (!$deleteok && !($isdraft && $createok)) {
611 if (!empty($objectid) && $objectid > 0) {
612 $ok =
checkUserAccessToObject($user, $featuresarray, $objectid, $tableandshare, $feature2, $dbt_keyfield, $dbt_select, $parentfortableentity);
613 $params = array(
'objectid' => $objectid,
'features' => join(
',', $featuresarray),
'features2' => $feature2);
640 function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tableandshare =
'', $feature2 =
'', $dbt_keyfield =
'', $dbt_select =
'rowid', $parenttableforentity =
'')
644 if (is_object($object)) {
645 $objectid = $object->id;
655 $params = explode(
'&', $tableandshare);
656 $dbtablename = (!empty($params[0]) ? $params[0] :
'');
657 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
659 foreach ($featuresarray as $feature) {
665 if ($feature ==
'member') {
666 $feature =
'adherent';
668 if ($feature ==
'project') {
671 if ($feature ==
'task') {
672 $feature =
'projet_task';
675 $checkonentitydone = 0;
678 $check = array(
'adherent',
'banque',
'bom',
'don',
'mrp',
'user',
'usergroup',
'payment',
'payment_supplier',
'product',
'produit',
'service',
'produit|service',
'categorie',
'resource',
'expensereport',
'holiday',
'salaries',
'website',
'recruitment');
679 $checksoc = array(
'societe');
680 $checkother = array(
'contact',
'agenda');
681 $checkproject = array(
'projet',
'project');
682 $checktask = array(
'projet_task');
683 $checkhierarchy = array(
'expensereport',
'holiday');
684 $nocheck = array(
'barcode',
'stock');
688 if (empty($dbtablename)) {
689 $dbtablename = $feature;
690 $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
694 if (in_array($feature, $check)) {
695 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
696 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
697 if (($feature ==
'user' || $feature ==
'usergroup') && !empty($conf->multicompany->enabled)) {
698 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
699 if ($conf->entity == 1 && $user->admin && !$user->entity) {
700 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
701 $sql .=
" AND dbt.entity IS NOT NULL";
703 $sql .=
",".MAIN_DB_PREFIX.
"usergroup_user as ug";
704 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
705 $sql .=
" AND ((ug.fk_user = dbt.rowid";
706 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
707 $sql .=
" OR dbt.entity = 0)";
710 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
711 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
715 if ($parenttableforentity && preg_match(
'/(.*)@(.*)/', $parenttableforentity, $reg)) {
716 $sql .=
", ".MAIN_DB_PREFIX.$reg[2].
" as dbtp";
717 $sql .=
" WHERE dbt.".$reg[1].
" = dbtp.rowid AND dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
718 $sql .=
" AND dbtp.entity IN (".getEntity($sharedelement, 1).
")";
720 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
721 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
724 $checkonentitydone = 1;
726 if (in_array($feature, $checksoc)) {
728 if ($user->socid > 0) {
729 if ($user->socid != $objectid) {
732 } elseif (!empty($conf->societe->enabled) && ($user->rights->societe->lire && empty($user->rights->societe->client->voir))) {
734 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
735 $sql .=
" FROM (".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
736 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s)";
737 $sql .=
" WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).
")";
738 $sql .=
" AND sc.fk_user = ".((int) $user->id);
739 $sql .=
" AND sc.fk_soc = s.rowid";
740 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
741 } elseif (!empty($conf->multicompany->enabled)) {
743 $sql =
"SELECT COUNT(s.rowid) as nb";
744 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
745 $sql .=
" WHERE s.rowid IN (".$db->sanitize($objectid, 1).
")";
746 $sql .=
" AND s.entity IN (".getEntity($sharedelement, 1).
")";
749 $checkonentitydone = 1;
751 if (in_array($feature, $checkother)) {
753 if ($user->socid > 0) {
754 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
755 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
756 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
757 $sql .=
" AND dbt.fk_soc = ".((int) $user->socid);
758 } elseif (!empty($conf->societe->enabled) && ($user->rights->societe->lire && empty($user->rights->societe->client->voir))) {
760 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
761 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
762 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
763 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
764 $sql .=
" AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)";
765 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
766 } elseif (!empty($conf->multicompany->enabled)) {
768 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
769 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
770 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
771 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
774 $checkonentitydone = 1;
776 if (in_array($feature, $checkproject)) {
777 if (!empty($conf->project->enabled) && empty($user->rights->projet->all->lire)) {
778 $projectid = $objectid;
780 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
781 $projectstatic =
new Project($db);
782 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
784 $tmparray = explode(
',', $tmps);
785 if (!in_array($projectid, $tmparray)) {
789 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
790 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
791 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
792 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
795 $checkonentitydone = 1;
797 if (in_array($feature, $checktask)) {
798 if (!empty($conf->project->enabled) && empty($user->rights->projet->all->lire)) {
799 $task =
new Task($db);
800 $task->fetch($objectid);
801 $projectid = $task->fk_project;
803 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
804 $projectstatic =
new Project($db);
805 $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
807 $tmparray = explode(
',', $tmps);
808 if (!in_array($projectid, $tmparray)) {
812 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
813 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
814 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
815 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
818 $checkonentitydone = 1;
820 if (!$checkonentitydone && !in_array($feature, $nocheck)) {
822 if ($user->socid > 0) {
823 if (empty($dbt_keyfield)) {
826 $sql =
"SELECT COUNT(dbt.".$dbt_keyfield.
") as nb";
827 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
828 $sql .=
" WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).
")";
829 $sql .=
" AND dbt.".$dbt_keyfield.
" = ".((int) $user->socid);
830 } elseif (!empty($conf->societe->enabled) && empty($user->rights->societe->client->voir)) {
832 if ($feature !=
'ticket') {
833 if (empty($dbt_keyfield)) {
836 $sql =
"SELECT COUNT(sc.fk_soc) as nb";
837 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
838 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
839 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
840 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
841 $sql .=
" AND sc.fk_soc = dbt.".$dbt_keyfield;
842 $sql .=
" AND sc.fk_user = ".((int) $user->id);
845 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
846 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
847 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON sc.fk_soc = dbt.".$dbt_keyfield.
" AND sc.fk_user = ".((int) $user->id);
848 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
849 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
850 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
" OR sc.fk_user IS NULL)";
852 } elseif (!empty($conf->multicompany->enabled)) {
854 $sql =
"SELECT COUNT(dbt.".$dbt_select.
") as nb";
855 $sql .=
" FROM ".MAIN_DB_PREFIX.$dbtablename.
" as dbt";
856 $sql .=
" WHERE dbt.".$dbt_select.
" IN (".$db->sanitize($objectid, 1).
")";
857 $sql .=
" AND dbt.entity IN (".getEntity($sharedelement, 1).
")";
863 if ($feature ===
'agenda') {
865 if ($objectid > 0 && empty($user->rights->agenda->allactions->read)) {
866 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
868 $action->fetch($objectid);
869 if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
877 if (in_array($feature, $checkhierarchy) && is_object($object)) {
878 $childids = $user->getAllChildIds(1);
880 if ($feature ==
'holiday') {
881 $useridtocheck = $object->fk_user;
882 if (!in_array($useridtocheck, $childids)) {
885 $useridtocheck = $object->fk_validator;
886 if (!in_array($useridtocheck, $childids)) {
890 if ($feature ==
'expensereport') {
891 $useridtocheck = $object->fk_user_author;
892 if (!$user->rights->expensereport->readall) {
893 if (!in_array($useridtocheck, $childids)) {
901 $resql = $db->query($sql);
903 $obj = $db->fetch_object(
$resql);
904 if (!$obj || $obj->nb < count(explode(
',', $objectid))) {
908 dol_syslog(
"Bad forged sql in checkUserAccessToObject", LOG_WARNING);
928 function accessforbidden($message =
'', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params = null)
930 global $conf, $db, $user, $langs, $hookmanager;
931 if (!is_object($langs)) {
932 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
934 $langs->setDefaultLang();
937 $langs->load(
"errors");
940 if (function_exists(
"llxHeader")) {
942 } elseif (function_exists(
"llxHeaderVierge")) {
946 print
'<div class="error">';
948 print $langs->trans(
"ErrorForbidden");
954 if (empty($showonlymessage)) {
955 global $action, $object;
956 if (empty($hookmanager)) {
959 $hookmanager->initHooks(array(
'main'));
961 $parameters = array(
'message'=>$message,
'params'=>$params);
962 $reshook = $hookmanager->executeHooks(
'getAccessForbiddenMessage', $parameters, $object, $action);
963 print $hookmanager->resPrint;
964 if (empty($reshook)) {
965 $langs->loadLangs(array(
"errors"));
967 print $langs->trans(
"CurrentLogin").
': <span class="error">'.$user->login.
'</span><br>';
968 print $langs->trans(
"ErrorForbidden2", $langs->transnoentitiesnoconv(
"Home"), $langs->transnoentitiesnoconv(
"Users"));
969 print $langs->trans(
"ErrorForbidden4");
971 print $langs->trans(
"ErrorForbidden3");
975 if ($printfooter && function_exists(
"llxFooter")) {
992 $max = $conf->global->MAIN_UPLOAD_DOC;
993 $maxphp = @ini_get(
'upload_max_filesize');
994 if (preg_match(
'/k$/i', $maxphp)) {
995 $maxphp = preg_replace(
'/k$/i',
'', $maxphp);
996 $maxphp = $maxphp * 1;
998 if (preg_match(
'/m$/i', $maxphp)) {
999 $maxphp = preg_replace(
'/m$/i',
'', $maxphp);
1000 $maxphp = $maxphp * 1024;
1002 if (preg_match(
'/g$/i', $maxphp)) {
1003 $maxphp = preg_replace(
'/g$/i',
'', $maxphp);
1004 $maxphp = $maxphp * 1024 * 1024;
1006 if (preg_match(
'/t$/i', $maxphp)) {
1007 $maxphp = preg_replace(
'/t$/i',
'', $maxphp);
1008 $maxphp = $maxphp * 1024 * 1024 * 1024;
1010 $maxphp2 = @ini_get(
'post_max_size');
1011 if (preg_match(
'/k$/i', $maxphp2)) {
1012 $maxphp2 = preg_replace(
'/k$/i',
'', $maxphp2);
1013 $maxphp2 = $maxphp2 * 1;
1015 if (preg_match(
'/m$/i', $maxphp2)) {
1016 $maxphp2 = preg_replace(
'/m$/i',
'', $maxphp2);
1017 $maxphp2 = $maxphp2 * 1024;
1019 if (preg_match(
'/g$/i', $maxphp2)) {
1020 $maxphp2 = preg_replace(
'/g$/i',
'', $maxphp2);
1021 $maxphp2 = $maxphp2 * 1024 * 1024;
1023 if (preg_match(
'/t$/i', $maxphp2)) {
1024 $maxphp2 = preg_replace(
'/t$/i',
'', $maxphp2);
1025 $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
1029 $maxphptoshow = $maxphptoshowparam =
'';
1031 $maxmin = min($maxmin, $maxphp);
1032 $maxphptoshow = $maxphp;
1033 $maxphptoshowparam =
'upload_max_filesize';
1036 $maxmin = min($maxmin, $maxphp2);
1037 if ($maxphp2 < $maxphp) {
1038 $maxphptoshow = $maxphp2;
1039 $maxphptoshowparam =
'post_max_size';
1045 return array(
'max'=>$max,
'maxmin'=>$maxmin,
'maxphptoshow'=>$maxphptoshow,
'maxphptoshowparam'=>$maxphptoshowparam);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getMaxFileSizeArray()
Return the max allowed for file upload.
dol_hash($chain, $type= '0')
Returns a hash of a string.
dol_decode($chain, $key= '1')
Decode a base 64 encoded + specific delta change.
Class to manage agenda events (actions)
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default= '')
Return dolibarr global constant string value.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
dol_verifyHash($chain, $hash, $type= '0')
Compute a hash and compare it to the given one For backward compatibility reasons, if the hash is not in the password_hash format, we will try to match against md5 and sha1md5 If constant MAIN_SECURITY_HASH_ALGO is defined, we use this function as hashing function.
checkUserAccessToObject($user, array $featuresarray, $object=0, $tableandshare= '', $feature2= '', $dbt_keyfield= '', $dbt_select= 'rowid', $parenttableforentity= '')
Check that access by a given user to an object is ok.
Class to manage projects.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_encode($chain, $key= '1')
Encode a string with base 64 algorithm + specific delta change.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage translations.
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOIPCHECK')) llxHeaderVierge()
Header function.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dolGetLdapPasswordHash($password, $type= 'md5')
Returns a specific ldap hash of a password.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...