dolibarr  9.0.0
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 // 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 /*
83 if (! empty($_POST['txtUsername']) && ! empty($conf->banque->enabled) && (empty($conf_fkaccount_cash) && empty($conf_fkaccount_cheque) && empty($conf_fkaccount_cb)))
84 {
85  $langs->load("errors");
86  $retour=$langs->trans("ErrorModuleSetupNotComplete");
87  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
88  exit;
89 }
90 */
91 
92 // Check password
93 $auth = new Auth($db);
94 $retour = $auth->verif($username, $password);
95 
96 if ( $retour >= 0 )
97 {
98  $return=array();
99 
100  $sql = "SELECT rowid, lastname, firstname";
101  $sql.= " FROM ".MAIN_DB_PREFIX."user";
102  $sql.= " WHERE login = '".$username."'";
103  $sql.= " AND entity IN (0,".$conf->entity.")";
104 
105  $result = $db->query($sql);
106  if ($result)
107  {
108  $tab = $db->fetch_array($res);
109 
110  foreach ( $tab as $key => $value )
111  {
112  $return[$key] = $value;
113  }
114 
115  $_SESSION['uid'] = $tab['rowid'];
116  $_SESSION['uname'] = $username;
117  $_SESSION['lastname'] = $tab['lastname'];
118  $_SESSION['firstname'] = $tab['firstname'];
119  $_SESSION['CASHDESK_ID_THIRDPARTY'] = ($thirdpartyid > 0 ? $thirdpartyid : '');
120  $_SESSION['CASHDESK_ID_WAREHOUSE'] = ($warehouseid > 0 ? $warehouseid : '');
121 
122  $_SESSION['CASHDESK_ID_BANKACCOUNT_CASH'] = ($bankid_cash > 0 ? $bankid_cash : '');
123  $_SESSION['CASHDESK_ID_BANKACCOUNT_CHEQUE'] = ($bankid_cheque > 0 ? $bankid_cheque : '');
124  $_SESSION['CASHDESK_ID_BANKACCOUNT_CB'] = ($bankid_cb > 0 ? $bankid_cb : '');
125  //var_dump($_SESSION);exit;
126 
127  header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation&id=NOUV');
128  exit;
129  }
130  else
131  {
132  dol_print_error($db);
133  }
134 }
135 else
136 {
137  // Load translation files required by the page
138  $langs->loadLangs(array("other","errors"));
139  $retour=$langs->trans("ErrorBadLoginPassword");
140  header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
141  exit;
142 }
143 
GETPOST($paramname, $check='none', $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:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...