<?php

if($_REQUEST['ajax']) {

  switch($_REQUEST['code']) {

    case "urutan":

           $ssql="SELECT MAX(fnOrder) FROM tlreport WHERE ftreport_group='{$_REQUEST['ftreport_group']}'";

           $urutan=RetRstField($ssql);
           $urutan = $urutan+1;

           ?>
                   document.getElementById('fnOrder').value='<?php echo $urutan; ?>';
           <?php


      break;

    case "ftreport_code":

      if(RetRstField("SELECT ftreport_code FROM tlreport WHERE ftreport_code='{$_REQUEST['ftreport_code']}'"))
      {
        ?>
          alert('Kode Laporan sudah dipakai... ');
        <?php
      }
      else
      {
        ?>
          submitbutton('Simpan','','','','');
        <?php
      }
    break;
  }

  die("");
  exit;
}
  Getsecurity('setting_laporan');
$objAxpDB->ViewName("Daftar Setting Laporan");

$SQL = "SELECT `fnid`,
       `ftreport_code`,
       `ftreport_name`,
       `ftreport_sql`,
       `ftreport_group`,
       `fnOrder`,
       `fnstatus`
       FROM `tlreport`";

$objAxpDB->ViewSQL($SQL);

$objAxpDB->ViewCaption("id,Kode Laporan,Nama Laporan,SQL, Grup Laporan, No Urut, Status");

$objAxpDB->FormName("Setting Laporan");

$objAxpDB->FormSQL("SELECT fnid,ftreport_code,ftreport_name,ftreport_sql,ftreport_group,fnOrder,fnstatus FROM tlreport");

$objAxpDB->FormCaption("id,Kode Laporan,Nama Laporan,SQL, Grup Laporan, No Urut, Status");

$objAxpDB->FormPosition("HD,TL, TL, TL, TR, TR, TR");

$objAxpDB->SetStatus("id");

$objAxpDB->Lookup('fnstatus', 'SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status where fntrans_status_code<>2 and fntrans_group_code=9', 'fntrans_status_code', 'fttrans_status_name', 1,true);

$objAxpDB->Lookup('ftreport_group', "SELECT ftmodule_code,ftmodule_name FROM tsmodule WHERE fnstatus = 1","ftmodule_code","ftmodule_name", -1,true);

$ajaxurutan="ajax_do('setting.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=urutan&ftreport_group='+ document.getElementById('ftreport_group').value);";

$objAxpDB->FormScript(4, "onChange=\"{$ajaxurutan}\"");

if ($objAxpDB->GetStatus("id") == "") {

    $objAxpDB->ButtonShow("baru");

  }elseif($objAxpDB->GetStatus("id") == 0){

    $objAxpDB->ButtonShow("reset, simpan, tutup");

  }elseif($objAxpDB->GetStatus("id") != 0) {

    $objAxpDB->ButtonShow("update, hapus, tutup");

  }

$objAxpDB->Process();
$objAxpDB->WriteHtmlTable();
