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

if(isset($_POST['owniD']))
  { 
 $owniD=$_POST['owniD'];
//////////////////
 //////////////
   $locationdescription="";
   $itemname="";
   $cphone= "";
   $itemcategory ="";
   $cperson = "";   
   $itemdescription = "";
   $itemcost ="";
   $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');

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

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


   $itemname=$_POST['itemname'];
   $cperson=$_POST['cperson'];
   $itemcategory =$_POST['itemcategory'];
   $cphone =$_POST['cphone']; 
   $itemdescription =$_POST['itemdescription'];
   $locationdescription =$_POST['locationdescription'];
   $itemcost =$_POST['itemcost'];
   $currency=$_POST['currency']; 

if($xcon->vImageType($ext,$allowedtype) && $xcon->vImageError($error) && $xcon->vImageSize($size) && $xcon->vImageExist($fn) && $xcon->vImageSelectF($fn) ){ 
   if($xcon->vitemname($itemname) && $xcon->vitemcategory($itemcategory) && $xcon->vcphone($cphone) && $xcon->vcperson($cperson) && $xcon->vitemdescription($itemdescription) && $xcon->vitemcost($itemcost,$currency) && $xcon->vlocationdescription($locationdescription))
      { 
        ?>
         <center>
         <div>
        
        <?php 
        $dealid=date("Ymdhis");
        $r= $xcon->addDealPost($dealid,$itemdescription,$itemcost,$itemcategory,$itemname,$cphone,$cperson,$locationdescription,$ownID,$fn,$currency);
         if($r->rowCount()>0)
         {
           $ro= $xcon->uploadImage($fn,$itemname,$tmp_name,$dealid);
           if ($ro->rowCount()>0) {
              echo "Post successful!..";
           $itemname="";
           $cperson= "";
           $itemcategory ="";
           $cphone = "";   
           $itemdescription = "";
           $locationdescription = "";
           $itemcost ="";
           $currency="";
           $locationdescription ="";
            }
            else
            {
              echo "Data not saved!..";
            }
         }else{
          echo "Submission error!..";
           $u=$r->ErrorInfo();
           print_r($u);//"Error occurred while saving data!..";
              }
        ?> 
       </div>
       </center> 

        <?php
    
      }
      else{

        //////////////
        ?>
         <center>
         <div>
         <sup>
             <?php  
              echo  $xcon->eitemname($itemname)."<p/>"; 
              echo  $xcon->eitemcategory($itemcategory)."<p/>";
              echo  $xcon->eitemdescription($itemdescription)."<p/>";
              echo  $xcon->elocationdescription($locationdescription)."<p/>";
              echo  $xcon->eitemcost($itemcost,$currency)."<p/>";
              echo  $xcon->ecperson($cperson)."<p/>";
              echo  $xcon->ecphone($cphone)."<p/>";
    
             ?>
       </sup>
       </div>
       </center> 

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

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

        <?php
        }

}
 
 

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

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

<center>
    <ul><li style="padding-right:3%;">

  <form action="hexaNdeal.php" method="post">
          <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">

               <input  class="pos" type="submit" value="My Deal Posts" name="post"  >
         </form>
        </li>
        
        
        <li style="padding-right:3%;">
        <form id="order" action="needPostForm.php" method="post">

                      <input class="hi" type="hidden" name="owniD"  value="<?php echo $ownID;?>">
                       
                      <input class="pos" type="submit" value="Post need" name="post">  

                 </form>
         </li>
        
        </ul>
      </center>
      
      
      
      
      
      
      
      
      
<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 >

               <label id="reg_form_tile_label"> Post you deal here:- <?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="new_user_registration" id="new_user_registration" action="dealPostForm.php" method="POST" autocomplete="on" enctype="multipart/form-data">
       <input class="hi" type="text" name="owniD"  value="<?php echo $ownID;?>"> 

          <tr>

              <td> 

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

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

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

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

        <select  name="itemcategory" id="itemcategory">
         <option value="">
         Select
         </option>
         <option value="Sell">
         Sell
        </option>
        <option value="Tender">
         Tender
        </option>
        <option value="Other">
         Other
        </option>
        </select><br/>  
         <sup id="rt"></sup>
      </td>

          </tr>
 
  <tr>

  <td>

       <label id="mini_label">Contact person:<sup>*</sup></label><br>
  </td>

  </tr>
  <tr>
  <td> 

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

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

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

    </td>
   </tr>
 <tr>
  

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


   </tr>


  <tr>
 
   

  <td >

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

          
  </td>
  <tr>
 
   

  <td  >
 

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

  </tr>
  <tr>
   <td > Currency:-
   </td>
</tr>
  <tr>
   <td  >  
   <select name="currency" id="currency" >
       <option  value="">Select</option>
       <option  value="TZS">TZS</option></option>
       <option  value="USD">USD</option>
   </select>
   </td>
</tr>


 <tr>
 
    

  <td>

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

  </tr>
  <tr>
 
    

  <td>
       <label id="mini_label">Deal location description:</label><br>
 
  </td>

  </tr>
  <tr>
 
    

  <td> 

          <textarea   name="locationdescription" id="locationdescription"  width="95%"  height="35px">
            <?php echo $locationdescription;?>
              
            </textarea><br/>
         <sup id="ld"></sup> 
  </td>

  </tr>
   <tr>
 
    

  <td height="60px">
 
    
         <textarea   name="itemdescription" id="itemdescription"  width="95%"  height="60px">
          <?php echo $itemdescription;?>
            
          </textarea><br/>
         <sup id="rd"></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 >

                 <center>

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

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

           </form> 


 
  </table> 
 
</fieldset>
      
      
      
  
       
  <?php
 
    }
    else{
    echo "ERROR OCCURED!";
  }
  }
  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 itemname =document.getElementById('itemname').value;
$.trim(itemname);  
var cphone =document.getElementById('cphone').value;
$.trim(cphone);  

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

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

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

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

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

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(itemname=="")
{
e.preventDefault();

document.getElementById('si').innerHTML="Deal title  required!..";
 } 
 else
 {

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

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

       
        document.getElementById('si').innerHTML="You typed deal title with error!.."; 


              }
         else{

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

              }
   }
 
    j=0, i=0;


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

document.getElementById('cp').innerHTML="A person to contact required!..";
 } 
 else
 {

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

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

       
        document.getElementById('cp').innerHTML="A person to contact typed with error!.."; 


              }
         else{

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

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

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

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

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

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

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

              }
   }
 
    j=0, i=0;
      
 ///VALIDATION
 
if(itemcost=="" || currency==""){
 e.preventDefault();

document.getElementById('cv').innerHTML="Both Capital value and currency are required!..";
 
 
              }
 else{

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

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

        document.getElementById('cv').innerHTML="Capital value typed with error!.."; 
              }
         else{

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

              }
   }
 
    j=0, i=0;
                                                                               // /i;
if(cphone==""){
 e.preventDefault();

document.getElementById('cpn').innerHTML="Phone number required!..";
 
 
              }
 else{

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

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

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

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

              }
   }
 
    j=0, i=0;

    //FROM LOCATION VALIDATION
 

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

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

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

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

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

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

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




