function awpcp_extra_fields_render_field($field, $value, $category, $context, $errors = array())
 {
     $label = stripslashes_deep($field->field_label);
     $name = "awpcp-{$field->field_name}";
     $type = $field->field_input_type;
     $id = $name;
     $classes = array_filter(array('awpcp-form-spacer', 'awpcp-extra-field', "awpcp-extra-field-{$field->field_name}"));
     foreach ($field->field_category as $category_id) {
         $classes[] = "awpcp-extra-field-category-{$category_id}";
     }
     $all_categories = awpcp_get_categories_ids();
     // always show field if no category is selected or all categories are selected
     if (empty($field->field_category) || count(array_diff($all_categories, $field->field_category)) == 0) {
         $classes[] = 'awpcp-extra-field-always-visible';
         // hide fields that belong to a different category
     } else {
         if (!empty($category) && !in_array($category, $field->field_category)) {
             $classes[] = 'awpcp-extra-field-hidden';
         }
     }
     $validators = array();
     switch ($field->field_validation) {
         case 'email':
             $validators[] = 'email';
             break;
         case 'url':
             $validators[] = 'url';
             break;
         case 'currency':
             $validators[] = 'money';
             break;
         case 'missing':
             $validators[] = 'required';
             break;
         case 'numericdeci':
             $validators[] = 'number';
             break;
         case 'numericnodeci':
             $validators[] = 'integer';
             break;
     }
     if ($context != 'search' && $field->required && $field->field_validation != 'missing') {
         $validators[] = 'required';
     }
     $validator = join(' ', $validators);
     /* Range Search support */
     $has_numeric_data_type = in_array($field->field_mysql_data_type, array('INT', 'FLOAT'));
     $has_numeric_validator = in_array($field->field_validation, array('numericdeci', 'numericnodeci'));
     $is_single_valued = in_array($type, array('Input Box', 'Select', 'Radio Button'));
     // TODO: pass min and max values
     if ($context == 'search' && $is_single_valued && ($has_numeric_validator || $has_numeric_data_type)) {
         $id = "awpcp-extra-field-{$name}-min";
         $body = '<span class="awpcp-range-search">';
         $body .= '<label for="%1$s-min">' . __('Min', 'awpcp-extra-fields') . '</label>';
         $body .= '<input id="%1$s-min" class="inputbox %2$s" type="text" name="%3$s-min" value="%4$s">';
         $body .= '<label for="%1$s-max">' . __('Max', 'awpcp-extra-fields') . '</label>';
         $body .= '<input id="%1$s-max" class="inputbox %2$s" type="text" name="%3$s-max" value="%5$s">';
         $body .= '</span>';
         if (!is_array($value)) {
             $value = stripslashes_deep(array('min' => $value, 'max' => $value));
         }
         $body = sprintf($body, "awpcp-extra-field-{$name}", $validator, $name, $value['min'], $value['max']);
         /* Normal Input */
     } else {
         if ($type == 'Input Box') {
             $body = '<input id="%s" class="inputbox %s" type="text" name="%s" value="%s">';
             $body = sprintf($body, $name, $validator, $name, stripslashes($value));
         } else {
             if ($type == 'Select') {
                 $options = array(sprintf('<option value="">%s</option>', __('Select One', 'awpcp-extra-fields')));
                 foreach ($field->field_options as $option) {
                     $option = trim($option);
                     $_html = '<option %s value="%s">%s</option>';
                     $_html = sprintf($_html, $value == $option ? 'selected' : '', awpcp_esc_attr($option), stripslashes($option));
                     $options[] = $_html;
                 }
                 $body = sprintf('<select id="%s" class="%s" name="%s">%s</select>', $name, $validator, $name, join('', $options));
             } else {
                 if ($type == 'Textarea Input') {
                     $body = '<textarea id="%s" class="awpcp-textarea textareainput %s" name="%s" rows="10" cols="50">%s</textarea>';
                     $body = sprintf($body, $name, $validator, $name, awpcp_esc_textarea($value));
                 } else {
                     if ($type == 'Radio Button') {
                         $options = array();
                         foreach ($field->field_options as $option) {
                             $_html = '<label class="secondary-label"><input class="%s" type="radio" %s name="%s" value="%s">%s</label><br>';
                             $_html = sprintf($_html, $validator, $value == $option ? 'checked' : '', $name, awpcp_esc_attr($option), stripslashes($option));
                             $options[] = $_html;
                         }
                         $body = join('', $options);
                     } else {
                         if ($type == 'Select Multiple') {
                             $value = is_array($value) ? $value : explode(',', $value);
                             $options = array();
                             foreach ($field->field_options as $option) {
                                 $option = trim($option);
                                 $_html = '<option %s value="%s">%s</option>';
                                 $options[] = sprintf($_html, in_array($option, $value) ? 'selected' : '', awpcp_esc_attr($option), stripslashes($option));
                             }
                             $body = '<select id="%s" class="%s" name="%s[]" multiple style="width:25%%;height:100px">%s</select>';
                             $body = sprintf($body, $name, $validator, $name, join('', $options));
                         } else {
                             if ($type == 'Checkbox') {
                                 $value = is_array($value) ? $value : explode(',', $value);
                                 $options = array();
                                 foreach ($field->field_options as $option) {
                                     $_html = '<label class="secondary-label"><input class="%s" type="checkbox" %s name="%s[]" value="%s">%s</label><br>';
                                     $options[] = sprintf($_html, $validator, in_array($option, $value) ? 'checked' : '', $name, awpcp_esc_attr($option), stripslashes($option));
                                 }
                                 $body = join('', $options);
                             }
                         }
                     }
                 }
             }
         }
     }
     $error = awpcp_form_error($field->field_name, $errors);
     $html = '<p class="%s" data-category="%s"><label for="%s">%s</label>%s %s</p>';
     return sprintf($html, join(' ', $classes), join(',', $field->field_category), $id, $label, $body, $error);
 }
