<%@page import="java.util.*" %>
<%@page import="java.net.*" %>
<%@page import="org.jini.rio.entry.ApplianceInfo" %>
<%@page import="edu.columbia.print.ninja.core.event.PrintQueueEvent" %>
<% 
Entry[] entries = serviceBean.serviceItem.attributeSets;
ApplianceInfo info = null;
for(int i=entries.length-1; i>=0; i--) {
	if(entries[i] instanceof ApplianceInfo) info = (ApplianceInfo )entries[i];
}
%>
<% if(request.getParameter("debug")!=null) {
	for(int i=entries.length-1; i>=0; i--) {
		%>
<%=entries[i]%><br>
<% }} %>

<br>
<a name="button">
<%
	String[][] buttons = {
		{"status all", "Status", "quick status of all print queues"},
		{"lpq private", "Printer Queue", "view possible problems with the printer or stuck jobs"},
		{"lpq private -L", "Verbose Printer Queue", "view possible problems with the printer or stuck jobs"},
		{"redo private", "Reprint Last", "Reprint the last job that was sent to the printer"},
		{"lprm private all", "Remove Jobs", "Remove All jobs destined for the printer"},
	};
	for(int i=0; i<buttons.length; i++) {
		%><a
		href="<c:out value='${alias}'/>/selector.jsp?view=monitor&action=lpc_button&cmd=<%=URLEncoder.encode(buttons[i][0], "UTF-8")%>"
		title="<%=buttons[i][2]%>">
		<%=buttons[i][1]%></a><br><%
	}
%>
<textarea cols="60" rows="8" readonly>
<% if("lpc_button".equals(request.getParameter("action"))) {
    ninja.setMethodName("control");
    ninja.setMethodParamClasses("java.lang.String");
    ninja.setMethodParams(new Object[] {request.getParameter("cmd")});
    out.println(ninja.getMethodResult());
} %>
</textarea>
<hr>
<table width=90%>
<tbody>
<tr><td width=100%></td>
<td>
<% if("restart".equals(request.getParameter("action"))) {
ninja.setMethodName("restart");
ninja.setMethodParamClasses(null);
ninja.setMethodParams(null);
ninja.getMethodResult();
}
%>
<a href="<c:out value='${alias}'/>/selector.jsp?view=monitor&action=restart">restart gui</a>
</td>
<td>
<% if("reboot".equals(request.getParameter("action"))) {
ninja.setMethodName("reboot");
ninja.setMethodParamClasses(null);
ninja.setMethodParams(null);
ninja.getMethodResult();
} %>
<a href="<c:out value='${alias}'/>/selector.jsp?view=monitor&action=reboot">reboot hardware</a>
</td>
</tr>
</tbody>
</table>
<hr>
<FORM ACTION="<c:out value='${alias}'/>/selector.jsp?view=monitor" METHOD=POST>
<INPUT TYPE=HIDDEN NAME="action" VALUE="view_queue">
<INPUT TYPE=SUBMIT VALUE="queue">
</FORM>
<% if("view_queue".equals(request.getParameter("action"))) {
ninja.setMethodName("getRequests");
ninja.setMethodParamClasses("[edu.columbia.print.ninja.core.event.PrintQueueEvent");
ninja.setMethodParams(null);
    edu.columbia.print.ninja.core.event.PrintQueueEvent[] items = 
        (edu.columbia.print.ninja.core.event.PrintQueueEvent[] )ninja.getMethodResult();
    %><table border=1><%
    %><tr><td><b>Doc</b></td><td><b>Expiration</b></td><td><b>Print</b></td></tr><%
    for(int i=0; items!=null && i<items.length; i++) {
        String name = null;
        long expiration = 0L;
        try {
			name =""+items[i].getPrintRequest().getAttributes().get(javax.print.attribute.standard.JobName.class);
            ninja.setMethodName("getRequestExpiration");
            ninja.setMethodParamClasses("net.jini.print.job.PrintRequest");
            ninja.setMethodParams(new Object[] {items[i].getPrintRequest()});
            expiration = ((Long )ninja.getMethodResult()).longValue();
        }
        catch(Exception e) {
			name = e+"";
        }
        Date date = new Date(expiration);
        %><tr><td><%=name%></td><td><%=date%></td><td>Go</td></tr><%
    }
    %></table><%
} %>
<hr>

<%
String cmd=request.getParameter("cmd");
if(cmd==null) cmd ="lpq all";
%>
<FORM ACTION="<c:out value='${alias}'/>/selector.jsp?view=monitor" METHOD=POST>
<INPUT TYPE=HIDDEN NAME="action" VALUE="lpc">
<INPUT TYPE="text" NAME="cmd" SIZE=80 VALUE="<%=cmd%>">
<INPUT TYPE=SUBMIT VALUE="lpc">
</FORM>
<a href="http://www.lprng.com/LPRng-HOWTO-Multipart/lpc.htm" target="_blank">LPC commands</a>
<textarea cols="60" rows="8" readonly>
<% if("lpc".equals(request.getParameter("action"))) {
    ninja.setMethodName("control");
    ninja.setMethodParamClasses("java.lang.String");
    ninja.setMethodParams(new Object[] {request.getParameter("cmd")});
    out.println(ninja.getMethodResult());
} %>
</textarea>
</c:if>
