<!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-&gt;desc = wp_filter_kses( $_POST['description'] );
</span><span class="cx">                         $field-&gt;is_required = wp_filter_kses( $_POST['required'] );
</span><span class="cx">                         $field-&gt;type = wp_filter_kses( $_POST['fieldtype'] );
</span><del>-                        $field-&gt;order_by = wp_filter_kses( $_POST[&quot;sort_order_$field-&gt;type&quot;] );
-                        $field-&gt;field_order = (int) $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT max(field_order) FROM {$bp-&gt;profile-&gt;table_name_fields} WHERE group_id = %d&quot;, $group_id ) );
-                        $field-&gt;field_order++;
</del><ins>+                        $field-&gt;order_by = wp_filter_kses( $_POST[&quot;sort_order_{$field-&gt;type}&quot;] );
+
+                        $field-&gt;field_order = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT field_order FROM {$bp-&gt;profile-&gt;table_name_fields} WHERE id = %d&quot;, $field_id ) );
+
+                        if ( !$field-&gt;field_order ) {
+                                $field-&gt;field_order = (int) $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT max(field_order) FROM {$bp-&gt;profile-&gt;table_name_fields} WHERE group_id = %d&quot;, $group_id ) );
+                                $field-&gt;field_order++;
+                        }
</ins><span class="cx">                         
</span><span class="cx">                         if ( !$field-&gt;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-&gt;id )
</del><ins>+                if ( !$this-&gt;id ||
+                        // Prevent deletion by url when can_delete is false.
+                        !$this-&gt;can_delete ||
+                        // Prevent deletion of option 1 since this invalidates fields with options.
+                        ( $this-&gt;parent_id &amp;&amp; $this-&gt;option_order == 1 ) )
</ins><span class="cx">                         return false;
</span><del>-                        
</del><ins>+
</ins><span class="cx">                 if ( !$wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM {$bp-&gt;profile-&gt;table_name_fields} WHERE id = %d OR parent_id = %d&quot;, $this-&gt;id, $this-&gt;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-&gt;prepare(&quot;INSERT INTO {$bp-&gt;profile-&gt;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 )&quot;, $this-&gt;group_id, $this-&gt;type, $this-&gt;name, $this-&gt;desc, $this-&gt;is_required, $this-&gt;order_by, $this-&gt;field_order );
</span><span class="cx"> 
</span><del>-                if ( $wpdb-&gt;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-&gt;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-&gt;id != null ) {
</span><span class="lines">@@ -456,11 +462,25 @@
</span><span class="cx">                                         &lt;/select&gt;
</span><span class="cx">         
</span><span class="cx">                                 &lt;?php
</span><del>-                                $options = $this-&gt;get_children(true);
-                                
</del><ins>+                                if ( !$options = $this-&gt;get_children(true) ) {
+                                        $i = 1;
+                                        while ( isset( $_POST[$type . '_option'][$i] ) ) {
+                                                (array) $options[] = (object) array(
+                                                        'id' =&gt; -1,
+                                                        'name' =&gt; $_POST[$type . '_option'][$i],
+                                                        'is_default_option' =&gt; ( 'multiselectbox' != $type &amp;&amp;
+                                                                'checkbox' != $type &amp;&amp;
+                                                                $_POST[&quot;isDefault_{$type}_option&quot;] == $i ) ?
+                                                                        1 :
+                                                                        $_POST[&quot;isDefault_{$type}_option&quot;][$i]
+                                                );
+
+                                                $i++;
+                                        }
+                                }
+
</ins><span class="cx">                                 if ( !empty($options) ) {
</span><span class="cx">                                         for ( $i = 0; $i &lt; 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">                                         ?&gt;
</span><span class="cx">                                                 &lt;p&gt;&lt;?php _e('Option', 'buddypress') ?&gt; &lt;?php echo $j ?&gt;: 
</span><span class="cx">                                                    &lt;input type=&quot;text&quot; name=&quot;&lt;?php echo $type ?&gt;_option[&lt;?php echo $j ?&gt;]&quot; id=&quot;&lt;?php echo $type ?&gt;_option&lt;?php echo $j ?&gt;&quot; value=&quot;&lt;?php echo attribute_escape( $options[$i]-&gt;name ) ?&gt;&quot; /&gt;
</span><del>-                                                   &lt;input type=&quot;&lt;?php echo $default_input ?&gt;&quot; name=&quot;isDefault_&lt;?php echo $type ?&gt;_option&lt;?php echo $default_name; ?&gt;&quot; &lt;?php if ( (int) $options[$i]-&gt;is_default_option ) {?&gt; checked=&quot;checked&quot;&lt;?php } ?&gt; &quot; value=&quot;&lt;?php echo $j ?&gt;&quot; /&gt; &lt;?php _e( 'Default Value', 'buddypress' ) ?&gt; 
-                                                &lt;a href=&quot;admin.php?page=&lt;?php echo BP_PLUGIN_DIR ?&gt;/bp-xprofile.php&amp;amp;mode=delete_option&amp;amp;option_id=&lt;?php echo $options[$i]-&gt;id ?&gt;&quot; class=&quot;ajax-option-delete&quot; id=&quot;delete-&lt;?php echo $options[$i]-&gt;id ?&gt;&quot;&gt;[x]&lt;/a&gt;&lt;/p&gt;
</del><ins>+                                                   &lt;input type=&quot;&lt;?php echo $default_input ?&gt;&quot; name=&quot;isDefault_&lt;?php echo $type ?&gt;_option&lt;?php echo $default_name ?&gt;&quot; &lt;?php if ( (int) $options[$i]-&gt;is_default_option ) {?&gt; checked=&quot;checked&quot;&lt;?php } ?&gt; &quot; value=&quot;&lt;?php echo $j ?&gt;&quot; /&gt; &lt;?php _e( 'Default Value', 'buddypress' ) ?&gt; 
+                                                        &lt;?php if ( $j != 1 &amp;&amp;
+                                                                $options[$i]-&gt;id != -1 ) : ?&gt;&lt;a href=&quot;admin.php?page=&lt;?php echo BP_PLUGIN_DIR ?&gt;/bp-xprofile.php&amp;amp;mode=delete_option&amp;amp;option_id=&lt;?php echo $options[$i]-&gt;id ?&gt;&quot; class=&quot;ajax-option-delete&quot; id=&quot;delete-&lt;?php echo $options[$i]-&gt;id ?&gt;&quot;&gt;[x]&lt;/a&gt;&lt;?php endif ?&gt;&lt;/p&gt;
</ins><span class="cx">                                                 &lt;/p&gt;
</span><span class="cx">                                         &lt;?php } // end for ?&gt;
</span><span class="cx">                                         &lt;input type=&quot;hidden&quot; name=&quot;&lt;?php echo $type ?&gt;_option_number&quot; id=&quot;&lt;?php echo $type ?&gt;_option_number&quot; value=&quot;&lt;?php echo $j + 1 ?&gt;&quot; /&gt;
</span><span class="cx">                                 
</span><span class="cx">                                 &lt;?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">                                 ?&gt;
</span><span class="cx">                                         
</span><span class="cx">                                         &lt;p&gt;&lt;?php _e('Option', 'buddypress') ?&gt; 1: &lt;input type=&quot;text&quot; name=&quot;&lt;?php echo $type ?&gt;_option[1]&quot; id=&quot;&lt;?php echo $type ?&gt;_option1&quot; /&gt;
</span><del>-                                        &lt;input type=&quot;&lt;?php echo $default_input ?&gt;&quot; name=&quot;isDefault_&lt;?php echo $type ?&gt;_option&lt;?php echo $default_name; ?&gt;&quot; id=&quot;isDefault_&lt;?php echo $type ?&gt;_option&quot; &lt;?php if ( (int) $options[$i]-&gt;is_default_option ) {?&gt; checked=&quot;checked&quot;&lt;?php } ?&gt;&quot; value=&quot;1&quot; /&gt; &lt;?php _e( 'Default Value', 'buddypress' ) ?&gt;
</del><ins>+                                        &lt;input type=&quot;&lt;?php echo $default_input ?&gt;&quot; name=&quot;isDefault_&lt;?php echo $type ?&gt;_option&lt;?php echo $default_name; ?&gt;&quot; id=&quot;isDefault_&lt;?php echo $type ?&gt;_option&quot; &lt;?php if ( $default_input == 'radio' ) {?&gt; checked=&quot;checked&quot;&lt;?php } ?&gt;&quot; value=&quot;1&quot; /&gt; &lt;?php _e( 'Default Value', 'buddypress' ) ?&gt;
</ins><span class="cx">                                         &lt;input type=&quot;hidden&quot; name=&quot;&lt;?php echo $type ?&gt;_option_number&quot; id=&quot;&lt;?php echo $type ?&gt;_option_number&quot; value=&quot;2&quot; /&gt;
</span><span class="cx">                                 
</span><span class="cx">                                 &lt;?php } // end if ?&gt;
</span><span class="lines">@@ -496,10 +517,15 @@
</span><span class="cx">                 if ( !$this-&gt;id ) {
</span><span class="cx">                         $title = __('Add Field', 'buddypress');
</span><span class="cx">                         $action = &quot;admin.php?page=&quot; . BP_PLUGIN_DIR . &quot;/bp-xprofile.php&amp;amp;group_id=&quot; . $this-&gt;group_id . &quot;&amp;amp;mode=add_field&quot;;
</span><ins>+
+                        $this-&gt;name                        = $_POST['title'];
+                        $this-&gt;desc                        = $_POST['description'];
+                        $this-&gt;is_required        = $_POST['required'];
+                        $this-&gt;type                        = $_POST['fieldtype'];
+                        $this-&gt;order_by                = $_POST[&quot;sort_order_{$this-&gt;type}&quot;];
</ins><span class="cx">                 } else {
</span><span class="cx">                         $title = __('Edit Field', 'buddypress');
</span><span class="cx">                         $action = &quot;admin.php?page=&quot; . BP_PLUGIN_DIR . &quot;/bp-xprofile.php&amp;amp;mode=edit_field&amp;amp;group_id=&quot; . $this-&gt;group_id . &quot;&amp;amp;field_id=&quot; . $this-&gt;id;                        
</span><del>-                        $options = $this-&gt;get_children();
</del><span class="cx">                 }
</span><span class="cx">         ?&gt;
</span><span class="cx">         
</span><span class="lines">@@ -528,7 +554,7 @@
</span><span class="cx">                                 &lt;div id=&quot;titlediv&quot; class=&quot;inside&quot;&gt;
</span><span class="cx">                                         &lt;h3&gt;&lt;label for=&quot;description&quot;&gt;&lt;?php _e(&quot;Field Description&quot;, 'buddypress') ?&gt;&lt;/label&gt;&lt;/h3&gt;
</span><span class="cx">                                         &lt;div id=&quot;titlewrap&quot;&gt;
</span><del>-                                                &lt;textarea name=&quot;description&quot; id=&quot;description&quot; rows=&quot;8&quot; cols=&quot;60&quot;&gt; &lt;?php echo htmlspecialchars( $this-&gt;desc ); ?&gt;&lt;/textarea&gt;
</del><ins>+                                                &lt;textarea name=&quot;description&quot; id=&quot;description&quot; rows=&quot;8&quot; cols=&quot;60&quot;&gt;&lt;?php echo htmlspecialchars( $this-&gt;desc ); ?&gt;&lt;/textarea&gt;
</ins><span class="cx">                                         &lt;/div&gt;
</span><span class="cx">                                 &lt;/div&gt;
</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' =&gt; __('Profile', 'buddypress'), 'slug' =&gt; $bp-&gt;profile-&gt;slug, 'position' =&gt; 20, 'screen_function' =&gt; 'xprofile_screen_display_profile', 'default_subnav_slug' =&gt; 'public', 'item_css_id' =&gt; $bp-&gt;profile-&gt;id ) );
</del><ins>+        bp_core_new_nav_item( array( 'name' =&gt; __( 'Profile', 'buddypress' ), 'slug' =&gt; $bp-&gt;profile-&gt;slug, 'position' =&gt; 20, 'screen_function' =&gt; 'xprofile_screen_display_profile', 'default_subnav_slug' =&gt; 'public', 'item_css_id' =&gt; $bp-&gt;profile-&gt;id ) );
</ins><span class="cx"> 
</span><span class="cx">         $profile_link = $bp-&gt;loggedin_user-&gt;domain . $bp-&gt;profile-&gt;slug . '/';
</span><span class="cx">         
</span><span class="lines">@@ -213,7 +213,7 @@
</span><span class="cx"> 
</span><span class="cx">         if ( $bp-&gt;current_component == $bp-&gt;profile-&gt;slug ) {
</span><span class="cx">                 if ( bp_is_home() ) {
</span><del>-                        $bp-&gt;bp_options_title = __('My Profile', 'buddypress');
</del><ins>+                        $bp-&gt;bp_options_title = __( 'My Profile', 'buddypress' );
</ins><span class="cx">                 } else {
</span><span class="cx">                         $bp-&gt;bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' =&gt; $bp-&gt;displayed_user-&gt;id, 'type' =&gt; 'thumb' ) );
</span><span class="cx">                         $bp-&gt;bp_options_title = $bp-&gt;displayed_user-&gt;fullname; 
</span></span></pre>
</div>
</div>

</body>
</html>