<?php 
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');
// Logical section of page
$agencyObj   = new agency();
$adminlogObj = new admin_log();
$modulepagesObj = new module_pages();
$filename=basename($_SERVER['SCRIPT_FILENAME']);
if($filename == 'agencyadd.php')
{
    $module_id = $adminlogObj->getModuleId($filename);
    $page_id = $adminlogObj->getPageId($filename);
    $allpages = $modulepagesObj->fromId($page_id);
    $pagename = $allpages->page;
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='edit' && isset($_REQUEST['agency_id'])){
	$agencyDetail = $agencyObj->fromId($_REQUEST['agency_id']);
}
if(isset($_POST['submit'])){
	   
    $data=array(
      'agency_name'=>trim($_POST['agency_name']),
      'agency_created_by'=>$_SESSION['admin_id']
    );

    if(isset($_POST['agency_status'])){
        $data['agency_status']           = '1';
    }else{
        $data['agency_status']           = '0';
    }  
    if (isset($_POST['agency_id'])){
        
        $id=$_POST['agency_id'];
        $rs=$agencyObj->updateRecords($data,$id);
        if ($rs){
            $successMsg = base64_encode("Agency Update successfully.");			
            header('Location:agencylist.php');
            exit;
        }

    }else{
        $data['agency_unique_id'] = $agencyObj->getNextUniqueId('agency_unique_id');
        $data['agency_created_at']=date('Y-m-d H:i:s');
        $rs = $agencyObj->addRecords($data);
        if($rs){
            $successMsg = base64_encode("Agency added successfully.");			
            header('Location:agencylist.php');
            exit;
        }
    }
}

// Include Template 
include_once('../libs/routs.php')

?>