<?php
class viewmenuweb{
    var $i= 0;
    
    function listmenu(){
        $menu = mysql_query("SELECT * FROM menuweb ORDER BY menu_order"); 
        
        while ($m = mysql_fetch_array($menu)){
            $data[$i] = array(
                        'id' => $m[id_menuweb],
                        'id_page' => $m[id_page],
                        'id_katpost' => $m[id_katpost],
                        'id_katgaleri' => $m[id_katgaleri],
                        'id_katlist' => $m[id_katlist],
                        'module' => $m[module],
                        'nama' => $m[nama],
                        'tag' => $m[tag],
                        'menu_order' => $m[menu_order]
                     );
            
            $i++;
        }
        
        return $data;
    }

    function listsubmenu(){
        $menu = mysql_query("SELECT * FROM submenuweb WHERE id_menu = $this->id ORDER BY submenu_order"); 
        
        while ($m = mysql_fetch_array($menu)){
            $data[$i] = array(
                        'id' => $m[id_submenuweb],
                        'id_menuweb' => $m[id_menuweb],
                        'id_page' => $m[id_page],
                        'id_katpost' => $m[id_katpost],
                        'id_katgaleri' => $m[id_katgaleri],
                        'id_katlist' => $m[id_katlist],
                        'module' => $m[module],
                        'nama' => $m[nama],
                        'tag' => $m[tag],
                        'submenu_order' => $m[submenu_order]
                     );
            
            $i++;
        }
        
        return $data;
    }

    function listtempsubmenu($user){
        $menu = mysql_query("SELECT * FROM temp_submenuweb WHERE id_user = $user ORDER BY submenu_order"); 
        
        while ($m = mysql_fetch_array($menu)){
            $data[$i] = array(
                        'id' => $m[id_tempsubmenu],
                        'id_page' => $m[id_page],
                        'id_katpost' => $m[id_katpost],
                        'id_katgaleri' => $m[id_katgaleri],
                        'id_katlist' => $m[id_katlist],
                        'module' => $m[module],
                        'nama' => $m[nama],
                        'submenu_order' => $m[submenu_order]
                     );
            
            $i++;
        }
        
        return $data;
    }

    function menu(){
        $menu = mysql_query("SELECT * FROM menuweb WHERE id_menuweb = $this->id");
        $m = mysql_fetch_array($menu);
        
        $data = array(
                        'id' => $m[id_menuweb],
                        'id_page' => $m[id_page],
                        'id_katpost' => $m[id_katpost],
                        'id_katgaleri' => $m[id_katgaleri],
                        'id_katlist' => $m[id_katlist],
                        'module' => $m[module],
                        'nama' => $m[nama],
                        'tag' => $m[tag],
                        'menu_order' => $m[menu_order]
                     );
        
        return($data);
    }

    function menutag($tag){
        $menu = mysql_query("SELECT * FROM menuweb WHERE tag = '$tag'");
        $m = mysql_fetch_array($menu);
        
        $data = array(
                        'id' => $m[id_menuweb],
                        'id_page' => $m[id_page],
                        'id_katpost' => $m[id_katpost],
                        'id_katgaleri' => $m[id_katgaleri],
                        'id_katlist' => $m[id_katlist],
                        'module' => $m[module],
                        'nama' => $m[nama],
                        'tag' => $m[tag],
                        'menu_order' => $m[menu_order]
                     );
        
        return($data);
    }

    function submenu($id){
        $menu = mysql_query("SELECT * FROM submenuweb WHERE id_submenuweb = $id");
        $m = mysql_fetch_array($menu);
        
        $data = array(
                        'id' => $m[id_submenuweb],
                        'id_menuweb' => $m[id_menuweb],
                        'id_page' => $m[id_page],
                        'id_katpost' => $m[id_katpost],
                        'id_katgaleri' => $m[id_katgaleri],
                        'id_katlist' => $m[id_katlist],
                        'module' => $m[module],
                        'nama' => $m[nama],
                        'tag' => $m[tag],
                        'submenu_order' => $m[submenu_order]
                     );
        
        return($data);
    }

