<?php
    require_once "../include/config.php";
    require_once GLOBAL_INCLUDE_PATH."include/startup.php";
    $alltable = new AllTables();
    
    if(!adminchecklogin('', '', '', $G_userid)){
        $redirect = ADMIN_DIR."auth/login.php";
        header("location:".$redirect);
        exit();
    }

    if($G_userid > 0 && $G_userid != null && $G_userid != ''){
        $sql = "select * from ".NEWS_TABLE." order by newsid DESC";
        $data = $alltable->getInfo('', $sql);
        $count = count($data);
        
        $record = '';
        
        if($count > 0){
            for($i=0;$i<$count;$i++){
                
                $newsid = $data[$i]['newsid'];
                $newstitle = $data[$i]['newstitle'];
                $status = $data[$i]['status'];
                
                $newsurl = $data[$i]['newsurl'];
                
                if($status == 1){
                    $displaystatus = "<span class='text text-success'>Active</span>";
                }else{
                    $displaystatus = "<span class='text text-danger'>Inactive</span>";
                }
                
                //$pageurl    =   cleanURL($blogtitle);
                $record .= "<tr>";
                    $record .= "<td>".($i+1)."</td>";
                    $record .= "<td>".$newstitle."</td>";   
                    $record .= "<td>".$displaystatus."</td>";
                    $record .= "<td><a href='add-news.php?newsid=".$newsid."'><i class='fa fa-pencil'></i> Edit </a></td>";
                    //$record .= "<td><a href='".DOC_ROOT."blog/".$blogurl.".html' target='_blank'> <i class='fa fa-eye'></i> View </a></td>";
                   // $record .= "<td><a href='".DOC_ROOT."".$newsurl.".htm' target='_blank'> <i class='fa fa-eye'></i> View </a></td>";
                $record .= "</tr>";
            }    
        }else{
            $record .= "<tr>";
                $record .= "<td colspan='4'>No Record Found..!</td>";
            $record .= "</tr>";
        }
        require_once "view-news1.html";    
    }else{
        $redirect = ADMIN_DIR."auth/login.php";
        header("location:".$redirect);
        exit();
    }   
?>