Fastpass

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<?php
if(empty($_SESSION["login"])){

    $_SESSION["login"]=false;
}
$title = "";
if( (empty($_GET["fastpass"])==false && empty($_GET["email"])==false) || (empty($_POST["fastpass"])==false && empty($_POST["email"])==false)){

    $title = "My Rewards Program Dashboard";
}else{

    $title = "Rewards Program";
}
error_reporting(E_ALL);
ini_set("display_errors", 1);

include('../gp/lobby/header_lobby2010.php');

include ('/home/milen2/www/auth/1_time_barcode/cls_database.php');
include ('/home/milen2/functions/functions.php');
include("customer.php");
$location = at_location();
// gmsatkie@yahoo.com 40036+634634
function time_of_day($time){
    $minutes = (int)$time / 10;
    $hour =   floor((int)$minutes / (int)60);
    $minutes = $minutes % 60;
    $PM_AM = "AM";
    if($hour>12){

        $PM_AM = "PM";
        $hour = $hour - 12;
    }
    if($minutes<10){

        $minutes = "0".(string)$minutes;
    }
    return (string)$hour.":".(string)$minutes." ".$PM_AM;

}

?>

<style type="text/css">

#content a{

    color:purple;
}
#alignleft {
    margin-top:10px;
	margin-left:20px;
    width:325px;
	float: left;
    position:relative;
    left:20px;
    height:100px;

    margin-left:50px;
}
.gradient-bg tr{


    /* IE10 Consumer Preview */
    background-image: -ms-linear-gradient(top, #FFFFFF 0%, #BAC5DB 100%);

    /* Mozilla Firefox */
    background-image: -moz-linear-gradient(top, #FFFFFF 0%, #BAC5DB 100%);

    /* Opera */
    background-image: -o-linear-gradient(top, #FFFFFF 0%, #BAC5DB 100%);

    /* Webkit (Safari/Chrome 10) */
    background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #FFFFFF), color-stop(1, #BAC5DB));

    /* Webkit (Chrome 11+) */
    background-image: -webkit-linear-gradient(top, #FFFFFF 0%, #BAC5DB 100%);

    /* W3C Markup, IE10 Release Preview */
    background-image: linear-gradient(to bottom, #FFFFFF 0%, #BAC5DB 100%);
}
#alignright {
    margin-top:10px;
    width:350px;
	float: left;
    border-left-color:black;
    border-left-width: 2px;
    border-left-style:solid;
    position:relative;
    padding-left:50px;
    padding-bottom:50px;
    height:100px;


}

#content{
  font-color:black;
  width:780px !important; /* Firefox */
  width:780px;
  background-color:white;

}

#vehicles {
	font-size: 9px;
	font-weight: bold;



}
#content ul{
    margin-left:30px;
    color:black;
    margin-bottom:20px;

}
#content h3{
    margin-left:5px;
    color:black;
    margin-bottom:20px;


}
hr{
   border-color:black;
    margin-top:20px;

}
p {clear:both;}
#vehicles table,tr,th {
    color:black;
    font-weight:normal;

}
#vehicles table,tr,td {
   font-weight:bold;
   text-align:left;
   font-size:11px;
    color:black;

}
.transaction_contents{
    text-align:center;



}
#transactions table,tr,td{
	color:black;
	text-align:center;
	font-size:11px;



}

#transactionform {
    width:100%;
	font-weight:normal;
    margin-left:100px;


}


</style>
<link href="jquery/css/ui-lightness/jquery-ui-1.10.1.custom.css" rel="stylesheet">
    <script src="jquery/js/jquery-1.9.1.js"></script>
    <script src="jquery/js/jquery-ui-1.10.1.custom.js"></script>
</head>

