1 19 package org.openbravo.erpCommon.info; 20 21 import org.openbravo.base.secureApp.*; 22 import org.openbravo.xmlEngine.XmlDocument; 23 import org.openbravo.erpCommon.utility.Utility; 24 import java.io.*; 25 import javax.servlet.*; 26 import javax.servlet.http.*; 27 import org.openbravo.utils.Replace; 28 29 30 31 public class UserContact extends HttpSecureAppServlet { 32 33 34 public void init (ServletConfig config) { 35 super.init(config); 36 boolHist = false; 37 } 38 39 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 40 VariablesSecureApp vars = new VariablesSecureApp(request); 41 42 if (vars.commandIn("DEFAULT")) { 43 String strNameValue = vars.getRequestGlobalVariable("inpNameValue", "UserContact.name"); 44 vars.removeSessionValue("UserContact.key"); 45 if (!strNameValue.equals("")) vars.setSessionValue("UserContact.name", strNameValue + "%"); 46 printPageFS(response, vars); 47 } else if (vars.commandIn("KEY")) { 48 String strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "UserContact.key"); 49 vars.removeSessionValue("UserContact.name"); 50 vars.setSessionValue("UserContact.key", strKeyValue + "%"); 51 UserContactData[] data = UserContactData.selectKey(this, strKeyValue + "%"); 52 if (data!=null && data.length==1) { 53 printPageKey(response, vars, data); 54 } else printPageFS(response, vars); 55 } else if (vars.commandIn("FRAME1")) { 56 String strKeyValue = vars.getGlobalVariable("inpKey", "UserContact.key", ""); 57 String strNameValue = vars.getGlobalVariable("inpName", "UserContact.name", ""); 58 printPageFrame1(response, vars, strKeyValue, strNameValue); 59 } else if (vars.commandIn("FRAME2")) { 60 String strKey = vars.getGlobalVariable("inpKey", "UserContact.key", ""); 61 String strName = vars.getGlobalVariable("inpName", "UserContact.name", ""); 62 String strLastResult = vars.getStringParameter("inpLastResult"); 63 String strFax = vars.getStringParameter("inpFax"); 64 String strTelephone = vars.getStringParameter("inpTelephone"); 65 printPageFrame2(response, vars, strKey, strName, strLastResult, strFax, strTelephone); 66 } else if (vars.commandIn("FIND")) { 67 String strKey = vars.getRequestGlobalVariable("inpKey", "UserContact.key"); 68 String strName = vars.getRequestGlobalVariable("inpName", "UserContact.name"); 69 String strLastResult = vars.getStringParameter("inpLastResult"); 70 String strFax = vars.getStringParameter("inpFax"); 71 String strTelephone = vars.getStringParameter("inpTelephone"); 72 73 vars.setSessionValue("UserContact.initRecordNumber", "0"); 74 75 printPageFrame2(response, vars, strKey, strName, strLastResult, strFax, strTelephone); 76 } else if (vars.commandIn("FRAME3")) { 77 printPageFrame3(response, vars); 78 } else if (vars.commandIn("PREVIOUS")) { 79 String strInitRecord = vars.getSessionValue("UserContact.initRecordNumber"); 80 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "UserContact"); 81 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 82 if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("UserContact.initRecordNumber", "0"); 83 else { 84 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 85 initRecord -= intRecordRange; 86 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 87 vars.setSessionValue("UserContact.initRecordNumber", strInitRecord); 88 } 89 90 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 91 } else if (vars.commandIn("NEXT")) { 92 String strInitRecord = vars.getSessionValue("UserContact.initRecordNumber"); 93 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "UserContact"); 94 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 95 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 96 if (initRecord==0) initRecord=1; 97 initRecord += intRecordRange; 98 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 99 vars.setSessionValue("UserContact.initRecordNumber", strInitRecord); 100 101 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 102 } else pageError(response); 103 } 104 105 void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 106 if (log4j.isDebugEnabled()) log4j.debug("Output: business partners seeker Frame Set"); 107 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_FS").createXmlDocument(); 108 109 response.setContentType("text/html; charset=UTF-8"); 110 PrintWriter out = response.getWriter(); 111 out.println(xmlDocument.print()); 112 out.close(); 113 } 114 115 void printPageKey(HttpServletResponse response, VariablesSecureApp vars, UserContactData[] data) throws IOException, ServletException { 116 if (log4j.isDebugEnabled()) log4j.debug("Output: user seeker Frame Set"); 117 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument(); 118 119 xmlDocument.setParameter("script", generateResult(data)); 120 response.setContentType("text/html; charset=UTF-8"); 121 PrintWriter out = response.getWriter(); 122 out.println(xmlDocument.print()); 123 out.close(); 124 } 125 126 String generateResult(UserContactData[] data) throws IOException, ServletException { 127 StringBuffer html = new StringBuffer (); 128 129 html.append("\nfunction depurarSelector() {\n"); 130 html.append("var clave = \"" + data[0].id + "\";\n"); 131 html.append("var texto = \"" + Replace.replace(data[0].name, "\"", "\\\"") + "\";\n"); 132 html.append("parent.opener.closeSearch(\"SAVE\", clave, texto, null);\n"); 133 html.append("}\n"); 134 return html.toString(); 135 } 136 137 void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strKeyValue, String strNameValue) throws IOException, ServletException { 138 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the business partners seeker"); 139 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_F1").createXmlDocument(); 140 if (strKeyValue.equals("") && strNameValue.equals("")) { 141 xmlDocument.setParameter("key", "%"); 142 } else { 143 xmlDocument.setParameter("key", strKeyValue); 144 } 145 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 146 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 147 response.setContentType("text/html; charset=UTF-8"); 148 PrintWriter out = response.getWriter(); 149 out.println(xmlDocument.print()); 150 out.close(); 151 } 152 153 void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strName, String strLastResult, String strFax, String strTelephone) throws IOException, ServletException { 154 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the business partners seeker"); 155 XmlDocument xmlDocument; 156 157 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "UserContact"); 158 int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange)); 159 String strInitRecord = vars.getSessionValue("UserContact.initRecordNumber"); 160 int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 161 162 if (strKey.equals("") && strName.equals("") && strLastResult.equals("") && strFax.equals("") && strTelephone.equals("")) { 163 String [] discard = {"sectionDetail", "hasPrevious", "hasNext"}; 164 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_F2", discard).createXmlDocument(); 165 xmlDocument.setData("structure1", UserContactData.set()); 166 } else { 167 String [] discard = {"withoutPrevious", "withoutNext"}; 168 UserContactData[] data = UserContactData.select(this, strTelephone, strFax, strLastResult, strKey, initRecordNumber, intRecordRange); 169 if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String ("hasPrevious"); 170 if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String ("hasNext"); 171 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_F2", discard).createXmlDocument(); 172 xmlDocument.setData("structure1", data); 173 } 174 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 175 response.setContentType("text/html; charset=UTF-8"); 176 PrintWriter out = response.getWriter(); 177 out.println(xmlDocument.print()); 178 out.close(); 179 } 180 181 void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 182 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the business partners seeker"); 183 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/UserContact_F3").createXmlDocument(); 184 185 response.setContentType("text/html; charset=UTF-8"); 186 PrintWriter out = response.getWriter(); 187 out.println(xmlDocument.print()); 188 out.close(); 189 } 190 191 public String getServletInfo() { 192 return "Servlet that presents the business partners seeker"; 193 } } 195 | Popular Tags |