<?php
do_action( 'bp_before_sidebar' );
?>

<div id="sidebar">
    <div class="padder">
    
    <?php
    do_action( 'bp_inside_before_sidebar' );
    
    /**
     * Only show widgets to logged in users
     **/
    if ( is_user_logged_in() ) {
        ?>
        <div id="search-bar">
            <div class="padder">
                <?php
                if ( bp_search_form_enabled() ) : ?>
                    <form action="<?php echo site_url() . '/customsearch/'; ?>" method="post" id="search-form">
                        <input type="text" id="search-terms" name="search-terms" value="" />
                        <input type="submit" name="search-submit" id="search-submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
                        <?php /*
                        <p class="iron_search_in">
                        <?php echo bp_search_form_type_select() ?>
                        </p>
                        */ ?>
                        <?php wp_nonce_field( 'bp_search_form' ) ?>
                    </form><!-- #search-form -->
                <?php
                endif;
                
            do_action( 'bp_search_login_bar' );
            ?>
            
            </div><!-- #search-bar .padder -->
        </div><!-- #search-bar -->
        
        <?php
        /**
         * Sidebar defecto
         */
        dynamic_sidebar( 'sidebar' );
        
        /**
         * Control de Widgets segun EstadoAnimo
         */
        $origmood = xprofile_get_field_data( 'EstadoAnimo', get_current_user_id());
        $cats     = get_categories(array('hide_empty' => 0, 'parent' => 1));
        
        if (sizeof($cats)>0) {
            foreach ($cats as $cat) {
                if ($cat->slug == $origmood)
                    dynamic_sidebar( $cat->name );
            }
        }
    }
    
    do_action( 'bp_inside_after_sidebar' );
    ?>
    
    </div><!-- .padder -->
</div><!-- #sidebar -->
<?php
do_action( 'bp_after_sidebar' );
?>