<?php
class viewgambar{
    var $id;
    
    function listgambar($produk){
        $gambar = mysql_query("SELECT * FROM gambar WHERE id_produk = $produk ORDER BY id_gambar DESC");

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

    function addgambar($produk,$nama){
        $tgl = date("d-m-Y");
        
        mysql_query("INSERT INTO gambar(    id_produk,
                                            nama,
                                            dateadd,
                                            dateedit) 
                                            VALUES(
                                            '$produk',
                                            '$nama',
                                            STR_TO_DATE('$tgl','%d-%m-%Y'),
                                            STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }

    function deletegambar(){
        mysql_query("DELETE FROM gambar where id_gambar = $this->id");
    }

    function deletegambarproduk($id){
        mysql_query("DELETE FROM gambar where id_produk = $id");
    }

    function listgambartemp($user){
        $gambar = mysql_query("SELECT * FROM temp_gambar WHERE id_user = $user ORDER BY id_tempgambar DESC");

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

    function addgambartemp($user,$nama){
        $tgl = date("d-m-Y");
        
        mysql_query("INSERT INTO temp_gambar(   id_user,
                                                nama,
                                                dateadd,
                                                dateedit) 
                                                VALUES(
                                                '$produk',
                                                '$nama',
                                                STR_TO_DATE('$tgl','%d-%m-%Y'),
                                                STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }

    function deletegambartemp(){
        mysql_query("DELETE FROM temp_gambar where id_tempgambar = $this->id");
    }

}

class viewgambarpost{
    var $id;

    function listgambar($produk){
        $gambar = mysql_query("SELECT * FROM gambar WHERE id_produk = $produk ORDER BY id_gambar DESC");

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

