index_verif.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 <https://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. // Load translation files required by the page
  31. $langs->loadLangs(array("main", "admin", "cashdesk"));
  32. $username = GETPOST("txtUsername");
  33. $password = GETPOST("pwdPassword");
  34. $thirdpartyid = (GETPOST('socid', 'int') > 0) ?GETPOST('socid', 'int') : $conf->global->CASHDESK_ID_THIRDPARTY;
  35. $warehouseid = (GETPOST("warehouseid") > 0) ?GETPOST("warehouseid", 'int') : $conf->global->CASHDESK_ID_WAREHOUSE;
  36. $bankid_cash = (GETPOST("CASHDESK_ID_BANKACCOUNT_CASH") > 0) ?GETPOST("CASHDESK_ID_BANKACCOUNT_CASH", 'int') : $conf->global->CASHDESK_ID_BANKACCOUNT_CASH;
  37. $bankid_cheque = (GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE") > 0) ?GETPOST("CASHDESK_ID_BANKACCOUNT_CHEQUE", 'int') : $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE;
  38. $bankid_cb = (GETPOST("CASHDESK_ID_BANKACCOUNT_CB") > 0) ?GETPOST("CASHDESK_ID_BANKACCOUNT_CB", 'int') : $conf->global->CASHDESK_ID_BANKACCOUNT_CB;
  39. // Check username
  40. if (empty($username))
  41. {
  42. $retour = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Login"));
  43. 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);
  44. exit;
  45. }
  46. // Check third party id
  47. if (!($thirdpartyid > 0))
  48. {
  49. $retour = $langs->trans("ErrorFieldRequired", $langs->transnoentities("CashDeskThirdPartyForSell"));
  50. 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);
  51. exit;
  52. }
  53. // If we setup stock module to ask movement on invoices, we must not allow access if required setup not finished.
  54. if (!empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK) && !($warehouseid > 0))
  55. {
  56. $retour = $langs->trans("CashDeskYouDidNotDisableStockDecease");
  57. 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);
  58. exit;
  59. }
  60. // If stock decrease on bill validation, check user has stock edit permissions
  61. if (!empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK) && !empty($username))
  62. {
  63. $testuser = new User($db);
  64. $testuser->fetch(0, $username);
  65. $testuser->getrights('stock');
  66. if (empty($testuser->rights->stock->creer))
  67. {
  68. $retour = $langs->trans("UserNeedPermissionToEditStockToUsePos");
  69. 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);
  70. exit;
  71. }
  72. }
  73. // Check password
  74. $auth = new Auth($db);
  75. $retour = $auth->verif($username, $password);
  76. if ($retour >= 0)
  77. {
  78. $return = array();
  79. $sql = "SELECT rowid, lastname, firstname";
  80. $sql .= " FROM ".MAIN_DB_PREFIX."user";
  81. $sql .= " WHERE login = '".$username."'";
  82. $sql .= " AND entity IN (0,".$conf->entity.")";
  83. $result = $db->query($sql);
  84. if ($result)
  85. {
  86. $tab = $db->fetch_array($res);
  87. foreach ($tab as $key => $value)
  88. {
  89. $return[$key] = $value;
  90. }
  91. $_SESSION['uid'] = $tab['rowid'];
  92. $_SESSION['uname'] = $username;
  93. $_SESSION['lastname'] = $tab['lastname'];
  94. $_SESSION['firstname'] = $tab['firstname'];
  95. $_SESSION['CASHDESK_ID_THIRDPARTY'] = ($thirdpartyid > 0 ? $thirdpartyid : '');
  96. $_SESSION['CASHDESK_ID_WAREHOUSE'] = ($warehouseid > 0 ? $warehouseid : '');
  97. $_SESSION['CASHDESK_ID_BANKACCOUNT_CASH'] = ($bankid_cash > 0 ? $bankid_cash : '');
  98. $_SESSION['CASHDESK_ID_BANKACCOUNT_CHEQUE'] = ($bankid_cheque > 0 ? $bankid_cheque : '');
  99. $_SESSION['CASHDESK_ID_BANKACCOUNT_CB'] = ($bankid_cb > 0 ? $bankid_cb : '');
  100. //var_dump($_SESSION);exit;
  101. header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation&id=NOUV');
  102. exit;
  103. }
  104. else
  105. {
  106. dol_print_error($db);
  107. }
  108. }
  109. else
  110. {
  111. // Load translation files required by the page
  112. $langs->loadLangs(array("other", "errors"));
  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. }