<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Map" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.docEngine.*" %>
<%@ include file="/sessionInfo.jsp"%>
<%@ include file="/docEngine/docEngineSession.jsp"%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<%
	//获取文件夹显示方式信息
	boolean isTree = false;
	if(docEngineInfo.getTypeShowTree().equals("1")){
		isTree = true;
	}

	//获取信息 以权限设置
	int DLID = Integer.parseInt(szDLID_SESSION);
	String DLXM = szLoginInfo_SESSION.getDLXM();
    boolean canAdd_SESSION = false;
    boolean canPrint_SESSION = false;
    boolean canDelete_SESSION = false;
    boolean canUpdate_SESSION = false;

    //管理资料，只有管理员和有权限的人才能添加。有权限的人员可以查看、修改、删除。
    if (isBarManager_SESSION || docEngineInfo.getModulePopedom().equals("0")) {
        canAdd_SESSION = true;
        canPrint_SESSION = true;
        canDelete_SESSION = true;
        canUpdate_SESSION = true;
    } else {
    	canAdd_SESSION = szPopedom_SESSION.isModuleCanAdd(szModuleInfo_SESSION.getMKID(), szLoginInfo_SESSION.getDLID());
        canPrint_SESSION = szPopedom_SESSION.isModuleCanPrint(szModuleInfo_SESSION.getMKID(), szLoginInfo_SESSION.getDLID());
        canDelete_SESSION = false;
        canUpdate_SESSION = false;
    }
    
%>
<%
		//2012-01-05增加
    String sSearchCond = SzConvert.strWriteDataHTML(request.getParameter("searchCond"));	
    //获取提交的参数
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
    String sPKEY = SzConvert.toZeroStr(request.getParameter("PKEY"));
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteDataHTML(request.getParameter("txtSearch"));
    String sSearch2 = SzConvert.strWriteData(request.getParameter("txtSearch"));
    String sSearchName = SzConvert.strWriteData(request.getParameter("txtSearchName"));
    String XXFL = SzConvert.toZeroStr(request.getParameter("XXFL"));
    
    String toFLID = SzConvert.toZeroStr(request.getParameter("toFLID"));

    ///////////////////////这一块判断是否有分类的管理权限
    //取得本人能管理的所有模块ID
    String strFLID_Manager = "0";
    WdyqType wdyqType = new WdyqType(moduleId);
    strFLID_Manager = wdyqType.getManagerFLID(iDLID_SESSION);
    boolean isMangerFLID = wdyqType.isMangerFLID(strFLID_Manager);
    Map mapType = wdyqType.getMainHashMap("1=1");
    if (isMangerFLID) {
        canAdd_SESSION = true;
    }
    //如果选择了分类，又是该分类的管理员，可以做管理操作
    if (!XXFL.equals("0")) {
    	if(wdyqType.isMangerFLID(strFLID_Manager, XXFL)){
    		//判断是否管理员
            canPrint_SESSION = true;
            canDelete_SESSION = true;
            canUpdate_SESSION = true;
    	}else{
    		WdyqTypeInfo typeInfo = (WdyqTypeInfo)wdyqType.getInfoByKey(Integer.valueOf(XXFL));
    		if(typeInfo!=null&&(","+typeInfo.getFLKTJDL()+",").indexOf(","+DLID+",")>0){
    			canAdd_SESSION = true;
    		}
    	}
    }
    /////////////////////判断分类管理权限

    String sTable_type = "";
    //读取数据
    WdyqDoc wdyqDoc = new WdyqDoc(moduleId);
    WdyqDocInfo wdyqDocInfo = null;
    String sCond = "XXGSID=" + szCOMPANY_SESSION;
    if (!sSearchCond.equals("")) {
    	//sSearchCond = sSearchCond.replaceAll("‘", "'");
    	//sSearchCond = SzConvert.toHTMLString(sSearchCond);
    	//
    	sCond += " AND " + sSearchCond;
    }
    sCond += " AND " + wdyqDoc.getCond(iBMID_SESSION, iDLID_SESSION, 
    						isBarManager_SESSION, strFLID_Manager, XXFL);
    //out.println(sCond);
    String sSortField = SzConvert.toSpaceStr(request.getParameter("txtSortField"));
    int iSortOrder    = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("txtSortOrder")));
    if (sSortField.equals("")) {
    	sSortField = "XXID";
    	iSortOrder = SzProperties.I_SortOrder_DESC;
    }
    int iCurrentPage = 1;
    try {
        iCurrentPage =  Integer.parseInt(sPage);
    }catch(Exception e) {
    }
    //if(XXFL.equals("0")){
	//	sCond += " or ','+ XXFJCKDLID+',' like '%,"+DLID+",%'";
    //}
    //out.println(sCond);
    
    Iterator iter = wdyqDoc.getArrayList(sCond, sSortField, iSortOrder, iCurrentPage, sSearch2).iterator();

    SzPageInfo pageInfo = wdyqDoc.getPageInfo();
    int iPageCount = pageInfo.getPageCount();
    int iRecordCount = pageInfo.getRecordCount();
    iCurrentPage = pageInfo.getCurrentPage();
    int i = 0;
    
    sCond = "FLGSID=" + szCOMPANY_SESSION;
    if (docEngineInfo.getModulePopedom().equals("0")) {
    	sCond += " AND FLDLID=" + szDLID_SESSION;
    } else {
    	sCond += " AND 1=1";
    }