    function lastmenu(){
        $menu = mysql_query("SELECT id_menuweb FROM menuweb WHERE id_menuweb IN ( SELECT MAX(id_menuweb) FROM menuweb )");
        $m = mysql_fetch_array($menu);

        $data = $p[id_menuweb];

        return($data);
    }

    function addmenu($id_page,$id_katpost,$id_katgaleri,$id_katlist,$module,$nama,$menu_order){

        $tgl = date("d-m-Y");
        $tag = str_replace(" ", "-", $nama);
        
        mysql_query("INSERT INTO menuweb(   id_page,
                                            id_katpost,
                                            id_katgaleri,
                                            id_katlist,
                                            module,
                                            nama,
                                            tag,
                                            menu_order,
                                            dateadd,
                                            dateedit) 
                                            VALUES(
                                            '$id_page',
                                            '$id_katpost',
                                            '$id_katgaleri',
                                            '$id_katlist',
                                            '$module',
                                            '$nama',
                                            '$tag',
                                            '$menu_order',
                                            STR_TO_DATE('$tgl','%d-%m-%Y'),
                                            STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }

    function addsubmenu($id_menuweb,$id_page,$id_katgaleri,$id_katlist,$id_katpost,$module,$nama,$order){

        $tgl = date("d-m-Y");
        $tag = str_replace(" ", "-", $nama);
        
        mysql_query("INSERT INTO submenuweb(    id_menu,
                                                id_page,
                                                id_katpost,
                                                id_katgaleri,
                                                id_katlist,
                                                module,
                                                nama,
                                                tag,
                                                submenu_order,
                                                dateadd,
                                                dateedit) 
                                                VALUES(
                                                '$id_menuweb',
                                                '$id_page',
                                                '$id_katpost',
                                                '$id_katgaleri',
                                                '$id_katlist',
                                                '$module',
                                                '$nama',
                                                '$tag',
                                                '$order',
                                                STR_TO_DATE('$tgl','%d-%m-%Y'),
                                                STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }

    function addtempsubmenu($user,$id_page,$id_katpost,$id_katgaleri,$id_katlist,$module,$nama,$order){

        $tgl = date("d-m-Y");
        
        mysql_query("INSERT INTO temp_submenuweb(   id_user,
                                                    id_page,
                                                    id_katpost,
                                                    id_katgaleri,
                                                    id_katlist,
                                                    module,
                                                    nama,
                                                    submenu_order,
                                                    dateadd,
                                                    dateedit) 
                                                    VALUES(
                                                    '$id_menuweb',
                                                    '$id_page',
                                                    '$id_katpost',
                                                    '$id_katgaleri',
                                                    '$id_katlist',
                                                    '$module',
                                                    '$nama',
                                                    '$order',
                                                    STR_TO_DATE('$tgl','%d-%m-%Y'),
                                                    STR_TO_DATE('$tgl','%d-%m-%Y'))");
    }
    
    function editmenu($id_page,$id_katpost,$id_katgaleri,$id_katlist,$module,$nama,$menu_order){

        $tgl = date("d-m-Y");
        $tag = str_replace(" ", "-", $nama);
        
        mysql_query("UPDATE menuweb SET id_page     = '$id_page',
                                        id_katpost  = '$id_katpost',
                                        id_katgaleri= '$id_katgaleri',
                                        id_katlist  = '$id_katlist',
                                        module      = '$module',
                                        nama        = '$nama',
                                        tag         = '$tag',
                                        menu_order  = '$menu_order',
                                        dateedit    =  STR_TO_DATE('$tgl','%d-%m-%Y')
                                        WHERE
                                        id_menuweb    = $this->id");
    }

    function deletemenu(){
        mysql_query("DELETE FROM menuweb where id_menuweb = $this->id");
    }

    function deletetempsubmenu($id){
        mysql_query("DELETE FROM temp_submenuweb where id_tempsubmenu = $id");
    }

    function deletealltempsubmenu($id){
        mysql_query("DELETE FROM temp_submenuweb where id_user = $id");
    }

    function deletesubmenu($id){
        mysql_query("DELETE FROM submenuweb where id_submenuweb = $id");
    }

    function deleteallsubmenu(){
        mysql_query("DELETE FROM submenuweb where id_menuweb = $this->id");
    }
    
}