<body>
<div id="page">
  <div id="contents">
  <script type='text/javascript'>
      document.write("<div id='loading'  style='position:absolute;left:600px;top:300px;background-color: white;'><img src='../gp/club/ajax-loader.gif'><p style='color:black'>&nbsp;&nbsp;&nbsp;Loading please wait...</p></div>");

  </script>
      <h2 class="subhead"><?php echo $title; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h2>

<!--<style type="text/css">
a.red:visited {color:#FF0000;}
a.red:link {color:#F0F;}
</style>-->

<script>
    $(function() {
        $( "#dialog" ).dialog({
            autoOpen: false,
            show: {
                effect: "blind",
                duration: 1000
            },
            hide: {
                effect: "explode",
                duration: 1000
            }
        });
        $("#dialog").dialog( "option", "width", 500 );
        $("#dialog").dialog("close");

        $(".receipt").click(function(){
                    str_email = $("#email_leader").text();
                    $("#dialog").css("visibility","visible");
                    $("#dialog").dialog("open");
                    $("#emailaddress").val(str_email);
                    $("#emailsubject").val("Jax Receipt for SALE ID:"+$(this).attr("id").toString());
                    $("#emailbody").html('<h3>Receipt Information</h3>'+$(this).val());


                }
        );
       $("#send_email").click(function(){

                 str_email =   $("#emailaddress").val();
                 emailsubject =   $("#emailsubject").val().replace('%','&#37;');
                 emailbody =  $("#emailbody").html().replace('%','&#37;');
                 urlstring = "email_link.php?email="+str_email.toString()+"&subject="+emailsubject.toString()+"&body="+emailbody.toString();

                 $.ajax({
                       type: "GET",
                       url: urlstring,
                       dataType: "html",
                     success:function(data) {
                            alert(data);
                     }

                 });

                $("#dialog").dialog("close");

               }
       );




    });

</script>
<div id="dialog" title="Email Receipt" style='visibility: hidden'>
     <table>
         <tr><td>Email Address</td><td><input type="text" id='emailaddress' name="email" size='35'></td></tr>
         <tr><td>Subject</td><td><input type="text" id='emailsubject' name="subject" value="Jax Kar Wash Sale Receipt" size='35'></td></tr>
         <tr><td colspan='2' align="center"><div id='emailbody'></div></td></tr>
         <tr><td colspan='2' align="center"><button id='send_email'>Send Email</button></td></tr>
     </table>
</div>
<div id="content">
<?php
$email = "";
$fastpass = "";
$startdate = "";
$enddate = "";
$transaction_table = "";

if(!empty($_POST["startdate"]) && !empty($_POST["enddate"]) ){

     $startdate = strtotime((string)$_POST["startdate"]);
     $enddate = strtotime((string)$_POST["enddate"]);


}


if((empty($_POST["fastpass"])==false && empty($_POST["email"])==false) ){
   $email = $_POST["email"];
   $fastpass  = $_POST["fastpass"];
}

if((empty($_GET["fastpass"])==false && empty($_GET["email"])==false)){
	$email = $_GET["email"];
   	$fastpass  = $_GET["fastpass"];
}
//
if( $email!="" && $fastpass!="" ){
	$fastpass = (string)str_replace(' ','+',$fastpass);
	$page = empty($_GET["page"])==true ? "" : (string)$_GET["page"];
	$login_info =true;
	$table = "";
	$url = "http://70.90.141.193/group.php?fastpass=$fastpass&email=$email";
	$json = hub_http($url);
	$groupjson = json_decode($json);
    if(!is_array($groupjson)){
        $_SESSION["login"] = false;

        ?>

        <script type='text/javascript'>

              alert("We could not find any records matching this fastpass and email address!");
              history.back();
        </script>

        <?php

    }else{
        $_SESSION["login"] = true;
    }
	
	$group = array();
	foreach($groupjson as $row){
	     $groupleader = "No";

	     if($row->CODE==(string)$fastpass){
		    $groupleader="Yes";
		 
		 }
	     $group[(string)$row->CODE] = array("fastpass"=>(string)$row->CODE,"name"=>(string)$row->NAME,"birthday"=>substr((string)$row->BIRTHDATE,5,5),"groupleader"=>$groupleader,"vehicle"=>vehicle((string)$row->CODE));
	
	}
    $points = 0;
    $credits = 0;
	foreach($group as $punches_points){
        $credits   += (int)$punches_points["vehicle"]["credits_earned"]  - (int)$punches_points["vehicle"]["credits_used"];
        $points +=  (int)$punches_points["vehicle"]["points_earned"] - (int)$punches_points["vehicle"]["points_used"];

    }

	$html = "";
	$groupleaderhtml = "";
	$grouplackies = "";
    $count = 0;
    $leader_bd = 0;

	foreach($group as $object){
	    $grouped_fastpass = $object["fastpass"];
		$name = $object["name"];
		$birthday = $object["birthday"];

		if($object["groupleader"]=="Yes"){
			$groupleaderhtml  .= "$grouped_fastpass<br>";
			$groupleaderhtml .= "$name<br>";
			$groupleaderhtml .= "<strong id='email_leader' style='font-size:13px;font-weight:normal;background-color:white;color:black;font-weight:bold;'>$email</strong>";
		    $leader_bd = $birthday;
		}else{

         if(!strpos($grouped_fastpass,"~")){
            $count += 1;

		    $grouplackies .= "<tr><td style='text-align:left'>$grouped_fastpass&nbsp;&nbsp;</td><td>$name&nbsp;&nbsp;&nbsp;&nbsp;</td><td>$birthday&nbsp;&nbsp;</td></tr>";
         }
		}
			
	
	}

    //if($count<4){
       // $grouplackies .= "<tr><td colspan='3' style='text-align:center'><a href='http://jaxkarwash.com/grouping/'>Group More Vehicles (Max 4)</a></td></td>";
    //}

    $vehicle = vehicle($fastpass);
	$credits_earned = (int)$credits;
	$points_earned  = $points;

		
	$groupleaderhtml = "<table cellpadding='15'><tr><td><strong style='font-size:13px;font-weight:normal;background-color:white;color:black;'>VEHICLE INFORMATION FOR:</strong><br/>$groupleaderhtml<br>Punches: $credits_earned<br>Points: $points_earned<br/>Birthday: $leader_bd</td></tr></table>";
	$tableheaders  =  "<tr><th>GROUPED VEHICLES</th><th>NAME</th><th>BIRTHDAY</th></tr>";
    $tableheaders = $count==0 ? "" : $tableheaders;
	$table = "<table>$tableheaders$grouplackies</table>";

	$html = "<p id='vehicles'>
				  <div id='alignleft'>$groupleaderhtml</div>
				  <div id='alignright'>$table</div></p><hr>";
    echo $html;
	
	    // for groups look at sale and find the lowest number. Once lowest number is found advance the array a step
	    // next
		if($page=="transactions"){

					$transaction_table = "<table border='1' class='gradient-bg' style='background-color:#FFF;border-color:#000000;border-style:solid;border-width:2px;width:100%'><tr><th>Date</th><th>Time</th><th>Site</th><th>Fastpass Number</th><th>Shift</th><th>Terminal</th><th>Transaction Contents</th><tr>";
				    $sales = $vehicle["SALE"];
					$grouped = empty($_POST["showall"])==true ? "" : $_POST["showall"];
					
					if($grouped=="yes"){
					 
					/*
                        foreach($group as $key=>$object){


                                 $group[$key]["vehicle"]  = vehicle((string)$key);


                        }
					*/
                    $number_of_vehicles = sizeof($group);
                    $number_of_finished = 0;
                    $sales = array();
                    $finished_vehicles = array();
                    $firstsale = array("fastpass"=>"","saleid"=>"0","saledate"=>10000000000000);
					while($number_of_finished<$number_of_vehicles){


                        foreach($group as $key=>$vehicle){

                            if(in_array($key,$finished_vehicles)==false){
                                $sale = current($group[$key]["vehicle"]["SALE"]);

                                $saleid = key($sale);


                                $saledate =  strtotime($sale[$saleid]["DATE"]);

                                if($saledate<=$firstsale["saledate"]){

                                    $firstsale["saleid"]= $saleid;
                                    $firstsale["saledate"] = $saledate;
                                    $firstsale["fastpass"] = $key;
                                }

                            }

                        }

						  $currentfastpass = $firstsale["fastpass"];

						    $currentsale = current($group[$firstsale["fastpass"]]["vehicle"]["SALE"]);
							$sdate = strtotime($currentsale["DATE"]);

                            $saleid = $currentsale["SALEID"];
                            $last = next($group[$firstsale["fastpass"]]["vehicle"]["SALE"]);
                            $status = $currentsale["SALESTATUS"];
                            if((($startdate=="" && $enddate=="") || ($sdate>=$startdate && $sdate<=$enddate)) && $status!="Adjusted"  ){


                                if(is_array($currentsale["ITEMS"])){
                                    $shift = $currentsale["SHIFT"];
                                    $time = time_of_day($currentsale["TIME"]); //"time";
                                    $location = $currentsale["SITE"];
                                    $terminal = $currentsale["TERMINAL"];
                                    $date = date("M j,Y",$sdate);
                                    $salestring = "";
                                    if($location["at_location"]){
                                        $salestring  =   "<br>$saleid";
                                    }
                                    $transaction_table .= "<tr>";
                                    $transaction_table .= "<td>$date $salestring</td>";

                                    $transaction_table .= "<td>$time</td>";
                                    $transaction_table .= "<td>$location</td>";
                                    $transaction_table .= "<td>$currentfastpass</td>";
                                    $transaction_table .= "<td>$shift</td>";
                                    $transaction_table .= "<td>$terminal</td>";
                                    $transaction_table .= "<td class='transaction_contents'>".transaction_contents($currentsale)."</td>";
                                    $transaction_table .= "</tr>";
                                }
                            }
						
						  
						  
						  if($last==false){
						    $number_of_finished +=1;
						    $finished_vehicles[] = $currentfastpass;
						  }
					  }
					
					  
					}else{
							foreach($sales as $key=>$sale){
								 $shift = $sale["SHIFT"];
								 $time = time_of_day($sale["TIME"]); //"time";
								 $location = $sale["SITE"];
								 $terminal = $sale["TERMINAL"];
                                $sdate = strtotime($sale["DATE"]);
                                $date = date("M j,Y",$sdate);
                                $status = $sale["SALESTATUS"];
                                if((($startdate=="" && $enddate=="") || ($sdate>=$startdate && $sdate<=$enddate))  && $status!="Adjusted"  ){
								 $transaction_table .= "<tr>";
                                  $salestring = "";
                                  if($location["at_location"]){
                                    $salestring  =   "<br>$key";
                                  }
								  $transaction_table .= "<td>$date $salestring</td>";
								  $transaction_table .= "<td>$time</td>";
								  $transaction_table .= "<td>$location</td>";
								  $transaction_table .= "<td>$fastpass</td>";
								  $transaction_table .= "<td>$shift</td>";
								  $transaction_table .= "<td>$terminal</td>";
                                  $trans_content = transaction_contents($sale);

								  $transaction_table .= "<td class='transaction_contents'>".$trans_content."</td>";
                                  $send_email = "<button id='$key' class='receipt' value='$trans_content'>Email</br>Receipt</button> ";
                                    $transaction_table .= "<td align='left'>".$send_email."</td>";

                                }
								 
							}
					}
	                $transaction_table .= "</table>";
					//echo $transaction_table;
		}
	?>
        <script type="text/javascript">
                $(function() {
                    $( "#startdate" ).datepicker();
                    $( "#enddate" ).datepicker();
                });
        </script>
         <div id="transactionform">
            <form method='post' action="login.php?page=transactions&fastpass=<?php echo $fastpass; ?>&email=<?php echo $email; ?>">
            <table style="font-weight:normal" cellspacing="20px">
            <tr><td>From:</td><td><input type="text" id="startdate"  name="startdate" /></td>
                <td>To:</td><td><input type="text" id="enddate" name="enddate" /></td></tr>
                <tr><td colspan="4"><input name="showall" type="checkbox" value="yes" title="If you have more than one vehicle, and have previously 'Grouped' them, check this box to display the transactions for all your 'Grouped' vehicles."  />&nbsp;INCLUDE GROUPED VEHICLES</td></tr>
                <tr><td colspan="4" align="center"><input type="submit" value="GO"/></td></tr>
            </table>
            </form>
        </div>

        <?php $transaction_table = $transaction_table != "" ? '<div id="transactions" style="background-color:#0066CC;padding:20px;">'.$transaction_table."<br><i>
        Any FastPass number starting with a ~ indicates that the FastPass has been deactivated. </i></div>" : "";
              echo $transaction_table;
        ?>


    <?
}
else{
?>
<br/>
<h3>Welcome Rewards Customer!</h3>
<h3>Access your account to view your:</h3>
<ul>
<li>Punches</li>
<li>Points</li>
<li>Transaction History</li>
</ul>
<script>
    $(function() {
        $( document ).tooltip();


        $("#fastpasserror").hide();
        $("#emailerror").hide();
        $("#fastpass").focusout(function(){
            fastpass = $("#fastpass").val();
            pattern = "[0-9][0-9][0-9][0-9][0-9][+][0-9][0-9][0-9][0-9][0-9][0-9]";
            var patt=new RegExp(pattern);
            if(!patt.test(fastpass)){
                $("#fastpasserror").show();
                $("#fastpasserror").effect("shake");
            }else{
                $("#fastpasserror").hide();

            }

        });
        $("#email").focusout(function(){

            str_email = $("#email").val();

            pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
            var patt=new RegExp(pattern);
            if(!patt.test(str_email)){
                $("#emailerror").show();
                $("#emailerror").effect("shake");
            }else{
                $("#emailerror").hide();

            }

        });
        // /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/


    });
</script>
<h3>Vehicles must be registered to access your account. If your vehicle isn't registered, <a href="/fastpass/">click here</a>.<br> 
  Login to your account will be available THE DAY AFTER your FastPass is registered.
</h3>
<form method='post'>
<table>
<tr><td width="176" align="right">Fast Pass Number:</td><td width="144"><input type="text" id="fastpass" name="fastpass"  /></td></tr>
<tr><td align="right">Email Address:</td><td><input id="email" type="text" name="email" /></td></tr>
<tr><td colspan='2' align="center"><p>&nbsp;
  </p>
    <p align="center">
      <input type="submit" value="   GO   "/>
      <br>
    </p>
    <p align="center">&nbsp; </p>
    <p align="center">Note: Your 11th Wash Free will automatically be issued when we scan your FastPass if eligible. </p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p></td></tr>
</table>
    <p>&nbsp;</p>
    <div class="ui-widget">
      <div id="fastpasserror" class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
          <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
                <strong>Alert:</strong> Invalid FastPass!</p>
        </div>
    </div>
    <div class="ui-widget">
        <div id="emailerror" class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
            <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
                <strong>Alert:</strong> Invalid email address!</p>
        </div>
    </div>
</form>

<?php } ?>
</div>
</div>

<div class="clear">
    <div align="left"><p>&nbsp;</p><br />
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
        <br/>
    </div>
</div>

<br />
  </div>

  <?php // include('../navbottom.php'); ?>
<script type="text/javascript">
    $(function() {
        // Handler for .ready() called.
        $('#loading').remove();
    });


</script>

</body>
</html>