<?php require_once '../../masterpage/webservice_master.php';
header("Access-Control-Allow-Origin: *");
extract($_POST);
ini_set('memory_limit','-1');
ini_set('max_execution_time', 0);
ini_set('post_max_size', 200428800);


  
if($lfs_firedoor_survey['firedoor_ID'] == 0){
        

      define('UPLOAD_DIR', '../../../images/door_images/');
      //------for door plug images--------------------
        if($lfs_firedoor_survey['door_plug_img1']!=''){
      $img1 = $lfs_firedoor_survey['door_plug_img1'];
      $img1 = str_replace('data:image/png;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
      $data1 = base64_decode($img1);
      $door_plug_img1 = uniqid() . '.png';
      $file1 = UPLOAD_DIR .$door_plug_img1 ;
      $success1 = file_put_contents($file1, $data1);
      }else{
        $door_plug_img1='';
      }
       if($lfs_firedoor_survey['door_plug_img2']!=''){
      $img1 = $lfs_firedoor_survey['door_plug_img2'];
      $img1 = str_replace('data:image/png;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
      $data1 = base64_decode($img1);
      $door_plug_img2 = uniqid() . '.png';
      $file1 = UPLOAD_DIR .$door_plug_img2 ;
      $success1 = file_put_contents($file1, $data1);
      }else{
        $door_plug_img2='';
      }

      //-----------------end door plug image section---------

      if($lfs_firedoor_survey['ext_door_image1']!=''){
      $img1 = $lfs_firedoor_survey['ext_door_image1'];
      $img1 = str_replace('data:image/png;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
      $data1 = base64_decode($img1);
      $ext_door_image1 = uniqid() . '.png';
      $file1 = UPLOAD_DIR .$ext_door_image1 ;
      $success1 = file_put_contents($file1, $data1);
      }else{
        $ext_door_image1='';
      }
     if($lfs_firedoor_survey['ext_door_image2']!=''){
      $img2 = $lfs_firedoor_survey['ext_door_image2'];
      $img2 = str_replace('data:image/png;base64,', '', $img2);
      $img2 = str_replace(' ', '+', $img2);
      $data2 = base64_decode($img2);
      $ext_door_image2 = uniqid() . '.png';
      $file2 = UPLOAD_DIR .$ext_door_image2;
      $success2 = file_put_contents($file2, $data2);
      }else{
      $ext_door_image2='';
      }

      if($lfs_firedoor_survey['cont_ass_fire_add_image1']!=''){
      $img1 = $lfs_firedoor_survey['cont_ass_fire_add_image1'];
      $img1 = str_replace('data:image/png;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
      $data1 = base64_decode($img1);
      $cont_ass_fire_add_image1 = uniqid() . '.png';
      $file1 = UPLOAD_DIR .$cont_ass_fire_add_image1 ;
      $success1 = file_put_contents($file1, $data1);
      }else{
        $cont_ass_fire_add_image1='';
      }
     if($lfs_firedoor_survey['cont_ass_fire_add_image2']!=''){
      $img2 = $lfs_firedoor_survey['cont_ass_fire_add_image2'];
      $img2 = str_replace('data:image/png;base64,', '', $img2);
      $img2 = str_replace(' ', '+', $img2);
      $data2 = base64_decode($img2);
      $cont_ass_fire_add_image2 = uniqid() . '.png';
      $file2 = UPLOAD_DIR .$cont_ass_fire_add_image2;
      $success2 = file_put_contents($file2, $data2);
      }else{
      $cont_ass_fire_add_image2='';
      }





      //-------------------------
          /*Door Ordering functionality*/  
   // echo "<pre>";print_r($lfs_firedoor_survey_details);exit;
          $last_door_count = $obj->fetchRow("lfs_firedoor_survey","project_ID = ".$lfs_firedoor_survey['project_ID']." ORDER BY firedoor_ID DESC LIMIT 1");
    $lfs_firedoor_survey_details = $obj->fetchRow("lfs_firedoor_survey","project_ID = ".$lfs_firedoor_survey['project_ID']." and firedoor_ID = ".$lfs_firedoor_survey['firedoor_ID']);

    $oldfloor = $lfs_firedoor_survey_details['floor_No'];
    $ordernumber= (int)$lfs_firedoor_survey_details['firedoor_Order'];
    if($oldfloor != $floor_No){
      /*if the floor is changed then*/

      /*
      Ordering Logic
      Minus Ordering for Basement eg. -10001
      Single digit ordering for Ground floor eg. 1
      Five Digit ordering for normal floor eg. 10001
      Six Digit ordering for normal Customfloor eg. 120001
      Seven Digit Ordering for text Custom floor eg.2010001
      */


      $doors = $obj->fetchRow("lfs_firedoor_survey","project_ID='".$lfs_firedoor_survey['project_ID']."' AND floor_No = '".$lfs_firedoor_survey['floor_No']."' order by firedoor_Order DESC LIMIT 1");
      //echo "<pre>";print_r($doors);exit;
      if(count($doors) > 0){
        $lastorder = ($doors['firedoor_Order'] != NULL || $doors['firedoor_Order'] !="")?(int)$doors['firedoor_Order']:0;
      }else{
        $lastorder = 0;
      }
      //echo $lastorder."<br>";

      if($lfs_firedoor_survey['floor_No'] == "G"){
        /*For Ground Floor*/
        $startupenum = $lastorder+1;

      }else if($lfs_firedoor_survey['floor_No'] == "B"){
        /*For Basement Floor*/
        if($lastorder != 0){
          $tempfloor = $lastorder-1;
          $startupenum = $tempfloor;  // Apend three zero

        }else{
          $tempfloor = $lastorder+1;
          $startupenum = "-1".sprintf("%04d", $tempfloor);
        }


      }else{

        if((int)$lfs_firedoor_survey['floor_No'] > 100 ){ // here floor id will be checked.
          /*For Custom Floor*/
          $tempfloor = $lastorder+1;
          $selfloor = $obj->fetchRow("lfs_custom_floor","floorNo='".$lfs_firedoor_survey['floor_No']."' AND project_ID=".$lfs_firedoor_survey['project_ID']);
          $getfloorno = $selfloor['floorNo'];
          $getfloororder = $selfloor['floor_Order'];
          /*Below condition is for checking whether custome floor is for normal floor or custom named floor*/
          if((int)$getfloorno == 0){
            /*Customenamed floor*/
            
            if($lastorder != 0){
              $startupenum = $tempfloor;
            }else{
              $startupenum = $lfs_firedoor_survey['floor_No'].sprintf("%04d", $tempfloor);
            }
          }else{
            /*Regular floor's Custome floor*/
            if($lastorder != 0){
              $startupenum = $tempfloor;
            }else{
              $startupenum = $getfloorno.$getfloororder.sprintf("%04d", $tempfloor);  
            }
          }
        }else{
          /*For Normal Floor*/
          $tempfloor = $lastorder+1;
          //echo $tempfloor;exit;
          if($lastorder != 0){
            $startupenum = $tempfloor;   // Apend two zero
          }else{  
            $startupenum = $lfs_firedoor_survey['floor_No'].sprintf("%03d", $tempfloor);   // Apend two zero
          }

        }        
      }
      $ordernumber = (int)$startupenum;
    }

    /*Door Ordering functionality*/
    $last_door_count = $obj->fetchRowAll("lfs_firedoor_survey","project_ID = ".$lfs_firedoor_survey['project_ID']." ORDER BY firedoor_ID DESC");
    if($last_door_count){
      $door_count=count($last_door_count)+1;
    }else{
      $door_count=1;
    }
    $createdDate=date('Y-m-d H:i:s',strtotime($lfs_firedoor_survey['createdDate']));
     $updatedDate=date('Y-m-d H:i:s',strtotime($lfs_firedoor_survey['updatedDate']));
      if($lfs_firedoor_survey['door_plug']!='1' && $lfs_firedoor_survey['door_plug']!='0'){
     $lfs_firedoor_survey['door_plug']='2';   
    }
      $field_new_fire_survey = array('firedoor_Order','project_ID','door_reference','Barcode_ref','floor_No','property_no_Name','location','client_door_reference','door_count','ext_door_image1','ext_door_image2','floor_plan','full_access','reason_no_access','add_info','manufaturer','installer','type_of_door','type_of_dooradd','construction_type','construction_typeadd','fanlight_present','sidelight_present','vision_panel','inteded_fire_rating','continue_assess_fire_door','na_immediate_fail','asses_fire_rated','fire_rate_asses_reason','cont_ass_fire_art_17','cont_ass_fire_art_18','cont_ass_fire_art_20','cont_ass_fire_add_field','cont_ass_fire_add_image1','cont_ass_fire_add_image2','door_plug','door_plug_img1','door_plug_img2','door_plug_description','test_evidance','hanging','hanging_NA','structural_opening','structural_opening_NA','leaf_size','leaf_size_NA','leaf_color','leaf_color_NA','leaf_colortxt','frame_color','frame_colortxt','frame_color_NA','door_closer_type','name_known_door','O_Lock','name_known_lock','O_Lock_add_field','door_status','door_statustxt','summary_of_findings','summary_add_info','certification','lfs_fire_door_result','isRepairs','operative_Status','Operative_comments','Operative_updated','createdBy','updatedBy','createdDate','updatedDate','isInstallation','last_door_data','NextMaintenanceDate','isActive','isDelete');

      $value_new_fire_survey = array($ordernumber,$lfs_firedoor_survey['project_ID'],$lfs_firedoor_survey['door_reference'],$lfs_firedoor_survey['Barcode_ref'],$lfs_firedoor_survey['floor_No'],$lfs_firedoor_survey['property_no_Name'],$lfs_firedoor_survey['location'],$lfs_firedoor_survey['client_door_reference'],$door_count,$ext_door_image1,$ext_door_image2,$lfs_firedoor_survey['floor_plan'],$lfs_firedoor_survey['full_access'],$lfs_firedoor_survey['reason_no_access'],$lfs_firedoor_survey['add_info'],$lfs_firedoor_survey['manufaturer'],$lfs_firedoor_survey['installer'],$lfs_firedoor_survey['type_of_door'],$lfs_firedoor_survey['type_of_dooradd'],$lfs_firedoor_survey['construction_type'],$lfs_firedoor_survey['construction_typeadd'],$lfs_firedoor_survey['fanlight_present'],$lfs_firedoor_survey['sidelight_present'],$lfs_firedoor_survey['vision_panel'],$lfs_firedoor_survey['inteded_fire_rating'],$lfs_firedoor_survey['continue_assess_fire_door'],$lfs_firedoor_survey['na_immediate_fail'],$lfs_firedoor_survey['asses_fire_rated'],$lfs_firedoor_survey['fire_rate_asses_reason'],$lfs_firedoor_survey['cont_ass_fire_art_17'],$lfs_firedoor_survey['cont_ass_fire_art_18'],$lfs_firedoor_survey['cont_ass_fire_art_20'],$lfs_firedoor_survey['cont_ass_fire_add_field'],$cont_ass_fire_add_image1,$cont_ass_fire_add_image2,$lfs_firedoor_survey['door_plug'],$door_plug_img1,$door_plug_img2,$lfs_firedoor_survey['door_plug_description'],$lfs_firedoor_survey['test_evidance'],$lfs_firedoor_survey['hanging'],$lfs_firedoor_survey['hanging_NA'],$lfs_firedoor_survey['structural_opening'],$lfs_firedoor_survey['structural_opening_NA'],$lfs_firedoor_survey['leaf_size'],$lfs_firedoor_survey['leaf_size_NA'],$lfs_firedoor_survey['leaf_color'],$lfs_firedoor_survey['leaf_color_NA'],$lfs_firedoor_survey['leaf_colortxt'],$lfs_firedoor_survey['frame_color'],$lfs_firedoor_survey['frame_colortxt'],$lfs_firedoor_survey['frame_color_NA'],$lfs_firedoor_survey['door_closer_type'],$lfs_firedoor_survey['name_known_door'],$lfs_firedoor_survey['O_Lock'],$lfs_firedoor_survey['name_known_lock'],$lfs_firedoor_survey['O_Lock_add_field'],$lfs_firedoor_survey['door_status'],$lfs_firedoor_survey['door_statustxt'],$lfs_firedoor_survey['summary_of_findings'],$lfs_firedoor_survey['summary_add_info'],$lfs_firedoor_survey['certification'],$lfs_firedoor_survey['lfs_fire_door_result'],$lfs_firedoor_survey['isRepairs'],$lfs_firedoor_survey['operative_Status'],$lfs_firedoor_survey['Operative_comments'],$lfs_firedoor_survey['Operative_updated'],$lfs_firedoor_survey['createdBy'],$lfs_firedoor_survey['updatedBy'], $createdDate,$updatedDate,$lfs_firedoor_survey['isInstallation'],$lfs_firedoor_survey['last_door_data'],$lfs_firedoor_survey['NextMaintenanceDate'],$lfs_firedoor_survey['isActive'],$lfs_firedoor_survey['isDelete']);

       
        $Ins_firedoor_ID = $obj->insert($field_new_fire_survey,$value_new_fire_survey,'lfs_firedoor_survey');

       if(isset($_POST['lfs_firedoor_survey_color']) && $lfs_firedoor_survey_color['isDelete']!="1"){
//FOR COLOR TABLE

         $createdDate=date('Y-m-d H:i:s',strtotime($lfs_firedoor_survey_color['createdDate']));
     $updatedDate=date('Y-m-d H:i:s',strtotime($lfs_firedoor_survey_color['updatedDate']));
      $field_new_fire_survey_color = array('firedoor_ID','project_ID','full_access','reason_no_access','add_info','manufaturer','installer','type_of_door','type_of_door_add_info','construction_type','construction_type_add_info','fanlight_present','sidelight_present','vision_panel','inteded_fire_rating','continue_assess_fire_door','cont_ass_fire_art_17','cont_ass_fire_art_18','cont_ass_fire_art_20','asses_fire_rated','fire_rate_asses_reason','door_plug','door_plug_description','test_evidance','hanging','hanging_NA','structural_opening','structural_opening_NA','leaf_size','leaf_color','leaf_color_NA','frame_color','door_closer_type','O_Lock','door_status','summary_of_findings','summary_add_info','certification','createdDate','updatedDate','isActive','isDelete');
      $value_new_fire_survey_color = array($Ins_firedoor_ID,$lfs_firedoor_survey_color['project_ID'],$lfs_firedoor_survey_color['full_access'],$lfs_firedoor_survey_color['reason_no_access'],$lfs_firedoor_survey_color['add_info'],$lfs_firedoor_survey_color['manufaturer'],$lfs_firedoor_survey_color['installer'],$lfs_firedoor_survey_color['type_of_door'],$lfs_firedoor_survey_color['type_of_door_add_info'],$lfs_firedoor_survey_color['construction_type'],$lfs_firedoor_survey_color['construction_type_add_info'],$lfs_firedoor_survey_color['fanlight_present'],$lfs_firedoor_survey_color['sidelight_present'],$lfs_firedoor_survey_color['vision_panel'],$lfs_firedoor_survey_color['inteded_fire_rating'],$lfs_firedoor_survey_color['continue_assess_fire_door'],$lfs_firedoor_survey_color['cont_ass_fire_art_17'],$lfs_firedoor_survey_color['cont_ass_fire_art_18'],$lfs_firedoor_survey_color['cont_ass_fire_art_20'],$lfs_firedoor_survey_color['asses_fire_rated'],$lfs_firedoor_survey_color['fire_rate_asses_reason'],$lfs_firedoor_survey_color['door_plug'],$lfs_firedoor_survey_color['door_plug_description'],$lfs_firedoor_survey_color['test_evidance'],$lfs_firedoor_survey_color['hanging'],$lfs_firedoor_survey_color['hanging_NA'],$lfs_firedoor_survey_color['structural_opening'],$lfs_firedoor_survey_color['structural_opening_NA'],$lfs_firedoor_survey_color['leaf_size'],$lfs_firedoor_survey_color['leaf_color'],$lfs_firedoor_survey_color['leaf_color_NA'],$lfs_firedoor_survey_color['frame_color'],$lfs_firedoor_survey_color['door_closer_type'],$lfs_firedoor_survey_color['O_Lock'],$lfs_firedoor_survey_color['door_status'],$lfs_firedoor_survey_color['summary_of_findings'],$lfs_firedoor_survey_color['summary_add_info'],$lfs_firedoor_survey_color['certification'],$createdDate,$updatedDate,$lfs_firedoor_survey_color['isActive'],$lfs_firedoor_survey_color['isDelete']);


  $firedoor_color = $obj->insert($field_new_fire_survey_color,$value_new_fire_survey_color,'lfs_firedoor_survey_color');
}
  //---------------------for category na feature----------------------
if($_POST['lfs_fds_category_na_feature']){
foreach ($_POST['lfs_fds_category_na_feature'] as $lfs_fds_category_na_feature) {
 
        if($lfs_fds_category_na_feature['isDelete']!="1"){
            $field_na_feature_field=array('project_ID','firedoor_ID','category_ID','NA','createdDate','updatedDate');
            $value_na_feature_val=array($lfs_fds_category_na_feature['project_ID'],$Ins_firedoor_ID,$lfs_fds_category_na_feature['category_ID'],$lfs_fds_category_na_feature['NA'],$lfs_fds_category_na_feature['createdDate'],$lfs_fds_category_na_feature['updatedDate']);
            $lfs_fds_category_na_featureins = $obj->insert($field_na_feature_field,$value_na_feature_val,'lfs_fds_category_na_feature');
        }
}
}
  //------------For  FIREDOOR QUESTION ANSWER ------------------------------------------
if($_POST['lfs_fire_door_question_answ']){
    foreach ($_POST['lfs_fire_door_question_answ'] as $lfs_fire_door_question_answ) {
       if($lfs_fire_door_question_answ['answer']==''){
                  $lfs_fire_door_question_answ['answer']=3;
                }
          if($lfs_fire_door_question_answ['isDelete']!="1"){
              $lfs_fire_door_question_answ_field = array('firedoor_ID','cat_question_ID','answer','color','isDelete');
              $lfs_fire_door_question_answ_value = array($Ins_firedoor_ID,$lfs_fire_door_question_answ['cat_question_ID'],$lfs_fire_door_question_answ['answer'],$lfs_fire_door_question_answ['color'],$lfs_fire_door_question_answ['isDelete']);
              $lfs_fire_door_question_answins = $obj->insert($lfs_fire_door_question_answ_field,$lfs_fire_door_question_answ_value,'lfs_fire_door_question_answ');
          }
    }
}
if($_POST['lfs_full_door_cate_additional_fields']){
foreach ($_POST['lfs_full_door_cate_additional_fields'] as $lfs_full_door_cate_additional_fields) {
 if($lfs_full_door_cate_additional_fields['isDelete']!="1"){
   //----category image
      define('UPLOAD_DIR', '../../../images/door_images/');
      if($lfs_full_door_cate_additional_fields['additional_image1']!=''){
      $img3 = $lfs_full_door_cate_additional_fields['additional_image1'];
      $img3 = str_replace('data:image/png;base64,', '', $img3);
      $img3 = str_replace(' ', '+', $img3);
      $data3 = base64_decode($img3);
      $additional_image1 = uniqid() . '.png';
      $file3 = UPLOAD_DIR .$additional_image1 ;
      $success3 = file_put_contents($file3, $data3);
      }else{
        $additional_image1='';
      }
     if($lfs_full_door_cate_additional_fields['additional_image2']!=''){
      $img4 = $lfs_full_door_cate_additional_fields['additional_image2'];
      $img4 = str_replace('data:image/png;base64,', '', $img4);
      $img4 = str_replace(' ', '+', $img4);
      $data4 = base64_decode($img4);
      $additional_image2 = uniqid() . '.png';
      $file4 = UPLOAD_DIR .$additional_image2;
      $success4 = file_put_contents($file4, $data4);
      }else{
      $additional_image2='';
      }

 //------------For  FIREDOOR CATEGORY ANSWER Additional Fields------------------------------------------
      $lfs_full_door_cate_additional_fields_field = array('firedoor_ID','category_ID','additional_info','additional_image1','additional_image2','isDelete');
      $lfs_full_door_cate_additional_fields_value = array($Ins_firedoor_ID,$lfs_full_door_cate_additional_fields['category_ID'],$lfs_full_door_cate_additional_fields['additional_info'],$additional_image1,$additional_image2,$lfs_full_door_cate_additional_fields['isDelete']);
      $lfs_full_door_cate_additional_fieldsins = $obj->insert($lfs_full_door_cate_additional_fields_field,$lfs_full_door_cate_additional_fields_value,'lfs_full_door_cate_additional_fields');
    }

}
}
//-------for art answer------------------------------------------------------------------
if($_POST['lfs_fire_door_art_question_answ']){
      foreach ($_POST['lfs_fire_door_art_question_answ'] as $lfs_fire_door_art_question_answ) {
         if($lfs_fire_door_art_question_answ['isDelete']!="1"){
                if($lfs_fire_door_art_question_answ['art_answer']==''){
                  $lfs_fire_door_art_question_answ['art_answer']=3;
                }
              $fldart = array('firedoor_ID','art_ID','category_ID','art_answer','color','isDelete');
             
              $valart = array($Ins_firedoor_ID,$lfs_fire_door_art_question_answ['art_ID'],$lfs_fire_door_art_question_answ['category_ID'],$lfs_fire_door_art_question_answ['art_answer'],$lfs_fire_door_art_question_answ['color'],$lfs_fire_door_art_question_answ['isDelete']);
            $addartans = $obj->insert($fldart,$valart,'lfs_fire_door_art_question_answ');
          }
    }
}
  //------------For  FIREDOOR CATEGORY STATUS ------------------------------------------
if($_POST['lfs_full_door_cate_status']){
    foreach($_POST['lfs_full_door_cate_status'] as $lfs_full_door_cate_status) {
       if($lfs_full_door_cate_status['isDelete']!="1"){
      $lfs_full_door_cate_status_field = array('firedoor_ID','category_ID','status');
      $lfs_full_door_cate_status_value = array($Ins_firedoor_ID,$lfs_full_door_cate_status['category_ID'],$lfs_full_door_cate_status['status']);
      $lfs_full_door_cate_statusins = $obj->insert($lfs_full_door_cate_status_field,$lfs_full_door_cate_status_value,'lfs_full_door_cate_status');
        }
}
}
        //------------For  CATEGORY color ------------------------------------------
if($_POST['lfs_category_color']){
foreach ($_POST['lfs_category_color'] as $lfs_category_color) {
        if($lfs_category_color['isDelete']!="1"){
      $lfs_category_color_field = array('project_ID','firedoor_ID','category_ID','color','createdDate','updatedDate');
      $lfs_category_color_status_value = array($lfs_category_color['project_ID'],$Ins_firedoor_ID,$lfs_category_color['category_ID'],$lfs_category_color['color'],$lfs_category_color['createdDate'],$lfs_category_color['updatedDate']);
      $lfs_category_color_statusins = $obj->insert($lfs_category_color_field,$lfs_category_color_status_value,'lfs_category_color');
        }
}
}
//---------------for main price list item -------------------------------
if($_POST['lfs_fds_pricelist_ans']){
foreach ($_POST['lfs_fds_pricelist_ans'] as $lfs_fds_pricelist_ans) {
         if($lfs_fds_pricelist_ans['isDelete']!="1"){
        $fldpricing=array('project_ID','firedoor_ID','item_id','units');
        $valpricing=array($lfs_fds_pricelist_ans['project_ID'],$Ins_firedoor_ID,$lfs_fds_pricelist_ans['item_id'],$lfs_fds_pricelist_ans['units']);
        $addpriceansw = $obj->insert($fldpricing,$valpricing,'lfs_fds_pricelist_ans');
        }
}
}

      //----------for coustome price list item ----------------------------
$custom_price_array_ins=array();
$t=0;
if($_POST['lfs_fds_custom_pricelist_ans']){
foreach ($_POST['lfs_fds_custom_pricelist_ans'] as $lfs_fds_custom_pricelist_ans) {
         if($lfs_fds_custom_pricelist_ans['isDelete']!="1"){
      $fldpricing_cu=array('project_ID','firedoor_ID','item_name','units');
      $valpricing_cu=array($lfs_fds_custom_pricelist_ans['project_ID'],$Ins_firedoor_ID,$lfs_fds_custom_pricelist_ans['item_name'],$lfs_fds_custom_pricelist_ans['units']);
      
      $addpriceanswinsert = $obj->insert($fldpricing_cu,$valpricing_cu,'lfs_fds_custom_pricelist_ans');
       $custom_price_array_ins[$t]['c_ans_id']=mysql_insert_id();
       $custom_price_array_ins[$t]['c_ans_id_local']=$lfs_fds_custom_pricelist_ans['c_ans_id_local'];
      }
      $t++;
} 
} 
      echo json_encode(array('result'=>'insert','id'=>$Ins_firedoor_ID,'pricelist'=>$custom_price_array_ins));

}else{
 //-------------------------------------------update door-----------------------------------------


      define('UPLOAD_DIR', '../../../images/door_images/');
       //------for door plug images--------------------
      if($lfs_firedoor_survey['door_plug_img1']!=''){
      $img1 = $lfs_firedoor_survey['door_plug_img1'];
      $img1 = str_replace('data:image/png;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
      $data1 = base64_decode($img1);
      $door_plug_img1 = uniqid() . '.png';
      $file1 = UPLOAD_DIR .$door_plug_img1 ;
      $success1 = file_put_contents($file1, $data1);
      }else{
        $door_plug_img1='';
      }
       if($lfs_firedoor_survey['door_plug_img2']!=''){
      $img1 = $lfs_firedoor_survey['door_plug_img2'];
      $img1 = str_replace('data:image/png;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
      $data1 = base64_decode($img1);
      $door_plug_img2 = uniqid() . '.png';
      $file1 = UPLOAD_DIR .$door_plug_img2 ;
      $success1 = file_put_contents($file1, $data1);
      }else{
        $door_plug_img2='';
      }

      //-----------------end door plug image section---------

      if($lfs_firedoor_survey['ext_door_image1']!=''){
      $img1 = $lfs_firedoor_survey['ext_door_image1'];
      $img1 = str_replace('data:image/png;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
      $data1 = base64_decode($img1);
      $ext_door_image1 = uniqid() . '.png';
      $file1 = UPLOAD_DIR .$ext_door_image1 ;
      $success1 = file_put_contents($file1, $data1);
      }else{
        $ext_door_image1='';
      }
      if($lfs_firedoor_survey['ext_door_image2']!=''){
      $img2 = $lfs_firedoor_survey['ext_door_image2'];
      $img2 = str_replace('data:image/png;base64,', '', $img2);
      $img2 = str_replace(' ', '+', $img2);
      $data2 = base64_decode($img2);
      $ext_door_image2 = uniqid() . '.png';
      $file2 = UPLOAD_DIR .$ext_door_image2;
      $success2 = file_put_contents($file2, $data2);
      }else{
      $ext_door_image2='';
      }

            if($lfs_firedoor_survey['cont_ass_fire_add_image1']!=''){
      $img1 = $lfs_firedoor_survey['cont_ass_fire_add_image1'];
      $img1 = str_replace('data:image/png;base64,', '', $img1);
      $img1 = str_replace(' ', '+', $img1);
      $data1 = base64_decode($img1);
      $cont_ass_fire_add_image1 = uniqid() . '.png';
      $file1 = UPLOAD_DIR .$cont_ass_fire_add_image1 ;
      $success1 = file_put_contents($file1, $data1);
      }else{
        $cont_ass_fire_add_image1='';
      }
     if($lfs_firedoor_survey['cont_ass_fire_add_image2']!=''){
      $img2 = $lfs_firedoor_survey['cont_ass_fire_add_image2'];
      $img2 = str_replace('data:image/png;base64,', '', $img2);
      $img2 = str_replace(' ', '+', $img2);
      $data2 = base64_decode($img2);
      $cont_ass_fire_add_image2 = uniqid() . '.png';
      $file2 = UPLOAD_DIR .$cont_ass_fire_add_image2;
      $success2 = file_put_contents($file2, $data2);
      }else{
      $cont_ass_fire_add_image2='';
      }


        $last_door_count = $obj->fetchRow("lfs_firedoor_survey","project_ID = ".$lfs_firedoor_survey['project_ID']." ORDER BY firedoor_ID DESC LIMIT 1");
               /*Door Ordering functionality*/  
   // echo "<pre>";print_r($lfs_firedoor_survey_details);exit;
        $last_door_count = $obj->fetchRow("lfs_firedoor_survey","project_ID = ".$lfs_firedoor_survey['project_ID']." ORDER BY firedoor_ID DESC LIMIT 1");
    $lfs_firedoor_survey_details = $obj->fetchRow("lfs_firedoor_survey","project_ID = ".$lfs_firedoor_survey['project_ID']." and firedoor_ID = ".$lfs_firedoor_survey['firedoor_ID']);

    $oldfloor = $lfs_firedoor_survey_details['floor_No'];
    $ordernumber= (int)$lfs_firedoor_survey_details['firedoor_Order'];
    if($oldfloor != $lfs_firedoor_survey['floor_No']){
      /*if the floor is changed then*/

      /*
      Ordering Logic
      Minus Ordering for Basement eg. -10001
      Single digit ordering for Ground floor eg. 1
      Five Digit ordering for normal floor eg. 10001
      Six Digit ordering for normal Customfloor eg. 120001
      Seven Digit Ordering for text Custom floor eg.2010001
      */
      $doors = $obj->fetchRow("lfs_firedoor_survey","project_ID='".$lfs_firedoor_survey['project_ID']."' AND floor_No = '".$lfs_firedoor_survey['floor_No']."' order by firedoor_Order DESC LIMIT 1");
      //echo "<pre>";print_r($doors);exit;
      if(count($doors) > 0){
        $lastorder = ($doors['firedoor_Order'] != NULL || $doors['firedoor_Order'] !="")?(int)$doors['firedoor_Order']:0;
      }else{
        $lastorder = 0;
      }
      //echo $lastorder."<br>";

      if($lfs_firedoor_survey['floor_No'] == "G"){
        /*For Ground Floor*/
        $startupenum = $lastorder+1;

      }else if($lfs_firedoor_survey['floor_No'] == "B"){
        /*For Basement Floor*/
        if($lastorder != 0){
          $tempfloor = $lastorder-1;
          $startupenum = $tempfloor;  // Apend three zero

        }else{
          $tempfloor = $lastorder+1;
          $startupenum = "-1".sprintf("%04d", $tempfloor);
        }


      }else{

        if((int)$lfs_firedoor_survey['floor_No'] > 100 ){ // here floor id will be checked.
          /*For Custom Floor*/
          $tempfloor = $lastorder+1;
          $selfloor = $obj->fetchRow("lfs_custom_floor","floorNo='".$lfs_firedoor_survey['floor_No']."' AND project_ID=".$lfs_firedoor_survey['project_ID']);
          $getfloorno = $selfloor['floorNo'];
          $getfloororder = $selfloor['floor_Order'];
          /*Below condition is for checking whether custome floor is for normal floor or custom named floor*/
          if((int)$getfloorno == 0){
            /*Customenamed floor*/
            
            if($lastorder != 0){
              $startupenum = $tempfloor;
            }else{
              $startupenum = $lfs_firedoor_survey['floor_No'].sprintf("%04d", $tempfloor);
            }
          }else{
            /*Regular floor's Custome floor*/
            if($lastorder != 0){
              $startupenum = $tempfloor;
            }else{
              $startupenum = $getfloorno.$getfloororder.sprintf("%04d", $tempfloor);  
            }
          }
        }else{
          /*For Normal Floor*/
          $tempfloor = $lastorder+1;
          //echo $tempfloor;exit;
          if($lastorder != 0){
            $startupenum = $tempfloor;   // Apend two zero
          }else{  
            $startupenum = $lfs_firedoor_survey['floor_No'].sprintf("%03d", $tempfloor);   // Apend two zero
          }

        }        
      }
      $ordernumber = (int)$startupenum;
    }


 $createdDate=date('Y-m-d H:i:s',strtotime($lfs_firedoor_survey['createdDate']));
     $updatedDate=date('Y-m-d H:i:s',strtotime($lfs_firedoor_survey['updatedDate']));
    /*Door Ordering functionality*/
      if($lfs_firedoor_survey['door_plug']!='1' && $lfs_firedoor_survey['door_plug']!='0'){
     $lfs_firedoor_survey['door_plug']='2';   
    }
      $field_new_fire_survey = array('firedoor_Order','project_ID','door_reference','Barcode_ref','floor_No','property_no_Name','location','client_door_reference','door_count','ext_door_image1','ext_door_image2','floor_plan','full_access','reason_no_access','add_info','manufaturer','installer','type_of_door','type_of_dooradd','construction_type','construction_typeadd','fanlight_present','sidelight_present','vision_panel','inteded_fire_rating','continue_assess_fire_door','na_immediate_fail','asses_fire_rated','fire_rate_asses_reason','cont_ass_fire_art_17','cont_ass_fire_art_18','cont_ass_fire_art_20','cont_ass_fire_add_field','cont_ass_fire_add_image1','cont_ass_fire_add_image2','door_plug','door_plug_img1','door_plug_img2','door_plug_description','test_evidance','hanging','hanging_NA','structural_opening','structural_opening_NA','leaf_size','leaf_size_NA','leaf_color','leaf_color_NA','leaf_colortxt','frame_color','frame_colortxt','frame_color_NA','door_closer_type','name_known_door','O_Lock','name_known_lock','O_Lock_add_field','door_status','door_statustxt','summary_of_findings','summary_add_info','certification','lfs_fire_door_result','isRepairs','operative_Status','Operative_comments','Operative_updated','createdBy','updatedBy','createdDate','updatedDate','isInstallation','last_door_data','NextMaintenanceDate','isActive','isDelete');

      $value_new_fire_survey = array($ordernumber,$lfs_firedoor_survey['project_ID'],$lfs_firedoor_survey['door_reference'],$lfs_firedoor_survey['Barcode_ref'],$lfs_firedoor_survey['floor_No'],$lfs_firedoor_survey['property_no_Name'],$lfs_firedoor_survey['location'],$lfs_firedoor_survey['client_door_reference'],$lfs_firedoor_survey['door_count'],$ext_door_image1,$ext_door_image2,$lfs_firedoor_survey['floor_plan'],$lfs_firedoor_survey['full_access'],$lfs_firedoor_survey['reason_no_access'],$lfs_firedoor_survey['add_info'],$lfs_firedoor_survey['manufaturer'],$lfs_firedoor_survey['installer'],$lfs_firedoor_survey['type_of_door'],$lfs_firedoor_survey['type_of_dooradd'],$lfs_firedoor_survey['construction_type'],$lfs_firedoor_survey['construction_typeadd'],$lfs_firedoor_survey['fanlight_present'],$lfs_firedoor_survey['sidelight_present'],$lfs_firedoor_survey['vision_panel'],$lfs_firedoor_survey['inteded_fire_rating'],$lfs_firedoor_survey['continue_assess_fire_door'],$lfs_firedoor_survey['na_immediate_fail'],$lfs_firedoor_survey['asses_fire_rated'],$lfs_firedoor_survey['fire_rate_asses_reason'],$lfs_firedoor_survey['cont_ass_fire_art_17'],$lfs_firedoor_survey['cont_ass_fire_art_18'],$lfs_firedoor_survey['cont_ass_fire_art_20'],$lfs_firedoor_survey['cont_ass_fire_add_field'],$cont_ass_fire_add_image1,$cont_ass_fire_add_image2,$lfs_firedoor_survey['door_plug'],$door_plug_img1,$door_plug_img2,$lfs_firedoor_survey['door_plug_description'],$lfs_firedoor_survey['test_evidance'],$lfs_firedoor_survey['hanging'],$lfs_firedoor_survey['hanging_NA'],$lfs_firedoor_survey['structural_opening'],$lfs_firedoor_survey['structural_opening_NA'],$lfs_firedoor_survey['leaf_size'],$lfs_firedoor_survey['leaf_size_NA'],$lfs_firedoor_survey['leaf_color'],$lfs_firedoor_survey['leaf_color_NA'],$lfs_firedoor_survey['leaf_colortxt'],$lfs_firedoor_survey['frame_color'],$lfs_firedoor_survey['frame_colortxt'],$lfs_firedoor_survey['frame_color_NA'],$lfs_firedoor_survey['door_closer_type'],$lfs_firedoor_survey['name_known_door'],$lfs_firedoor_survey['O_Lock'],$lfs_firedoor_survey['name_known_lock'],$lfs_firedoor_survey['O_Lock_add_field'],$lfs_firedoor_survey['door_status'],$lfs_firedoor_survey['door_statustxt'],$lfs_firedoor_survey['summary_of_findings'],$lfs_firedoor_survey['summary_add_info'],$lfs_firedoor_survey['certification'],$lfs_firedoor_survey['lfs_fire_door_result'],$lfs_firedoor_survey['isRepairs'],$lfs_firedoor_survey['operative_Status'],$lfs_firedoor_survey['Operative_comments'],$lfs_firedoor_survey['Operative_updated'],$lfs_firedoor_survey['createdBy'],$lfs_firedoor_survey['updatedBy'], $createdDate,$updatedDate,$lfs_firedoor_survey['isInstallation'],$lfs_firedoor_survey['last_door_data'],$lfs_firedoor_survey['NextMaintenanceDate'],$lfs_firedoor_survey['isActive'],$lfs_firedoor_survey['isDelete']);

       $Update_firedoor_ID = $obj->update($field_new_fire_survey,$value_new_fire_survey,'firedoor_ID = '.$lfs_firedoor_survey['firedoor_ID'],'lfs_firedoor_survey');

//FOR COLOR TABLE
if($_POST['lfs_firedoor_survey_color']){
       $createdDate=date('Y-m-d H:i:s',strtotime($lfs_firedoor_survey['createdDate']));
     $updatedDate=date('Y-m-d H:i:s',strtotime($lfs_firedoor_survey['updatedDate']));
      $field_new_fire_survey_color = array('firedoor_ID','project_ID','full_access','reason_no_access','add_info','manufaturer','installer','type_of_door','type_of_door_add_info','construction_type','construction_type_add_info','fanlight_present','sidelight_present','vision_panel','inteded_fire_rating','continue_assess_fire_door','cont_ass_fire_art_17','cont_ass_fire_art_18','cont_ass_fire_art_20','asses_fire_rated','fire_rate_asses_reason','door_plug','door_plug_description','test_evidance','hanging','hanging_NA','structural_opening','structural_opening_NA','leaf_size','leaf_color','leaf_color_NA','frame_color','door_closer_type','O_Lock','door_status','summary_of_findings','summary_add_info','certification','createdDate','updatedDate','isActive','isDelete');
    
       $value_new_fire_survey_color = array($lfs_firedoor_survey['firedoor_ID'],$lfs_firedoor_survey_color['project_ID'],$lfs_firedoor_survey_color['full_access'],$lfs_firedoor_survey_color['reason_no_access'],$lfs_firedoor_survey_color['add_info'],$lfs_firedoor_survey_color['manufaturer'],$lfs_firedoor_survey_color['installer'],$lfs_firedoor_survey_color['type_of_door'],$lfs_firedoor_survey_color['type_of_door_add_info'],$lfs_firedoor_survey_color['construction_type'],$lfs_firedoor_survey_color['construction_type_add_info'],$lfs_firedoor_survey_color['fanlight_present'],$lfs_firedoor_survey_color['sidelight_present'],$lfs_firedoor_survey_color['vision_panel'],$lfs_firedoor_survey_color['inteded_fire_rating'],$lfs_firedoor_survey_color['continue_assess_fire_door'],$lfs_firedoor_survey_color['cont_ass_fire_art_17'],$lfs_firedoor_survey_color['cont_ass_fire_art_18'],$lfs_firedoor_survey_color['cont_ass_fire_art_20'],$lfs_firedoor_survey_color['asses_fire_rated'],$lfs_firedoor_survey_color['fire_rate_asses_reason'],$lfs_firedoor_survey_color['door_plug'],$lfs_firedoor_survey_color['door_plug_description'],$lfs_firedoor_survey_color['test_evidance'],$lfs_firedoor_survey_color['hanging'],$lfs_firedoor_survey_color['hanging_NA'],$lfs_firedoor_survey_color['structural_opening'],$lfs_firedoor_survey_color['structural_opening_NA'],$lfs_firedoor_survey_color['leaf_size'],$lfs_firedoor_survey_color['leaf_color'],$lfs_firedoor_survey_color['leaf_color_NA'],$lfs_firedoor_survey_color['frame_color'],$lfs_firedoor_survey_color['door_closer_type'],$lfs_firedoor_survey_color['O_Lock'],$lfs_firedoor_survey_color['door_status'],$lfs_firedoor_survey_color['summary_of_findings'],$lfs_firedoor_survey_color['summary_add_info'],$lfs_firedoor_survey_color['certification'],$createdDate,$updatedDate,$lfs_firedoor_survey_color['isActive'],$lfs_firedoor_survey_color['isDelete']);

          $door_colors = $obj->fetchRow("lfs_firedoor_survey_color","project_ID='".$lfs_firedoor_survey['project_ID']."' AND firedoor_ID = '".$lfs_firedoor_survey_color['firedoor_ID']."' order by firedoor_ID");
        //   echo "<pre>";
        //   print_r( $door_colors);
        //   echo "</pre>";
       		 if($door_colors){
       		 		$firedoor_color = $obj->update($field_new_fire_survey_color,$value_new_fire_survey_color,'firedoor_ID = '.$lfs_firedoor_survey_color['firedoor_ID'],'lfs_firedoor_survey_color');
       		 }else{
       		      $firedoor_color = $obj->insert($field_new_fire_survey_color,$value_new_fire_survey_color,'lfs_firedoor_survey_color');
       		 
       		 }
}
 //---------------------for category na feature----------------------
if(isset($_POST['lfs_fds_category_na_feature'])){
foreach ($_POST['lfs_fds_category_na_feature'] as $lfs_fds_category_na_feature) {
  # code...

$hasfire_lfs_fds_category_na_feature = $obj->fetchNumOfRow("lfs_fds_category_na_feature","firedoor_ID = ".$lfs_fds_category_na_feature['firedoor_ID']." AND category_ID='".$lfs_fds_category_na_feature['category_ID']."'");
  

  
  $createdDate=date('Y-m-d H:i:s',strtotime($lfs_fds_category_na_feature['createdDate']));
     $updatedDate=date('Y-m-d H:i:s',strtotime($lfs_fds_category_na_feature['updatedDate']));
           $field_na_feature_field=array('project_ID','firedoor_ID','category_ID','NA','createdDate','updatedDate');
          $value_na_feature_val=array($lfs_fds_category_na_feature['project_ID'],$lfs_fds_category_na_feature['firedoor_ID'],$lfs_fds_category_na_feature['category_ID'],$lfs_fds_category_na_feature['NA'],$createdDate,$updatedDate);
          if($hasfire_lfs_fds_category_na_feature > 0){
              if($lfs_fds_category_na_feature['isDelete']=='1'){
                $obj->delete('lfs_fds_category_na_feature',"firedoor_ID = ".$lfs_fds_category_na_feature['firedoor_ID']." AND category_ID='".$lfs_fds_category_na_feature['category_ID']."'");
              }else{
                $update_additional_fieldupd = $obj->update($field_na_feature_field,$value_na_feature_val,"firedoor_ID = ".$lfs_fds_category_na_feature['firedoor_ID']." AND category_ID=".$lfs_fds_category_na_feature['category_ID'],'lfs_fds_category_na_feature');
              }
            
          }else{
                  if($lfs_fds_category_na_feature['isDelete']!='1'){
             $lfs_fds_category_na_featureins = $obj->insert($field_na_feature_field,$value_na_feature_val,'lfs_fds_category_na_feature');
                  }
          }
          
}
}
  //------------For  FIREDOOR QUESTION ANSWER ------------------------------------------
if(isset($_POST['lfs_fire_door_question_answ'])){
foreach ($_POST['lfs_fire_door_question_answ'] as $lfs_fire_door_question_answ) {
  
      $hasfire_lfs_fire_door_question_answ = $obj->fetchNumOfRow("lfs_fire_door_question_answ","firedoor_ID ='".$lfs_fire_door_question_answ['firedoor_ID']."' AND cat_question_ID='".$lfs_fire_door_question_answ['cat_question_ID']."'");
   
    
      $lfs_fire_door_question_answ_field = array('firedoor_ID','cat_question_ID','answer','color','isDelete');
      $lfs_fire_door_question_answ_value = array($lfs_fire_door_question_answ['firedoor_ID'],$lfs_fire_door_question_answ['cat_question_ID'],$lfs_fire_door_question_answ['answer'],$lfs_fire_door_question_answ['color'],$lfs_fire_door_question_answ['isDelete']);
      // echo "<pre>";
      // print_r($lfs_fire_door_question_answ_field);
      // print_r($lfs_fire_door_question_answ_value);
      //exit();
        if($hasfire_lfs_fire_door_question_answ > 0){
            if($lfs_fire_door_question_answ['isDelete']=='1'){
                $obj->delete('lfs_fire_door_question_answ',"firedoor_ID ='".$lfs_fire_door_question_answ['firedoor_ID']."' AND cat_question_ID='".$lfs_fire_door_question_answ['cat_question_ID']."'");
            }else{
               $lfs_fire_door_question_answupd = $obj->update($lfs_fire_door_question_answ_field,$lfs_fire_door_question_answ_value,"firedoor_ID ='".$lfs_fire_door_question_answ['firedoor_ID']."' AND cat_question_ID='".$lfs_fire_door_question_answ['cat_question_ID']."'","lfs_fire_door_question_answ");
            }
         
        }else{
              if($lfs_fire_door_question_answ['isDelete']!='1'){

              $lfs_fire_door_question_answins = $obj->insert($lfs_fire_door_question_answ_field,$lfs_fire_door_question_answ_value,'lfs_fire_door_question_answ');
              }
        }
      
}
}
  //-------for art answer------------------------------------------------------------------
if(isset($_POST['lfs_fire_door_art_question_answ'])){
 foreach ($_POST['lfs_fire_door_art_question_answ'] as $lfs_fire_door_art_question_answ) {

 $hasfire_lfs_fire_door_art_question_answ = $obj->fetchNumOfRow("lfs_fire_door_art_question_answ","firedoor_ID = ".$lfs_fire_door_art_question_answ['firedoor_ID']." AND category_ID='".$lfs_fire_door_art_question_answ['category_ID']."' AND art_ID='".$lfs_fire_door_art_question_answ['art_ID']."'");
 
     
        $fldart = array('firedoor_ID','art_ID','category_ID','art_answer','color','isDelete');
       
        $valart = array($lfs_fire_door_art_question_answ['firedoor_ID'],$lfs_fire_door_art_question_answ['art_ID'],$lfs_fire_door_art_question_answ['category_ID'],$lfs_fire_door_art_question_answ['art_answer'],$lfs_fire_door_art_question_answ['color'],$lfs_fire_door_art_question_answ['isDelete']);
        if($hasfire_lfs_fire_door_art_question_answ > 0){
              if($lfs_fire_door_art_question_answ['isDelete']=='1'){
                $obj->delete('lfs_fire_door_art_question_answ',"firedoor_ID = ".$lfs_fire_door_art_question_answ['firedoor_ID']." AND category_ID='".$lfs_fire_door_art_question_answ['category_ID']."' AND art_ID='".$lfs_fire_door_art_question_answ['art_ID']."'");
            }else{
           $addartans = $obj->update($fldart,$valart,"firedoor_ID = ".$lfs_fire_door_art_question_answ['firedoor_ID']." AND category_ID='".$lfs_fire_door_art_question_answ['category_ID']."' AND art_ID=".$lfs_fire_door_art_question_answ['art_ID'],"lfs_fire_door_art_question_answ");
            }
        }else{
           if($lfs_fire_door_art_question_answ['isDelete']!='1'){
           $addartans = $obj->insert($fldart,$valart,'lfs_fire_door_art_question_answ');
              }
        }
       
}
}
if(isset($_POST['lfs_full_door_cate_additional_fields'])){
foreach ($_POST['lfs_full_door_cate_additional_fields'] as $lfs_full_door_cate_additional_fields) {

$hasfire_lfs_full_door_cate_additional_fields = $obj->fetchNumOfRow("lfs_full_door_cate_additional_fields","firedoor_ID = ".$lfs_full_door_cate_additional_fields['firedoor_ID']." AND category_ID='".$lfs_full_door_cate_additional_fields['category_ID']."'");



       //----category image
      define('UPLOAD_DIR', '../../../images/door_images/');
      $additional_image1 = $lfs_full_door_cate_additional_fields['additional_image1'];
      $additional_image2 = $lfs_full_door_cate_additional_fields['additional_image2'];
      if($additional_image1!=''){
      $img3 = $additional_image1;
      $img3 = str_replace('data:image/png;base64,', '', $img3);
      $img3 = str_replace(' ', '+', $img3);
      $data3 = base64_decode($img3);
      $additional_image1 = uniqid() . '.png';
      $file3 = UPLOAD_DIR .$additional_image1 ;
      $success3 = file_put_contents($file3, $data3);
      }else{
        $additional_image1='';
      }
     if($additional_image2!=''){
      $img4 = $additional_image2;
      $img4 = str_replace('data:image/png;base64,', '', $img4);
      $img4 = str_replace(' ', '+', $img4);
      $data4 = base64_decode($img4);
      $additional_image2 = uniqid() . '.png';
      $file4 = UPLOAD_DIR .$additional_image2;
      $success4 = file_put_contents($file4, $data4);
      }else{
      $additional_image2='';
      }
 //------------For  FIREDOOR CATEGORY ANSWER Additional Fields------------------------------------------
      $lfs_full_door_cate_additional_fields_field = array('firedoor_ID','category_ID','additional_info','additional_image1','additional_image2','isDelete');
      $lfs_full_door_cate_additional_fields_value = array($lfs_full_door_cate_additional_fields['firedoor_ID'],$lfs_full_door_cate_additional_fields['category_ID'],$lfs_full_door_cate_additional_fields['additional_info'],$additional_image1,$additional_image2,$lfs_full_door_cate_additional_fields['isDelete']);
    if($hasfire_lfs_full_door_cate_additional_fields > 0){

         if($lfs_full_door_cate_additional_fields['isDelete']=='1'){
          $obj->delete('lfs_full_door_cate_additional_fields',"firedoor_ID = ".$lfs_full_door_cate_additional_fields['firedoor_ID']." AND category_ID='".$lfs_full_door_cate_additional_fields['category_ID']."'");
         }else{
          $lfs_full_door_cate_additional_fieldsupd = $obj->update($lfs_full_door_cate_additional_fields_field,$lfs_full_door_cate_additional_fields_value,"firedoor_ID = ".$lfs_full_door_cate_additional_fields['firedoor_ID']." AND category_ID='".$lfs_full_door_cate_additional_fields['category_ID']."'",'lfs_full_door_cate_additional_fields');
         }
      
    }else{

         if($lfs_full_door_cate_additional_fields['isDelete']!='1'){
       $lfs_full_door_cate_additional_fieldsins = $obj->insert($lfs_full_door_cate_additional_fields_field,$lfs_full_door_cate_additional_fields_value,'lfs_full_door_cate_additional_fields');
          }
    }
 }
}   
  //------------For  FIREDOOR CATEGORY STATUS ------------------------------------------
if(isset($_POST['lfs_full_door_cate_status'])){
  foreach($_POST['lfs_full_door_cate_status'] as $lfs_full_door_cate_status) {
 
$hasfire_full_door_cate_statusupd = $obj->fetchNumOfRow("lfs_full_door_cate_status","firedoor_ID ='".$lfs_full_door_cate_status['firedoor_ID']."' AND category_ID='".$lfs_full_door_cate_status['category_ID']."'");
   
    
      $lfs_full_door_cate_status_field = array('firedoor_ID','category_ID','status');
      $lfs_full_door_cate_status_value = array($lfs_full_door_cate_status['firedoor_ID'],$lfs_full_door_cate_status['category_ID'],$lfs_full_door_cate_status['status']);
        if($hasfire_full_door_cate_statusupd > 0){

           if($lfs_full_door_cate_status['isDelete']=='1'){
            $obj->delete('lfs_full_door_cate_status',"firedoor_ID = ".$lfs_full_door_cate_status['firedoor_ID']." AND category_ID='".$lfs_full_door_cate_status['category_ID']."'");
           }else{
            $lfs_full_door_cate_statusupd = $obj->update($lfs_full_door_cate_status_field,$lfs_full_door_cate_status_value,"firedoor_ID ='".$lfs_full_door_cate_status['firedoor_ID']."' AND category_ID='".$lfs_full_door_cate_status['category_ID']."'",'lfs_full_door_cate_status');
           }
           
        }else{
            if($lfs_full_door_cate_status['isDelete']!='1'){
           $lfs_full_door_cate_statusins = $obj->insert($lfs_full_door_cate_status_field,$lfs_full_door_cate_status_value,'lfs_full_door_cate_status');
         }
        }
     
}
}




//---------------for main price list item -------------------------------
if(isset($_POST['lfs_fds_pricelist_ans'])){
 foreach ($_POST['lfs_fds_pricelist_ans'] as $lfs_fds_pricelist_ans) {
  
  $hasfire_addpriceansw = $obj->fetchNumOfRow("lfs_fds_pricelist_ans","firedoor_ID = ".$lfs_fds_pricelist_ans['firedoor_ID']." AND item_id = ".$lfs_fds_pricelist_ans['item_id']);
  
  
        $fldpricing=array('project_ID','firedoor_ID','item_id','units');
        $valpricing=array($lfs_fds_pricelist_ans['project_ID'],$lfs_fds_pricelist_ans['firedoor_ID'],$lfs_fds_pricelist_ans['item_id'],$lfs_fds_pricelist_ans['units']);
        if($hasfire_addpriceansw > 0){
            if($lfs_fds_pricelist_ans['isDelete']=='1'){
            $obj->delete('lfs_fds_pricelist_ans',"firedoor_ID = ".$lfs_fds_pricelist_ans['firedoor_ID']." AND item_id = ".$lfs_fds_pricelist_ans['item_id']);
           }else{
          $addpriceansw= $obj->update($fldpricing,$valpricing,"firedoor_ID = ".$lfs_fds_pricelist_ans['firedoor_ID']." AND item_id = ".$lfs_fds_pricelist_ans['item_id'],'lfs_fds_pricelist_ans');
          }
        }else{

             if($lfs_fds_pricelist_ans['isDelete']!='1'){
           $addpriceansw = $obj->insert($fldpricing,$valpricing,'lfs_fds_pricelist_ans');
            }
        }
        

}
}
      //----------for coustome price list item ----------------------------
$t=0;
$custom_price_array=array();
if(isset($_POST['lfs_fds_custom_pricelist_ans'])){
foreach ($_POST['lfs_fds_custom_pricelist_ans'] as $lfs_fds_custom_pricelist_ans) {

 $hasfire_lfs_fds_custom_pricelist_ans = $obj->fetchNumOfRow("lfs_fds_custom_pricelist_ans","c_ans_id = ".$lfs_fds_custom_pricelist_ans['c_ans_id']);

  $hasfire_lfs_fds_custom_pricelist_ans = $obj->fetchNumOfRow("lfs_fds_custom_pricelist_ans","c_ans_id = ".$lfs_fds_custom_pricelist_ans['c_ans_id']);
      $fldpricing_cu=array('project_ID','firedoor_ID','item_name','units');
      $valpricing_cu=array($lfs_fds_custom_pricelist_ans['project_ID'],$lfs_fds_custom_pricelist_ans['firedoor_ID'],$lfs_fds_custom_pricelist_ans['item_name'],$lfs_fds_custom_pricelist_ans['units']);
       if($lfs_fds_custom_pricelist_ans['c_ans_id']==0){

                 if($lfs_fds_custom_pricelist_ans['isDelete']!='1'){
                $addpriceanswinsert = $obj->insert($fldpricing_cu,$valpricing_cu,'lfs_fds_custom_pricelist_ans');
                $custom_price_array[$t]['c_ans_id']=mysql_insert_id();
                 $custom_price_array[$t]['c_ans_id_local']=$lfs_fds_custom_pricelist_ans['c_ans_id_local'];
                }

          }else{

                if($lfs_fds_custom_pricelist_ans['isDelete']=='1'){
                $obj->delete('lfs_fds_custom_pricelist_ans',"c_ans_id = ".$lfs_fds_custom_pricelist_ans['c_ans_id']);
                 $custom_price_array[$t]['c_ans_id']=$lfs_fds_custom_pricelist_ans['c_ans_id'];
                 $custom_price_array[$t]['c_ans_id_local']=$lfs_fds_custom_pricelist_ans['c_ans_id_local'];
              }else{
                $addpriceanswup= $obj->update($fldpricing_cu,$valpricing_cu,'c_ans_id = '.$lfs_fds_custom_pricelist_ans['c_ans_id'],'lfs_fds_custom_pricelist_ans');
                 $custom_price_array[$t]['c_ans_id']=$lfs_fds_custom_pricelist_ans['c_ans_id'];
                 $custom_price_array[$t]['c_ans_id_local']=$lfs_fds_custom_pricelist_ans['c_ans_id_local'];
            }

          }
          $t++;

}
}

      echo json_encode(array('result'=>'update','id'=>$lfs_firedoor_survey['firedoor_ID'],'pricelist'=>$custom_price_array));

}


 

  
?>
