<%@	taglib prefix =	"egui" uri = "../WEB-INF/eg-taglib.tld"	%>
<%@ include file = "../admin/EgAdminTracker.jsp" %>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.eg.EgDiscInfo"%>
<%@ page import = "java.io.IOException"%>
<%@ page import = "java.io.File"%>
<%@ page import = "java.io.FileInputStream"%>
<%@ page import = "java.util.ArrayList"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import = "com.egurkha.ini.IniUI"%>
<%@ page import = "java.util.Hashtable"%>
<%@ page import = "java.util.Vector"%>
<%@ page import = "com.egurkha.admin.EgAssetManagementDAO"%>
<%@ page import="egurkha.config.EcCurrentConfigurationBean"%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%
	response.setHeader("Cache-Control", "no-store");
	response.setHeader("Pragma", "no-cache");
	response.setDateHeader("Expires", -1);
	IniUI iniUI = IniUI .getInstance();
    
	String homepageLogo=iniUI.getMonitorHomeLogo();
	if(iniUI.isHKTThemeEnabled())
	{
		homepageLogo = iniUI.getHKTReporterLogo();
	}
%>
<html>
	<head>
		<title>Asset Report</title>
<link rel="stylesheet" type="text/css" href="/final/styles/eGLightThemeIcons.css" />
<style>

@media print {body {-webkit-print-color-adjust: exact;}}


@font-face{font-family:'LucidaGrandeRegular';src:url('/final/fonts/6216/6216.woff') format('woff')}
@font-face{font-family:'LucidaGrandeBold';src:url('/final/fonts/6215/6215.woff') format('woff')}

