package org.apache.jsp.membership.parent;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import com.tootsville.user.*;
import org.starhope.appius.user.*;
import org.starhope.appius.mb.Messages;
import com.tootsville.WebUtil;

public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.List _jspx_dependants;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;


//----------  Universal Declarations: Place this on every page.
/**
 *   Parent/User object.  On myAccount this should be declared User and on parent this should be declared Parent
*/
Parent sessionUser=null;
/**
 *   Error message list
*/
 
HashMap <String, String> storeValues = new HashMap <String, String> (); 

String url = "/membership/";


//----------- Verify the session and create a User or Parent Object
//-----------   This should be placed on any of the 'logged in' sections on the website.
if (null!=session.getAttribute("sUserID")
		&& null!=session.getAttribute("sUserPassword")
		&& null!=session.getAttribute("sUserType")) {
	String userID=session.getAttribute("sUserID").toString();
	String userPassword=session.getAttribute("sUserPassword").toString();
	String userType=session.getAttribute("sUserType").toString();
	if (userPassword.equals("approval")) {
		WebUtil.log ("A parent has come to approve or deny their child.");
		sessionUser=Parent.getByID(Integer.parseInt(userID));
		WebUtil.log ("userID: " + userID + " userType: " + userType + " password: " + userPassword);
	} else {
		if (sess.getVisitorRole()==VisitorRole.self) {
			err.put("username", Messages.getText("login_invalid"));
			url = "/membership/";
		} else if (sess.getVisitorRole()==VisitorRole.parent) {
			sessionUser=WebUtil.verifyParentLogin(userID, userPassword);

		}
		if (null==sessionUser)
			err.put("username", Messages.getText("login_invalid"));
	}
} else {
	if (null==session.getAttribute("sUserID"))
	if (null==session.getAttribute("sUserPassword"))
	if (null==session.getAttribute("sUserType"))
	
	err.put("username", Messages.getText("login_invalid"));
}

Toot selectedChild = null;
String childID = "";
if (null!=request.getParameter("toot") && !request.getParameter("toot").equals("")) {
	childID = request.getParameter("toot");
	selectedChild = (Toot) User.getByID(Integer.parseInt(childID));
}


//----------- Error handling:  Place this on every page.
//-----------    These errors are read and displayed by Header.jsp
if (err.size() > 0) {
	session.setAttribute("sError", err);
	response.sendRedirect(url);
} else {

      out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html>\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n<head>\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge\" />\n<title>Tootsville™ Membership</title>\n<link rel=\"shortcut icon\" href=\"/t.png\" type=\"image/png\" />\n<link rel=\"stylesheet\" href=\"/membership/style.css\" type=\"text/css\" />\n<script type=\"text/javascript\">\n<!--\nfunction cancel_child() {\n\tvar answer = confirm(\"Are you sure you want to disable this Toots Account?  Note:  This will not unsubscribe a V.I.T. membership.\");\n\tif (answer)\n\t\twindow.location.href = \"");
      out.print("/membership/parent/edit/edit-child.jsp?childID=" +  childID + "&action=deny");
      out.write("\";\n}\n-->\n</script>\n</head>\n<body>\n<div class=\"content-pane\">\n");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "/membership/Header.jsp", out, false);
      out.write("\n<h2><img src=\"/images/text-manage-my-parent-account.png\" alt=\"Manage My Account!\" /></h2>\n<h4>Welcome to Manage My Parent Account.</h4>\n<div class=\"floatingimage\" id=\"tango-handstand\"><img src=\"/images/icon-tango-handstand.png\" alt=\"Manage My Account\" /></div>\n<div class=\"logoutbutton\">\n<a href=\"/membership/logout.jsp\">\n<img src=\"/images/manageaccount/button-logout1.png\" alt=\"Logout\" />\n</a>\n</div>\n<div class=\"logoutcompensator\">\n<div class=\"fieldset\"><div class=\"legend\"><img src=\"/images/text-account-details.png\" /></div>\n<br />\nHello, ");
      out.print( sessionUser.getDisplayName()  );
      out.print( ("      (" + sessionUser.getMail() + ")") );
      out.write(" \n<br />\n<br />\nTo review the details of your child's Toots® Account(s), edit your profile and register \nnew Toots® accounts, please select from the options below. \n<div class=\"parentcontainer\">\n<span class=\"parentpane\" style=\"float: left;\">\n<img src=\"/images/icon-my-child-toots-account.png\" style=\"margin:-1em -1.5em 0.5em -1.5em;width:18em;\" />\n<br />\n<div class=\"toot-select\">\n");

