<?php

require_once "./conexao.php";
require "./DaoContato.php";
require "./DaoUsuario.php";
session_start();
//Cadastrar Conta
if (isset($_POST['nome']) && isset($_POST['username']) && isset($_POST['senha'])) {
    echo '<pre>';
    $us = new DaoUsuario();
    $usuario = $us->populausuario($_POST);
    $u[] = addslashes($usuario->getUsername());
    $u[] = addslashes($usuario->getNome());
    $u[] = addslashes($usuario->getSenha());
    $us->InserirUsuario($u);
    echo '<meta http-equiv="refresh" content="0;url=form.php">';
}
if (isset($_POST['opcao'])) {
    if ($_POST['opcao'] == 1) {
        $where = $_POST['username'];
        $query = "SELECT * FROM usuario WHERE username = '******'";
        $result = mysql_query($query);
        $dados_usuario = mysql_fetch_assoc($result);
        $senha = $dados_usuario['senha'];
        if ($senha == trim($_POST["senha"])) {
            echo '<script>';
            echo 'alert("Bem vindo a Agenda Mobile!!!")';
            echo '</script>';
            session_start();
            $_SESSION["username"] = $dados_usuario["username"];
            $_SESSION["nome"] = $dados_usuario["nome_completo"];