<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.CallableStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="com.stfoa.dao.hibernate.DocumentDAO"%>
<%@page import="com.myoa.common.util.DESUtil"%>
<%@page import="java.math.BigInteger"%>
<%@page import="com.myoa.common.util.FormatUtil"%>
<%@page import="com.stfoa.domain.Employee"%>
<%@page import="org.apache.commons.lang.StringEscapeUtils"%>
<%@include file="/common/include/taglibs.jsp"%>
<html>
<head>
<%@include file="/common/include/meta.jsp"%>
<%@include file="/common/include/jquery.jsp"%>
<link href="${ctx}/common/css/desktop.css" rel="stylesheet" type="text/css">
<SCRIPT src="${ctx}/common/js/showdoc.js" type=text/javascript></SCRIPT>
</head>
<script type="text/javascript">
//保持跟踪
function keepTag(docId){
 if(window.confirm('本事项设为“保持跟踪”后，将始终显示在“我的跟踪事项”中，\r\n直至执行“取消跟踪”时为止，您确认吗？')){
  ajaxQuery('${ctx}/collaborate.do?actionmethod=keeptag&docId='+docId,ajaxQueryHandler,'text');
 }
}

//取消跟踪
function undoTag(docId){
 if(window.confirm('取消跟踪后，本事项将从“我的跟踪事项”中消失，您确认要取消跟踪吗？')){
  ajaxQuery('${ctx}/collaborate.do?actionmethod=undotag&docId='+docId,ajaxQueryHandler,'text');
 }
}

 function ajaxQueryHandler(responseText){
  if(responseText=='success'){
    location.reload();
  }else if(responseText=='fail'){
    alert('操作失败！');
  }else{
    alert(responseText);
  }
 }