// Sort the child list array
User childList[]=sessionUser.getChildren();
out.println("\n");
for (User child : childList) {
	out.println("<a href=\"?toot=" + child.getUserID() + "\" class=\"child\" style=\"");
	if (child.isCanceled())
		out.print("text-decoration:line-through;");
	if (null != selectedChild && child.getUserID() == selectedChild.getUserID())
		out.print("background-color: #ccff99 !important;");
	out.print("\">");
	if (child.isPaidMember())
		out.println("<img src=\"/images/icon-vit-membership.png\" style=\"float:right\" alt=\"This child has a Very Important Toot membership.\" />");
	if (child.isNeedsParentAttention())
		out.println("<img src=\"/images/icon-needs-attention.png\" style=\"float:right\" alt=\"This child needs attention.\" />");
	out.print("User Name: <br />&raquo;&nbsp;" + child.getUserNameOrRequest ());
	out.println("<br />");
	if (null==child.getGivenName() || child.getGivenName().equals("")
			|| child.getGivenName().equals("null") || child.getGivenName().equals("")) {
		// do nothing	
	} else {
		out.print("Child: " + child.getGivenName() + "\n");
	}
	out.println("</a>\n");
}

      out.write("\n</div>\n</span><span class=\"parentpane\" style=\"float: right;\">\n<img src=\"/images/icon-your-parent-box.png\" style=\"margin:-1em -1.5em 0.5em -1.5em;width:18em;\" />\n<br />\n<button type=\"button\" style=\"margin: 1em 1.25em;\" class=\"parentbuttons\" ");

	if (sessionUser.isRegistered()) {
		out.print("onclick=\"document.location='/membership/parent/?edit=true#edit';\" id=\"edit-account\""); 
	} else {
		storeValues.put("email", sessionUser.getMail());
		storeValues.put("emailConfirm", sessionUser.getMail());
		session.setAttribute("storeValues", storeValues);
		out.print("onclick=\"document.location='/membership/register/parent/';\" id=\"parent-register\"");	
	}
	
      out.write("> </button>\n<button type=\"button\" style=\"margin: 1em 1.25em;\"  class=\"parentbuttons\" onclick=\"document.location='/membership/register/membership/?register=parent';\" id=\"add-a-child\"> </button>\n</span>\n</div>\n<br clear=\"all\" />\n<img src=\"/images/icon-vit-membership.png\" style=\"float:left\" alt=\"This child has a Very Important Toot membership.\" /> V.I.T. Memberships <br />\n<img src=\"/images/icon-needs-attention.png\" style=\"float:left\" alt=\"This child needs attention.\" /> Your Child's Account Needs Attention\n<br />\n</div>\n");


