<?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 == 'languagelist.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']=='change_status' && isset($_REQUEST['language_id'])){
    if(isset($_REQUEST['status'])){
        $languageObj->changeStatus($_REQUEST['language_id']);
        echo RECORD_STATUS;
    }
    return true;
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='delete' && isset($_REQUEST['language_id'])){
    $languageObj->deleteFromId($_REQUEST['language_id']);
    $successMsg = base64_encode(RECORD_DELETE);
}


if (isset($_REQUEST['act']) && $_REQUEST['act']=='load'){
    $records = $_REQUEST['length'];
    $start=0;
    if(isset($_GET['start']) && $_GET['start']!='0'){
        $page = $_GET['start'];
    }
    $start=($page-1)*$limit;
    $limit = array('start'=>$_GET['start'],'record'=>$records);
    $where = " 1=1 ";

    if(isset($_REQUEST['lanuage_name']) && $_REQUEST['lanuage_name'] != '')
    {
        $where .= " AND language_name LIKE '%".$_REQUEST['lanuage_name']."%'";
    }

    if (isset($_REQUEST['search']['value']) && $_REQUEST['search']['value']!=""){
        $where = " language_name LIKE '%".$_REQUEST['search']['value']."%' ";
    }    
    $orderFields = array('','language_name','');
    // Array of order by 
    $orderby=array();
    if (isset($_REQUEST['order']['0']['column']) && $_REQUEST['order']['0']['column']!=""){
        $orderby = array(" ".$orderFields[$_REQUEST['order']['0']['column']]." ".$_REQUEST['order']['0']['dir']);
    }else{
        $orderby = array(" language_id desc ");
    }
    $data    = array('where' => $where,'limit' => $limit,'orderBy' => $orderby);
    $languageDetails = $languageObj->getAllRecords($data);
    $recordsTotal   =   $languageObj->getAllCount($data);

    if ($languageDetails && count($languageDetails)>0){
        foreach ($languageDetails as $key => $language){
            $action = '<a href="languageadd.php?act=edit&language_id='.$language->language_id.'" class="btn btn-success white-btn"><i class="nav-icon i-Pen-2 "></i></a>';
            $response[] = array('<input type="checkbox" name="check[]" id="check[]" value="'.$language->language_id.'" class="check_class" />', 
                    $language->language_name,                    
                    $action
            );
        }
        $result=array('recordsFiltered'=>$recordsTotal,'recordsTotal'=>$recordsTotal,'data'=>$response);
    }else{
        $result=array('recordsFiltered'=>0,'recordsTotal'=>0,'data'=>array());
    }
    echo json_encode($result);
    exit;
}
// Include Template 
include_once('../libs/routs.php');
?>