PageRenderTime 46ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.0
  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. 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")!='')?GETPOST("socid"):$conf->global->CASHDESK_ID_THIRDPARTY;
  31. $warehouseid = (GETPOST("warehouseid")!='')?GETPOST("warehouseid"):$conf->global->CASHDESK_ID_WAREHOUSE;
  32. // Check username
  33. if (empty($username))
  34. {
  35. $retour=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Login"));
  36. header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
  37. exit;
  38. }
  39. // Check third party id
  40. if (! ($thirdpartyid > 0))
  41. {
  42. $retour=$langs->trans("ErrorFieldRequired",$langs->transnoentities("CashDeskThirdPartyForSell"));
  43. header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
  44. exit;
  45. }
  46. // If we setup stock module to ask movement on invoices, we must not allow access if required setup not finished.
  47. if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL && ! ($warehouseid > 0))
  48. {
  49. $retour=$langs->trans("CashDeskSetupStock");
  50. header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
  51. exit;
  52. }
  53. if (! empty($_POST['txtUsername']) && $conf->banque->enabled && (empty($conf_fkaccount_cash) || empty($conf_fkaccount_cheque) || empty($conf_fkaccount_cb)))
  54. {
  55. $langs->load("errors");
  56. $retour=$langs->trans("ErrorModuleSetupNotComplete");
  57. header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
  58. exit;
  59. }
  60. // Check password
  61. $auth = new Auth($db);
  62. $retour = $auth->verif($username, $password);
  63. if ( $retour >= 0 )
  64. {
  65. $return=array();
  66. $sql = "SELECT rowid, name, firstname";
  67. $sql.= " FROM ".MAIN_DB_PREFIX."user";
  68. $sql.= " WHERE login = '".$username."'";
  69. $sql.= " AND entity IN (0,".$conf->entity.")";
  70. $result = $db->query($sql);
  71. if ($result)
  72. {
  73. $tab = $db->fetch_array($res);
  74. foreach ( $tab as $key => $value )
  75. {
  76. $return[$key] = $value;
  77. }
  78. $_SESSION['uid'] = $tab['rowid'];
  79. $_SESSION['uname'] = $username;
  80. $_SESSION['nom'] = $tab['name'];
  81. $_SESSION['prenom'] = $tab['firstname'];
  82. $_SESSION['CASHDESK_ID_THIRDPARTY'] = $thirdpartyid;
  83. $_SESSION['CASHDESK_ID_WAREHOUSE'] = $warehouseid;
  84. //var_dump($_SESSION);exit;
  85. header('Location: '.DOL_URL_ROOT.'/cashdesk/affIndex.php?menu=facturation&id=NOUV');
  86. exit;
  87. }
  88. else
  89. {
  90. dol_print_error($db);
  91. }
  92. }
  93. else
  94. {
  95. $langs->load("errors");
  96. $langs->load("other");
  97. $retour=$langs->trans("ErrorBadLoginPassword");
  98. header('Location: '.DOL_URL_ROOT.'/cashdesk/index.php?err='.urlencode($retour).'&user='.$username.'&socid='.$thirdpartyid.'&warehouseid='.$warehouseid);
  99. exit;
  100. }
  101. ?>