Skip to:
Content

BuddyPress.org

Changeset 16


Ignore:
Timestamp:
04/08/2008 12:49:51 AM (19 years ago)
Author:
apeatling
Message:

added delete and edit functionality for groups

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp_xprofile.php

    r15 r16  
    7373        require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    7474        dbDelta($sql);
    75                
    7675}
    7776
  • trunk/bp_xprofile/bp_xprofile.admin.php

    r1 r16  
    3939                }
    4040        }
    41 
     41        else if(isset($_GET['mode']) && isset($_GET['group_id']) && $_GET['mode'] == "edit_group")
     42        {
     43                if(bp_core_validate($_GET['group_id'])) {
     44                        xprofile_admin_manage_group($_GET['group_id']); die;
     45                }
     46        }
    4247?>     
    4348        <div class="wrap">
    … …  
    6671                                        <thead>
    6772                                            <tr>
    68                                                 <th scope="col" colspan="6"><?php echo $groups[$i]->name; ?> <?php if($groups[$i]->can_delete) { ?> [<a href="admin.php?page=xprofile_settings&amp;mode=delete_group&amp;group_id=<?php echo $groups[$i]->id; ?>">x</a>] <?php } ?></th>
    69                                             </tr>
     73                                                <th scope="col" colspan="<?php if($groups[$i]->can_delete) { ?>3<?php } else { ?>5<?php } ?>"><?php echo $groups[$i]->name; ?></th>
     74                                                        <?php if($groups[$i]->can_delete) { ?>         
     75                                                                <th scope="col"><a class="edit" href="admin.php?page=xprofile_settings&amp;mode=edit_group&amp;group_id=<?php echo $groups[$i]->id; ?>">Edit</a></th>
     76                                                        <th scope="col"><a class="delete" href="admin.php?page=xprofile_settings&amp;mode=delete_group&amp;group_id=<?php echo $groups[$i]->id; ?>">Delete</a></th>
     77                                                        <?php } ?>
     78                                                </tr>
    7079                                        </thead>
    7180                                        <tbody id="the-list">
    … …  
    137146{
    138147        global $message, $type;
    139        
     148
    140149        $group = new BP_XProfile_Group($group_id);
    141150
    … …  
    212221       
    213222        $field = new BP_XProfile_Field($field_id);
     223        $field->group_id = $group_id;
    214224
    215225        if(isset($_POST['saveField']))
    … …  
    217227                if(BP_XProfile_Field::admin_validate($_POST))
    218228                {
    219                         $field->group_id = $group_id;
    220229                        $field->name = bp_core_clean($_POST['title']);
    221230                        $field->desc = bp_core_clean($_POST['description']);
  • trunk/bp_xprofile/bp_xprofile.classes.php

    r15 r16  
    6161        {
    6262                global $wpdb;
    63                
     63
    6464                if($this->id != null)
    6565                {
    66                         // Update a group.
     66                        $sql = "UPDATE " . $this->table_name . "_groups
     67                                        SET
     68                                                name = '" . $this->name . "',
     69                                                description = '" . $this->description . "'
     70                                        WHERE id = " . $this->id;
    6771                }
    6872                else
    … …  
    7074                        $sql = "INSERT INTO " . $this->table_name . "_groups (
    7175                                                name,
    72                                                 description
     76                                                description,
     77                                                can_delete
    7378                                        ) VALUES (
    7479                                                '" . $this->name . "',
    75                                                 '" . $this->description . "'
     80                                                '" . $this->description . "',
     81                                                1
    7682                                        )";                     
    7783                }
    … …  
    94100                                WHERE id = " . $this->id;
    95101
    96                 if($wpdb->query($sql) === false) {
    97                         return false;
    98                 }
    99                 else {
     102                if($wpdb->query($sql) === false)
     103                {
     104                        return false;
     105                }
     106                else
     107                {
    100108                        // Now the group is deleted, remove the group's fields.
    101                         $sql = "DELETE FROM " . $this->table_name . "_fields
    102                                         WHERE group_id = " . $this->id;
    103 
    104                         if($wpdb->query($sql) === false) {
    105                                 return false;
    106                         }
    107                         else
     109                        if(BP_XProfile_Field::delete_for_group($this->id))
    108110                        {
    109111                                // Now delete all the profile data for the groups fields
    110 
    111112                                for($i=0; $i<count($this->fields); $i++)
    112                                 {                       
    113                                         $sql = "DELETE FROM " . $this->table_name . "_data
    114                                                         WHERE field_id = " . $this->fields[$i]->id;
    115                                        
    116                                         $wpdb->query($sql);
     113                                {       
     114                                        BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id);
    117115                                }
    118116                        }
    … …  
    144142        {
    145143                global $message;
     144
     145                if($this->id == null) {
     146                        $title = __('Add Group');
     147                        $action = "admin.php?page=xprofile_settings&amp;mode=add_group";
     148                }
     149                else {
     150                        $title = __('Edit Group');
     151                        $action = "admin.php?page=xprofile_settings&amp;mode=edit_group&amp;group_id=" . $this->id;                     
     152                }
    146153               
    147154                ?>
    … …  
    149156                <div class="wrap">
    150157               
    151                         <h2><?php _e('Add Group'); ?></h2>
     158                        <h2><?php echo $title; ?></h2>
    152159
    153160                        <?php if($message != '') { ?>
    … …  
    157164                        <?php } ?>
    158165                       
    159                         <form action="admin.php?page=xprofile_settings&amp;mode=add_group" method="post">
     166                        <form action="<?php echo $action; ?>" method="post">
    160167                               
    161168                                <fieldset id="titlediv">
    … …  
    167174                               
    168175                                <p class="submit" style="text-align: left">
    169                                         <input type="submit" name="saveGroup" value="Create Group &raquo;" />
     176                                        <input type="submit" name="saveGroup" value="<?php echo $title; ?> &raquo;" />
    170177                                </p>
    171178                       
    … …  
    302309               
    303310                // delete the data in the DB for this field
    304                 BP_XProfile_ProfileData::delete_all($this->id);
     311                BP_XProfile_ProfileData::delete_for_field($this->id);
    305312               
    306313                return true;
    … …  
    598605        function render_admin_form($message = '')
    599606        {
    600                 if($this->id != null) {
     607                if($this->id == null) {
     608                        $title = __('Add Field');
     609                        $action = "admin.php?page=xprofile_settings&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
     610                }
     611                else {
     612                        $title = __('Edit Field');
     613                        $action = "admin.php?page=xprofile_settings&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;                       
    601614                        $options = $this->get_children();
    602615                }
     616               
    603617        ?>
    604618       
    605619        <div class="wrap">
    606620               
    607                 <h2><?php _e("Profile Settings") ?> &raquo; <?php _e('Add Field') ?></h2>
     621                <h2><?php echo $title; ?></h2>
    608622
    609623                <?php if($message != '') { ?>
    … …  
    765779                return false;
    766780        }
     781       
     782        function delete_for_group($group_id)
     783        {
     784                global $wpdb, $bp_xprofile_table_name;
     785
     786                if(bp_core_validate($group_id))
     787                {
     788                        $sql = "DELETE FROM " . $bp_xprofile_table_name . "_fields
     789                                        WHERE group_id = " . $group_id;
     790
     791                        if($wpdb->get_var($sql) === false)
     792                        {
     793                                return false;
     794                        }
     795                       
     796                        return true;
     797                }
     798               
     799                return false;
     800        }
    767801}
    768802
    … …  
    940974        }
    941975       
    942         function delete_all($field_id)
     976        function delete_for_field($field_id)
    943977        {
    944978                global $wpdb, $userdata;
Note: See TracChangeset for help on using the changeset viewer.