<?PHP  

if(is_logged_in($user)){
$tagtext = "I'm going here";
$actionlink = "individual.php?roadshow_id=$row[roadshow_id]&".get_sid();
}else{
$tagtext = "Log in to tag roadshow event";
$actionlink = "http://forum.slowtwitch.com/gforum.cgi?do=login&from=roadshow";
$tagstatus = "no";
}

if(is_logged_in($user)){
//Get user's uid
//$testresults = mysql_query("SELECT user_id FROM ".$prefix."User WHERE user_username=\"$username\"") or die(mysql_error());
//$testrow = mysql_fetch_array($testresults);
//$useruid = $testrow[user_id];
$useruid = base64_decode($_SESSION['user_id']);

// is the current user the owner of the open water event?
$roadshow_submitted_by = FALSE;
if($useruid == $row[roadshow_submitted_by]){
  $roadshow_submitted_by = TRUE;
}

$tagresults = mysql_query("SELECT roadshow_user_tags FROM ".$prefix."Roadshow WHERE roadshow_id=$row[roadshow_id]");
$tagrow = mysql_fetch_array($tagresults);
$tags = explode(",", $tagrow[roadshow_user_tags]);

$profileresults = mysql_query("SELECT user_roadshowtags FROM ".$prefix."User WHERE user_id='$useruid'") or die(mysql_error());
$profilerow = mysql_fetch_array($profileresults);
$profiletags = explode(",", $profilerow[user_roadshowtags]);

if($_POST[status] == "tag"){
//tag the open water event
if(array_search($useruid, $tags) == FALSE){
array_push($tags, $useruid);
}
$tags = implode(",", $tags);
mysql_query("UPDATE ".$prefix."Roadshow SET roadshow_user_tags='$tags' WHERE roadshow_id=$row[roadshow_id]") or die(mysql_error());
$tags = explode(",", $tags);

if(array_search($row[roadshow_id], $profiletags) == FALSE){
array_push($profiletags, $row[roadshow_id]);
}
$profiletags = implode(",", $profiletags);
mysql_query("UPDATE ".$prefix."User SET user_roadshowtags='$profiletags' WHERE user_id='$useruid'") or die(mysql_error());
}else if($_POST[status] == "untag"){
//untag the open water event
$key = array_search($useruid, $tags);
unset($tags[$key]);
$tags = implode(",", $tags);
mysql_query("UPDATE ".$prefix."Roadshow SET roadshow_user_tags='$tags' WHERE roadshow_id=$row[roadshow_id]") or die(mysql_error()); 
$tags = explode(",", $tags);

$key = array_search($row[roadshow_id], $profiletags);
unset($profiletags[$key]);
$profiletags = implode(",", $profiletags);
mysql_query("UPDATE ".$prefix."User SET user_roadshowtags='$profiletags' WHERE user_id=$useruid");
}

//Is the open water event tagged already?
if(array_search($useruid, $tags) !== FALSE){ $swimshere = TRUE; }else{ $swimshere = FALSE; }

if($swimshere){ $tagstatus = "untag"; $tagtext = "Untag this";}else{ $tagstatus = "tag"; $tagtext = "I'm going here";}
}
?>

<div>
<form action="<? echo $actionlink; ?>" method="post" style="display: inline;">
    <input type="hidden" value="<? echo $tagstatus; ?>" name="status" class="btn"/>
    <input type="submit" value="<? echo $tagtext; ?>" class="nobutton btn" />
</form>
<form method="post" action="<? echo "individual.php?roadshow_id=$row[roadshow_id]#goinghere"; ?>" style="display: inline;">
    <input type="submit" value="Who's going here?" class="nobutton btn" />
</form>
<? /**<form method="post" action="<? echo "individual.php?roadshow_id=$row[roadshow_id]#rate"; ?>" style="display: inline;">
<input type="submit" value="Rate this open water event" class="nobutton" />
</form> **/?>
<? if(is_logged_in($user)){ ?>
	<form method="post" action="<? echo "individual.php?roadshow_id=$row[roadshow_id]#comment"; ?>" style="display: inline;">
	<input type="submit" value="Add a comment" class="nobutton btn" />
	</form>
	
	<form method="post" action="<? echo "wiki_edit.php?roadshow_id=$row[roadshow_id]"; ?>" style="display: inline;">
	<input type="submit" value="Wiki-edit this" class="nobutton btn" />
	</form>

<? if (is_admin($user)) { ?>

<form method="post" action="delete_X.php" style="display: inline;">
    <input type="hidden" name="roadshow_id" value="<? echo($row[roadshow_id]); ?>" class="btn" />
    <input type="submit" value="DELETE" class="nobutton btn" onclick="return confirm('Are you sure you want to DELETE this open water event?');" />
</form>

<?

//Get user's username
$testresults = mysql_query("SELECT user_username FROM ".$prefix."User WHERE user_id='$row[roadshow_submitted_by]'") or die(mysql_error());
$testrow = mysql_fetch_array($testresults);
$username = $testrow[user_username];
//echo("<br /><br /><strong>Entered By: </strong> <a href='http://forum.slowtwitch.com/gforum.cgi?username=$username;'>$username</a>");  
  }
}
?>
</div>
