websitepanel/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangePublicFolders.ascx.cs
robvde 6203fd48c5 Fixed: When having multiple organization the quotas and available resources
quotas were only displayed for the tenant. Quota usage now displayed per
organization

Added public folders to organization home screen

Added Lync to organization home screen

Added the ability to hide the theme and locale. This can be hidden by adding
the element <HideThemeAndLocale>true</HideThemeAndLocale> to the file
SiteSettings.config
2012-09-03 15:00:52 +04:00

206 lines
No EOL
6.8 KiB
C#

// Copyright (c) 2012, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// - Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// - Neither the name of the Outercurve Foundation nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebsitePanel.Providers.HostedSolution;
namespace WebsitePanel.Portal.ExchangeServer
{
public partial class ExchangePublicFolders : WebsitePanelModuleBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// quota values
BindStats();
// build tree
BuildFoldersTree();
}
}
private void BindStats()
{
OrganizationStatistics stats = ES.Services.ExchangeServer.GetOrganizationStatisticsByOrganization(PanelRequest.ItemID);
OrganizationStatistics tenantStats = ES.Services.ExchangeServer.GetOrganizationStatistics(PanelRequest.ItemID);
foldersQuota.QuotaUsedValue = stats.CreatedPublicFolders;
foldersQuota.QuotaValue = stats.AllocatedPublicFolders;
if (stats.AllocatedPublicFolders != -1) foldersQuota.QuotaAvailable = tenantStats.AllocatedPublicFolders - tenantStats.CreatedPublicFolders;
}
private void BuildFoldersTree()
{
// clear all tree
FoldersTree.Nodes.Clear();
// get organization info
Organization org = ES.Services.ExchangeServer.GetOrganization(PanelRequest.ItemID);
string rootFolder = org.OrganizationId;
TreeNode rootNode = new TreeNode(rootFolder, "");
rootNode.Expanded = true;
rootNode.ImageUrl = GetThemedImage("FileManager/OpenFolder.gif");
FoldersTree.Nodes.Add(rootNode);
// get public folder accounts
ExchangeAccount[] folders = ES.Services.ExchangeServer.GetAccounts(PanelRequest.ItemID, ExchangeAccountType.PublicFolder);
// add folders to the tree
foreach(ExchangeAccount folder in folders)
{
string[] path = folder.DisplayName.Substring(1).Split('\\');
AddNodeToTree(folder.AccountId, path);
}
}
private void AddNodeToTree(int accountId, string[] path)
{
TreeNodeCollection nodes = FoldersTree.Nodes;
TreeNode node = null;
int i = 0;
while (i < path.Length)
{
bool found = false;
foreach (TreeNode childNode in nodes)
{
if (String.Compare(childNode.Text, path[i], true) == 0)
{
node = childNode;
nodes = childNode.ChildNodes;
found = true;
break;
}
}
// create node if required
if (!found)
{
node = new TreeNode(path[i], "");
node.Expanded = true;
node.ShowCheckBox = true;
node.ImageUrl = GetThemedImage("FileManager/OpenFolder.gif");
nodes.Add(node);
nodes = node.ChildNodes;
}
// set accountId
if (i == path.Length - 1)
node.Value = accountId.ToString();
// set navigation url
if(!String.IsNullOrEmpty(node.Value))
node.NavigateUrl = EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), "public_folder_settings",
"AccountID=" + node.Value,
"ItemID=" + PanelRequest.ItemID.ToString());
i++;
}
}
protected void btnCreatePublicFolder_Click(object sender, EventArgs e)
{
Response.Redirect(EditUrl("ItemID", PanelRequest.ItemID.ToString(), "create_public_folder",
"SpaceID=" + PanelSecurity.PackageId.ToString()));
}
protected void btnDeleteFolders_Click(object sender, EventArgs e)
{
List<int> accountIds = new List<int>();
// check if any folder is checked to delete
if (FoldersTree.CheckedNodes.Count == 0 && FoldersTree.Nodes[0].ChildNodes.Count > 0)
{
messageBox.ShowWarningMessage("EXCHANGE_SELECT_PUBLIC_FOLDER_TO_DELETE");
}
else
{
if (FoldersTree.Nodes[0].ChildNodes.Count == 0)
{
messageBox.ShowWarningMessage("EXCHANGE_NONE_PUBLIC_FOLDER_TO_DELETE");
}
}
// delete folders
GetSelectedFoldersRecursively(accountIds, FoldersTree.Nodes[0]);
// delete selected folders
try
{
int result = ES.Services.ExchangeServer.DeletePublicFolders(
PanelRequest.ItemID, accountIds.ToArray());
if (result < 0)
{
messageBox.ShowResultMessage(result);
return;
}
}
catch (Exception ex)
{
ShowErrorMessage("EXCHANGE_DELETE_PUBLIC_FOLDER", ex);
}
// re-build tree
BuildFoldersTree();
// rebind stats
BindStats();
}
private void GetSelectedFoldersRecursively(List<int> accountIds, TreeNode parentNode)
{
foreach (TreeNode node in parentNode.ChildNodes)
{
// recurse children
GetSelectedFoldersRecursively(accountIds, node);
}
// delete node if required
if (parentNode.Checked)
{
accountIds.Add(Utils.ParseInt(parentNode.Value, 0));
}
}
}
}