body{font-size:11px;line-height:1.5em;color:#2a292a;background:#fff}
header{font-size:15px;}
.formLabel {font-size:12px;}
.formValue {font-weight:500;font-size:12px;}
b{font-weight:500;font-size:11px;}

/*  table tr td{font-size:11px;padding:4px;}  */

.printTable{border: 1px solid #c3c3c3; border-collapse: collapse;}

.printTable tr th{border: 0px solid #c3c3c3;padding:4px;background-color:#e2e2e2;font-weight:500;font-size:11px;}
.printTable tr td{border: 0px solid #c3c3c3;padding:4px;font-size:11px;line-height:1.5em;color:#2a292a;}

.printTableHeader{font-weight:500;border: 1px solid #c3c3c3;text-align:left;background-color:#cdcdcd;padding:4px;font-size:12px;}
table,
table tr td,
table tr th {
	page-break-inside: avoid;
}
</style>

<script>
	function printData()
	{
		window.print();
	}
</script>
</head>
<body style="padding:10px">
<table width="100%" cellpadding="0" cellspacing="0" border="0" >
	<tr>
		<td width="100%">
<%
			if(!StringUtils.isNull(homepageLogo))
			{	
%>
			<table cellpadding="0" cellspacing="0" border="0" width="100%" align="center">
				<tr>
					<td style="padding:5px 10px 10px 10px"><img src="<%=homepageLogo.trim()%>" border="0" /></td>
				</tr>
			</table>
<%
			}
%>
			
			<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"  style="border-bottom:1px solid #999;">
				<tr>
					<td style="padding:2px;">
						<div style="float:left;" > <header>
						<egui:intnl text="admin.Asset.ASSET REPORT"/></header></div><br/><br/></br>
						<div style="float:right"><img class="iconPrinter mouse" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" border="0" onClick="javascript:printData()" alt='<egui:intnl text="reporter.common.PRINT"/>' title='<egui:intnl text="reporter.common.PRINT"/>'/></div>
					</td>
				</tr>
			</table>
			<br/><br/><br/>
<%
			response.setContentType("text/html"); 
			response.setContentType("APPLICATION/OCTET-STREAM");
			Hashtable pdfData = (Hashtable)session.getAttribute("pdfData");
			boolean isSoftareListReq=false;
			Vector columnNames = null;
			ArrayList columnDetails = null;
			if(pdfData != null){
			columnNames = (Vector)pdfData.get("columnNames");
			columnDetails = (ArrayList)pdfData.get("columnDetails");
			}
			Vector generalList = new Vector();
			Vector technicalList = new Vector();
			Vector softwareList = new Vector();
			Vector hardwareList = new Vector();
			Vector networkList = new Vector();
			Vector upsList = new Vector();
			Vector cloudList = new Vector();
			Vector awsList = new Vector();
			Vector miscList = new Vector();
			Vector generalSelect = new Vector();
			Vector technicalSelect = new Vector();
			Vector softwareSelect = new Vector();
			Vector hardwareSelect = new Vector();
			Vector networkSelect = new Vector();
			Vector upsSelect = new Vector();
			Vector cloudSelect = new Vector();
			Vector awsSelect = new Vector();
			Vector miscSelect = new Vector();

			EgDiscInfo discInfo = new EgDiscInfo("manager");
			String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
			IniFile servicesIni = new IniFile(s_iniFile_dir + "eg_services.ini");
			String[] categories =servicesIni.getVariables("ASSET_FIELDS");
			if(categories != null){
				if(categories.length > 0){
			for(int i=0;i<categories.length;i++){
				String[] columnListArray = null;
				String columnList = servicesIni.getValue("ASSET_FIELDS",categories[i]);
				if(columnList != null){
				columnListArray = columnList.split(",");
				}
				if(columnListArray != null){
					if(columnListArray.length > 0){
				if(categories[i].equalsIgnoreCase("network")){
					for(int j=0;j<columnListArray.length;j++){
						networkList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}

				}else if(categories[i].equalsIgnoreCase("general")){
					for(int j=0;j<columnListArray.length;j++){
						generalList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}

				}else if(categories[i].equalsIgnoreCase("technical")){
					for(int j=0;j<columnListArray.length;j++){
						technicalList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}

				}else if(categories[i].equalsIgnoreCase("software")){
					for(int j=0;j<columnListArray.length;j++){
						softwareList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}
				}else if(categories[i].equalsIgnoreCase("hardware")){
					for(int j=0;j<columnListArray.length;j++){
						hardwareList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}

				}else if(categories[i].equalsIgnoreCase("ups")){
					for(int j=0;j<columnListArray.length;j++){
						upsList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}
				}else if(categories[i].equalsIgnoreCase("cloud")){
					for(int j=0;j<columnListArray.length;j++){
						cloudList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}
				}else if(categories[i].equalsIgnoreCase("aws")){
					for(int j=0;j<columnListArray.length;j++){
						awsList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}

				}else if(categories[i].equalsIgnoreCase("misc")){
					for(int j=0;j<columnListArray.length;j++){
						miscList.add(servicesIni.getValue("ASSET_FIELDS TEXT MAPPING",columnListArray[j]));
					}
				}
				}
				}
			}
			}
			}
			generalSelect.add("Asset Type");

			if(columnNames != null){
			for(int colIdx=0; colIdx<columnNames.size(); colIdx++)
			{
			String columnName = columnNames.get(colIdx).toString();
			if(generalList.contains(columnName)){
				generalSelect.add(columnName);
			}else if(technicalList.contains(columnName)){
				technicalSelect.add(columnName);
			}else if(softwareList.contains(columnName)){
				if(columnName.equalsIgnoreCase("Software List"))
				{
					isSoftareListReq=true;
					continue;
				}
				softwareSelect.add(columnName);
			}else if(hardwareList.contains(columnName)){
				hardwareSelect.add(columnName);
			}else if(networkList.contains(columnName)){
				networkSelect.add(columnName);
			}else if(upsList.contains(columnName)){
				upsSelect.add(columnName);
			}else if(cloudList.contains(columnName)){
				cloudSelect.add(columnName);
			}else if(awsList.contains(columnName)){
				awsSelect.add(columnName);
			}else if(miscList.contains(columnName)){
				miscSelect.add(columnName);
				}

			}
			}
			if(columnDetails != null){
			Iterator it1 = columnDetails.iterator();
%>
			<table width="100%"  cellpadding="0" cellspacing="0" border="0"  align="center" class="printTable">
				<tr>
			
					<th align="left" width="10%" class="printTableHeader"><egui:intnl text="admin.Asset.COMPONENT TYPE"/></th>
					<th align="left" width="10%" class="printTableHeader"><egui:intnl text="admin.Asset.COMPONENT NAME"/></th>
					<th align="center" width="80%" class="printTableHeader"><egui:intnl text="admin.Asset.ASSET DETAILS"/></th>
				</tr>
<%
			while(it1.hasNext()){
				Hashtable colData = (Hashtable)it1.next();
				String[] categoryList = null;
				Object[] colObjList = null;
				String categoryTitle = "";
				if(colData != null){
				String Asset_Type = colData.get("Asset Type").toString();
				String categoryInfo = servicesIni.getValue("ASSET_TYPE_FIELDS MAPPING",Asset_Type);
				
				if(categoryInfo != null){
				categoryList = categoryInfo.split(",");
				}
				
%>
				<tr>
					<td align="left" style="vertical-align:top;" width="10%"><%= colData.get("Component Type")%></td>
					<td align="left" style="vertical-align:top;" width="10%"><%= colData.get("Component Name")%></td>
					<td align="left" width="80%">
<%
				if(categoryList != null){
					if(categoryList.length > 0){
					for(int cateIdx = 0;cateIdx<categoryList.length;cateIdx++){
						int len = 0;
						categoryTitle = null;
						colObjList = null;
						if(categoryList[cateIdx].equalsIgnoreCase("general")){
							
							if(generalSelect != null){
							len = generalSelect.size();
							if(len>0){
							colObjList = new Object[len];
							generalSelect.copyInto(colObjList);
							categoryTitle = null;
							}
							}
						}else if(categoryList[cateIdx].equalsIgnoreCase("technical")){
							if(technicalSelect != null){
							len = technicalSelect.size();
							if(len>0){
							colObjList = new Object[len];
							technicalSelect.copyInto(colObjList);
							categoryTitle = "Technical Details";
							}
							}
						}else if(categoryList[cateIdx].equalsIgnoreCase("software")){
							if(softwareSelect != null){
							len = softwareSelect.size();
							if(len>0){
							colObjList = new Object[len];
							softwareSelect.copyInto(colObjList);
							categoryTitle = "Software Details";
							}
							}
						}else if(categoryList[cateIdx].equalsIgnoreCase("hardware")){
							if(hardwareSelect != null){
							len = hardwareSelect.size();
							if(len>0){
							colObjList = new Object[len];
							hardwareSelect.copyInto(colObjList);
							categoryTitle = "Hardware Details";
							}
							}
						}else if(categoryList[cateIdx].equalsIgnoreCase("network")){
							 if(networkSelect != null){
							 len = networkSelect.size();
							if(len>0){
							colObjList = new Object[len];
							networkSelect.copyInto(colObjList);
							categoryTitle = "Network Details";
							}
							}
						}else if(categoryList[cateIdx].equalsIgnoreCase("ups")){
							if(upsSelect != null){
							len = upsSelect.size();
							if(len>0){
							colObjList = new Object[len];
							upsSelect.copyInto(colObjList);
							categoryTitle = "UPS Details";
							}
							}
						}else if(categoryList[cateIdx].equalsIgnoreCase("cloud")){
							if(cloudSelect != null){
							len = cloudSelect.size();
							if(len>0){
							colObjList = new Object[len];
							cloudSelect.copyInto(colObjList);
							categoryTitle = "Cloud Details";
							}
							}
						}else if(categoryList[cateIdx].equalsIgnoreCase("aws")){
							if(awsSelect != null){
							len = awsSelect.size();
							if(len>0){
							colObjList = new Object[len];
							awsSelect.copyInto(colObjList);
							categoryTitle = "AWS Details";
							}
							}
						}else if(categoryList[cateIdx].equalsIgnoreCase("misc")){
							if(miscSelect != null){
							len = miscSelect.size();
							if(len>0){
							colObjList = new Object[len];
							miscSelect.copyInto(colObjList);
							categoryTitle = "MISC Details";
							}
							}
						}
				
						int headerCount = 0;
						int dataCount = 0;
						if(colObjList != null){
							if(colObjList.length > 0){
%>
						<table width="100%"  cellpadding="0" cellspacing="0" border="0"  align="center" class="printTable">
<%
						if(categoryTitle != null){
%>
							<tr>
								<th align="left" width="100%" class="printTableHeader"><egui:intnl text="<%=\"admin.Asset.\"+categoryTitle%>"/></th>
							</tr>
<%
						}
%>
							<tr><td>
								<table width="100%"  cellpadding="0" cellspacing="0" border="0"  align="center" class="printTable">
<%
									while(true){
										
%>
										<tr>
<%
										for(int j=0; j<5; j++){
											String colName = colObjList[headerCount++].toString();
%>
											<th align="left" width="16%" class="printTableHeader"><egui:intnl text="<%=\"admin.Asset.\"+colName%>"/></th>
<%
											if(headerCount >= colObjList.length)
												break;
										}
%>
										</tr>
										<tr>
<%
										for(int k=0; k<5; k++){
											String colName = colObjList[dataCount++].toString();
%>
											<td align="left" width="16%"><%= colData.get(colName)%></td>
<%
											if(dataCount >= colObjList.length)
												break;
										}
%>
										</tr>
<%
										if(headerCount >= colObjList.length)
											break;
										
									}
%>
								</table>
							</td></tr>
						</table>
<%
						}										
						}
					}
				}
				}
				EgMappingInfo mappingInfo=null;
				String userid = "";
				String userLang = "";
				if(_user != null){
					userid = _user.getLoginID();
					userLang = _user.getLanguage();
				}
				mappingInfo=new EgMappingInfo(userLang);
				String ctype = colData.get("Component Type").toString();
				ctype = mappingInfo.getReverseComponentTypeDescription(ctype);
				String cname = colData.get("Component Name").toString();				
				Hashtable customFields = new Hashtable();
				Hashtable assetCustomData = new Hashtable();
				boolean customFieldReq=false;
				String user_gridColums=servicesIni.getValue("ASSET_GRID_COLUMNS",userid);
				Map map = new HashMap();//compName + ":" + port, cmpType
				if(!StringUtils.isNull(user_gridColums)){
					StringTokenizer userGridColums_st=new StringTokenizer(user_gridColums,",");
					while(userGridColums_st.hasMoreTokens())
					{
						String cName=(String)userGridColums_st.nextToken();
						if(cName.equalsIgnoreCase("custom")){
							customFieldReq=true;
							break;
						}
					}
				}
				if(customFieldReq)
				{
					Hashtable assetDataForComp = new Hashtable();
					ArrayList customColumnList = new ArrayList();
					EgAssetManagementDAO assetMgmtDAO = new EgAssetManagementDAO();
					if (!StringUtils.isNull(ctype) && !StringUtils.isNull(cname))
						{
							assetDataForComp = assetMgmtDAO.getAssetInfoForComponent(ctype+":"+cname);
						}
						if (assetDataForComp != null && !assetDataForComp.isEmpty())
						{
							assetCustomData = (Hashtable)assetDataForComp.get("cols");
							if (assetCustomData != null && !assetCustomData.isEmpty())
							{
								Iterator itr = assetCustomData.keySet().iterator();
								while (itr.hasNext())
								{
									String colName = (String)itr.next();
									String colVal = (String)assetCustomData.get(colName);
									if (StringUtils.isNull(colVal) || colVal.equalsIgnoreCase("none"))
										continue;
									customFields.put(colName,colVal);
								}
							}
						}
%>
							<table width="100%"  cellpadding="0" cellspacing="0" border="0"  align="center" class="printTable">
								<tr>
										<th align="left" width="100%" class="printTableHeader"><egui:intnl text="admin.Asset.Custom Fields"/></th>
								</tr>
								<tr><td>
									<table width="100%"  cellpadding="0" cellspacing="0" border="0"  align="center" class="printTable">
									<tr>
<%
						customColumnList = new ArrayList(customFields.keySet());
						Collections.sort(customColumnList);
						Iterator itr = customColumnList.iterator();
						while(itr.hasNext())
						{
							String customFieldName=(String)itr.next();
%>
									<th align="left" width="16%" class="printTableHeader"><egui:intnl text="<%=\"admin.Asset.\"+customFieldName%>"/></th>
<%
						}
%>
									</tr>
									<tr>
<%
						Iterator itr2 = customColumnList.iterator();
						while(itr2.hasNext())
						{
							String customFieldName=(String)itr2.next();
							String customFieldValue=(String)customFields.get(customFieldName);
%>
									<td align="left" width="16%"><%= customFieldValue%></td>
<%
						}
%>
									</tr>
									</table>
										</td>
									</tr>
								</table>
<%
				}

				if(isSoftareListReq)
				{
					if(cname.indexOf(":")==-1)
					{
						String Compport = discInfo.getPortForHost(cname, ctype);
						cname = cname + ":" + Compport;
					}
					String comp = cname+":"+ctype;
					String[] ec_component = {comp};
					String[] navigatingFrom = {"Current"};
					String[] user_language = {"en_US"};
					String[] ec_test = {"SoftwareList_cf"};
					map.put("ec_component",ec_component);
					map.put("navigatingFrom",navigatingFrom);
					map.put("user_language",user_language);
					map.put("ec_test",ec_test);
					EcCurrentConfigurationBean configBean = new EcCurrentConfigurationBean(map);
					ArrayList al_configDetails = configBean.getConfigurationDetails();
					categoryTitle = "Software List";
					if( al_configDetails != null && !al_configDetails.isEmpty())
					{
%>
								<table width="100%"  cellpadding="0" cellspacing="0" border="0"  align="center" class="printTable">
								<tr>
									<th align="left" width="100%" class="printTableHeader"><egui:intnl text="<%=\"admin.Asset.\"+categoryTitle%>"/></th>
								</tr>
								<tr>
									<td>
										<table width="100%"  cellpadding="0" cellspacing="0" border="0"  align="center" class="printTable">
<%
						for(int m=1;m<al_configDetails.size();m++){
							ArrayList a = (ArrayList)al_configDetails.get(m);
							ArrayList al_columnNames = (ArrayList)a.get(2);
							TreeMap tmap_data = (TreeMap)a.get(3);
%>
											<tr align="left">
<%
							for(int colInx = 0; colInx<al_columnNames.size(); colInx++) {					
								String value = (String)al_columnNames.get(colInx);
								if(value!=null){
%>
												<th align="left" width="26%" class="printTableHeader"><egui:intnl text="<%=\"admin.Asset.\"+value%>"/></th>
<%
								}
							}
%>
											</tr>				
<%
							Iterator iter = tmap_data.keySet().iterator();
		
							while(iter.hasNext())
							{
								String key_info = (String)iter.next();
%>
											<tr align="left">
												<td align="left" width="26%"><%=key_info%></td>
<%
								ArrayList al2 = (ArrayList)tmap_data.get(key_info);
								for(Object data : al2){
%>
												<td align="left" width="26%"><%=data%></td>
<%
								}
%>
											</tr>
<%
							}
						}
%>
										</table>
									</td>	
								</tr>
							</table>
<%
					}
				}
%>
					</td>
				</tr>
				<tr ><td colspan="3" ><hr></td></tr>
<%
				}			
			}
%>
			</table>
<%
		}			
%>
</td>
</tr>
</table>
</body>
</html>
