$field_data = array();
// Data object we will save
// Init Error bits
$data['id.error'] = '';
$data['title.error'] = '';
$data['callback.error'] = '';
$data['id.error_class'] = '';
$data['title.error_class'] = '';
$data['callback.error_class'] = '';
$data['style'] = file_get_contents(CCTM_PATH . '/css/validation.css');
// Save if submitted...
if (!empty($_POST) && check_admin_referer($data['action_name'], $data['nonce_name'])) {
    //print_r($_POST); exit;
    $def = CCTM_Metabox::sanitize($_POST);
    //print_r($def); exit;
    if (CCTM_Metabox::is_valid_def($_POST, true)) {
        $data['msg'] = CCTM::format_msg(__('Metabox updated.', CCTM_TXTDOMAIN));
        // Find any refs to the old id and update them
        if ($def['id'] != $def['old_id']) {
            if (isset(CCTM::$data['post_type_defs']) && is_array(CCTM::$data['post_type_defs'])) {
                foreach (CCTM::$data['post_type_defs'] as $pt => $ptd) {
                    if (isset($ptd['map_field_metabox']) && is_array($ptd['map_field_metabox'])) {
                        foreach ($ptd['map_field_metabox'] as $cf => $mb) {
                            if ($mb == $def['old_id']) {
                                CCTM::$data['post_type_defs'][$pt]['map_field_metabox'][$cf] = $def['id'];
                            }
                        }
                    }
                }
            }
        }
$data['title.error_class'] = '';
$data['callback.error_class'] = '';
// Init data points
$data['id'] = '';
$data['title'] = '';
$data['context'] = 'advanced';
$data['priority'] = 'default';
$data['callback'] = '';
$data['callback_args'] = '';
$data['visibility_control'] = '';
$data['style'] = file_get_contents(CCTM_PATH . '/css/validation.css');
// Save if submitted...
if (!empty($_POST) && check_admin_referer($data['action_name'], $data['nonce_name'])) {
    $def = CCTM_Metabox::sanitize($_POST);
    unset($def['old_id']);
    if (CCTM_Metabox::is_valid_def($_POST)) {
        CCTM::$data['metabox_defs'][$def['id']] = $def;
        CCTM::set_flash(CCTM::format_msg(__('Metabox created.', CCTM_TXTDOMAIN)));
        $continue_editing = CCTM::get_value($_POST, 'continue_editing');
        unset($_POST);
        if ($continue_editing) {
            CCTM::redirect('?page=cctm&a=edit_metabox&id=' . $def['id']);
        } else {
            CCTM::redirect('?page=cctm');
        }
        return;
    } else {
        $data['msg'] = CCTM::format_error_msg(CCTM_Metabox::$errors, __('Please correct the following problems.', CCTM_TXTDOMAIN));
        foreach (CCTM_Metabox::$errors as $field => $error) {
            $data[$field . '.error'] = sprintf('<span class="cctm_validation_error">%s</span>', $error);
            $data[$field . '.error_class'] = 'cctm_validation_error';
    }
}
// Get things sorted into their spots
if (isset($metaboxes['normal'])) {
    foreach ($metaboxes['normal'] as $m => $items) {
        $data['normal_boxes'] .= CCTM_Metabox::get_metabox_holder($m, $items);
    }
}
if (isset($metaboxes['advanced'])) {
    foreach ($metaboxes['advanced'] as $m => $items) {
        $data['advanced_boxes'] .= CCTM_Metabox::get_metabox_holder($m, $items);
    }
}
if (isset($metaboxes['side'])) {
    foreach ($metaboxes['side'] as $m => $items) {
        $data['side_boxes'] .= CCTM_Metabox::get_metabox_holder($m, $items);
    }
}
//print_r($data); exit;
// List the unused custom fields
$remaining_custom_fields = array_diff($all_custom_fields, $active_custom_fields);
foreach ($remaining_custom_fields as $cf) {
    $d = self::$data['custom_field_defs'][$cf];
    if (!($FieldObj = CCTM::load_object($d['type'], 'fields'))) {
        continue;
    }
    $d['icon'] = $FieldObj->get_icon();
    if (!CCTM::is_valid_img($d['icon'])) {
        $d['icon'] = self::get_custom_icons_src_dir() . 'default.png';
    }
    $d['class'] = 'ui-state-default';