dolibarr  7.0.0-beta
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 <http://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 $langs->load("main");
34 $langs->load("admin");
35 $langs->load("cashdesk");
36 
37 $username = GETPOST("txtUsername");
38 $password = GETPOST("pwdPassword");
39 $thirdpartyid = (GETPOST('socid','int') > 0)?GETPOST('socid','int'):$conf->global->CASHDESK_ID_THIRDPARTY;
40 $warehouseid = (GETPOST("warehouseid") > 0)?GETPOST("warehouseid",'int'):$conf->global->CASHDESK_ID_WAREHOUSE;
41 $bankid_cash = (GETPOST("CASHDESK_ID_BANKACCOUNT_CASH") > 0)?GETPOST("CASHDESK_ID_BANKACCOUNT_CASH",'int'):$conf->global->CASHDESK_ID_BANKACCOUNT_CASH;
42 $bankid_cheque = (GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE") > 0)?GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE",'int'):$conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE;
43 $bankid_cb = (GETPOST("CASHDESK_ID_BANKACCOUNT_CB") > 0)?GETPOST("CASHDESK_ID_BANKACCOUNT_CB",'int'):$conf->global->CASHDESK_ID_BANKACCOUNT_CB;
44 
45 // Check username
46 if (empty($username))
47 {
48  $retour=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Login"));
49  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);
50  exit;
51 }
52 // Check third party id
53 if (! ($thirdpartyid > 0))
54 {
55  $retour=$langs->trans("ErrorFieldRequired",$langs->transnoentities("CashDeskThirdPartyForSell"));
56  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);
57  exit;
58 }
59 
60 // If we setup stock module to ask movement on invoices, we must not allow access if required setup not finished.
61 if (! empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK) && ! ($warehouseid > 0))
62 {
63  $retour=$langs->trans("CashDeskYouDidNotDisableStockDecease");
64  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);
65  exit;
66 }
67 
68 // If stock decrease on bill validation, check user has stock edit permissions
69 if (! empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK) && ! empty($username))
70 {
71  $testuser=new User($db);
72  $testuser->fetch(0,$username);
73  $testuser->getrights('stock');
74  if (empty($testuser->rights->stock->creer))
75  {
76  $retour=$langs->trans("UserNeedPermissionToEditStockToUsePos");
77  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);
78  exit;
79  }
80 }
81 
82 
83 /*
84 if (! empty($_POST['txtUsername']) && ! empty($conf->banque->enabled) && (empty($conf_fkaccount_cash) && empty($conf_fkaccount_cheque) && empty($conf_fkaccount_cb)))
85 {
86  $langs->load("errors");
87  $retour=$langs->trans("ErrorModuleSetupNotComplete");
88  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
89  exit;
90 }
91 */
92 
93 // Check password
94 $auth = new Auth($db);
95 $retour = $auth->verif($username, $password);
96 
97 if ( $retour >= 0 )
98 {
99  $return=array();
100 
101  $sql = "SELECT rowid, lastname, firstname";
102  $sql.= " FROM ".MAIN_DB_PREFIX."user";
103  $sql.= " WHERE login = '".$username."'";
104  $sql.= " AND entity IN (0,".$conf->entity.")";
105 
106  $result = $db->query($sql);
107  if ($result)
108  {
109  $tab = $db->fetch_array($res);
110 
111  foreach ( $tab as $key => $value )
112  {
113  $return[$key] = $value;
114  }
115 
116  $_SESSION['uid'] = $tab['rowid'];
117  $_SESSION['uname'] = $username;
118  $_SESSION['lastname'] = $tab['lastname'];
119  $_SESSION['firstname'] = $tab['firstname'];
120  $_SESSION['CASHDESK_ID_THIRDPARTY'] = ($thirdpartyid > 0 ? $thirdpartyid : '');
121  $_SESSION['CASHDESK_ID_WAREHOUSE'] = ($warehouseid > 0 ? $warehouseid : '');
122 
123  $_SESSION['CASHDESK_ID_BANKACCOUNT_CASH'] = ($bankid_cash > 0 ? $bankid_cash : '');
124  $_SESSION['CASHDESK_ID_BANKACCOUNT_CHEQUE'] = ($bankid_cheque > 0 ? $bankid_cheque : '');
125  $_SESSION['CASHDESK_ID_BANKACCOUNT_CB'] = ($bankid_cb > 0 ? $bankid_cb : '');
126  //var_dump($_SESSION);exit;
127 
128  header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation&id=NOUV');
129  exit;
130  }
131  else
132  {
133  dol_print_error($db);
134  }
135 }
136 else
137 {
138  $langs->load("errors");
139  $langs->load("other");
140  $retour=$langs->trans("ErrorBadLoginPassword");
141  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
142  exit;
143 }
144 
Class ot manage authentication for pos module (cashdesk)
Definition: Auth.class.php:23
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.