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

// Logical section of page
$languageObj =  new  language();

$adminlogObj = new admin_log();
$modulepagesObj = new module_pages();

$filename=basename($_SERVER['SCRIPT_FILENAME']);
if($filename == 'languageadd.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['language_id'])){
    $languageDetail = $languageObj->fromId($_REQUEST['language_id']);
}

if(isset($_POST['submit'])){
    	$data=array(
	  'language_name'=>trim($_POST['language_name'])
	);
        /*if(isset($_POST['language_status'])){
            $data['language_status'] 			= '1';
        }else{
            $data['language_status'] 			= '0';
        }*/

        $languageDetail = $languageObj->fromId($_REQUEST['language_id']);
        if(!empty($languageDetail))
        {
            $languagedata = "<b>Edit Record</b> ";
            if($languageDetail->language_name != trim($_POST['language_name']))
            {   

                $languagedata .= " <b>Name</b>: "." ".$languageDetail->language_name." <b>To</b> ".$_POST['language_name']." and ";
            
                $chages_data = true;
            }

            
        }

	if (isset($_POST['language_id'])){
            $id=$_POST['language_id'];
            $rs=$languageObj->updateRecords($data,$id);
            if ($rs){

                if($chages_data == true)
                { 
                    $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,rtrim($languagedata," and"));
                }

                $successMsg = base64_encode(RECORD_UPDATE);			
                header('Location:languagelist.php?successMsg='.$successMsg);
                exit;
            }
        }else{

            $languagedata = "<b>Add Record</b> ";
            $languagedata.= " <b>Language Data</b>: ".json_encode($data);

            $rs = $languageObj->addRecords($data);
            if($rs){

            $admin_log = $adminlogObj->addAdminLog($_SESSION['admin_id'],$module_id,$page_id,$pagename,$languagedata);
    		$successMsg = base64_encode(RECORD_ADD);			
            //?successMsg='.$successMsg
    		header('Location:languagelist.php');
    		exit;
            }
	}
}
// Include Template 
include_once('../libs/routs.php')

?>