<%
/**
 * 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.
 */
%>

<%
List subfolderIds = new ArrayList();

subfolderIds.add(new Long(curFolder.getFolderId()));

DLFolderServiceUtil.getSubfolderIds(subfolderIds, scopeGroupId, curFolder.getFolderId());

int curFoldersCount = subfolderIds.size() - 1;
int curFileEntriesCount = DLFolderServiceUtil.getFileEntriesAndFileShortcutsCount(scopeGroupId, subfolderIds, status);

for (int j = 0; j < folderColumns.length; j++) {
	String folderColumn = folderColumns[j];
%>

	<c:choose>
		<c:when test='<%= folderColumn.equals("action") %>'>

			<%
			String align = SearchEntry.DEFAULT_ALIGN;

			if ((j + 1) == folderColumns.length) {
				align = "right";
			}
			%>

			<liferay-ui:search-container-column-jsp
				align="<%= align %>"
				path="/html/portlet/document_library/folder_action.jsp"
			/>
		</c:when>
		<c:when test='<%= folderColumn.equals("downloads") %>'>
			<liferay-ui:search-container-column-text
				name="<%= folderColumn %>"
				value="--"
			/>
		</c:when>
		<c:when test='<%= folderColumn.equals("folder") || folderColumn.equals("name") %>'>
			<liferay-ui:search-container-column-text
				buffer="buffer"
				href="<%= rowURL %>"
				name="<%= folderColumn %>"
			>

				<%
				buffer.append("<a href=\"");
				buffer.append(rowURL);
				buffer.append("\">");
				buffer.append("<img align=\"left\" border=\"0\" src=\"");
				buffer.append(themeDisplay.getPathThemeImages());
				buffer.append("/common/folder.png\">");
				buffer.append("<strong>");
				buffer.append(curFolder.getName());
				buffer.append("</strong>");

				if (Validator.isNotNull(curFolder.getDescription())) {
					buffer.append("<br />");
					buffer.append(curFolder.getDescription());
				}

				buffer.append("</a>");

				if (showSubfolders) {
					List subfolders = DLFolderServiceUtil.getFolders(scopeGroupId, curFolder.getFolderId(), 0, 5);

					if (!subfolders.isEmpty()) {
						int subfoldersCount = DLFolderServiceUtil.getFoldersCount(scopeGroupId, curFolder.getFolderId());

						buffer.append("<br /><u>");
						buffer.append(LanguageUtil.get(pageContext, "subfolders"));
						buffer.append("</u>: ");

						for (int k = 0; k < subfolders.size(); k++) {
							DLFolder subfolder = (DLFolder)subfolders.get(k);

							rowURL.setParameter("folderId", String.valueOf(subfolder.getFolderId()));

							buffer.append("<a href=\"");
							buffer.append(rowURL);
							buffer.append("\">");
							buffer.append(subfolder.getName());
							buffer.append("</a>");

							if ((k + 1) < subfolders.size()) {
								buffer.append(", ");
							}
						}

						if (subfoldersCount > subfolders.size()) {
							rowURL.setParameter("folderId", String.valueOf(curFolder.getFolderId()));

							buffer.append(", <a href=\"");
							buffer.append(rowURL);
							buffer.append("\">");
							buffer.append(LanguageUtil.get(pageContext, "more"));
							buffer.append(" &raquo;");
							buffer.append("</a>");
						}

						rowURL.setParameter("folderId", String.valueOf(curFolder.getFolderId()));
					}
				}
				%>

			</liferay-ui:search-container-column-text>
		</c:when>
		<c:when test='<%= folderColumn.equals("locked") %>'>

			<%
			boolean isLocked = LockLocalServiceUtil.isLocked(DLFolder.class.getName(), curFolder.getFolderId());
			%>

			<liferay-ui:search-container-column-text
				href="<%= rowURL %>"
				name="<%= folderColumn %>"
				value='<%= LanguageUtil.get(pageContext, isLocked ? "yes" : "no") %>'
			/>
		</c:when>
		<c:when test='<%= folderColumn.equals("num-of-documents") %>'>
			<liferay-ui:search-container-column-text
				href="<%= rowURL %>"
				name="<%= folderColumn %>"
				value="<%= String.valueOf(curFileEntriesCount) %>"
			/>
		</c:when>
		<c:when test='<%= folderColumn.equals("num-of-folders") %>'>
			<liferay-ui:search-container-column-text
				href="<%= rowURL %>"
				name="<%= folderColumn %>"
				value="<%= String.valueOf(curFoldersCount) %>"
			/>
		</c:when>
		<c:when test='<%= folderColumn.equals("size") %>'>
			<liferay-ui:search-container-column-text
				name="<%= folderColumn %>"
				value="--"
			/>
		</c:when>
		<c:when test='<%= folderColumn.equals("tags") %>'>
			<liferay-ui:search-container-column-text
				name="<%= folderColumn %>"
				value="--"
			/>
		</c:when>
	</c:choose>

<%
}
%>