예제 #1
0
<?php

use PermissionsManager\PermissionsManager;
$toReturn = [];
if (isset($_GET['id'])) {
    require '../../vendor/autoload.php';
    require '../tools.php';
    $menu_id = $_GET['id'];
    if (!hasOnlyDigits($menu_id)) {
        die('Wrong menu id format, only digits are allowed.');
    }
    $pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
    $menu = $pm->getMenus()->getMenuById($menu_id);
    if (count($menu) < 1) {
        $toReturn = ['error' => 'There was an error, the requested menu id was not found.'];
    } else {
        $toReturn = ['menuDetails' => $menu];
    }
} else {
    $toReturn = ['error' => 'No menu id was provided. Please check the request URL.'];
}
header('Content-Type: application/json');
echo json_encode($toReturn);
예제 #2
0
<?php

$method = isset($_SERVER['REQUEST_METHOD']) ? mb_strtolower($_SERVER['REQUEST_METHOD']) : '';
if ($method !== 'post') {
    header('Content-Type: application/json');
    echo json_encode(['messages' => ['Error: Request method is not supported.']]);
    die;
}
if (!isset($_POST['groupsToDelete'])) {
    header('Content-Type: application/json');
    echo json_encode(['messages' => ['Error: No groups to delete.']]);
    die;
}
if (!is_array($_POST['groupsToDelete'])) {
    header('Content-Type: application/json');
    echo json_encode(['messages' => ['Error: No groups to delete.']]);
    die;
}
require '../../vendor/autoload.php';
require '../tools.php';
use PermissionsManager\PermissionsManager;
$pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
$g = $pm->getGroups();
foreach ($_POST['groupsToDelete'] as $group_id) {
    if (is_scalar($group_id) && hasOnlyDigits($group_id)) {
        $g->deleteGroupById($group_id);
    }
}
header('Content-Type: application/json');
echo json_encode(['redirect' => BASE_URL . '/groups/']);
예제 #3
0
<?php