if (null!=selectedChild && sessionUser.getID() == selectedChild.getParentID()) {
	
      out.write("\n<form  method=\"post\">\n<input type=\"hidden\" name=\"childID\" value=\"");
      out.print( childID );
      out.write("\" />\n<a name=\"child\" />\n<div class=\"fieldset\"><div class=\"legend\"><img src=\"/images/text-user-details.png\" /></div>\nTo update individual or all listed items of the user details, edit the field boxes provided and hit submit. \n<br />\n<br />\n<table style=\"width:100%\">\n<tr>\n<td style=\"width:50%;vertical-align:top;\">\n<span class=\"sel_user\">Child: ");
      out.print( selectedChild.getDisplayName() );
      out.write("</span>\n<br /><br />\n</td>\n<td style=\"width:50%;vertical-align:top;\" rowspan=\"2\">\n");
 if (!selectedChild.isApproved() && !selectedChild.isBanned() ) {
      out.write("\n<a href=\"");
      out.print("/membership/parent/edit/edit-child.jsp?childID=" +  childID + "&action=approve");
      out.write("\">\n<div class=\"child\" style=\"border-color:green; text-align: center;\">\n<img src=\"/images/manageaccount/icon-approve.png\" alt=\"Approve\" style=\"float:left;padding: 0 0.5em;\" />Approve Child Account<br />\n<small style=\"color:green\">(This action will approve your child's account and allow your child to chat in Tootsville™)</small>\n</div>\n</a>\n");
 
if (!selectedChild.isCanceled()) { 
      out.write("\n<a href=\"");
      out.print("/membership/parent/edit/edit-child.jsp?childID=" +  childID + "&action=deny");
      out.write("\">\n<div class=\"child\" style=\"border-color:red; text-align: center;\">\n<img src=\"/images/manageaccount/icon-denied.png\" alt=\"Deny\" style=\"float:left;padding: 0 0.5em;\" />Cancel Child Account<br />\n<small style=\"color:red\">(This action will cancel your child's account)</small>\n</div>\n</a>\n");
 }}
if (selectedChild.isBanned()) {

      out.write("\n<a href=\"");
      out.print( "mailto:CustomerService@tootsville.com?subject=Why was my child, " + selectedChild.getUserName() 
		+ ", banned from Tootsville™?&body=Dear Customer Service," );
      out.write("\">\n<div class=\"child\" style=\"border-color:red;\">\n<img src=\"/images/icon-needs-attention.png\" alt=\"Deny\" style=\"float:left;padding: 0 0.5em;\" />Your child is banned!<br />\n<small style=\"color:red\">(Click here to send Tootsville™'s Customer Service an e-mail)</small>\n</div>\n</a>\n");
 } 
      out.write("\n</td>\n</tr>\n<tr>\n<td>\nStatus:  \n");
 
if (selectedChild.isActive()) {
	// Active
	out.println ("<font color='green'>Active</font>");
} else if (selectedChild.isCanceled()) {
	// Canceled
	out.println ("<font color='gray'>Canceled</font>");
} else if (selectedChild.isBanned()) {
	// Banned
	out.println ("<font color='red'>Banned</font>");
} else if (selectedChild.isKicked()) {
	// Kicked + message
	out.println ("<font color='red'>Kicked: "+selectedChild.getKickedMessage()+"</font>"); 
}

      out.write("\n</td>\n</tr>\n</table>\n<br />\n<table class=\"edit-child\" >\n");
 if (selectedChild.needsNaming()) { 
      out.write("\n<tr>\n<td colspan=\"2\">\nThe user name your child has requested was not approved.  Please select another user name.\n</td>\n</tr>\n<tr>\n<td>\nNew User Name:\n</td>\n<td>\n<input type=\"text\" name=\"username\" size=\"20\" maxlength=\"30\" />\n</td>\n</tr>\n");
 } 
      out.write("\n<tr>\n<td>\nChild's Password:\n</td>\n<td>\n<input type=\"text\" name=\"childPassword\" value=\"");
      out.print( selectedChild.getPassword() );
      out.write("\" size=\"20\" maxlength=\"30\" />\n</td>\n</tr>\n<tr>\n<td>\nChild's First Name:\n</td>\n<td>\n<input type=\"text\" name=\"childFirstName\" value=\"");
      out.print( null!=selectedChild.getGivenName()?selectedChild.getGivenName():"" );
      out.write("\" size=\"20\" maxlength=\"30\" />\n</td>\n</tr>\n<tr>\n<td>\nAllow Child to Chat\n</td>\n<td>\n<label><input type=\"radio\" name=\"isCanTalk\" value=\"true\" ");
      out.print( selectedChild.isCanTalk()? "checked=\"checked\"":"" );
      out.write(" />Allow</label><br />\n<label><input type=\"radio\" name=\"isCanTalk\" value=\"false\" ");
      out.print( selectedChild.isCanTalk()? "":"checked=\"checked\"" );
      out.write(" />Deny</label>\n</td>\n</tr>\n<tr>\n<td>\nForgotten Password Question:<br />\n");
      out.print( selectedChild.getForgotPasswordQuestion() );
      out.write("\n</td>\n<td>\nForgotten Password Answer:<br />\n<input type=\"text\" name=\"childAnswer\" value=\"");
      out.print( selectedChild.getForgotPasswordAnswer() );
      out.write("\" size=\"20\" maxlength=\"30\" />\n</td>\n</tr>\n<tr>\n<td>\nChild's Date of Birth\n</td>\n<td>\n");
      out.print( Messages.prettyDate(selectedChild.getBirthDate()) );
      out.write("\n</td>\n</tr>\n<tr>\n<td colspan=\"2\">\n<br />\nIf you have a Chase-It eCode or Peanut Code and you wish to apply its value to this child's account, \nplease enter the corresponding code below.\n<br />\n<br />\n</td>\n</tr>\n<tr>\n<td>\nChase-It eCode:\n</td>\n<td>\n<input type=\"text\" name=\"chaseItCode\" value=\"\" size=\"20\" maxlength=\"30\" />\n</td>\n</tr>\n<tr>\n<td>\nPeanut Code:\n</td>\n<td>\n<input type=\"text\" name=\"peanutCode\" value=\"\" size=\"20\" maxlength=\"30\" />\n</td>\n</tr>\n<tr>\n<td>\n");
 if (!selectedChild.isPaidMember()) { 
      out.write("\n<button type=\"button\" name=\"upgrade\" id=\"parent-upgrade\" onclick=\"document.location=('");
      out.print( "/membership/register/premium/?toot=" + selectedChild.getUserID() );
      out.write("')\"></button>\n");
 } 
      out.write("\n</td>\n<td>\n<input type=\"submit\" name=\"parent-edit-child\" class=\"formbuttons\" id=\"submit\" value=\" \" />\n</td>\n</tr>\n</table>\n");
 if (selectedChild.isApproved()) { 
      out.write("\n<div class=\"cancel_child\" onclick=\"cancel_child();\">\nDisable This Toots Account\n</div>\n");
 } 
      out.write("\n<br />\n</div>\n</form>\n");

}


