<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.security.ireport.model.vo.*"%>
<%@ page import="com.security.ireport.engine.definition.*"%>
<%@ page import="com.security.ireport.engine.ReportConstants"%>
<%@ page import="com.security.ireport.util.IReportUtil"%>
<%@ page import="com.security.ireport.util.IReportConfCheckUtil"%>
<%@ page import="com.security.ireport.util.EscapeUtil"%>
<%@ page import="com.security.ireport.util.chart.LegendUtil"%>
<%@ page import="com.security.ireport.util.TableGroupShowUtil.ClassCount"%>
<%@ page import="com.security.ireport.util.TableGroupShowUtil"%>
<%@ page import="com.hs.atic.util.AticUtil" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page isELIgnored="false" %>
<%
	
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
	String sessionId = String.valueOf(request.getAttribute("sessionId"));
%>
<input type="hidden" id="sessionId" name="sessionId" value="<%=sessionId%>" />
<%		
	TableObj tableObj = (TableObj) request.getAttribute("tableObj");	
%>
<table cellspacing="0" cellpadding="0" class="table_list"
	align="center" id="tab_List" style="margin-top:5px;">

<%
if(!IReportConfCheckUtil.isStringEmpty(tableObj.getTableHeader()))
{
%>
<tr>
<td colspan="<%=tableObj.getColumnList().size()+1%>">
<%
out.print(tableObj.getTableHeader());
%>
</td>
</tr>
<% 
}
%>

<tr><td colspan="<%=tableObj.getColumnList().size()+1%>">
	
<%
if (tableObj.isTopPageBarShow()) 
{ 
%>
    <jsp:include page="pagesp.jsp" flush="true"></jsp:include>
<% 
}
%>
</td></tr>


<%
if(!tableObj.getHeaderRowList().isEmpty())
{
    HeaderRow row;
    HeaderColumn column;
    for(int i=0; i< tableObj.getHeaderRowList().size(); i++)
    {
        row = tableObj.getHeaderRowList().get(i);
        %>
        <tr>
        <%
        for(int j=0; j<row.getHeaderColumnList().size(); j++)
        {
            column = row.getHeaderColumnList().get(j);
            %>
            <td class="report_td_title_serialNumber" colspan=<%=column.getColspan()%>>
             <%
             out.print(IReportUtil.transHtml(column.getValue()));
             %>
            </td>
            <%
        }
        %>
        </tr>
        <%
    }
}
%>


<tr class="ireport_head_row">
	<% 
	if(!tableObj.isFlexTable() && tableObj.isSerialNumShow())
	{ 
	%>
		<td class="td_list_title_left">&nbsp;&nbsp;&nbsp;&nbsp;</td>
	<%
	}
	int tableWidth = 0;
	for (int i = 0; i < tableObj.getColumnList().size(); i++) {
		IRColumn columnObj = (IRColumn)tableObj.getColumnList().get(i);
		tableWidth = tableWidth + Integer.valueOf(columnObj.getWidth());
	}
	for (int i = 0; i < tableObj.getColumnList().size(); i++) {
		IRColumn columnObj = (IRColumn)tableObj.getColumnList().get(i);
		 %>
	<td class="report_td_title_serialNumber" width="<%=Integer.valueOf(columnObj.getWidth()) * 99 / tableWidth%>%">
		<% 
		if(!tableObj.isFlexTable())
		{ 
		    if (columnObj.getSortable().equals("true"))
		    {
		%>
		<a style="cursor:pointer;color:#464646;font-weight:bold;font-family:arial,'宋体';"  title="<s:text name='page.sort'/>" href="javascript:changeSort('<%=columnObj.getField() %>')"><%out.print(columnObj.getHeader()); %></a>
		<%      if (columnObj.getField().equals(tableObj.getOrderInfo().getOrderField())) {
					if (tableObj.getOrderInfo().getOrderType().equals("ASC")) {%>
						<img src="<s:url value='/iReport/images/vsm_sort_asc.gif' includeParams='none' />" >
					<%}
					if (tableObj.getOrderInfo().getOrderType().equals("DESC")) {%>
						<img src="<s:url value='/iReport/images/vsm_sort_desc.gif' includeParams='none' />" >
				<%	 }
			    }
			}
			else
			{
			%>
			<span style="width: 4px;"></span>
		    <%
				
				out.print(columnObj.getHeader());
			%>
			<%		
			}
		}
		else
		{
		    if(IReportConfCheckUtil.isStringEmpty(columnObj.getDataDrillAction()))
			{
			%>
			<span style="width: 4px;"></span>
			<%
				out.print(columnObj.getHeader());
			%>
			<%		
			}
			else
			{
				String outPrintValue = "<a style='cursor:pointer;color:#464646;font-weight:bold;font-family:arial,'宋体';' href=\"javascript:window.open('"+LegendUtil.changeToWOS(basePath+"/"+columnObj.getDataDrillAction())+"')\">"+columnObj.getHeader()+"</a>";
				out.print(outPrintValue);
			}
		}
		    %>

	</td>
<% 
	}							
