PageRenderTime 45ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/cashdesk/index_verif.php

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