<?PHP session_start(); 
	// Call config file
	include("config.php");
	// logout code
	if ($_GET['stat'] == 'logout' )
		{
			$_SESSION['P1_Login_uid'] 		=	'';
			$_SESSION['P1_login_error1']	=	'';
			$_SESSION['P1_Login_name'] 	=   '';
			header("Location: login.php"); 		
		}
	// login code
	if ($_GET['stat'] == 'login') {   		
			$LoginU=$_POST['username'];
			$LoginP=md5($_POST['password']);
			//$LoginP=$_POST['password'];
			$query = mysql_query("SELECT * FROM p1_powers where username = '$LoginU' and password  = '$LoginP' and stop_user = 0"); 		
			if (mysql_num_rows($query) <> "0")
				{
					$_SESSION['P1_Login_uid'] = mysql_result($query,0,"uid");
					$_SESSION['P1_Login_name'] = mysql_result($query,0,"fullname");
					// load the power of the user
					$_SESSION['P1_Login_appointments'] = mysql_result($query,0,"appointments");
					$_SESSION['P1_Login_factory'] = mysql_result($query,0,"factory");
					$_SESSION['P1_Login_delivery'] = mysql_result($query,0,"delivery");
					$_SESSION['P1_Login_fixing'] = mysql_result($query,0,"fixing");
					$_SESSION['P1_Login_search'] = mysql_result($query,0,"search");
					$_SESSION['P1_Login_add_new_date'] = mysql_result($query,0,"add_new_date");
					$_SESSION['P1_Login_control_user'] = mysql_result($query,0,"control_user");
					$_SESSION['P1_Login_report_os'] = mysql_result($query,0,"report_os");
					$_SESSION['P1_Login_manage_sales'] = mysql_result($query,0,"manage_sales");
					
					header("Location: index.php"); 
				}else{
					$_SESSION['P1_login_error1']='Error in login';
				}	
	} 
	//Html code
?>
<!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=windows-1256" />
<title><? echo $life_software;?></title>
<link href="mstyle.css" rel="stylesheet" type="text/css" />
<link href="wstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center">
  <p><img src="images/login_icon.jpg" width="133" height="135" /></p>
  <form id="form1" name="form1" method="post" action="login.php?stat=login">
    <p><? echo $_SESSION['P1_login_error1']?>&nbsp;</p>
    <table width="300" border="0">
      <tr>
        <td class="td2">UserName</td>
        <td class="td2"><input name="username" type="text" id="username" /></td>
      </tr>
      <tr>
        <td class="td2">Password</td>
        <td class="td2"><input name="password" type="password" id="password" /></td>
      </tr>
      <tr>
        <td class="td2">&nbsp;</td>
        <td class="td2"><input name="Submit" type="submit" class="Submit" id="Submit" value="   Login   " /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
       <td><div align="center"></div></td>
      </tr>
    </table>
    <p>&nbsp;</p>
  </form>
  <p>&nbsp;</p>
</div>
</body>
</html>
