<?php
global $wpdb;
/**
 * Template Name: Eventos
 * Description: Eventos
 **/
?>
<?php get_header() ?>
<?php
$eventExist = $wpdb->get_row('select * from wp_jet_events where slug = "' . $_GET['view'] . '"');

if ($eventExist) {
    $titleEvent = __('Evento:','buddypress') . ' ' . $eventExist->name;
} else {
    $titleEvent = __('Eventos','buddypress');
}

echo '<title>' . apply_filters(bp_get_page_title(), $titleEvent . ' | ' . get_blog_option( BP_ROOT_BLOG, 'blogname' )) . '</title>';
?>


<?php locate_template( array( 'leftsidebar.php' ), true ) ?>

    <div id="content">
    <?php if (!$_GET['view'] or $eventExist == null ) { ?>
        
        <div id="iron-encabezado-container">
            <h2 class="iron-encabezado-seccion"><?php echo __('Eventos','buddypress'); ?></h2>

            <ul class="iron-encabezado-ul">
                <?php if (xprofile_get_field_data('Privacidad', bp_loggedin_user_id()) != 'Privado') { ?>
                    <li class="iron-encabezado-li"><a class="fancybox-groups" href="<?php echo bp_get_root_domain() . '/eventos-create/' ?>"><?php _e( 'Crear Evento', 'buddypress' ) ?></a></li>
                <?php } ?>
                <li class="iron-encabezado-li">
                <?php
                    if (xprofile_get_field_data('Privacidad', bp_loggedin_user_id()) != 'Privado') { ?>
                <?php } ?>
                <li class="iron-encabezado-li">&middot;&nbsp;<a <?php if (bp_current_action() == 'my-events') echo 'class="selected"'; ?> href="<?php echo bp_loggedin_user_domain() . 'events/' ?>"><?php printf( __( 'Mis Eventos', 'buddypress' )  ) ?></a></li>
                <li class="iron-encabezado-li">&middot;&nbsp;<a <?php if (bp_current_action() == 'invites') echo 'class="selected"'; ?> href="<?php echo bp_loggedin_user_domain() . 'events/invites/' ?>"><?php _e( 'Invitaciones', 'buddypress' ) ?></a></li>
            </ul>
        </div>
        
        <div class="padder" id="jes-padder">
        
            <div id="content-top"></div>
        
            <div id="content-middle" style="padding: 10px;">
                <form action="" method="post" id="groups-directory-form" class="dir-form">
                    <?php do_action( 'bp_before_directory_events_content' ) ?>
                    <div id="group-dir-search" class="dir-search">
                    
                    <?php
                        bp_directory_events_search_form();
                    ?>
                    </div><!-- #event-dir-search -->
        
                    <div class="item-list-tabs">
                        
                        <ul>
                            <li class="selected" id="events-all">
                                <a href="<?php echo bp_get_root_domain() . '/eventos/' ?>">
                                    <?php printf( __( 'All Events (%s)', 'buddypress' ), bp_jes_get_jes_total_event_count() ) ?>
                                </a>
                            </li>
                            <?php
                            if ( is_user_logged_in() && bp_jes_get_jes_total_event_count_for_user( bp_loggedin_user_id() ) ) {
                            ?>
                                <li id="events-personal">
                                    <a href="<?php echo bp_loggedin_user_domain() . JES_SLUG . '/' ?>">
                                        <?php printf( __( 'My Events (%s)', 'buddypress' ), bp_jes_get_jes_total_event_count_for_user( bp_loggedin_user_id() ) ) ?>
                                    </a>
                                </li>
                            <?php
                            }
                            ?>
                            
                            <?php do_action( 'jes_bp_events_directory_event_types' ) ?>
                            
                            <li id="events-order-select" class="last filter">
                                <?php
                                    $sortby = $jes_adata[ 'jes_events_sort_by' ];
                                ?>
                                <?php _e( 'Order By:', 'buddypress' ) ?>
                                <select>
                                    <option <?php if ($sortby == 'soon' ) { ?>selected<?php } ?> value="soon"><?php _e( 'Upcoming', 'buddypress' ) ?></option>
                                    <option <?php if ($sortby == 'active' ) { ?>selected<?php } ?> value="active"><?php _e( 'Last Active', 'buddypress' ) ?></option>
                                    <option <?php if ($sortby == 'popular' ) { ?>selected<?php } ?> value="popular"><?php _e( 'Most Members', 'buddypress' ) ?></option>
                                    <option <?php if ($sortby == 'newest' ) { ?>selected<?php } ?> value="newest"><?php _e( 'Newly Created', 'buddypress' ) ?></option>
                                    <option <?php if ($sortby == 'alphabetical' ) { ?>selected<?php } ?> value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ) ?></option>
                                    <?php do_action( 'jes_bp_events_directory_order_options' ) ?>
                                </select>
                            </li>
                        </ul>
                    </div><!-- .item-list-tabs -->
                    
                    <div id="groups-dir-list" class="events dir-list">
                        <?php locate_template( array( 'events/events-loop.php' ), true ) ?>
                    </div><!-- #events-dir-list -->
                    
                    <?php do_action( 'bp_directory_events_content' ) ?>
                    
                    <?php wp_nonce_field( 'directory_events', '_wpnonce-events-filter' ) ?>
                    
                </form><!-- #events-directory-form -->
                
                <?php do_action( 'bp_after_directory_events_content' ) ?>
            </div><!-- content-middle -->
            
            <div id="content-bottom"></div>
            
        </div><!-- .padder -->
        
        <?php } else {
                $adminEvent = $wpdb->get_row("select user_id from wp_jet_events wje inner join wp_jet_events_members wjem on wje.id = wjem.event_id where wje.slug = '" . $_GET['view'] . "' and wjem.is_admin = '1' and wjem.user_id = '" . wp_get_current_user()->ID . "'");
                
                if ($_GET['Admin'] == 'details' and isset($adminEvent->user_id)) {
                    require_once(dirname(__FILE__) . '/events/custom/admin/details.php');
                } elseif ($_GET['Admin'] == 'avatar' and isset($adminEvent->user_id)) {
                    require_once(dirname(__FILE__) . '/events/custom/admin/avatar.php');
                } elseif ($_GET['Admin'] == 'members' and isset($adminEvent->user_id)) {
                    require_once(dirname(__FILE__) . '/events/custom/admin/members.php');
                } elseif ($_GET['Admin'] == 'sendInvites' and isset($adminEvent->user_id)) {
                    require_once(dirname(__FILE__) . '/events/custom/admin/invites.php');
                } elseif ($_GET['Admin'] == 'delete' and isset($adminEvent->user_id)) {
                    require_once(dirname(__FILE__) . '/events/custom/admin/delete.php');
                } else {
                    require_once(dirname(__FILE__) . '/events/custom/view/home.php');
                }
            } ?>
    </div><!-- #content -->
    <?php locate_template( array( 'sidebar.php' ), true ) ?>
<?php get_footer() ?>