<?php
global $current_user;

get_currentuserinfo();
$home = home_url();
?>
<style>
.av01 {
    background: url('<?php echo $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 $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 $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 $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(isset($_GET["action"]) && $_GET["action"]=="deletecomment"){



	$wpdb->get_row('delete from '.$wpdb->prefix.'comments where comment_ID="'.$_GET["id"].'"');

}

if(isset($_POST["comment_post_ID"]) && $_POST["comment"] != ""){

$wpdb->get_row("insert into ".$wpdb->prefix."comments 
		(comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_date,comment_content,user_id)
	values
		('".$_POST["comment_post_ID"]."000','".$current_user->display_name."','".$current_user->user_email."','".home_url().'/members/'.$current_user->user_login."','".date('Y-m-j H:i:s')."','".$_POST["comment"]."','".$current_user->ID."')");

}

$event_id = $wpdb->get_row('select *from '.$wpdb->prefix.'jet_events where id="'.bp_get_event_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 $event_id->id?>">
<span class="comments_Num_Comments">

<?php 

$Num_Comments = count($comment_event);
if($Num_Comments == null){
echo '<a title="' . __( 'events','buddypress' ) . '" style="font-size: 11px;" href="'.$home.'/events/'.$event_id->slug.'/#comment">' . _e( 'No Comment &raquo;', 'buddypress' ) . '</a>';
}
if($Num_Comments == '1'){
echo '<a title="' . __( 'events','buddypress' ) . '" style="font-size: 11px;" href="'.$home.'/events/'.$event_id->slug.'/#comment">' . _e( '1 Comment &raquo;', 'buddypress' ) . '</a>';
}
if($Num_Comments > '1'){
echo '<a title="' . __( 'events','buddypress' ) . '" style="font-size: 11px;" href="'.$home.'/events/'.$event_id->slug.'/#comment">' . $Num_Comments . ' ' . _e( 'Comments &raquo;', 'buddypress' ) . '</a>';
}

?></span>
</p>
<div class="clear">&nbsp;</div>
<?php
foreach($comment_event as $comment_list)
{

echo '<div class="author-box ' . calculate_moodbar($comment_list->user_id) . '"><a href="'.$comment_list->comment_author_url.'">'.get_avatar( $comment_list->user_id, 50 ).'</a></div>';

echo '<div class="comments_event">';
echo '<a href="'.$comment_list->comment_author_url.'">'.$comment_list->comment_author.'</a> ' .__('said:','buddypress');
echo '<span class="span_date_comment">'.$comment_list->comment_date.'</span>';
echo '<div class="comment-options"></div>';
echo '<p>'.($comment_list->comment_content).'</p>';
echo '<div class="comment-options" style="margin-bottom:0;"></div>';
if($comment_list->user_id==$current_user->ID){

?>

<a onclick="if(!confirm('<?php _e('Delete Comment?','buddypress')?>')) {return false;}" href="<?php echo home_url().'/events/'.$event_id->slug ?>/?action=deletecomment&amp;id=<?php echo $comment_list->comment_ID?>"><?php _e('Delete' , 'buddypress')?></a>
<?php

}
echo '</div>';

}

?>

<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>';


echo $class;
?>
<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 $event_id->id;?>" name="comment_post_ID">
	</p>

</form>
</div>
