/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: Apache Tomcat/7.0.19
 * Generated at: 2014-03-11 08:24:13 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.sql.*;
import java.util.*;
import java.security.*;
import java.io.*;
import java.text.*;
import java.lang.*;
import java.util.Calendar.*;
import com.goldhuman.util.*;
import protocol.*;
import com.goldhuman.auth.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.goldhuman.util.LocaleUtil;
import com.goldhuman.util.*;

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

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  static {
    _jspx_dependants = new java.util.HashMap<java.lang.String,java.lang.Long>(3);
    _jspx_dependants.put("/../include/foot.jsp", Long.valueOf(1394524943000L));
    _jspx_dependants.put("/include/.config.jsp", Long.valueOf(1394526092000L));
    _jspx_dependants.put("/include/header.jsp", Long.valueOf(1394526250000L));
  }

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
  }

  public void _jspDestroy() {
  }

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

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;


    try {
      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;

      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");

	String db_host = "localhost";
	String db_port = "3306";
	String db_user = "root";
	String db_password = "1234";
	String db_database = "pw";
	String item_labels = "pwi";
	String pw_server_path = "/home/";

      out.write('\n');
      out.write("\n");
      out.write("\n");
      out.write("<html>\n");
      out.write("<head>\n");
      out.write("<link href=\"../iweb/include/style.css\" rel=\"stylesheet\" type=\"text/css\">\n");
      out.write("<title>Управление аккаунтами</title>\n");
      out.write("\n");
      out.write("\n");
      out.write("<title>IWEB 1.4.5</title>\n");
      out.write("<LINK href=\"/iweb/css/style.css\" rel=stylesheet type=text/css>\n");
      out.write("<meta http-equiv=\"Pragma\" content=\"no-cache\">\n");
      out.write("<meta http-equiv=\"cache-control\" content=\"no-cache\">\n");
      out.write("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#FFFFFF\">\n");
      out.write("\t<tr>\n");
      out.write("\t\t<td width=\"30\" height=\"70\" bgcolor=\"#007fff\">\n");
      out.write("\t\t</td>\n");
      out.write("\t\t</td>\n");
      out.write("\t\t<td width=\"600\" class=\"navColor align=\"center\" >\n");
      out.write("\t\t<a href=\"/iweb/index.jsp\" class=\"white\">[Аккаунты]</a> | \n");
      out.write("\t\t<a href=\"/iweb/role/index.jsp\" class=\"white\">[Редактирование XML]</a>| \n");
      out.write("\t\t<a href=\"/iweb/role/manage.jsp\" class=\"white\">[Персонажи]</a> | \n");
      out.write("\t\t<a href=\"/iweb/manage/index.jsp\" class=\"white\">[Настройки сервера]</a>\t| \n");
      out.write("\t\t<a href=\"/iweb/manage/instance.jsp\" class=\"white\">[Локации и службы]</a> | \n");
      out.write("\t\t<a href=\"http://forum.kn1fe-zone.ru\" class=\"white\">[Доработал до 1.5.1 Kn1fe]</a>\n");
      out.write("\t</td>\n");
      out.write("\t</tr>\n");
      out.write("\t<tr class=\"shadow\">\n");
      out.write("\t\t<td height=\"4\" colspan=\"3\"></td>\n");
      out.write("\t</tr>\n");
      out.write("\t<tr>\n");
      out.write("\t\t<td height=\"10\" colspan=\"3\"></td>\n");
      out.write("\t</tr>\n");
      out.write("</table>");
      out.write("\n");
      out.write("</head>\n");
      out.write("<body style=\"background-color:#ffffff;\">\n");
      out.write("<div align=\"center\"><font size=\"5\">Управление аккаунтами</font>\n");
      out.write("<table width=\"800\" border=\"0\" cellspacing=\"0\">\n");
      out.write("\n");

	String message = "<br>";
	if(request.getParameter("action") != null)
	{
			String action = new String(request.getParameter("action"));


			if(action.compareTo("changegm") == 0)
			{
					String type = request.getParameter("type");
					String ident = request.getParameter("ident");
					String truename = request.getParameter("truename");
					String act = request.getParameter("act");

					if(type.length() > 0 && ident.length() > 0 && act.length() > 0)
					{
						try
						{
							Class.forName("com.mysql.jdbc.Driver").newInstance();
							Connection connection = DriverManager.getConnection("jdbc:mysql://" + db_host + ":" + db_port + "/" + db_database, db_user, db_password);
							Statement statement = connection.createStatement();
							ResultSet rs;
							int count;

							if(type.compareTo("id") == 0)
							{
								rs = statement.executeQuery("SELECT ID FROM users WHERE ID='" + ident + "'");
								count = 0;
								while(rs.next())
								{
									count++;
								}
							}

							else
							{
								rs = statement.executeQuery("SELECT ID FROM users WHERE name='" + ident + "'");
								count = 0;
								while(rs.next())
								{
									ident = rs.getString("ID");
									count++;
								}
							}

							if(count <= 0)
							{
								message = "<font color=\"ee0000\">Пользователя не существует</font>";
							}
							else
							{
								rs = statement.executeQuery("SELECT userid FROM auth WHERE userid='" + ident + "'");
								count = 0;
								while(rs.next())
								{
									count++;
								}
								if(count > 0)
								{
									if(act.compareTo("delete") == 0)
									{
										statement.executeUpdate("DELETE FROM auth WHERE userid='" + ident + "'");
										message = "<font color=\"00cc00\">Права GM сняты с пользователя</font>";
									}
									else
									{
										message = "<font color=\"ee0000\">Пользователь Уже GM</font>";
									}
								}
								else
								{
									if(act.compareTo("add") == 0)
									{
										rs = statement.executeQuery("call addGM('" + ident + "', '1')");
										message = "<font color=\"00cc00\">Права GM выданы пользователю</font>";
									}
									else
									{
										message = "<font color=\"ee0000\">Доступ к GM Недоступен</font>";
									}
								}
							}

							rs.close();
							statement.close();
							connection.close();
						}
						catch(Exception e)
						{
							message = "<font color=\"#ee0000\"><b>Подключиться к базе данных MySQL не удалось</b></font>";
						}
					}
					else ;
			}
			else ;

			if(action.compareTo("addcubi") == 0)
			{
					String type = request.getParameter("type");
					String ident = request.getParameter("ident");
					int amount = 0;
					try
					{
						amount = Integer.parseInt(request.getParameter("amount"));
					}
					catch(Exception e)
					{}

					if(type.length() > 0 && ident.length() > 0)
					{
						if(amount < 1 || amount > 999999999)
						{
							message = "<font color=\"ee0000\">Неверное количество (1-999999999)</font>";
						}
						else
						{
							try
							{
								Class.forName("com.mysql.jdbc.Driver").newInstance();
								Connection connection = DriverManager.getConnection("jdbc:mysql://" + db_host + ":" + db_port + "/" + db_database, db_user, db_password);
								Statement statement = connection.createStatement();
								ResultSet rs;
								int count;

								if(type.compareTo("id") == 0)
								{
									rs = statement.executeQuery("SELECT ID FROM users WHERE ID='" + ident + "'");
									count = 0;
									while(rs.next())
									{
										count++;
									}
								}

								else
								{
									rs = statement.executeQuery("SELECT ID FROM users WHERE name='" + ident + "'");
									count = 0;
									while(rs.next())
									{
										ident = rs.getString("ID");
										count++;
									}
								}

								if(count <= 0)
								{
									message = "<font color=\"ee0000\">Пользователь не существует</font>";
								}
								else
								{
									rs = statement.executeQuery("CALL usecash ( '" + ident + "' , 1, 0, 1, 0, '" + 100*amount + "', 1, @error)");
									message = "<font color=\"00cc00\">" + amount + ".00 GOLD Добавлено</font><br><font color=\"ee0000\">Транзакция может занять до 5 минут<br>Relog, необходимые для получения GOLD</font>";
								}
								
								rs.close();
								statement.close();
								connection.close();
							}
							catch(Exception e)
							{
								message = "<font color=\"#ee0000\"><b>Подключиться к базе данных MySQL не удалось</b></font>";
							}
						}
					}
					else ;
			}
			else ;
			
			if(action.compareTo("enhance") == 0)
			{
					String type = request.getParameter("type");
					String ident = request.getParameter("ident");
					String truename = request.getParameter("truename");
					String act = request.getParameter("act");

					if(type.length() > 0 && ident.length() > 0 && act.length() > 0)
					{
						try
						{
							Class.forName("com.mysql.jdbc.Driver").newInstance();
							Connection connection = DriverManager.getConnection("jdbc:mysql://" + db_host + ":" + db_port + "/" + db_database, db_user, db_password);
							Statement statement = connection.createStatement();
							ResultSet rs;
							int count;

							if(type.compareTo("id") == 0)
							{
								rs = statement.executeQuery("SELECT ID FROM users WHERE ID='" + ident + "'");
								count = 0;
								while(rs.next())
								{
									count++;
								}
							}

							else
							{
								rs = statement.executeQuery("SELECT ID FROM users WHERE name='" + ident + "'");
								count = 0;
								while(rs.next())
								{
									ident = rs.getString("ID");
									count++;
								}
							}

							if(count <= 0)
							{
								message = "<font color=\"ee0000\">User Don't Exists</font>";
							}
							else
							{
								rs = statement.executeQuery("SELECT userid FROM enhanced WHERE userid='" + ident + "'");
								count = 0;
								while(rs.next())
								{
									count++;
								}
								if(count > 0)
								{
									if(act.compareTo("delete") == 0)
									{
										statement.executeUpdate("DELETE FROM enhanced WHERE userid='" + ident + "'");
										message = "<font color=\"00cc00\">Enhancement Removed From User</font>";
									}
									else
									{
										message = "<font color=\"ee0000\">User is Already enhanced</font>";
									}
								}
								else
								{
									if(act.compareTo("farmer") == 0)
									{
										rs = statement.executeQuery("CALL addEnhanced('" + ident + "', '" + truename + "', '2')");
										message = "<font color=\"00cc00\">User has been enhanced to farmer</font>";
									}
									if(act.compareTo("soldier") == 0)
									{
										rs = statement.executeQuery("CALL addEnhanced('" + ident + "', '" + truename + "', '3')");
										message = "<font color=\"00cc00\">User has been enhanced to Soldier</font>";
									}
									if(act.compareTo("merchant") == 0)
									{
										rs = statement.executeQuery("CALL addEnhanced('" + ident + "', '" + truename + "', '4')");
										message = "<font color=\"00cc00\">User has been enhanced to Merchant</font>";
									}
									if(act.compareTo("hero") == 0)
									{
										rs = statement.executeQuery("CALL addEnhanced('" + ident + "', '" + truename + "', '5')");
										message = "<font color=\"00cc00\">User has been enhanced to Hero</font>";
									}
									else
									{
										message = "<font color=\"ee0000\">User is not enhanced</font>";
									}
								}
							}

							rs.close();
							statement.close();
							connection.close();
						}
						catch(Exception e)
						{
							message = "<font color=\"#ee0000\"><b>Подключиться к базе данных MySQL не удалось</b></font>";
						}
					}
					else ;
			}
			else ;
	}
	else ;

      out.write("\n");
      out.write("\n");
      out.write("<table width=\"800\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n");
      out.write("\n");
      out.write("<tr>\n");
      out.write("\t<td height=\"1\" align=\"center\" valign=\"top\" colspan=\"3\">\n");
      out.write("\t\t<b>");
 out.print(message); 
      out.write("</b>\n");
      out.write("\t</td>\n");
      out.write("</tr>\n");
      out.write("\n");
      out.write("<tr>\n");
      out.write("\t<td height=\"1\" align=\"center\" valign=\"top\" colspan=\"3\">\n");
      out.write("\t\t<br>\n");
      out.write("\t</td>\n");
      out.write("</tr>\n");
      out.write("\n");
      out.write("<tr>\n");
      out.write("\t<td height=\"1\" colspan=\"3\">\n");
      out.write("\t\t<br>\n");
      out.write("\t</td>\n");
      out.write("</tr>\n");
      out.write("\n");
      out.write("<tr>\n");
      out.write("\t<td align=\"center\" valign=\"top\">\n");
      out.write("\t\t");

				out.println("<form action=\"index.jsp?page=account&action=changegm\" method=\"post\" style=\"margin: 0px;\"><table width=\"240\" cellpadding=\"5\" cellspacing=\"0\" style=\"border:1px solid #cccccc;\">");
				out.println("<tr><th align=\"center\" colspan=\"2\"><b><font color=\"#000000\">ИГРОВОЙ MASTER</font></b></th></tr>");
				out.println("<tr><td>Тип:</td><td align=\"right\"><select name=\"type\" style=\"width: 100; text-align: center;\"><option value=\"id\">ID</option><option value=\"login\">Login</option></select></td></tr>");
				out.println("<tr><td>Аккаунт (ID):</td><td align=\"right\"><input type=\"text\" name=\"ident\" style=\"width: 100; text-align: center;\"></td></tr>");
				out.println("<tr><td>Имя персонажа:</td><td align=\"right\"><input type=\"text\" name=\"truename\" style=\"width: 100; text-align: center;\"></td></tr>");
				out.println("<tr><td>Действие:</td><td align=\"right\"><select name=\"act\" style=\"width: 100; text-align: center;\"><option value=\"add\">Дать GM</option><option value=\"delete\">Убрать GM</option></select></td></tr>");
				out.println("<tr><td align=\"center\" colspan=\"2\"><input type=\"image\" name=\"submit\" src=\"include/btn_submit.jpg\" style=\"border: 0px;\"></td></tr>");
				out.println("</table></form>");
		
      out.write("\n");
      out.write("\t</td>\n");
      out.write("\n");
      out.write("\t<td align=\"center\" valign=\"top\">\n");
      out.write("\t\t");

				out.println("<form action=\"index.jsp?page=account&action=addcubi\" method=\"post\" style=\"margin: 0px;\"><table width=\"240\" cellpadding=\"5\" cellspacing=\"0\" style=\"border:1px solid #cccccc;\">");
				out.println("<tr><th align=\"center\" colspan=\"2\"><b><font color=\"#000000\">ЗАЧИСЛИТЬ GOLD</font></b></th></tr>");
				out.println("<tr><td>Тип:</td><td align=\"right\"><select name=\"type\" style=\"width: 100; text-align: center;\"><option value=\"id\">ID</option><option value=\"login\">Login</option></select></td></tr>");
				out.println("<tr><td>Аккаунт (ID):</td><td align=\"right\"><input type=\"text\" name=\"ident\" style=\"width: 100; text-align: center;\"></td></tr>");
				out.println("<tr><td>Количество:</td><td align=\"right\"><input type=\"text\" name=\"amount\" style=\"width: 100; text-align: center;\"></td></tr>");
				out.println("<tr><td align=\"center\" colspan=\"2\"><input type=\"image\" name=\"submit\" src=\"include/btn_submit.jpg\" style=\"border: 0px;\"></td></tr>");
				out.println("</table></form>");
		
      out.write("\n");
      out.write("\t</td>\n");
      out.write("\n");
      out.write("\t<td align=\"center\" valign=\"top\">\n");
      out.write("\t\t");

				out.println("<table cellpadding=\"0\" cellspacing=\"0\" style=\"border:1px solid #cccccc;\">");
				out.println("<tr><th height=\"1\" align=\"center\" colspan=\"3\" style=\"padding: 5;\"><b><font color=\"#000000\">СПИСОК АККАУНТА</font></b></th></tr>");
				out.println("<tr bgcolor=\"f0f0f0\"><td align=\"center\" style=\"border-bottom: 1px solid #cccccc;\"><b>ID</b></td><td align=\"center\" style=\"border-bottom: 1px solid #cccccc;\"><b>Имя</b></td><td align=\"center\" style=\"border-bottom: 1px solid #cccccc;\"><b>Время создания</b></td></tr>");
				out.println("<tr><td colspan=\"3\" ><div style=\"width: 280; height: 110; overflow: auto;\">");
				out.println("<table width=\"100%\" cellpadding=\"3\" cellspacing=\"0\" style=\"border:0px solid #cccccc;\">");

				try
				{
					Class.forName("com.mysql.jdbc.Driver").newInstance();
					Connection connection = DriverManager.getConnection("jdbc:mysql://" + db_host + ":" + db_port + "/" + db_database, db_user, db_password);
					Statement statement = connection.createStatement();
					ResultSet rs;

					rs = statement.executeQuery("SELECT DISTINCT userid FROM auth");
					ArrayList gm = new ArrayList();

					while(rs.next())
					{
						gm.add(rs.getInt("userid"));
					}

					rs = statement.executeQuery("SELECT ID, name, creatime FROM users");
					while(rs.next())
					{
						if(gm.contains(rs.getInt("ID")))
						{
							out.print("<tr><td align=\"center\" style=\"border-bottom: 1px solid #cccccc;\">" + rs.getString("ID") + "</td><td style=\"border-bottom: 1px solid #cccccc;\"><font color=\"#ee0000\">" + rs.getString("name") + "</font></td><td align=\"center\" style=\"border-bottom: 1px solid #cccccc;\">" + rs.getString("creatime").substring(0, 16) + "</td></tr>");
						}
						else
						{
							out.print("<tr><td align=\"center\" style=\"border-bottom: 1px solid #cccccc;\">" + rs.getString("ID") + "</td><td style=\"border-bottom: 1px solid #cccccc;\">" + rs.getString("name") + "</td><td align=\"center\" style=\"border-bottom: 1px solid #cccccc;\">" + rs.getString("creatime").substring(0, 16) + "</td></tr>");
						}
					}

					rs.close();
					statement.close();
					connection.close();
				}
				catch(Exception e)
				{
					out.println("<tr><td align=\"center\" style=\"border-bottom: 1px solid #cccccc;\"><font color=\"#ee0000\"><b>Подключиться к базе данных MySQL не удалось</b></font></table></div></td></tr>");
				}

				out.println("</table></div></td></tr></table>");
		
      out.write("\n");
      out.write("\t</td>\n");
      out.write("</tr>\n");
      out.write("</table>\n");
      out.write("</div>\n");
      out.write("</body>\n");
      out.write("\n");
      out.write("<table width=\"100%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#FFFFFF\">\n");
      out.write("  <tr>\n");
      out.write("    <td height=\"10\"></td>\n");
      out.write("  </tr>\n");
      out.write("  <tr>\n");
      out.write("    <td align=\"right\" class=\"topline\"></td>\n");
      out.write("  </tr>\n");
      out.write("</table>\n");
      out.write("\n");
      out.write("</html>\n");
      out.write("\n");
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
