PageRenderTime 209ms CodeModel.GetById 130ms app.highlight 6ms RepoModel.GetById 65ms app.codeStats 6ms

/htdocs/cashdesk/index_verif.php

https://github.com/asterix14/dolibarr
PHP | 118 lines | 76 code | 17 blank | 25 comment | 12 complexity | e92147f450e3048ad864b12e0ebf214e MD5 | raw 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 2 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
 23include('../main.inc.php');
 24require_once(DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php');
 25require_once(DOL_DOCUMENT_ROOT.'/cashdesk/class/Auth.class.php');
 26
 27$langs->load("main");
 28$langs->load("admin");
 29$langs->load("cashdesk");
 30
 31$username = GETPOST("txtUsername");
 32$password = GETPOST("pwdPassword");
 33$thirdpartyid = (GETPOST("socid")!='')?GETPOST("socid"):$conf->global->CASHDESK_ID_THIRDPARTY;
 34$warehouseid = (GETPOST("warehouseid")!='')?GETPOST("warehouseid"):$conf->global->CASHDESK_ID_WAREHOUSE;
 35
 36// Check username
 37if (empty($username))
 38{
 39	$retour=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Login"));
 40	header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
 41	exit;
 42}
 43// Check third party id
 44if (! ($thirdpartyid > 0))
 45{
 46    $retour=$langs->trans("ErrorFieldRequired",$langs->transnoentities("CashDeskThirdPartyForSell"));
 47    header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
 48    exit;
 49}
 50
 51// If we setup stock module to ask movement on invoices, we must not allow access if required setup not finished.
 52if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL &&  ! ($warehouseid > 0))
 53{
 54	$retour=$langs->trans("CashDeskSetupStock");
 55	header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
 56	exit;
 57}
 58
 59if (! empty($_POST['txtUsername']) && $conf->banque->enabled && (empty($conf_fkaccount_cash) || empty($conf_fkaccount_cheque) || empty($conf_fkaccount_cb)))
 60{
 61	$langs->load("errors");
 62	$retour=$langs->trans("ErrorModuleSetupNotComplete");
 63    header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
 64    exit;
 65}
 66
 67
 68
 69// Check password
 70$auth = new Auth($db);
 71$retour = $auth->verif($username, $password);
 72
 73if ( $retour >= 0 )
 74{
 75	$return=array();
 76
 77	$sql = "SELECT rowid, name, firstname";
 78	$sql.= " FROM ".MAIN_DB_PREFIX."user";
 79	$sql.= " WHERE login = '".$username."'";
 80	$sql.= " AND entity IN (0,".$conf->entity.")";
 81
 82	$result = $db->query($sql);
 83	if ($result)
 84	{
 85		$tab = $db->fetch_array($res);
 86
 87		foreach ( $tab as $key => $value )
 88		{
 89			$return[$key] = $value;
 90		}
 91
 92		$_SESSION['uid'] = $tab['rowid'];
 93		$_SESSION['uname'] = $username;
 94		$_SESSION['nom'] = $tab['name'];
 95		$_SESSION['prenom'] = $tab['firstname'];
 96		$_SESSION['CASHDESK_ID_THIRDPARTY'] = $thirdpartyid;
 97        $_SESSION['CASHDESK_ID_WAREHOUSE'] = $warehouseid;
 98		//var_dump($_SESSION);exit;
 99
100		header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&id=NOUV');
101		exit;
102	}
103	else
104	{
105		dol_print_error($db);
106	}
107
108}
109else
110{
111	$langs->load("errors");
112    $langs->load("other");
113	$retour=$langs->trans("ErrorBadLoginPassword");
114	header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
115	exit;
116}
117
118?>