<%
/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */
%>

<%= ReleaseInfo.getReleaseInfo() %><br />

<%
long uptimeDiff = System.currentTimeMillis() - PortalUtil.getUptime().getTime();
long days = uptimeDiff / Time.DAY;
long hours = (uptimeDiff / Time.HOUR) % 24;
long minutes = (uptimeDiff / Time.MINUTE) % 60;
long seconds = (uptimeDiff / Time.SECOND) % 60;

NumberFormat numberFormat = NumberFormat.getInstance();

numberFormat.setMaximumIntegerDigits(2);
numberFormat.setMinimumIntegerDigits(2);
%>

<liferay-ui:message key="uptime" />:

<c:if test="<%= days > 0 %>">
	<%= days %> <%= LanguageUtil.get(pageContext, ((days > 1) ? "days" : "day")) %>,
</c:if>

<%= numberFormat.format(hours) %>:<%= numberFormat.format(minutes) %>:<%= numberFormat.format(seconds) %>

<br /><br />

<c:choose>
	<c:when test="<%= windowState.equals(WindowState.NORMAL) %>">
		<html:link page="/admin/view?windowState=maximized&portletMode=view&actionURL=0"><liferay-ui:message key="more" /></html:link> &raquo;
	</c:when>
	<c:otherwise>
		<liferay-ui:tabs
			names="resources,log-levels,properties,captcha,data-migration,file-uploads,mail,OpenOffice,script,shutdown"
			param="tabs2"
			url="<%= portletURL.toString() %>"
		/>

		<c:choose>
			<c:when test='<%= tabs2.equals("log-levels") %>'>
				<liferay-ui:tabs
					names="update-categories,add-category"
					param="tabs3"
					url="<%= portletURL.toString() %>"
				/>

				<c:choose>
					<c:when test='<%= tabs3.equals("add-category") %>'>
						<aui:fieldset>
							<aui:input cssClass="lfr-input-text-container" label="" name="loggerName" type="text" />

							<aui:select label="" name="priority">

								<%
								for (int i = 0; i < Levels.ALL_LEVELS.length; i++) {
								%>

									<aui:option label="<%= Levels.ALL_LEVELS[i] %>" selected="<%= Level.INFO.equals(Levels.ALL_LEVELS[i]) %>" />

								<%
								}
								%>
							</aui:select>
						</aui:fieldset>

						<aui:button-row>

							<%
							String taglibAddLogLevel = renderResponse.getNamespace() + "saveServer('addLogLevel');";
							%>

							<aui:button type="button" onClick="<%= taglibAddLogLevel %>" value="save" />
						</aui:button-row>
					</c:when>
					<c:otherwise>

						<%
						String keywords = ParamUtil.getString(request, "keywords");
						%>

						<span class="aui-search-bar">
							<aui:input inlineField="<%= true %>" label="" name="keywords" title="search-categories" type="text" value="<%= keywords %>" />

							<aui:button type="submit" value="search" />
						</span>

						<br /><br />

						<%
						List<String> headerNames = new ArrayList<String>();

						headerNames.add("category");
						headerNames.add("level");

						SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, portletURL, headerNames, null);

						Map currentLoggerNames = new TreeMap();

						Enumeration enu = LogManager.getCurrentLoggers();

						while (enu.hasMoreElements()) {
							Logger logger = (Logger)enu.nextElement();

							if (Validator.isNull(keywords) || logger.getName().contains(keywords)) {
								currentLoggerNames.put(logger.getName(), logger);
							}
						}

						List results = ListUtil.fromCollection(currentLoggerNames.entrySet());

						Iterator itr = results.iterator();

						while (itr.hasNext()) {
							Map.Entry entry = (Map.Entry)itr.next();

							String name = (String)entry.getKey();
							Logger logger = (Logger)entry.getValue();

							Level level = logger.getLevel();

							if (level == null) {
								itr.remove();
							}
						}

						searchContainer.setTotal(results.size());

						results = ListUtil.subList(results, searchContainer.getStart(), searchContainer.getEnd());

						searchContainer.setResults(results);

						List resultRows = searchContainer.getResultRows();

						for (int i = 0; i < results.size(); i++) {
							Map.Entry entry = (Map.Entry)results.get(i);

							String name = (String)entry.getKey();
							Logger logger = (Logger)entry.getValue();

							Level level = logger.getLevel();

							ResultRow row = new ResultRow(entry, name, i);

							// Name

							row.addText(name);

							// Logger

							StringBundler sb = new StringBundler(Levels.ALL_LEVELS.length * 6 + 7);

							sb.append("<select name=\"");
							sb.append(renderResponse.getNamespace());
							sb.append("logLevel");
							sb.append(name);
							sb.append("\">");

							for (int j = 0; j < Levels.ALL_LEVELS.length; j++) {
								sb.append("<option ");

								if (level.equals(Levels.ALL_LEVELS[j])) {
									sb.append("selected");
								}

								sb.append(" value=\"");
								sb.append(Levels.ALL_LEVELS[j]);
								sb.append("\">");
								sb.append(Levels.ALL_LEVELS[j]);
								sb.append("</option>");
							}

							sb.append("</select>");

							row.addText(sb.toString());

							// Add result row

							resultRows.add(row);
						}
						%>

						<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />

						<br />

						<aui:button-row>

							<%
							String taglibUpdateLogLevels = renderResponse.getNamespace() + "saveServer('updateLogLevels');";
							%>

							<aui:button type="button" onClick="<%= taglibUpdateLogLevels %>" value="save" />
						</aui:button-row>
					</c:otherwise>
				</c:choose>
			</c:when>
			<c:when test='<%= tabs2.equals("properties") %>'>
				<liferay-ui:tabs
					names="system-properties,portal-properties"
					param="tabs3"
					url="<%= portletURL.toString() %>"
				/>

				<c:choose>
					<c:when test='<%= tabs3.equals("portal-properties") %>'>

						<%
						List<String> headerNames = new ArrayList<String>();

						headerNames.add("property");
						headerNames.add("value");

						SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, portletURL, headerNames, null);

						Map portalProps = new TreeMap();

						portalProps.putAll(PropsUtil.getProperties());

						List results = ListUtil.fromCollection(portalProps.entrySet());

						searchContainer.setTotal(results.size());

						results = ListUtil.subList(results, searchContainer.getStart(), searchContainer.getEnd());

						searchContainer.setResults(results);

						List resultRows = searchContainer.getResultRows();

						for (int i = 0; i < results.size(); i++) {
							Map.Entry entry = (Map.Entry)results.get(i);

							String property = (String)entry.getKey();
							String value = (String)entry.getValue();

							ResultRow row = new ResultRow(entry, property, i);

							// Property

							row.addText(StringUtil.shorten(property, 80));

							// Value

							row.addText(StringUtil.shorten(value, 80));

							// Add result row

							resultRows.add(row);
						}
						%>

						<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
					</c:when>
					<c:otherwise>

						<%
						List<String> headerNames = new ArrayList<String>();

						headerNames.add("property");
						headerNames.add("value");

						SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, portletURL, headerNames, null);

						Map portalProps = new TreeMap();

						portalProps.putAll(System.getProperties());

						List results = ListUtil.fromCollection(portalProps.entrySet());

						searchContainer.setTotal(results.size());

						results = ListUtil.subList(results, searchContainer.getStart(), searchContainer.getEnd());

						searchContainer.setResults(results);

						List resultRows = searchContainer.getResultRows();

						for (int i = 0; i < results.size(); i++) {
							Map.Entry entry = (Map.Entry)results.get(i);

							String property = (String)entry.getKey();
							String value = (String)entry.getValue();

							ResultRow row = new ResultRow(entry, property, i);

							// Property

							row.addText(StringUtil.shorten(property, 80));

							// Value

							row.addText(StringUtil.shorten(value, 80));

							// Add result row

							resultRows.add(row);
						}
						%>

						<liferay-ui:search-iterator searchContainer="<%= searchContainer %>" />
					</c:otherwise>
				</c:choose>
			</c:when>
			<c:when test='<%= tabs2.equals("captcha") %>'>
				<aui:fieldset>
					<aui:input inlineLabel="right" label="enable-recaptcha" name="reCaptchaEnabled" type="checkbox" value="<%= PrefsPropsUtil.getString(PropsKeys.CAPTCHA_ENGINE_IMPL, PropsValues.CAPTCHA_ENGINE_IMPL).equals(ReCaptchaImpl.class.getName()) %>" />

					<aui:input cssClass="lfr-input-text-container" label="recaptcha-public-key" name="reCaptchaPublicKey" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PUBLIC, PropsValues.CAPTCHA_ENGINE_RECAPTCHA_KEY_PUBLIC) %>" />

					<aui:input cssClass="lfr-input-text-container" label="recaptcha-private-key" name="reCaptchaPrivateKey" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PRIVATE, PropsValues.CAPTCHA_ENGINE_RECAPTCHA_KEY_PRIVATE) %>" />
				</aui:fieldset>

				<aui:button-row>

					<%
					String taglibUpdateCaptcha = renderResponse.getNamespace() + "saveServer('updateCaptcha');";
					%>

					<aui:button type="button" onClick="<%= taglibUpdateCaptcha %>" value="save" />
				</aui:button-row>
			</c:when>
			<c:when test='<%= tabs2.equals("data-migration") %>'>

				<%
				List<ConvertProcess> convertProcesses = new ArrayList<ConvertProcess>();

				for (String convertProcessClassName : PropsValues.CONVERT_PROCESSES) {
					ConvertProcess convertProcess = (ConvertProcess)InstancePool.get(convertProcessClassName);

					if (convertProcess.isEnabled()) {
						convertProcesses.add(convertProcess);
					}
				}
				%>

				<c:choose>
					<c:when test="<%= convertProcesses.isEmpty() %>">
						<div class="portlet-msg-info">
							<liferay-ui:message key="no-data-migration-processes-are-available" />
						</div>
					</c:when>
					<c:otherwise>

						<%
						int i = 0;

						for (ConvertProcess convertProcess : convertProcesses) {
						%>

							<liferay-ui:panel-container extended="<%= true %>" id='<%= "convert" + i + "PanelContainer" %>' persistState="<%= true %>">
								<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id='<%= "convert" + i + "Panel" %>' persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, convertProcess.getDescription()) %>'>
									<c:if test="<%= convertProcess.getParameterNames() != null %>">
										<aui:fieldset label='<%= Validator.isNotNull(convertProcess.getParameterDescription()) ? convertProcess.getParameterDescription() : "" %>'>

											<%
											for (String parameter : convertProcess.getParameterNames()) {
												if (parameter.contains(StringPool.EQUAL) && parameter.contains(StringPool.SEMICOLON)) {
													String[] parameterPair = StringUtil.split(parameter, StringPool.EQUAL);
													String[] parameterSelectEntries = StringUtil.split(parameterPair[1], StringPool.SEMICOLON);
											%>

												<aui:select label="<%= parameterPair[0] %>" name="<%= convertProcess.getClass().getName() + StringPool.PERIOD + parameterPair[0] %>">

													<%
													for (String parameterSelectEntry : parameterSelectEntries) {
													%>

														<aui:option label="<%= parameterSelectEntry %>" />

													<%
													}
													%>

												</aui:select>

											<%
												}
												else {
													String[] parameterPair = StringUtil.split(parameter, StringPool.EQUAL);

													String parameterName = null;
													String parameterType = null;

													if (parameterPair.length > 1) {
														parameterName = parameterPair[0];
														parameterType = parameterPair[1];
													}
													else {
														parameterName = parameter;
													}
											%>

													<aui:input cssClass="lfr-input-text-container" label="<%= parameterName %>" name="<%= convertProcess.getClass().getName() + StringPool.PERIOD + parameterName %>" type='<%= parameterType != null ? parameterType : "" %>' />

											<%
												}
											}
											%>

										</aui:fieldset>
									</c:if>

									<aui:button-row>

										<%
										String taglibConvertProcess = renderResponse.getNamespace() + "saveServer('convertProcess." + convertProcess.getClass().getName() + "');";
										%>

										<aui:button type="button" onClick="<%= taglibConvertProcess %>" value="execute" />
									</aui:button-row>
								</liferay-ui:panel>
							</liferay-ui:panel-container>

							<br />

						<%
							i++;
						}
						%>

					</c:otherwise>
				</c:choose>
			</c:when>
			<c:when test='<%= tabs2.equals("file-uploads") %>'>
				<aui:fieldset label="configure-the-file-upload-settings">
					<liferay-ui:panel-container extended="<%= true %>" id="generalUploadPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="generalUploadPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "general") %>'>
							<aui:input cssClass="lfr-input-text-container" label="overall-maximum-file-size" name="uploadServletRequestImplMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE) %>" />

							<aui:input cssClass="lfr-input-text-container" label="temporary-storage-directory" name="uploadServletRequestImplTempDir" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_TEMP_DIR, StringPool.BLANK) %>" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>

					<liferay-ui:panel-container extended="<%= true %>" id="documentLibraryPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="documentLibraryPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "document-library") %>'>
							<aui:input cssClass="lfr-input-text-container" label="maximum-file-size" name="dlFileMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE) %>" />

							<aui:input cssClass="lfr-input-text-container" label="allowed-file-extensions" name="dlFileExtensions" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.DL_FILE_EXTENSIONS) %>" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>

					<liferay-ui:panel-container extended="<%= true %>" id="imageGalleryPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="imageGalleryPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "image-gallery") %>'>
							<aui:input cssClass="lfr-input-text-container" label="maximum-file-size" name="igImageMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.IG_IMAGE_MAX_SIZE) %>" />

							<aui:input cssClass="lfr-input-text-container" label="allowed-file-extensions" name="igImageExtensions" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.IG_IMAGE_EXTENSIONS) %>" />

							<aui:input cssClass="lfr-input-text-container" label="maximum-thumbnail-dimensions" name="igImageThumbnailMaxDimensions" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.IG_IMAGE_THUMBNAIL_MAX_DIMENSION) %>" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>

					<liferay-ui:panel-container extended="<%= true %>" id="webContentImagesPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="webContentImagesPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "web-content-images") %>'>
							<aui:input cssClass="lfr-input-text-container" label="maximum-file-size" name="journalImageSmallMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE) %>" />

							<aui:input cssClass="lfr-input-text-container" label="allowed-file-extensions" name="journalImageExtensions" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.JOURNAL_IMAGE_EXTENSIONS) %>" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>

					<liferay-ui:panel-container extended="<%= true %>" id="shoppingCartImagesPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="shoppingCartImagesPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "shopping-cart-images") %>'>
							<aui:input cssClass="lfr-input-text-container" label='<%= LanguageUtil.get(pageContext, "maximum-file-size") + "(" + LanguageUtil.get(pageContext,"large-image") + ")" %>' name="shoppingImageLargeMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE) %>" />

							<aui:input cssClass="lfr-input-text-container" label='<%= LanguageUtil.get(pageContext, "maximum-file-size") + "(" + LanguageUtil.get(pageContext,"medium-image") + ")" %>' name="shoppingImageMediumMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE) %>" />

							<aui:input cssClass="lfr-input-text-container" label='<%= LanguageUtil.get(pageContext, "maximum-file-size") + "(" + LanguageUtil.get(pageContext,"small-image") + ")" %>' name="shoppingImageSmallMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_SMALL_MAX_SIZE) %>" />

							<aui:input cssClass="lfr-input-text-container" label="allowed-file-extensions" name="shoppingImageExtensions" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.SHOPPING_IMAGE_EXTENSIONS) %>" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>

					<liferay-ui:panel-container extended="<%= true %>" id="softwareCatalogImagesPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="softwareCatalogImagesPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "software-catalog-images") %>'>
							<aui:input cssClass="lfr-input-text-container" label="maximum-file-size" name="scImageMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.SC_IMAGE_MAX_SIZE) %>" />

							<aui:input cssClass="lfr-input-text-container" label="maximum-thumbnail-height" name="scImageThumbnailMaxHeight" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.SC_IMAGE_THUMBNAIL_MAX_HEIGHT) %>" />

							<aui:input cssClass="lfr-input-text-container" label="maximum-thumbnail-width" name="scImageThumbnailMaxWidth" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.SC_IMAGE_THUMBNAIL_MAX_WIDTH) %>" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>

					<liferay-ui:panel-container extended="<%= true %>" id="userImagesPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="userImagesPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "user-images") %>'>
							<aui:input cssClass="lfr-input-text-container" label="maximum-file-size" name="usersImageMaxSize" type="text" value="<%= PrefsPropsUtil.getLong(PropsKeys.USERS_IMAGE_MAX_SIZE) %>" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>
				</aui:fieldset>

				<aui:button-row>

					<%
					String taglibUpdateFileUploads = renderResponse.getNamespace() + "saveServer('updateFileUploads');";
					%>

					<aui:button type="button" onClick="<%= taglibUpdateFileUploads %>" value="save" />
				</aui:button-row>
			</c:when>
			<c:when test='<%= tabs2.equals("mail") %>'>
				<aui:fieldset>
					<liferay-ui:panel-container extended="<%= true %>" id="mailServerSettingsPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="mailServerSettingsPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "configure-the-mail-server-settings") %>'>
							<aui:input cssClass="lfr-input-text-container" label="incoming-pop-server" name="pop3Host" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_HOST) %>" />

							<aui:input cssClass="lfr-input-text-container" label="incoming-port" name="pop3Port" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_PORT) %>" />

							<aui:input inlineLabel="right" label="use-a-secure-network-connection" name="pop3Secure" type="checkbox" value='<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL).equals("pop3s") %>' />

							<aui:input cssClass="lfr-input-text-container" label="user-name" name="pop3User" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_USER) %>" />

							<aui:input cssClass="lfr-input-text-container" label="password" name="pop3Password" type="password" value="<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD) %>" />

							<aui:input cssClass="lfr-input-text-container" label="outgoing-smtp-server" name="smtpHost" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST) %>" />

							<aui:input cssClass="lfr-input-text-container" label="outgoing-port" name="smtpPort" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT) %>" />

							<aui:input inlineLabel="right" label="use-a-secure-network-connection" name="smtpSecure" type="checkbox" value='<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL).equals("smtps") %>' />

							<aui:input cssClass="lfr-input-text-container" label="user-name" name="smtpUser" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER) %>" />

							<aui:input cssClass="lfr-input-text-container" label="password" name="smtpPassword" type="password" value="<%= PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD) %>" />

							<aui:input cssClass="lfr-textarea-container" label="manually-specify-additional-javamail-properties-to-override-the-above-configuration" name='<%= "advancedProperties" + PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES, StringPool.BLANK) %>' type="textarea" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>
				</aui:fieldset>

				<aui:button-row>

					<%
					String taglibUpdateMail = renderResponse.getNamespace() + "saveServer('updateMail');";
					%>

					<aui:button type="button" onClick="<%= taglibUpdateMail %>" value="save" />
				</aui:button-row>
			</c:when>
			<c:when test='<%= tabs2.equals("OpenOffice") %>'>
				<aui:fieldset>
					<liferay-ui:panel-container extended="<%= true %>" id="openOfficeConversionPanelContainer" persistState="<%= true %>">
						<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="openOfficeConversionPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "enabling-openoffice-integration-provides-document-conversion-functionality") %>'>
							<aui:input inlineLabel="right" name="enabled" type="checkbox" value="<%= PrefsPropsUtil.getBoolean(PropsKeys.OPENOFFICE_SERVER_ENABLED) %>" />

							<aui:input cssClass="lfr-input-text-container" name="port" type="text" value="<%= PrefsPropsUtil.getString(PropsKeys.OPENOFFICE_SERVER_PORT) %>" />
						</liferay-ui:panel>
					</liferay-ui:panel-container>
				</aui:fieldset>

				<aui:button-row>

					<%
					String taglibUpdateOpenOffice = renderResponse.getNamespace() + "saveServer('updateOpenOffice');";
					%>

					<aui:button type="button" onClick="<%= taglibUpdateOpenOffice %>" value="save" />
				</aui:button-row>
			</c:when>
			<c:when test='<%= tabs2.equals("script") %>'>

				<%
				String language = ParamUtil.getString(renderRequest, "language", "javascript");
				String script = ParamUtil.getString(renderRequest, "script", "// ### Javascript Sample ###\n\n// number = Packages.com.liferay.portal.service.UserLocalServiceUtil.getUsersCount();\n" + "// out.println(number);");

				String scriptOutput = (String)SessionMessages.get(renderRequest, "script_output");
				%>

				<aui:fieldset>
					<aui:select name="language">

						<%
						for (String supportedLanguage: ScriptingUtil.getSupportedLanguages()) {
						%>

							<aui:option label="<%= TextFormatter.format(supportedLanguage, TextFormatter.J) %>" selected="<%= supportedLanguage.equals(language) %>" value="<%= supportedLanguage %>" />

						<%
						}
						%>
					</aui:select>

					<aui:input cssClass="lfr-textarea-container" name="script" type="textarea" value="<%= script %>" />
				</aui:fieldset>

				<c:if test="<%= Validator.isNotNull(scriptOutput) %>">
					<b><liferay-ui:message key="output" /></b>

					<pre><%= scriptOutput %></pre>

					<br /><br />
				</c:if>

				<aui:button-row>

					<%
					String taglibRunScript = renderResponse.getNamespace() + "saveServer('runScript');";
					%>

					<aui:button type="button" onClick="<%= taglibRunScript %>" value="execute" />
				</aui:button-row>
			</c:when>
			<c:when test='<%= tabs2.equals("shutdown") %>'>
				<aui:fieldset>
					<aui:input label="number-of-minutes" name="minutes" size="3" type="text" />

					<aui:input cssClass="lfr-textarea-container" label="custom-message" name='<%= "message" + GetterUtil.getString(ShutdownUtil.getMessage()) %>' type="textarea" />
				</aui:fieldset>

				<aui:button-row>

					<%
					String taglibShutdown = renderResponse.getNamespace() + "saveServer('shutdown');";
					%>

					<aui:button type="button" onClick="<%= taglibShutdown %>" value="shutdown" />

					<c:if test="<%= ShutdownUtil.isInProcess() %>">

						<%
						String taglibCancelShutdown = "document." + renderResponse.getNamespace() + "fm." + renderResponse.getNamespace() + "minutes.value = 0;" + renderResponse.getNamespace() + "saveServer('shutdown');";
						%>

						<aui:button type="button" onClick="<%= taglibCancelShutdown %>" value="cancel-shutdown" />
					</c:if>
				</aui:button-row>
			</c:when>
			<c:otherwise>

				<%
				Runtime runtime = Runtime.getRuntime();

				numberFormat = NumberFormat.getInstance(locale);

				long usedMemory = runtime.totalMemory() - runtime.freeMemory();
				%>

				<div>

					<%
					DefaultValueDataset dataset = new DefaultValueDataset(usedMemory * 100 / runtime.totalMemory());

					MeterPlot plot = _getMeterPlot(dataset, pageContext);

					JFreeChart chart = _getChart(LanguageUtil.get(pageContext, "used-memory") + " / " + LanguageUtil.get(pageContext, "total-memory"), plot);
					%>

					<img border="0" src="<%= themeDisplay.getPathContext() %>/display_chart?filename=<%= ServletUtilities.saveChartAsPNG(chart, 280, 180, null, null) %>" />

					<%
					dataset = new DefaultValueDataset(usedMemory * 100 / runtime.maxMemory());

					plot = _getMeterPlot(dataset, pageContext);

					chart = _getChart(LanguageUtil.get(pageContext, "used-memory") + " / " + LanguageUtil.get(pageContext, "maximum-memory"), plot);
					%>

					<img border="0" src="<%= themeDisplay.getPathContext() %>/display_chart?filename=<%= ServletUtilities.saveChartAsPNG(chart, 280, 180, null, null) %>" />
				</div>

				<br />

				<table class="lfr-table">
				<tr>
					<td>
						<liferay-ui:message key="used-memory" />:
					</td>
					<td>
						<%= numberFormat.format(usedMemory) %> <liferay-ui:message key="bytes" />
					</td>
				</tr>
				<tr>
					<td>
						<liferay-ui:message key="total-memory" />:
					</td>
					<td>
						<%= numberFormat.format(runtime.totalMemory()) %> <liferay-ui:message key="bytes" />
					</td>
				</tr>
				<tr>
					<td>
						<liferay-ui:message key="maximum-memory" />:
					</td>
					<td>
						<%= numberFormat.format(runtime.maxMemory()) %> <liferay-ui:message key="bytes" />
					</td>
				</tr>
				</table>

				<br />

				<liferay-ui:panel-container extended="<%= true %>" id="serverAdministrationActionsPanelContainer" persistState="<%= true %>">
					<liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="serverAdministrationActionsPanel" persistState="<%= true %>" title='<%= LanguageUtil.get(pageContext, "actions") %>'>
						<table class="lfr-table">
						<tr>
							<td>
								<liferay-ui:message key="run-the-garbage-collector-to-free-up-memory" />
							</td>
							<td>
								<input type="button" value="<liferay-ui:message key="execute" />" onClick="<portlet:namespace />saveServer('gc');" />
							</td>
						</tr>
						<tr>
							<td>
								<liferay-ui:message key="clear-content-cached-by-this-vm" />
							</td>
							<td>
								<input type="button" value="<liferay-ui:message key="execute" />" onClick="<portlet:namespace />saveServer('cacheSingle');" />
							</td>
						</tr>
						<tr>
							<td>
								<liferay-ui:message key="clear-content-cached-across-the-cluster" />
							</td>
							<td>
								<input type="button" value="<liferay-ui:message key="execute" />" onClick="<portlet:namespace />saveServer('cacheMulti');" />
							</td>
						</tr>
						<tr>
							<td>
								<liferay-ui:message key="clear-the-database-cache" />
							</td>
							<td>
								<input type="button" value="<liferay-ui:message key="execute" />" onClick="<portlet:namespace />saveServer('cacheDb');" />
							</td>
						</tr>
						<tr>
							<td>
								<liferay-ui:message key="reindex-all-search-indexes" />
							</td>
							<td>
								<input type="button" value="<liferay-ui:message key="execute" />" onClick="<portlet:namespace />saveServer('reindex');" />
							</td>
						</tr>
						<tr>
							<td>
								<liferay-ui:message key="generate-thread-dump" />
							</td>
							<td>
								<input type="button" value="<liferay-ui:message key="execute" />" onClick="<portlet:namespace />saveServer('threadDump');" />
							</td>
						</tr>
						<tr>
							<td>
								<liferay-ui:message key="verify-database-tables-of-all-plugins" />
							</td>
							<td>
								<input type="button" value="<liferay-ui:message key="execute" />" onClick="<portlet:namespace />saveServer('verifyPluginTables');" />
							</td>
						</tr>
						</table>
					</liferay-ui:panel>
				</liferay-ui:panel-container>
			</c:otherwise>
		</c:choose>
	</c:otherwise>