%>
<!-----上面的工具栏------>
<%@ include file="/docEngine/title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>">
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">
  
  <tr>
    <td>
    <% out.println(SzPageHelp.addButtonSubmit(canAdd_SESSION)); %>
    <% out.println(SzPageHelp.deleteButtonUpload(canDelete_SESSION)); %>
    <% if (!isTree&&!docEngineInfo.getTypeName().equals("")) {
         out.println(SzPageHelp.idSelectTreeSubmit(readDocEngineXml.getTypeTable(moduleId) ,"FLID","FLMC","FLBH","XXFL",Integer.parseInt(XXFL), "txtClass200", sCond));
       } else {
    	   out.println("<input type=\"hidden\" name=\"XXFL\" value=\"" + XXFL + "\">");
       }
		//取得本人能管理的所有模块ID
		sCond = "FLGSID=" + szCOMPANY_SESSION;
		String strFLID_Manager2 = "0";
		if (!isBarManager_SESSION && docEngineInfo.getModulePopedom().equals("1")) {
		    strFLID_Manager2 = SzConvert.toZeroStr(wdyqType.getAddFLID(iDLID_SESSION,false));
		    sCond += " AND FLID in ( " + strFLID_Manager + ")";
		} else if (docEngineInfo.getModulePopedom().equals("0")) {
			//个人资料
			sCond += " AND FLDLID=" + szDLID_SESSION + "";
		} else if (docEngineInfo.getModulePopedom().equals("2")) {
			sCond += " AND 1=1";
		}
		
		String selectStr = WdyqDoc.idSelectTreeByFunction(readDocEngineXml.getTypeTable(moduleId),"FLID","FLMC","FLBH", sCond, "toXXFL",Integer.parseInt(toFLID), "txtClass200","FormSubmit2(this,formList,'delete.jsp?OPERATOR=move');");
		if(selectStr.split("<option").length>2){
			out.println(selectStr);
		}
		out.println(SzPageHelp.indexerButton("doc", moduleId, isBarManager_SESSION));
	  %>  
	  <%=SzPageHelp.button("综合查询","javascript:FormSubmit(formBar, 'search.jsp');") %>
    </td>
  </tr>
  </form>
</table>

<!-----信息列表----->
<table width="100%" border="1"  class="tableClass" cellpadding="1" cellspacing="0">

  <form name="formList" method="post">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>">
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">
  <input type="hidden" name="XXFL" value="<%=XXFL%>">  
 
  <tr class="trClassTitle">
    <td width="5"><input type="checkbox" name="chkCheckAll" OnClick="javascript:CheckAll(formList, chkCheckAll, 'chkId');"></td>
    <% if (docEngineInfo.getHasAnnex().equals("1")) {%>
    <td width="5" title="附件标志"><%=SzPageHelp.annexImage(strSkin_SESSION, true)%></td>
    <% } %>
    <% if (!docEngineInfo.getTypeName().equals("")) { %>
    <td width="120"><%=SzPageHelp.sortTitle("分类名称", "XXFL", sSortField, iSortOrder)%></td>
    <% } %>
    <td><%=SzPageHelp.sortTitle("标题", "XXBT", sSortField, iSortOrder)%></td>
    <td><%=SzPageHelp.sortTitle("归档号", "XXBY2", sSortField, iSortOrder)%></td>    
    <td width="120"><%=SzPageHelp.sortTitle("发布时间", "XXSJ", sSortField, iSortOrder)%></td>
    <td width="80"><%=SzPageHelp.sortTitle("发布部门", "XXBMMC", sSortField, iSortOrder)%></td>
    <td width="80"><%=SzPageHelp.sortTitle("发布人员", "XXDLXM", sSortField, iSortOrder)%></td>
    <td width="40">操作</td>
  </tr>
