// Sponsor: Oregon Dept. of Administrative Services, State Data Center
// Original Author of file: Ryan Foster
// Contact: Matt Hoover <*****@*****.**>
// Project Website: http://www.opensourcegov.net
// Purpose of file: Perform update, add, and delete actions
// ----------------------------------------------------------------------
include '../../../inc/includes.php';
if (!isset($_GET['id'])) {
    $_GET['id'] = '';
}
if (!isset($_GET['withtemplate'])) {
    $_GET['withtemplate'] = '';
}
if (isset($_POST['delete'])) {
    // Delete custom field
    $PluginItem = new PluginCustomfieldsItemtype($_REQUEST['itemtype']);
    $PluginItem->check($_POST['id'], 'w');
    $PluginItem->delete($_POST);
    Html::redirect($_SERVER['HTTP_REFERER']);
} elseif (isset($_POST['update'])) {
    // Update custom field
    $PluginItem = new PluginCustomfieldsItemtype($_REQUEST['itemtype']);
    $PluginItem->update($_POST);
    Html::redirect($_SERVER['HTTP_REFERER']);
} elseif (isset($_GET['add']) && isset($_REQUEST['itemtype']) && isset($_GET['id'])) {
    // Add custom field
    $PluginItem = new PluginCustomfieldsItemtype($_REQUEST['itemtype']);
    $PluginItem->getRestricted($_REQUEST['itemtype']);
    $newID = $PluginItem->add($_GET, false);
    Html::redirect($_SERVER['HTTP_REFERER']);
}