 <?php 
   require_once("../head2Alts.php");
   if(isset($_POST['post']) || isset($_POST['submit']))
 {

if( isset($_POST['house_no']) &&   isset($_POST['roomid']) && isset($_POST['owniD']))
  {
 $house_no=$_POST['house_no'];
 $ownID=$_POST['owniD'];
 $room_no=$_POST['roomid'];

  $roomid=$_POST['roomid'];///////////////
 //////////////
 
   $cduration= "";
   $category ="";    
   $description = "";
   $imgdescription = "";
   $rcost ="";
   $currency="";
   $post=$_POST['post'];

   if($post=="Submit"){
 
        /////////////////
 
        ///////////////// 
   $cduration=$_POST['cduration'];
   $category =$_POST['category'];  
   $description =$_POST['description'];
   $rcost =$_POST['rcost'];
   $currency=$_POST['currency']; 
  // $itemid =substr(Date("Ymdhis"),2);

 
   if($hcon->vRoomno($room_no) && $hcon->vCategory($category) && $hcon->vcduration($cduration) && $hcon->vdescription($description)  && $hcon->vrcost($rcost,$currency))
      {
        ?>
         <center>
         <div>
        
        <?php 
         $r= $hcon->updateHouseRoom($category,$rcost,$currency,$cduration,$description,$house_no,$room_no);
         if($r->rowCount()>0)
         {
          echo "Update successfully!..";
          $room_no="";
          $cduration= "";
          $category ="";    
          $description = "";
          $rcost ="";
          $currency=""; 
         }else{
          echo "Submission error!..";
          //$u=$r->ErrorInfo();
          //print_r($u);//"Error occurred while saving data!..";
              }
        ?> 
       </div>
       </center> 

        <?php
    
      }
      else{

        //////////////
        ?>
         <center>
         <div>
         <sup>
             <?php 
              echo  $hcon->eRoomno($room_no)."<p/>"; 
              echo  $hcon->ecategory($category)."<p/>";
              echo  $hcon->ercost($rcost,$currency)."<p/>";
              echo  $hcon->edescription($description)."<p/>";
              echo  $hcon->ecduration($cduration)."<p/>";
              
    
             ?>
       </sup>
       </div>
       </center> 

        <?php
        /////////////

      }
 

}
 
 $rD=$hcon->getMyHouseThisRoomDetail($house_no,$roomid);
        if ($rD->rowCount()>0)
         {
            $Dr=$rD->fetch();
   $cduration=$Dr["contract_duration"];
   $category =$Dr["category"];    
   $description = $Dr["finishingdisc"]; ; 
   $rcost =$Dr["cost"];
   $currency=$Dr["currency"];

        //////////////////////

        ////////////////////
 
     
?> 
 
  
 
   <!--NEW USER REGISTRATION FORM, DISPLAYED BY DEFAULTS IN PAGE LOAD-->


<center>
 <ul style="padding-top:0%">
      <?php
          $hMG=$hcon->getHousesPImg($house_no);
          if($hMG->rowCount()>0)
                       {
                         $img=$hMG->fetch();
                         $pMG= $img['directory'] ;
                        }
                        else
                        {
          $pMG='../houseimages/defaultP.jpg';
                        }


      if($hMG->rowCount()<=0)
              {
              ?>
        <li>
           
                  <form action="uploadHouseImageForm.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">


                      <input class="hi" type="hidden" name="house_no"  value="<?php echo $house_no;?>">

 

                      <input  id="item" type="submit" value="Post profile image" name="post"  >

                 </form>
        </li>
              <?php
                }
               ?>
        <li>
           
                  <form action="addHouseRoomForm.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">


                      <input class="hi" type="hidden" name="house_no"  value="<?php echo $house_no;?>">

 

                      <input  id="item" type="submit" value="Add room" name="post"  >

                 </form>
        </li>
                <li>
           
                  <form action="getMyHouseRoomPreview.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">


                      <input class="hi" type="hidden" name="house_no"  value="<?php echo $house_no;?>">

 

                      <input  id="item" type="submit" value="Preview rooms" name="post">

                 </form>
        </li>
         <li>
           
                  <form action="getMyHouseRoomContractPreview.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">


                      <input class="hi" type="hidden" name="house_no"  value="<?php echo $house_no;?>">

 

                      <input  id="item" type="submit" value="Preview contract" name="post"  >

                 </form>
        </li>
 
                <li>
           
                  <form action="EditMyHouseProfileFormPro.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">


                      <input class="hi" type="hidden" name="house_no"  value="<?php echo $house_no;?>">

 

                      <input  id="item" type="submit" value="Edit house profile" name="post"  >

                 </form>
              </li>
        

        <li>
           
                  <form action="getMyHouseRoomForContract.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">


                      <input class="hi" type="hidden" name="house_no"  value="<?php echo $house_no;?>">

 

                      <input  id="item" type="submit" value="Sign contract" name="post"  >

                 </form>
        </li>
  </ul>
  <!--TAIL-->

  <fieldset id="new_item_reg_form">
  
<label id="reg_form_tile_label">Add new item here </label></p/>
<i>Please fill the form below to add new item-</i>
<form name="new_user_registration" id="new_user_registration" action="EditMyHouseRoomForm.php" method="POST" autocomplete="on" enctype="multipart/form-data">

<table border="0" id="reg_form_table">

   <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">


   <input class="hi" type="hidden" name="house_no"  value="<?php echo $house_no;?>">

   <input type="hidden" name="roomid" id="roomid" class="prof_info" value="<?php echo $room_no;?>"/>
  
  
<tr>
  
  <td height="40px" align="right" width="40%" valign="top">

        <label id="mini_label">Room category:<sup>*</sup></label><br>

  </td> 


  <td id="reg_form_table_cell">
     
         <select name="category" id="category" class="prof_info">
         <option value=""></option>
         <option value="Self">Self</option>
         <option value="None self">None self</option>
       </select><br/><sup id="rc"></sup>
         
         
  </td>

</tr>
  <tr>
 
  <td height="40px" align="right"  valign="top">

        <label id="mini_label">Contract duration:<sup>*</sup></label><br>

  </td> 

  <td id="reg_form_table_cell">

    
         <input type="text" name="cduration" id="cduration" class="prof_info"  value="<?php echo $cduration;?>" /><br/>
         <sup id="cd"></sup>
  </td>

  </tr>


 

  <tr>
 
  <td height="40px" align="right" valign="top">

        <label id="mini_label">Cost:<sup>*</sup></label><br>

  </td> 

  <td id="reg_form_table_cell">

    
         <input type="text" name="rcost" id="rcost" class="prof_info"  value="<?php echo $rcost;?>" /><br/>
         <sup id="rt"></sup>
  </td>
  
 </tr>
 <tr>
 
   <td align="right"> Currency:</td><td><input type="text" name="currency" id="currency"  value="<?php echo $currency;?>" class="prof_info" />
   </td>
 </tr>
 
 

  <tr>
 
  
  <td id="reg_form_table_cell" colspan="2">

        <label id="mini_label">Finishing description:<sup>*</sup></label><br>

   


    
         <textarea   name="description" id="description"  width="95%"  height="60px" ><?php echo $description;?></textarea><br/>
         <sup id="rd"></sup>
  </td>

  </tr>

   
<tr>

  <td colspan="2" align="center">
        <input type="submit"  name="post" value="Submit" id="submit" />
  </td>

</tr>

</table>
 
</form>
</fieldset> </center>
  <?php
 }
else{
   echo "The room not found!";
}
    }
    else{
    echo "SOMETHING WENT WRONG!";
  }
  }
  else{
    echo "NETWORK ERROR!";
  }
  ?>
