<?php

require_once("../head2Alts.php");
if(isset($_POST["submit"])){

  $house_no=$_POST['hnumber'];
$post =$_POST["submit"];
}

if(isset($_POST["post"])){
 $house_no=$_POST['house_no'];
$post =$_POST["post"];
}
  $ownID=$_POST['owniD'];

  /////// EXECUTE BY DEFAULTS////
//echo $post;
     $ownerid="";

     $email=""; 

     $phoneno=""; 

     $pobox="";
    

     $cduration="";

     $distancerm="";

     $rnumber="";
    
     $hnumber="";
 

     $finishD="";

     $hcost="";

     $tcondition="";

     $popularDistination="";

     $hname="";

     $currency="";
/////////
////////  
if($post=="Submit")
{
  
     $category=$_POST["category"];
   
  
     $email=$_POST['email']; 

     $phoneno=$_POST['phoneno']; 

      $tcondition=$_POST['tcondition'];  

     $distancerm=$_POST['distancerm'];

     $rnumber=$_POST['rnumber'];
    
     $hnumber=$_POST['hnumber'];

     $finishD=$_POST['finishD'];

     $hcost=$_POST['hcost'];

     $popularDistination=$_POST['popularDistination'];

     $hname=$_POST['hname'];

     $currency=$_POST["currency"];

     $accountId=$_POST['accountId'];

     $regno=$_POST['regno'];

     $regdate=$_POST['regdate'];
 

     $cduration=$_POST['cduration'];

   
     
   if(!$hcon->vcduration($cduration) ||  !$hcon->vCategory($category) ||  !$hcon->vTcondition($tcondition) ||  !$hcon->vaccountId($accountId) ||  !$hcon->vRnumber($rnumber) ||  !$hcon->vHcost($hcost,$currency) ||  !$hcon->vDistancerm($distancerm) || !$hcon->vHnumber($hnumber)|| !$hcon->vFinishD($finishD) || !$hcon->vPopularDistination($popularDistination) || !$hcon->vHname($hname) || !$hcon->vPhoneno($phoneno) || !$hcon->vEmail($email))
         
      {
         // echo $post;
      ?><center><font color="red" ><section style="background-color:silver;width:50%;align-content: left;">

    <?php
    echo "ERROR IN SUMISSION!..";
     echo $hcon->eCategory($category)."<p/>";
     echo $hcon->eHcost($hcost,$currency)."<p/>";
     echo $hcon->eDistancerm($distancerm)."<p/>";
     echo $hcon->eHnumber($hnumber)."<p/>";
     echo $hcon->eRnumber($rnumber)."<p/>";
     echo $hcon->eFinishD($finishD)."<p/>";
     echo $hcon->eaccountId($accountId)."<p/>";
     echo $hcon->ePopularDistination($popularDistination)."<p/>"; 
     echo $hcon->eTcondition($tcondition)."<p/>";
     echo $hcon->eHname($hname)."<p/>";     
     echo $hcon->ePhoneno($phoneno)."<p/>";
      echo $hcon->ecduration($cduration)."<p/>";
     echo $hcon->eEmail($email)."<p/>";
?></section> </font></center><?php
    require("EditMyHouseProfileForm.php");
      }
   else
      {
       if(isset($_POST['owniD']))
           { 
         $OW =$con->checkIdOfemployyeeExist($accountId);
           if($OW->rowCount()<=0)
        {
        ?>
      <center><font color="red" ><section style="background-color:silver;width:50%;align-content: left;">
        <?php
          echo "User with Id ".$accountId." not exist!..";

         ?>
  
      </section> </font></center>
     <?php
    require("EditMyHouseProfileForm.php");
        }
  else{
echo $OW->rowCount(); 
print_r($hcon->updateMyHouseProfile($hnumber,$accountId,$hname,$cduration,$category,$email,$phoneno,$popularDistination,$rnumber,$distancerm,$tcondition,$hcost,$currency,$finishD,$regno,$regdate));

    require("EditMyHouseProfileForm.php");;
     }
       
    
     }
      }

 
     }/*
else 

!$hcon->vHcost($hcost) ||  !$hcon->vDistancerm($distancerm) || !$hcon->vHnumber($hnumber)|| !$hcon->vFinishD($finishD) || !$hcon->vPopularDistination($popularDistination) || !$hcon->vStreet($street) || !$hcon->vHname($hname) || !$hcon->vWard($ward) || !$hcon->vDistrict($district) || !$hcon->vRegion($region) || !$hcon->vCountry($country) || !$hcon->vPhoneno($phoneno) || !$hcon->vEmail($email))

     {
  echo "Error occured when saving data!..";
     }*/

     if($post=="Edit house profile"){
     $HH=$hcon->getThisMyHouses($house_no,$ownID);
     if ($HH->rowCount()>0) {
      $Dh=$HH->fetch();

     $accountId=$Dh['ownerid'];

     $email=$Dh['email']; 

     $cduration=$Dh['cduration']; 

     $phoneno=$Dh['phone_no']; 

     $regno=$Dh['reg_no'];
      
     $category=$Dh['category'];

     $distancerm=$Dh['distance_m_r'];

     $rnumber=$Dh['rooms_no'];
    
     $hnumber=$Dh['house_no'];
 
     $finishD=$Dh['finishdisc'];

     $hcost=$Dh['cost_ifany'];

     $tcondition=$Dh['term_condition'];

     $popularDistination=$Dh['popularmark'];

     $hname=$Dh['house_title'];

     $currency=$Dh['currency'];

     $regdate=$Dh['regdate'];

    require("EditMyHouseProfileForm.php");
     }
     else{
      echo "House not found!..";
     }
      
 }

 
 require_once('../footerIns.php');
?>