<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"      prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"       prefix="fmt" %>
<%@ taglib uri="http://struts.apache.org/tags-html"     prefix="html" %>

<div class="LINKS">
<h2>Topic "${requestScope.Topic.name}"</h2>
<p>
<c:if test="${not empty requestScope.Topic.creator}">
	Angelegt von
	<c:choose>
		<c:when test="${requestScope.Topic.creator.username == sessionScope.User.username}">
			Ihnen selbst!
		</c:when>
		<c:otherwise>
			${requestScope.Topic.creator.firstname} ${requestScope.Topic.creator.lastname} (${requestScope.Topic.creator.username}).
		</c:otherwise>
	</c:choose>
	<br>
</c:if>
${requestScope.Topic.version}</p>
<p>
<c:choose>
	<c:when test="${requestScope.Topic.ratingsCount > 0}">
		<jsp:include page="/WEB-INF/content/rating.jsp">
			<jsp:param name="wert" value="${requestScope.Topic.averageRatingValue}"/>
			<jsp:param name="anzahl" value="${requestScope.Topic.ratingsCount}"/>
		</jsp:include>
	</c:when>
	<c:otherwise>
		Noch keine Bewertungen.
	</c:otherwise>
</c:choose>
<p>Synonyme:
<c:choose>
	<c:when test="${not empty requestScope.Synonyms}">
		<ul>
		<c:forEach items="${requestScope.Synonyms}" var="i">
			<li> <html:link action="topicview?id=${i.synonym.id}">${i.synonym.name}</html:link>
				<c:if test="${i.ratingsCount > 0}">
					<jsp:include page="/WEB-INF/content/rating.jsp">
						<jsp:param name="wert" value="${i.averageRatingValue}"/>
					</jsp:include>
				</c:if>
			</li>
		</c:forEach>
		</ul>
	</c:when>
	<c:otherwise>
		<br>Keine.
	</c:otherwise>
</c:choose>
</div>

<div class="FLOATMENU">
	<html:link action="newtopic?id=${requestScope.Topic.id}">Neue Instanz dieses Topics anlegen</html:link>
</div>
<br clear="right">
<div class="FLOATFORMULAR">
	<c:if test="${requestScope.Topic.version > requestScope.Rating.ratedVersion}">
		<span class="HINWEIS">Sie haben eine &auml;ltere Version dieses Topics bewertet. Bitte pr&uuml;fen Sie, ob Ihre Bewertung noch zutrifft.</span><br>
	</c:if>
	<html:form action="changetopicrating?id=${requestScope.Topic.id}">
		Ich stimme diesem Topic
		<html:radio property="topicrating" value="YES">zu</html:radio>
		<html:radio property="topicrating" value="NO">nicht zu</html:radio>
		<html:radio property="topicrating" value="NEUTRAL">keine Meinung</html:radio>
		&nbsp;&nbsp;<input type="submit" value="Bewerten">
		<br>Kommentar: <html:text property="ratingcomment" size="30"/>
		<c:if test="${not empty requestScope.Rating.comment}">
			<br>(Derzeitiger Kommentar: "${requestScope.Rating.comment}")
		</c:if>
	</html:form>
</div>
<br clear="right">
<div class="FLOATMENU">
	<html:link action="editsynonyms?id=${requestScope.Topic.id}">Synonym hinzuf&uuml;gen / bewerten</html:link>
</div>

<br clear="all">


<hr>


<div class="FLOATMENU">
<html:link action="edittopiccomment?id=${requestScope.Topic.id}">&Auml;ndern</html:link>
</div>

<h3>Beschreibung:</h3>

<c:choose>
	<c:when test="${not empty requestScope.Topic.comment}">
		${requestScope.Topic.comment}
		<p>
	</c:when>
	<c:otherwise>
		<p>Noch nicht vorhanden.
	</c:otherwise>
</c:choose>

<br clear="all"></p>


<hr>


<div class="FLOATMENU">
<html:link action="edittypes?id=${requestScope.Topic.id}">Typ hinzuf&uuml;gen / bewerten</html:link>
</div>

