<?php 
include_once('database_connection.php');
if(isset($_POST['submit']))
{
   // print_r($_POST);
        //$_SESSION['userid']=
        $COAID=$_POST['dealer'];
        $userid=1;//$_SESSION['userid'];
        $visitdate=$_POST['visitdate'];
        $newappoint=$_POST['appointarrange'];
        $appointdate=$_POST['appointdate'];
        $additional_info=$_POST['additional_info'];
        $ContactPerson=$_POST['ContactPerson'];
       // $ContactType=$_POST['ContactType'];
        $contactTypeId=$_POST['contactTypeId'];
        $TypeContactId=$_POST['TypeContactId'];
        $customerCategoryId=$_POST['customerCategoryId'];
        $discuss=$_POST['discuss'];
        $feedback=$_POST['feedback'];
        $notes=$_POST['notes'];
        $managernotes=$_POST['managernotes'];  
       $id=1;
       $sql="select max(id) as id from VisitMaster";
                $result=odbc_exec($connection,$sql);
               // print_r($result);
                while($row=odbc_fetch_array($result))
                {
                $id=$row['id'];
                $id=$id+1;
               // echo "id=".$id;
                 }
      // code for image 

      //end code for image              
     $sql="insert into VisitMaster (id,COAID,salesrepid,visitdate,appointdate,newappoint,additional_info,contact_person,contactTypeId,TypeContactId,customerCategoryId,discuss,feedback,notes,managernotes) values('$id','$COAID','$userid','$visitdate','$appointdate','$newappoint','$additional_info','$ContactPerson','$contactTypeId','$TypeContactId','$customerCategoryId','$discuss','$feedback','$notes','$managernotes')";
    odbc_exec($connection,$sql);
    echo "<script>alert('Visit Saved Sucessfully');window.location='visit.php?sidebarid=21#supplier</script>";
}
if(isset($_POST['update']))
{
   // print_r($_POST);
        //$_SESSION['userid']=
        $id=$_POST['visitid'];
        $COAID=$_POST['dealer'];
        $userid=1;//$_SESSION['userid'];
        $visitdate=$_POST['visitdate'];
        $newappoint=$_POST['appointarrange'];
        $appointdate=$_POST['appointdate'];
        $additional_info=$_POST['additional_info'];
        $ContactPerson=$_POST['ContactPerson'];
       // $ContactType=$_POST['ContactType'];
        $contactTypeId=$_POST['contactTypeId'];
        $TypeContactId=$_POST['TypeContactId'];
        $customerCategoryId=$_POST['customerCategoryId'];
        $discuss=$_POST['discuss'];
        $feedback=$_POST['feedback'];
        $notes=$_POST['notes'];
        $managernotes=$_POST['managernotes'];  
echo      $sql="update VisitMaster set COAID='$COAID',salesrepid='$userid',visitdate='$visitdate',appointdate='$appointdate',newappoint='$newappoint',additional_info='$additional_info',contact_person='$ContactPerson',contactTypeId='$contactTypeId',TypeContactId='$TypeContactId',customerCategoryId='$customerCategoryId',discuss='$discuss',feedback='$feedback',notes='$notes',managernotes='$managernotes' where id=$id";
    odbc_exec($connection,$sql);
    echo "<script>alert('Visit Saved Sucessfully');window.location='visit.php?sidebarid=21#supplier</script>";
}

?>
