<?php

	// include files
	require_once('../admin/php/config.php');
	require_once('../admin/php/db.php');
	require_once('../admin/php/info.php');
	//

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['user'])) {
  $loginUsername=$_POST['user'];
  $password=$_POST['pass'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "home.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_conn, $db);
  
  $LoginRS__query=sprintf("SELECT * FROM moderators WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $db) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	
	//
	if($myrowlog = mysql_fetch_array($LoginRS))
	{
		$_SESSION['idb'] = $myrowlog['id'];
		$_SESSION['userb'] = $myrowlog['username'];
		$_SESSION['cityb'] = $myrowlog['city'];	
		//
		$cityid = $myrowlog['city'];
		$Lcity = mysql_query("SELECT * FROM city WHERE id = $cityid", $db);
		if($myrowlog2 = mysql_fetch_array($Lcity))
		{
			$_SESSION['citynameb'] = $myrowlog2['title2'];
		}

	}
    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo($admin_title);?></title>
<link rel="stylesheet" type="text/css" href="../admin/css/style.css" />
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="82%" valign="top" style="padding: 10px;"><br />
		  <br />
          <br />
          <br />
          <br />
		<table width="24%" border="0" align="center" cellpadding="0" cellspacing="100" bgcolor="#EAEAEA">
		<tr>
        <td height="202" valign="top" style="background-color: #FFFFFF; border: 1px solid #999999; padding: 10px">
		<form id="form1" name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
          <table width="100%" border="0" cellspacing="10" cellpadding="0">
            <tr>
              <td><strong>Moderator Panel</strong></td>
            </tr>
            <tr>
              <td>Username:</td>
            </tr>
            <tr>
              <td><input name="user" type="text" id="user" size="40" class="inp1" /></td>
            </tr>
            <tr>
              <td>Password:</td>
            </tr>
            <tr>
              <td><input name="pass" type="password" id="pass" size="40" class="inp1" /></td>
            </tr>
            <tr>
              <td align="right"><input type="submit" name="login" id="login" value="Login" class="but1"/></td>
            </tr>
          </table>
        </form>
        </td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>