if (null!=request.getParameter("edit") && !request.getParameter("edit").equals("")) {
	String edit = request.getParameter("edit");
	if (edit.equals("true")) {

      out.write("\n<a name=\"edit\" />\n<form  method=\"post\">\n<div class=\"fieldset\"><div class=\"legend\"><img src=\"/images/manageaccount/text-update-password.png\" /></div>\n<br />\n<table>\n<tr>\n<td colspan=\"\">\nDo you want to change your password?  Type your old password then your new password twice and hit submit!\n<br />\n<br />\n</td>\n</tr>\n<tr>\n<td colspan=\"2\"><br /></td>\n</tr>\n<tr>\n<td>Old Password:</td>\n<td><input type=\"password\" name=\"oldPassword\" maxlength=\"30\" size=\"40\" /></td>\n</tr>\n<tr>\n<td colspan=\"2\"><br /></td>\n</tr>\n<tr>\n<td>New Password:</td>\n<td><input type=\"password\" name=\"newPassword\" maxlength=\"30\" size=\"40\" /></td>\n</tr>\n<tr>\n<td>Confirm New Password:</td>\n<td><input type=\"password\" name=\"newPasswordConfirm\" maxlength=\"30\" size=\"40\" /></td>\n</tr>\n<tr>\n<td><br /></td>\n</tr>\n");

/** 
 *<tr>
 *<td colspan="2"><h2>Update E-mail</h2></td>
 *</tr>
 *<tr>
 *<td colspan="2"><br /></td>
 *</tr>
 *<tr>
 *<td>New E-mail:</td>
 *<td><input type="text" name="newEmail" maxlength="50" size="40" /></td>
 *</tr>
 *<tr>
 *<td>Confirm New E-mail:</td>
 *<td><input type="text" name="newEmailConfirm" maxlength="50" size="40" /></td>
 *</tr>
 *<tr>
 *<td colspan="2"><br /></td>
 *</tr>
 */

      out.write("\n<tr>\n<td> </td>\n<td><input type=\"submit\" value=\"\" class=\"formbuttons\" id=\"submit\" /></td>\n</tr>\n</table>\n</div>\n</form>\n");
 }} 
      out.write("\n</div>\n\n");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "/membership/privacy.jsp", out, false);
      out.write("\n</div>\n");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "/membership/footer.jsp", out, false);
      out.write("\n\n<div class=\"imagepreload\">\n<img src=\"/images/button-submit1.png\" />\n<img src=\"/images/button-submit2.png\" />\n<img src=\"/images/button-submit3.png\" />\n<img src=\"/images/manageaccount/button-make-me-a-vit1.png\" />\n<img src=\"/images/manageaccount/button-make-me-a-vit2.png\" />\n<img src=\"/images/button-edit-account1.png\" />\n<img src=\"/images/button-edit-account2.png\" />\n<img src=\"/images/button-edit-account3.png\" />\n<img src=\"/images/button-add-a-child1.png\" />\n<img src=\"/images/button-add-a-child2.png\" />\n<img src=\"/images/button-add-a-child3.png\" />\n</div>\n\n</body>\n</html>\n");

}

    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