<h3>Typen dieses Topics:</h3>

<c:choose>
	<c:when test="${not empty requestScope.TopicTypes}">
		<ul>
		<c:forEach items="${requestScope.TopicTypes}" var="i">
			<li> <html:link action="topicview?id=${i.type.id}">${i.type.name}</html:link>
				<c:if test="${i.ratingsCount > 0}">
					<jsp:include page="/WEB-INF/content/rating.jsp">
						<jsp:param name="wert" value="${i.averageRatingValue}"/>
					</jsp:include>
				</c:if>
			</li>
		</c:forEach>
		</ul>
	</c:when>
	<c:otherwise>
		<p>Dieses Topic ist typenlos.
	</c:otherwise>
</c:choose>

<br clear="all"></p>


<hr>


<div class="FLOATMENU">
<html:link action="newattribute?id=${requestScope.Topic.id}">Attribut hinzuf&uuml;gen</html:link>
</div>

<h3>Attribute:</h3>

<c:choose>
	<c:when test="${not empty requestScope.Attributes}">
		<ul>
		<c:forEach items="${requestScope.Attributes}" var="a">
			<li>
				<html:link action="attributeview?id=${requestScope.Topic.id}&amp;attrid=${a.id}">"${a.name}" <c:if test="${not empty a.type}">(Typ: ${a.type.name})</c:if></html:link> = ${a.value}
				<c:if test="${a.ratingsCount > 0}">
					<jsp:include page="/WEB-INF/content/rating.jsp">
						<jsp:param name="wert" value="${a.averageRatingValue}"/>
					</jsp:include>
				</c:if>
			</li>
		</c:forEach>
		</ul>
		<p>
	</c:when>
	<c:otherwise>
		<p>Dieses Topic besitzt noch keine Attribute.
	</c:otherwise>
</c:choose>

<br clear="all"></p>


<hr>


<div class="FLOATMENU">
<html:link action="newassociation?id=${requestScope.Topic.id}">Neue Assoziation hinzuf&uuml;gen</html:link>
<c:if test="${not empty sessionScope.LastAssociation}">
<br><html:link action="associationjoin?id=${requestScope.Topic.id}">Assoziation "${sessionScope.LastAssociation.name}" beitreten</html:link>
</c:if>
</div>

<h3>Assoziationen, in denen dieses Topic eine Rolle spielt:</h3>

<c:choose>
	<c:when test="${not empty requestScope.TopicAssociations}">
		<ul>
		<c:forEach items="${requestScope.TopicAssociations}" var="ab">
			<li>
				<html:link action="associationview?id=${ab.association.id}">${ab.association.name}</html:link>
				<c:if test="${ab.association.ratingsCount > 0}">
					<jsp:include page="/WEB-INF/content/rating.jsp">
						<jsp:param name="wert" value="${ab.association.averageRatingValue}"/>
					</jsp:include>
				</c:if>
				
				<c:if test="${not empty ab.roleBeans}">
					<ul>
						<c:forEach items="${ab.roleBeans}" var="rb">
							<li> Rolle "${rb.role.name}"
								<c:if test="${not empty rb.topics}">
									<ul>
										<c:forEach items="${rb.topics}" var="t">
											<li>
												<c:choose>
													<c:when test="${requestScope.Topic == t}">
														dieses Topic
													</c:when>
													<c:otherwise>
														Topic "<html:link action="topicview?id=${t.id}">${t.name}</html:link>"
													</c:otherwise>
												</c:choose>
											</li>
										</c:forEach>
									</ul>
								</c:if>
							</li> 
						</c:forEach>
					</ul>
				</c:if>
			</li>
		</c:forEach>
		</ul>
		<p>
	</c:when>
	<c:otherwise>
		<p>Dieses Topic spielt in keiner Assoziation eine Rolle.
	</c:otherwise>
</c:choose>

<br clear="all"></p>


<hr>


