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

if( isset($_POST['admin']))
  {
// $shopid="20160828035211";//$_POST['shopid'];
// $owniD=$_POST['owniD'];
 
//////////////////
 /////////////

  // $vendor="";
   $itemname="";
   $itemtype= "";
   $itemcategory ="";
   //$expiredate = "";   
   //$itemdescription = "";
   $itemcost ="";
   $currency="";
   $post=$_POST['post'];

   if($post=="Submit"){

   /*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["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');*/

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

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


   $itemname=strtoupper($_POST['itemname']);
   $itemtype=strtoupper($_POST['itemtype']);
   $itemcategory =strtoupper($_POST['itemcategory']);
   //$expiredate =$_POST['expiredate']; 
  // $itemdescription =$_POST['itemdescriptrion']);
   $itemcost =$_POST['itemcost'];
   $currency=strtoupper($_POST['currency']);
   //$vendor=$_POST['vendor'];
   $itemid =substr(Date("Ymdhis"),2);

/*if($econ->vImageType($ext,$allowedtype) && $econ->vImageError($error) && $econ->vImageSize($size) && $econ->vImageExist($fn) && $econ->vImageSelectF($fn) ){ 
 if($scon->vvendor($vendor) &&$econ->vitemname($itemname) && $econ->vitemcategory($itemcategory) && $econ->vitemtype($itemtype) && $econ->vitemdescription($itemdescription) && $econ->vitemcost($itemcost,$currency) && $econ->vexpiredate($expiredate))*/
 
   if($pcon->vitemname($itemname) && $pcon->vitemcategory($itemcategory) && $pcon->vitemtype($itemtype)  && $pcon->vitemcost($itemcost,$currency))
   
   
      {
         // $scon->vvendor($vendor) && && $econ->vitemdescription($itemdescription)
        ?>
         <center>
         <div>
        
        <?php 
         //$r= $pcon->addItem($itemid,$itemdescription,$itemcost,$itemcategory,$itemname,$itemtype, $currency,$vendor);
         
         
         $re= $pcon->checkExistItem($itemcost,$itemcategory,$itemname,$itemtype,$currency);
         if($re->rowCount()<=0)
          {
          $r= $pcon->addItem($itemid, $itemcost,$itemcategory,$itemname,$itemtype, $currency);
          if($r->rowCount()>0)
          {
           //echo $scon->uploadImage($fn,$itemname, $itemid,$tmp_name,$shopid);
           $itemname="";
           echo "Submission successfully!..";
           $itemtype= "";
           $itemcategory ="";
           //$expiredate = "";   
          // $itemdescription = "";
           $itemcost ="";
           $currency="";
           $vendor="";
         }else{
         // echo "Submission error!..";
          $u=$r->ErrorInfo();
          //print_r($u);//"Error occurred while saving data!..";
              }
          }
          else{
              echo "Item exist!..";
          }
        ?> 
       </div>
       </center> 

        <?php
    
      }
      else{

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

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

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

        <?php
        }*/

}
 
 

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

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


<center>


 <?php
                  require_once('pharmacyNavLink.php');
   ?>           
                   

<!--TAIL-->

  <fieldset id="new_item_reg_form">
<label id="reg_form_tile_label">Add new item here </label></p/>
<i>Please fill the form below to add new item-</i>
<form name="new_user_registration" id="new_user_registration" action="postNewItemPharmacy.php" method="POST" autocomplete="on" enctype="multipart/form-data">

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

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

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

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

  </td> 


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

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

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

  </td> 


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

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

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

  </td> 

  <td id="reg_form_table_cell">

    
         <select name="itemcategory" id="itemcategory" class="prof_info"  value="<?php echo $itemcategory;?>">
          <option value="">Select</option>
          <option value="DROP">DROP</option>
          <option value="LIQUID">LIQUID</option>
          <option value="TABLET">TABLET</option>
          <option value="SYRINGE">SYRINGE</option> 
          <option value="SUSPENSION">SUSPENSION</option>
          <option value="SOLUTION">SOLUTION</option>
          <option value="CAPSULES">CAPSULES</option>
          <option value="INJECTION">INJECTION</option>
          <option value="SYRUP">SYRUP</option>
          <option value="INHALATION">INHALATION</option>
          <option value="OINTMENT">OINTMENT</option>
         <option value="PESSARY">PESSARY</option>
         <option value="CREAM">CREAM</option>
         <option value="GEL">GEL</option>
         <option value="SUPPOSITORY">SUPPOSITORY</option>
         <option value="SPRAY">SPRAY</option>
         <option value="POWDER">POWDER</option>
         <option value="GLOVES">GLOVES</option>
         <option value="NEEDLES">NEEDLES</option>
         <option value="CANULAS">CANULAS</option>
         <option value="SET">SET</option>
         <option value="CATHETER">CATHETER</option>
         <option value="TUBE">TUBE</option>
         <option value="RUBBER">RUBBER</option> 
         <option value="BANDAGE">BANDAGE</option>
         <option value="GAUZE">GAUZE</option>
         <option value="PLASTER">PLASTER</option>
         <option value="WOOL">WOOL</option>
         >
         <option value="Bone & Cartilage Products">Bone and Cartilage Products </option>
         <option value=" Beverages"> Beverages</option>
         <option value="Immune Boosters ">Immune Boosters </option>
         <option value="Sexual  products ">Sexual  products </option>
         <option value="Digestive products">Digestive products</option>
         <option value="Personal care Products">Personal care Products</option> 
         <option value="Cardio Vascula Products">Cardio Vascula Products</option>
         <option value="Anti- oxidant">Anti oxidant</option>
         <option value="Health supplements other">Health supplements other</option>
         <option value="OTHER">OTHER</option>
          <?php/*
          $HD=$scon->getShopCategory(); 
    
        if($HD->rowCount()>0){
          $ro=$HD->fetchAll();
          foreach ($ro as $key => $v) {
          echo "<option value='".$v['category']."'>".$v['category']."</option>";
          }
         }
           */?> 
</select>
          <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_info" value="<?php// echo $expiredate;?>"  /><br/>
         <sup id="rv"></sup>
  </td>

  </tr>-->
  <!--<tr>
  <td>
    Vendor:
  </td>
  <td>
    <input type="text" name="vendor" id="vendor" class="prof_info"  value="<?php //echo $vendor;?>" /><br/>
         <sup id="vd"></sup>
  </td>
   <!--<td><label id="mini_label">Choose image:<sup>*</sup></label><br/>

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

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

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

  </td> 

  <td id="reg_form_table_cell">

    
         <input type="text" name="itemcost" id="itemcost" class="prof_info"  value="<?php echo $itemcost=2000;?>" /><br/>
         <sup id="rdn"></sup>
  </td>
  
</tr>
<tr>
 
   <td align="right"> Currency:</td><td><select name="currency" id="currency">
       <!-- <option value="">Select</option>-->
          <option value="TZS">TZS</option>
          <option value="USD">USD</option> 
       </select>
   </td>
 </tr>

  <!--<tr>
 
  <td height="40px"   valign="top" colspan="2">

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

        <sup id="rd"></sup>
    
         <textarea   name="itemdescriptrion" id="itemdescriptrion"  width="95%"  height="60px"><?php //echo $itemdescription;?></textarea><br/>
         
  </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 "Error occurred!";
  }
  }
  else{
    echo "Something want wrong!";
  }
  ?>
<script>

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

    reader.onload = function (e) {
        // get loaded data and render thumbnail.
        document.getElementById("itemimage").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 vendor =document.getElementById('vendor').value;
//$.trim(vendor);  
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 floc= document.getElementById('file').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="";
    }
if(vendor=="")
{
e.preventDefault();

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

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

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

       
        document.getElementById('vd').innerHTML="You typed item vendor with error!.."; 


              }
         else{

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

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

                                                         //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>





