<?php
class viewkatgaleri{
	var $id;

	function listkategori(){
        $galeri = mysql_query("SELECT * FROM kategori_galeri ORDER BY id_katgaleri");

        while ($p = mysql_fetch_array($galeri)){
            $data[$i] = array(
                        'id' => $p[id_katgaleri],
                        'nama' => $p[nama],
                        'tag' => $p[tag]
                     );
            
            $i++;
        }
        
        return($data);
        
    }

    function katgaleri(){
        $galeri = mysql_query("SELECT * FROM kategori_galeri WHERE id_katgaleri = $this->id");
        $p = mysql_fetch_array($galeri);
        
        $data = array(
                        'id' => $p[id_katgaleri],
                        'nama' => $p[nama],
                        'keterangan' => $p[keterangan],
                        'tag' => $p[tag]
                     );
        
        return($data);
        
    }

    function katgaleritag($tag){
        $galeri = mysql_query("SELECT * FROM kategori_galeri WHERE tag = '$tag'");
        $p = mysql_fetch_array($galeri);
        
        $data = array(
                        'id' => $p[id_katgaleri],
                        'nama' => $p[nama],
                        'keterangan' => $p[keterangan],
                        'tag' => $p[tag]
                     );
        
        return($data);
        
    }

    function addkatgaleri($nama,$keterangan,$tag){
        $tgl = date("d-m-Y");
        
        mysql_query("INSERT INTO kategori_galeri(   nama,
                                                    tag,
                                                    keterangan,
                                                    dateadd,
                                                    dateedit) 
                                                    VALUES(
                                                    '$nama',
                                                    '$tag',
                                                    '$keterangan',
                                                    STR_TO_DATE('$tgl','%d-%m-%Y'),
                                                    STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }

    function editkatgaleri($nama,$keterangan){
        $tgl = date("d-m-Y");
        $tag = str_replace(" ", "-", $nama);
        
        mysql_query("UPDATE kategori_galeri    SET nama            = '$nama',
                                                    tag             = '$tag',
                                                    keterangan      = '$keterangan',
                                                    dateedit        =  STR_TO_DATE('$tgl','%d-%m-%Y')
                                                    WHERE 
                                                    id_katgaleri    = $this->id");
    }

    function deletekatgaleri(){
        mysql_query("DELETE FROM kategori_galeri where id_katgaleri = $this->id");
    }
}