<?php
global $bp, $wpdb;

$idEventCreate = $wpdb->get_row('select * from wp_jet_events where  slug = "' . $_GET['view'] . '"');

?>
<script type="text/javascript" src="wp-content/themes/cvp-irontec/events/custom/js/scripts.js"></script>
<style>
li.iron-encabezado-li a.selected {
    background: whiteSmoke;
    color: #444;
    padding: 5px 7px;
}

li.iron-encabezado-li a:HOVER {
    text-decoration: none;
}
</style>
<div id="iron-encabezado-container">
    <h2 class="iron-encabezado-seccion"><?php echo __('Eventos','buddypress'); ?></h2>

    <ul class="iron-encabezado-ul">
        <li class="iron-encabezado-li">
            <a href="<?php bp_root_domain() ?>/eventos/">
                <?php _e ( 'Todos', 'buddypress' ); ?>
            </a>
        </li>
        </li>
        <li class="iron-encabezado-li">&middot;&nbsp;
            <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view']; ?>">
                <?php _e ( 'Volver al evento', 'buddypress' ) ; ?>
            </a>
        </li>
        <li class="iron-encabezado-li">&middot;&nbsp;
            <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] . '&Admin=details'; ?>">
                <?php _e ( 'Administración', 'buddypress' ) ; ?>
            </a>
        </li>
    </ul>
</div>

<script type="text/javascript">
var $ = jQuery;
$(document).ready( function() {
    $('#messages-seleted').click(function(){
        
        var Lis = $('#invite-list li').length;
        var CountList = 0;
        
        for ( x=0; x<Lis;) {
            if ($('#invite-list li p.invite').eq(x).length != 0) {
                $('#invite-list li p.invite').eq(x).click();
            }
            x++;
        }
    });
    
});
</script>

<div class="padder" id="jes-padder">
    
    <div id="content-top"></div>

    <div id="content-middle">
    
    <div id="content-middle-add">

        <div id="item-body">

        <div id="iron-encabezado-container-sub">
            <ul class="iron-encabezado-ul">
                <li class="iron-encabezado-li">
                    <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=details' ?>">
                        <?php _e('Editar', 'buddypress'); ?>
                    </a>
                </li>
                <li class="iron-encabezado-li">&nbsp;
                    <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=avatar' ?>">
                        <?php _e('Avatar', 'buddypress'); ?>
                    </a>
                </li>
                <li class="iron-encabezado-li">&nbsp;
                    <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=members' ?>">
                            <?php _e('Miembros', 'buddypress'); ?>
                    </a>
                </li>
                <li class="iron-encabezado-li">&nbsp;
                    <a class="selected" href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=sendInvites' ?>">
                        <?php _e('Enviar invitaciones', 'buddypress'); ?>
                    </a>
                </li>
                <li class="iron-encabezado-li">&nbsp;
                    <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=delete' ?>">
                        <?php _e('Delete', 'buddypress'); ?>
                    </a>
                </li>
            </ul>
        </div>
        
        <div class="left-menu" style="width: 315px;">
            <div id="invite-list" style="width: 300px;">
                <ul class="event-<?php echo $idEventCreate->id; ?>">
                    <?php
                    foreach (friends_get_friend_user_ids(wp_get_current_user()->ID) as $id_friend) {
                        
                        $sendInvitacionNot = $wpdb->get_row('select * from wp_bp_notifications where user_id = "' . get_userdata($id_friend)->ID . '" and item_id = "' . $idEventCreate->id . '" and component_name = "jes_events" and component_action ="jes_event_invite"');
                        
                        $sendInvitacionTab = $wpdb->get_row('select * from wp_jet_events_members where user_id = "' . get_userdata($id_friend)->ID . '" and event_id = "' . $idEventCreate->id . '" and is_confirmed = "0"');
                        
                        $memberGroup    = $wpdb->get_row('select * from wp_jet_events_members where user_id = "' . get_userdata($id_friend)->ID . '" and event_id = "' . $idEventCreate->id . '" and is_confirmed = "1"');
                        
                        //var_dump(!$sendInvitacionTab);
                        
                        if ($memberGroup) {
                            echo '<li id="send-invite" class="member-'.get_userdata($id_friend)->ID.'">' .
                            jes_get_member_avatar('id='.get_userdata($id_friend)->ID.'&alt='.get_userdata($id_friend)->display_name.'&height=40&width=40') .
                            get_userdata($id_friend)->display_name . '<span class="is-member">' . __('Es Miembro', 'buddypress') . '</span>' .
                            '</li>';
                        } elseif (!$sendInvitacionNot or !$sendInvitacionTab) {
                            echo '<li id="send-invite" class="friend-'.get_userdata($id_friend)->ID.'">' . 
                            jes_get_member_avatar('id='.get_userdata($id_friend)->ID.'&alt='.get_userdata($id_friend)->display_name.'&height=40&width=40') .
                            get_userdata($id_friend)->display_name . '<p class="invite" id="invite-'.get_userdata($id_friend)->ID.'">' . __('Enviar Invitación', 'buddypress') . '</p>' . '<p class="send-invite" style="display: none; color: green;">' . __('Invitación Enviada', 'buddypress') . '</p>' .
                            '</li>';
                        } elseif ($sendInvitacionNot and !$memberGroup)  {
                            echo '<li id="send-invite" class="friend-'.get_userdata($id_friend)->ID.'">' .
                            jes_get_member_avatar('id='.get_userdata($id_friend)->ID.'&alt='.get_userdata($id_friend)->display_name.'&height=40&width=40') .
                            get_userdata($id_friend)->display_name . '<span class="send-invite" style="color: green;">' . __('Invitación Enviada', 'buddypress') . '</span>' . 
                            '</li>';
                        }
                    }
                    ?>
                </ul>
            </div>
            
            <p id="messages-seleted">
                <?php _e('Invitar a todos mis amigos', 'buddypress'); ?>
            </p>
        </div><!-- .left-menu -->

        <div class="main-column" style="margin-left: 266px;">
            <div id="message" class="info">
                <p><?php _e('Select people to invite from your friends list.', 'buddypress'); ?></p>
            </div>
        </div><!-- .main-column -->
        
        </div><!-- #item-body -->
            
        </div>
    
    </div><!-- #content-middle -->
    
    <div id="content-bottom"></div>
    
</div><!-- .padder -->
    
