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

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

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

   if($post=="UPLOAD"){

   ini_set('upload_max_filesize', '2M');
   ini_set('post_max_size', '2M');
   ini_set('max_input_time', 300);
   ini_set('max_execution_time', 300);
  
    $fn = $_FILES["imagefile"]["name"]; 
    $type=$_FILES["imagefile"]["type"];
    $size=$_FILES["imagefile"]["size"];
    $error=$_FILES["imagefile"]["error"];
    $tmp_name=$_FILES["imagefile"]["tmp_name"];
    $ext = pathinfo($fn, PATHINFO_EXTENSION);
    $allowedtype=array('png','jpg','jpeg','gif','jpeg','JPG','JPEG','GIF','PNG');

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

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


   $room_no=$_POST['room_no'];
   $cduration=$_POST['cduration'];
   $category =$_POST['category'];  
   $description =$_POST['description'];
   $rcost =$_POST['rcost'];
   $currency=$_POST['currency'];
   $imgdescription=$_POST['imgdescription'];
  // $itemid =substr(Date("Ymdhis"),2);

if($hcon->vImageType($ext,$allowedtype) && $hcon->vImageError($error) && $hcon->vImageSize($size) && $hcon->vRoomImageExist($fn) && $hcon->vImageSelectF($fn) ){

   if($hcon->vRoomno($room_no) && $hcon->vCategory($category) && $hcon->vcduration($cduration) && $hcon->vdescription($description) && $hcon->vimgdescription($imgdescription) && $hcon->vrcost($rcost,$currency))
      {
        ?>
         <center>
         <div>
        
        <?php 
         $r= $hcon->addHouseRoom($house_no,$room_no,$category,$rcost,$currency,$cduration,$description,$imgdescription,$fn,$tmp_name);
        //print_r($r= $hcon->addHouseRoom($house_no,$room_no,$category,$rcost,$currency,$cduration,$description,$imgdescription,$fn,$tmp_name));
        
         if($r->rowCount()>0)
         {
          // echo $scon->uploadImage($fn,$itemname, $itemid,$tmp_name,$shopid);
          $room_no="";
          $cduration= "";
          $category ="";    
          $description = "";
          $rcost ="";
          $currency="";
          $imgdescription="";
         }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->eimgdescription($imgdescription)."<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
        /////////////

      }
    }
    else{
///////////////////////
      ?>
         <center>
         <div>
         <sup>
             <?php
              echo $hcon->eImageType($ext,$allowedtype)."<p/>";
              echo $hcon->eImageError($error)."<p/>";
              echo $hcon->eImageSize($size)."<p/>";
              echo $hcon->eRoomImageExist($fn)."<p/>"; 
              echo $hcon->eImageSelectF($fn)."<p/>";
      //////////////////
       ?>
       </sup>
       </div>
       </center> 

        <?php
        }

}
 
 

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

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


<center>
<!---HEADING -->
<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>
</center>
<!--TAIL-->


 


<fieldset style="border-color:silver; border:0;padding-bottom:95%; width:100%; ">

<center>Before you upload an image please verify you image here:-</center>

    <div style="width:70%; margin-left:1%;" id="app">
     <div style="height:80px;" class="card bg-light mb-4" @change="change" @dragover="dragover" @drop="drop">  
          <div class="p-5 text-center">Drop image here or <input type="file" id="file" accept="image/jpeg,image/jpg,image/jpe,image/png,image/gif,image/webp,image/bmp,image/tiff" ref="input" onclick="var q=0; document.getElementById('inputQuality').value=q;"></div>
       
      <div class="row">
        <div class="col-lg-4 mb-4">
          <div class="card">
            <div class="card-body">
              <h3 class="card-title">Options</h3>
              <hr>
              <fieldset class="form-group">
                <div class="form-check form-check-inline">
                  <input type="checkbox" name="checkOrientation" class="form-check-input" id="inputCheckOrientation" v-model="options.checkOrientation">
                  <label class="form-check-label" for="inputCheckOrientation">checkOrientation</label>
                </div>
              </fieldset>
            
              <div class="form-group row">
                <label for="inputQuality" class="col-sm-5 col-form-label">quality</label>
                <div class="col-sm-7">
                  <input type ="text" class="form-control" name="quality" id="inputQuality"v-model.number="options.quality">
                  
                  </select>
                </div>
              </div>
              <div class="form-group row">
                <label for="inputMimeType" class="col-sm-5 col-form-label">mimeType</label>
                <div class="col-sm-7">
                  <input type="text" name="mimeType" class="form-control" id="inputMimeType" placeholder="auto" v-model.number="options.mimeType">
                </div>
              </div>
              <div class="form-group row mb-0">
                <label for="inputConvertSize" class="col-sm-5 col-form-label">convertSize</label>
                <div class="col-sm-7">
                  <input type="number" name="convertSize" class="form-control" id="inputConvertSize" placeholder="5000000" v-model.number="options.convertSize">
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="col-lg-8 mb-4">
          <div class="card mb-4">
            <div class="card-body">
              The image you selected is not compatible, download the equivalent compatible copy.  
              <hr>
              <div class="row">
                <div class="col-md-4 d-flex">
                  <div class="w-100 text-center" v-if="inputURL">
                    <img class="mw-100" :src="inputURL" :alt="input.name">
                  </div>
                  <div v-else class="w-100 bg-light"></div>
                </div>
                <div class="col-md-8">
                  <dl class="row"> 
                    <dt class="col-sm-5">name:</dt>
                    <dd class="col-sm-7">{{ input.name || 'N/A' }}</dd>
                    <dt class="col-sm-5">type:</dt>
                    <dd class="col-sm-7">{{ input.type || 'N/A' }}</dd>
                    <dt class="col-sm-5">size:</dt>
                    <dd class="col-sm-7">{{ input.size | prettySize }}</dd>
                  </dl>
                </div>
              </div>
            </div>
          </div>
          <div class="card">
            <div class="card-body">
               Plealse  download the compatible version below:- 
              <hr>
              <div class="row">
                <div class="col-md-4 d-flex justify-content-center">
                  <div class="w-100 text-center" v-if="outputURL">
                    <img class="mw-100" :src="outputURL" :alt="output.name">
                    <div class="mt-2">
                      <a class="btn btn-sm btn-blocks btn-outline-primary mt-2" :download="output.name" :href="outputURL" title="Download the compressed image" sysle="color:blue;" >Download</a>
                    </div>
                  </div>
                  <div v-else class="w-100 bg-light"></div>
                </div>
                <div class="col-md-8">
                  <dl class="row"> 
                    <dt class="col-sm-5">name:</dt>
                    <dd class="col-sm-7">{{ output.name || 'N/A' }}</dd>
                    <dt class="col-sm-5">type:</dt>
                    <dd class="col-sm-7">{{ output.type || 'N/A' }}</dd>
                    <dt class="col-sm-5">size:</dt>
                    <dd class="col-sm-7">{{ output.size | prettySize }}
                      <span v-if="output.size">({{ ((1 - (output.size / input.size)) * 100).toFixed(2) }}% off)</span>
                    </dd>
                  </dl>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    </div>
