<?php
require_once($global['root-model']."Crud.php");
$obj_crud = new Crud();

require_once($global['root-model']."Ppn.php");
$obj_ppn = new Ppn();

require_once($global['root-model']."Access.php");
$obj_access = new Access();

if(!isset($_GET['action'])){

    $data = $obj_ppn->get_ppn($obj_crud);
    $acsp_edit = $obj_access->check_access($obj_cruds,$_SESSION['admin_id'],'edit_ppn');

    if($acsg_ppn != 1){
        header("Location:".$path['dashboard']);
    }

    if(isset($_SESSION['status'])){
        $message = $_SESSION['status'];
        unset($_SESSION['status']);
    } else {
        $message = "";
    }

    if(isset($_SESSION['alert'])){
        $alert = $_SESSION['alert'];
        unset($_SESSION['alert']);
    } else {
        $alert = "";
    }


} else if(isset($_GET['action'])){

    if($_GET['action'] == "edit"){

        $N_item_id = $obj_crud->escape_string(check_input($_POST['item_id']));
        $N_ppn = $obj_crud->escape_string(check_input($_POST['ppn']));

        $result = $obj_ppn->update_ppn($obj_crud, $N_item_id, $N_ppn);
        if($result != 0){
            $message = "PPN Succesfully Edited.";
            $_SESSION['alert'] = "success";
        }else{
            $message = "PPN Failed to Edited.";
            $_SESSION['alert'] = "error";
        }

        $_SESSION['status'] = $message;
        header("Location:".$path['ppn']."");

    }
}
?>