<?php
global $bp, $wpdb;

$eventData        = $wpdb->get_row('select * from wp_jet_events where slug = "' . $_GET['view'] . '"');
$eventMembers     = $wpdb->get_row('select * from wp_jet_events_members where event_id = "' . $eventData->id . '" and user_id ="' . wp_get_current_user()->ID . '"');
?>
<script type="text/javascript" src="wp-content/themes/cvp-irontec/events/custom/js/scripts.js"></script>
<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_loggedin_user_domain() . 'events/' ?>">
                <?php _e ( 'Mis eventos', 'buddypress' ) ; ?>
            </a>
        </li>
        <?php if ($eventMembers->is_admin == '1' ) { ?>
            <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>
        <?php } ?>
    </ul>
</div>

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

    <div id="content-middle">

        <?php 
        $avatar_folder_dir  =  BP_AVATAR_UPLOAD_PATH . '/event-avatars/' . $eventData->id . '/';
        if (file_exists($avatar_folder_dir)) {
            $av_dir = opendir( $avatar_folder_dir );
            
            while (($full = readdir($av_dir))) {
                if ($full == '..' or $full == '.' or substr_count($full, '-bpthumb') == '1') {
                    continue;
                } else {
                    $img = $full;
                }
            }
        }
        
        if ($img) {
            $srcEventAvatar = $bp->root_domain . '/wp-content/uploads/event-avatars/' . $eventData->id . '/' . $img;
        } else {
            $srcEventAvatar = $bp->root_domain . '/wp-content/themes/cvp-irontec/_inc/images/bp_default_avatar.jpg';
        }
        
        ?>
        <div id="content-middle-add">
        
            <div id="content-middle-add-left-event">
    
                        <div id="item-body">
    
                        <h2>
                            <a href="<?php echo $bp->root_domain ?>/eventos?view=<?php echo $eventData->slug; ?>" title="<?php echo $eventData->name; ?>">
                                <?php echo $eventData->name; ?>
                            </a>
                        </h2>
                        <p>
                            <?php _e($eventData->etype, 'buddypress')?>
                            <?php
                            $enddate = str_replace('/','-', $eventData->edted);
                            $enddate = new DateTime($enddate);
                            
                            $stm = date_timestamp_get($enddate);
                            $stm2 = $stm + 86400; // Sumamos 1 dia en segundos
                            
                            if ($stm2 > time()) {
                                echo '&middot;&nbsp;<span class="active-event">'. __ ('evento activo', 'buddypress') .'</span>';
                            } else {
                                echo '&middot;&nbsp;<span class="past-event">'. __ ('evento pasado', 'buddypress') .'</span>';
                            } ?>
                        </p>
                        
                        <div class="clear">&nbsp;</div>
                        
                        <p>
                            <strong>
                                <?php _e('Cu&aacute;ndo','buddypress'); ?>
                            </strong>
                        </p>
                        
                        <p>
                            <strong>
                                <?php _e('Inicio', 'buddypress') ?>:
                            </strong>
                                <?php echo $eventData->edtsd; ?>,
                                <strong>
                                    <?php _e('a las:','buddypress') ?>
                                </strong>
                                    <?php echo $eventData->edtsth; ?>:<?php echo $eventData->edtstm; ?>
                            <br />
                            
                            <strong>
                                <?php _e('Fin', 'buddypress') ?>:
                            </strong>
                                <?php echo $eventData->edted; ?>,
                                <strong>
                                    <?php _e('a las:','buddypress') ?>
                                </strong>
                                    <?php echo $eventData->edteth; ?>:<?php echo $eventData->edtetm; ?>
                        </p>
                        
                        <div class="clear">&nbsp;</div>
    
                        <?php
                        if ( $eventData->placedaddress ) { ?>
                                <p>
                                    <strong>
                                        <?php _e('D&oacute;nde','buddypress'); ?>
                                    </strong>
                                </p>
                                <?php echo $eventData->placedaddress; ?>
                                <div class="clear">&nbsp;</div>
                        <?php }
                        if ( $eventData->placednote) { ?>
                                <p>
                                    <strong>
                                        <?php _e('Sitio Web','buddypress'); ?>
                                    </strong>
                                </p>
                                <?php if ( $eventData->placednote ) {
                                        if (strstr($eventData->placednote, 'http://'))
                                                $eventlink = $eventData->placednote;
                                        else
                                                $eventlink = 'http://' . $eventData->placednote;
                        
                                        echo '<a href="'. $eventlink . '" target="_blank">'. $eventData->placednote .'</a>';
                                } ?>
                                <div class="clear">&nbsp;</div>
                        <?php } ?>
                        
                        </div><!-- #item-body -->
                        
                    </div><!-- content-middle-add-left -->
        
                    <div id="content-middle-add-right-event">
                    
                        <div id="item-header">
    
                            <div id="item-header-avatar" style="height: 154px; width: 135px;">
                                <a href="<?php echo $bp->root_domain ?>/eventos?view=<?php echo $eventData->slug; ?>" title="<?php echo $eventData->name; ?>">
                                    <img src="<?php echo $srcEventAvatar ?>" alt="Event avatar" class="avatar event-126-avatar" width="100" height="100">
                                </a>
                            </div><!-- #item-header-avatar -->
        
                            <div class="generic-button event-button public" id="eventbutton-<?php echo $eventData->id; ?>">
                                <?php
                                echo '<div class="custom-event-list-generic generic-button event-button ' . $event->status . '" id="eventbutton-' . $eventData->id . '" alt="user-' . wp_get_current_user()->ID . '">';
                                
                                if (!jes_bp_event_is_admin_custom($eventData->id, wp_get_current_user()->ID)) {
                                    echo '<div class="participacion-status">';
                                            if ( $eventMembers == true ) {
                                                echo '<a class="leave-event" href="' . $bp->root_domain . '/eventos?view=' . $eventData->slug . '" id="user-' . wp_get_current_user()->ID . '" attr="event-' . $eventData->id . '">
                                                    ' . __( 'Leave Event', 'buddypress' ) . '
                                                </a>';
                                                
                                                echo '<a class="join-event" style="display: none;" href="' . $bp->root_domain . '/eventos?view=' . $eventData->slug . '" id="user-' . wp_get_current_user()->ID . '" attr="event-' . $eventData->id . '">
                                                    ' . __( 'Join Event', 'buddypress' ) . '
                                                </a>';
                                                
                                            } else {
                                                echo '<a class="join-event" href="' . $bp->root_domain . '/eventos?view=' . $eventData->slug . '" id="user-' . wp_get_current_user()->ID . '" attr="event-' . $eventData->id . '">
                                                    ' . __( 'Join Event', 'buddypress' ) . '
                                                </a>';
                                                
                                                echo '<a class="leave-event" style="display: none;" href="' . $bp->root_domain . '/eventos?view=' . $eventData->slug . '" id="user-' . wp_get_current_user()->ID . '" attr="event-' . $eventData->id . '">
                                                    ' . __( 'Leave Event', 'buddypress' ) . '
                                                </a>';
                                            }
                                    echo '</div>';
                                }
                                echo '</div>';
                                ?>
                            </div>
                            
                        </div><!-- #item-header -->
    
                    </div><!-- content-middle-add-right -->
                    
                    
                    <div style=" float: left; display: block; width: 100%; margin-left: 10px;">
                    
                    <p>
                            <strong>
                                <?php _e('Descripci&oacute;n','buddypress'); ?>
                            </strong>
                        </p>
                        <?php
                        /*$texto = trim($eventData->description);
                        $end   = strlen($eventData->description);
                        $cantidadCaracteres = 170;
                        
                        if ($end >= $cantidadCaracteres) {
    
                            $text_ini = substr($texto,0,strrpos(substr($texto,0,$cantidadCaracteres)," "));
                            $text_fin = substr($texto,166,$end);
                            ?>
                            <div id="description">
                                <div class="more-less">
                                    <div class="more-block" style="white-space: pre; width: 310px; text-align: left;"><?php echo trim($text_ini . $text_fin); ?></div>
                                </div>
                            </div>
                        <?php
                        }else {
*/
                            echo '<div style="width: 100%; text-align: left;">' . nl2br($eventData->description) . '</div>';
                        //}
                        ?>
                        
                        <div class="clear">&nbsp;</div>
                    
                        <p>
                            <strong>
                                <?php _e('Miembros','buddypress'); ?>
                            </strong>
                        </p>
                        
                        <?php if ( bp_event_jes_has_members( 'per_page=15&exclude_banned=false', $eventData->id ) ) { ?>
                            <div class="iron-group-member-list">
                                <div class="iron-group-list-padder">
                                        <ul id="members-list" class="item-list">
                                        <?php while ( bp_event_members() ) : bp_event_the_member(); ?>
                                
                                        <?php
                                        // Los usuarios privados no se muestran en el listado de miembros
                                        if (xprofile_get_field_data('Privacidad',bp_get_event_member_id()) == 'Privado' ) continue;
                                        ?>
                                
                                        <li>
                                        <a href="<?php bp_group_member_domain() ?>" title="<?php bp_group_member_name(); ?>"><?php bp_group_member_avatar_mini('32','32') ?></a>
                                        </li>
                                
                                        <?php endwhile; ?>
                                        </ul>
                                </div>
                            </div>
                        <?php } else { ?>
                                <?php _e('No hay miembros en este evento.', 'buddypress'); ?>
                        <?php } ?>
    
                        <div class="clear">&nbsp;</div>
                    </div>

                
