<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [1907] trunk: Fixes #1040 props junsuljin</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>1907</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-09-21 18:02:36 +0000 (Mon, 21 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fixes #1040 props junsuljin</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpxprofilebpxprofileadminphp">trunk/bp-xprofile/bp-xprofile-admin.php</a></li>
<li><a href="#trunkbpxprofilebpxprofileclassesphp">trunk/bp-xprofile/bp-xprofile-classes.php</a></li>
<li><a href="#trunkbpxprofilephp">trunk/bp-xprofile.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpxprofilebpxprofileadminphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-admin.php (1906 => 1907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-admin.php        2009-09-21 17:35:43 UTC (rev 1906)
+++ trunk/bp-xprofile/bp-xprofile-admin.php        2009-09-21 18:02:36 UTC (rev 1907)
</span><span class="lines">@@ -219,9 +219,14 @@
</span><span class="cx">                         $field->desc = wp_filter_kses( $_POST['description'] );
</span><span class="cx">                         $field->is_required = wp_filter_kses( $_POST['required'] );
</span><span class="cx">                         $field->type = wp_filter_kses( $_POST['fieldtype'] );
</span><del>-                        $field->order_by = wp_filter_kses( $_POST["sort_order_$field->type"] );
-                        $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 ) );
-                        $field->field_order++;
</del><ins>+                        $field->order_by = wp_filter_kses( $_POST["sort_order_{$field->type}"] );
+
+                        $field->field_order = $wpdb->get_var( $wpdb->prepare( "SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) );
+
+                        if ( !$field->field_order ) {
+                                $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 ) );
+                                $field->field_order++;
+                        }
</ins><span class="cx">                         
</span><span class="cx">                         if ( !$field->save() ) {
</span><span class="cx">                                 $message = __('There was an error saving the field. Please try again', 'buddypress');
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofileclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-classes.php (1906 => 1907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-classes.php        2009-09-21 17:35:43 UTC (rev 1906)
+++ trunk/bp-xprofile/bp-xprofile-classes.php        2009-09-21 18:02:36 UTC (rev 1907)
</span><span class="lines">@@ -231,9 +231,13 @@
</span><span class="cx">         function delete() {
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx">                 
</span><del>-                if ( !$this->id )
</del><ins>+                if ( !$this->id ||
+                        // Prevent deletion by url when can_delete is false.
+                        !$this->can_delete ||
+                        // Prevent deletion of option 1 since this invalidates fields with options.
+                        ( $this->parent_id && $this->option_order == 1 ) )
</ins><span class="cx">                         return false;
</span><del>-                        
</del><ins>+
</ins><span class="cx">                 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) )
</span><span class="cx">                         return false;
</span><span class="cx">                 
</span><span class="lines">@@ -264,7 +268,9 @@
</span><span class="cx">                 else
</span><span class="cx">                         $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 );
</span><span class="cx">
</span><del>-                if ( $wpdb->query($sql) ) {
</del><ins>+                // Check for null so field options can be changed without changing any other part of the field.
+                // The described situation will return 0 here.
+                if ( $wpdb->query($sql) !== null ) {
</ins><span class="cx">                         
</span><span class="cx">                         // Only do this if we are editing an existing field
</span><span class="cx">                         if ( $this->id != null ) {
</span><span class="lines">@@ -456,11 +462,25 @@
</span><span class="cx">                                         </select>
</span><span class="cx">         
</span><span class="cx">                                 <?php
</span><del>-                                $options = $this->get_children(true);
-                                
</del><ins>+                                if ( !$options = $this->get_children(true) ) {
+                                        $i = 1;
+                                        while ( isset( $_POST[$type . '_option'][$i] ) ) {
+                                                (array) $options[] = (object) array(
+                                                        'id' => -1,
+                                                        'name' => $_POST[$type . '_option'][$i],
+                                                        'is_default_option' => ( 'multiselectbox' != $type &&
+                                                                'checkbox' != $type &&
+                                                                $_POST["isDefault_{$type}_option"] == $i ) ?
+                                                                        1 :
+                                                                        $_POST["isDefault_{$type}_option"][$i]
+                                                );
+
+                                                $i++;
+                                        }
+                                }
+
</ins><span class="cx">                                 if ( !empty($options) ) {
</span><span class="cx">                                         for ( $i = 0; $i < count($options); $i++ ) {
</span><del>-                                                //var_dump($options[$i]);
</del><span class="cx">                                                 $j = $i + 1;
</span><span class="cx">                                                 
</span><span class="cx">                                                 if ( 'multiselectbox' == $type || 'checkbox' == $type )
</span><span class="lines">@@ -468,20 +488,21 @@
</span><span class="cx">                                         ?>
</span><span class="cx">                                                 <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>:
</span><span class="cx">                                                  <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 ) ?>" />
</span><del>-                                                 <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' ) ?>
-                                                <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>
</del><ins>+                                                 <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' ) ?>
+                                                        <?php if ( $j != 1 &&
+                                                                $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>
</ins><span class="cx">                                                 </p>
</span><span class="cx">                                         <?php } // end for ?>
</span><span class="cx">                                         <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="<?php echo $j + 1 ?>" />
</span><span class="cx">                                 
</span><span class="cx">                                 <?php
</span><span class="cx">                                 } else {
</span><del>-                                        if ( 'multiselectbox' == $type || 'checkxbox' == $type )
</del><ins>+                                        if ( 'multiselectbox' == $type || 'checkbox' == $type )
</ins><span class="cx">                                                 $default_name = '[1]';
</span><span class="cx">                                 ?>
</span><span class="cx">                                         
</span><span class="cx">                                         <p><?php _e('Option', 'buddypress') ?> 1: <input type="text" name="<?php echo $type ?>_option[1]" id="<?php echo $type ?>_option1" />
</span><del>-                                        <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' ) ?>
</del><ins>+                                        <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' ) ?>
</ins><span class="cx">                                         <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="2" />
</span><span class="cx">                                 
</span><span class="cx">                                 <?php } // end if ?>
</span><span class="lines">@@ -496,10 +517,15 @@
</span><span class="cx">                 if ( !$this->id ) {
</span><span class="cx">                         $title = __('Add Field', 'buddypress');
</span><span class="cx">                         $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
</span><ins>+
+                        $this->name                        = $_POST['title'];
+                        $this->desc                        = $_POST['description'];
+                        $this->is_required        = $_POST['required'];
+                        $this->type                        = $_POST['fieldtype'];
+                        $this->order_by                = $_POST["sort_order_{$this->type}"];
</ins><span class="cx">                 } else {
</span><span class="cx">                         $title = __('Edit Field', 'buddypress');
</span><span class="cx">                         $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;                        
</span><del>-                        $options = $this->get_children();
</del><span class="cx">                 }
</span><span class="cx">         ?>
</span><span class="cx">         
</span><span class="lines">@@ -528,7 +554,7 @@
</span><span class="cx">                                 <div id="titlediv" class="inside">
</span><span class="cx">                                         <h3><label for="description"><?php _e("Field Description", 'buddypress') ?></label></h3>
</span><span class="cx">                                         <div id="titlewrap">
</span><del>-                                                <textarea name="description" id="description" rows="8" cols="60"> <?php echo htmlspecialchars( $this->desc ); ?></textarea>
</del><ins>+                                                <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->desc ); ?></textarea>
</ins><span class="cx">                                         </div>
</span><span class="cx">                                 </div>
</span><span class="cx">         
</span></span></pre></div>
<a id="trunkbpxprofilephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile.php (1906 => 1907)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile.php        2009-09-21 17:35:43 UTC (rev 1906)
+++ trunk/bp-xprofile.php        2009-09-21 18:02:36 UTC (rev 1907)
</span><span class="lines">@@ -202,7 +202,7 @@
</span><span class="cx">         global $bp;
</span><span class="cx">         
</span><span class="cx">         /* Add 'Profile' to the main navigation */
</span><del>-        bp_core_new_nav_item( array( 'name' => __('Profile', 'buddypress'), 'slug' => $bp->profile->slug, 'position' => 20, 'screen_function' => 'xprofile_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => $bp->profile->id ) );
</del><ins>+        bp_core_new_nav_item( array( 'name' => __( 'Profile', 'buddypress' ), 'slug' => $bp->profile->slug, 'position' => 20, 'screen_function' => 'xprofile_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => $bp->profile->id ) );
</ins><span class="cx">
</span><span class="cx">         $profile_link = $bp->loggedin_user->domain . $bp->profile->slug . '/';
</span><span class="cx">         
</span><span class="lines">@@ -213,7 +213,7 @@
</span><span class="cx">
</span><span class="cx">         if ( $bp->current_component == $bp->profile->slug ) {
</span><span class="cx">                 if ( bp_is_home() ) {
</span><del>-                        $bp->bp_options_title = __('My Profile', 'buddypress');
</del><ins>+                        $bp->bp_options_title = __( 'My Profile', 'buddypress' );
</ins><span class="cx">                 } else {
</span><span class="cx">                         $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
</span><span class="cx">                         $bp->bp_options_title = $bp->displayed_user->fullname;
</span></span></pre>
</div>
</div>
</body>
</html>