</script>
<% 
 Employee self = (Employee) session.getAttribute("session_employee");
 Integer empid = self.getEmpId();	
 DocumentDAO docdao = new DocumentDAO();
 String sqlcount1 = "select count(*)"+
 " from oa_tbl_document as doc,oa_tbl_employee as emp,oa_tbl_department as dept"+
 " where emp.empid=doc.empid and dept.deptid=emp.deptid  and doc.docType=1 and doc.docstatus!=0 and doc.docstatus!=6 and doc.docstatus<24 and doc.empid="+empid+" and ((doc.tagFlag=4)"+
 " or(doc.tagFlag=1 and (select count(*) from oa_tbl_documentinstance as instance where instance.docId=doc.docid and instance.status<4)>0))";
 BigInteger count1 = (BigInteger)docdao.getSession().createSQLQuery(sqlcount1).uniqueResult();
 String sqlcount2 = "select count(*)"+
	 " from oa_tbl_documentinstance as instance,oa_tbl_document as doc,oa_tbl_employee as emp,oa_tbl_department as dept"+
	 " where doc.docId=instance.docId and emp.empid=doc.empid and dept.deptid=emp.deptid  and instance.empid="+empid+" and instance.tagFlag=4";
 BigInteger count2 = (BigInteger)docdao.getSession().createSQLQuery(sqlcount2).uniqueResult();
 Connection conn = docdao.getSession().connection();
 CallableStatement stmt = null;
 ResultSet rs = null;
  try{
	  stmt = conn.prepareCall("{call sp_oa_dotagpage(?,?,?)}");   
	  stmt.setInt(1,self.getEmpId());
	  stmt.setInt(2,0);
	  stmt.setInt(3,8);
     rs = stmt.executeQuery();
     
%>
<body onkeydown=return(!(event.keyCode==78&&event.ctrlKey)) oncontextmenu="return false" 
onselectstart="self.event.returnValue=false"  ondrag="return false">
   <table width="100%"  height="100%" border="1" align="center" cellpadding="0" cellspacing="1"  style="background-color:whitesmoke;border-color: #ECE9D8;">
      <tr>
        <td height="20" bgcolor="buttonface">
         <div style="float:left;">
        <img src="${ctx}/common/images/tuding.gif" valign=bottom>&nbsp;&nbsp;<b>我的跟踪事项（<%=count1.add(count2)%>项）</b>
        </div>
        <div style="float:right;">
        <a href="#" onclick="parent.location.href='${ctx}/jsp/collaborate/tag/index.jsp'"><font color='black'><B>[更多...]</B></font></a>
        </div>
        </td>
      </tr>
      <tr>
        <td>
        
			 <table width=100% height=100% align="center" cellspacing="0"  style="background-color:white;border-color: #ECE9D8;">
			 <%int numtag=0; %>
			<%if(rs!=null){%>	
			<%while(rs.next()){ %>    
		    <%
		     numtag++; 
		     Integer empId = rs.getInt("empId");
		     String docId =  DESUtil.doEncrypt(rs.getInt("docId")+"");
		     Short hasAttach = rs.getShort("hasAttach");
		     Short tagFlag = rs.getShort("tagFlag");
		     Timestamp createTime = rs.getTimestamp("docCreatTime");
		     String docTitle = rs.getString("docTitle");
		     String empName = rs.getString("empName");
		    %>
           <tr id=infoRow style="font-weigth:;">
		      <td bgcolor=#ffffff height=20 valign=bottom width="4%"> <p><img border=0 height=11 src="${ctx}/common/images/arrow_circle.gif" width=11></p></td>
		      <td bgcolor=#ffffff height=20 valign=bottom style="BORDER-BOTTOM: 1px solid;"  width="50%">  
			  <a title=<%=StringEscapeUtils.escapeHtml(docTitle)%> 
			  href="javascript:showDoc('<%=docId.toString()%>','<%=hasAttach%>','${ctx}','<%=FormatUtil.formatDate("yyyyMMddHHmmss",createTime)%>')">
			  <%if(empId != empid.intValue() || tagFlag==4){ %><img border=0 src="${ctx}/common/images/tuding.gif"><%} %>
			  <%=StringEscapeUtils.escapeHtml(FormatUtil.formatString(docTitle,12))%>
			  <%if(hasAttach>0) out.print("<img border=0  src='"+request.getContextPath()+"/common/images/attachment.gif'>"); %>
			  </a>
			  </td>
		      <td bgcolor=#ffffff height=20 style="BORDER-BOTTOM: 1px solid" valign=bottom width="14%" >
			   <%if(empId==empid.intValue()){ %>
		      <label title=<%=empName%>><%=FormatUtil.formatString(empName,4) %></label>
		      <%}else{ %>
			  <a title=<%=empName%> href="#" onclick="parent.location.href='relaemp/empInfo.jsp?relaType=othertoyou&otherEmpId=<%=empId%>'"><%=FormatUtil.formatString(empName,4) %></a></td>
			  <%}%>
		      <td bgcolor=#ffffff height=20 style="BORDER-BOTTOM: 1px solid" valign=bottom width="20%" >
			<p style="MARGIN-TOP: 3px"><%=FormatUtil.formatDate("MM-dd HH:mm",createTime)%></p></td>
			<td bgcolor=#ffffff height=20 style="BORDER-BOTTOM: 1px solid" valign=bottom width="12%" >
			<%if(empId != empid.intValue()){%>
           <img style="filter:gray;" border=0 height=11 src="${ctx}/common/images/tag_small_grey.gif" width=14   title="已保持跟踪">
           <img onclick=undoTag('<%=docId%>') border=0 height=11 src="${ctx}/common/images/del_small.gif" width=14 style="cursor:hand" onmouseover="this.height=12;this.width=14" onmouseout="this.height=11;this.width=14" title="取消跟踪"> 
         <%}else{
           if(tagFlag==4){
         %>
           <img  border=0 height=11 src="${ctx}/common/images/tag_small_grey.gif" width=14   title="已保持跟踪">
           <img onclick=undoTag('<%=docId%>') border=0 height=11 src="${ctx}/common/images/del_small.gif" width=14 style="cursor:hand" onmouseover="this.height=12;this.width=14" onmouseout="this.height=11;this.width=14" title="取消跟踪">

          <%}else{ %>
           <img onclick=keepTag('<%=docId%>') border=0 height=11 src="${ctx}/common/images/tag_small.gif" width=14 style="cursor:hand" onmouseover="this.height=12;this.width=14" onmouseout="this.height=11;this.width=14" title="保持跟踪">
           <img onclick=undoTag('<%=docId%>') border=0 height=11 src="${ctx}/common/images/del_small.gif" width=14 style="cursor:hand" onmouseover="this.height=12;this.width=14" onmouseout="this.height=11;this.width=14" title="取消跟踪">
          <%}
          } %> 
			</td>
		    </tr>
           <%} %>
          <%
           rs.close();
           stmt.close();
          } %>
         <% while(numtag<8){
		     numtag++;
		 %>
		 <tr>
		   <td bgcolor=#ffffff height=20 valign=bottom width="5%"> <p><img border=0 height=11 src="${ctx}/common/images/arrow_circle.gif" width=11></p></td>
		   <td height=20  width="95%" align=right colspan=4  style="BORDER-BOTTOM: 1px solid">&nbsp;</td>
		 </tr>
		       
		<%} %>
		
          </table>
          
        </td>
      </tr>
    </table>
  </body>
  <% }catch(Exception e){
  }  %>
</html>