require '../../vendor/autoload.php';
require '../tools.php';
use PermissionsManager\PermissionsManager;
use PermissionsManager\Models\Users;
if (!isset($_GET['id'])) {
    die('User id to edit is missing from request URL.');
}
$user_id_to_edit = $_GET['id'];
if (!hasOnlyDigits($user_id_to_edit)) {
    die('Wrong User id format, only digits are allowed.');
}
$pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
$user_to_edit = $pm->getUsers()->getUserById($user_id_to_edit);
if (count($user_to_edit) < 1) {
    die('No User exists having the requested id.');
}
$method = isset($_SERVER['REQUEST_METHOD']) ? mb_strtolower($_SERVER['REQUEST_METHOD']) : '';
$errors = [];
$is_post = false;
if ($method == 'post') {
    $is_post = true;
    $first_name = isset($_POST['user_first_name']) && $_POST['user_first_name'] != '' ? $_POST['user_first_name'] : NULL;
    $last_name = isset($_POST['user_last_name']) && $_POST['user_last_name'] != '' ? $_POST['user_last_name'] : NULL;
    $username = isset($_POST['user_username']) ? $_POST['user_username'] : '';
    $password = isset($_POST['user_password']) ? $_POST['user_password'] : '';
    $email_address = isset($_POST['user_email_address']) ? $_POST['user_email_address'] : '';
    $status = isset($_POST['user_status']) ? $_POST['user_status'] : '';
    if (strlen($username) < 1 || strlen($username) > 128) {
        $errors[] = 'Username length must be 1..128.';
예제 #4
0
<?php

require '../../vendor/autoload.php';
require '../tools.php';
use PermissionsManager\PermissionsManager;
use PermissionsManager\Models\HttpRequests;
if (!isset($_GET['id'])) {
    die('Http request id to edit is missing from request URL.');
}
$http_request_id_to_edit = $_GET['id'];
if (!hasOnlyDigits($http_request_id_to_edit)) {
    die('Wrong Http request id format, only digits are allowed.');
}
$pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
$http_request_to_edit = $pm->getHttpRequests()->getHttpRequestById($http_request_id_to_edit);
if (count($http_request_to_edit) < 1) {
    die('No Http request exists having the requested menu id.');
}
$method = isset($_SERVER['REQUEST_METHOD']) ? mb_strtolower($_SERVER['REQUEST_METHOD']) : '';
$errors = [];
$is_post = false;
if ($method == 'post') {
    $is_post = true;
    $method = isset($_POST['http_request_method']) ? $_POST['http_request_method'] : '';
    $method_regex = isset($_POST['http_request_method_regex']) && $_POST['http_request_method_regex'] == 'on' ? HttpRequests::HTTP_REQUEST_METHOD_REGEX : HttpRequests::HTTP_REQUEST_METHOD_NOT_REGEX;
    $value = isset($_POST['http_request_value']) ? $_POST['http_request_value'] : '';
    $value_regex = isset($_POST['http_request_value_regex']) && $_POST['http_request_value_regex'] == 'on' ? HttpRequests::HTTP_REQUEST_VALUE_REGEX : HttpRequests::HTTP_REQUEST_VALUE_NOT_REGEX;
    $description = isset($_POST['http_request_description']) ? $_POST['http_request_description'] : '';
    $status = isset($_POST['http_request_status']) ? $_POST['http_request_status'] : '';
    if (strlen($method) < 1 || strlen($method) > 255) {
        $errors[] = 'Method length must be 1..255.';
<?php

use PermissionsManager\PermissionsManager;
use PermissionsManager\Models\HttpRequests;
require '../../vendor/autoload.php';
require '../tools.php';
if (!isset($_GET['id'])) {
    die('Http request id is missing from request URL.');
}
$http_request_id_to_edit_for_relations = $_GET['id'];
if (!hasOnlyDigits($http_request_id_to_edit_for_relations)) {
    die('Wrong Http request id format, only digits are allowed.');
}
$pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
$http_request_to_edit_for_relations = $pm->getHttpRequests()->getHttpRequestById($http_request_id_to_edit_for_relations);
if (count($http_request_to_edit_for_relations) < 1) {
    die('No Http request exists having the requested id.');
}
$assigned_groups = $pm->getHttpRequests()->getAssignedGroups($http_request_to_edit_for_relations['id']);
$method = isset($_SERVER['REQUEST_METHOD']) ? mb_strtolower($_SERVER['REQUEST_METHOD']) : '';
$errors = [];
$is_post = false;
if ($method == 'post') {
    $is_post = true;
    if (!isset($_POST['groups'])) {
        $errors[] = 'No groups to assign, in post request.';
    }
    try {
        $groups_to_assign = json_decode($_POST['groups']);
    } catch (Exception $exc) {
        $errors[] = 'Invalid groups format.';
<?php

use PermissionsManager\PermissionsManager;
use PermissionsManager\Models\Menus;
require '../../vendor/autoload.php';
require '../tools.php';
if (!isset($_GET['id'])) {
    die('Menu id is missing from request URL.');
}
$menu_id_to_edit_for_relations = $_GET['id'];
if (!hasOnlyDigits($menu_id_to_edit_for_relations)) {
    die('Wrong menu id format, only digits are allowed.');
}
$pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
$menu_to_edit_for_relations = $pm->getMenus()->getMenuById($menu_id_to_edit_for_relations);
if (count($menu_to_edit_for_relations) < 1) {
    die('No menu exists having the requested menu id.');
}
if ($menu_to_edit_for_relations['id'] == $pm->getMenus()->getRootMenuId()) {
    die('Cannot relate root menu (RootMenu) to any group.');
}
$menu_parent = $pm->getMenus()->getMenuById($menu_to_edit_for_relations['parent_id']);
$menu_parent_name = isset($menu_parent['name']) ? $menu_parent['name'] : 'unknown';
$menu_parent_name .= ' (' . (isset($menu_parent['id']) ? $menu_parent['id'] : '?') . ')';
$assigned_groups = $pm->getMenus()->getAssignedGroups($menu_to_edit_for_relations['id']);
$method = isset($_SERVER['REQUEST_METHOD']) ? mb_strtolower($_SERVER['REQUEST_METHOD']) : '';
$errors = [];
$is_post = false;
if ($method == 'post') {
    $is_post = true;
    if (!isset($_POST['groups'])) {
<?php

use PermissionsManager\PermissionsManager;
use PermissionsManager\Models\Users;
require '../../vendor/autoload.php';
require '../tools.php';
if (!isset($_GET['id'])) {
    die('User id is missing from request URL.');
}
$user_id_to_edit_for_relations = $_GET['id'];
if (!hasOnlyDigits($user_id_to_edit_for_relations)) {
    die('Wrong User id format, only digits are allowed.');
}
$pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
$user_to_edit_for_relations = $pm->getUsers()->getUserById($user_id_to_edit_for_relations);
if (count($user_to_edit_for_relations) < 1) {
    die('No User exists having the requested id.');
}
$assigned_groups = $pm->getUsers()->getAssignedGroups($user_to_edit_for_relations['id']);
$method = isset($_SERVER['REQUEST_METHOD']) ? mb_strtolower($_SERVER['REQUEST_METHOD']) : '';
$errors = [];
$is_post = false;
if ($method == 'post') {
    $is_post = true;
    if (!isset($_POST['groups'])) {
        $errors[] = 'No groups to assign, in post request.';
    }
    try {
        $groups_to_assign = json_decode($_POST['groups']);
    } catch (Exception $exc) {
        $errors[] = 'Invalid groups format.';
<?php

use PermissionsManager\PermissionsManager;
$toReturn = [];
if (isset($_GET['id'])) {
    require '../../vendor/autoload.php';
    require '../tools.php';
    $group_id = $_GET['id'];
    if (!hasOnlyDigits($group_id)) {
        die('Wrong group id format, only digits are allowed.');
    }
    $pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
    $group = $pm->getGroups()->getGroupById($group_id);
    if (count($group) < 1) {
        $toReturn = ['error' => 'There was an error, the requested group id was not found.'];
    } else {
        $toReturn = ['groupDetails' => $group];
    }
} else {
    $toReturn = ['error' => 'No group id was provided. Please check the request URL.'];
}
header('Content-Type: application/json');
echo json_encode($toReturn);
예제 #9
0
<?php

use PermissionsManager\PermissionsManager;
use PermissionsManager\Models\Menus;
require '../../vendor/autoload.php';
require '../tools.php';
if (!isset($_GET['id'])) {
    die('Menu id to edit is missing from request URL.');
}
$menu_id_to_edit = $_GET['id'];
if (!hasOnlyDigits($menu_id_to_edit)) {
    die('Wrong menu id format, only digits are allowed.');
}
$pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
$menu_to_edit = $pm->getMenus()->getMenuById($menu_id_to_edit);
if (count($menu_to_edit) < 1) {
    die('No menu exists having the requested menu id.');
}
if ($menu_to_edit['id'] == $pm->getMenus()->getRootMenuId()) {
    die('Cannot edit root menu (RootMenu)');
}
$method = isset($_SERVER['REQUEST_METHOD']) ? mb_strtolower($_SERVER['REQUEST_METHOD']) : '';
$errors = [];
$is_post = false;
if ($method == 'post') {
    $is_post = true;
    $name = isset($_POST['menu_name']) ? $_POST['menu_name'] : '';
    $href = isset($_POST['menu_href']) ? $_POST['menu_href'] : '';
    $display_order = isset($_POST['menu_display_order']) ? (int) $_POST['menu_display_order'] : 0;
    $class = isset($_POST['menu_class']) ? $_POST['menu_class'] : NULL;
    $image = isset($_POST['menu_image']) ? $_POST['menu_image'] : NULL;
예제 #10
0
<?php

use PermissionsManager\PermissionsManager;
use PermissionsManager\Models\Groups;
require '../../vendor/autoload.php';
require '../tools.php';
if (!isset($_GET['id'])) {
    die('Group id to edit is missing from request URL.');
}
$group_id_to_edit = $_GET['id'];
if (!hasOnlyDigits($group_id_to_edit)) {
    die('Wrong group id format, only digits are allowed.');
}
$pm = new PermissionsManager(include '../../src/PermissionsManager/config.php');
$group_to_edit = $pm->getGroups()->getGroupById($group_id_to_edit);
if (count($group_to_edit) < 1) {
    die('No group exists having the requested group id.');
}
if ($group_to_edit['id'] == $pm->getGroups()->getRootGroupId()) {
    die('Cannot edit root group (public)');
}
$method = isset($_SERVER['REQUEST_METHOD']) ? mb_strtolower($_SERVER['REQUEST_METHOD']) : '';
$errors = [];
$is_post = false;
if ($method == 'post') {
    $is_post = true;
    $name = isset($_POST['group_name']) ? $_POST['group_name'] : '';
    $description = isset($_POST['group_description']) ? $_POST['group_description'] : '';
    $details = isset($_POST['group_details']) ? $_POST['group_details'] : NULL;
    $status = isset($_POST['group_status']) ? $_POST['group_status'] : '';
    $group_parent = isset($_POST['group_parent']) ? $_POST['group_parent'] : '';