<?php
   include_once '../../scripts/bd.php';
   
   if(isset($_GET['action'])){
    $action=$_GET['action'];
    if($action=='signup')signup();
    if($action=='signin')signin();
    if($action=='forgot')forgot();
   }
   
   /*function signup(){ 
        $firstname=$_POST["firstname"];
        $lastname=$_POST["lastname"];
        $phone=$_POST["phone"];
        $email=$_POST["email"];
        $imid=$_POST["imid"];
        $imservice=$_POST["imservice"];
        $username=$_POST["username"];
        $password=$_POST["password"];
        $challengequestion=addslashes($_POST["challengequestion"]);
        $answer=$_POST["answer"];
        $paymentname=$_POST["paymentname"];
        $paymentmethod=$_POST["paymentmethod"];
        $paymentinfos=$_POST["paymentinfos"];
        $statut="Under Review";
        $dateadd=date('Y-m-d h:i:s');
        $dateset=date('Y-m-d h:i:s');
        bd::query("INSERT INTO mailer VALUES (NULL, '$firstname', '$lastname', '$phone', '$email', '$imid', '$imservice', '$username', '$password', '$challengequestion', '$answer', '$paymentname', '$paymentmethod', '$paymentinfos', '$statut','$dateadd', '$dateset');");
   }*/
   
   
   function signin(){
       if(isset($_POST["username"]) && isset($_POST["password"])){
       $username=str_replace(array("'","=","".'"'),"",$_POST["username"]);
       $password=str_replace(array("'","=","".'"'),"",$_POST["password"]); 
        
        $data = bd::query("SELECT * FROM account_guest WHERE username='$username'");
        $row  = mysql_fetch_array($data);
        if($row!=null){
           if($row['password']==$password){
               if($row['status'] == 'Active') {
                    session_start();
                    $_SESSION["id-guest"] = $row['id'];
                    $_SESSION["username-guest"] = $row['username'];
                    switch ($row['id']) {
                        case 1: $_SESSION["id-news"]='5';
                            break;
                        case 2: $_SESSION["id-news"]='3';
                            break;

                        default: $_SESSION["id-news"]='0';
                            break;
                    }
                    //$_SESSION['start'] = time();
                    //$_SESSION['expire'] = $_SESSION['start'] + (30*60);
                    //add_log("<span class='badge badge-success'>Logged in sucessfully</span>");
                    header("Location: /app/guest/");
                }else{
                    return 'Your Acount is ' . $row['status'];
                }
            }else{
                return 'Username or Password Not Match';
            }
        }else{
          return 'Username or Password Not Match';
        }
      }
   }
   
   function forgot(){ 
        
   }
   
   /*function add_log($str){
        $mailer=$_SESSION['id-mailer'];
        $ip=$_SERVER["REMOTE_ADDR"];
        $activity=addslashes($str);
        $dateactivity=date('Y-m-d h:i:s');
        bd::query("INSERT INTO mailer_log VALUES (NULL, '$mailer', '$ip', '$activity', '$dateactivity');");
   }*/
   
  