<?php

require_once("headUserAcc.php");

if(isset($_POST["submit"]))
{
     $category=$_POST['category'];

     $email=$_POST['email']; 

     $phoneno=$_POST['phoneno']; 

     $pobox=$_POST['pobox'];

     $street=$_POST['street'];

     $ward=$_POST['ward'];

     $district=$_POST['district'];

     $region=$_POST['region'];

     $country=$_POST['country'];

     $popularDistination=$_POST['popularDistination'];

     $hname=$_POST['hname'];
     $ownerid=$ownID=$_POST['owniD']; 
     $admin=$_POST['admin']; 
   
     
   if(!$con->vCategory($category)|| !$con->vPopularDistination($popularDistination) || !$con->vStreet($street) || !$con->vHname($hname) || !$con->vWard($ward) || !$con->vDistrict($district) || !$con->vRegion($region) || !$con->vCountry($country) || !$con->vPhoneno($phoneno) || !$con->vEmail($email))
         
      {
        echo "<center><div><sup>";
      echo $con->eCountry($country)."<p/>";
      echo $con->eRegion($region)."<p/>";
      echo $con->eDistrict($district)."<p/>";
      echo $con->eStreet($street)."<p/>";
      echo $con->ePhoneno($phoneno)."<p/>";
      echo $con->eHname($hname)."<p/>";
      echo $con->eCategory($category)."<p/>";
      echo "</div></center></sup>";
        require("myStockRegForm.php");
      }
   else
      {
	     if(isset($_POST['admin']) && isset($_POST['owniD']))
           {
           $ce= $con->checkIdOfUserIfExist($ownerid); 
            if ($ce->rowCount()>0) {
              $hnm=Date("Ymdhis");
            ////////////
                /////////////////
 //$result=0;
   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');

    
        /////////////////PROFILE IMAGE VALIDATION BEGIN ////////////////

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

                        if($con->vImageType($ext,$allowedtype) && $con->vImageError($error) && $con->vImageSize($size) && $mcon->vImageExist($fn) && $con->vImageSelectF($fn) )
                        {
                         

                                        /////////////////
                           ?>
                           <center>
                           <font color="blue" size="14">
                           <?php
                ///////      ////////////////

                                         print_r($mcon->addShop($hnm,$ownerid,$hname,$category,$phoneno, $email,$pobox,$district,$country, $street ,$ward, $region,$popularDistination,$fn,$tmp_name)); 
                                           ?>
                             </font>
                             </center>
                             
                             <?php  

                              $ownID="";
                              $email=""; 

                              $phoneno=""; 

                              $pobox="";

                              $street="";

                              $ward="";

                              $district="";

                              $region="";

                              $country="";
                              $category="";
                              $popularDistination="";

                                          require("myStockRegForm.php");

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

                                <?php

                                          require("myStockRegForm.php");

                        }


             ////////////PROFILE IMAGE VALIDATION END/////////////
                        /////////////////////
              
            }
            else{
              echo "<center><sup>Invalid user id!..</sup></center>";
               require("myStockRegForm.php");
            }
  
           }
      }

 
     }
else 
     {
      $ownID="";
      $email=""; 

     $phoneno=""; 

     $pobox="";

     $street="";

     $ward="";
     $hname="";
     $district="";

     $region="";

     $country="";
     $category="";
     $popularDistination="";

     $hname="";
      require("agroRegForm.php");
      
	//echo "Error occured when saving data!..";
     }

?>