<?php
    session_start();
    if (!isset($_SESSION['username'])) {
        $_SESSION['login_msg'] = "Please login first to continue.";
        header("Location: login.php");
        exit();
    }
    
    require_once('include/config.php');
    require_once('include/startup.php');                           
    $alltables = new AllTables();
    
    include('include/header.php');  
    
    // Add Correspondence Address
    if ($_POST['btn-submit']) 
    {
        $add_name                   = $_POST['txt_name'];
        $add_cmp_name               = $_POST['txt_cmpname'];
        $add_designation            = $_POST['txt_designation'];
        $add_mobileno               = $_POST['txt_mobile'];
        $add_email                  = $_POST['txt_email'];
        
        
        $array['cmp_id']            = $G_companyid;     
        $array['name']              = $add_name;
        $array['cmp_name']          = $add_cmp_name;
        $array['designation']       = $add_designation;
        $array['mobile_no']         = $add_mobileno;
        $array['email']             = $add_email;
                                
            
        $address = $alltables -> AddInfo($array,'exhibitors_badges'); 
        // echo "Last insetr id:".$address;
        // exit();   
        
        if($address){
            echo '<script>alert("Exhibitor Badge added successfully!");window.location.href = "exhibitors-badges.php";</script>';
            exit();
        }
        else{
            echo '<script>alert("Exhibitor Badge not added, please try again. ");window.location.href = "exhibitors-badges.php";</script>';
            exit();
        }
    }  
    else{
                                
    }
    
    // Add Correspondence Address
    if ($_POST['btn-edit']) 
    {
      
        $edit_id                     = $_POST['txt_id'];
        $edit_name                   = $_POST['txt_name'];
        $edit_cmp_name               = $_POST['txt_cmpname'];
        $edit_designation            = $_POST['txt_designation'];
        $edit_mobileno               = $_POST['txt_mobile'];
        $edit_email                  = $_POST['txt_email'];
        
        
        $array['cmp_id']            = $G_companyid;     
        $array['name']              = $edit_name;
        $array['cmp_name']          = $edit_cmp_name;
        $array['designation']       = $edit_designation;
        $array['mobile_no']         = $edit_mobileno;
        $array['email']             = $edit_email;

        $wherecondition = "id = $edit_id";
        $result = $alltables -> EditInfo($array,$wherecondition,'exhibitors_badges');   
        // $result = $alltables -> EditInfo($array,$wherecondition,'mst_company',1);    // To print query
        if($result){
            echo '<script>alert("Exhibitor Badge Edited successfully!");window.location.href = "exhibitors-badges.php";</script>';
            exit();
        }
        else{
            echo '<script>alert("Exhibitor Badge not Edited, please try again. ");window.location.href = "exhibitors-badges.php";</script>';
            exit();
        }
    }  
    else{
                                
    }
    
    include('include/footer.php');         
?>    