<%
    
    while (iter != null && iter.hasNext()) {
        wdyqDocInfo = (WdyqDocInfo)iter.next();
        i++;
        
        //如果是个人的
        if (docEngineInfo.getModulePopedom().equals("0")) {
        	if (wdyqDocInfo.getXXDLID() == iDLID_SESSION) {
        		canUpdate_SESSION = true;
        	} else {
        		canUpdate_SESSION = false;
        	}
        } else if (docEngineInfo.getModulePopedom().equals("1")) {
        	canUpdate_SESSION = false;
        	if (isBarManager_SESSION) {
        		canUpdate_SESSION = true;
        	} else {
        		XXFL = "" + wdyqDocInfo.getXXFL();
        		//管理类型的
    			if (!XXFL.equals("0") 
    				&& wdyqType.isMangerFLID(strFLID_Manager, XXFL) 
    				&& (wdyqDocInfo.getXXDLID() == iDLID_SESSION)) {
        			canUpdate_SESSION = true;
    			}else if(!XXFL.equals("0")&&docEngineInfo.getManagerCanSee().equals("1")){
    				//这个条件可管理人员可以管理可管理文件夹及下级文件夹的文档
    				if(wdyqType.isMangerFLID(wdyqType.getManagerFLID(iDLID_SESSION),XXFL)){
    				
    				//可管理人员可以有对可管理文件夹下的文档进行管理
    				//if(wdyqType.isMangerFLID(((WdyqTypeInfo)wdyqType.getInfoByKey(wdyqDocInfo.getXXFL())).getFLGLDL(),DLID+"")){
    					canUpdate_SESSION = true;
    				}
    			}
        	}
        }
%>
  <tr  onMouseOver="javascript:this.className='trMouseOver'" onMouseOut="javascript:this.className='trMouseOut'">
    <td width="5" title="<%=i%>">
    <%=SzPageHelp.checkButton("chkId", Integer.toString(wdyqDocInfo.getXXID()) , canUpdate_SESSION)%></td>
    <% if (docEngineInfo.getHasAnnex().equals("1")) {%>
    <td width="5"><%=SzPageHelp.annexImage(strSkin_SESSION, wdyqDoc.hasAnnex(wdyqDocInfo.getXXID()))%></td>
    <% } %>
    <% if (!docEngineInfo.getTypeName().equals("")) { %>
    <td><%=mapType.get(new Integer(wdyqDocInfo.getXXFL()))%>&nbsp;</td>
    <% } %>
    <td><a href="#" OnClick="javascript:FormSubmit(formPage,'detail.jsp?OPERATOR=detail&type=0&KEY=<%=wdyqDocInfo.getXXID()%>');">
        <%=wdyqDocInfo.getXXBT()%>&nbsp;
        </a>
        <%
        if (docEngineInfo.getModulePopedom().equals("1") && docEngineInfo.getHasReadRecord().equals("1")) {
          out.println(SzPageHelp.newImage(strSkin_SESSION, wdyqDoc.hasRead(wdyqDocInfo.getXXID(), iDLID_SESSION)));
        }
        %>
        <%=SzPageHelp.titleHelp(strSkin_SESSION, wdyqDocInfo.getXXZD(), "推荐") %>
        <%=SzPageHelp.titleHelp(strSkin_SESSION, wdyqDocInfo.getXXJH(), "精华") %>
    </td>
    <td><%=wdyqDocInfo.getXXBY2()%>&nbsp;</td>
    <td><%=wdyqDocInfo.getXXSJ()%>&nbsp;</td>
    <td><%=wdyqDocInfo.getXXBMMC()%>&nbsp;</td>
    <td><%=wdyqDocInfo.getXXDLXM()%>&nbsp;</td>
    <td>
      <%
        if (docEngineInfo.getModulePopedom().equals("1") && docEngineInfo.getHasReadRecord().equals("1")) {
          out.println( SzPageHelp.operatorButton(sType, wdyqDocInfo.getXXID(), "feedback.jsp", "feedback", "反馈") );
        }
      %>
      <% out.println( SzPageHelp.viewButton(sType, wdyqDocInfo.getXXID()) );%>
      <% out.println( SzPageHelp.updateButton(sType, wdyqDocInfo.getXXID(), canUpdate_SESSION) );%>
    </td>
  </tr>
<%
    }
    int iLen = 7;
    if (docEngineInfo.getHasAnnex().equals("1")) {
    	iLen ++;
    }
    if (!docEngineInfo.getTypeName().equals("")) {
    	iLen ++;
    }
    out.println(SzPageHelp.outIndexTableTr(i, SzProperties.I_PageSize, iLen));
%>

  </form>
</table>

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="txtSearchName" value="<%=sSearchName%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>">
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">
  <input type="hidden" name="XXFL" value="<%=XXFL%>">  
  <tr>
    <td align="right">
      <%@ include file="/share/page/page_include.jsp"%>
    </td>
  </tr>
  </form>
</table>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>">
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">
  <input type="hidden" name="XXFL" value="<%=XXFL%>">    
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<%
  mapType = null;
%>
<script language="javascript">
  //第一个表示对象，form，第二个表示字符串
  function FormSubmit2(obj,oFormName, vUrl) {
  	if(obj.value=="0"){
  		alert("请选择文件夹！");
  		return false;
  	}
  	if(confirm("确定要转移选中的文件？")){
	    oFormName.action = vUrl+"&toFLID="+document.getElementById("toXXFL").value;
	    oFormName.submit();
    }
  }
</script>