public function post() { $data = $this->get_posted_data(); $field_id = $this->request->param('awpcp_extra_field_id'); if (!empty($field_id)) { $previous_field = awpcp_get_extra_field($field_id); } else { $previous_field = null; } try { // TODO: do not return output, render it // The above is not currently possible, because the whole admin section is // being handled in a single function. That code needs to be converted into // a page class. return $this->save_field_data($data, $previous_field); } catch (AWPCP_Exception $e) { $output = load_the_extra_fields_form($previous_field ? $previous_field->field_id : 0, $data['field_name'], $data['field_label'], $data['field_label_view'], $data['field_input_type'], $data['field_mysql_data_type'], $data['field_options'], $data['field_validation'], $data['field_privacy'], $data['field_category'], $e->getMessage(), $data['nosearch'], $data['show_on_listings'], $data['required']); throw new AWPCP_Exception($output); } }
function awpcp_add_new_field() { global $wpdb, $tbl_ads; $output = ''; $show_settings = true; $action = awpcp_request_param('action'); if ($action == 'addnewfield') { $show_settings = false; $output .= load_the_extra_fields_form($awpcp_x_field_id = '', $awpcp_x_field_name = '', $awpcp_x_field_label = '', $awpcp_x_field_label_view = '', $awpcp_x_field_input_type = '', $awpcp_x_field_mysqldata_type = '', $awpcp_x_field_options = '', $awpcp_x_field_validation = '', $awpcp_x_field_privacy = '', $awpcp_x_field_category = array(), $x_error_msg = ''); } elseif ($action == 'edit') { if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { $x_id = $_REQUEST['id']; } if (!isset($x_id) || empty($x_id)) { $x_msg = __("There was no ID supplied for the field you would like to edit", 'awpcp-extra-fields'); $output .= awpcp_display_extra_fields($x_msg); } else { $field = awpcp_get_extra_field($x_id); $show_settings = false; $output .= load_the_extra_fields_form($field->field_id, $field->field_name, $field->field_label, $field->field_label_view, $field->field_input_type, $field->field_mysql_data_type, $field->field_options, $field->field_validation, $field->field_privacy, $field->field_category, '', $field->nosearch, $field->show_on_listings, $field->required); } } elseif ($action == 'delete') { if (isset($_REQUEST['id']) && !empty($_REQUEST['id'])) { $x_id = $_REQUEST['id']; } if (!isset($x_id) || empty($x_id)) { $x_msg = __("There was no ID supplied for the field you would like to delete", 'awpcp-extra-fields'); $output .= awpcp_display_extra_fields($x_msg); } else { $query = 'SELECT field_name FROM ' . AWPCP_TABLE_EXTRA_FIELDS . ' WHERE field_id = %d'; $query = $wpdb->prepare($query, $x_id); $x_field_name = $wpdb->get_var($query); $query = 'DELETE FROM ' . AWPCP_TABLE_EXTRA_FIELDS . ' WHERE field_id = %d'; $query = $wpdb->prepare($query, $x_id); if ($wpdb->query($query) !== false) { $wpdb->query("ALTER TABLE " . AWPCP_TABLE_ADS . " DROP `" . $x_field_name . "`"); $x_msg = __("The field has been successfully deleted", 'awpcp-extra-fields'); } $output .= awpcp_display_extra_fields($x_msg); } } elseif ($action == 'savefielddata') { // TODO: is this really necessary? // we are passing the variable as a parameter to another function. global $x_msg; $step = awpcp_save_extra_field_data_step(); try { $x_msg = $step->post(); $output .= awpcp_display_extra_fields($x_msg); } catch (AWPCP_Exception $e) { $show_settings = false; $output .= $e->getMessage(); } } else { global $x_msg; $output .= awpcp_display_extra_fields($x_msg); } $output = awpcp_extra_fields_admin_head($show_settings) . $output . awpcp_extra_fields_admin_foot(); echo $output; }