<?php

$path = '../../../';
require_once $path . 'core/includes/header.inc.php';

$custom = [];

if (isset($_REQUEST['custom']) && is_array($_REQUEST['custom'])) {
    $custom = $_REQUEST['custom'];
} elseif (isset($_REQUEST['item_id'])) {
    $item = new Item($_REQUEST['item_id']);
    $custom = $item->custom;
}

$set_id = 0;

if (is_numeric($_REQUEST['category_id'])) {
    // for sub_categories, search parent categories for field sets also
    $category_id = $_REQUEST['category_id'];
    $set_id = CustomFieldsHelper::getCategorySet($category_id);
}

//Get the default set if the category doesn't have one.
if ($set_id == 0) {
    $set_id = CustomFieldsHelper::getDefaultSet();
}

CustomFieldsHelper::displaySet($set_id, 'items', $custom);
?>

<input type="hidden" name="custom_field_set_id" value="<?= clean_page($set_id) ?>" />
