<?php

//SESSION
session_name("SIGNADMAUTH");
session_start();

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

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

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

//MAIN CONDITION
if (!authen())
{
    header("location: login.php");
}
else
{
    // //SELECT OPTION KOTA
    $queryKota="SELECT * FROM $db_kota ORDER BY namakota ASC";
    $qk=mysqli_query($dbConnection, $queryKota);

    $selectKota="<select name='idkota'>
                    <option value=''>-- Pilih Nama Kota --</option>";

    while ($loopKota=mysqli_fetch_array($qk))
    {
        $selectKota.="<option value='".$loopKota['idkota']."'>".$loopKota['idkota']." - ".$loopKota['namakota']."</option>";
    }
    $selectKota.="</select>";


    //SELECT OPTION PROPINSI
    $queryPropinsi="SELECT * FROM $db_propinsi";
    $qp=mysqli_query($dbConnection, $queryPropinsi);

    $selectPropinsi="<select name='idpropinsi'>
                        <option value=''>-- Pilih Nama Propinsi --</option>";

    while ($loopPropinsi=mysqli_fetch_array($qp))
    {
        $selectPropinsi.="<option value='".$loopPropinsi['idpropinsi']."'>".$loopPropinsi['idpropinsi']." - ".$loopPropinsi['namapropinsi']."</option>";
    }
    $selectPropinsi.="<select>";
    

    // ==============================================================================================================

    //FORM
    $form="<form method='POST' action='rekanan_add_process.php?menuid=".$_GET['menuid']."' enctype='multipart/form-data' style='padding:0; margin:0'>
                <table border='0' cellpadding='10px' cellspacing='0'>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Nama Rekanan
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='text' size='25' name='rekanan_add' autocomplete='off' placeholder='input nama rekanan..' required>
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Kode Rekanan
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='text' size='25' name='kodeRekanan_add' autocomplete='off' placeholder='input kode rekanan..' required>
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            PID
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='text' size='25' name='kodeRekanan_add' autocomplete='off' placeholder='input PID..' required>
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Alamat Rekanan
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='text' size='25' name='kodeRekanan_add' autocomplete='off' placeholder='input alamat rekanan..' required>
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            ID/Nama Kota 
                        </td>
                        <td align='left' valign='middle' nowrap>
                            ".$selectKota."
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            ID/Nama Propinsi 
                        </td>
                        <td align='left' valign='middle' nowrap>
                            ".$selectPropinsi."
                        </td>
                    </tr>                  
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Nama Lengkap
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='text' size='25' name='namaLengkap_add' autocomplete='off' placeholder='input nama lengkap..' required>
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Telepon Rekanan
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='text' size='25' name='teleponRekanan_add' autocomplete='off' placeholder='input telepon rekanan..' required>
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Email Rekanan
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='text' size='25' name='emailRekanan_add' autocomplete='off' placeholder='input email rekanan..' required>
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Tanggal Input
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='text' size='25' name='tglInput_add' autocomplete='off' placeholder='input tanggal..' required>
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Status Suspend
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='radio' name='statusSuspend_add' value='0' checked> Tidak Disuspend &nbsp;
                            <input type='radio' name='statusSuspend_add' value='1'> Disuspend
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap>
                            Status Aktif
                        </td>
                        <td align='left' valign='middle' nowrap>
                            <input type='radio' name='statusAktif_add' value='0' checked> Tidak Aktif &nbsp;
                            <input type='radio' name='statusAktif_add' value='1'> Aktif
                        </td>
                    </tr>
                    <tr>
                        <td align='left' valign='middle' nowrap></td>
                        <td align='left' valign='middle' nowrap>
                            <input type='submit' value=' Simpan ' class='text-primary'> &nbsp;
                            <input type='button' value=' Batal ' onclick='history.back(-1)'>
                        </td>
                    </tr>
                </table>
            </form>";
                    
    //------------------------------------------------------------------------------------------------------------------------

        //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);

        //TABLE
        $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' width'100%'>
                                    <tr>
                                        <td align='left' valign='top'>
                                            ".$form."<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();

?>