diff --git a/org.adempiere.base/src/org/compiere/model/MSysConfig.java b/org.adempiere.base/src/org/compiere/model/MSysConfig.java index 93424d5eaf..5ee2b1903c 100644 --- a/org.adempiere.base/src/org/compiere/model/MSysConfig.java +++ b/org.adempiere.base/src/org/compiere/model/MSysConfig.java @@ -44,7 +44,7 @@ public class MSysConfig extends X_AD_SysConfig /** * */ - private static final long serialVersionUID = -1225938049955333281L; + private static final long serialVersionUID = 6202541582080272987L; public static final String ADDRESS_VALIDATION = "ADDRESS_VALIDATION"; public static final String ALERT_SEND_ATTACHMENT_AS_XLS = "ALERT_SEND_ATTACHMENT_AS_XLS"; @@ -128,6 +128,7 @@ public class MSysConfig extends X_AD_SysConfig public static final String LOCATION_MAX_CITY_ROWS = "LOCATION_MAX_CITY_ROWS"; public static final String LOGIN_HELP_URL = "LOGIN_HELP_URL"; public static final String LOGIN_PREFIX_SEPARATOR = "LOGIN_PREFIX_SEPARATOR"; + public static final String LOGIN_SELECT_ROLE_HELP_URL = "LOGIN_SELECT_ROLE_HELP_URL"; public static final String LOGIN_SHOW_RESETPASSWORD = "LOGIN_SHOW_RESETPASSWORD"; public static final String LOGIN_WITH_TENANT_PREFIX = "LOGIN_WITH_TENANT_PREFIX"; public static final String MAIL_DONT_SEND_TO_ADDRESS = "MAIL_DONT_SEND_TO_ADDRESS"; diff --git a/org.adempiere.base/src/org/compiere/util/WebUtil.java b/org.adempiere.base/src/org/compiere/util/WebUtil.java index 15f3ce0006..3a70bfcb8e 100644 --- a/org.adempiere.base/src/org/compiere/util/WebUtil.java +++ b/org.adempiere.base/src/org/compiere/util/WebUtil.java @@ -24,9 +24,11 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; +import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; +import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; import java.net.UnknownHostException; @@ -1130,4 +1132,23 @@ public final class WebUtil return retVal; } + /** + * returns true if the URL exists and answer with a 200 code + * @param urlString + * @return boolean + */ + public static boolean isUrlOk(String urlString) { + int responseCode = 0; + URL url; + try { + url = new URL(urlString); + HttpURLConnection huc = (HttpURLConnection) url.openConnection(); + huc.setRequestMethod("HEAD"); + responseCode = huc.getResponseCode(); + } catch (IOException e) { + responseCode = -1; + } + return responseCode == HttpURLConnection.HTTP_OK; + } + } // WebUtil diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/LoginPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/LoginPanel.java index 2e14952cc3..df4c03960f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/LoginPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/LoginPanel.java @@ -65,6 +65,7 @@ import org.compiere.util.Language; import org.compiere.util.Login; import org.compiere.util.Msg; import org.compiere.util.Util; +import org.compiere.util.WebUtil; import org.zkoss.lang.Strings; import org.zkoss.util.Locales; import org.zkoss.web.Attributes; @@ -475,11 +476,15 @@ public class LoginPanel extends Window implements EventListener } private void openLoginHelp() { - String langName = (String) lstLanguage.getSelectedItem().getValue(); - langName = langName.substring(0, 2); - String helpURL = MSysConfig.getValue(MSysConfig.LOGIN_HELP_URL, "http://wiki.idempiere.org/{lang}/Login_Help"); - if (helpURL.contains("{lang}")) - helpURL = Util.replace(helpURL, "{lang}", langName); + String lang = (String) lstLanguage.getSelectedItem().getValue(); + lang = lang.substring(0, 2); + String helpURL = MSysConfig.getValue(MSysConfig.LOGIN_HELP_URL, "https://wiki.idempiere.org/{lang}/Login_Help"); + if (helpURL.contains("{lang}")) { + String rawURL = helpURL; + helpURL = Util.replace(rawURL, "{lang}", lang); + if (!"en".equals(lang) && !WebUtil.isUrlOk(helpURL)) + helpURL = Util.replace(rawURL, "{lang}", "en"); // default to English + } try { Executions.getCurrent().sendRedirect(helpURL, "_blank"); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java index c674d4dee7..c105385a1e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/RolePanel.java @@ -29,6 +29,7 @@ import java.util.Properties; import org.adempiere.util.Callback; import org.adempiere.webui.AdempiereIdGenerator; import org.adempiere.webui.LayoutUtils; +import org.adempiere.webui.component.Button; import org.adempiere.webui.component.ComboItem; import org.adempiere.webui.component.Combobox; import org.adempiere.webui.component.ConfirmPanel; @@ -51,18 +52,19 @@ import org.compiere.util.Language; import org.compiere.util.Login; import org.compiere.util.Msg; import org.compiere.util.Util; +import org.compiere.util.WebUtil; import org.zkoss.zhtml.Table; import org.zkoss.zhtml.Td; import org.zkoss.zhtml.Tr; import org.zkoss.zk.au.out.AuFocus; import org.zkoss.zk.au.out.AuScript; +import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.event.Deferrable; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.util.Clients; -import org.zkoss.zul.Button; import org.zkoss.zul.Comboitem; import org.zkoss.zul.Div; import org.zkoss.zul.Image; @@ -273,7 +275,12 @@ public class RolePanel extends Window implements EventListener, Deferrabl pnlButtons.addActionListener(this); Button okBtn = pnlButtons.getButton(ConfirmPanel.A_OK); okBtn.setWidgetListener("onClick", "zAu.cmd0.showBusy(null)"); - + + Button helpButton = pnlButtons.createButton(ConfirmPanel.A_HELP); + helpButton.addEventListener(Events.ON_CLICK, this); + helpButton.setSclass(ITheme.LOGIN_BUTTON_CLASS); + pnlButtons.addComponentsRight(helpButton); + LayoutUtils.addSclass(ITheme.LOGIN_BOX_FOOTER_PANEL_CLASS, pnlButtons); ZKUpdateUtil.setWidth(pnlButtons, null); pnlButtons.getButton(ConfirmPanel.A_OK).setSclass(ITheme.LOGIN_BUTTON_CLASS); @@ -545,6 +552,10 @@ public class RolePanel extends Window implements EventListener, Deferrabl { validateRoles(false); } + else if (event.getTarget().getId().equals(ConfirmPanel.A_HELP)) + { + openLoginHelp(); + } else if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) { if (isChangeRole()) { @@ -563,6 +574,25 @@ public class RolePanel extends Window implements EventListener, Deferrabl } } + private void openLoginHelp() { + String lang = Env.getContext(Env.getCtx(), Env.LANGUAGE); + lang = lang.substring(0, 2); + String helpURL = MSysConfig.getValue(MSysConfig.LOGIN_SELECT_ROLE_HELP_URL, "https://wiki.idempiere.org/{lang}/Login_Select_Role_Help"); + if (helpURL.contains("{lang}")) { + String rawURL = helpURL; + helpURL = Util.replace(rawURL, "{lang}", lang); + if (!"en".equals(lang) && !WebUtil.isUrlOk(helpURL)) + helpURL = Util.replace(rawURL, "{lang}", "en"); // default to English + } + try { + Executions.getCurrent().sendRedirect(helpURL, "_blank"); + } + catch (Exception e) { + String message = e.getMessage(); + Dialog.warn(0, "URLnotValid", message); + } + } + private void setUserID() { if (lstClient.getSelectedItem() != null) { Env.setContext(m_ctx, Env.AD_CLIENT_ID, (String) lstClient.getSelectedItem().getValue());