%@ page language="java"
import="java.sql.*, java.io.*, java.util.*, users.databases.*"
errorPage="error.jsp"
%>
<%
/***** VARIABLE DECLARATION and INITIALIZATION *****/
String strMainDB = "product_pgpClientInfoDB";
String strTblName = ""; // DETERMINES WHICH TABLE TO USE DEPENDING ON VALUE OF bytDeptID
String strPrefix = "", strPageTitle = "", strSubTitle = "", strCompanyName = "", strBtnName = "";
String [] arrBDName; // CONTAINER FOR BRANCHES/DOWNLINES
int [] arrBDID; // CONTAINER FOR BRANCH/DOWNLINE'S ID NUMBER
int ctr = 0; // USE FOR COUNTING TOTAL NUMBER OF BRANCHES/DOWNLINES
int intID = 0; // USE TO INDICATE IF TABLE IS EMPTY OF BRANCH/DOWNLINE OF A PARTICULAR COMPANY
int intUserID = Integer.parseInt(request.getParameter("uid"));
int intCompanyID = Integer.parseInt(request.getParameter("cid"));
byte bytDeptID = Byte.parseByte(request.getParameter("did"));
/***** END OF VARIABLE DECLARATION *****/
switch (bytDeptID) {
case 8:
strTblName = "tblBranches";
strPrefix = "Br";
strPageTitle = "Branches";
strSubTitle = "LIST OF BRANCHES";
strBtnName = "Branch";
break;
case 9:
strTblName = "tblDownlines";
strPrefix = "DL";
strPageTitle = "Downlines";
strSubTitle = "LIST OF DOWNLINES";
strBtnName = "Downline";
}
String SQLstmt = "SELECT LogOnStatus FROM tblLogOn WHERE Usr_ID=" + intUserID + ";";
users.connect(strMainDB);
ResultSet rs = users.listQuery(SQLstmt);
byte bytLogStatus = 0;
while (rs.next()) {
bytLogStatus = rs.getByte("LogOnStatus");
}
SQLstmt = "SELECT * FROM " + strTblName + " WHERE Co_ID=" + intCompanyID + ";";
rs = users.listQuery(SQLstmt);
while (rs.next()) {
intID = rs.getInt(strPrefix + "_ID");
}
if (bytLogStatus != 1) { // LOG CHECK RESULT - LOG-OUT, DISPLAYS HOME PAGE
%>
<%
} else if (intID==0) {
%>
<%
} else { // LOG CHECK RESULT - LOG-ON, PROCEED DISPLAYING ACTUAL PAGE
SQLstmt = "SELECT Co_Name FROM tblCompanyInfo WHERE Co_ID=" + intCompanyID + ";";
rs = users.listQuery(SQLstmt);
while (rs.next()) { // GET NAME OF COMPANY
strCompanyName = rs.getString("Co_Name");
}
SQLstmt = "SELECT " + strPrefix + "_Name, " + strPrefix + "_ID FROM " + strTblName +
" WHERE Co_ID=" + intCompanyID + " ORDER BY " + strPrefix + "_ID;";
rs = users.listQuery(SQLstmt);
while (rs.next()) {
ctr++; // COUNTS TOTAL NUMBER OF BRANCHES/DOWNLINES
}
arrBDName = new String[ctr];
arrBDID = new int[ctr];
rs.beforeFirst();
ctr = 0;
while (rs.next()) {
arrBDName[ctr] = rs.getString(strPrefix + "_Name");
arrBDID[ctr] = rs.getInt(strPrefix + "_ID");
ctr++;
}
if (arrBDName.length > 1) {
/***** MERGING WITH MAIN HTML CODES STARTS HERE *****/
%>
<%= strPageTitle %>
<% } else { %>
<% } %>
<% } // END OF LOG CHECK %>