<!--TAIL-->


  <table style="width:27%; margin-left:72%;" border="0" class="himgf" >
        
          <tr>
               <td>

               <label id="reg_form_tile_label"> Add house post here:- </label>

               </td></tr>
               <tr> 

              
          
         <form name="new_user_registration" id="new_user_registration" action="addHouseRoomForm.php" method="POST" autocomplete="on" enctype="multipart/form-data">
      <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">


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



   <tr>
  
  <td  valign="top">

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

  </td> 
</tr>
<tr> 

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

</tr>


<tr>
  
  <td   valign="top">

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

  </td> 

</tr>


<tr>
  <td>
     
         <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    valign="top">

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

  </td> 
</tr>


<tr>
  <td>

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

</tr>


 

<tr>
 
  <td>

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

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

  <tr>
 
  <td>

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

  </td> 
</tr>

<tr>

  <td>

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

</tr>

<tr>

              <td valign="top" id="hf"> 

                   <label id="mini_label">Image name(Title):<sup>*</sup></label>

              </td>
</tr>
<tr> 
              <td valign="top">
              
              <input type="text" name="imgdescription" id="imgdescription"  class="prof_info"/  value="<?php echo $imgdescription;?>">
              <sup id="nf"></sup>
              </td>
 </tr>
 <tr>
              <td valign="top" id="hf"> 

              <label id="mini_label">Choose image:<sup>*</sup></label>

              </td>
       </tr>
       <tr> 
              <td valign="top">

              <input type="file" class="prof_info" name="imagefile" id="imagefile"  onchange="readURL(this);"/>
              <sup id="mg"></sup>;
              </td>
        </tr>
        <tr>
        <td height="120px">
               	 <div id="deta" ><img style="width:100%;" id="image">  </div> 
         </td>
       </tr>
        <tr> 
           <td >
          <center>

            <input type = "submit" value="UPLOAD" name="post"  id="submit"  />

         </center>
          </td>
       </tr>

           </form> 


 
  </table> 
 
</fieldset>




















 
  <?php
 
    }
    else{
    echo "NETWORK ERROR!";
  }
  }
  else{
    echo "NETWORK ERROR!";
  }
  ?>
<script>

   document.getElementById("imagefile").onchange = function () {
    var reader = new FileReader();

    reader.onload = function (e) {
        // get loaded data and render thumbnail.
        document.getElementById("image").src = e.target.result;
    };

    // read the image file as a data URL.
    reader.readAsDataURL(this.files[0]);
}
 
$(document).ready(function(){
 
$("#new_user_registration").on('submit',function(e){
// e.preventDefault();
var imgdescription =document.getElementById('imgdescription').value;
$.trim(imgdescription);
var room_no =document.getElementById('room_no').value;
$.trim(room_no);  
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 floc= document.getElementById('imagefile').value
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

if (floc=="") 
    {
   e.preventDefault();
    document.getElementById('mg').innerHTML="Image file is required!..";
    }
    else
    {

    document.getElementById('mg').innerHTML="";
    }

                                                         //ITEM NAME VALIDATION
if(room_no=="")
{
e.preventDefault();

document.getElementById('rn').innerHTML="Room no  required!..";
 } 
 else
 {
 
        document.getElementById('rn').innerHTML="";
 
  }
 
     


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

document.getElementById('rc').innerHTML="Category required!..";
 } 
 else
 { 

        

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

    
   }
 
 
                                                                               ///ROUTE LENGTH VALIDATION
 

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="";

               
   }
 
    
  if(imgdescription==""){
 e.preventDefault();

document.getElementById('nf').innerHTML="Image description required!..";
 }
  
    else{
       

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

               
   }
 
    
      
     
 
                                                                            ///ROOM ID VALIDATION
  
  
}
);
}
);  
    
 
</script>

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


