<!-- Realisatsiooni aluseks on võetud:
Login Registration with Email Verification, Forgot Password using PHP
Kasutatud 6.04.2016
http://www.codingcage.com/2015/09/login-registration-email-verification-forgot-password-php.html
-->
<?php
include "config.php";
session_start();
include_once ROOT . 'db/dbconfig.php';
require_once ROOT . 'admin/objects/kasutaja.class.php';
$user_home = new Kasutaja();

if(empty($_GET['id']) && empty($_GET['code']))
{
	$user->redirect('index.php');
}

if(isset($_GET['id']) && isset($_GET['code']))
{
	$id = base64_decode($_GET['id']);
	$code = $_GET['code'];
	
	$statusY = "Y";
	$statusN = "N";
	
	$stmt = $user->runQuery("SELECT id, staatus FROM kasutajad WHERE id=:uID AND token=:code LIMIT 1");
	$stmt->execute(array(":uID"=>$id,":code"=>$code));
	$row=$stmt->fetch(PDO::FETCH_ASSOC);
	if($stmt->rowCount() > 0)
	{
		if($row['staatus']==$statusN)
		{
			$stmt = $user->runQuery("UPDATE kasutajad SET staatus=:status WHERE id=:uID");
			$stmt->bindparam(":status",$statusY);
			$stmt->bindparam(":uID",$id);
			$stmt->execute();	
			
			$msg = "
		           <div class='alert alert-success'>
				   <button class='close' data-dismiss='alert'>&times;</button>
					  <strong>Kasutaja aktiveerimine õnnestus!</strong> Võite nüüd sisse logida.
			       </div>
			       ";	
		}
		else
		{
			$msg = "
		           <div class='alert alert-error'>
				   <button class='close' data-dismiss='alert'>&times;</button>
					  Kasutaja on juba aktiveeritud. Võite sisse logida!
			       </div>
			       ";
		}
	}
	else
	{
		$msg = "
		       <div class='alert alert-error'>
			   <button class='close' data-dismiss='alert'>&times;</button>
			   <strong>Aktiveerimine ebaõnnestus!</strong> Kasutajat ei leitud. Registreeru <a href='signup.php'>siin</a>
			   </div>
			   ";
	}	
}

?>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Oksjoniportaal</title>

    <!-- Bootstrap Core CSS -->
    <link href="<?php echo ROOT ?>css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="<?php echo ROOT ?>css/custom.css" rel="stylesheet">
</head>

<body>

    <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class="container">

            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/">Oksjoniportaal</a>
            </div>

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li>
                        <a href="#" class="active">Online oksjonid</a>
                    </li>
                    <li>
                        <a href="#">Saalioksjonid</a>
                    </li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                  <li><a href="login.php">Logi sisse</a></li>
                  <li><a href="signup.php">Registreeru</a></li>
              </ul>
          </div>
          <!-- /.navbar-collapse -->
      </div>
      <!-- /.container -->
  </nav>

  <!-- Content -->
  <div class="container">

    <div class="row">

        <div class="col-md-6 col-md-offset-3">
            <h2>Kasutaja aktiveerimine</h2>
            <hr />
<?php if(isset($msg)) { echo $msg; } ?>

</div>
<!-- /.container -->

</div></div>
<?php
include ROOT . "footer.php";
?>
