/// <summary> /// Unigrid button clicked. /// </summary> protected void gridElem_OnAction(string actionName, object actionArgument) { // Perform 'remove' action if (actionName == "remove") { // Delete the object int accountId = ValidationHelper.GetInteger(actionArgument, 0); AccountInfo account = AccountInfoProvider.GetAccountInfo(accountId); if (account != null) { // User has no permission to modify site accounts if (((account.AccountSiteID > 0) && !modifySiteAccounts) || !ContactGroupHelper.AuthorizedModifyContactGroup(cgi.ContactGroupSiteID, false)) { CMSPage.RedirectToCMSDeskAccessDenied(ModuleEntry.CONTACTMANAGEMENT, "ModifyAccounts"); } // User has no permission to modify global accounts else if ((account.AccountSiteID == 0) && !modifyGlobalAccounts || !ContactGroupHelper.AuthorizedModifyContactGroup(cgi.ContactGroupSiteID, false)) { CMSPage.RedirectToCMSDeskAccessDenied(ModuleEntry.CONTACTMANAGEMENT, "ModifyGlobalAccounts"); } // User has permission else { // Get the relationship object ContactGroupMemberInfo mi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, accountId, ContactGroupMemberTypeEnum.Account); if (mi != null) { ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(mi); } } } } }
/// <summary> /// Items changed event handler. /// </summary> protected void UniSelector_OnItemsSelected(object sender, EventArgs e) { CheckModifyPermissions(); // Get new items from selector string newValues = ValidationHelper.GetString(accountSelector.Value, null); string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Get all selected items foreach (string item in newItems) { // Check if relation already exists int itemID = ValidationHelper.GetInteger(item, 0); if (ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, itemID, ContactGroupMemberTypeEnum.Account) == null) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(cgi.ContactGroupID, itemID, ContactGroupMemberTypeEnum.Account, MemberAddedHowEnum.Manual); } } gridElem.ReloadData(); pnlUpdate.Update(); accountSelector.Value = null; }
/// <summary> /// New groups selected event handler. /// </summary> private void UniSelector_OnItemsSelected(object sender, EventArgs e) { // Get new items from selector string newValues = ValidationHelper.GetString(selectGroup.Value, null); string[] newGroupIDs = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newGroupIDs != null) { ContactGroupMemberInfo cgmi; ContactGroupInfo group; int groupID; // Get all selected groups foreach (string newGroupID in newGroupIDs) { groupID = ValidationHelper.GetInteger(newGroupID, 0); group = ContactGroupInfoProvider.GetContactGroupInfo(groupID); if (group == null) { // Group was most probably deleted after the uniselector // window was opened. continue; } if (UserCanManageGroup(group) || UserCanManageContact(editedContact)) { // Check if relation already exists cgmi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(groupID, editedContact.ContactID, ContactGroupMemberTypeEnum.Contact); if (cgmi == null) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupID, editedContact.ContactID, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual); } else if (!cgmi.ContactGroupMemberFromManual) { cgmi.ContactGroupMemberFromManual = true; ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(cgmi); } } else { RedirectToAccessDenied(ModuleName.CONTACTMANAGEMENT, "ModifyContact or ModifyGroup"); } } // Reload unigrid LoadContactGroups(); contactGroups.ReloadData(); pnlUpdate.Update(); selectGroup.Value = null; } }
/// <summary> /// Items changed event handler. /// </summary> protected void UniSelector_OnItemsSelected(object sender, EventArgs e) { if (modifyCombined) { // Get new items from selector string newValues = ValidationHelper.GetString(contactSelector.Value, null); string[] newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { ContactGroupMemberInfo cgmi; int itemId; // Get all selected items foreach (string item in newItems) { // Check if relation already exists itemId = ValidationHelper.GetInteger(item, 0); cgmi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, itemId, ContactGroupMemberTypeEnum.Contact); if (cgmi == null) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(cgi.ContactGroupID, itemId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual); } else if (!cgmi.ContactGroupMemberFromManual) { cgmi.ContactGroupMemberFromManual = true; ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(cgmi); } } gridElem.ReloadData(); pnlUpdate.Update(); contactSelector.Value = null; } } // No permissions else { if (siteID > 0) { CMSPage.RedirectToCMSDeskAccessDenied("CMS.ContactManagement", "ModifyContactGroups"); } else { CMSPage.RedirectToCMSDeskAccessDenied("CMS.ContactManagement", "ModifyGlobalContactGroups"); } } }
/// <summary> /// Attempt to remove user from group event handler. /// </summary> private void cContactGroups_OnRemoveFromGroup(object sender, EventArgs e) { int contactGroupID = ValidationHelper.GetInteger(sender, 0); if (contactGroupID != 0) { ContactGroupInfo removedGroup = ContactGroupInfoProvider.GetContactGroupInfo(contactGroupID); if (UserCanManageGroup(removedGroup) || UserCanManageContact(editedContact)) { // Get the relationship object ContactGroupMemberInfo mi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(contactGroupID, editedContact.ContactID, ContactGroupMemberTypeEnum.Contact); if (mi != null) { ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(mi); } } } }
/// <summary> /// Unigrid button clicked. /// </summary> protected void gridElem_OnAction(string actionName, object actionArgument) { // Perform 'remove' action if (actionName == "remove") { // Delete the object int contactId = ValidationHelper.GetInteger(actionArgument, 0); ContactInfo contact = ContactInfoProvider.GetContactInfo(contactId); if (contact != null) { // User has no permission to modify site contacts if (((contact.ContactSiteID > 0) && !modifySiteContacts) || !ContactGroupHelper.AuthorizedModifyContactGroup(cgi.ContactGroupSiteID, false)) { CMSPage.RedirectToCMSDeskAccessDenied("CMS.ContactManagement", "ModifyContacts"); } // User has no permission to modify global contacts else if ((contact.ContactSiteID == 0) && !modifyGlobalContacts || !ContactGroupHelper.AuthorizedModifyContactGroup(cgi.ContactGroupSiteID, false)) { CMSPage.RedirectToCMSDeskAccessDenied("CMS.ContactManagement", "ModifyGlobalContacts"); } // User has permission else { // Get the relationship object ContactGroupMemberInfo mi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, contactId, ContactGroupMemberTypeEnum.Contact); if (mi != null) { ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(mi); } } } // Check modify permission if ((siteID > 0) && !(CheckPermissions("cms.contactmanagement", "ModifyContactGroups"))) { return; } else if ((siteID == 0) && !(CheckPermissions("cms.contactmanagement", "ModifyGlobalContactGroups"))) { return; } } }
/// <summary> /// Items changed event handler. /// </summary> protected void UniSelector_OnItemsSelected(object sender, EventArgs e) { // Check modify permission if (modifyCombined) { // Get new items from selector string newValues = ValidationHelper.GetString(accountSelector.Value, null); string[] newItems = newValues.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (newItems != null) { int itemID; // Get all selected items foreach (string item in newItems) { // Check if relation already exists itemID = ValidationHelper.GetInteger(item, 0); if (ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, itemID, ContactGroupMemberTypeEnum.Account) == null) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(cgi.ContactGroupID, itemID, ContactGroupMemberTypeEnum.Account, MemberAddedHowEnum.Manual); } } gridElem.ReloadData(); pnlUpdate.Update(); accountSelector.Value = null; } } else { if (siteID > 0) { CMSPage.RedirectToCMSDeskAccessDenied(ModuleEntry.CONTACTMANAGEMENT, "ModifyContactGroups"); } else { CMSPage.RedirectToCMSDeskAccessDenied(ModuleEntry.CONTACTMANAGEMENT, "ModifyGlobalContactGroups"); } } }
/// <summary> /// Unigrid button clicked. /// </summary> protected void gridElem_OnAction(string actionName, object actionArgument) { // Perform 'remove' action if (actionName == "remove") { // Delete the object int accountId = ValidationHelper.GetInteger(actionArgument, 0); AccountInfo account = AccountInfoProvider.GetAccountInfo(accountId); if (account != null) { CheckModifyPermissions(); // Get the relationship object ContactGroupMemberInfo mi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, accountId, ContactGroupMemberTypeEnum.Account); if (mi != null) { ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(mi); } } } }
/// <summary> /// Mass operation button "OK" click. /// </summary> protected void btnOk_Click(object sender, EventArgs e) { // Get where condition depending on mass action selection string where = null; What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0); switch (what) { // All items case What.All: where = SqlHelper.AddWhereCondition(gridElem.WhereCondition, gridElem.WhereClause); break; // Selected items case What.Selected: where = SqlHelper.GetWhereCondition <int>("AccountID", gridElem.SelectedItems, false); break; } Action action = (Action)ValidationHelper.GetInteger(drpAction.SelectedItem.Value, 0); switch (action) { // Action 'Change status' case Action.ChangeStatus: { // Get selected status ID from hidden field int statusId = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If status ID is 0, the status will be removed if (statusId >= 0) { AccountInfoProvider.UpdateAccountStatus(statusId, where); ShowConfirmation(GetString("om.account.massaction.statuschanged")); } } break; // Action 'Add to contact group' case Action.AddToGroup: { // Get contact group ID from hidden field int groupId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0); if (groupId > 0) { IEnumerable <string> accountIds = null; switch (what) { // All items case What.All: // Get selected IDs based on where condition DataSet accounts = AccountInfoProvider.GetAccounts().Where(where).Column("AccountID"); if (!DataHelper.DataSourceIsEmpty(accounts)) { // Get array list with IDs accountIds = DataHelper.GetUniqueValues(accounts.Tables[0], "AccountID", true); } break; // Selected items case What.Selected: // Get selected IDs from UniGrid accountIds = gridElem.SelectedItems; break; } if (accountIds != null) { // Add each selected account to the contact group, skip accounts that are already members of the group foreach (string item in accountIds) { int accountId = ValidationHelper.GetInteger(item, 0); if ((accountId > 0) && (ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(groupId, accountId, ContactGroupMemberTypeEnum.Account) == null)) { ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, accountId, ContactGroupMemberTypeEnum.Account, MemberAddedHowEnum.Account); } } // Get contact group to show result message with its display name ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId); if (group != null) { ShowConfirmation(String.Format(GetString("om.account.massaction.addedtogroup"), ResHelper.LocalizeString(group.ContactGroupDisplayName))); } } } } break; // Merge click case Action.Merge: DataSet selectedAccounts = AccountHelper.GetAccounListInfos(null, where, null, -1, null); if (!DataHelper.DataSourceIsEmpty(selectedAccounts)) { // Get selected account ID from hidden field int accountID = ValidationHelper.GetInteger(hdnIdentifier.Value, -1); // If account ID is 0 then new contact must be created if (accountID == 0) { int siteID; if (filter.DisplaySiteSelector || filter.DisplayGlobalOrSiteSelector) { siteID = filter.SelectedSiteID; } else { siteID = SiteID; } SetDialogParameters(selectedAccounts, AccountHelper.GetNewAccount(AccountHelper.MERGED, siteID)); } // Selected contact to be merged into else if (accountID > 0) { SetDialogParameters(selectedAccounts, AccountInfoProvider.GetAccountInfo(accountID)); } OpenWindow(); } break; default: return; } // Reload UniGrid gridElem.ResetSelection(); gridElem.ReloadData(); pnlUpdate.Update(); }