<?php
include "library.php";

function menu() {
    $menu=mysql_query("SELECT * FROM menu WHERE status = 'web' ORDER BY menu_order");
				  
            while($m=mysql_fetch_array($menu)){
                echo"
                <li><a href='$m[link]'>$m[nama]</a>
                ";
                $submenu=mysql_query("SELECT * FROM sub_menu WHERE id_menu = $m[id_menu] ORDER BY submenu_order");
                $n = mysql_num_rows($submenu);
                
                if($n > 0){
                    echo"
                    <ul role='menu' class='sub-menu'>";
                    while($sm=mysql_fetch_array($submenu)){
                        echo"<li><a href='$sm[link]'>$sm[nama]</a></li>";
                    }
                    echo"
                    </ul>";
                }
                echo"
                </li>";
            }               
}

function kategori() {
    $kategori=mysql_query("SELECT * FROM kategori_produk ORDER BY nama_kategori");
            
            $i=1;
            while($k=mysql_fetch_array($kategori)){
                echo"
                <div class='panel panel-default'>
                ";
                $subkategori=mysql_query("SELECT * FROM subkategori_produk WHERE id_kategori_produk = $k[id_kategori_produk] ORDER BY nama_kategori");
                $n = mysql_num_rows($submenu);
                
                
                if($n > 0){
                    echo"
                    <div class='panel-heading'>
			<h4 class='panel-title'>
			<a data-toggle='collapse' data-parent='#accordian' href='#$i'>
                            <span class='badge pull-right'><i class='fa fa-plus'></i></span>
                            $k[nama_kategori]
			</a>
			</h4>
                    </div>    
                    <div id='$i' class='panel-collapse collapse'>
                        <div class='panel-body'>
                            <ul>";
                            while($sk=mysql_fetch_array($subkategori)){
                                echo"<li><a href='index.php?s=list&id=$k[id_kategori_produk]&ids=$sk[id_subkategori_produk]'>$sk[nama_kategori]</a></li>";
                            }
                            echo"
                            </ul>
                        </div>";
                }else{
                   echo"
                    <div class='panel panel-default'>
                        <div class='panel-heading'>
                            <h4 class='panel-title'><a href='index.php?s=list&id=$k[id_kategori_produk]'>$k[nama_kategori]</a></h4>
			</div>
                    </div>
                   "; 
                }
                echo"
                </div>";
            }               
}

function tags() {
    $tags=mysql_query("SELECT * FROM tags ORDER BY nama");
				  
            while($t=mysql_fetch_array($tags)){
                echo"
                <li><a href='$t[link]'>$t[nama]</a></li>
                ";
            }               
}

function banner() {
    $banner=mysql_query("SELECT * FROM banner ORDER BY id_banner DESC LIMIT 3");
            
            $n = 1;
            while($b=mysql_fetch_array($banner)){
                echo"
                <div class='item active'>
                    <div class='col-sm-6'>
                        <img src='photo/banner/$b[photo]' class='girl img-responsive' alt='' />
                        <img src='images/home/pricing.png'  class='pricing' alt='' />
                    </div>
                </div>    
                ";
            }               
}

function list_search($search){
    $list = mysql_query("SELECT * FROM produk WHERE nama LIKE '%$search%' ORDER BY id_produk");
    
    while($l = mysql_fetch_array($list)){
        echo"
            <li>
                <a class='cbp-vm-image' href='index.php?s=detail&id=$l[id_produk]'>
                    <div class='view view-first'>
                        <div class='inner_content clearfix'>
                            <div class='product_image'>
                                <img src='photo/produk/$l[gambar1]' class='img-responsive' alt=''/>
                                <div class='mask'>
                                    <div class='info'>Quick View</div>
                                </div>
                                <div class='product_container'>
                                    <div class='cart-left'>
                                        <p class='title'>$l[nama]</p>
                                    </div>
                                    <div class='clearfix'></div>
                                </div>		
                            </div>
                        </div>
                    </div>
                </a>
            </li>
        ";
    }
}

function counter($nomer,$kd){
        date_default_timezone_set('Asia/Jakarta');
        $bln_sekarang = date("m");
        $thn_sekarang = date("y");
    
        $kode = substr($nomer, 0, 2);
        $bulan = substr($nomer, 2, 2);
        $tahun = substr($nomer, 4, 2);
        $satuan = $kd;
        
        if($bulan != $bln_sekarang){
            $bulan = $bln_sekarang;
            $satuan = 0;
        }
        
        if ($tahun != $thn_sekarang){
            $tahun = $thn_sekarang;
        }
        
        $satuan = $satuan + 1;
        
        if($satuan >= 0 && $satuan < 10){
            $nilai = '000'.$satuan;
        }elseif ($satuan >= 10 && $satuan < 100) {
            $nilai = '00'.$satuan;
        }elseif ($satuan >= 100 && $satuan < 1000) {
            $nilai = '0'.$satuan;
        }elseif ($satuan >= 1000) {
            $nilai = $satuan;
        }
        
        $nl = $kode.$bulan.$tahun.$nilai;
        
        return array($nl,$satuan);
}

function artikel() {
    $artikel=mysql_query("SELECT * FROM berita ORDER BY id_berita DESC LIMIT 5");
				  
            while($a=mysql_fetch_array($artikel)){
                echo"
                <li><a href='index.php?s=isi&id=$a[id_berita]'>$a[judul]</a></li>
                ";
            }               
}

function metadata(){
    $keywords = mysql_query("SELECT nilai FROM defaults WHERE nama = 'keyword'");
    $k = mysql_fetch_array($keywords);
    
    $description = mysql_query("SELECT nilai FROM defaults WHERE nama = 'description'");
    $d = mysql_fetch_array($description);
    
    echo"
        <META NAME='DESCRIPTION' CONTENT='$d[nilai]'>
        <META NAME='KEYWORDS' CONTENT='$k[nilai]'>
        <META NAME='SUBJECT' CONTENT='$d[nilai]'>
        <META NAME='RATING' CONTENT='GENERAL'>
        <META NAME='ABSTRACT' CONTENT='$d[nilai]'>
        <META NAME='REVISIT-AFTER' CONTENT='2 DAYS'>
        <META NAME='GENERATOR' CONTENT='Microsoft FrontPage 4.0'>
        <META NAME='LANGUAGE' CONTENT='EN'>
        <META NAME='ROBOTS' CONTENT='All'>
        <META HTTP-EQUIV='REFRESH' CONTENT='1200'>
        <META content='MSHTML 6.00.2600.0' name=GENERATOR>
        <META name='y_key' content='378d5c6a24e0d697' >    
    ";
}


?>
