Skip to:
Content

BuddyPress.org

Ticket #1040: bp-xprofile-admin-fixes.patch

File bp-xprofile-admin-fixes.patch, 7.2 KB (added by junsuijin, 15 years ago)
  • bp-xprofile/bp-xprofile-admin.php

     
    219219                        $field->desc = wp_filter_kses( $_POST['description'] );
    220220                        $field->is_required = wp_filter_kses( $_POST['required'] );
    221221                        $field->type = wp_filter_kses( $_POST['fieldtype'] );
    222                         $field->order_by = wp_filter_kses( $_POST["sort_order_$field->type"] );
    223                         $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) );
    224                         $field->field_order++;
     222                        $field->order_by = wp_filter_kses( $_POST["sort_order_{$field->type}"] );
     223
     224                        $field->field_order = $wpdb->get_var( $wpdb->prepare( "SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) );
     225
     226                        if ( $field->field_order === null ) {
     227
     228                                $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) );
     229                                $field->field_order++;
     230
     231                        }
    225232                       
    226233                        if ( !$field->save() ) {
    227234                                $message = __('There was an error saving the field. Please try again', 'buddypress');
  • bp-xprofile/bp-xprofile-classes.php

     
    231231        function delete() {
    232232                global $wpdb, $bp;
    233233               
    234                 if ( !$this->id )
     234                if ( !$this->id ||
     235                        // Prevent deletion by url when can_delete is false.
     236                        !$this->can_delete ||
     237                        // Prevent deletion of option 1 since this invalidates fields with options.
     238                        ( $this->parent_id && $this->option_order == 1 ) )
    235239                        return false;
    236                        
     240
    237241                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) )
    238242                        return false;
    239243               
     
    264268                else
    265269                        $sql = $wpdb->prepare("INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, 0, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->type, $this->name, $this->desc, $this->is_required, $this->order_by, $this->field_order );
    266270
    267                 if ( $wpdb->query($sql) ) {
     271                // Check for null so field options can be changed without changing any other part of the field.
     272                // The described situation will return 0 here.
     273                if ( $wpdb->query($sql) !== null ) {
    268274                       
    269275                        // Only do this if we are editing an existing field
    270276                        if ( $this->id != null ) {
     
    456462                                        </select>
    457463       
    458464                                <?php
    459                                 $options = $this->get_children(true);
    460                                
     465                                if ( !$options = $this->get_children(true) ) {
     466                                        $i = 1;
     467                                        while ( isset( $_POST[$type . '_option'][$i] ) ) {
     468                                                (array) $options[] = (object) array(
     469                                                        'id' => -1,
     470                                                        'name' => $_POST[$type . '_option'][$i],
     471                                                        'is_default_option' => ( 'multiselectbox' != $type &&
     472                                                                'checkbox' != $type &&
     473                                                                $_POST["isDefault_{$type}_option"] == $i ) ?
     474                                                                        1 :
     475                                                                        $_POST["isDefault_{$type}_option"][$i]
     476                                                );
     477
     478                                                $i++;
     479                                        }
     480                                }
     481
    461482                                if ( !empty($options) ) {
    462483                                        for ( $i = 0; $i < count($options); $i++ ) {
    463                                                 //var_dump($options[$i]);
    464484                                                $j = $i + 1;
    465485                                               
    466486                                                if ( 'multiselectbox' == $type || 'checkbox' == $type )
     
    468488                                        ?>
    469489                                                <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>:
    470490                                                   <input type="text" name="<?php echo $type ?>_option[<?php echo $j ?>]" id="<?php echo $type ?>_option<?php echo $j ?>" value="<?php echo attribute_escape( $options[$i]->name ) ?>" />
    471                                                    <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name; ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j ?>" /> <?php _e( 'Default Value', 'buddypress' ) ?>
    472                                                 <a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id ?>">[x]</a></p>
     491                                                   <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j ?>" /> <?php _e( 'Default Value', 'buddypress' ) ?>
     492                                                        <?php if ( $j != 1 &&
     493                                                                $options[$i]->id != -1 ) : ?><a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id ?>">[x]</a><?php endif ?></p>
    473494                                                </p>
    474495                                        <?php } // end for ?>
    475496                                        <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="<?php echo $j + 1 ?>" />
    476497                               
    477498                                <?php
    478499                                } else {
    479                                         if ( 'multiselectbox' == $type || 'checkxbox' == $type )
     500                                        if ( 'multiselectbox' == $type || 'checkbox' == $type )
    480501                                                $default_name = '[1]';
    481502                                ?>
    482503                                       
    483504                                        <p><?php _e('Option', 'buddypress') ?> 1: <input type="text" name="<?php echo $type ?>_option[1]" id="<?php echo $type ?>_option1" />
    484                                         <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type ?>_option" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?>" value="1" /> <?php _e( 'Default Value', 'buddypress' ) ?>
     505                                        <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type ?>_option" <?php if ( $default_input == 'radio' ) {?> checked="checked"<?php } ?>" value="1" /> <?php _e( 'Default Value', 'buddypress' ) ?>
    485506                                        <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="2" />
    486507                               
    487508                                <?php } // end if ?>
     
    496517                if ( !$this->id ) {
    497518                        $title = __('Add Field', 'buddypress');
    498519                        $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
     520
     521                        $this->name                     = $_POST['title'];
     522                        $this->desc                     = $_POST['description'];
     523                        $this->is_required      = $_POST['required'];
     524                        $this->type                     = $_POST['fieldtype'];
     525                        $this->order_by         = $_POST["sort_order_{$this->type}"];
    499526                } else {
    500527                        $title = __('Edit Field', 'buddypress');
    501528                        $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;                   
    502                         $options = $this->get_children();
    503529                }
    504530        ?>
    505531       
     
    528554                                <div id="titlediv" class="inside">
    529555                                        <h3><label for="description"><?php _e("Field Description", 'buddypress') ?></label></h3>
    530556                                        <div id="titlewrap">
    531                                                 <textarea name="description" id="description" rows="8" cols="60"> <?php echo htmlspecialchars( $this->desc ); ?></textarea>
     557                                                <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->desc ); ?></textarea>
    532558                                        </div>
    533559                                </div>
    534560