<%@page import="java.util.Collection"%>
<%@page import="java.util.Collections"%>
<%@page import="com.gridnine.xtrip.server.gds.sabre.session.pool.SabreSessionPoolInfo"%>
<%@page import="java.text.SimpleDateFormat"%>
<% SimpleDateFormat dformat = new SimpleDateFormat("HH:mm:ss dd.MM"); %>
<html>
<head>
	<script>
		function toggle(name) {
			var el = document.getElementById(name);
			el.style.display = (el.style.display == 'none') ? '' : 'none';
		}
	</script>
</head>
<body>
	<style type="text/css">

		table {
			border-collapse: collapse;
		}

		table td {
			border: 1px solid gray;
			padding: 5px; }

		table th {
			background: #ddd;
			border: 1px solid gray;
		}

	</style>

	<h1>Get Sabre Sessions By IPCC and PCC</h1>

	<div>
		<form>
			<span>Type in IPCC and PCC</span><br><br>
			<input name="ipcc" type="text" value="<%= request.getAttribute("ipcc") %>" /><br><br>
			<input name="pcc" type="text" value="<%= request.getAttribute("pcc") %>" />
			<input type="hidden" name="command" value="sessions-search" />
			<br><br>
			<button type="submit">Search</button>
		</form>
	</div>

    <% final Collection<SabreSessionPoolInfo> sessions = (Collection<SabreSessionPoolInfo>) request.getAttribute("models"); %>

      <h1>IPCC "<%= request.getParameter("ipcc") %>" and PCC "<%= request.getParameter("pcc") %>" found <%= sessions.size() %> sessions</h1>

        <table>
            <tr>
                <th>IPCC</th>
                <th>PCC</th>
                <th>Created</th>
                <th>Expired after</th>
                <th>ConversationId</th>
                <th>Held</th>
                <th>Acquired</th>
                <th>Uid</th>
                <th>Action</th>
                <th>Action</th>
            </tr>

            <% for (SabreSessionPoolInfo sabreSession : sessions) { %>

                <tr>
                    <td><%= sabreSession.getSession().getIpcc() %></td>
                    <td><%= sabreSession.getSession().getPcc() %></td>
                    <td><%= dformat.format(sabreSession.getSession().getCreated()) %></td>
                    <td><%= dformat.format(sabreSession.getInfo().getExpiredAfter()) %></td>
                    <td><%= sabreSession.getSession().getConversationId() %></td>
                    <td><%= !sabreSession.getSession().isUnheld() %></td>
                    <td><%= sabreSession.getInfo().isAcquired() %></td>
                    <td><%= sabreSession.getSession().getUid() %></td>
                    <td>
                        <form method="post">
                            <input type="hidden" name="ipcc" value="<%= request.getAttribute("ipcc") %>" />
                            <input type="hidden" name="pcc" value="<%= request.getAttribute("pcc") %>" />
                            <input name="session.uid" type="hidden" value="<%= sabreSession.getSession().getUid() %>" />
                            <input type="hidden" name="command" value="release-session" />
                            <button type="submit">Release session</button></td>
                        </form>
                    </td>
                    <td>
                        <form method="post">
                            <input type="hidden" name="ipcc" value="<%= request.getAttribute("ipcc") %>" />
                            <input type="hidden" name="pcc" value="<%= request.getAttribute("pcc") %>" />
                            <input name="session.uid" type="hidden" value="<%= sabreSession.getSession().getUid() %>" />
                            <input type="hidden" name="command" value="remove-session" />
                            <button type="submit">Remove session</button></td>
                        </form>
                    </td>
                </tr>
           <% } %>

        </table>

        <p>
         release session - move acquired session back to the pool</p>
        <p>
         remove session - removes session from pool with no gds call! </p>
</body>
</html>