Esempio n. 2
0
 protected function get_ad_info($ad_id)
 {
     global $wpdb, $hasextrafieldsmodule;
     $fields = array('ad_id', 'user_id', 'adterm_id', 'ad_title', 'ad_contact_name', 'ad_contact_email', 'ad_category_id', 'ad_contact_phone', 'ad_item_price', 'ad_details', 'websiteurl', 'ad_startdate', 'ad_enddate', 'ad_key');
     if ($hasextrafieldsmodule) {
         foreach (x_fields_fetch_fields() as $field) {
             $fields[] = "`{$field}` AS `awpcp-{$field}`";
         }
     }
     $query = "SELECT " . join(', ', $fields) . " ";
     $query .= "FROM " . AWPCP_TABLE_ADS . " ";
     $query .= "WHERE ad_id=%d";
     $data = $wpdb->get_row($wpdb->prepare($query, (int) $ad_id), ARRAY_A);
     if (get_awpcp_option('allowhtmlinadtext')) {
         $data['ad_details'] = awpcp_esc_textarea($data['ad_details']);
     }
     // please note we are dividing the Ad price by 100
     // Ad prices have been historically stored in cents
     $data['ad_category'] = $data['ad_category_id'];
     $data['ad_item_price'] = $data['ad_item_price'] / 100;
     $data['start_date'] = $data['ad_startdate'];
     $data['end_date'] = $data['ad_enddate'];
     $data['regions'] = AWPCP_Ad::get_ad_regions($ad_id);
     return $data;
 }
<textarea id="<?php 
echo esc_attr($html['id']);
?>
" class="awpcp-textarea textareainput <?php 
echo esc_attr($html['class']);
?>
" name="<?php 
echo esc_attr($html['name']);
?>
" rows="10" cols="50"><?php 
echo awpcp_esc_textarea($value);
?>
</textarea>