<?php
include 'include/db.php';
include 'include/connect.php';

$id = $_POST['id'];


if(!empty($id)){
            
              $data['cus_name'] = $_POST['cus_name'];
              $data['cus_tel'] = $_POST['cus_tel'];
              $data['cus_mail'] = $_POST['cus_mail'];
              $data['iv_admin'] = $_POST['iv_admin'];
              $data['iv_date'] = $_POST['iv_date'];
              $data['iv_namepro'] = $_POST['iv_namepro'];
              $data['iv_codepro'] = $_POST['iv_codepro'];
              $data['pro_datego'] = $_POST['pro_datego'];
              $data['pro_dateback'] = $_POST['pro_dateback'];
              $data['adult_price'] = $_POST['adult_price'];
              $data['adult_num'] = $_POST['adult_num'];
              $data['c_price'] = $_POST['c_price'];
              $data['c_num'] = $_POST['c_num'];
              $data['nb_price'] = $_POST['nb_price'];
              $data['nb_num'] = $_POST['nb_num'];
              $data['s_price'] = $_POST['s_price'];
              $data['s_num'] = $_POST['s_num'];
              $data['custom1_name'] = $_POST['custom1_name'];
              $data['custom1_price'] = $_POST['custom1_price'];
              $data['custom1_num'] = $_POST['custom1_num'];
              $data['custom2_name'] = $_POST['custom2_name'];
              $data['custom2_price'] = $_POST['custom2_price'];
              $data['custom2_num'] = $_POST['custom2_num'];
              $data['custom3_name'] = $_POST['custom3_name'];
              $data['custom3_price'] = $_POST['custom3_price'];
              $data['custom3_num'] = $_POST['custom3_num'];
              $data['custom4_name'] = $_POST['custom4_name'];
              $data['custom4_price'] = $_POST['custom4_price'];
              $data['custom4_num'] = $_POST['custom4_num'];
              $data['discount_price'] = $_POST['discount_price'];
              $data['discount_sum'] = $_POST['discount_sum'];
              $data['cus_ads'] = $_POST['cus_ads'];
              $data['mus_price'] = $_POST['mus_price'];
              $data['mus_num'] = $_POST['mus_num'];
              $data['mus_date'] = $_POST['mus_date'];
              $data['date_line'] = $_POST['date_line'];
              $data['cus_de_name'] = $_POST['cus_de_name'];
              $data['cus_de_num'] = $_POST['cus_de_num'];
              $data['cus_de_price'] = $_POST['cus_de_price'];
              $data['cus_de_name2'] = $_POST['cus_de_name2'];
              $data['cus_de_num2'] = $_POST['cus_de_num2'];
              $data['cus_de_price2'] = $_POST['cus_de_price2'];

              $data['cus_de_name3'] = $_POST['cus_de_name3'];
              $data['cus_de_num3'] = $_POST['cus_de_num3'];
              $data['cus_de_price3'] = $_POST['cus_de_price3'];

              $data['custom1_val'] = $_POST['custom1_val'];
              $data['custom2_val'] = $_POST['custom2_val'];
              $data['custom3_val'] = $_POST['custom3_val'];
              $data['custom4_val'] = $_POST['custom4_val'];

              $data['iv_pay'] = $_POST['iv_pay'];


              $data['iv_ref1'] = $_POST['iv_ref1'];
              $data['iv_ref2'] = $_POST['iv_ref2'];
              $data['iv_ref3'] = $_POST['iv_ref3'];
              $data['iv_ref4'] = $_POST['iv_ref4'];
              $data['iv_ref5'] = $_POST['iv_ref5'];

              $data['iv_note'] = $_POST['iv_note'];
              $data['iv_remark'] = $_POST['iv_remark'];

              $data['mus_time'] = $_POST['mus_time'];
              $data['date_line_time'] = $_POST['date_line_time'];


        
    $rs = $db->update('tbiv',$data,'iv_id',$id);

// function send_line_notify($message, $token)
// {
//   $ch = curl_init();
//   curl_setopt( $ch, CURLOPT_URL, "https://notify-api.line.me/api/notify");
//   curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0);
//   curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0);
//   curl_setopt( $ch, CURLOPT_POST, 1);
//   curl_setopt( $ch, CURLOPT_POSTFIELDS, "message=$message");
//   curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
//   $headers = array( "Content-type: application/x-www-form-urlencoded", "Authorization: Bearer $token", );
//   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//   curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
//   $result = curl_exec( $ch );
//   curl_close( $ch );

//   return $result;
// }



// $message = " คุณ ".$_POST['iv_admin']." ได้ออก INVOICE เลขที่  IM".$id." กรุณาเช็ค และ ทำการอนุมัติในระบบ 
// INVOICE : https://www.imaginetourservice.com/ivnew.php?id=".$id." 
// อนุมัติ คลิก https://www.imaginetourservice.com/backend/signin.php ";
// $token = 'J1mGd351Sp6OcILHzsVeOAfFerJ3dnTGnaMvTJe9khz';

// echo send_line_notify($message,$token); 
// function send_line_notify($message, $token)
// {
//   $ch = curl_init();
//   curl_setopt( $ch, CURLOPT_URL, "https://notify-api.line.me/api/notify");
//   curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0);
//   curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0);
//   curl_setopt( $ch, CURLOPT_POST, 1);
//   curl_setopt( $ch, CURLOPT_POSTFIELDS, "message=$message");
//   curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
//   $headers = array( "Content-type: application/x-www-form-urlencoded", "Authorization: Bearer $token", );
//   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//   curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
//   $result = curl_exec( $ch );
//   curl_close( $ch );

//   return $result;
// }



// $message = " คุณ ".$_POST['iv_admin']." ได้ออก INVOICE เลขที่  IM".$id." กรุณาเช็ค และ ทำการอนุมัติในระบบ 
// INVOICE : https://www.imaginetourservice.com/ivnew.php?id=".$id." 
// อนุมัติ คลิก https://www.imaginetourservice.com/b_end_2/login.php ";
// $token = 'J1mGd351Sp6OcILHzsVeOAfFerJ3dnTGnaMvTJe9khz';

// echo send_line_notify($message,$token); 

                
                if($rs){
                    echo '0';
                }  else {
                    echo '00';
                } 
  } else {    
        if($_POST['cus_name'] != "" && $_POST['cus_tel'] != "" && $_POST['cus_mail'] != ""){
        $rs = $db->insert('tbiv',array(
      'cus_name' => $_POST['cus_name'],
        'cus_tel' => $_POST['cus_tel'],
        'cus_mail' => $_POST['cus_mail'],
        'iv_admin' => $_POST['iv_admin'],
        'iv_date' => $_POST['iv_date'],
        'iv_namepro' => $_POST['iv_namepro'],
        'iv_codepro' => $_POST['iv_codepro'],
        'pro_datego' => $_POST['pro_datego'],
        'pro_dateback' => $_POST['pro_dateback'],
        'adult_price' => $_POST['adult_price'],
        'adult_num' => $_POST['adult_num'],
        'c_price' => $_POST['c_price'],
        'c_num' => $_POST['c_num'],
        'nb_price' => $_POST['nb_price'],
        'nb_num' => $_POST['nb_num'],
        's_price' => $_POST['s_price'],
        's_num' => $_POST['s_num'],
        'custom1_name' => $_POST['custom1_name'],
        'custom1_price' => $_POST['custom1_price'],
        'custom1_num' => $_POST['custom1_num'],
        'custom2_name' => $_POST['custom2_name'],
        'custom2_price' => $_POST['custom2_price'],
        'custom2_num' => $_POST['custom2_num'],

        'custom3_name' => $_POST['custom3_name'],
        'custom3_price' => $_POST['custom3_price'],
        'custom3_num' => $_POST['custom3_num'],
        'custom4_name' => $_POST['custom4_name'],
        'custom4_price' => $_POST['custom4_price'],
        'custom4_num' => $_POST['custom4_num'],

        'discount_price' => $_POST['discount_price'],
        'discount_sum' => $_POST['discount_sum'],
        'cus_ads' => $_POST['cus_ads'],
        'mus_price' => $_POST['mus_price'],
        'mus_num' => $_POST['mus_num'],
        'mus_date' => $_POST['mus_date'],
        'mus_time' => $_POST['mus_time'],
        'date_line' => $_POST['date_line'],
        'date_line_time' => $_POST['date_line_time'],
        'tax' => $_POST['tax'],
        'cus_de_name' => $_POST['cus_de_name'],
        'cus_de_num' => $_POST['cus_de_num'],
        'cus_de_price' => $_POST['cus_de_price'],
        'cus_de_name2' => $_POST['cus_de_name2'],
        'cus_de_num2' => $_POST['cus_de_num2'],
        'cus_de_price2' => $_POST['cus_de_price2'],
        'iv_pay' => $_POST['iv_pay'],
        'iv_remark' => $_POST['iv_remark'],

        'custom1_val' => $_POST['custom1_val'],
        'custom2_val' => $_POST['custom2_val'],
        'custom3_val' => $_POST['custom3_val'],
        'custom4_val' => $_POST['custom4_val'],

    ));
        if($rs){

            echo '2';
           
            }else {
                
            echo '00';
            }           
        

  } else {
        echo "3";
    }    
}   
?>

