<?php
    
    session_start();
    if (!isset($_SESSION['username'])) {
        header("Location: login.php");
        exit();
    }
    
    require_once('include/config.php');
    require_once('include/startup.php');                           
    $alltables = new AllTables();
    
    
    $sql= "SELECT * FROM mst_company WHERE id = $G_companyid";
	$data = $alltables -> getInfo('',$sql);
	
	    $company_name               = $data[0]['cmp_name'];
        $company_type               = $data[0]['cmp_type'];
        $hall_no                    = $data[0]['hall_no'];
        $stall_no                   = $data[0]['stall_no'];
        
        $company_email              = $data[0]['cmp_email'];
        $phone_no                   = $data[0]['phone'];
        $whatsapp_no                = $data[0]['whatsapp'];
        $website                    = $data[0]['cmp_website'];
        
        $gst_no                     = $data[0]['cmp_gst'];
        $pan_no                     = $data[0]['cmp_pan'];
        $tan_no                     = $data[0]['cmp_tan'];
        $cin_no                     = $data[0]['cmp_cin'];
	
	

    if ($_POST['btn-edit']) 
    {
      
            $edit_company_name               = $_POST['txt_cmpname'];
            $edit_company_type               = $_POST['txt_cmptype'];
            $edit_hall_no                    = $_POST['txt_hallno'];
            $edit_stall_no                   = $_POST['txt_stallno'];
            
            $edit_company_email              = $_POST['txt_cmpemail'];
            $edit_phone_no                   = $_POST['txt_phone'];
            $edit_whatsapp_no                = $_POST['txt_whatsapp'];
            $edit_website                    = $_POST['txt_website'];
            
            $edit_gst_no                     = $_POST['txt_cmpgst'];
            $edit_pan_no                     = $_POST['txt_cmppan'];
            $edit_tan_no                     = $_POST['txt_cmptan'];
            $edit_cin_no                     = $_POST['txt_cmpcin'];
            
        
        
            $array['cmp_name']          = $edit_company_name;     
            $array['cmp_type']          = $edit_company_type;
            $array['hall_no']           = $edit_hall_no;
            $array['stall_no']          = $edit_stall_no;
            
            $array['cmp_email']         = $edit_company_email;
            $array['phone']             = $edit_phone_no;            
            $array['whatsapp']          = $edit_whatsapp_no;
            $array['cmp_website']       = $edit_website;
            
            $array['cmp_gst']           = $edit_gst_no;
            $array['cmp_pan']           = $edit_pan_no;
            $array['cmp_tan']           = $edit_tan_no;
            $array['cmp_cin']           = $edit_cin_no;
                                
            $wherecondition = "id = $G_companyid";
            $result = $alltables -> EditInfo($array,$wherecondition,'mst_company');   
            // $result = $alltables -> EditInfo($array,$wherecondition,'mst_company',1);    // To print query
            if($result){
                echo '<script>alert("Form edited successfully!");window.location.href = "company-details.php";</script>';
                exit();
            }
            else{
                echo '<script>alert("Form not edited, please try again. ");window.location.href = "company-details.php";</script>';
                exit();
            }
    }  
    else{
                                
    }
       
    include('include/header.php');   
    include_once('company-details1.html');   
    include('include/footer.php');         
?>    