*
 * Copyright 2004–2006 Twenty One Degrees Pty. Ltd.
 *
 * @version 1.7
 * @licence https://github.com/symphonycms/symphony-1.7/blob/master/LICENCE
 *
 ***/
if (@array_key_exists("delete", $_POST['action'])) {
    $field_id = $_REQUEST['id'];
    ###
    # Delegate: Delete
    # Description: Prior to deletion of a custom field. ID is provided.
    $CampfireManager->notifyMembers('Delete', CURRENTPAGE, array("customfield_id" => $field_id));
    include_once TOOLKIT . "/class.customfieldmanager.php";
    $CustomFieldManager = new CustomFieldManager($Admin);
    $CustomFieldManager->delete($field_id);
    $Admin->rebuildWorkspaceConfig();
    General::redirect(URL . "/symphony/?page=/structure/customfields/&_f=complete");
}
if (@array_key_exists("save", $_POST['action']) || @array_key_exists("done", $_POST['action'])) {
    $required = array('name');
    extract($_POST);
    for ($i = 0; $i < count($required); $i++) {
        if (trim($fields[$required[$i]]) == "") {
            $errors[$required[$i]] = true;
        }
    }
    if (is_array($errors)) {
        define("__SYM_ENTRY_MISSINGFIELDS__", true);
    } else {
        $field_id = $_REQUEST['id'];
 *
 * Copyright 2004–2006 Twenty One Degrees Pty. Ltd.
 *
 * @version 1.7
 * @licence https://github.com/symphonycms/symphony-1.7/blob/master/LICENCE
 *
 ***/
$checked = @array_keys($_POST['items']);
switch ($_POST["with-selected"]) {
    case 'delete':
        $sql = "SELECT `primary_field` FROM `tbl_sections`";
        $primary_fields = $DB->fetchCol('primary_field', $sql);
        $fieldsList = array_map('intval', $checked);
        $fieldsList = array_diff($fieldsList, $primary_fields);
        if (is_array($fieldsList) && !empty($fieldsList)) {
            ###
            # Delegate: Delete
            # Description: Prior to deleting a custom field.
            #			   Array of fields is provided. This can be manipulated
            $CampfireManager->notifyMembers('Delete', CURRENTPAGE, array('customfields' => &$fieldsList));
            include_once TOOLKIT . "/class.customfieldmanager.php";
            $CustomFieldManager = new CustomFieldManager($Admin);
            foreach ($fieldsList as $id) {
                $CustomFieldManager->delete($id);
            }
            $Admin->rebuildWorkspaceConfig();
            $Admin->flush_cache(array("entries", "customfields"));
            General::redirect($Admin->getCurrentPageURL() . "&_f=complete");
        }
        break;
}