 <?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'];///////////////
 //////////////
 
   $edate= "";
   $sdate ="";    
   $rentorid= "";
   $currency="";
   $rcost=""; 
   $post=$_POST['post'];

   if($post=="Submit")
  {
 
        /////////////////
 
        ///////////////// 
        $edate=$_POST['edate'];
        $sdate =$_POST['sdate'];  
        $rentorid =$_POST['rentorid'];
        $rcost=$_POST['rcost'];
        $currency=$_POST['currency'] ;
       // $itemid =substr(Date("Ymdhis"),2);

 
   if($hcon->vsdate($sdate) && $hcon->vedate($edate) && $hcon->vrcost($rcost,$currency))
      {
        ?>
         <center>
         <div>
        
           <?php 

                 $ownerid=$_POST['rentorid'];

                 $OW =$con->checkIdOfUserIfExist($ownerid);
     

                  if($OW->rowCount()<=0)
                 

                 {
                    ?>
                       <center><font color="red" ><section style="background-color:silver;width:50%;align-content: left;">
                       <?php
                        echo $accountId="User with Id ".$ownerid." not exist!..";

                        ?>
  
                        </section> </font></center>
                        <?php
                       // require("EditMyHouseProfileForm.php");
               }
             
              else

              {

                  $r= $hcon->addHouseRentContract($ownID,$rentorid,$roomid, $house_no, $sdate,$edate,$rcost,$currency);
         
                       //print_r($r);
                       if($r->rowCount()>0)
                      
                        {
                
                          echo "Update successfully!..";
                          $edate= "";
                          $sdate ="";    
                          $rentorid= "";
                          $currency="";
                          $rcost="" ;
                        }

                       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->esdate($sdate)."<p/>"; 
              echo  $hcon->eedate($edate)."<p/>"; 
              echo  $hcon->vrcost($rcost,$currency);
    
             ?>
       </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="text" name="owniD"  value="<?php echo $ownID;?>">


                      <input class="hi" type="text" 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 contract here </label></p/>
<i>Please fill the form below to add new contract-</i>
<form name="new_user_registration" id="new_user_registration" action="signContractPage.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"  value="<?php echo $room_no;?>"  />
  
  
<tr>
  
  <td height="40px" align="right" width="40%" valign="top">

        <label id="mini_label">Enter rentor id here:</label><br>

  </td> 
<td height="40px" align="right" width="40%" valign="top">
<sup id="rd">*</sup>
<input type="text" name="rentorid" id="rentorid" class="prof_info" value="<?php echo $rentorid;?>" >
   
</td>
</tr>
<tr>
  
  <td height="40px" align="right" width="40%" valign="top">

        <label id="mini_label">Cash paid:</label><br>

  </td> 
<td height="40px" align="right" width="40%" valign="top">
<sup id="rt">*</sup>
<input type="text" name="rcost" id="rcost" class="prof_info" value="<?php echo $rcost;?>" >
   
</td>
</tr>
<tr>
  
  <td height="40px" align="right" width="40%" valign="top">

        <label id="mini_label">Currency:</label><br>

  </td> 
<td height="40px" align="right" width="40%" valign="top">
<sup id="rt">*</sup>
<input type="text" name="currency" id="currency" class="prof_info" value="<?php echo $currency;?>" >
   
</td>
</tr>

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

        <label id="mini_label">Starting date:</label><br>

  </td> 
<td height="40px" align="right" width="40%" valign="top">
<sup id="sd">*</sup>
<input type="date" name="sdate" id="sdate" class="prof_info" value="<?php echo $sdate;?>" >
   
</td>
</tr>

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

        <label id="mini_label">Ending date:</label><br>

  </td> 
<td height="40px" align="right" width="40%" valign="top">
<sup id="ed">*</sup>
<input type="date" name="edate" id="edate" class="prof_info" value="<?php echo $sdate;?>" >
   
</td>
</tr>
  

 

   
<tr>

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

</tr>

</table>
 
</form>
</fieldset> </center>


  <?php
 
    
  }
  else

    {
    echo "SOMETHING WENT WRONG!";
  }
  }
  else{
    echo "NETWORK ERROR!";
  }
  ?>
<script>

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

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

var currency=document.getElementById('currency').value;
$.trim(currency);
var sdate =document.getElementById('sdate').value;
$.trim(rentorid);  
 
var edate =document.getElementById('edate').value;
$.trim(edate);
   
var rentorid=document.getElementById('rentorid').value;
$.trim(rentorid); 
 
var vN =/[\(A-Za-z)]/g;
 var nC =/[0-9]/i;
var nR =/[A-Za-z0-9]/i; 
var j=0,k=0, g=0,i=0;
                      //////IMAGE VALIDATION

 
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;
             

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

document.getElementById('sd').innerHTML="Starting date required!..";
 } 
 else
 { 
   document.getElementById('sd').innerHTML="";
 }
 
 if(edate=="")
{
e.preventDefault();

document.getElementById('ed').innerHTML="Ending date required!..";
 } 
 else
 { 
   document.getElementById('ed').innerHTML="";
 }
 
                                                                               ///ROUTE LENGTH VALIDA
if(rentorid==""){
 e.preventDefault();

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

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

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

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

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

 


    
  
}
);
}
);  
    
 
</script>

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