</c:choose>

<%!
private JFreeChart _getChart(String title, MeterPlot plot) {
	JFreeChart chart = new JFreeChart(title, new Font(null, Font.PLAIN, 13), plot, true);

	chart.setBackgroundPaint(Color.white);

	chart.removeLegend();

	return chart;
}

private MeterPlot _getMeterPlot(DefaultValueDataset dataset, PageContext pageContext) {
	MeterPlot plot = new MeterPlot(dataset);

	plot.setDialBackgroundPaint(Color.white);
	plot.setDialShape(DialShape.PIE);
	plot.setDialOutlinePaint(Color.gray);
	plot.setTickLabelFont(new Font(null, Font.PLAIN, 10));
	plot.setTickLabelPaint(Color.darkGray);
	plot.setTickLabelsVisible(true);
	plot.setTickPaint(Color.lightGray);
	plot.setTickSize(5D);
	plot.setMeterAngle(180);
	plot.setNeedlePaint(Color.darkGray);
	plot.setRange(new Range(0.0D, 100D));
	plot.setValueFont(new Font(null, Font.PLAIN, 10));
	plot.setValuePaint(Color.black);
	plot.setUnits("%");

	plot.addInterval(new MeterInterval(LanguageUtil.get(pageContext, "normal"), new Range(0.0D, 75D), Color.lightGray, new BasicStroke(2.0F), new Color(0, 255, 0, 64)));
	plot.addInterval(new MeterInterval(LanguageUtil.get(pageContext, "warning"), new Range(75D, 90D), Color.lightGray, new BasicStroke(2.0F), new Color(255, 255, 0, 64)));
	plot.addInterval(new MeterInterval(LanguageUtil.get(pageContext, "critical"), new Range(90D, 100D), Color.lightGray, new BasicStroke(2.0F), new Color(255, 0, 0, 128)));

	return plot;
}
%>