<script>

 
 
$(document).ready(function(){
 
$("#new_user_registration").on('submit',function(e){

// e.preventDefault();
 
  
var category =document.getElementById('category').value;
$.trim(category);  
 
var cduration =document.getElementById('cduration').value;
$.trim(cduration);
   
var rcost=document.getElementById('rcost').value;
$.trim(rcost);  

var currency=document.getElementById('currency').value;
$.trim(currency);

var description=document.getElementById('description').value;
$.trim(description);
 
var vN =/[\(A-Za-z)]/g;
var nV =/[a-z\s]/i;
var nR =/[\sA-Za-z0-9]/i;
var nC =/[0-9]/i;
var j=0,k=0, g=0,i=0;
                      //////IMAGE VALIDATION

 


                                                         //ROUTE START VALIDATION
if(category=="")
{
e.preventDefault();

document.getElementById('rc').innerHTML="Category required!..";
 } 
 else
 { 
   document.getElementById('rc').innerHTML="";
 }
 
                                                                               ///ROUTE LENGTH VALIDA
if(cduration==""){
 e.preventDefault();

document.getElementById('cd').innerHTML="Contract duration required!..";
 }
 else{

     for(i=0;i<cduration.length;i++)
       {
         if(!cduration[i].match(nR))
          {
             j++;

           }
        }
      
       if(j>0){
       e.preventDefault();
 
        document.getElementById('cd').innerHTML="Contract duration typed with error!.."; 
              }
         else{
       

        document.getElementById('cd').innerHTML="";

              }
   }
 
    j=0, i=0;
      
 
                                                                            ///VIA VALIDATION

 


                                                         //ITEM COST DESTINATION VALIDATION
var nC =/[0-9]/i;
if(rcost=="" || currency==""){
 e.preventDefault();

document.getElementById('rt').innerHTML="Both cost and currency are required!..";
 
 
              }
 else{

     for(i=0;i<rcost.length;i++)
       {
         if(!rcost[i].match(nC))
          {
             j++;

           }
        }
      
       if(j>0){
        e.preventDefault();

        document.getElementById('rt').innerHTML="Cost typed with error!.."; 
              }
         else{

        document.getElementById('rt').innerHTML="";

              }
   }
 
    j=0, i=0;
                                                                               ///DESTINATION DISTANCE FROM LOCATION VALIDATION
 

if(description==""){
 e.preventDefault();

document.getElementById('rd').innerHTML="Description required!..";
 }
  
    else{
       

        document.getElementById('rd').innerHTML="";

               
   }
 
  
}
);
}
);  
    
 
</script>



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

