From 231bbfa2022a5589b46b8fac209ad3ccbfc43bfc Mon Sep 17 00:00:00 2001 From: me Date: Sun, 8 Feb 2015 22:30:39 +0400 Subject: [PATCH] wsp-10311 Set service level for multiple accounts at once + VIP checkbox --- .../WebsitePanel_SharedResources.ascx.resx | 9 + .../App_Themes/Default/Styles/Skin.css | 5 + .../WebsitePanel/Code/Framework/Utils.cs | 26 +- .../WebsitePanel/Code/Helpers/Extensions.cs | 18 ++ .../ExchangeServer/ExchangeMailboxes.ascx | 77 +++-- .../ExchangeServer/ExchangeMailboxes.ascx.cs | 38 ++- .../ExchangeMailboxes.ascx.designer.cs | 9 + .../ExchangeServer/OrganizationUsers.ascx | 64 ++-- .../ExchangeServer/OrganizationUsers.ascx.cs | 39 +++ .../OrganizationUsers.ascx.designer.cs | 9 + .../WebsitePanel/IPAddresses.ascx.cs | 1 + .../ServerIPAddressesControl.ascx.cs | 1 + .../App_LocalResources/UserActions.ascx.resx | 189 ++++++++++++ .../UserControls/UserActions.ascx | 135 +++++++++ .../UserControls/UserActions.ascx.cs | 253 ++++++++++++++++ .../UserControls/UserActions.ascx.designer.cs | 277 ++++++++++++++++++ .../WebsitePanel.Portal.Modules.csproj | 9 + 17 files changed, 1101 insertions(+), 58 deletions(-) create mode 100644 WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/App_LocalResources/UserActions.ascx.resx create mode 100644 WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx create mode 100644 WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx.cs create mode 100644 WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx.designer.cs diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/App_GlobalResources/WebsitePanel_SharedResources.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/App_GlobalResources/WebsitePanel_SharedResources.ascx.resx index fb127d9e..8b25c269 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/App_GlobalResources/WebsitePanel_SharedResources.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/App_GlobalResources/WebsitePanel_SharedResources.ascx.resx @@ -3136,6 +3136,15 @@ User general settings have been successfully updated. + + Action has been successfully performed. + + + Failed to perform action. + + + Please select the users for which you want to perform actions. + User password has been successfully updated. diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/App_Themes/Default/Styles/Skin.css b/WebsitePanel/Sources/WebsitePanel.WebPortal/App_Themes/Default/Styles/Skin.css index 08834b23..829d8662 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/App_Themes/Default/Styles/Skin.css +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/App_Themes/Default/Styles/Skin.css @@ -93,6 +93,7 @@ select:disabled {border:1px solid #ccc; background:#f5f5f5; color:#ccc; cursor:n textarea {font-family:inherit; font-size:inherit; color:inherit; background:#fff; border: 1px solid #ccc; padding:3px 0 3px 3px; margin:0; resize:none;} /* checkbox */ input[type=checkbox], input[type=radio] {margin:8px 4px 8px; vertical-align:-1px;} +.HeaderCheckbox {margin-left:5px;} input[type=image] {margin-right:4px;} .LoginLabel {display:block; line-height:34px; width:auto !important; padding-right:8px;} .LoginContainer .SubHead {padding-right:8px; color:#333;} @@ -180,6 +181,9 @@ h2.ProductTitle.Huge {margin:0;} .FormButtonsBarClean {clear: both; padding-bottom: 4px;} .FormButtonsBarCleanLeft {float: left;} .FormButtonsBarCleanRight {text-align: right;} +.FormButtonsBarCleanMiddle {float: right;} +.FormButtonsBarCleanSeparator {padding-right: 30px;} +.FormButtonsBarCleanSeparatorSmall {padding-right: 15px;} .GridFooter .Left {float: left;} .GridFooter .Right {text-align: right;} .FormRow {padding-top: 4px; padding-bottom: 4px;} @@ -190,6 +194,7 @@ SPAN.Checkbox.Bold {font-weight: bold;} .Checkbox INPUT {vertical-align: middle;} .FormFooter {padding:10px 0;} .FormFooterClean {font-size: 9pt; margin-top: 10px; padding: 10px 10px 0px 0px; border-top: solid 1px #DFDFDF;} +.FormFooterMiddle {padding:10px;} .FormRBtnL {padding-top: 10px;} UL.VerticalButtons {margin: 0px; list-style: none; padding-left: 20px; float: right; width: 150px;} UL.VerticalButtons LI {padding-top: 2px; padding-bottom: 2px;} diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Framework/Utils.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Framework/Utils.cs index 428ab43f..fccbcbb2 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Framework/Utils.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Framework/Utils.cs @@ -328,21 +328,21 @@ namespace WebsitePanel.Portal return idn.GetAscii(domainName); } - /// - /// Adds the specified parameter to the Query String. - /// - /// - /// Name of the parameter to add. - /// Value for the parameter to add. - /// Url with added parameter. - public static Uri AddParameter(this Uri url, string paramName, string paramValue) + public static List GetCheckboxValuesFromGrid(GridView gridView, string checkboxName) { - var uriBuilder = new UriBuilder(url); - var query = HttpUtility.ParseQueryString(uriBuilder.Query); - query[paramName] = paramValue; - uriBuilder.Query = query.ToString(); + // Get checked users + var userIds = new List(); - return new Uri(uriBuilder.ToString()); + foreach (GridViewRow gvr in gridView.Rows) + { + if (((CheckBox)gvr.FindControl(checkboxName)).Checked) + { + string userId = gridView.DataKeys[gvr.DataItemIndex].Value.ToString(); + userIds.Add((T)Convert.ChangeType(userId, typeof(T))); + } + } + + return userIds; } } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/Extensions.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/Extensions.cs index 767435ca..b38fc2ea 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/Extensions.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/Code/Helpers/Extensions.cs @@ -66,6 +66,24 @@ namespace WebsitePanel.Portal.Code.Helpers || PackagesHelper.CheckGroupQuotaEnabled(packageId, t.ResourceGroup, t.Quota) select t; } + + + /// + /// Adds the specified parameter to the Query String. + /// + /// + /// Name of the parameter to add. + /// Value for the parameter to add. + /// Url with added parameter. + public static Uri AddParameter(this Uri url, string paramName, string paramValue) + { + var uriBuilder = new UriBuilder(url); + var query = HttpUtility.ParseQueryString(uriBuilder.Query); + query[paramName] = paramValue; + uriBuilder.Query = query.ToString(); + + return new Uri(uriBuilder.ToString()); + } } public class Tab diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx index aba30904..910bb75b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx @@ -2,6 +2,15 @@ <%@ Register Src="../UserControls/SimpleMessageBox.ascx" TagName="SimpleMessageBox" TagPrefix="wsp" %> <%@ Register Src="../UserControls/QuotaViewer.ascx" TagName="QuotaViewer" TagPrefix="wsp" %> <%@ Register Src="../UserControls/EnableAsyncTasksSupport.ascx" TagName="EnableAsyncTasksSupport" TagPrefix="wsp" %> +<%@ Register Src="../UserControls/UserActions.ascx" TagName="UserActions" TagPrefix="wsp" %> + + + + @@ -23,35 +32,45 @@ -
- - - - - - 10 - 20 - 50 - - 100 - - +
+ + + + + + +
+ + + + + + + + 10 + 20 + 50 - - DisplayName - Email - AccountName - Account Number - Login - - + 100 + + + + + DisplayName + Email + AccountName + Account Number + Login + + +
@@ -60,6 +79,14 @@ + + + + + + + + @@ -80,7 +107,7 @@ - + <%# GetServiceLevel((int)Eval("LevelId")).LevelName%> diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx.cs index 734314f2..3ac06800 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx.cs @@ -69,7 +69,6 @@ namespace WebsitePanel.Portal.ExchangeServer BindServiceLevels(); - if (cntx.Quotas.ContainsKey(Quotas.EXCHANGE2007_ISCONSUMER)) { if (cntx.Quotas[Quotas.EXCHANGE2007_ISCONSUMER].QuotaAllocatedValue != 1) @@ -273,5 +272,42 @@ namespace WebsitePanel.Portal.ExchangeServer odsAccountsPaged.SelectParameters["accountTypes"].DefaultValue = string.Join(",", accountTypes); } + protected void userActions_OnExecutingUserAction(object sender, EventArgs e) + { + // Get checked users + var userIds = Utils.GetCheckboxValuesFromGrid(gvMailboxes, "chkSelectedUsersIds"); + + if (userActions.SelectedAction != UserActionTypes.None) + { + if (userIds.Count > 0) + { + try + { + var result = userActions.DoUserActions(userIds); + + if (result < 0) + { + messageBox.ShowResultMessage(result); + return; + } + + messageBox.ShowSuccessMessage("ORGANIZATION_USERS_ACTIONS"); + } + catch (Exception ex) + { + messageBox.ShowErrorMessage("ORGANIZATION_USERS_ACTIONS", ex); + } + + // Refresh users grid + gvMailboxes.DataBind(); + } + else + { + messageBox.ShowWarningMessage("ORGANIZATION_USERS_ACTIONS"); + } + } + + userActions.ResetSelection(); + } } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx.designer.cs index 94c5736e..121ed1c5 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/ExchangeMailboxes.ascx.designer.cs @@ -85,6 +85,15 @@ namespace WebsitePanel.Portal.ExchangeServer { /// protected global::System.Web.UI.WebControls.Button btnCreateMailbox; + /// + /// userActions control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::WebsitePanel.Portal.UserActions userActions; + /// /// SearchPanel control. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx index 5f70a82f..a963d2c4 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx @@ -3,6 +3,15 @@ <%@ Register Src="../UserControls/SimpleMessageBox.ascx" TagName="SimpleMessageBox" TagPrefix="wsp" %> <%@ Register Src="../UserControls/QuotaViewer.ascx" TagName="QuotaViewer" TagPrefix="wsp" %> <%@ Register Src="../UserControls/EnableAsyncTasksSupport.ascx" TagName="EnableAsyncTasksSupport" TagPrefix="wsp" %> +<%@ Register Src="../UserControls/UserActions.ascx" TagName="UserActions" TagPrefix="wsp" %> + + + + @@ -25,25 +34,35 @@ -
- - - 10 - 20 - 50 - 100 - +
+ + + + + + +
+ + + + + 10 + 20 + 50 + 100 + - - DisplayName - Email - AccountName - Account Number - Login - - + + DisplayName + Email + AccountName + Account Number + Login + + +
@@ -59,7 +78,14 @@
- + + + + + + + + diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx.cs index 2854f39c..1c711e93 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx.cs @@ -388,5 +388,44 @@ namespace WebsitePanel.Portal.HostedSolution messageBox.ShowErrorMessage("ORGANIZATIONS_DELETE_USERS", ex); } } + + + protected void userActions_OnExecutingUserAction(object sender, EventArgs e) + { + // Get checked users + var userIds = Utils.GetCheckboxValuesFromGrid(gvUsers, "chkSelectedUsersIds"); + + if (userActions.SelectedAction != UserActionTypes.None) + { + if (userIds.Count > 0) + { + try + { + var result = userActions.DoUserActions(userIds); + + if (result < 0) + { + messageBox.ShowResultMessage(result); + return; + } + + messageBox.ShowSuccessMessage("ORGANIZATION_USERS_ACTIONS"); + } + catch (Exception ex) + { + messageBox.ShowErrorMessage("ORGANIZATION_USERS_ACTIONS", ex); + } + + // Refresh users grid + gvUsers.DataBind(); + } + else + { + messageBox.ShowWarningMessage("ORGANIZATION_USERS_ACTIONS"); + } + } + + userActions.ResetSelection(); + } } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx.designer.cs index 22dab4cf..17643c1b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ExchangeServer/OrganizationUsers.ascx.designer.cs @@ -85,6 +85,15 @@ namespace WebsitePanel.Portal.HostedSolution { /// protected global::System.Web.UI.WebControls.Button btnCreateUser; + /// + /// userActions control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::WebsitePanel.Portal.UserActions userActions; + /// /// SearchPanel control. /// diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/IPAddresses.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/IPAddresses.ascx.cs index 950cd86d..10757751 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/IPAddresses.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/IPAddresses.ascx.cs @@ -31,6 +31,7 @@ using System.Web.UI.WebControls; using System.Collections.Generic; using WebsitePanel.Providers.Common; using System.Text; +using WebsitePanel.Portal.Code.Helpers; namespace WebsitePanel.Portal { diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ServerIPAddressesControl.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ServerIPAddressesControl.ascx.cs index fc805eee..b3d8849c 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ServerIPAddressesControl.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ServerIPAddressesControl.ascx.cs @@ -36,6 +36,7 @@ using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; +using WebsitePanel.Portal.Code.Helpers; namespace WebsitePanel.Portal { diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/App_LocalResources/UserActions.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/App_LocalResources/UserActions.ascx.resx new file mode 100644 index 00000000..659f25a5 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/App_LocalResources/UserActions.ascx.resx @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Cancel + + + Ok + + + Cancel + + + Ok + + + Cancel + + + Ok + + + Cancel + + + Ok + + + - Actions - + + + Disable + + + Enable + + + Set Service Level + + + Set VIP + + + Set VIP + + + Unset VIP + + + Disable users + + + Enable users + + + Service Level + + + Set VIP + + + Do you wish to disable all selected users? + + + Do you wish to enable all selected users? + + + Please select a Service Level for the all checked users + + + Please select a VIP status for the all checked users + + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx new file mode 100644 index 00000000..93583c75 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx @@ -0,0 +1,135 @@ +<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserActions.ascx.cs" Inherits="WebsitePanel.Portal.UserActions" %> + + + + + + Actions + Disable + Enable + SetServiceLevel + SetVIP + + + + + <%-- Enable --%> + + + <%-- Disable --%> + + + <%--Set Service Level--%> + + + <%-- VIP --%> + + + + + + + + + + + diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx.cs new file mode 100644 index 00000000..ab5b3c8f --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/UserControls/UserActions.ascx.cs @@ -0,0 +1,253 @@ +// Copyright (c) 2015, 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.Drawing; +using System.Linq; +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 Microsoft.Web.Services3.Referral; +using WebsitePanel.EnterpriseServer; +using WebsitePanel.EnterpriseServer.Base.HostedSolution; +using WebsitePanel.Providers.HostedSolution; + +namespace WebsitePanel.Portal +{ + public enum UserActionTypes + { + None = 0, + Disable = 1, + Enable = 2, + SetServiceLevel = 3, + SetVIP = 4, + } + + public partial class UserActions : WebsitePanelControlBase + { + public event EventHandler ExecutingUserAction; + + protected void Page_Load(object sender, EventArgs e) + { + // Remove Service Level item and VIP item from Action List if current Hosting plan does not allow Service Levels + if (!PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId).Groups.ContainsKey(ResourceGroups.ServiceLevels)) + { + ddlUserActions.Items.Remove(ddlUserActions.Items.FindByValue(UserActionTypes.SetServiceLevel.ToString())); + ddlUserActions.Items.Remove(ddlUserActions.Items.FindByValue(UserActionTypes.SetVIP.ToString())); + } + } + + public UserActionTypes SelectedAction + { + get + { + return (UserActionTypes)Convert.ToInt32(ddlUserActions.SelectedValue); + } + } + + protected void ddlUserActions_OnSelectedIndexChanged(object sender, EventArgs e) + { + switch (SelectedAction) + { + case UserActionTypes.Disable: + Modal.PopupControlID = DisablePanel.ID; + break; + case UserActionTypes.Enable: + Modal.PopupControlID = EnablePanel.ID; + break; + case UserActionTypes.SetServiceLevel: + FillServiceLevelsList(); + Modal.PopupControlID = ServiceLevelPanel.ID; + break; + case UserActionTypes.SetVIP: + Modal.PopupControlID = VIPPanel.ID; + break; + } + + Modal.Show(); + } + + public int DoUserActions(List userIds) + { + switch (SelectedAction) + { + case UserActionTypes.Disable: + return ChangeUsersSettings(userIds, true, null, null); + case UserActionTypes.Enable: + return ChangeUsersSettings(userIds, false, null, null); + case UserActionTypes.SetServiceLevel: + return ChangeUsersSettings(userIds, null, SelectedServiceId, null); + case UserActionTypes.SetVIP: + return ChangeUsersSettings(userIds, null, null, SelectedVIP); + } + + return 0; + } + + protected void btnModalOk_Click(object sender, EventArgs e) + { + if (ExecutingUserAction != null) + ExecutingUserAction(this, new EventArgs()); + } + protected void btnModalCancel_OnClick(object sender, EventArgs e) + { + ResetSelection(); + } + + public void ResetSelection() + { + ddlUserActions.ClearSelection(); + } + + protected int ChangeUsersSettings(List userIds, bool? disable, int? serviceLevelId, bool? isVIP) + { + foreach (var userId in userIds) + { + OrganizationUser user = ES.Services.Organizations.GetUserGeneralSettings(PanelRequest.ItemID, userId); + + int result = ES.Services.Organizations.SetUserGeneralSettings( + PanelRequest.ItemID, + userId, + + user.DisplayName, + string.Empty, + false, + disable ?? user.Disabled, + user.Locked, + + user.FirstName, + user.Initials, + user.LastName, + + user.Address, + user.City, + user.State, + user.Zip, + user.Country, + + user.JobTitle, + user.Company, + user.Department, + user.Office, + user.Manager != null ? user.Manager.AccountName : String.Empty, + + user.BusinessPhone, + user.Fax, + user.HomePhone, + user.MobilePhone, + user.Pager, + user.WebPage, + user.Notes, + user.ExternalEmail, + user.SubscriberNumber, + serviceLevelId ?? user.LevelId, + isVIP ?? user.IsVIP); + + if (result < 0) + { + return result; + } + } + + return 0; + } + + + #region ServiceLevel + + protected int? SelectedServiceId + { + get + { + if (ddlServiceLevels.SelectedValue == string.Empty) + return null; + + return Convert.ToInt32(ddlServiceLevels.SelectedValue); + } + } + + protected void FillServiceLevelsList() + { + PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); + + if (cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels)) + { + List enabledServiceLevels = new List(); + + foreach (var quota in cntx.Quotas.Where(x => x.Key.Contains(Quotas.SERVICE_LEVELS))) + { + foreach (var serviceLevel in ES.Services.Organizations.GetSupportServiceLevels()) + { + if (quota.Key.Replace(Quotas.SERVICE_LEVELS, "") == serviceLevel.LevelName && CheckServiceLevelQuota(quota.Value)) + { + enabledServiceLevels.Add(serviceLevel); + } + } + } + + ddlServiceLevels.DataSource = enabledServiceLevels; + ddlServiceLevels.DataTextField = "LevelName"; + ddlServiceLevels.DataValueField = "LevelId"; + ddlServiceLevels.DataBind(); + + ddlServiceLevels.Items.Insert(0, new ListItem("