<?php  
	include '../config.php';     
	
	if(isset($_POST['first_time_adminlogin']))		
	{
	    if($_POST['first_time_adminlogin']==2)
    	{
    	    if($_SESSION['temp_admin_otp']==$_POST['otpno'])
            {
        	   $stmt = $conn->prepare("select * from admin where username=:username and password=:password and roll=1");  
    		   $stmt->bindValue(':username', $_SESSION['temp_adminusername'], PDO::PARAM_STR);
    		   $stmt->bindValue(':password', $_SESSION['temp_adminpassword'], PDO::PARAM_STR);
    		   $stmt->execute();    
    		   $affected_rows = $stmt->rowCount();	
    		   if($affected_rows > 0)
    		   { 
    			  $row = $stmt->fetch(PDO::FETCH_OBJ);
    			  //$_SESSION['admin_username']=$row->username;
    			  //$_SESSION['admin_password']=$row->password; 
    			  
                  define("COOKIE_PATH",ROOTPATH.'/admin/');  
                  define("COOKIE_EXPIRATION", time() + (10 * 365 * 24 * 60 * 60));            			
                  setcookie("admin_username", $row->username,COOKIE_EXPIRATION, COOKIE_PATH);
                    
    			  if($row->roll==1)
    			  {
    				//$_SESSION['admin1'] = 1;
                    setcookie("admin1", 1,COOKIE_EXPIRATION, COOKIE_PATH);
    			  }
        	       echo 1;
        	   }
        	   else 
        	   {
        	     echo 2;
        	     
        	   }
        	  unset($_SESSION['temp_admin_otp']);
        	  unset($_SESSION['temp_adminusername']);
        	  unset($_SESSION['temp_adminpassword']);
        	  unset($_SESSION['wrong_otp']);
        	  die;
            }
    	    else
    	    {  
                $_SESSION['wrong_otp']  = 1;
                echo 0;
                die;
            } 
    	}
	}    
?>