String strCommand = null;
TableData[] data=null;
XmlDocument xmlDocument=null;
FieldProvider dataField = vars.getEditionData(tabId);
vars.removeEditionData(tabId);
String strParamTableName = vars.getSessionValue(tabId + "|paramTableName");
boolean hasSearchCondition=false;
if (!(strParamTableName.equals(""))) hasSearchCondition=true;
String strParamSessionDate = vars.getGlobalVariable("inpParamSessionDate", Utility.getTransactionalDate(this, vars, windowId), "");
String buscador = "";
String[] discard = {"", "isNotTest"};
if (vars.getSessionValue("#ShowTest", "N").equals("Y")) discard[1] = new String("isTest");
if (dataField==null) {
if (!boolNew) {
discard[0] = new String("newDiscard");
if (strParamTableName.equals("") && strAD_Table_ID.equals("")) {
buscador = "openSearchWindow('../businessUtility/Buscador.html', 'BUSCADOR', " + tabId + ", 'TablesandColumns/Table_Relation.html', " + windowId + ");";
} else if (strAD_Table_ID.equals("")) {
TableData[] data1 = TableData.select(this, vars.getLanguage(), strParamTableName, strParamSessionDate, vars.getUser(), Utility.getContext(this, vars, "#User_Client", windowId, accesslevel), Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel), strOrderByFilter);
data = new TableData[1];
if (data1!=null && data1.length!=0) data[0] = data1[0];
} else data = TableData.selectEdit(this, vars.getSessionValue("#AD_SqlDateTimeFormat"), vars.getLanguage(), strAD_Table_ID, Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel));
if (!strAD_Table_ID.equals("") && (data == null || data.length==0)) {
response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
return;
}
refreshSessionEdit(vars, data);
strCommand = "EDIT";
}
if (boolNew || data==null || data.length==0) {
discard[0] = new String ("editDiscard");
strCommand = "NEW";
data = new TableData[0];
} else {
discard[0] = new String ("newDiscard");
}
} else {
if (dataField.getField("adTableId") == null || dataField.getField("adTableId").equals("")) {
discard[0] = new String ("editDiscard");
strCommand = "NEW";
boolNew = true;
} else {
discard[0] = new String ("newDiscard");
strCommand = "EDIT";
}
}
if (dataField==null) {
if (boolNew || data==null || data.length==0) {
refreshSessionNew(vars);
data = TableData.set("", Utility.getDefault(this, vars, "Name", "", "100", "", dataField), Utility.getDefault(this, vars, "Description", "", "100", "", dataField), Utility.getDefault(this, vars, "Help", "", "100", "", dataField), Utility.getDefault(this, vars, "AD_Window_ID", "", "100", "", dataField), Utility.getDefault(this, vars, "TableName", "", "100", "", dataField), Utility.getDefault(this, vars, "AccessLevel", "4", "100", "", dataField), "0", "0", Utility.getDefault(this, vars, "IsHighVolume", "", "100", "N", dataField), "Y", Utility.getDefault(this, vars, "CreatedBy", "", "100", "", dataField), TableData.selectDef545_0(this, Utility.getDefault(this, vars, "CreatedBy", "", "100", "", dataField)), Utility.getDefault(this, vars, "UpdatedBy", "", "100", "", dataField), TableData.selectDef547_1(this, Utility.getDefault(this, vars, "UpdatedBy", "", "100", "", dataField)), Utility.getDefault(this, vars, "Classname", "", "100", "", dataField), Utility.getDefault(this, vars, "IsView", "N", "100", "N", dataField), Utility.getDefault(this, vars, "ImportTable", "", "100", "N", dataField), Utility.getDefault(this, vars, "Acctdate_Column_ID", "", "100", "", dataField), Utility.getDefault(this, vars, "Acctclassname", "", "100", "", dataField), Utility.getDefault(this, vars, "IsSecurityEnabled", "", "100", "N", dataField), Utility.getDefault(this, vars, "IsDeleteable", "Y", "100", "N", dataField), Utility.getDefault(this, vars, "IsDefaultAcct", "N", "100", "N", dataField), Utility.getDefault(this, vars, "SQL_Record_Identifier", "", "100", "", dataField), Utility.getDefault(this, vars, "Developmentstatus", "RE", "100", "", dataField), Utility.getDefault(this, vars, "IsChangeLog", "", "100", "N", dataField), Utility.getDefault(this, vars, "AD_Package_ID", "0", "100", "", dataField), Utility.getDefault(this, vars, "PO_Window_ID", "", "100", "", dataField), Utility.getDefault(this, vars, "Treetype", "", "100", "", dataField));
}
}
String currentOrg = (boolNew?"":(dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId")));
if (!currentOrg.equals("") && !currentOrg.startsWith("'")) currentOrg = "'"+currentOrg+"'";
String currentClient = (boolNew?"":(dataField!=null?dataField.getField("adClientId"):data[0].getField("adClientId")));
if (!currentClient.equals("") && !currentClient.startsWith("'")) currentClient = "'"+currentClient+"'";
boolean editableTab = (!org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId) && (currentOrg.equals("") || Utility.isElementInList(Utility.getContext(this, vars, "#User_Org", windowId, accesslevel),currentOrg)) && (currentClient.equals("") || Utility.isElementInList(Utility.getContext(this, vars, "#User_Client", windowId, accesslevel), currentClient)));
if (editableTab)
xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpWindows/TablesandColumns/Table_Edition",discard).createXmlDocument();
else
xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpWindows/TablesandColumns/Table_NonEditable",discard).createXmlDocument();
xmlDocument.setParameter("tabId", tabId);
ToolBar toolbar = new ToolBar(this, editableTab, vars.getLanguage(), "Table", (strCommand.equals("NEW") || boolNew || (dataField==null && (data==null || data.length==0))), "document.frmMain.inpadTableId", "", "..", "".equals("Y"), "TablesandColumns", strReplaceWith, true, false, false, Utility.hasTabAttachments(this, vars, tabId, strAD_Table_ID));
toolbar.prepareEditionTemplate("N".equals("Y"), hasSearchCondition, vars.getSessionValue("#ShowTest", "N").equals("Y"), "STD", Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
xmlDocument.setParameter("toolbar", toolbar.toString());
try {
WindowTabs tabs = new WindowTabs(this, vars, tabId, windowId, true, (strCommand.equalsIgnoreCase("NEW")));
xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
// if (!strAD_Table_ID.equals("")) xmlDocument.setParameter("childTabContainer", tabs.childTabs(false));
// else xmlDocument.setParameter("childTabContainer", tabs.childTabs(true));
xmlDocument.setParameter("childTabContainer", tabs.childTabs(false));
NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "Table_Relation.html", "TablesandColumns", "W", strReplaceWith, tabs.breadcrumb());
xmlDocument.setParameter("navigationBar", nav.toString());
LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "Table_Relation.html", strReplaceWith);
xmlDocument.setParameter("leftTabs", lBar.editionTemplate(strCommand.equals("NEW")));
} catch (Exception ex) {
throw new ServletException(ex);
}
xmlDocument.setParameter("commandType", strCommand);
xmlDocument.setParameter("buscador",buscador);
xmlDocument.setParameter("windowId", windowId);
xmlDocument.setParameter("changed", "");
xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
xmlDocument.setParameter("theme", vars.getTheme());
final String strMappingName = UtilityData.selectObjectMapping(this, tabId);
xmlDocument.setParameter("mappingName", strMappingName);
xmlDocument.setParameter("confirmOnChanges", Utility.getJSConfirmOnChanges(vars, windowId));
//xmlDocument.setParameter("buttonReference", Utility.messageBD(this, "Reference", vars.getLanguage()));
xmlDocument.setParameter("paramSessionDate", strParamSessionDate);
xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
OBError myMessage = vars.getMessage(tabId);
vars.removeMessage(tabId);
if (myMessage!=null) {
xmlDocument.setParameter("messageType", myMessage.getType());
xmlDocument.setParameter("messageTitle", myMessage.getTitle());
xmlDocument.setParameter("messageMessage", myMessage.getMessage());
}
xmlDocument.setParameter("displayLogic", getDisplayLogicContext(vars, boolNew));
if (dataField==null) {
xmlDocument.setData("structure1",data);
} else {
FieldProvider[] dataAux = new FieldProvider[1];
dataAux[0] = dataField;
xmlDocument.setData("structure1",dataAux);
}
try {
ComboTableData comboTableData = null;
String userClientList = "";
if (editableTab)
userClientList=Utility.getContext(this, vars, "#User_Client", windowId, accesslevel); //editable record
else
userClientList=currentClient;
comboTableData = new ComboTableData(vars, this, "19", "AD_Client_ID", "", "103", null, userClientList, 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("adClientId"):dataField.getField("adClientId")));
xmlDocument.setData("reportAD_Client_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
String userOrgList = "";
if (editableTab)
userOrgList=Utility.getContext(this, vars, "#User_Org", windowId, accesslevel); //editable record
else
userOrgList=currentOrg;
comboTableData = new ComboTableData(vars, this, "19", "AD_Org_ID", "", "", userOrgList, Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("adOrgId"):dataField.getField("adOrgId")));
xmlDocument.setData("reportAD_Org_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "19", "AD_Package_ID", "", "78CBED13BC3F4BF989A90CA75BA8DFCD", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("adPackageId"):dataField.getField("adPackageId")));
xmlDocument.setData("reportAD_Package_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "17", "AccessLevel", "5", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("accesslevel"):dataField.getField("accesslevel")));
xmlDocument.setData("reportAccessLevel","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "17", "Treetype", "120", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("treetype"):dataField.getField("treetype")));
xmlDocument.setData("reportTreetype","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "19", "AD_Window_ID", "", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("adWindowId"):dataField.getField("adWindowId")));
xmlDocument.setData("reportAD_Window_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "18", "PO_Window_ID", "284", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("poWindowId"):dataField.getField("poWindowId")));
xmlDocument.setData("reportPO_Window_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "17", "Developmentstatus", "800103", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("developmentstatus"):dataField.getField("developmentstatus")));
xmlDocument.setData("reportDevelopmentstatus","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
xmlDocument.setParameter("ImportTable_BTNname", Utility.getButtonName(this, vars, "5126", "ImportTable_linkBTN", usedButtonShortCuts, reservedButtonShortCuts));
comboTableData = new ComboTableData(vars, this, "18", "Acctdate_Column_ID", "F4175D3FED5949AAAA9C04A281E60866", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("acctdateColumnId"):dataField.getField("acctdateColumnId")));
xmlDocument.setData("reportAcctdate_Column_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
xmlDocument.setParameter("Created_Format", vars.getSessionValue("#AD_SqlDateTimeFormat"));xmlDocument.setParameter("Created_Maxlength", Integer.toString(vars.getSessionValue("#AD_SqlDateTimeFormat").length()));
xmlDocument.setParameter("Updated_Format", vars.getSessionValue("#AD_SqlDateTimeFormat"));xmlDocument.setParameter("Updated_Maxlength", Integer.toString(vars.getSessionValue("#AD_SqlDateTimeFormat").length()));
} catch (Exception ex) {