<?php
include("../../db.php");

$status = 0;
$msg = 'Unknown error';

$role_id = $_POST['role_id'];
$permission_name = $_POST['permission_name'];
$roll_status = $_POST['roll_status'];
$app_admin_id = $_POST['admin_id'];

$is_check = $db->getVal("select id from tbl_privilages where page_name='" . $permission_name . "' and roll_id='" . $role_id . "'");

$all = 0;
$none = 0;

if ($roll_status == 1) $all = 1; else $none = 1;

$aryData = array('page_name' => $permission_name, 'a' => $all, 'n' => $none, 'roll_id' => $role_id);

$flgIn = 0;

if ($is_check != "") {

    $flgIn = $db->updateAry("tbl_privilages", $aryData, " where id = '$is_check' ");

} else {
    $aryData["school_id"] = 1;
    $aryData["added_by"]  = $app_admin_id;

    $flgIn = $db->insertAry("tbl_privilages", $aryData);
}

if ($flgIn > 0) {
    $status = 1;
    $msg = 'Record updated successfully';
} else {
    $msg = "Unable to update info...! Please try again later";
}

echo json_encode(array("status" => $status, "msg" => "$msg"));