<?php session_start();

include("includes/db_config.php");
$id=$_GET['id'];
if(isset($_POST['submit']))
{  
    $logo = "https://orangegroceries.com/img/logo.png";
    $logo_width = "100%";
    $logo_height = "";
    // All CSS
    // Body
    $body_title = "Orange Groceries";
    $width_of_mail_body = "80%"; // Please write in % percentage for better view...
    $padding_of_mail_body = "20px";
    $body_background_color = "";
    $body_text_color = "";
    // Header
    $header_background_color = "";
    $header_text_color = "";
    $header_font_size = "";
    $header_font_family = "";
    // Footer
    $footer_background_color = "#2F3B59";
    $footer_text_color = "white";
    $footer_font_size = "10px";
    $footer_font_family = "monospace";
    // Button
    $button_background_color = "#4db7fe";
    $button_text_color = "white";
    $button_font_size = "20px";
    $button_font_family = "monospace";
    $button_padding = "15px";
    $button_border_radius = "10px";
    // Highlight
    $highlight_color = "#4db7fe";
    $highlight_font_size = "25px";
    $highlight_font_family = "monospace";
    // Heading
    $heading_color = "#4db7fe";
    $heading_font_size = "25px";
    $heading_font_family = "monospace";
    // Paragraph
    $paragraph_color = "";
    $paragraph_font_size = "14px";
    $paragraph_font_family = "monospace";
    // Write the email id and team name that you send From
    $from_team = "Orange Groceries";
   $from_email = "support@orangegroceries.com";
   $from_website = "https://orangegroceries.com/index.php";
    extract($_POST);
     $sql_pt="select * from user_payment where id='".$id."'";
     $result_pt = mysqli_query($conn, $sql_pt);
     $res_pt= mysqli_fetch_array($result_pt);
     $plan_id=$res_pt['cart_id'];
     $rid = explode(",",$plan_id);
     $user_id=$_SESSION['id'];
    foreach($rid as $pm_id){
     $status="1";
    $stat="0";
    $sql_paytm ="UPDATE  addto_cart SET payment_status='$status',invoice_id='$stat' WHERE user_id='".$user_id."' and id='".$pm_id."'"; 
    $result_ptm=mysqli_query($conn,$sql_paytm) or die(mysqli_error());
    }
    date_default_timezone_set('Asia/Kolkata');
    $created_at = date( 'Y-m-d h:i:s A', time () );
    //$transactionId=$_POST['transaction_id']; 
    $payment_status="completed";
    /*$tmp_file = $_FILES['proof_code']['tmp_name'];
    $ext = pathinfo($_FILES["proof_code"]["name"], PATHINFO_EXTENSION);
    $rand = md5(uniqid().rand());
    $prfimg = $rand.".".$ext;
    move_uploaded_file($tmp_file,"admin/img/proof/".$prfimg);
    */$statuss=1;
    $sql_pay ="UPDATE  user_payment SET payment_method='$payment_method',pay_status='$payment_status',payable_status='$statuss',created_date='$created_at' WHERE id='".$id."'"; 
    $res_ptm=mysqli_query($conn,$sql_pay) or die(mysqli_error()); 
    if($res_ptm){
    $sql_ss=mysqli_query($conn, "select * from user_payment where id='".$id."'");
    $rowss=mysqli_fetch_array($sql_ss);
    $sql1=mysqli_query($conn, "select * from user_profile where id=".$_SESSION['id']);
    $row1=mysqli_fetch_array($sql1);
    $total_price = $rowss['total_price'];
    $user_id = $_SESSION['id'];
    $email = $row1['email'];
    $name = $row1['fname'];
    $date = date("d-m-Y");
    $to = $email;
    $subject = "Order Placed And Payment Successfully Completed";
    $message = "
                <html>
                    <head>
                        <title>$body_title</title>
                    </head>
                    <body style='background-color: $body_background_color; color: $body_text_color;'>
                        <center>
                            <div style='width: $width_of_mail_body; padding: $padding_of_mail_body;' >
                                <br/><br/>
                                <p style='color: $paragraph_color; font-size: $paragraph_font_size; font-family: $paragraph_font_family;'> 
                                    <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'>
                                        Hi $name,
                                    </span> 
                                    <br/>
                                    Welcome to <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'> $from_team</span>, Your Order Placed with RS.$total_price , Pay On Delivery <br/> Thankyou!!!
                                </p>
                                <br/><br/><br/><br/>
                                <div style='width: 100%; background-color: $footer_background_color; color: $footer_text_color; font-family: $footer_font_family; font-size: $footer_font_size; padding-top: 30px; padding-bottom: 30px;'>
                                    Thanks And Regards
                                    <br/>
                                    <span style='color: white;'>$from_website</span>
                                </div>
                            </div>
                        </center>
                    </body>
                </html>";
    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    // Write your information where you send this mail FROM
    $headers .= 'From: ' .$from_team. ' <' .$from_email. '>' . "\r\n";
    // If Required
   // $headers .= 'Cc: ' .$cc. "\r\n";
    // Chechking Mail Sent or Not
    if( mail($to,$subject,$message,$headers)){
    $sql1=mysqli_query($conn, "select * from user_profile where id=".$_SESSION['id']);
    $row1=mysqli_fetch_array($sql1);
    $phone = $_SESSION['mob_no'];
    $user_id = $_SESSION['id'];
    $email = $row1['email'];
    $name = $row1['fname'];
    $date = date("d-m-Y");
    $to = "support@orangegroceries.com";
    $subject = "Order Placed And Payment Successfully Completed";
     $message = "
                <html>
                    <head>
                        <title>$body_title</title>
                    </head>
                    <body style='background-color: $body_background_color; color: $body_text_color;'>
                        <center>
                            <div style='width: $width_of_mail_body; padding: $padding_of_mail_body;' >
                                <br/><br/>
                                <p style='color: $paragraph_color; font-size: $paragraph_font_size; font-family: $paragraph_font_family;'> 
                                    <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'>
                                        Hi Team,
                                    </span> 
                                    <br/>
                                    Order Placed By <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'> $name</span>, with RS.$total_price , Payment method Is Cash On Delivery ..<br/> !!!
                                </p>
                            </div>
                        </center>
                    </body>
                </html>";
    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
    // Write your information where you send this mail FROM
    $headers .= 'From: ' .$from_team. ' <' .$from_email. '>' . "\r\n";
    // If Required
   // $headers .= 'Cc: ' .$cc. "\r\n";
    // Chechking Mail Sent or Not
     if (! mail("support@orangegroceries.com",$name . " Placed an Order",$message,$headers)){
       echo "<script>alert('Problem in sending email!');</script>";
    } else {
       echo "<script>alert('sended email!');</script>";
    }
    }
          header("location:invoice.php?id=".$_GET['id']);
    } else{
        //exit();
        echo "
            <script> 
                alert('Your Payment Successfully completed, but your pannel is not activated please contact to our support team to activate your pannel!!!'); 
                location.replace('index.php');
            </script>";
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content=" ">
    <meta name="author" content="">
    <title>Orange Groceries</title>
    <?php include("includes/css.php");?> 
	<style>
	label {
    font-size: 15px;
    margin: 0 0 3px;
    font-weight: 600;
    color: #000;
}
	</style>
</head>

<body>
    <?php include("includes/header.php");?>

   
	<section class="page-info section-padding border-bottom topthumb">
        <div class="container-fluid">
            <div class="row"> 
                    <a href="https://orangegroceries.com/index.php"> &nbsp; &nbsp; <span class="mdi mdi-home"></span> &nbsp; Home</a> <span class="mdi mdi-chevron-right"></span> <a href="#">Payment</a>
                </div> 
        </div>
    </section>
    <section class="checkout-page section-padding">
        <div class="container-fluid">
        <?php $id=$_GET['id'];
         $sql_ptm="select * from user_payment where id='".$id."'";
         $result_ptm = mysqli_query($conn, $sql_ptm); 
         $res_ptm= mysqli_fetch_array($result_ptm); ?>   
		<div class="col-xs-12">
						<div class="box box-danger">
							<div class="box-header">
								<div class="row">
									<div class="col-md-5"><h3 class="box-title">Digital Wallet</h3></div>
									<div class="col-md-3"> <h5 style="text-align:center; background-color:#ec1d27; color:#fff;font-weight:700;padding:10px;">Total Amount:  <?php echo $res_ptm['total_price']; ?></h5> 
							 </div>
							 <div class="col-md-3"></div>
									<div class="col-md-1 pull-right"><a href="https://orangegroceries.com/payment.php?id=<?php echo $res_ptm['id']; ?>"><button class="btn btn-success btn-md btn-custom2"><i class="mdi mdi-arrow-left"></i> Back</button></a></div>									 
								</div>
								<hr/>
							</div> 
							 <div class="box-body"> 
							 <div class="row"> 
                                <div class="col-md-8">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="payment-box" align="center"> 
                                         <h4 class="pb-10">Scan QR Code For Payment</h4>
                                        <img src="https://orangegroceries.com/img/paytm.jpg" class="img-responsive" alt="paytm number : 9100454581">
                                    </div>
                                </div>
                            <div class="col-md-4">
                                    <div class="payment-box" align="center"> 
                                        <h4 class="pb-15">Scan QR Code For UPI Payment</h4>
                                        <img src="https://orangegroceries.com/img/anajghar-upi.jpg" class="img-responsive" alt="Number : 9100454581">
                                    </div>
                                </div>
                                 
                            <div class="col-md-4">
                                    <div class="payment-box" align="center"> 
                                        <h4 class="pb-15">Scan QR Code For Bharatpay UPI Payment</h4>
                                        <img src="https://orangegroceries.com/img/bharatpay-upi.jpg" class="img-responsive" alt="Number : 9100454581">
                                    </div>
                                </div>
                                </div>
                                </div>
                                 
								<div class="col-md-4" style="background-color:#bfca02;color:#fff;border-radius:5px; padding-bottom:10px;">
									<div class="box box-danger">
										<div class="box-header">
											<div class="row">
												<div class="col-md-12"> <h5 class="text-center pt-10" style="color:#007848;font-weight:800; text-transform:uppercase;">Please Upload Payment Success Photo Here...</h5> 
											</div>
										</div> 
									</div> <hr/>
									 <div class="box-body"> 
										<div class="payment-pic"> 
											<form method="post" action="" enctype="multipart/form-data">
												<div class="col-md-12">
													<div class="form-group mb-20">
														<label for="">Payment Method</label>
														<select name="payment_method" class="form-control" required="" onchange="yesnoCheck(this);">
															<option value="">Select</option>
															<!-- <option value="Digital Wallet">Digital Wallet</option>
															 --><option value="Cash On Delivery">Cash On Delivery</option>
														   <!--  <option value="2">Bank Transfer</option> -->
														</select>
													</div>
												<div class="form-group mb-20">
													<label for="description">Amount Paid</label>
												  <input class="form-control" placeholder="Enter amount " name="amount" type="text" >
												  <input name="order_id" type="hidden" value="<?php echo $res['order_id']; ?>" >
												  <input name="total_amount" type="hidden" value="<?php echo $famt; ?>" >
												</div>
												<!-- <div class="form-group mb-20" id="ifYes">
													 <label for="">Transaction-Id</label>
													<input type="text" name="transaction_id" placeholder="Transaction ID" class="form-control" >
												</div>
												 <div class="form-group mb-20">
												   <label for="">Upload Photo</label>
													<input type="file" name="proof_code" class="form-control" >
												</div> 
												 --><div class="col-md-12"> 
													<input type="submit" name="submit" class="btn btn-primary btn-lg" value="Upload">
												</div>
											</form>
										</div>
									</div>
								</div>
							</div>  
							</div>  
					</div>
				</div> 
			</div> 
									 
      
            </div> 
        </div>
    </section>
    <?php include("includes/footer.php");?>
    <?php include("includes/js.php");?>
    <script type="text/javascript">function yesnoCheck(that) {
    if (that.value == "Cash On Delivery") {
        document.getElementById("ifYes").style.display = "none";
    } else {
        document.getElementById("ifYes").style.display = "block";
    }
    }
</script>
</body>

</html> 