dolibarr  13.0.2
index_verif.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2008 Jeremie Ollivier <jeremie.o@laposte.net>
3  * Copyright (C) 2008-2010 Laurent Destailleur <eldy@uers.sourceforge.net>
4  * Copyright (C) 2011 Juanjo Menent <jmenent@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  *
19  * This page is called after submission of login page.
20  * We set here login choices into session.
21  */
22 
29 include '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php';
31 require_once DOL_DOCUMENT_ROOT.'/cashdesk/class/Auth.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("main", "admin", "cashdesk"));
35 
36 $username = GETPOST("txtUsername");
37 $password = GETPOST("pwdPassword");
38 $thirdpartyid = (GETPOST('socid', 'int') > 0) ?GETPOST('socid', 'int') : $conf->global->CASHDESK_ID_THIRDPARTY;
39 $warehouseid = (GETPOST("warehouseid") > 0) ?GETPOST("warehouseid", 'int') : $conf->global->CASHDESK_ID_WAREHOUSE;
40 $bankid_cash = (GETPOST("CASHDESK_ID_BANKACCOUNT_CASH") > 0) ?GETPOST("CASHDESK_ID_BANKACCOUNT_CASH", 'int') : $conf->global->CASHDESK_ID_BANKACCOUNT_CASH;
41 $bankid_cheque = (GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE") > 0) ?GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE", 'int') : $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE;
42 $bankid_cb = (GETPOST("CASHDESK_ID_BANKACCOUNT_CB") > 0) ?GETPOST("CASHDESK_ID_BANKACCOUNT_CB", 'int') : $conf->global->CASHDESK_ID_BANKACCOUNT_CB;
43 
44 // Check username
45 if (empty($username))
46 {
47  $retour = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Login"));
48  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid.'&bankid_cash='.$bankid_cash.'&bankid_cheque='.$bankid_cheque.'&bankid_cb='.$bankid_cb);
49  exit;
50 }
51 // Check third party id
52 if (!($thirdpartyid > 0))
53 {
54  $retour = $langs->trans("ErrorFieldRequired", $langs->transnoentities("CashDeskThirdPartyForSell"));
55  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid.'&bankid_cash='.$bankid_cash.'&bankid_cheque='.$bankid_cheque.'&bankid_cb='.$bankid_cb);
56  exit;
57 }
58 
59 // If we setup stock module to ask movement on invoices, we must not allow access if required setup not finished.
60 if (!empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK) && !($warehouseid > 0))
61 {
62  $retour = $langs->trans("CashDeskYouDidNotDisableStockDecease");
63  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid.'&bankid_cash='.$bankid_cash.'&bankid_cheque='.$bankid_cheque.'&bankid_cb='.$bankid_cb);
64  exit;
65 }
66 
67 // If stock decrease on bill validation, check user has stock edit permissions
68 if (!empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK) && !empty($username))
69 {
70  $testuser = new User($db);
71  $testuser->fetch(0, $username);
72  $testuser->getrights('stock');
73  if (empty($testuser->rights->stock->creer))
74  {
75  $retour = $langs->trans("UserNeedPermissionToEditStockToUsePos");
76  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid.'&bankid_cash='.$bankid_cash.'&bankid_cheque='.$bankid_cheque.'&bankid_cb='.$bankid_cb);
77  exit;
78  }
79 }
80 
81 
82 // Check password
83 $auth = new Auth($db);
84 $retour = $auth->verif($username, $password);
85 
86 if ($retour >= 0)
87 {
88  $return = array();
89 
90  $sql = "SELECT rowid, lastname, firstname";
91  $sql .= " FROM ".MAIN_DB_PREFIX."user";
92  $sql .= " WHERE login = '".$db->escape($username)."'";
93  $sql .= " AND entity IN (0,".$conf->entity.")";
94 
95  $result = $db->query($sql);
96  if ($result)
97  {
98  $tab = $db->fetch_array($res);
99 
100  foreach ($tab as $key => $value)
101  {
102  $return[$key] = $value;
103  }
104 
105  $_SESSION['uid'] = $tab['rowid'];
106  $_SESSION['uname'] = $username;
107  $_SESSION['lastname'] = $tab['lastname'];
108  $_SESSION['firstname'] = $tab['firstname'];
109  $_SESSION['CASHDESK_ID_THIRDPARTY'] = ($thirdpartyid > 0 ? $thirdpartyid : '');
110  $_SESSION['CASHDESK_ID_WAREHOUSE'] = ($warehouseid > 0 ? $warehouseid : '');
111 
112  $_SESSION['CASHDESK_ID_BANKACCOUNT_CASH'] = ($bankid_cash > 0 ? $bankid_cash : '');
113  $_SESSION['CASHDESK_ID_BANKACCOUNT_CHEQUE'] = ($bankid_cheque > 0 ? $bankid_cheque : '');
114  $_SESSION['CASHDESK_ID_BANKACCOUNT_CB'] = ($bankid_cb > 0 ? $bankid_cb : '');
115  //var_dump($_SESSION);exit;
116 
117  header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation&id=NOUV');
118  exit;
119  } else {
120  dol_print_error($db);
121  }
122 } else {
123  // Load translation files required by the page
124  $langs->loadLangs(array("other", "errors"));
125  $retour = $langs->trans("ErrorBadLoginPassword");
126  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
127  exit;
128 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class ot manage authentication for pos module (cashdesk)
Definition: Auth.class.php:23
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...