index_verif.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. // 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. /*
  74. if (! empty($_POST['txtUsername']) && ! empty($conf->banque->enabled) && (empty($conf_fkaccount_cash) && empty($conf_fkaccount_cheque) && empty($conf_fkaccount_cb)))
  75. {
  76. $langs->load("errors");
  77. $retour=$langs->trans("ErrorModuleSetupNotComplete");
  78. header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
  79. exit;
  80. }
  81. */
  82. // Check password
  83. $auth = new Auth($db);
  84. $retour = $auth->verif($username, $password);
  85. if ( $retour >= 0 )
  86. {
  87. $return=array();
  88. $sql = "SELECT rowid, lastname, firstname";
  89. $sql.= " FROM ".MAIN_DB_PREFIX."user";
  90. $sql.= " WHERE login = '".$username."'";
  91. $sql.= " AND entity IN (0,".$conf->entity.")";
  92. $result = $db->query($sql);
  93. if ($result)
  94. {
  95. $tab = $db->fetch_array($res);
  96. foreach ( $tab as $key => $value )
  97. {
  98. $return[$key] = $value;
  99. }
  100. $_SESSION['uid'] = $tab['rowid'];
  101. $_SESSION['uname'] = $username;
  102. $_SESSION['lastname'] = $tab['lastname'];
  103. $_SESSION['firstname'] = $tab['firstname'];
  104. $_SESSION['CASHDESK_ID_THIRDPARTY'] = ($thirdpartyid > 0 ? $thirdpartyid : '');
  105. $_SESSION['CASHDESK_ID_WAREHOUSE'] = ($warehouseid > 0 ? $warehouseid : '');
  106. $_SESSION['CASHDESK_ID_BANKACCOUNT_CASH'] = ($bankid_cash > 0 ? $bankid_cash : '');
  107. $_SESSION['CASHDESK_ID_BANKACCOUNT_CHEQUE'] = ($bankid_cheque > 0 ? $bankid_cheque : '');
  108. $_SESSION['CASHDESK_ID_BANKACCOUNT_CB'] = ($bankid_cb > 0 ? $bankid_cb : '');
  109. //var_dump($_SESSION);exit;
  110. header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation&id=NOUV');
  111. exit;
  112. }
  113. else
  114. {
  115. dol_print_error($db);
  116. }
  117. }
  118. else
  119. {
  120. // Load translation files required by the page
  121. $langs->loadLangs(array("other","errors"));
  122. $retour=$langs->trans("ErrorBadLoginPassword");
  123. header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
  124. exit;
  125. }