<?php
  include_once 'opendb.php';
   $mret="Error";
     
    if (isset($_POST["AppID"]) &&  isset($_POST["CompCode"]))
    {
	
        $AppID=$_POST["AppID"] ;
        $coCode=$_POST["CompCode"] ;
        $sql = "SELECT * FROM company WHERE app_id like '".$AppID."' and comp_code like '".$coCode."'";
        $sresult = $conn->query($sql);
        if ($sresult->num_rows == 0 )
        { 
            $conn->query("update company set app_id='".$AppID."' where comp_code like '".$coCode."' and (app_id='' or app_id IS NULL)");
            $sresult = $conn->query($sql);            
        }
        if ($sresult->num_rows > 0 )
        { 
               if($srow = $sresult->fetch_assoc())
                 {
                   
                    if($srow['expiry_date']!=''){
                        $expiry_date = date('Y-m-d', strtotime($srow['expiry_date']));
                        $today=date("Y-m-d");
                        if($expiry_date < $today){
                            $mret= 'company status expired '; 
                             $conn->close();
                             die( $mret);
                        }

                   }
                    if ($srow["inactive"]!=0)
                    {
                       $mret="company status Inactive";                       
                    }                    
                    else {                       
                        $mret = $srow["comp_id"];
                    }                          
                }
        }
        else {
                 $mret = "PC/Co Not registered..!  : ".$AppID . " comp id :" .$coCode;
        }
        
  
    }
    else
    {
        $mret = "No Data for app id/company code";
    }
    
    $conn->close();
    echo $mret;
    ?>

