dolibarr  17.0.4
security.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2021 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2008-2021 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2020 Ferran Marcet <fmarcet@2byte.es>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  * or see https://www.gnu.org/
19  */
20 
38 function dol_encode($chain, $key = '1')
39 {
40  if (is_numeric($key) && $key == '1') { // rule 1 is offset of 17 for char
41  $output_tab = array();
42  $strlength = dol_strlen($chain);
43  for ($i = 0; $i < $strlength; $i++) {
44  $output_tab[$i] = chr(ord(substr($chain, $i, 1)) + 17);
45  }
46  $chain = implode("", $output_tab);
47  } elseif ($key) {
48  $result = '';
49  $strlength = dol_strlen($chain);
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));
53  }
54  $chain = $result;
55  }
56 
57  return base64_encode($chain);
58 }
59 
69 function dol_decode($chain, $key = '1')
70 {
71  $chain = base64_decode($chain);
72 
73  if (is_numeric($key) && $key == '1') { // rule 1 is offset of 17 for char
74  $output_tab = array();
75  $strlength = dol_strlen($chain);
76  for ($i = 0; $i < $strlength; $i++) {
77  $output_tab[$i] = chr(ord(substr($chain, $i, 1)) - 17);
78  }
79 
80  $chain = implode("", $output_tab);
81  } elseif ($key) {
82  $result = '';
83  $strlength = dol_strlen($chain);
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));
87  }
88  $chain = $result;
89  }
90 
91  return $chain;
92 }
93 
100 function dolGetRandomBytes($length)
101 {
102  if (function_exists('random_bytes')) { // Available with PHP 7 only.
103  return bin2hex(random_bytes((int) floor($length / 2))); // the bin2hex will double the number of bytes so we take length / 2
104  }
105 
106  return bin2hex(openssl_random_pseudo_bytes((int) floor($length / 2))); // the bin2hex will double the number of bytes so we take length / 2. May be very slow on Windows.
107 }
108 
120 function dolEncrypt($chain, $key = '', $ciphering = 'AES-256-CTR', $forceseed = '')
121 {
122  global $dolibarr_main_instance_unique_id;
123  global $dolibarr_disable_dolcrypt_for_debug;
124 
125  if ($chain === '' || is_null($chain)) {
126  return '';
127  }
128 
129  $reg = array();
130  if (preg_match('/^dolcrypt:([^:]+):(.+)$/', $chain, $reg)) {
131  // The $chain is already a crypted string
132  return $chain;
133  }
134 
135  if (empty($key)) {
136  $key = $dolibarr_main_instance_unique_id;
137  }
138  if (empty($ciphering)) {
139  $ciphering = 'AES-256-CTR';
140  }
141 
142  $newchain = $chain;
143 
144  if (function_exists('openssl_encrypt') && empty($dolibarr_disable_dolcrypt_for_debug)) {
145  $ivlen = 16;
146  if (function_exists('openssl_cipher_iv_length')) {
147  $ivlen = openssl_cipher_iv_length($ciphering);
148  }
149  if ($ivlen === false || $ivlen < 1 || $ivlen > 32) {
150  $ivlen = 16;
151  }
152  if (empty($forceseed)) {
153  $ivseed = dolGetRandomBytes($ivlen);
154  } else {
155  $ivseed = dol_substr(md5($forceseed), 0, $ivlen, 'ascii', 1);
156  }
157 
158  $newchain = openssl_encrypt($chain, $ciphering, $key, 0, $ivseed);
159  return 'dolcrypt:'.$ciphering.':'.$ivseed.':'.$newchain;
160  } else {
161  return $chain;
162  }
163 }
164 
174 function dolDecrypt($chain, $key = '')
175 {
176  global $dolibarr_main_instance_unique_id;
177 
178  if ($chain === '' || is_null($chain)) {
179  return '';
180  }
181 
182  if (empty($key)) {
183  $key = $dolibarr_main_instance_unique_id;
184  }
185 
186  $reg = array();
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]);
193  } else {
194  $newchain = openssl_decrypt($tmpexplode[0], $ciphering, $key, 0, null);
195  }
196  } else {
197  $newchain = 'Error function openssl_decrypt() not available';
198  }
199  return $newchain;
200  } else {
201  return $chain;
202  }
203 }
204 
215 function dol_hash($chain, $type = '0')
216 {
217  global $conf;
218 
219  // No need to add salt for password_hash
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);
222  }
223 
224  // Salt value
225  if (!empty($conf->global->MAIN_SECURITY_SALT) && $type != '4' && $type !== 'openldap') {
226  $chain = $conf->global->MAIN_SECURITY_SALT.$chain;
227  }
228 
229  if ($type == '1' || $type == 'sha1') {
230  return sha1($chain);
231  } elseif ($type == '2' || $type == 'sha1md5') {
232  return sha1(md5($chain));
233  } elseif ($type == '3' || $type == 'md5') {
234  return md5($chain);
235  } elseif ($type == '4' || $type == 'openldap') {
236  return dolGetLdapPasswordHash($chain, getDolGlobalString('LDAP_PASSWORD_HASH_TYPE', 'md5'));
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') {
242  return sha1($chain);
243  } elseif (!empty($conf->global->MAIN_SECURITY_HASH_ALGO) && $conf->global->MAIN_SECURITY_HASH_ALGO == 'sha1md5') {
244  return sha1(md5($chain));
245  }
246 
247  // No particular encoding defined, use default
248  return md5($chain);
249 }
250 
263 function dol_verifyHash($chain, $hash, $type = '0')
264 {
265  global $conf;
266 
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);
270  } elseif (dol_strlen($hash) == 32) {
271  return dol_verifyHash($chain, $hash, '3'); // md5
272  } elseif (dol_strlen($hash) == 40) {
273  return dol_verifyHash($chain, $hash, '2'); // sha1md5
274  }
275 
276  return false;
277  }
278 
279  return dol_hash($chain, $type) == $hash;
280 }
281 
289 function dolGetLdapPasswordHash($password, $type = 'md5')
290 {
291  if (empty($type)) {
292  $type = 'md5';
293  }
294 
295  $salt = substr(sha1(time()), 0, 8);
296 
297  if ($type === 'md5') {
298  return '{MD5}' . base64_encode(hash("md5", $password, true)); //For OpenLdap with md5 (based on an unencrypted password in base)
299  } elseif ($type === 'md5frommd5') {
300  return '{MD5}' . base64_encode(hex2bin($password)); // Create OpenLDAP MD5 password from Dolibarr MD5 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; // Just for test, plain text password is not secured !
323  }
324 }
325 
346 function restrictedArea(User $user, $features, $object = 0, $tableandshare = '', $feature2 = '', $dbt_keyfield = 'fk_soc', $dbt_select = 'rowid', $isdraft = 0, $mode = 0)
347 {
348  global $db, $conf;
349  global $hookmanager;
350 
351  if (is_object($object)) {
352  $objectid = $object->id;
353  } else {
354  $objectid = $object; // $objectid can be X or 'X,Y,Z'
355  }
356  if ($objectid == "-1") {
357  $objectid = 0;
358  }
359  if ($objectid) {
360  $objectid = preg_replace('/[^0-9\.\,]/', '', $objectid); // For the case value is coming from a non sanitized user input
361  }
362 
363  //dol_syslog("functions.lib:restrictedArea $feature, $objectid, $dbtablename, $feature2, $dbt_socfield, $dbt_select, $isdraft");
364  //print "user_id=".$user->id.", features=".$features.", feature2=".$feature2.", objectid=".$objectid;
365  //print ", dbtablename=".$tableandshare.", dbt_socfield=".$dbt_keyfield.", dbt_select=".$dbt_select;
366  //print ", perm: ".$features."->".$feature2."=".($user->rights->$features->$feature2->lire)."<br>";
367 
368  $parentfortableentity = '';
369 
370  // Fix syntax of $features param
371  $originalfeatures = $features;
372  if ($features == 'facturerec') {
373  $features = 'facture';
374  }
375  if ($features == 'supplier_invoicerec') {
376  $features = 'fournisseur';
377  $feature2 = 'facture';
378  }
379  if ($features == 'mo') {
380  $features = 'mrp';
381  }
382  if ($features == 'member') {
383  $features = 'adherent';
384  }
385  if ($features == 'subscription') {
386  $features = 'adherent';
387  $feature2 = 'cotisation';
388  };
389  if ($features == 'websitepage') {
390  $features = 'website';
391  $tableandshare = 'website_page';
392  $parentfortableentity = 'fk_website@website';
393  }
394  if ($features == 'project') {
395  $features = 'projet';
396  }
397  if ($features == 'product') {
398  $features = 'produit';
399  }
400  if ($features == 'payment_sc') {
401  $tableandshare = 'paiementcharge';
402  $parentfortableentity = 'fk_charge@chargesociales';
403  }
404 
405  // Get more permissions checks from hooks
406  $parameters = array('features'=>$features, 'originalfeatures'=>$originalfeatures, 'objectid'=>$objectid, 'dbt_select'=>$dbt_select, 'idtype'=>$dbt_select, 'isdraft'=>$isdraft);
407  $reshook = $hookmanager->executeHooks('restrictedArea', $parameters);
408 
409  if (isset($hookmanager->resArray['result'])) {
410  if ($hookmanager->resArray['result'] == 0) {
411  if ($mode) {
412  return 0;
413  } else {
414  accessforbidden(); // Module returns 0, so access forbidden
415  }
416  }
417  }
418  if ($reshook > 0) { // No other test done.
419  return 1;
420  }
421 
422  // Features/modules to check
423  $featuresarray = array($features);
424  if (preg_match('/&/', $features)) {
425  $featuresarray = explode("&", $features);
426  } elseif (preg_match('/\|/', $features)) {
427  $featuresarray = explode("|", $features);
428  }
429 
430  // More subfeatures to check
431  if (!empty($feature2)) {
432  $feature2 = explode("|", $feature2);
433  }
434 
435  $listofmodules = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL);
436 
437  // Check read permission from module
438  $readok = 1;
439  $nbko = 0;
440  foreach ($featuresarray as $feature) { // first we check nb of test ko
441  $featureforlistofmodule = $feature;
442  if ($featureforlistofmodule == 'produit') {
443  $featureforlistofmodule = 'product';
444  }
445  if ($featureforlistofmodule == 'supplier_proposal') {
446  $featureforlistofmodule = 'supplierproposal';
447  }
448  if (!empty($user->socid) && !empty($conf->global->MAIN_MODULES_FOR_EXTERNAL) && !in_array($featureforlistofmodule, $listofmodules)) { // If limits on modules for external users, module must be into list of modules for external users
449  $readok = 0;
450  $nbko++;
451  continue;
452  }
453 
454  if ($feature == 'societe') {
455  if (!$user->hasRight('societe', 'lire') && !$user->hasRight('fournisseur', 'lire')) {
456  $readok = 0;
457  $nbko++;
458  }
459  } elseif ($feature == 'contact') {
460  if (empty($user->rights->societe->contact->lire)) {
461  $readok = 0;
462  $nbko++;
463  }
464  } elseif ($feature == 'produit|service') {
465  if (empty($user->rights->produit->lire) && empty($user->rights->service->lire)) {
466  $readok = 0;
467  $nbko++;
468  }
469  } elseif ($feature == 'prelevement') {
470  if (empty($user->rights->prelevement->bons->lire)) {
471  $readok = 0;
472  $nbko++;
473  }
474  } elseif ($feature == 'cheque') {
475  if (empty($user->rights->banque->cheque)) {
476  $readok = 0;
477  $nbko++;
478  }
479  } elseif ($feature == 'projet') {
480  if (empty($user->rights->projet->lire) && empty($user->rights->projet->all->lire)) {
481  $readok = 0;
482  $nbko++;
483  }
484  } elseif ($feature == 'payment') {
485  if (empty($user->rights->facture->lire)) {
486  $readok = 0;
487  $nbko++;
488  }
489  } elseif ($feature == 'payment_supplier') {
490  if (empty($user->rights->fournisseur->facture->lire)) {
491  $readok = 0;
492  $nbko++;
493  }
494  } elseif ($feature == 'payment_sc') {
495  if (empty($user->rights->tax->charges->lire)) {
496  $readok = 0;
497  $nbko++;
498  }
499  } elseif (!empty($feature2)) { // This is for permissions on 2 levels
500  $tmpreadok = 1;
501  foreach ($feature2 as $subfeature) {
502  if ($subfeature == 'user' && $user->id == $objectid) {
503  continue; // A user can always read its own card
504  }
505  if (!empty($subfeature) && empty($user->rights->$feature->$subfeature->lire) && empty($user->rights->$feature->$subfeature->read)) {
506  $tmpreadok = 0;
507  } elseif (empty($subfeature) && empty($user->rights->$feature->lire) && empty($user->rights->$feature->read)) {
508  $tmpreadok = 0;
509  } else {
510  $tmpreadok = 1;
511  break;
512  } // Break is to bypass second test if the first is ok
513  }
514  if (!$tmpreadok) { // We found a test on feature that is ko
515  $readok = 0; // All tests are ko (we manage here the and, the or will be managed later using $nbko).
516  $nbko++;
517  }
518  } elseif (!empty($feature) && ($feature != 'user' && $feature != 'usergroup')) { // This is permissions on 1 level
519  if (empty($user->rights->$feature->lire)
520  && empty($user->rights->$feature->read)
521  && empty($user->rights->$feature->run)) {
522  $readok = 0;
523  $nbko++;
524  }
525  }
526  }
527 
528  // If a or and at least one ok
529  if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
530  $readok = 1;
531  }
532 
533  if (!$readok) {
534  if ($mode) {
535  return 0;
536  } else {
537  accessforbidden();
538  }
539  }
540  //print "Read access is ok";
541 
542  // Check write permission from module (we need to know write permission to create but also to delete drafts record or to upload files)
543  $createok = 1;
544  $nbko = 0;
545  $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));
546  $wemustcheckpermissionfordeletedraft = ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete');
547 
548  if ($wemustcheckpermissionforcreate || $wemustcheckpermissionfordeletedraft) {
549  foreach ($featuresarray as $feature) {
550  if ($feature == 'contact') {
551  if (empty($user->rights->societe->contact->creer)) {
552  $createok = 0;
553  $nbko++;
554  }
555  } elseif ($feature == 'produit|service') {
556  if (empty($user->rights->produit->creer) && empty($user->rights->service->creer)) {
557  $createok = 0;
558  $nbko++;
559  }
560  } elseif ($feature == 'prelevement') {
561  if (!$user->rights->prelevement->bons->creer) {
562  $createok = 0;
563  $nbko++;
564  }
565  } elseif ($feature == 'commande_fournisseur') {
566  if (empty($user->rights->fournisseur->commande->creer) || empty($user->rights->supplier_order->creer)) {
567  $createok = 0;
568  $nbko++;
569  }
570  } elseif ($feature == 'banque') {
571  if (empty($user->rights->banque->modifier)) {
572  $createok = 0;
573  $nbko++;
574  }
575  } elseif ($feature == 'cheque') {
576  if (empty($user->rights->banque->cheque)) {
577  $createok = 0;
578  $nbko++;
579  }
580  } elseif ($feature == 'import') {
581  if (empty($user->rights->import->run)) {
582  $createok = 0;
583  $nbko++;
584  }
585  } elseif ($feature == 'ecm') {
586  if (!$user->rights->ecm->upload) {
587  $createok = 0;
588  $nbko++;
589  }
590  } elseif (!empty($feature2)) { // This is for permissions on one level
591  foreach ($feature2 as $subfeature) {
592  if ($subfeature == 'user' && $user->id == $objectid && $user->rights->user->self->creer) {
593  continue; // User can edit its own card
594  }
595  if ($subfeature == 'user' && $user->id == $objectid && $user->rights->user->self->password) {
596  continue; // User can edit its own password
597  }
598  if ($subfeature == 'user' && $user->id != $objectid && $user->rights->user->user->password) {
599  continue; // User can edit another user's password
600  }
601 
602  if (empty($user->rights->$feature->$subfeature->creer)
603  && empty($user->rights->$feature->$subfeature->write)
604  && empty($user->rights->$feature->$subfeature->create)) {
605  $createok = 0;
606  $nbko++;
607  } else {
608  $createok = 1;
609  // Break to bypass second test if the first is ok
610  break;
611  }
612  }
613  } elseif (!empty($feature)) { // This is for permissions on 2 levels ('creer' or 'write')
614  //print '<br>feature='.$feature.' creer='.$user->rights->$feature->creer.' write='.$user->rights->$feature->write; exit;
615  if (empty($user->rights->$feature->creer)
616  && empty($user->rights->$feature->write)
617  && empty($user->rights->$feature->create)) {
618  $createok = 0;
619  $nbko++;
620  }
621  }
622  }
623 
624  // If a or and at least one ok
625  if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
626  $createok = 1;
627  }
628 
629  if ($wemustcheckpermissionforcreate && !$createok) {
630  if ($mode) {
631  return 0;
632  } else {
633  accessforbidden();
634  }
635  }
636  //print "Write access is ok";
637  }
638 
639  // Check create user permission
640  $createuserok = 1;
641  if (GETPOST('action', 'aZ09') == 'confirm_create_user' && GETPOST("confirm", 'aZ09') == 'yes') {
642  if (!$user->rights->user->user->creer) {
643  $createuserok = 0;
644  }
645 
646  if (!$createuserok) {
647  if ($mode) {
648  return 0;
649  } else {
650  accessforbidden();
651  }
652  }
653  //print "Create user access is ok";
654  }
655 
656  // Check delete permission from module
657  $deleteok = 1;
658  $nbko = 0;
659  if ((GETPOST("action", "aZ09") == 'confirm_delete' && GETPOST("confirm", "aZ09") == 'yes') || GETPOST("action", "aZ09") == 'delete') {
660  foreach ($featuresarray as $feature) {
661  if ($feature == 'bookmark') {
662  if (!$user->rights->bookmark->supprimer) {
663  if ($user->id != $object->fk_user || empty($user->rights->bookmark->creer)) {
664  $deleteok = 0;
665  }
666  }
667  } elseif ($feature == 'contact') {
668  if (!$user->rights->societe->contact->supprimer) {
669  $deleteok = 0;
670  }
671  } elseif ($feature == 'produit|service') {
672  if (!$user->rights->produit->supprimer && !$user->rights->service->supprimer) {
673  $deleteok = 0;
674  }
675  } elseif ($feature == 'commande_fournisseur') {
676  if (!$user->rights->fournisseur->commande->supprimer) {
677  $deleteok = 0;
678  }
679  } elseif ($feature == 'payment_supplier') { // Permission to delete a payment of an invoice is permission to edit an invoice.
680  if (!$user->rights->fournisseur->facture->creer) {
681  $deleteok = 0;
682  }
683  } elseif ($feature == 'payment') {
684  if (!$user->rights->facture->paiement) {
685  $deleteok = 0;
686  }
687  } elseif ($feature == 'payment_sc') {
688  if (!$user->rights->tax->charges->creer) {
689  $deleteok = 0;
690  }
691  } elseif ($feature == 'banque') {
692  if (empty($user->rights->banque->modifier)) {
693  $deleteok = 0;
694  }
695  } elseif ($feature == 'cheque') {
696  if (empty($user->rights->banque->cheque)) {
697  $deleteok = 0;
698  }
699  } elseif ($feature == 'ecm') {
700  if (!$user->rights->ecm->upload) {
701  $deleteok = 0;
702  }
703  } elseif ($feature == 'ftp') {
704  if (!$user->rights->ftp->write) {
705  $deleteok = 0;
706  }
707  } elseif ($feature == 'salaries') {
708  if (!$user->rights->salaries->delete) {
709  $deleteok = 0;
710  }
711  } elseif ($feature == 'adherent') {
712  if (empty($user->rights->adherent->supprimer)) {
713  $deleteok = 0;
714  }
715  } elseif ($feature == 'paymentbybanktransfer') {
716  if (empty($user->rights->paymentbybanktransfer->create)) { // There is no delete permission
717  $deleteok = 0;
718  }
719  } elseif ($feature == 'prelevement') {
720  if (empty($user->rights->prelevement->bons->creer)) { // There is no delete permission
721  $deleteok = 0;
722  }
723  } elseif (!empty($feature2)) { // This is for permissions on 2 levels
724  foreach ($feature2 as $subfeature) {
725  if (empty($user->rights->$feature->$subfeature->supprimer) && empty($user->rights->$feature->$subfeature->delete)) {
726  $deleteok = 0;
727  } else {
728  $deleteok = 1;
729  break;
730  } // For bypass the second test if the first is ok
731  }
732  } elseif (!empty($feature)) { // This is used for permissions on 1 level
733  //print '<br>feature='.$feature.' creer='.$user->rights->$feature->supprimer.' write='.$user->rights->$feature->delete;
734  if (empty($user->rights->$feature->supprimer)
735  && empty($user->rights->$feature->delete)
736  && empty($user->rights->$feature->run)) {
737  $deleteok = 0;
738  }
739  }
740  }
741 
742  // If a or and at least one ok
743  if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) {
744  $deleteok = 1;
745  }
746 
747  if (!$deleteok && !($isdraft && $createok)) {
748  if ($mode) {
749  return 0;
750  } else {
751  accessforbidden();
752  }
753  }
754  //print "Delete access is ok";
755  }
756 
757  // If we have a particular object to check permissions on, we check if $user has permission
758  // for this given object (link to company, is contact for project, ...)
759  if (!empty($objectid) && $objectid > 0) {
760  $ok = checkUserAccessToObject($user, $featuresarray, $object, $tableandshare, $feature2, $dbt_keyfield, $dbt_select, $parentfortableentity);
761  $params = array('objectid' => $objectid, 'features' => join(',', $featuresarray), 'features2' => $feature2);
762  //print 'checkUserAccessToObject ok='.$ok;
763  if ($mode) {
764  return $ok ? 1 : 0;
765  } else {
766  if ($ok) {
767  return 1;
768  } else {
769  accessforbidden('', 1, 1, 0, $params);
770  }
771  }
772  }
773 
774  return 1;
775 }
776 
792 function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tableandshare = '', $feature2 = '', $dbt_keyfield = '', $dbt_select = 'rowid', $parenttableforentity = '')
793 {
794  global $db, $conf;
795 
796  if (is_object($object)) {
797  $objectid = $object->id;
798  } else {
799  $objectid = $object; // $objectid can be X or 'X,Y,Z'
800  }
801  $objectid = preg_replace('/[^0-9\.\,]/', '', $objectid); // For the case value is coming from a non sanitized user input
802 
803  //dol_syslog("functions.lib:restrictedArea $feature, $objectid, $dbtablename, $feature2, $dbt_socfield, $dbt_select, $isdraft");
804  //print "user_id=".$user->id.", features=".join(',', $featuresarray).", objectid=".$objectid;
805  //print ", tableandshare=".$tableandshare.", dbt_socfield=".$dbt_keyfield.", dbt_select=".$dbt_select."<br>";
806 
807  // More parameters
808  $params = explode('&', $tableandshare);
809  $dbtablename = (!empty($params[0]) ? $params[0] : '');
810  $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename);
811  foreach ($featuresarray as $feature) {
812  $sql = '';
813 
814  //var_dump($feature);exit;
815 
816  // For backward compatibility
817  if ($feature == 'member') {
818  $feature = 'adherent';
819  }
820  if ($feature == 'project') {
821  $feature = 'projet';
822  }
823  if ($feature == 'task') {
824  $feature = 'projet_task';
825  }
826  if ($feature == 'payment_sc') {
827  $feature = 'paiementcharge';
828  }
829  $checkonentitydone = 0;
830 
831  // Array to define rules of checks to do
832  $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', 'paiementcharge'); // Test on entity only (Objects with no link to company)
833  $checksoc = array('societe'); // Test for object Societe
834  $checkother = array('contact', 'agenda', 'contrat'); // Test on entity + link to third party on field $dbt_keyfield. Allowed if link is empty (Ex: contacts...).
835  $checkproject = array('projet', 'project'); // Test for project object
836  $checktask = array('projet_task'); // Test for task object
837  $checkhierarchy = array('expensereport', 'holiday'); // check permission among the hierarchy of user
838  $checkuser = array('bookmark'); // check permission among the fk_user (must be myself or null)
839  $nocheck = array('barcode', 'stock'); // No test
840 
841  //$checkdefault = 'all other not already defined'; // Test on entity + link to third party on field $dbt_keyfield. Not allowed if link is empty (Ex: invoice, orders...).
842 
843  // If dbtablename not defined, we use same name for table than module name
844  if (empty($dbtablename)) {
845  $dbtablename = $feature;
846  $sharedelement = (!empty($params[1]) ? $params[1] : $dbtablename); // We change dbtablename, so we set sharedelement too.
847  }
848 
849  // To avoid an access forbidden with a numeric ref
850  if ($dbt_select != 'rowid' && $dbt_select != 'id') {
851  $objectid = "'".$objectid."'"; // Note: $objectid was already cast into int at begin of this method.
852  }
853  // Check permission for objectid on entity only
854  if (in_array($feature, $check) && $objectid > 0) { // For $objectid = 0, no check
855  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
856  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
857  if (($feature == 'user' || $feature == 'usergroup') && isModEnabled('multicompany')) { // Special for multicompany
858  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
859  if ($conf->entity == 1 && $user->admin && !$user->entity) {
860  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
861  $sql .= " AND dbt.entity IS NOT NULL";
862  } else {
863  $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
864  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
865  $sql .= " AND ((ug.fk_user = dbt.rowid";
866  $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
867  $sql .= " OR dbt.entity = 0)"; // Show always superadmin
868  }
869  } else {
870  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
871  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
872  }
873  } else {
874  $reg = array();
875  if ($parenttableforentity && preg_match('/(.*)@(.*)/', $parenttableforentity, $reg)) {
876  $sql .= ", ".MAIN_DB_PREFIX.$reg[2]." as dbtp";
877  $sql .= " WHERE dbt.".$reg[1]." = dbtp.rowid AND dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
878  $sql .= " AND dbtp.entity IN (".getEntity($sharedelement, 1).")";
879  } else {
880  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
881  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
882  }
883  }
884  $checkonentitydone = 1;
885  }
886  if (in_array($feature, $checksoc) && $objectid > 0) { // We check feature = checksoc. For $objectid = 0, no check
887  // If external user: Check permission for external users
888  if ($user->socid > 0) {
889  if ($user->socid != $objectid) {
890  return false;
891  }
892  } elseif (isModEnabled("societe") && ($user->hasRight('societe', 'lire') && empty($user->rights->societe->client->voir))) {
893  // If internal user: Check permission for internal users that are restricted on their objects
894  $sql = "SELECT COUNT(sc.fk_soc) as nb";
895  $sql .= " FROM (".MAIN_DB_PREFIX."societe_commerciaux as sc";
896  $sql .= ", ".MAIN_DB_PREFIX."societe as s)";
897  $sql .= " WHERE sc.fk_soc IN (".$db->sanitize($objectid, 1).")";
898  $sql .= " AND sc.fk_user = ".((int) $user->id);
899  $sql .= " AND sc.fk_soc = s.rowid";
900  $sql .= " AND s.entity IN (".getEntity($sharedelement, 1).")";
901  } elseif (isModEnabled('multicompany')) {
902  // If multicompany and internal users with all permissions, check user is in correct entity
903  $sql = "SELECT COUNT(s.rowid) as nb";
904  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
905  $sql .= " WHERE s.rowid IN (".$db->sanitize($objectid, 1).")";
906  $sql .= " AND s.entity IN (".getEntity($sharedelement, 1).")";
907  }
908 
909  $checkonentitydone = 1;
910  }
911  if (in_array($feature, $checkother) && $objectid > 0) { // Test on entity + link to thirdparty. Allowed if link is empty (Ex: contacts...).
912  // If external user: Check permission for external users
913  if ($user->socid > 0) {
914  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
915  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
916  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
917  $sql .= " AND dbt.fk_soc = ".((int) $user->socid);
918  } elseif (isModEnabled("societe") && ($user->hasRight('societe', 'lire') && empty($user->rights->societe->client->voir))) {
919  // If internal user: Check permission for internal users that are restricted on their objects
920  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
921  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
922  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON dbt.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
923  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
924  $sql .= " AND (dbt.fk_soc IS NULL OR sc.fk_soc IS NOT NULL)"; // Contact not linked to a company or to a company of user
925  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
926  } elseif (isModEnabled('multicompany')) {
927  // If multicompany and internal users with all permissions, check user is in correct entity
928  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
929  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
930  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
931  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
932  }
933 
934  $checkonentitydone = 1;
935  }
936  if (in_array($feature, $checkproject) && $objectid > 0) {
937  if (isModEnabled('project') && empty($user->rights->projet->all->lire)) {
938  $projectid = $objectid;
939 
940  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
941  $projectstatic = new Project($db);
942  $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
943 
944  $tmparray = explode(',', $tmps);
945  if (!in_array($projectid, $tmparray)) {
946  return false;
947  }
948  } else {
949  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
950  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
951  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
952  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
953  }
954 
955  $checkonentitydone = 1;
956  }
957  if (in_array($feature, $checktask) && $objectid > 0) {
958  if (isModEnabled('project') && empty($user->rights->projet->all->lire)) {
959  $task = new Task($db);
960  $task->fetch($objectid);
961  $projectid = $task->fk_project;
962 
963  include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
964  $projectstatic = new Project($db);
965  $tmps = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
966 
967  $tmparray = explode(',', $tmps);
968  if (!in_array($projectid, $tmparray)) {
969  return false;
970  }
971  } else {
972  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
973  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
974  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
975  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
976  }
977 
978  $checkonentitydone = 1;
979  }
980  if (!$checkonentitydone && !in_array($feature, $nocheck) && $objectid > 0) { // By default (case of $checkdefault), we check on object entity + link to third party on field $dbt_keyfield
981  // If external user: Check permission for external users
982  if ($user->socid > 0) {
983  if (empty($dbt_keyfield)) {
984  dol_print_error('', 'Param dbt_keyfield is required but not defined');
985  }
986  $sql = "SELECT COUNT(dbt.".$dbt_keyfield.") as nb";
987  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
988  $sql .= " WHERE dbt.rowid IN (".$db->sanitize($objectid, 1).")";
989  $sql .= " AND dbt.".$dbt_keyfield." = ".((int) $user->socid);
990  } elseif (isModEnabled("societe") && empty($user->rights->societe->client->voir)) {
991  // If internal user: Check permission for internal users that are restricted on their objects
992  if ($feature != 'ticket') {
993  if (empty($dbt_keyfield)) {
994  dol_print_error('', 'Param dbt_keyfield is required but not defined');
995  }
996  $sql = "SELECT COUNT(sc.fk_soc) as nb";
997  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
998  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
999  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1000  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1001  $sql .= " AND sc.fk_soc = dbt.".$dbt_keyfield;
1002  $sql .= " AND sc.fk_user = ".((int) $user->id);
1003  } else {
1004  // On ticket, the thirdparty is not mandatory, so we need a special test to accept record with no thirdparties.
1005  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
1006  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1007  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = dbt.".$dbt_keyfield." AND sc.fk_user = ".((int) $user->id);
1008  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1009  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1010  $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR sc.fk_user IS NULL)";
1011  }
1012  } elseif (isModEnabled('multicompany')) {
1013  // If multicompany and internal users with all permissions, check user is in correct entity
1014  $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb";
1015  $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";
1016  $sql .= " WHERE dbt.".$dbt_select." IN (".$db->sanitize($objectid, 1).")";
1017  $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")";
1018  }
1019  }
1020 
1021 
1022  // For events, check on users assigned to event
1023  if ($feature === 'agenda' && $objectid > 0) {
1024  // Also check owner or attendee for users without allactions->read
1025  if ($objectid > 0 && empty($user->rights->agenda->allactions->read)) {
1026  require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1027  $action = new ActionComm($db);
1028  $action->fetch($objectid);
1029  if ($action->authorid != $user->id && $action->userownerid != $user->id && !(array_key_exists($user->id, $action->userassigned))) {
1030  return false;
1031  }
1032  }
1033  }
1034 
1035  // For some object, we also have to check it is in the user hierarchy
1036  // Param $object must be the full object and not a simple id to have this test possible.
1037  if (in_array($feature, $checkhierarchy) && is_object($object) && $objectid > 0) {
1038  $childids = $user->getAllChildIds(1);
1039  $useridtocheck = 0;
1040  if ($feature == 'holiday') {
1041  $useridtocheck = $object->fk_user;
1042  if (!in_array($useridtocheck, $childids)) {
1043  return false;
1044  }
1045  $useridtocheck = $object->fk_validator;
1046  if (!in_array($useridtocheck, $childids)) {
1047  return false;
1048  }
1049  }
1050  if ($feature == 'expensereport') {
1051  $useridtocheck = $object->fk_user_author;
1052  if (!$user->rights->expensereport->readall) {
1053  if (!in_array($useridtocheck, $childids)) {
1054  return false;
1055  }
1056  }
1057  }
1058  }
1059 
1060  // For some object, we also have to check it is public or owned by user
1061  // Param $object must be the full object and not a simple id to have this test possible.
1062  if (in_array($feature, $checkuser) && is_object($object) && $objectid > 0) {
1063  $useridtocheck = $object->fk_user;
1064  if (!empty($useridtocheck) && $useridtocheck > 0 && $useridtocheck != $user->id && empty($user->admin)) {
1065  return false;
1066  }
1067  }
1068 
1069  if ($sql) {
1070  $resql = $db->query($sql);
1071  if ($resql) {
1072  $obj = $db->fetch_object($resql);
1073  if (!$obj || $obj->nb < count(explode(',', $objectid))) { // error if we found 0 or less record than nb of id provided
1074  return false;
1075  }
1076  } else {
1077  dol_syslog("Bad forged sql in checkUserAccessToObject", LOG_WARNING);
1078  return false;
1079  }
1080  }
1081  }
1082 
1083  return true;
1084 }
1085 
1086 
1098 function httponly_accessforbidden($message = 1, $http_response_code = 403, $stringalreadysanitized = 0)
1099 {
1100  top_httphead();
1101  http_response_code($http_response_code);
1102 
1103  if ($stringalreadysanitized) {
1104  print $message;
1105  } else {
1106  print htmlentities($message);
1107  }
1108 
1109  exit(1);
1110 }
1111 
1125 function accessforbidden($message = '', $printheader = 1, $printfooter = 1, $showonlymessage = 0, $params = null)
1126 {
1127  global $conf, $db, $user, $langs, $hookmanager;
1128 
1129  if (!is_object($langs)) {
1130  include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
1131  $langs = new Translate('', $conf);
1132  $langs->setDefaultLang();
1133  }
1134 
1135  $langs->load("errors");
1136 
1137  if ($printheader) {
1138  if (function_exists("llxHeader")) {
1139  llxHeader('');
1140  } elseif (function_exists("llxHeaderVierge")) {
1141  llxHeaderVierge('');
1142  }
1143  }
1144  print '<div class="error">';
1145  if (empty($message)) {
1146  print $langs->trans("ErrorForbidden");
1147  } else {
1148  print $langs->trans($message);
1149  }
1150  print '</div>';
1151  print '<br>';
1152  if (empty($showonlymessage)) {
1153  global $action, $object;
1154  if (empty($hookmanager)) {
1155  $hookmanager = new HookManager($db);
1156  // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1157  $hookmanager->initHooks(array('main'));
1158  }
1159  $parameters = array('message'=>$message, 'params'=>$params);
1160  $reshook = $hookmanager->executeHooks('getAccessForbiddenMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1161  print $hookmanager->resPrint;
1162  if (empty($reshook)) {
1163  $langs->loadLangs(array("errors"));
1164  if ($user->login) {
1165  print $langs->trans("CurrentLogin").': <span class="error">'.$user->login.'</span><br>';
1166  print $langs->trans("ErrorForbidden2", $langs->transnoentitiesnoconv("Home"), $langs->transnoentitiesnoconv("Users"));
1167  print $langs->trans("ErrorForbidden4");
1168  } else {
1169  print $langs->trans("ErrorForbidden3");
1170  }
1171  }
1172  }
1173  if ($printfooter && function_exists("llxFooter")) {
1174  llxFooter();
1175  }
1176 
1177  exit(0);
1178 }
1179 
1180 
1188 {
1189  global $conf;
1190 
1191  $max = $conf->global->MAIN_UPLOAD_DOC; // In Kb
1192  $maxphp = @ini_get('upload_max_filesize'); // In unknown
1193  if (preg_match('/k$/i', $maxphp)) {
1194  $maxphp = preg_replace('/k$/i', '', $maxphp);
1195  $maxphp = $maxphp * 1;
1196  }
1197  if (preg_match('/m$/i', $maxphp)) {
1198  $maxphp = preg_replace('/m$/i', '', $maxphp);
1199  $maxphp = $maxphp * 1024;
1200  }
1201  if (preg_match('/g$/i', $maxphp)) {
1202  $maxphp = preg_replace('/g$/i', '', $maxphp);
1203  $maxphp = $maxphp * 1024 * 1024;
1204  }
1205  if (preg_match('/t$/i', $maxphp)) {
1206  $maxphp = preg_replace('/t$/i', '', $maxphp);
1207  $maxphp = $maxphp * 1024 * 1024 * 1024;
1208  }
1209  $maxphp2 = @ini_get('post_max_size'); // In unknown
1210  if (preg_match('/k$/i', $maxphp2)) {
1211  $maxphp2 = preg_replace('/k$/i', '', $maxphp2);
1212  $maxphp2 = $maxphp2 * 1;
1213  }
1214  if (preg_match('/m$/i', $maxphp2)) {
1215  $maxphp2 = preg_replace('/m$/i', '', $maxphp2);
1216  $maxphp2 = $maxphp2 * 1024;
1217  }
1218  if (preg_match('/g$/i', $maxphp2)) {
1219  $maxphp2 = preg_replace('/g$/i', '', $maxphp2);
1220  $maxphp2 = $maxphp2 * 1024 * 1024;
1221  }
1222  if (preg_match('/t$/i', $maxphp2)) {
1223  $maxphp2 = preg_replace('/t$/i', '', $maxphp2);
1224  $maxphp2 = $maxphp2 * 1024 * 1024 * 1024;
1225  }
1226  // Now $max and $maxphp and $maxphp2 are in Kb
1227  $maxmin = $max;
1228  $maxphptoshow = $maxphptoshowparam = '';
1229  if ($maxphp > 0) {
1230  $maxmin = min($maxmin, $maxphp);
1231  $maxphptoshow = $maxphp;
1232  $maxphptoshowparam = 'upload_max_filesize';
1233  }
1234  if ($maxphp2 > 0) {
1235  $maxmin = min($maxmin, $maxphp2);
1236  if ($maxphp2 < $maxphp) {
1237  $maxphptoshow = $maxphp2;
1238  $maxphptoshowparam = 'post_max_size';
1239  }
1240  }
1241  //var_dump($maxphp.'-'.$maxphp2);
1242  //var_dump($maxmin);
1243 
1244  return array('max'=>$max, 'maxmin'=>$maxmin, 'maxphptoshow'=>$maxphptoshow, 'maxphptoshowparam'=>$maxphptoshowparam);
1245 }
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOIPCHECK')) llxHeaderVierge()
Header function.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage agenda events (actions)
Class to manage hooks.
Class to manage projects.
Class to manage tasks.
Definition: task.class.php:38
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:47
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=0)
Make a substring.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1440
dolEncrypt($chain, $key='', $ciphering='AES-256-CTR', $forceseed='')
Encode a string with a symetric encryption.
dolGetRandomBytes($length)
Return a string of random bytes (hexa string) with length = $length fro cryptographic purposes.
dol_encode($chain, $key='1')
Encode a string with base 64 algorithm + specific delta change.
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.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
getMaxFileSizeArray()
Return the max allowed for file upload.
restrictedArea(User $user, $features, $object=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.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
httponly_accessforbidden($message=1, $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
dolDecrypt($chain, $key='')
Decode a string with a symetric encryption.
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.