PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

http://ebpls.googlecode.com/
PHP | 249 lines | 172 code | 51 blank | 26 comment | 45 complexity | fcf39f265c64d395c7158940e1a4952b MD5 | raw file
  1. <?php
  2. /*
  3. Prupose: Initial login screen for eBPLS
  4. Author: Pagod Na Kami Inc.
  5. Date Started: Limot na sa tagal
  6. Modification History:
  7. 2008.04.25: Fix problems reported in phperror.log
  8. */
  9. // application initialization
  10. ob_start();
  11. session_start();
  12. require_once "includes/config.php";
  13. $strSetupDir = (empty($ThUserData['domain'])) ? "" : $ThUserData['domain'];
  14. $frmLoginDomain = isset($frmLoginDomain) ? $frmLoginDomain : ''; //2008.05.16
  15. $strSetupDir = (is_dir("setup/{$strSetupDir}")) ? $strSetupDir . '/' : "";
  16. $strSettingScript = "setup" . $strSetupDir . "setting.php";
  17. include_once $strSettingScript;
  18. //include_once 'ebpls5501.php';
  19. require_once "lib/ebpls.lib.php";
  20. include'includes/variables.php';
  21. include_once("lib/multidbconnection.php");
  22. $dbLinkFunc =Open($dbtype,$connecttype,$dbhost,$dbuser,$dbpass,$dbname);
  23. dbConnect();
  24. $checktaxfeeother = @mysql_query("select * from ebpls_buss_taxfeeother");
  25. $checktaxfeeother1 = @mysql_num_rows($checktaxfeeother);
  26. if ($checktaxfeeother1 == 0 || $checktaxfeeother == "") {
  27. $inserttfo1 = @mysql_query("insert into ebpls_buss_taxfeeother values ('','','','','','','','','','','')");
  28. $getid = @mysql_insert_id();
  29. $deleteid = @mysql_query("delete from ebpls_buss_taxfeeother where taxfeeid = '$getid'");
  30. if ($getid <= 300) {
  31. $x = 1;
  32. while ($x <= 300) {
  33. $inserttfo = @mysql_query("insert into ebpls_buss_taxfeeother values ('','','','','','','','','','','')");
  34. $x++;
  35. }
  36. }
  37. $deleteall = @mysql_query("delete from ebpls_buss_taxfeeother where taxfeeid > 0");
  38. }
  39. if (!isset($part) or $part=='') { // 2008.04.25 add isset check
  40. if ($GLOBALS['watbrowser']=='msie') {
  41. $strQuery =mysql_query("UPDATE ebpls_user SET login = NOW(), logout = NOW() WHERE id = '$ThUserData[id]'");
  42. setUserLogout();
  43. } else {
  44. setUserLogout();
  45. }
  46. $ThUserData['id']=''; //2008.04.25 add quotes
  47. }
  48. $ses = isset($_COOKIE['PHPSESSID'])?$_COOKIE['PHPSESSID']:''; //2008.05.06
  49. //validates login session
  50. if (getenv('HTTP_X_FORWARDED_FOR')) {
  51. $remoteip = getenv('HTTP_X_FORWARDED_FOR');
  52. } else {
  53. $remoteip = getenv('REMOTE_ADDR');
  54. }
  55. $seslog = mysql_query("select * from user_session where ip_add='$remoteip'");
  56. $haveses = mysql_num_rows($seslog);
  57. $getses = mysql_fetch_assoc($seslog);
  58. if ($ses=='') { //new browser
  59. $frmUserKey = crypt_md5($frmUserKey, $decoder);
  60. $hulog = mysql_query("select * from ebpls_user where username='$frmUserName' and
  61. password='$frmUserKey'");
  62. $gethu = mysql_fetch_assoc($hulog);
  63. $willlog = $gethu['id'];
  64. if ($haveses>0) { //na close ang browser dapat logout
  65. //$updses = mysql_query("Update user_session set date_input=now() where ip_add='$remoteip'");
  66. $delses = mysql_query("delete from user_session where ip_add='$remoteip' and user_id='$willlog'");
  67. $strQuery =mysql_query("UPDATE ebpls_user SET login = NOW(), logout = NOW() WHERE id = '$willlog'")
  68. or die (mysql_error());
  69. } else { //lipat pc
  70. $seslog = mysql_query("select * from user_session where user_id='$willlog'");
  71. $haveses = mysql_num_rows($seslog);
  72. $getses = mysql_fetch_assoc($seslog);
  73. if ($haveses>0) { //hindi na close ang browser lipat pc dapat logout
  74. $lastlog = strtotime(date("Y-m-d h:i:s")) - strtotime($getses['date_input']) ;
  75. if ($lastlog >= $thIntCookieExp) {
  76. $delses = mysql_query("delete from user_session where ip_add='$remoteip' and user_id='$willlog'");
  77. $strQuery =mysql_query("UPDATE ebpls_user SET login = NOW(), logout = NOW() WHERE id = '$willlog'")
  78. or die (mysql_error());
  79. }
  80. }
  81. }
  82. }
  83. // this is from txthotline001.php: Logging In
  84. if (isset($frmLoginSubmit)) {
  85. if (!session_is_registered('count')) {
  86. session_register("count");
  87. $count = 0;
  88. } else {
  89. $count++;
  90. }
  91. if (md5($frmUserName)==$goduser and md5($frmUserKey)==$godpass) {
  92. } else {
  93. $frmUserKey = crypt_md5($frmUserKey, $decoder);
  94. }
  95. $strNewOp = (stristr($HTTP_SERVER_VARS['HTTP_REFERER'], '?')) ? '&' : '?';
  96. //error if invalid user
  97. $invuser = mysql_query("select * from ebpls_user where username='$frmUserName'") or die(mysql_error());
  98. $invu = mysql_num_rows($invuser);
  99. if ($invu==0) {
  100. header("Location: " . $HTTP_SERVER_VARS['HTTP_REFERER'] . $strNewOp . "errlog=0" . $intRsltLog);
  101. $count=0;
  102. } else {
  103. //$frmLoginDomain = isset($frmLoginDomain)?$frmLoginDomain:'0.0.0.0'; //2008.04.25
  104. $intRsltLog = (is_dir("setup/{$frmLoginDomain}")) ? setUserLogin($frmUserName, $frmUserKey, $frmLoginDomain) : 0;
  105. if ($intRsltLog == 1) {
  106. $count = 0;
  107. header("Location: " . $HTTP_SERVER_VARS['REQUEST_URI']);
  108. } elseif ($count >= $thIntPassRetLimit || $intRsltLog == -1) {
  109. $frmUserKey = crypt_md5($frmUserKey, $decoder);
  110. setUserLock($frmUserName, $frmUserKey);
  111. header("Location: " . $HTTP_SERVER_VARS['HTTP_REFERER'] . $strNewOp . "errlog=-1");
  112. $count=0;
  113. } else {
  114. header("Location: " . $HTTP_SERVER_VARS['HTTP_REFERER'] . $strNewOp . "errlog=" . $intRsltLog);
  115. }
  116. }
  117. }
  118. // this part is for application maintenance
  119. $intUserLevel = isUserLogged();
  120. syncUserCookieDbLogStat();
  121. // prevent client-side caching: must be called before displaying any output/html headers
  122. header("Expires: Sat, 22 Jul 1978 15:00:00 GMT"); // Any date in the past
  123. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
  124. header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
  125. header("Cache-Control: post-check=0, pre-check=0", false);
  126. header("Pragma: no-cache"); // HTTP/1.0
  127. // this part is the GUI: displays initial output
  128. if (!empty($part)){
  129. require_once "includes/eBPLS_header.php";
  130. //echo setSystemMenu($intUserLevel);
  131. }else{
  132. ?>
  133. <html>
  134. <head>
  135. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  136. <title>eBPLS Business Permit and Licensing System</title>
  137. <meta name="Author" content=" PARV ">
  138. <link rel="stylesheet" href="stylesheets/default.css" type="text/css"/>
  139. <script language="JavaScript" src="includes/eBPLS.js"></script>
  140. </head>
  141. <?php
  142. }
  143. if (!isset($part)) $part = ""; // 2008.04.25
  144. if (empty($part) || $part == eBPLS_PAGE_LOGIN || intval($intUserLevel) < 0) {
  145. // if not logged-in you start in log-in page else you start in main page
  146. if ($part<>4) {
  147. $part = ($intUserLevel < 0) ? eBPLS_PAGE_LOGIN : eBPLS_PAGE_MAIN;
  148. }
  149. }
  150. /*
  151. */
  152. include_once getFilename($part);
  153. if ($part != 1){
  154. require_once "includes/eBPLS_footer.php";
  155. }
  156. if ($GLOBALS['watbrowser']=='msie') {
  157. // log this system activity for ie
  158. if ($ThUserData[id]<>'') {
  159. foreach ($GLOBALS['HTTP_POST_VARS'] as $key => $val) {
  160. $strPostVarData[] = "$key = $val";
  161. }
  162. //if (is_array($strPostVarData)) $strPostVarData = implode('|-|', $strPostVarData);
  163. $strUpdatePostVar = ($strPostVarData) ? "postvarval = '$strPostVarData'," : "";
  164. $intPartId = (empty($GLOBALS['part'])) ? getCurrFilePartNum() : $GLOBALS['part'];
  165. $getun = mysql_query("select * from ebpls_user where id = '$ThUserData[id]'");
  166. $geth = mysql_fetch_assoc($getun);
  167. $levele = crypt_md5($geth[level],$decoder);
  168. $username = $geth[username];
  169. // echo crypt_md5($geth[level],$decoder);
  170. $be1 = $GLOBALS[HTTP_SERVER_VARS].$GLOBALS[QUERY_STRING];
  171. $strQuqery = mysql_query("INSERT INTO ebpls_activity_log SET
  172. userid = '$ThUserData[id]',
  173. userlevel = '$levele' ,
  174. username = '$geth[username]' ,
  175. part_constant_id = '$intPartId ',
  176. querystring = '$be1',
  177. $strUpdatePostVar
  178. action = '$strAction',
  179. remoteip = '$remoteip',
  180. lastupdated = NOW()
  181. ");
  182. }
  183. } else {
  184. $thStrLogAction = isset($thStrLogAction) ? $thStrLogAction : ''; //2008.05.06
  185. if ($intUserLevel > -1) setCurrentActivityLog($thStrLogAction);
  186. }
  187. if ($part==1 || $part==2) {
  188. if ($GLOBALS['watbrowser']=='msie') {
  189. $strQuery =mysql_query("UPDATE ebpls_user SET login = NOW(), logout = NOW() WHERE id = '$_COOKIE[ieuser]'");
  190. setUserLogout();
  191. } else {
  192. setUserLogout();
  193. }
  194. }
  195. // dbClose(); // not necessary if DB Connection is persistent
  196. ob_end_flush();
  197. ?>