index_verif.php 5.7 KB

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