<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once("../head2Alts.php");

//echo "YES";
if(isset($_POST['itemid']) && isset($_POST['shopid']) && isset($_POST['owniD']))
  {
 $itemid=$_POST['itemid'];
 $shopid=$_POST['shopid'];
 $owniD=$_POST['owniD'];
 $post=$_POST['post'];
 //$result=0; 
 $rQ="";     //require_once("buda_connect.php");

       //$con=new connect_class();

$item=$scon->getThisItem($itemid);
if($item->rowCount()<=0){ 
          

          echo "Page time out";
          }
       else
          {
  

///////////////////////IF THE UPLOAD BUTTON IS CLICK///////////////////
            ///////////////////////////////////

  /////////////
if ($post=="UPLOAD") 
{
  $result=0;
   ini_set('upload_max_filesize', '1M');
   ini_set('post_max_size', '1M');
   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');

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

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


 $itemname=$_POST['title']; 

if($scon->vImageType($ext,$allowedtype) && $scon->vimagename($itemname) && $scon->vImageError($error) && $scon->vImageSize($size) && $scon->vImageExist($fn) && $scon->vImageSelectF($fn) )
{
$result=0;
           $rQ= $scon->updatePImage($fn,$itemname, $itemid,$tmp_name);//uploadImage($fn,$itemname, $itemid,$tmp_name,$shopid);
          /* if ($rQ->rowCount()>0) 
           {
            // $result=$rQ->rowCount();
             echo "Upload successful!..";
           }
           else{
            $result=$rQ ;
            echo "Error in upload!..";
           }*/

}
else{
     //////////////
        ?>
         <center>
         <div>
         <sup>
             <?php 

              echo  $scon->eimagename($itemname)."<p/>";
              echo $scon->eImageType($ext,$allowedtype)."<p/>";
              echo $scon->eImageError($error)."<p/>";
              echo $scon->eImageSize($size)."<p/>";
              echo $scon->eImageExist($fn)."<p/>"; 
              echo $scon->eImageSelectF($fn)."<p/>";
             ?>
       </sup>
       </div>
       </center> 

        <?php
}


}


 if ($post=="UPLOAD" && $result>0) {
   require('editItemSucessfull.php');
 }
 else{
 if ($post=="UPLOAD") {
   //echo $rQ;
  // print_r($result);
 }
 $itm=$item->fetch();
 
          ?>
          <center>
       <?php
      $getS=$scon->getSelectedShopOther($shopid);
      if ($getS->rowCount()>0)
       {
          $shop=$getS->fetch();

       }
         require_once('shopNavLink.php');
         ?>
         </center>
         
         
         
         
         
         
         
 <!--   IMAGE COMPRESSION-->
<? /*
<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:25%; margin-left:72%;" border="0" class="himgf" >
        
          <tr>
               <td colspan="2">

               <label id="reg_form_tile_label"> Upload more images for <?php echo $itm['itemname'];?> here:- </label>

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

               <td height="120px">
               	 <div id="deta" ><img style="width:100%;" id="image">  </div> 
               </td>
          </tr>
          
         <form  name="upload_form" id="upload_form" action="addMoreItemImages.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="shopid"  value="<?php echo $shopid;?>">

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

          <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="title" id="title"  class="prof_info"/>
              <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);getMeta(url);"/>
              <sup id="mg"></sup>;
              </td>
        </tr>

           <tr> 

               <td >

                 <center>

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

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

           </form> 


 
  </table>
<!--<table><tr><td><div id="detail" > </div></td></tr> </table>-->
 
</fieldset>
 <?php
}
 }
 
}
else{
	echo "Oops page not found!";
}

?>

<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() {

	
  $(" #upload_form").on('submit',(function(e){
     // e.preventDefault();
	var floc= document.getElementById('imagefile').value
	var tit = document.getElementById('title').value; 
	var nV =/[A-Za-z0-9\s]/i;
    var j=0,k=0, g=0,i=0;
if (floc=="") 
    {
	 e.preventDefault();
    document.getElementById('mg').innerHTML="Image file is required!..";
    }
    else
    {

    document.getElementById('mg').innerHTML="";
    }
                                                         //TITLE VALIDATION
if(tit=="")
{
 e.preventDefault();

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

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

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

       
        document.getElementById('nf').innerHTML="Typed title with error!.."; 


              }
         else{

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

              }
   }
 
    j=0, i=0;
                                                                               ///MIDDLE NAME VALIDATION
 

	/*
	if($.trim(hid) !=""  && $.trim(tit) !="" && $.trim(floc) !=""){
	 var formData = new FormData($("#upload_form")[0]);
	  
      formData.append("hotelid",hid);
	  formData.append("room",roo);
	  formData.append("title",tit);
		$.ajax({
			url:"image_upload_form_pro.php",
			
			type: "POST",
			
			data: formData,
			//async:false,
			contentType: false,
			cache: false,
			processData: false,
			
			success:function(data){
				$("#detail").html(data).show();
			}
			
		});
 
	}else{alert("You are trying to send incomplete information!..") ;}*/
	})); 
	 
}); 
</script>
<?php
 require_once('../footerIns.php');
?>