<style>
.av01 {
    background: url('<?php echo get_option('home'); ?>/wp-content/themes/cvp-irontec/_inc/images/01/bg_status_50.png') no-repeat scroll 1px 60px transparent;
    display: block;
    float: left;
    height: 75px;
    width: 53px;
}
.av02 {
    background: url('<?php echo get_option('home'); ?>/wp-content/themes/cvp-irontec/_inc/images/02/bg_status_50.png') no-repeat scroll 1px 60px transparent;
    display: block;
    float: left;
    height: 75px;
    width: 53px;
}
.av03 {
    background: url('<?php echo get_option('home'); ?>/wp-content/themes/cvp-irontec/_inc/images/03/bg_status_50.png') no-repeat scroll 1px 60px transparent;
    display: block;
    float: left;
    height: 75px;
    width: 53px;
}
.av04 {
    background: url('<?php echo get_option('home'); ?>/wp-content/themes/cvp-irontec/_inc/images/04/bg_status_50.png') no-repeat scroll 1px 60px transparent;
    display: block;
    float: left;
    height: 75px;
    width: 53px;
}
</style>

                <div class="clear">&nbsp;</div>
                <?php
                if ($eventMembers) {
                    require_once(dirname(__FILE__) . '/comment.php' );
                }
                ?>
                </div>
    
    </div><!-- #content-middle -->
    
    <div id="content-bottom"></div>
    
</div><!-- .padder -->

<script>
var $ = jQuery;
$(document).ready( function() {
	var adjustheight = 80;
	var moreText = "+ <?php _e('more', 'buddypress')?>";
	var lessText = "- <?php _e('less', 'buddypress')?>";

	$(".more-less .more-block").css('height', adjustheight).css('overflow', 'hidden');

	$(".more-less").append('<p class="continued">[&hellip;]</p><a href="#" class="adjust"></a>');

	$("a.adjust").text(moreText);

	$(".adjust").toggle(function() {
			$(this).parents("div:first").find(".more-block").css('height', 'auto').css('overflow', 'visible');
			$(this).parents("div:first").find("p.continued").css('display', 'none');
			$(this).text(lessText);
		}, function() {
			$(this).parents("div:first").find(".more-block").css('height', adjustheight).css('overflow', 'hidden');
			$(this).parents("div:first").find("p.continued").css('display', 'block');
			$(this).text(moreText);
	});
});
</script>