<?php
include_once('../libs/main.php');

$userPermissionObj = new userPermission();

if(isset($_REQUEST['act']) && $_REQUEST['act']=='edit' && isset($_REQUEST['id'])){
    $permissionDetail = $userPermissionObj->fromId($_REQUEST['id']);
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='load' && isset($_REQUEST['title'])){
    $data=array(
        'title'=>trim($_POST['title'])
    );

    $permissionDetail = $userPermissionObj->fromId($_REQUEST['id'] ?? 0);

    if(!empty($permissionDetail)){
        
        $id = $_POST['id'];
        $rs=$userPermissionObj->updateRecords($data,$id);
        header('Location:userPermission.php');
        exit;

    }else{

        $data['created_at'] = date('Y-m-d H:i:s');
        $rs=$userPermissionObj->addRecords($data);
        header('Location:userPermission.php');
        exit;
    }
}
include_once('../libs/routs.php');
