<?php 
// Include main file
include_once('../libs/main.php');
// Check admin Login
include_once('checkLogin.php');

// Logical section of page
$faqObj = new faq();
// Edit Load
if(isset($_REQUEST['act']) && $_REQUEST['act']=='edit' && isset($_REQUEST['id'])){
     $faqDetail = $faqObj->fromId($_REQUEST['id']);
}

// Add / Update submit
if(isset($_REQUEST['act']) && $_REQUEST['act']=='load' && isset($_REQUEST['question']) && $_REQUEST['question'] != "")
{
    $data=array(
        'question'=>trim($_REQUEST['question']),
        'answer'=>$_REQUEST['answer']
    );
    
    if(isset($_REQUEST['status']) && $_REQUEST['status'] == '1'){
        $data['status'] = 1;
    }else{
        $data['status'] = 0;
    } 

    
    // Update
    if (isset($_REQUEST['id'])){
        $id=$_REQUEST['id'];
        
        $rs=$faqObj->updateRecords($data,$id);
        if ($rs)
        {   	
            header('Location:faqlist.php');
            exit;
        }
    }
    else // Insert
    {
     
        //print_r($data);exit;   
        $rs = $faqObj->addRecords($data);
        if($rs)
        {
            header('Location:faqlist.php');
            exit;
        }
    }
}

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