<?php

session_name("SIGNADMAUTH");
session_start();

include "common/config/config.php";
include "common/config/dbconfig.php";
include "common/functions/funcconnect.php";
openDB();

include "common/functions/funcselectdb.php";
include "common/functions/funcdeletedb.php";
include "common/functions/funcauthen.php";

//----------------------------------------------------------------------------------------------------------------------------

//MAIN CONDITION
if (!authen())
{
    header ("location: login.php");
}
else
{
    $id=$_GET['id'];
    $konfirmasi=isset($_GET['konfirmasi']) ? $_GET['konfirmasi'] : NULL;
    $tableName=$db_model;
    $fieldArray=array("namamodel");
    $condition="idmodel='".mysqli_real_escape_string($dbConnection, $id)."' ";
    $orderArray=array();
    $orderRule="";
    $limit="";

    $getData=simpleselect($tableName, $fieldArray, $condition, $orderArray, $orderRule, $limit);
    $dataModel=mysqli_fetch_array($getData);

    //CONDITION (delete confirmation)
    if ($konfirmasi=="")
    {
        $msg="Anda yakin ingin menghapus data Model Produk: <b>".$dataModel['namamodel']."</b>?<br><br>
                <input type='button' value=' Hapus ' onclick=\"document.location='model_delete.php?id=".$id."&konfirmasi=ok&menuid=".$_GET['menuid']."'\"> &nbsp; 
                <input type='button' value=' Batal ' onclick='history.back(-1)'>";
        $resultstatus="Konfirmasi"; 
    }
    //CONDITION (delete excecution)
    else
    {
        $qdm="DELETE FROM $db_model WHERE $condition";
        $rdm=mysqli_query($dbConnection, $qdm);

        //sub-condition
        if($rdm)
        {
            $msg="Menghapus Model Produk sukses.";
        }
        else
        {
            $msg="Menghapus Model Produk gagal.<br><br>".$linkback;
        }
    }

    //------------------------------------------------------------------------------------------------------------------

    //QUERY APP MENU
    $qq="SELECT a.appmenuname, b.parentmenuname FROM $db_appmenu a, $db_parent_menu b ";
	$qq.="WHERE a.appmenuid='".mysqli_real_escape_string($dbConnection, $_GET['menuid'])."' AND b.parentmenuid=a.parentid";
	$rr=mysqli_query($dbConnection, $qq);
	$dd=mysqli_fetch_array($rr);

    //CONTENT
    $content="<table border='0' cellpadding='6px' cellspacing='0' width='100%'>
						<tr>
							<td align='left' valign='top' width='100%'>
								<b class='title'>".$dd['parentmenuname']." &gt; ".$dd['appmenuname']."</b>
								<br><hr size='1' color='#000000'><br>
								<table border='0' cellpadding='0' cellspacing='0'>
									<tr>
										<td align='left' valign='top' width='45%'>
											".$msg."
											<br><br><br>
										</td>
									</tr>
								</table>		
							</td>
						</tr>
					</table>";

    //----------------------------------------------------------------------------------------------------------------------------

    //TEMPLATE
    include "webmenu.php";
	include "common/include/template.php";
	$temp=new template;
	$temp->define_theme("themes/theme1.html");
	$temp->define_tag("{PAGETITLE}", $namaaplikasi);
	$temp->define_tag("{NAMAUSER}", strtoupper($_SESSION['SES_FULLNAME']));
	$temp->define_tag("{APPMENU}", $webmenu);
	$temp->define_tag("{APPCONTENT}", $content);
	$temp->parse();
	$temp->printproses();
}

closeDB();

?>