<?php

  function UpdateDataLast() {
   global $objAxpDB;
   $strSQL=array();
   $objAxpDB->Allow_update(true);

   switch($_REQUEST[mode]) {

   case "update":

   //UPDATE MODULE
    $ubah_module ="UPDATE tlsecurity
    SET ftmodule_code = '{$_REQUEST['ftmenu_category']}'
    WHERE ftmenu_code = '{$_REQUEST['ftmenu_code']}'";

    mysql_query($ubah_module);

  //UPDATE STATUS
  for($j=1; $j < count($_REQUEST['ftsecurity_codeD0']); $j++) {

    $ubah_status ="UPDATE tlsecurity
    SET fnstatus = '{$_REQUEST['fnstatusD0'][$j]}'
    WHERE fnid = '{$_REQUEST['fnidD0'][$j]}'";
    mysql_query($ubah_status);

  }

   $ambil = mysql_query("SELECT fnurut, `ftmenu_category`, ftmenu_name FROM tlmenu
            where ftmenu_category='{$_REQUEST['ftmenu_category']}'
            and ftmenu_type = '{$_REQUEST['ftmenu_type']}'
            AND ftmenu_code = '{$_REQUEST['ftmenu_code']}'");

   $hasil  = mysql_fetch_assoc($ambil);

    $srint1 ="UPDATE tlmenu
    SET fnurut = '{$hasil['fnurut']}'
    WHERE ftmenu_category = '{$_REQUEST['ftmenu_category']}'
    AND ftmenu_type = '{$_REQUEST['ftmenu_type']}'
    AND fnurut = '{$_REQUEST['fnurut']}'";

    mysql_query($srint1);

    $srint2 ="UPDATE tlmenu
    SET fnurut = '{$_REQUEST['fnurut']}'
    WHERE ftmenu_category = '{$_REQUEST['ftmenu_category']}'
    AND ftmenu_type = '{$_REQUEST['ftmenu_type']}'
    AND ftmenu_code = '{$_REQUEST['ftmenu_code']}'";

    mysql_query($srint2);

           break;
    }
    return $strSQL;
  }

    function DeleteData() {

    $sql ="DELETE FROM tlsecurity WHERE ftmenu_code='{$_REQUEST['ftmenu_code']}'";
    mysql_query($sql);

    }


  function SaveData() {
      global $objAxpDB;
      $strSQL=array();
      $objAxpDB->Allow_Save(true);
      switch($_REQUEST[mode]) {


    case "simpan":


    $ambil = mysql_query("SELECT fnurut, `ftmenu_category`, ftmenu_name FROM tlmenu
             where ftmenu_category='{$_REQUEST['ftmenu_category']}'
             and ftmenu_type = '{$_REQUEST['ftmenu_type']}'
             and fnurut = '{$_REQUEST['fnurut']}'");

    if($hasil = mysql_fetch_assoc($ambil)){

    $ssql1="SELECT MAX(fnurut)
                 FROM tlmenu
                 WHERE ftmenu_category = '{$_REQUEST['ftmenu_category']}'
                 AND ftmenu_type = '{$_REQUEST['ftmenu_type']}'";

    $no=RetRstField($ssql1);

    $plus = $no+1;

    $srint ="UPDATE tlmenu

    SET fnurut = '{$plus}'
    WHERE ftmenu_category = '{$_REQUEST['ftmenu_category']}'
    AND ftmenu_type = '{$_REQUEST['ftmenu_type']}'
    AND fnurut = '{$_REQUEST['fnurut']}'";

    mysql_query($srint);

  }

  break;

  }

    //MEMBUAT SECURITY
    $codesecurity = $_REQUEST['ftmenu_name'];
    $codesecurity = str_replace(" ", "_", $codesecurity);

    $array = array("","Baru","Detail","Batal","Simpan","Cetak","Revisi","Simpan_Revisi");

    for($j=0; $j < count($array); $j++) {

    // NAMA SECURITY
    $namasecurity = $_REQUEST['ftmenu_name'];
    // PARENT CODE
    $parentcode = $_REQUEST['ftmenu_name'];
    // MODUL CODE
    $modulecode = $_REQUEST['ftmenu_category'];
    // WENU CODE
    $menucode = $_REQUEST['ftmenu_code'];

    $array_[$j] = '_'.strtolower($array[$j]);

    if ($array[$j] == '') {

      $sql = "INSERT INTO tlsecurity
              (ftbranch_code,
                ftsecurity_code,
                ftsecurity_name,
                fnlevel,
               ftparent_code,
               ftmodule_code,
               ftmenu_code,
               ftcreated_user,
               fdcreated_date,
               ftmodified_user,
               fdmodified_date)
      VALUES ('{$_SESSION['strbranch']}','$codesecurity', '$namasecurity',
            '2','$parentcode','$modulecode','$menucode',
            '{$_SESSION['username']}', now() ,'{$_SESSION['username']}', now())";

    }else{

    $sql = "INSERT INTO tlsecurity
            (ftbranch_code,
              ftsecurity_code,
             ftsecurity_name,
             fnlevel,
             ftparent_code,
             ftmodule_code,
             ftmenu_code,
             ftcreated_user,
             fdcreated_date,
             ftmodified_user,
             fdmodified_date)
    VALUES ('{$_SESSION['strbranch']}','$codesecurity$array_[$j]', '$namasecurity ($array[$j])',
          '2','$parentcode','$modulecode','$menucode',
          '{$_SESSION['username']}', now() ,'{$_SESSION['username']}', now())";
    }

    mysql_query($sql);

    }

   return $strSQL;
}


?>