%>
</tr>
<% 
if(null != tableObj.getGroupTableCellNodeList())
			{
				StringBuilder builder = new StringBuilder() ;
				ClassCount count = new ClassCount() ;
				TableGroupShowUtil.showTableCellNode(tableObj , tableObj.getGroupTableCellNodeList() , count , tableObj.getColumnList() , basePath , builder , 0) ;
				out.print(builder.toString()) ;
			}
			else 
			{
if (tableObj.getCellOjbListMap() == null || tableObj.getCellOjbListMap().isEmpty()) 
{

%>
			<tr>
				<td class="report_td_list_resultContent" colspan="<%=tableObj.getColumnList().size() + 1%>">
					<s:text name="page.nodata"/>
				</td>
			</tr>
<% 
}

%>
<%
List<TableCellObj[]> dataSet = null;
for(String groupValue : tableObj.getGroupKeyList())
{
    dataSet = tableObj.getCellOjbListMap().get(groupValue);
    
for (int i = 0; i < dataSet.size(); i++)
{
	if (i%2 == 0)
	{
	%>
		<tr class="ireport_tr_line2">
<%  }
	else
	{
	%>
		<tr class="ireport_tr_line1">
	<%
	}  
	if(!tableObj.isFlexTable() && tableObj.isSerialNumShow())
	{ 
	%>
	<td class="td_sn">
		<%out.print(i + 1);%>&nbsp;
	</td>
	<% 
	} %>
	<%
		for (int j = 0; j < tableObj.getColumnList().size(); j++) {
		    
			TableCellObj[] column = dataSet.get(i);
			String colTooltips = tableObj.getColumnList().get(j).getTooltips();
			IRColumn dcolumn = tableObj.getColumnList().get(j);
			if(tableObj.isFlexTable())
			{
				if(0 == j)
				{
			%>
			<td class="ireport_table_td" style="text-align:center">
			<%  }
				else
				{
				%>
				<td class="ireport_table_td" style="text-align:center">
				<% 
				} 		
			}
			else 
			{
			    if(0 == j && !groupValue.equals(ReportConstants.DEFAULT_GROUP_NAME))
				{
			        if(0 == i)
			        {
			            %>
						<td class="ireport_table_td" rowspan="<%=dataSet.size() %>" <%=tableObj.getColumnList().get(j).getTextAlignStyle()  %> >
						<%
			        }
			        else
			        {
			            continue;
			        }
				}
			    else
			    {
			        %>
			        <td class="ireport_table_td" <%=tableObj.getColumnList().get(j).getTextAlignStyle()  %> >
			        <%
			    }
			}
			
			try
			{
			    String outPrintValue = "";
			    if(false == IReportConfCheckUtil.isStringEmpty(column[j].getImgPath()))
			    {
			        outPrintValue ="<img border=\"0\" src=\"" + column[j].getImgPath() + "\" >";
			    }
			    else
			    {
			        outPrintValue = (column[j].getDataText());
			    }
			    
				
				if(!IReportConfCheckUtil.isStringEmpty(column[j].getUrlText()))
				{
					if(column[j].getDataTextList().isEmpty() || (false == IReportConfCheckUtil.isStringEmpty(column[j].getImgPath())))
					{
					    String urlText = column[j].getUrlText();
						if(!IReportConfCheckUtil.isStringEmpty(column[j].getDataDrillCond()))
						{
							if(urlText.indexOf("&") > 0)
							{
    							urlText += "&";
							}	
							else
							{
								urlText += "?";
							}
							urlText += column[j].getDataDrillCond();
						}
						if(!IReportConfCheckUtil.isStringEmpty(dcolumn.getDataDrillTitle()))
						{
							urlText += "&dataDrillTitle="+dcolumn.getDataDrillTitle();
						}
						if(dcolumn.isUserJavaScript())
						{
							outPrintValue = "<a href=\"#\" onclick=\""+urlText+"\">"+outPrintValue+"</a>";
					    }
						else
					    {
							outPrintValue = "<a href=\"javascript:window.open(('"+LegendUtil.changeToWOS(basePath+"/"+urlText).replace("'", "\\'").replace("\"", "\\&quot;")+"'),'_blank');void(0);\">"+outPrintValue+"</a>";
						}
					}
				    else
				    {
				        outPrintValue = "";
				        if(dcolumn.isUserJavaScript()){
				        outPrintValue += "<a href=\"#\" onclick=\""+column[j].getUrlTextList().get(0)+"\">"+(column[j].getDataTextList().get(0))+"</a>";
				     	}else{
				     	outPrintValue += "<a href=\"javascript:window.open(('"+LegendUtil.changeToWOS(basePath+"/"+column[j].getUrlTextList().get(0)+"&dataDrillTitle="+dcolumn.getDataDrillTitle()).replace("'", "\\'").replace("\"", "\\&quot;")+"'),'_blank');void(0);\">"+(column[j].getDataTextList().get(0))+"</a>";
				     	}
				     	for(int k=1;k<column[j].getDataTextList().size();k++)
				     	{
 
				     	   if(dcolumn.isUserJavaScript()){
					        outPrintValue += " | <a href=\"#\" onclick=\""+column[j].getUrlTextList().get(k)+"\">"+(column[j].getDataTextList().get(k))+"</a>";
					     	}else{
					     	outPrintValue += " | <a href=\"javascript:window.open(('"+LegendUtil.changeToWOS(basePath+"/"+column[j].getUrlTextList().get(k)+"&dataDrillTitle="+dcolumn.getDataDrillTitle()).replace("'", "\\'").replace("\"", "\\&quot;")+"'),'_blank');void(0);\">"+(column[j].getDataTextList().get(k))+"</a>";
					     	}
				     	}
				    }
					out.print(IReportUtil.transHtml(outPrintValue));
				}
				else if (colTooltips.length() != 0 && outPrintValue.length() > Integer.valueOf(colTooltips))
				{
					%>
                    <%
						String title = AticUtil.htmlDecode(outPrintValue);
						String subDecodeStr = title.substring(0, Integer.valueOf(colTooltips));
						String subOutPrintValue = AticUtil.htmlEncodeCore(subDecodeStr);
                    %>
					<a id="toolTip<%=i%>"  style="color:#000000;"><%=subOutPrintValue%>...</a>
				    <script type="text/javascript">
					var strToolTip ="toolTip<%=i%>";
					var buffer="<%=title%>";
					if (buffer.length > 0)
					{
					  var titleBuffer = '';
					  var str = ''; 
				      for(var n = 0; n < buffer.length;n++)
				      {
				        str = buffer.substring(n,n+1);
				        titleBuffer+= str;
				        if(n!=0 && n%75==0)
				         {
				          titleBuffer+=" ";
				         }
				      }
				      $("#"+ strToolTip).attr("title", titleBuffer);
				    }
					</script>			
					<%
				}
				else
				{
				    out.print(IReportUtil.transHtml(outPrintValue));
				}
			}
			catch(Exception e)
			{
				out.print(IReportUtil.transHtml(column[j].toString()));
			}
			%>
		</td>
	<% 
		}
	%>
</tr>
<% 
}
}

}
%>
<%
if (tableObj.isPageShow()) 
{ 
%>
<tr><td colspan="<%=tableObj.getColumnList().size()+1%>">

	<jsp:include page="pagesp.jsp" flush="true"></jsp:include>
</td></tr>
<% 
}
%>
<%
if(!IReportConfCheckUtil.isStringEmpty(tableObj.getTableFooter()))
{
%>
<tr><td colspan="<%=tableObj.getColumnList().size()+1%>">
<%
out.print(tableObj.getTableFooter());
%>
</td></tr>
<% 
}
%>
</table>	
<input type="hidden" id="orderField" name="orderField" value="<%=tableObj.getOrderInfo().getOrderField() %>" />	
<input type="hidden" id="orderType" name="orderType" value="<%=tableObj.getOrderInfo().getOrderType() %>" />				
<input type="hidden" id="pageNum" name="pageNum" value="<%=tableObj.getPageNum() %>" />
<input type="hidden" id="pageSize" name="pageSize" value="<%=tableObj.getPageSize() %>" />
<input type="hidden" id="totalPageNum" name="totalPageNum" value="<%=tableObj.getTotalPageNum() %>" />
<input type="hidden" id="totalRecordNum" name="totalRecordNum" value="<%=tableObj.getTotalNum() %>" />
