<?php


    function SaveData() {
      
        global $objAxpDB;
        $objAxpDB->Allow_Save(false);
        switch($_REQUEST[mode]) {
        case "simpan":

              $strSQL['Update tluser '][]="
               INSERT INTO tluser (
                    fnid,ftbranch_code,ftusername,
                    ftpassword,ftfirst_name,ftmiddle_name,
                    ftlast_name,ftdepartment,ftuser_group_code,
                    fndefault_module,fnstatus,ftcreated_user,
                    fdcreated_date,ftmodified_user,fdmodified_date
                )
                SELECT
                    '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftusername']}' AS ftusername,
                    '{$_REQUEST['ftpassword']}' AS ftpassword, '{$_REQUEST['ftfirst_name']}' AS ftfirst_name, '{$_REQUEST['ftmiddle_name']}' AS ftmiddle_name,
                     '{$_REQUEST['ftlast_name']}' AS ftlast_name, '{$_REQUEST['ftdepartment']}'  AS ftdepartment,'{$_REQUEST['ftuser_group_code']}' AS ftuser_group_code,
                    '' AS fndefault_module,'{$_REQUEST['fnstatus']}' AS fnstatus,'{$_SESSION['username']}' AS ftcreated_user,
                    NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,NOW() AS fdmodified_date";


            foreach ($_REQUEST['fnS']  as $key => $value) {
                $m="$value";
                if(isset($_REQUEST['c'.$m])) {
                    $c="1";
                }
                else {
                    $c="0";
                }

                $strSQL['Insert tluser'][]="
                    REPLACE INTO tluser_access (
                            fnid,ftbranch_code,ftusername,
                            ftsecurity_code,fbaccess,ftcreated_user,
                            fdcreated_date,ftmodified_user,fdmodified_date
                            )
                            SELECT
                            '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftusername']}' AS ftusername,
                            '{$value}' AS fnsecurity_access,'{$c}' AS fnsecurity,'{$_SESSION['username']}' AS ftcreated_user,
                            now() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,now() AS fdmodified_date";

                }

        break;
        }
      return $strSQL;
    }

     function UpdateData() {
//           pr($_REQUEST);
//        die("");
        global $objAxpDB;
        $objAxpDB->Allow_Update(false);
        switch($_REQUEST[mode]) {

        case "update":

             $strSQL['Update tluser '][]="
               REPLACE INTO tluser (
                    ftbranch_code,ftusername,
                    ftpassword,ftfirst_name,ftmiddle_name,
                    ftlast_name,ftdepartment,ftuser_group_code,
                    fndefault_module,fnstatus,ftcreated_user,
                    fdcreated_date,ftmodified_user,fdmodified_date
                )
                SELECT
                    '{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftusername']}' AS ftusername,
                    '{$_REQUEST['ftpassword']}' AS ftpassword, '{$_REQUEST['ftfirst_name']}' AS ftfirst_name, '{$_REQUEST['ftmiddle_name']}' AS ftmiddle_name,
                     '{$_REQUEST['ftlast_name']}' AS ftlast_name, '{$_REQUEST['ftdepartment']}'  AS ftdepartment,'{$_REQUEST['ftuser_group_code']}' AS ftuser_group_code,
                    '' AS fndefault_module,'{$_REQUEST['fnstatus']}' AS fnstatus,'{$_SESSION['username']}' AS ftcreated_user,
                    NOW() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,NOW() AS fdmodified_date";


             foreach ($_REQUEST['fnS']  as $key => $value) {
                $m="$value";
                if(isset($_REQUEST['c'.$m])) {
                    $c="1";
                }
                else {
                    $c="0";
                }

                $strSQL['Insert tluser'][]="
                REPLACE INTO tluser_access (
                        fnid,ftbranch_code,ftusername,
                        ftsecurity_code,fbaccess,ftcreated_user,
                        fdcreated_date,ftmodified_user,fdmodified_date
                        )
                        SELECT
                        '' AS fnid,'{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftusername']}' AS ftusername,
                        '{$value}' AS fnsecurity_access,'{$c}' AS fnsecurity,'{$_SESSION['username']}' AS ftcreated_user,
                        now() AS fdcreated_date,'{$_SESSION['username']}' AS ftmodified_user,now() AS fdmodified_date";


             }
        break;
        }
		 #pr($strSQL);die("mm");
      return $strSQL;
    }

      function DeleteData() {
            global $objAxpDB;
            $objAxpDB->Allow_Delete(false);
            switch($_REQUEST[mode]) {
                case "hapus":

                    $ftusername="";
                    $ssql="select ftusername FROM tluser WHERE fnid='{$_REQUEST['id']}'";
                    $rs=mysql_query($ssql);
                    $r=mysql_fetch_assoc($rs);
                    $ftusername=$r['ftusername'];

                    $strSQL['Del tluser'][]="DELETE FROM tluser WHERE  ftusername='{$_REQUEST['ftusername']}'";
                    $strSQL['Del tluser_access'][]="DELETE FROM tluser_access WHERE  ftusername='{$_REQUEST['ftusername']}'";
                    break;
                }

          return $strSQL;
        }

?>