<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";

$txtBillingEmail = $_REQUEST['email'];

 $chk="SELECT user_id FROM " . $tableprefix . "users WHERE email='" . addslashes($txtBillingEmail) . "'";

                        $chk_email_exists = mysql_query($chk);

			$chk_email_exists_num_rows = mysql_num_rows($chk_email_exists);

                        if($chk_email_exists_num_rows > 0){

			$rsObj=mysql_fetch_object($chk_email_exists);
                        
			if($rsObj->user_id!='')
				{

                                    $userid=$rsObj->user_id;


                               // When User wish to purchase as a guest Check Cart Items  Exists for a user  with same email id Modified By Asha ON 08-10-2012

                                  $sql_itmesQ = "SELECT * FROM  ".$tableprefix."cart c
                                                where c.user_id ='".$userid."'  ";

                                 $rs_itemsQ  = mysql_query($sql_itmesQ) or die(mysql_error());
                                 
                                 if($_SESSION["sess_userid"] == ""){
                                     
                                    $updateQ = "UPDATE ".$tableprefix."cart SET user_id = '".$userid."',visitor_cart_id = ''
                                                where visitor_cart_id ='".session_id()."'";
                                    $query    = mysql_query($updateQ) or die(mysql_error());
                                    session_start();
                                    session_regenerate_id();
                                    session_destroy();
                                    unset($_SESSION);
                                    session_start();
                                 }
                                  
                                 if(mysql_num_rows($rs_itemsQ)>0)
                                     {
                                        echo json_encode(array("response"=>"exists","items"=>"exists"));

                                    }
                                    else 
                                        {
                                        echo json_encode(array("response"=>"exists","items"=>"notexists"));
                                    }

                              }
                        }
                        else {
                            
                            echo json_encode(array("response"=>"failure","items"=>"notexists"));
                        }

                        exit ;

?>
