<%@page language="java" contentType="text/html; charset=UTF-8"%> <%@page import="java.util.Iterator"%> <%@include file="./config.jsp" %> <%@include file="include/SurveyConfBLF.jsp" %> <%@include file="include/SurveyDefaBLF.jsp" %> <%@include file="include/SurveyTagParse.jsp" %> <%@page import="jcms.publish.Publish"%> <%@page import="jcms.blf.user.UserRightBLF"%> <%@page import="jcms.make.makeunit.Unit"%> <% int iFormId = Convert.getParameterInt(request,"formid"); //表单ID int iBuild = Convert.getParameterInt(request,"build"); //手动生成文件并发布 int iPreview = Convert.getParameterInt(request,"preview"); //是否为预览 int isCus = Convert.getParameterInt(request,"isCus"); if(iFormId==0){ LogWriter.error("Form id is null!"); return; } String webPath = application.getRealPath("") + File.separator + "jcms_files" + File.separator + "jcms" + strAppID + File.separator + "web" + strWebID + File.separator +"site"+File.separator; String confPath = webPath + "module" + File.separator + "survey" + File.separator + "config" + File.separator + "config.xml"; String loadhtmlPath = webPath + "module" + File.separator + "survey" + File.separator + "html" + File.separator + "loadform_" + iFormId + ".html"; String webtype = xmlFile.getContent( "webtype",confPath ); //1:内网 2:外网 String appName = xmlFile.getContent( "web_in_servername",confPath ); String modulePath; if(webtype.trim().equals("1")) modulePath = request.getContextPath() + "/jcms_files/jcms" + strAppID + "/web" + strWebID + "/site/module/"; else modulePath = "/module/"; SurveyFormBLF formBlf = new SurveyFormBLF(strAppID,Convert.getStringValueInt(strWebID)); SurveyFormEntity formEn = formBlf.getEntity(iFormId); if(formEn==null){ LogWriter.error("The form does not exist!"); return; } boolean isShow = formEn.getB_show() == 1 ? true : false; if(!isShow){ LogWriter.message("The form is set invisible!"); return; } //默认设置 SurveyDefaBLF defaBlf = new SurveyDefaBLF(strAppID,Convert.getStringValueInt(strWebID)); //解析配置 HashMap confMap = new HashMap(); confMap.put("showResult",""+formEn.getB_showresult()); confMap.put("showAnswer",""+formEn.getB_showanswer()); confMap.put("currentPath",modulePath); confMap.put("formId",""+iFormId); confMap.put("cateId",""+formEn.getI_cateid()); String name = ""; //标签 if(isCus == 1){ String strName = "SELECT vc_cataname FROM jcms_cataloginfo WHERE i_id = " + formEn.getVc_name(); String[][] sqlName = Manager.doQuery("1",strName); if(sqlName != null && sqlName.length > 0){ name = Convert.getValue(sqlName[0][0]); confMap.put("title",name); } }else{ name = formEn.getVc_name(); confMap.put("title",name); } confMap.put("desc",formEn.getVc_desc()); confMap.put("createtime",formEn.getC_createtime()); confMap.put("starttime",formEn.getC_starttime()); confMap.put("endtime",formEn.getC_endtime()); confMap.put("formid",""+iFormId); String regEx = "(?s:.*?)"; String strContent = ""; String temp = ""; String style = ""; SurveyDefaEntity defaEn = defaBlf.getEntity(); boolean haveDefa = true; if(defaEn==null){ defaEn = new SurveyDefaEntity(); } SurveyTagParse parse = new SurveyTagParse(strAppID,Convert.getStringValueInt(strWebID)); int state = parse.getState(formEn.getC_starttime(),formEn.getC_endtime(),formEn.getB_show()); System.out.println("state = "+state); String tempPath = webPath + "module" + File.separator + "survey" + File.separator + "template"; String defaPath = webPath + "module" + File.separator + "survey" + File.separator + "config"; String filePath = "/" + appName + "/jcms_files/jcms" + strAppID + "/web" + strWebID + "/site/"; Unit unit = new Unit(strAppID, Convert.getStringValueInt(strWebID)); switch(state){ case 0: //未开始 temp = defaBlf.getModal("survey_beforeaffi",application.getRealPath(""),iPreview); if(!haveDefa||temp==null||temp.length()==0){//没有设置默认 Convert cv = new Convert(); temp = cv.readInputStream(tempPath+File.separator+"default.html", "UTF-8"); } style = defaEn.getVc_beforeaffistyle().replaceAll("\r\n",""); if(!haveDefa||style==null||style.length()==0){//没有设置默认 String beforeConfPath = defaPath + File.separator + "beforeaffi.xml"; style = xmlFile.getContent("stylecode",beforeConfPath); style = style.substring(10,style.length()-4).replaceAll("\r\n",""); } String beforeAffiContent = formEn.getVc_startaffiche(); if(!haveDefa||beforeAffiContent==null||beforeAffiContent.length()==0){//没有设置默认 beforeAffiContent = "调查尚未开始!"; } confMap.put("affiche",beforeAffiContent); //公告内容 strContent = parse.parseTag(style,confMap); Pattern p1 = Pattern.compile(regEx); Matcher m1 = p1.matcher(temp); String tag1 = ""; if(m1.find()){ tag1 = m1.group(); //标签和内容 }else{ LogWriter.error("Tag1 is not set!"); return; } strContent = temp.replaceFirst(tag1,strContent); //解析正文中的video代码 strContent = unit.parseVideoCode(strContent, strAppID, Convert.getStringValueInt(strWebID) + ""); strContent = "" + strContent; if(webtype.trim().equals("2")){ strContent = strContent.replaceAll(filePath,"/"); } out.println(strContent); return; case 1: //进行中 if(formEn.getB_updatehtml()==1&&iBuild==0&&iPreview!=1){ File htmlFile = new File(loadhtmlPath); if(htmlFile.exists()){ Convert cv = new Convert(); strContent = cv.readInputStream(loadhtmlPath, "UTF-8"); if(webtype.trim().equals("2")){ strContent = strContent.replaceAll(filePath,"/"); } out.println(strContent); return; } } temp = defaBlf.getModal("survey_htmlform",application.getRealPath(""),iPreview); if(!haveDefa||temp==null||temp.length()==0){//没有设置默认 Convert cv = new Convert(); temp = cv.readInputStream(tempPath+File.separator+"default.html", "UTF-8"); } style = defaEn.getVc_htmlformstyle(); if(!haveDefa||style==null||style.length()==0){//没有设置默认 String runConfPath = defaPath + File.separator + "htmlform.xml"; style = xmlFile.getContent("stylecode",runConfPath); style = style.substring(10,style.length()-4); } break; case 2: //已结束 temp = defaBlf.getModal("survey_afteraffi",application.getRealPath(""),iPreview); if(!haveDefa||temp==null||temp.length()==0){//没有设置默认 Convert cv = new Convert(); temp = cv.readInputStream(tempPath+File.separator+"default.html", "UTF-8"); } style = defaEn.getVc_afteraffistyle(); if(!haveDefa||style==null||style.length()==0){//没有设置默认 String afterConfPath = defaPath + File.separator + "afteraffi.xml"; style = xmlFile.getContent("stylecode",afterConfPath); style = style.substring(10,style.length()-4).replaceAll("\r\n",""); } String AfterAffiContent = formEn.getVc_endaffiche(); if(!haveDefa||AfterAffiContent==null||AfterAffiContent.length()==0){//没有设置默认 AfterAffiContent = "调查已结束!"; } //解析正文中的video代码 // AfterAffiContent = unit.parseVideoCode(AfterAffiContent, strAppID, Convert.getStringValueInt(strWebID) + ""); // AfterAffiContent = "" + AfterAffiContent; confMap.put("affiche",AfterAffiContent); //公告内容 confMap.put("pageType","1"); //页面类型 1:结果页 break; case 3: //不可见 out.println("
该调查不存在!
"); break; } Pattern p2 = Pattern.compile(regEx); Matcher m2 = p2.matcher(temp); String tag2 = ""; if(m2.find()){ tag2 = m2.group(); //标签和内容 }else{ LogWriter.error("Tag2 is not set!"); return; } SurveyQuesBLF quesBlf = new SurveyQuesBLF(strAppID,Convert.getStringValueInt(strWebID)); List quesList = quesBlf.getEntities(iFormId); strContent = Convert.getAlterScript("document.title = document.title + '" + name + "';"); strContent += "" + "" + "" + "" + ""+ ""; if(quesList==null) strContent += "
该调查不存在!
"; else{ SurveyConfBLF confBlf = new SurveyConfBLF(strAppID,Convert.getStringValueInt(strWebID)); SurveyConfEntity confEn = confBlf.getEntity(); //配置 confMap.put("mostSubmit",""+formEn.getI_mostsubmit()); confMap.put("state",""+parse.getState(formEn.getC_starttime(),formEn.getC_endtime(),formEn.b_show)); confMap.put("styleCode",style); confMap.put("afterResult",""+confEn.getB_afterresult()); confMap.put("showAnswer",""+formEn.getB_showanswer()); confMap.put("otherLen",""+confEn.getI_otherlen()); String formName = "surveyForm" + iFormId; //验证码 int validateCode = confEn.getB_validatecode(); if(validateCode==1){ //开启验证码,需要插入标签 strContent += ""; Random random = new Random(); confMap.put("validatecode"," " + ""); }else{ strContent += ""; } //重置表单 String reset = formName + ".reset();if(typeof(reset" + formName + ")!='undefined')\\\\$.formValidator.resetTipState('" + formName + "');"; confMap.put("reset",reset); //查看结果 confMap.put("result",modulePath + "survey/que_survey_result.jsp?formid=" + iFormId); //查看答案 confMap.put("answer",modulePath + "survey/que_survey_answer.jsp?formid=" + iFormId); confMap.put("formid", iFormId + ""); strContent += parse.parseForm(confMap,quesList); } strContent = temp.replaceFirst(tag2,strContent); //解析正文中的video代码 // if(iPreview!=1){ // strContent = unit.parseVideoCode(strContent, strAppID, Convert.getStringValueInt(strWebID) + ""); // } if(webtype.trim().equals("2")){ strContent = unit.parseVideoCode(strContent, strAppID, Convert.getStringValueInt(strWebID) + ""); strContent = strContent.replaceAll(filePath,"/"); }else{ strContent = unit.parseVideoCode(strContent, strAppID, Convert.getStringValueInt(strWebID) + ""); strContent = strContent.replaceAll("/view",""); } out.println(strContent); if(iPreview==1) return; Convert.createDirectory(webPath + "module" + File.separator + "survey" + File.separator + "html"); Convert updateHtml = new Convert(); try{ boolean bl = false; String htmlPath = webPath + "module" + File.separator + "survey" + File.separator + "html" + File.separator + "form_" + iFormId + ".html"; if(iBuild==1){//后台 sys.initSysPara(request); strContent = strContent.replaceAll("/"+SysInit.getM_strAppPath()+"/jcms_files/jcms"+strAppID+"/web"+strWebID+"/site/","/"); strContent = strContent.replaceAll("\\.\\./","../../"); updateHtml.writeByteStream(htmlPath,strContent.getBytes("UTF-8")); bl = updateHtml.writeByteStream(loadhtmlPath,strContent.getBytes("UTF-8")); if(bl){ out.println(Convert.getAlterScript("alert('已送发布列表!')")); jcms.entity.Merp_Pub_UserEntity userentity = UserRightBLF.getUserInfo(request); String strUserName = ""; if( userentity != null ){ strUserName = userentity.getVc_username(); } /*把文件发布到对应的目录*/ String strSavePath = "/jcms_files/jcms" + strAppID+"/web" +strWebID+"/site/module/survey/html/"; publisthFile( strAppID,Convert.getStringValueInt(strWebID),htmlPath,strUserName,strSavePath ); publisthFile( strAppID,Convert.getStringValueInt(strWebID),loadhtmlPath,strUserName,strSavePath ); } }else bl = updateHtml.writeByteStream(loadhtmlPath,strContent.getBytes("UTF-8")); if(bl) formBlf.setUpdateHtml(iFormId,1); }catch(Exception e){ LogWriter.error("[que_survey_htmlform.jsp] Writing file fail!"); } %> <%! public static void publisthFile( String strAppID, int nWebID, String strFile, String strPublisher,String strSavePath ){ strFile = Convert.getValue( strFile ); strPublisher = Convert.getValue( strPublisher ); File file = new File( strFile ); if( !file.exists() ){ LogWriter.debug("publisthFile:要发布的文件不存在!"); return; } String strLocalPath = strFile; String strFileName = file.getName(); java.util.Hashtable htFile = new java.util.Hashtable(); htFile.put("localfile", strLocalPath); htFile.put("remoteabspath", strSavePath); htFile.put("filename", strFileName); ArrayList list = new ArrayList(); list.add(htFile); String strComment = "(发布)在线调查! [发布人:" + strPublisher + "]"; java.util.Hashtable htInfo = new java.util.Hashtable(); htInfo.put("file", list); htInfo.put("webid", "" + nWebID ); htInfo.put("comment", strComment); htInfo.put("type", "add"); Publish publish = new Publish(strAppID); publish.publish(htInfo); } %>