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

if(isset($_POST['itemid']) && isset($_POST['shopid']) && isset($_POST['owniD']))
  {
 $itemid=$_POST['itemid'];
 $shopid=$_POST['shopid'];
 $owniD=$_POST['owniD'];
//////////////////
 //////////////
$result=0;
$item=$myAgrocon->getThisItem($itemid);
if($item->rowCount()>0){
   $itm=$item->fetch(); 
    
 

   $itemname=$itm['itemname'];
   $itemtype=$itm['itemtype'];
   $itemcategory= $itm['itemcategory'];
   $expiredate =$itm['expiredate'];   
   $itemdescription =$itm['description'];
   $itemcost =$itm['itemcost'];
   $currency=$itm['currency'];
   $post=$_POST['post'];
}
   
    
        /////////////////
if ($post=="Submit") {
      /////////////////


   $itemname=$_POST['itemname'];
   $itemtype=$_POST['itemtype'];
   $itemcategory =$_POST['itemcategory'];
   $expiredate =$_POST['expiredate']; 
   $itemdescription =$_POST['itemdescriptrion'];
   $itemcost =$_POST['itemcost'];
   $currency=$_POST['currency']; 
 

   if($myAgrocon->vitemname($itemname) && $myAgrocon->vitemcategory($itemcategory) && $myAgrocon->vitemtype($itemtype) && $myAgrocon->vitemdescription($itemdescription) && $myAgrocon->vitemcost($itemcost,$currency) && $myAgrocon->vexpiredate($expiredate))
      {
        ?>
         <center>
         <div>
        
        <?php 
         $r= $myAgrocon->updateItem($itemid,$itemdescription,$itemcost,$itemcategory,$itemname,$itemtype,$expiredate,$shopid,$currency);
         if($r->rowCount()>0)
         {  
           $result=$r->rowCount(); 
         }
         else{
          echo "Submission error!..";
         // $u=$r->ErrorInfo();
          //print_r($u);//"Error occurred while saving data!..";
              }
        ?> 
       </div>
       </center> 

        <?php
    
      }
      else{

        //////////////
        ?>
         <center>
         <div>
         <sup>
             <?php 
              echo  $myAgrocon->eitemname($itemname)."<p/>";
              echo  $myAgrocon->eitemtype($itemtype)."<p/>";
              echo  $myAgrocon->eitemcategory($itemcategory)."<p/>";
              echo  $myAgrocon->eitemdescription($itemdescription)."<p/>";
              echo  $myAgrocon->eitemcost($itemcost,$currency)."<p/>";
              echo  $myAgrocon->eexpiredate($expiredate)."<p/>";
    
             ?>
       </sup>
       </div>
       </center> 

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

      }

}
  
 if ($post=="Submit" && $result>0) {
   require('editItemSucessfull.php');
 }
 else{


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


<center><fieldset id="edit_item_reg_form">
<label id="reg_form_tile_label">Edit item profile here:- </label></p/>
<i>Please fill the form below to add new item-</i>
<form name="new_user_registration" id="new_user_registration" action="editItemprofile.php" method="POST" autocomplete="on" enctype="multipart/form-data">

<table border="0" id="reg_form_table">

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


   <input class="hi" type="text" name="shopid"  value="<?php echo $shopid;?>">

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

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

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

  </td> 


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

</tr>
  
<tr>
  
  <td height="40px" width="30%" valign="top">

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

  </td> 


  <td id="reg_form_table_cell">
     
         <input type="text" name="itemtype" id="itemtype" class="prof_edit" value="<?php echo $itemtype;?>"  /><br/>
         <sup id="ln"></sup>
         
  </td>

</tr>
  <tr>
 
  <td height="40px"   valign="top">

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

  </td> 

  <td id="reg_form_table_cell">

    
         <input type="text" name="itemcategory" id="itemcategory" class="prof_edit"  value="<?php echo $itemcategory;?>" /><br/>
         <sup id="rt"></sup>
  </td>

  </tr>


<tr>
 
  <td height="40px"   valign="top">

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

  </td> 

  <td id="reg_form_table_cell">

    
         <input type="date" name="expiredate" id="expiredate" class="prof_edit" value="<?php echo $expiredate;?>"  /><br/>
         <sup id="rv"></sup>
  </td>

  </tr>

  <tr>
 
  <td height="40px"  rowspan="2" valign="top">

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

  </td> 

  <td id="reg_form_table_cell">

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

  </tr>
 <tr>
   <td align="right"> Currency:<input type="text" name="currency" id="currency"  value="<?php echo $currency;?>" />
   </td>

    
</tr>

  <tr>
 
  <td height="40px"   valign="top">

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

  </td> 

  <td id="reg_form_table_cell"  >

    
         <textarea   name="itemdescriptrion" id="itemdescriptrion"  width="100%"  height="60px" value="<?php echo $itemdescription;?>" /></textarea><br/>
         <sup id="rd"></sup>
  </td>

  </tr>

   
<tr>

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

</tr>

</table>
 
</form>
</fieldset> </center>
  <?php
 }
    }
    else{
    echo "NETWORK ERROR!";
  }
  }
  else{
    echo "NETWORK ERROR!";
  }
  ?>
<script>

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

//e.preventDefault();
var itemname =document.getElementById('itemname').value;
$.trim(itemname);  
var itemtype =document.getElementById('itemtype').value;
$.trim(itemtype);  
 
var itemcategory =document.getElementById('itemcategory').value;
$.trim(itemcategory);

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

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

var itemdescriptrion=document.getElementById('itemdescriptrion').value;
$.trim(itemdescriptrion);
 
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

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

document.getElementById('si').innerHTML="Item name  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 item name with error!.."; 


              }
         else{

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

              }
   }
 
    j=0, i=0;


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

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

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

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

       
        document.getElementById('ln').innerHTML="Item type typed with error!.."; 


              }
         else{

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

              }
   }
 
    j=0, i=0;
                                                                               ///ROUTE LENGTH VALIDATION
 

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

document.getElementById('rt').innerHTML="Item 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="Item category typed with error!.."; 
              }
         else{
       

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

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


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

document.getElementById('rv').innerHTML="Expire date required!..";
 } 
 else
 {
 
 document.getElementById('rv').innerHTML="";
           
 }
 
    j=0, i=0;


                                                         //ITEM COST DESTINATION VALIDATION
var nC =/[0-9]/i;
if(itemcost=="" || currency==""){
 e.preventDefault();

document.getElementById('rdn').innerHTML="Both price 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('rdn').innerHTML="Item typed with error!.."; 
              }
         else{

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

              }
   }
 
    j=0, i=0;
                                                                               ///DESTINATION DISTANCE FROM LOCATION VALIDATION
 

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

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

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

               
   }
 
    j=0, i=0;
      
 
                                                                            ///ROOM ID VALIDATION
  
  
}
);
}
);  
    
 
</script>

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



