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

$id = $_POST['id'];
$edits = $_POST['edits'];
$day = $_POST['allx'];
    if(!empty($edits) && $_POST['code_p'] != ""){
      for ($i = 1; $i<= (int)$day; $i++){ 
      $idapppro = $_POST['idpro'.$i.''];
      $data2['tour_programe'] = $_POST['code_p'];
      $data2['tour_head'] = $_POST['tour_head'.$i.''];
      $data2['tour_day'] = $_POST['day'.$i.''];

      if($_POST['apppro_B'.$i.'']){
        $B = "1";
      }else{
        $B = "0";
      }
      $data2['apppro_B'] = $B;


      if($_POST['apppro_L'.$i.'']){
        $L = "1";
      }else{
        $L = "0";
      }
      $data2['apppro_L'] = $L;


  if($_POST['apppro_D'.$i.'']){
        $D = "1";
      }else{
        $D = "0";
      }
      $data2['apppro_D'] = $D;

      $ro = $db->update('tb_tour',$data2,'tour_id',$idapppro);   
      }
            
      if($ro){
                echo '0';
                } else{
                echo '00';
                } 
              
      } else {    
       if($_POST['code_p'] != ""){
    for ($i = 1; $i<= (int)$day; $i++){
       $rss = $db->insert('tb_tour',array(
       'tour_programe' => $_POST['code_p'],
       'tour_day' => $_POST['day'.$i.''],
       'tour_head' => $_POST['tour_head'.$i.''],
       'apppro_B' => $_POST['apppro_B'.$i.''],
       'apppro_L' => $_POST['apppro_L'.$i.''],
       'apppro_D' => $_POST['apppro_D'.$i.'']
            ));
          }
       if($rs){
            echo '2';
            }else {
            echo '00';
            }           
        } else {
          echo "3";
        }
}

?>





