/** @see com.pureinfo.ark.interaction.ActionBase#beforeExecution() */
  protected ActionForward beforeExecution() throws PureException {
    Product product = (Product) getSearchBean();
    SRMWebUtil.propertyAndOrSearch((SearchForm) form, request);

    String sProductForm = product.getProductForm();

    // 1. to validate the authorization
    IAuth2Mgr authMgr = Auth2Helper.getManager();
    ISQLLogic logic = authMgr.getSQLLogicRule(loginUser, product, ArkActionTypes.LIST);
    if (logic == SQLLogicString.FALSE) {
      String sDesc =
          (StringUtils.isEmpty(sProductForm)) ? "成果" : ProductConstants.getDescByForm(sProductForm);
      throw new PureException(ArkExceptionTypes.AUTH_NO_RIGHT, "对不起,您没有权限查看" + sDesc + "列表!");
    }

    // 2. to add the restriction
    QueryFilter filter = ((SearchForm) form).getQueryFilter();
    OrganizationHelper.addOrgTypeFilter(filter, request);
    /** 此处需要讨论 if (logic != SQLLogicString.TRUE) { filter.addCondition(logic); } */

    // 3. to parse some special parameters
    int nCurrRange = this.getRange();

    // 获奖与鉴定的年份小搜索是具体的年份

    if (StringUtils.isNotEmpty(sProductForm)) {
      if (sProductForm.equals(ProductConstants.SPRODUCT_FORM_HONOR)) {
        if (nCurrRange != 0) {
          filter.addCondition("year(publish_date)=" + nCurrRange);
          // filter.addOrder("{this.rank}");
        }
      } else if (sProductForm.equals(ProductConstants.SPRODUCT_FORM_APPRAISE)) {
        if (nCurrRange != 0) {
          filter.addCondition("{this.publicationYear}=" + nCurrRange);
        }
      } else {
        if (!(nCurrRange == RANGE_ALL)) {
          filter.addPropertyCondition(
              "this",
              "publishDate",
              SQLOperator.BETWEEN,
              new Date[] {getBeginYear(), getEndYear()});
        }
      }
    } else {
      String sPaperForm = request.getParameter("paperForm");
      if (sPaperForm != null) {
        if (sPaperForm.equals(ProductConstants.SPRODUCT_FORM_HONOR)) {
          filter.addPropertyCondition("this", "productForm", SQLOperator.EQUAL, sPaperForm);
          // filter.addOrder("{this.rank}");
        } else {
          String[] _sPaper =
              new String[] {
                ProductConstants.SPRODUCT_FORM_PAPER, ProductConstants.SPRODUCT_FORM_MONOGRAPH
              };
          filter.addPropertyCondition("this", "productForm", SQLOperator.IN, _sPaper);
          // 显示范围
          filter.addPropertyCondition(
              "this", "publishDate", SQLOperator.GREATER_OR_EQUAL, getBeginYear());
          filter.addPropertyCondition(
              "this", "publishDate", SQLOperator.LESS_OR_EQUAL, getEndYear());
        }
        String sOrderBy = request.getTrimedParameter("orderBy");
        if (sOrderBy == null || sOrderBy.length() == 0) {
          filter.setOrder("{this.lastModifiedTime} DESC, " + filter.getOrder());
        }
      }
    }

    // set default order for honor list and appraise list
    if (ProductConstants.SPRODUCT_FORM_HONOR.equals(sProductForm)
        || ProductConstants.SPRODUCT_FORM_APPRAISE.equals(sProductForm)) {
      String sOrderBy = request.getTrimedParameter("orderBy");
      if (sOrderBy == null || sOrderBy.length() == 0) {
        // filter.setOrder("YEAR({this.publishDate})
        // DESC,{this.level}");
        filter.setOrder("{this.rank},YEAR({this.publishDate}),{this.level}");
      }
    }

    return super.beforeExecution();
  }
  public String getTailedButtons() throws PureException {
    SRMUser user = (SRMUser) loginUser;
    String sProductForm = request.getParameter("dp_productForm");

    if (request.getParameter("paperForm") != null) {
      Product product = new Product();
      product.setProductForm(ProductConstants.SPRODUCT_FORM_PAPER);
      product.setCollege(user.getCollegeId());
      if (Auth2Helper.getManager().hasRight(loginUser, product, ArkActionTypes.AUDIT, false)) {
        StringBuffer sbuff = new StringBuffer();
        try {
          sbuff.append("<BUTTON class=\"img_button\" onClick=\"if(count()<1)alert('请至少选择一项');");
          sbuff.append("else{if(confirm('确实要打回为待审核吗?')){");
          sbuff.append("this.disabled=true;mainForm.action='../product/productBackWaitCheck.do");
          sbuff.append("';mainForm.target='_blank';mainForm.submit();}}\">");
          sbuff.append(
              "<img align=\"absMiddle\" src=\"../images/return.gif\">打回待审核</button>&nbsp;&nbsp;");
          return sbuff.toString();
        } finally {
          sbuff.setLength(0);
        }
      }
    }

    if (user.isAdmin1() || user.isProductAdmin()) {
      if (ProductConstants.SPRODUCT_FORM_HONOR.equals(sProductForm)
          || ProductConstants.SPRODUCT_FORM_APPRAISE.equals(sProductForm)) {
        StringBuffer sbuff = new StringBuffer();
        try {
          if (ProductConstants.SPRODUCT_FORM_HONOR.equals(sProductForm)) {
            sbuff.append("<BUTTON class=\"img_button\" onClick=\"if(count()<1)alert('请至少选择一项');");
            sbuff.append("else{doCompile();this.disabled=true;}\">");
            sbuff.append(
                "<img align=\"absMiddle\" src=\"../images/word.gif\">奖励汇编</button>&nbsp;&nbsp;");
            sbuff.append("<script>");
            sbuff.append("	function doCompile() {");
            sbuff.append("    	var aa = document.getElementsByName('id');");
            sbuff.append("var ids = '';");
            sbuff.append("for(var i=0;i<aa.length;i++){");
            sbuff.append("if(aa[i].checked){");
            sbuff.append("ids += aa[i].value + ',';");
            sbuff.append("}");
            sbuff.append("}");
            sbuff.append("document.HeadForm.ids.value = ids;");
            sbuff.append("document.HeadForm.action = '../product/honor-compile-type-select.jsp';");
            // sbuff.append("document.HeadForm.target='_blank';");
            sbuff.append("document.HeadForm.submit();");
            sbuff.append("}");
            sbuff.append("</script>");
          }
          sbuff.append("<BUTTON class=\"img_button\" onClick=\"if(count()<1)alert('请至少选择一项');");
          sbuff.append("else{if(confirm('确实要修改选中奖励吗?')){");
          sbuff.append(
              "this.disabled=true;mainForm.action='../product/ProductBatchEditDatumAndCer.do?");
          sbuff.append("actionType=cer&dp_productForm=").append(sProductForm);
          sbuff.append("';mainForm.submit();}}\">");
          sbuff.append(
              "<img align=\"absMiddle\" src=\"../images/edit.gif\">证书存档批量修改</button>&nbsp;&nbsp;");
          sbuff.append("<BUTTON class=\"img_button\" onClick=\"if(count()<1)alert('请至少选择一项');");
          sbuff.append("else{if(confirm('确实要修改选中奖励吗?')){");
          sbuff.append(
              "this.disabled=true;mainForm.action='../product/ProductBatchEditDatumAndCer.do?");
          sbuff.append("actionType=datum&dp_productForm=");
          sbuff.append(sProductForm).append("';mainForm.submit();}}\">");
          sbuff.append(
              "<img align=\"absMiddle\" src=\"../images/edit.gif\">材料存档批量修改</button>&nbsp;&nbsp;");
          return sbuff.toString();
        } finally {
          sbuff.setLength(0);
        }
      }
    }

    return null;
  }