<!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>CMS Ambcom</title>
<style type="text/css">
	/* Login */
	
	#login{
		width: 250px;
		-moz-border-radius: 20px;
		-webkit-border-radius: 20px;
		border-radius:20px;
		margin:100px auto 0;
		padding: 30px;
		-moz-box-shadow:0px 0px 80px #999;
		-webkit-box-shadow:0px 0px 80px #999;
		box-shadow:0px 0px 80px #999;
		background-color:#f5f5f5;
		border:1px solid #D5D5D5
	}
	#login label {
		font-size: 16px;
		color: #666;
		font-weight: bold;
	}
	#login input[type=text], #login input[type=password] {
		font-size: 16px;
		padding: 2px;
		margin:0 0 15px;
		border: 1px solid #999;
		background: #fff;
		width: 100%;
		color:#000;
	}
	#login input[type=text]:hover, #login input[type=password]:hover {
		-moz-box-shadow:0px 0px 5px #999;
		-webkit-box-shadow:0px 0px 5px #999;
		box-shadow:0px 0px 5px #999;
	}
	#login input[type=submit]{
		font-size:16px;
		width:100%;
		text-align:center;
		margin:0 auto;
		padding:2px;
		cursor:pointer;
		border-radius:5px;
		color:#fff;
		text-shadow:1px 1px 0 #3070D5;
		border:1px solid #3079ED;
		font-weight: bold
	}
	
</style>
</head>
<body>
	<?php
		// Abre conexão com o banco //
		include 'connect/db.php';
		db_connect() or die ("Houve erro ao acessar estes dados!");

		// criar novo user no momento da instalação do sistema
		if ($_GET['acao'] == 'install' && $_POST['numRows'] == 0) {
			
			$createUserMaster = mysql_query("INSERT INTO usuarios (nomeUser, emailUser, login, senha, nivelUser) VALUES ('".$_POST['nome']."', '".$_POST['email']."', '".$_POST['login']."', '".sha1($_POST['pass'])."', 1)");

			if ($createUserMaster >= 1) {
				
				echo "<meta HTTP-EQUIV='refresh' CONTENT='0;URL=index.php'>";
			}
		}

		// verifica se já existe algum usuário no banco
		$selectEmptyUsers = mysql_query("SELECT * FROM usuarios");
		$numRows = mysql_num_rows($selectEmptyUsers);

		if ($numRows == 0) {
	?>
			<div id="login">
				<form action="?acao=install" method="post">
					<input type="hidden" name="numRows" value="<?php echo($numRows); ?>">
					<label for="nome">Nome</label>
					<input type="text" name="nome" value="">
					<br />
					<label for="email">Email</label>
					<input type="text" name="email" value="">
					<br />
					<label for="login">Login</label>
					<input type="text" name="login" value="">
					<br />
					<label for="password">Senha</label>
					<input type="password" name="pass" value="">
					<input type="submit" name="virificarLog" value="Install">
				</form> 
			</div>
	<?
		}
		else {
	?>
			<div id="login">
				<form action="miolo.php"  method="post">
					<label for="login">Login</label>
					<input type="text" name="login" value="">
					<br />
					<label for="password">Senha</label>
					<input type="password" name="pass" value="">
					<input type="submit" name="virificarLog" value="Login">
				</form>
				<p><?php echo($_GET['msg']); ?></p> 
			</div>
	<?			
		}
	?>
	
</body>
</html>
