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

$id = $_POST['id'];
$day = $_POST['allx'];
$idedit = $_POST['idedit'];
    
    if(!empty($idedit) && $_POST['datego'] != "" && $_POST['dateback'] != ""){

                $data['trip_date_go'] = $_POST['datego'];
                $data['trip_date_back'] = $_POST['dateback'];
                $data['price_size'] = $_POST['price-c'];
                $data['price_start'] = $_POST['price-ad'];
                
    $rs = $db->update('tbtripth',$data,'trip_id',$idedit);
           if($rs){
            echo "0";
           } else {
            echo "00";
           }           

    } else {    
       if($_POST['code'] != ""){
        for ($i = 1; $i<= (int)$day; $i++){
        $rs = $db->insert('tbtripth',array(
       'trip_programe_code' => $_POST['code'],
       'trip_date_go' => $_POST['datego'.$i.''],
       'trip_date_back' => $_POST['dateback'.$i.''],
       'price_size' => $_POST['price-c'.$i.''],
       'price_start' => $_POST['price-ad'.$i.'']
            )); 
       }

          if($rs){
            
            echo '2';
           
            }else {
                
            echo '00';
            }           
        
      } else {
        echo "3";
    }         
        
      }



?>





