<?php
class viewpage{
    var $id;
    
    function listpage(){
        $page = mysql_query("SELECT * FROM page ORDER BY id_page");

        while ($p = mysql_fetch_array($page)){
            $data[$i] = array(
                        'id' => $p[id_page],
                        'judul' => $p[judul],
                        'tag' => $p[tag],
                        'isi' => $p[isi],
                        'keterangan' => $p[keterangan],
                        'publish' => $p[publish]
                     );
            
            $i++;
        }
        
        return($data);
        
    }

    function listpageaktif(){
        $page = mysql_query("SELECT * FROM page WHERE publish = 'Y' ORDER BY id_page");

        while ($p = mysql_fetch_array($page)){
            $data[$i] = array(
                        'id' => $p[id_page],
                        'judul' => $p[judul],
                        'tag' => $p[tag],
                        'isi' => $p[isi],
                        'keterangan' => $p[keterangan],
                        'publish' => $p[publish]
                     );
            
            $i++;
        }
        
        return($data);
        
    }
    
    function page(){
        $page = mysql_query("SELECT * FROM page WHERE id_page = $this->id");
        $p = mysql_fetch_array($page);
        
        $data = array(
                        'id' => $p[id_page],
                        'judul' => $p[judul],
                        'tag' => $p[tag],
                        'gambar' => $p[gambar],
                        'isi' => $p[isi],
                        'keterangan' => $p[keterangan],
                        'publish' => $p[publish]
                     );
        
        return($data);
        
    }

    function pagetag($tag){
        $page = mysql_query("SELECT * FROM page WHERE tag = '$tag'");
        $p = mysql_fetch_array($page);
        
        $data = array(
                        'id' => $p[id_page],
                        'judul' => $p[judul],
                        'tag' => $p[tag],
                        'gambar' => $p[gambar],
                        'isi' => $p[isi],
                        'keterangan' => $p[keterangan],
                        'publish' => $p[publish]
                     );
        
        return($data);
        
    }
    
    function addpage($judul,$isi,$keterangan,$gambar,$publish){

        $tgl = date("d-m-Y");
        $tag = str_replace(" ", "-", $judul);
        
        mysql_query("INSERT INTO page(  judul,
                                        tag,
                                        isi,
                                        keterangan,
                                        gambar,
                                        publish,
                                        dateadd,
                                        dateedit) 
                                        VALUES(
                                        '$judul',
                                        '$tag',
                                        '$isi',
                                        '$keterangan',
                                        '$gambar',
                                        '$publish',
                                        STR_TO_DATE('$tgl','%d-%m-%Y'),
                                        STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }
    
    function editpage($judul,$isi,$keterangan,$gambar,$publish){

        $tgl = date("d-m-Y");
        $tag = str_replace(" ", "-", $judul);
        
        mysql_query("UPDATE page SET    judul       = '$judul',
                                        tag         = '$tag',
                                        isi         = '$isi',
                                        keterangan  = '$keterangan',
                                        gambar      = '$gambar',
                                        publish     = '$publish',
                                        dateedit    = STR_TO_DATE('$tgl','%d-%m-%Y')
                                        WHERE
                                        id_page     = $this->id");
    }
    
    function deletepage(){
        mysql_query("DELETE FROM page where id_page = $this->id");
    }
}