<?php

require_once("head2Alt.php");

if(isset($_POST["post"])){

       require_once("buda_connect.php");

       $con=new connect_class();

       $post=$_POST['post'];

        $ownID=$_POST["owniD"];

  if (isset($_POST["owniD"])) {

 

  if($post=="UPLOAD")
  {
    ///////////////////////UPLOAD IMAGE HERE////////////////
    //////////////////////////////////////////////////
   
//session_start();
//set_time_limit(); 
ini_set('upload_max_filesize', '2M');
ini_set('post_max_size', '2M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);
 
 if( isset($_FILES['file']['name'])   && isset( $_FILES["file"]["tmp_name"]))
 {
  
   $fn = $_FILES["file"]["name"]; 
 
   $type=$_FILES["file"]["type"];

   $size=$_FILES["file"]["size"];

   $error=$_FILES["file"]["error"];

   $tmp_name=$_FILES["file"]["tmp_name"];

   $ext = pathinfo($fn, PATHINFO_EXTENSION);
 

   $allowedtype=array('png','jpg','jpeg','gif','jpeg','JPG','JPEG','GIF','PNG');

//list($height,$width)=getimagesize($tmp_name);


//echo " Name:  ".$fn ."Type:  ".$type ." Size:  ".$size."  Temp_Name:  ".$tmp_name."  Extension:  ".$ext.$hid;

// alternative way for checking type if($ext=='png' || $ext=='JPEG' || $ext=='gif' || $type=='jpg')
 
if(!$con->vImageType($ext,$allowedtype) || !$con->vImageError($error)  || !$con->vImageSize($size) || !$con->vImageProfileExist($fn) || !$con->vImageSelectF($fn))
  {
  ?>
<center>
  
  <section>

     <sup>
      
      <?php
         echo $con->eImageType($ext,$allowedtype)."<p/>";
         echo $con->eImageSize($size)."<p/>";
         echo $con->eImageError($error)."<p/>";
         echo $con-> eImageProfileExist($fn)."<p/>" ; 
         echo $con->eImageSelectF($fn)."<p/>" ; 
      ?>
      </sup>

  </section>

 </center>
 <?php
    require("myAccountProfileAfterPost.php");
  }

else{

    ?>
 <center>
  
  <div>

    <sup>
     
     <?php
    
       echo $con->uploadProfileImage($fn, $ownID,$tmp_name);
      
      ?>
    
    </sup>
   
   </div>

    <?php

      require("myAccountProfileAfterPost.php");
    }
  

  }
else
  {
    echo "Error occured when page load!..";


      require("myAccountProfileAfterPost.php");
  }
 



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

  }

      //////////////////////////////////////////////////////////
       ////////////////////BLOCK OF CODE EXECUTED WHEN FORM IS TO BE LOADED //////////////
       //////////////////////////////////////////////////////////////

  if($post=="Upload profile photo"){
	 

       $HD=$con->getOwnerAddImage($ownID);
       if($HD->rowCount()<=0)
          {

          echo "Page time out".$ownID;
          }
       else
          { 

         
  
  ?>

<center><table  class="himgf" >
        
          <tr>
               <td colspan="2">

                      <label id="reg_form_tile_label"> Upload profile image here:- </label>

               </td>

               <td rowspan="3" width="30%">
               	 <div id="deta" ><img id="image">  </div> 
               </td>
          </tr>

         <form  name="upload_form" id="upload_form" action="myAccountProfileImageForm.php"   method="post"   autocomplete="on" enctype="multipart/form-data">

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

        
          

          <tr>
              <td valign="top" id="hf" height="55px"> 

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

              </td>

              <td valign="top">

              <input type="file" class="prof_info" name="file" id="file"  onchange="readURL(this);"/>
              <sup id="mg"></sup>
              </td>
           </tr>

           <tr> 

               <td colspan="2">

                 <center>

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

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

           </form> 


 
  </table>
<!--<table><tr><td><div id="detail" > </div></td></tr> </table>-->
</center>
 

<script>

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

    reader.onload = function (e) { 
        document.getElementById("image").src = e.target.result;
    };
     reader.readAsDataURL(this.files[0]);
}
 
$(document).ready(function() {
	
	
  $(" #upload_form").on('submit',(function(e){
	var floc= document.getElementById('file').value 
	var ownID = document.getElementById('owniD').value;  
	var nV =/[a-z\s]/i;
  var j=0,k=0, g=0,i=0;
  var vN =/[\(A-Za-z0-9)]/g;
 if (floc=="") 
    {
	 e.preventDefault();
    document.getElementById('mg').innerHTML="Image file is required!..";
    }
    else
    {

    document.getElementById('mg').innerHTML="";
    }
                                                         //TITLE VALIDATION
 
                                                                               ///ROOM ID VALIDATION


    
	})); 
	 
}); 
</script>
<?php
}
 }
 else{
  echo "Page load time out";
 }
 
}
}
 
require_once('footerIn.php');
?>
