<?php
class viewlist{
	var $id;

	function listdata(){
        $list = mysql_query("SELECT * FROM list ORDER BY id_list");

        while ($p = mysql_fetch_array($list)){
            $data[$i] = array(
                        'id' => $p[id_list],
                        'nama' => $p[nama],
                        'keterangan' => $p[keterangan],
                        'gambar' => $p[gambar]
                     );
            
            $i++;
        }
        
        return($data);
        
    }

    function listdatakat($id){
        $list = mysql_query("SELECT * FROM list WHERE id_katlist = $id ORDER BY id_list");

        while ($p = mysql_fetch_array($list)){
            $data[$i] = array(
                        'id' => $p[id_list],
                        'nama' => $p[nama],
                        'keterangan' => $p[keterangan],
                        'gambar' => $p[gambar]
                     );
            
            $i++;
        }
        
        return($data);
        
    }

    function listdatatag($tag){
        $list = mysql_query("SELECT list.* FROM list, kategori_list WHERE list.id_katlist = kategori_list.id_katlist AND kategori_list.tag = '$tag' ORDER BY list.id_list");

        while ($p = mysql_fetch_array($list)){
            $data[$i] = array(
                        'id' => $p[id_list],
                        'nama' => $p[nama],
                        'keterangan' => $p[keterangan],
                        'gambar' => $p[gambar]
                     );
            
            $i++;
        }
        
        return($data);
        
    }

    function addlist($id_katlist,$nama,$keterangan,$gambar){
        $tgl = date("d-m-Y");
        
        mysql_query("INSERT INTO list(  id_katlist,
                                        nama,
                                        keterangan,
                                        gambar,
                                        dateadd,
                                        dateedit) 
                                        VALUES(
                                        '$id_katlist',
                                        '$nama',
                                        '$keterangan',
                                        '$gambar',
                                        STR_TO_DATE('$tgl','%d-%m-%Y'),
                                        STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }

    function deletelistkat($id){
        mysql_query("DELETE FROM list where id_katlist = $id");
    }

    function deletelist(){
        mysql_query("DELETE FROM list where id_list = $this->id");
    }
}