<div class="FLOATMENU">
<html:link action="newtopic?id=${requestScope.Topic.id}">Neue Instanz dieses Topics anlegen</html:link>
</div>

<h3>Instanzen dieses Topics:</h3>

<c:choose>
	<c:when test="${not empty requestScope.TopicInstances}">
		<ul>
		<c:forEach items="${requestScope.TopicInstances}" var="i">
			<li> <html:link action="topicview?id=${i.instance.id}">${i.instance.name}</html:link>
				<c:if test="${i.ratingsCount > 0}">
					<jsp:include page="/WEB-INF/content/rating.jsp">
						<jsp:param name="wert" value="${i.averageRatingValue}"/>
					</jsp:include>
				</c:if>
			</li>
		</c:forEach>
		</ul>
		<p>
	</c:when>
	<c:otherwise>
		<p>Es existieren keine Instanzen dieses Topics.
	</c:otherwise>
</c:choose>

<br clear="all"></p>


<hr>


<div class="FLOATFORMULAR">
	<html:form action="createoccurrence?id=${requestScope.Topic.id}">
		<html:text property="occurrencedata" size="50"/>
		<input type="submit" value="Neu">
	</html:form>
</div>

<h3>Occurrences</h3>

<c:choose>
	<c:when test="${not empty requestScope.Occurrences}">
		<ul>
			<c:forEach items="${requestScope.Occurrences}" var="i">
				<li> "${i.data}" (<html:link action="deleteoccurrence?id=${requestScope.Topic.id}&amp;occid=${i.id}">l&ouml;schen</html:link>) </li>
			</c:forEach>
		</ul>
		<p>
	</c:when>
	<c:otherwise>
		<p>Dieses Topic hat noch keine Occurrences.
	</c:otherwise>
</c:choose>

<br clear="all"></p>


<c:if test="${not empty requestScope.AssociationsOfType}">
	<hr>

	<h3>Assoziationen dieses Typs:</h3>
	<ul>
		<c:forEach items="${requestScope.AssociationsOfType}" var="i">
			<li> <html:link action="associationview?id=${i.id}">${i.name}</html:link> </li>
		</c:forEach>
	</ul>
</c:if>


<c:if test="${requestScope.Topic.ratingsCount > 0}">
	<hr>
	
	<h3>Alle Bewertungen zu diesem Topic:</h3>

	<table border="1" cellpadding="2" cellspacing="2">
		<tr>
			<th>&nbsp;</th> <th>Benutzer</th> <th>Bewertung</th> <th>Version der Bewertung</th> <th>Kommentar</th>
		</tr>

		<c:forEach items="${requestScope.Topic.ratings}" var="rating" varStatus="nr">
			<tr>
				<td align="right"> ${nr.count} </td>
				<td>
					<c:choose>
						<c:when test="${rating.creator.username == sessionScope.User.username}">
							Sie selbst!
						</c:when>
						<c:otherwise>
							${rating.creator}
						</c:otherwise>
					</c:choose>
				</td>
				<td align="right"> <fmt:formatNumber value="${rating.value}" maxFractionDigits="2"/> </td>
				<td> ${rating.version} </td>
				<td> ${rating.comment} </td>
			</tr>
		</c:forEach>
	</table>
	<br>
</c:if>


<c:if test="${not empty requestScope.RatingHistory}">
	<hr>
	
	<h3>Ihre alten Bewertungen zu diesem Topic:</h3>

	<table border="1" cellpadding="2" cellspacing="2">
		<tr>
			<th>&nbsp;</th> <th>Bewertung</th> <th>Version der Bewertung</th> <th>Kommentar</th>
		</tr>

		<c:forEach items="${requestScope.RatingHistory}" var="rating" varStatus="nr">
			<tr>
				<td align="right"> ${nr.count} </td>
				<td align="right"> <fmt:formatNumber value="${rating.value}" maxFractionDigits="2"/> </td>
				<td> ${rating.version} </td>
				<td> ${rating.comment} </td>
			</tr>
		</c:forEach>
	</table>	
	<br>
</c:if>
