<?php
global $current_user;

get_currentuserinfo();
$home = home_url() . '/wp-content/themes/cvp-irontec/_inc/images/';
?>
<style>
.av01 {
    background: url('<?php echo $home ?>01/bg_status_50.png') no-repeat scroll 1px 60px transparent;
}
.av02 {
    background: url('<?php echo $home ?>02/bg_status_50.png') no-repeat scroll 1px 60px transparent;
}
.av03 {
    background: url('<?php echo $home ?>03/bg_status_50.png') no-repeat scroll 1px 60px transparent;
}
.av04 {
    background: url('<?php echo $home ?>04/bg_status_50.png') no-repeat scroll 1px 60px transparent;
}

.av01, .av02, .av03, .av04 {
    display: block;
    float: left;
    height: 75px;
    width: 53px;
}

.loading-ajax-comments {
    background-image: url("<?php echo $home ?>loading.gif");
    background-position: 102% 50%;
    background-repeat: no-repeat;
    display: block;
    float: left;
    clear: both;
}
</style>

    <div class="clear">&nbsp;</div>

    <?php
    if (isset($_POST["comment_post_ID"]) && $_POST["comment"] != "") {
        
        
        $table = $wpdb->prefix. 'comments';
        
        $data = array(
                        'comment_post_ID'      => $_POST["comment_post_ID"] . "000",
                        'comment_author'       => $current_user->display_name,
                        'comment_author_email' => $current_user->user_email,
                        'comment_author_url'   => home_url() . '/members/' . $current_user->user_login,
                        'comment_date'         => date('Y-m-j H:i:s'),
                        'comment_content'      => $_POST["comment"],
                        'user_id'              => $current_user->ID
                      );
        
        $wpdb->insert( $table, $data);
    
    }
    
    $event_id = $wpdb->get_row('select *from '.$wpdb->prefix.'jet_events where id="'. $eventData->id .'"');
    
    if (empty($event_id->id)) {
        $comment_event = array();
    } else {
        $comment_event = $wpdb->get_results('select *from '.$wpdb->prefix.'comments where comment_post_ID="'.$event_id->id.'000" ORDER BY     comment_date ASC');
    }
    ?>
    
    <p class="postmetadata" data-title="<?php echo jes_bp_get_event_name()?>" data-eventid="<?php echo $eventData->id ?>">
        <span class="comments_Num_Comments">
            <?php 
            $Num_Comments = count($comment_event);
            if ($Num_Comments == null) {
                echo __( 'No Comment &raquo;', 'buddypress' );
            }
            if ($Num_Comments == '1') {
                echo __( '1 Comment &raquo;', 'buddypress' );
            }
            if ($Num_Comments > '1') {
                echo ' ' . $Num_Comments . ' ' . _e( 'Comments &raquo;', 'buddypress' );
            }
            ?>
        </span>
    </p>
    
    <div class="clear">&nbsp;</div>
    
    <?php
    foreach ($comment_event as $comment_list) {
    ?>
        <div id="comment-event-<?php echo $comment_list->comment_ID; ?>">
            <div class="author-box <?php echo calculate_moodbar($comment_list->user_id); ?>">
                <a href="<?php echo $comment_list->comment_author_url; ?>">
                    <?php echo get_avatar( $comment_list->user_id, 50 ); ?>
                </a>
            </div>
            
            <div class="comments_event">
                <a href="<?php echo get_option('home') . '/miembros/' . get_userdata($comment_list->user_id)->user_login; ?>">
                    <?php echo $comment_list->comment_author; ?>
                </a>
                <?php _e('said:','buddypress'); ?>
                
                <span class="span_date_comment">
                    <?php echo $comment_list->comment_date; ?>
                </span>
                
                <div class="comment-options"></div>
                
                <p>
                    <?php
                    echo nl2br(contenidoMuroCompleto($comment_list->comment_content));
                    ?>
                </p>
                
                <div class="comment-options" style="margin-bottom:0;"></div>
                
                <?php
                $adminsEvent = $wpdb->get_row('select * from wp_jet_events_members where event_id = "'. $eventData->id .'" and user_id = "' . wp_get_current_user()->ID . '" and is_admin = "1"');

                if ( $comment_list->user_id == $current_user->ID or $adminsEvent == true) {
                ?>
                    <span id="comments-event-delete" class="comment-delete-<?php echo $comment_list->comment_ID; ?>" style=" float: right; cursor: pointer;" >
                        <?php _e('Delete', 'buddypress'); ?>
                    </span>
                <?php
            }
            ?>
            </div><!-- .comments_event -->
        </div><!-- #comment-event -->
        
    <?php
    } ?>
    <div class="clear">&nbsp;</div>
    <?php
    echo '<div class="author-box ' . calculate_moodbar(get_current_user_id()) . '">' . get_avatar( bp_loggedin_user_id(), 50 ) . '</div>';
    ?>
    
    <div class="comment-content">
        <form class="standard-form" id="commentform" method="post" action="">

            <h3 style=" color: #555555; font-size: 20px; font-weight: normal; margin: 5px 0 10px;">
                <?php _e( 'Leave a Reply', 'buddypress' ); ?>
            </h3>
            
            <p class="form-textarea">
                <textarea tabindex="4" rows="10" cols="60" id="comment" name="comment"></textarea>
            </p>
                
            <p class="form-submit">
                <input type="submit" value="<?php _e('Submit' , 'buddypress')?>" tabindex="5" id="submit" name="submit" class="submit-comment button">
                <input type="hidden" id="comment_post_ID" value="<?php echo $eventData->id;?>" name="comment_post_ID">
            </p>
        </form>
    </div>