<?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 ".PAGE_TABLE." order by pageid DESC";
        $data = $alltable->getInfo('', $sql);
        $count = count($data);
        
        $record = '';
        
        if($count > 0){
            for($i=0;$i<$count;$i++){
                
                $pageid = $data[$i]['pageid'];
                $pagetitle = $data[$i]['pagetitle'];
                $status = $data[$i]['status'];
                $parentpageid = $data[$i]['parentpageid'];
                $isparentpage = $data[$i]['isparentpage'];
                $pageurl = $data[$i]['pageurl'];
                
                if($status == 1){
                    $displaystatus = "<span class='text text-success'>Active</span>";
                }else{
                    $displaystatus = "<span class='text text-danger'>Inactive</span>";
                }
                
                if($isparentpage == 1 && $parentpageid == 0){
                    $displaypagestatus = "<span class='text text-success'>Yes</span>";
                }else{
                    $displaypagestatus = "<span class='text text-danger'>No</span>";
                }
                
                $record .= "<tr>";
                    $record .= "<td>".($i+1)."</td>";
                    $record .= "<td>".$pagetitle."</td>";   
                    $record .= "<td>".$pageurl."</td>";
                    $record .= "<td>".$displaypagestatus."</td>";
                    $record .= "<td>".$displaystatus."</td>";
                    $record .= "<td><a href='add-page.php?pageid=".$pageid."'><i class='fa fa-pencil'></i> Edit </a></td>";
                    $record .= "<td><a href='".DOC_ROOT.$pageurl.".html' 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-page.html";    
    }else{
        $redirect = ADMIN_DIR."auth/login.php";
        header("location:".$redirect);
        exit();
    }   
?>