 <?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 = "";
   $region ="";
   $district="";
   $post=$_POST['post'];

   if($post=="Submit"){

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

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


   $region=$_POST['region'];
   $district=$_POST['district'];
   $itemname=$_POST['itemname'];
   $cperson=$_POST['cperson'];
   $itemcategory =$_POST['itemcategory'];
   $cphone =$_POST['cphone']; 
   $itemdescription =$_POST['itemdescription'];
   $locationdescription =$_POST['locationdescription'];
   
 

   if($xcon->vDistrict($district) && $xcon->vRegion($region) && $xcon->vitemname($itemname) && $xcon->vitemcategory($itemcategory) && $xcon->vcphone($cphone) && $xcon->vcperson($cperson) && $xcon->vitemdescription($itemdescription) && $xcon->vlocationdescription($locationdescription))
      {
        ?>
         <center>
         <div>
        
        <?php 
        $needid=date("Ymdhis");
        $r= $xcon->addNeedPost($needid,$ownID,$itemname,$cperson,$cphone,$region,$district,$locationdescription,$itemcategory,$itemdescription);
         if($r->rowCount()>0)
         {
            
           $itemname="";
           $cperson= "";
           $itemcategory ="";
           $cphone = "";   
           $itemdescription = "";
           $locationdescription = "";
            
           $region ="";
           $district="";
           $locationdescription ="";
           echo "Submission successfully!..";
            
         }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->eRegion($region)."<p/>";
              echo  $xcon->eDistrict($district)."<p/>";

              echo  $xcon->eitemcategory($itemcategory)."<p/>";
              echo  $xcon->eitemdescription($itemdescription)."<p/>";
              echo  $xcon->elocationdescription($locationdescription)."<p/>"; 
              echo  $xcon->ecperson($cperson)."<p/>";
              echo  $xcon->ecphone($cphone)."<p/>";
    
             ?>
       </sup>
       </div>
       </center> 

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

      }
 

}
 
 

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

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


<center>
<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="dealPostForm.php" method="post">

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

                 </form>
         </li>
        
        </ul>
      </center>

<fieldset id="new_item_reg_form">
<label id="reg_form_tile_label">Post a deal here.. </label></p/>
<i>Please fill the form below to post your deal-</i>
<form name="new_user_registration" id="new_user_registration" action="needPostForm.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;?>">

 

        
    <tr>
  
   


  <td id="reg_form_table_cell">
    <br/>
     <label id="mini_label">Need title:<sup>*</sup></label><br>
         <input type="text" name="itemname" id="itemname" class="prof_info" value="<?php echo $itemname;?>"  /><br/>
         <sup id="si"></sup>
         
  </td>
    <td id="reg_form_table_cell">
     <label id="mini_label"><b>Your current location:-</b><br/> region:<sup>*</sup></label><br>
         <input type="text" name="region" id="region" class="prof_info" value="<?php echo $region;?>"  /><br/>
         <sup id="rr"></sup>
         
  </td>
   

</tr>
  
<tr>
    

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

     <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>
  <td id="reg_form_table_cell">
     <label id="mini_label">District:<sup>*</sup></label><br>
         <input type="text" name="district" id="district" class="prof_info" value="<?php echo $district;?>"  /><br/>
         <sup id="dd"></sup>
         
  </td>
</tr>
<tr>
 
   
  <td id="reg_form_table_cell">

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

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

   

    <td id="reg_form_table_cell">

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

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


   </tr>

 
<tr>
 
    

  <td id="reg_form_table_cell" colspan="2" >
       <label id="mini_label">Street address description:</label><br>
          <sup id="ld"></sup>
          <input class="prof_info" name="locationdescription" id="locationdescription"  width="95%"  height="60px" value="<?php echo $locationdescription;?>">
              
          
  </td>

  </tr>
  <tr>
 
    

  <td id="reg_form_table_cell" colspan="2">

        <label id="mini_label">Describe your need specification:<sup>*</sup></label><br>
    
         <textarea   name="itemdescription" id="itemdescription"  width="95%"  height="60px">
          <?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 "ERROR OCCURED!";
  }
  }
  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 cphone =document.getElementById('cphone').value;
$.trim(cphone);  

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

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

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

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






///VALIDATION
if(region=="")
{
e.preventDefault();

document.getElementById('rr').innerHTML="Region required!..";
 } 
 else
 {

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

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

       
        document.getElementById('rr').innerHTML="You typed region with error!.."; 


              }
         else{

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

              }
   }
 
    j=0, i=0;

    ///////
    ///////
 if(district=="")
{
e.preventDefault();

document.getElementById('dd').innerHTML="District required!..";
 } 
 else
 {

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

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

       
        document.getElementById('dd').innerHTML="You typed district with error!.."; 


              }
         else{

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

              }
   }
 
    j=0, i=0;



                                                   //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
 
 
                                                                               // /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');
        ?>




