<?php 
    include "Admin/config/setup.php";
    session_start();
    date_default_timezone_set("Asia/Kolkata");
    if(isset($_POST['rid'])){
        $user_id = $_POST['userId'];
        $ticket = $_POST['ticket'];
        $order_date = date("Y-m-d H-i-s");
        $rid = $_POST['rid'];
        $tran_id = $_POST['tran_id'];
        
        $pack_sql = $config->query("SELECT * FROM package_master WHERE pack_id = '$rid' ");
        $res = $pack_sql->fetch_assoc();
        $pack_cost = $res['pack_cost'];
        $pack_sub_cate = $res['pack_sub_cate'];
        
        $sub_sql = $config->query("SELECT * FROM sub_category WHERE Sub_Category_id = '$pack_sub_cate' ");
        $sub = $sub_sql->fetch_assoc();
        $cate = $sub['Main_Category_sub'];
        
        $sql = $config->query("INSERT INTO order_master(customer_id, ticket, transaction_id, order_category, order_sub_category, order_package, order_price, order_on, order_status)
        VALUES('$user_id' ,'$ticket' ,'$tran_id' ,'$cate' ,'$pack_sub_cate' ,'$rid' ,'$pack_cost' ,'$order_date' ,1) " );
    }
    if(isset($_POST['urid'])){
        $uid = $_POST['urid'];
        $ticket = $_POST['ticket'];
        $buy_date = date("Y-m-d H-i-s");
        $tran_id = $_POST['tran_id'];
        
        $sql = $config->query("INSERT INTO buypack_master(user_id, ticket, transaction_id, buy_on, buy_status)
        VALUES('$uid' ,'$ticket' ,'$tran_id' ,'$buy_date' ,1) " );
    }
    
    if(isset($_POST['eid'])){
        $eid = $_POST['eid'];
        $uid = $_POST['uid'];
        
        $entry_sql = $config->query("SELECT * FROM event_post WHERE event_id = '$eid' ");
        $entry_res = $entry_sql->fetch_assoc();
        $entry = $entry_res['entry'];
        $entry_fees = $entry_res['entry_fees'];
        
        $subsql = "SELECT * FROM ewallet_master WHERE user_id = '$uid' " ;
        $result = $config->query($subsql);
        $subrow = $result->fetch_assoc();
        $wallet = $subrow['total_amount'] - $entry_fees ;
        
        $sql = "UPDATE ewallet_master SET total_amount = '$wallet' WHERE user_id = '$uid' ;" ;
        $sql .= "INSERT INTO apply_request(user_id, event_id, entry, entry_fees, apply_status) VALUES('$uid', '$eid', '$entry', '$entry_fees', 1) ";
        $res = $config->multi_query($sql);
    }
?>