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

$id = $_POST['id'];
$day = $_POST['allx'];
$idedit = $_POST['edits'];
    
    if(!empty($idedit)){

      for ($i = 1; $i<= (int)$day; $i++){ 
      $idapppro = $_POST['idpro'.$i.''];
      $data2['pass_iv'] = $_POST['code'];
      // $data2['pass_pic'] = $_POST['image_field2'.$i.''];
      $data2['pass_pic'] = $_POST['image_field'.$i.''];
      $data2['pass_name'] = $_POST['name'.$i.''];

      $data2['pass_title_eg'] = $_POST['pass_title_eg'.$i.''];
      $data2['pass_name_eg'] = $_POST['pass_name_eg'.$i.''];
      $data2['pass_lastname_eg'] = $_POST['pass_lastname_eg'.$i.''];
      $data2['pass_title_th'] = $_POST['pass_title_th'.$i.''];
      $data2['pass_name_th'] = $_POST['pass_name_th'.$i.''];
      $data2['pass_lastname_th'] = $_POST['pass_lastname_th'.$i.''];
      $data2['pass_num'] = $_POST['pass_num'.$i.''];

      $ro = $db->update('tbpass',$data2,'pass_id',$idapppro);   
      }
            
      if($ro){
                echo '0';
                } else{
                echo '00';
                }          

    } else {    
       if($_POST['code'] != ""){
        for ($i = 1; $i<= (int)$day; $i++){
        $rs = $db->insert('tbpass',array(
       'pass_iv' => $_POST['code'],
       'pass_pic' => $_POST['image_field2'.$i.''],
       'pass_name' => $_POST['name'.$i.''],

       'pass_title_eg' => $_POST['pass_title_eg'.$i.''],
       'pass_name_eg' => $_POST['pass_name_eg'.$i.''],
       'pass_lastname_eg' => $_POST['pass_lastname_eg'.$i.''],
       'pass_title_th' => $_POST['pass_title_th'.$i.''],
       'pass_name_th' => $_POST['pass_name_th'.$i.''],
       'pass_lastname_th' => $_POST['pass_lastname_th'.$i.''],
        'pass_num' => $_POST['pass_num'.$i.''],


            )); 
       }

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



?>





