private void cContactGroups_OnDrawRemoveButton(object sender, CMSModules_ContactManagement_Controls_UI_Contact_ContactGroups.DrawButtonEventArgs e)
 {
     if (sender is CMSGridActionButton)
     {
         // Enable or disable button
         ContactGroupInfo editedGroup = ContactGroupInfoProvider.GetContactGroupInfo((int)e.EditedObject);
         e.ButtonEnabled = UserCanManageGroup(editedGroup) || UserCanManageContact(editedContact);
     }
 }
Пример #2
0
    /// <summary>
    /// OnBeforeSave event handler.
    /// </summary>
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Set site ID only when creating new object
        if ((EditForm.EditedObject != null))
        {
            int groupId = EditForm.EditedObject.Generalized.ObjectID;

            if (groupId == 0)
            {
                if (SiteID > 0)
                {
                    EditForm.Data["ContactGroupSiteID"] = SiteID;
                }
                else
                {
                    EditForm.Data["ContactGroupSiteID"] = null;
                }
            }
            else
            {
                if (!chkDynamic.Checked)
                {
                    // Remove dynamic condition
                    EditForm.Data.SetValue("ContactGroupDynamicCondition", null);

                    // Remove dynamically created members
                    if (ValidationHelper.GetBoolean(hdnConfirmDelete.Value, false))
                    {
                        ContactGroupMemberInfoProvider.DeleteContactGroupMembers("ContactGroupMemberContactGroupID = " + groupId + " AND (ContactGroupMemberFromCondition = 1 AND (ContactGroupMemberFromAccount = 0 OR ContactGroupMemberFromAccount IS NULL) AND (ContactGroupMemberFromManual = 0 OR ContactGroupMemberFromManual IS NULL))", groupId, false, false);
                    }
                }
                else
                {
                    // Get new condition
                    string condition = EditForm.FieldControls["ContactGroupDynamicCondition"].Value.ToString();

                    // Display error if the condition is empty
                    if (string.IsNullOrEmpty(condition))
                    {
                        EditForm.StopProcessing  = true;
                        EditForm.ErrorLabel.Text = GetString("om.contactgroup.nocondition");
                    }
                    else
                    {
                        // Get current object to compare dynamic conditions
                        ContactGroupInfo currentGroup = ContactGroupInfoProvider.GetContactGroupInfo(EditForm.EditedObject.Generalized.ObjectID);
                        if ((currentGroup != null) && (!condition.EqualsCSafe(currentGroup.ContactGroupDynamicCondition, true)))
                        {
                            // Set 'Rebuild required' status
                            EditForm.Data["ContactGroupStatus"] = 2;
                        }
                    }
                }
            }
        }
    }
        private void GenerateEmailCampaignSubscribers()
        {
            var contactGroupInfo = ContactGroupInfoProvider.GetContactGroupInfo(EmailCampaignContactGroup);
            var newsletter       = NewsletterInfoProvider.GetNewsletterInfo(NEWSLETTER_COFFEE_CLUB_MEMBERSHIP, _mSite.SiteID);

            SubscribeContactGroupToIssue(
                IssueInfoProvider.GetIssues().First(issue => issue.IssueNewsletterID == newsletter.NewsletterID),
                contactGroupInfo);
            AddContactsToSubscribedContactGroup(contactGroupInfo);
        }
    /// <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;
        }
    }
Пример #5
0
    /// <summary>
    /// Unigrid button clicked.
    /// </summary>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "delete")
        {
            int groupId          = ValidationHelper.GetInteger(actionArgument, 0);
            ContactGroupInfo cgi = ContactGroupInfoProvider.GetContactGroupInfo(groupId);

            // Check permission
            if ((cgi != null) && ContactGroupHelper.AuthorizedModifyContactGroup(cgi.ContactGroupSiteID, true))
            {
                // Delete contact group
                ContactGroupInfoProvider.DeleteContactGroupInfo(groupId);
            }
        }
    }
Пример #6
0
    /// <summary>
    /// Checkbox chkDynamic event handler.
    /// </summary>
    protected void chkDynamic_CheckedChanged(object sender, EventArgs e)
    {
        plcDynamic.Visible = chkDynamic.Checked;

        // Set confirmation dialog
        if (!chkDynamic.Checked)
        {
            ContactGroupInfo cgi = ContactGroupInfoProvider.GetContactGroupInfo(EditForm.EditedObject.Generalized.ObjectID);
            if ((cgi != null) && (!String.IsNullOrEmpty(cgi.ContactGroupDynamicCondition)))
            {
                InitHeaderActions(true);
                ((CMSPage)Page).CurrentMaster.HeaderActions.ReloadData();
            }
        }
    }
Пример #7
0
        private void CreateContactGroupWithFormConsentAgreementRule()
        {
            if (ContactGroupInfoProvider.GetContactGroupInfo(CONTACT_GROUP_NAME) != null)
            {
                return;
            }

            var contactGroup = new ContactGroupInfo
            {
                ContactGroupDisplayName      = CONTACT_GROUP_DISPLAY_NAME,
                ContactGroupName             = CONTACT_GROUP_NAME,
                ContactGroupDynamicCondition = GetFormConsentMacroRule(),
                ContactGroupEnabled          = true
            };

            ContactGroupInfoProvider.SetContactGroupInfo(contactGroup);
        }
Пример #8
0
        private static void CreateContactGroup(string contactGroupCodeName, string contactGroupName)
        {
            var contactGroup = ContactGroupInfoProvider.GetContactGroupInfo(contactGroupCodeName);

            if (contactGroup != null)
            {
                return;
            }

            contactGroup = new ContactGroupInfo
            {
                ContactGroupDisplayName = contactGroupName,
                ContactGroupName        = contactGroupCodeName,
                ContactGroupEnabled     = true
            };
            ContactGroupInfoProvider.SetContactGroupInfo(contactGroup);
        }
    /// <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);
                }
            }
        }
    }
Пример #10
0
        private ContactGroupInfo CreateContactGroup(
            string contactGroupCodeName,
            string contactGroupName)
        {
            var contactGroupInfo = ContactGroupInfoProvider.GetContactGroupInfo(contactGroupCodeName);

            if (contactGroupInfo != null)
            {
                ContactGroupInfoProvider.DeleteContactGroupInfo(contactGroupInfo);
            }

            var groupObj = new ContactGroupInfo();

            groupObj.ContactGroupDisplayName = contactGroupName;
            groupObj.ContactGroupName        = contactGroupCodeName;
            groupObj.ContactGroupEnabled     = true;
            ContactGroupInfoProvider.SetContactGroupInfo(groupObj);
            return(groupObj);
        }
Пример #11
0
    /// <summary>
    /// Contact group items selected event handler.
    /// </summary>
    protected void CGSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

        // Get new items from selector
        string newValues = ValidationHelper.GetString(contactGroupsSelector.Value, null);

        // Get added items
        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            int contactGroupId = ValidationHelper.GetInteger(item, 0);
            ContactGroupInfo contactGroup = ContactGroupInfoProvider.GetContactGroupInfo(contactGroupId);
            mSubscriptionService.Subscribe(contactGroup, mNewsletter);
        }

        contactGroupsSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
Пример #12
0
        private void AddContactGroupSubscriber(
            string contactGroupName,
            string newsletterName,
            string siteName)
        {
            var contactGroupInfo = ContactGroupInfoProvider.GetContactGroupInfo(contactGroupName);

            if (contactGroupInfo == null)
            {
                return;
            }

            var siteInfo       = SiteInfoProvider.GetSiteInfo(siteName);
            var newsletterInfo = NewsletterInfoProvider.GetNewsletterInfo(newsletterName, siteInfo.SiteID);

            if (newsletterInfo == null ||
                SubscriberInfoProvider.GetSubscriberInfo("om.contactgroup", contactGroupInfo.ContactGroupID,
                                                         siteInfo.SiteID) != null)
            {
                return;
            }

            var subscriber = new SubscriberInfo
            {
                SubscriberType      = "om.contactgroup",
                SubscriberRelatedID = contactGroupInfo.ContactGroupID,
                SubscriberSiteID    = siteInfo.SiteID,
                SubscriberFirstName = contactGroupInfo.ContactGroupDisplayName,
                SubscriberFullName  = string.Format("Contact group '{0}'", contactGroupInfo.ContactGroupDisplayName)
            };

            SubscriberInfoProvider.SetSubscriberInfo(subscriber);
            SubscriberNewsletterInfoProvider.AddSubscriberToNewsletter(subscriber.SubscriberID,
                                                                       newsletterInfo.NewsletterID, DateTime.Now, true);
            SubscriberNewsletterInfoProvider.AddSubscriberToNewsletter(subscriber.SubscriberID,
                                                                       newsletterInfo.NewsletterID, DateTime.Now, true);
        }
Пример #13
0
        private static ContactGroupInfo CreateContactGroup(PersonaInfo persona)
        {
            var contactGroupInfo = ContactGroupInfoProvider.GetContactGroupInfo(CoffeeGeekPersonaContactGroupName);

            if (contactGroupInfo != null)
            {
                ContactGroupInfoProvider.DeleteContactGroupInfo(contactGroupInfo);
            }

            var groupObj = new ContactGroupInfo();

            groupObj.ContactGroupDisplayName = "Is in persona 'Martina, the Coffee Geek'";
            groupObj.ContactGroupName        = CoffeeGeekPersonaContactGroupName;
            groupObj.ContactGroupEnabled     = true;
            var str = MacroSecurityProcessor.AddSecurityParameters(
                string.Format(
                    "{{%Rule(\"(Contact.IsInPersona(\\\"{0}\\\"))\", \"<rules><r pos=\\\"0\\\" par=\\\"\\\" op=\\\"and\\\" n=\\\"ContactIsInPersona\\\" ><p n=\\\"_is\\\"><t>is</t><v></v><r>0</r><d>select operation</d><vt>text</vt><tv>0</tv></p><p n=\\\"personaguid\\\"><t>{1}</t><v>{0}</v><r>1</r><d>select persona</d><vt>text</vt><tv>0</tv></p></r></rules>\") %}}",
                    persona.PersonaGUID, persona.PersonaDisplayName),
                MacroIdentityOption.FromUserInfo(UserInfoProvider.AdministratorUser), null);

            groupObj.ContactGroupDynamicCondition = str;
            ContactGroupInfoProvider.SetContactGroupInfo(groupObj);
            return(groupObj);
        }
Пример #14
0
    /// <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();
    }
Пример #15
0
    /// <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>("ContactID", 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)
            {
                ContactInfoProvider.UpdateContactStatus(statusId, where);
                ShowConfirmation(GetString("om.contact.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)
            {
                var contactGroup = ContactGroupInfoProvider.GetContactGroupInfo(groupId);

                if (contactGroup == null)
                {
                    RedirectToAccessDenied(GetString("general.invalidparameters"));
                    return;
                }

                if (contactGroup.ContactGroupSiteID != CurrentSite.SiteID)
                {
                    RedirectToAccessDenied(GetString("general.invalidparameters"));
                    return;
                }

                List <string> contactIds = null;
                switch (what)
                {
                // All items
                case What.All:
                    // Get selected IDs based on where condition
                    DataSet contacts = ContactInfoProvider.GetContacts().Where(where).Column("ContactID");
                    if (!DataHelper.DataSourceIsEmpty(contacts))
                    {
                        // Get array list with IDs
                        contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true);
                    }
                    break;

                // Selected items
                case What.Selected:
                    // Get selected IDs from unigrid
                    contactIds = gridElem.SelectedItems;
                    break;
                }

                if (contactIds != null)
                {
                    // Add each selected contact to the contact group, skip contacts that are already members of the group
                    foreach (string item in contactIds)
                    {
                        int contactId = item.ToInteger(0);

                        if (contactId > 0)
                        {
                            ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual);
                        }
                    }
                    // Show result message with contact group's display name
                    ShowConfirmation(String.Format(GetString("om.contact.massaction.addedtogroup"), ResHelper.LocalizeString(contactGroup.ContactGroupDisplayName)));
                }
            }
            break;

        // Merge click
        case Action.Merge:
            DataSet selectedContacts = ContactHelper.GetContactListInfos(null, where, null, -1, null);
            if (!DataHelper.DataSourceIsEmpty(selectedContacts))
            {
                // Get selected contact ID from hidden field
                int contactID = ValidationHelper.GetInteger(hdnIdentifier.Value, -1);
                // If contact ID is 0 then new contact must be created
                if (contactID == 0)
                {
                    int siteID;
                    if (filter.DisplaySiteSelector || filter.DisplayGlobalOrSiteSelector)
                    {
                        siteID = filter.SelectedSiteID;
                    }
                    else
                    {
                        siteID = SiteID;
                    }

                    SetDialogParameters(selectedContacts, ContactHelper.GetNewContact(ContactHelper.MERGED, true, siteID));
                }
                // Selected contact to be merged into
                else if (contactID > 0)
                {
                    SetDialogParameters(selectedContacts, ContactInfoProvider.GetContactInfo(contactID));
                }
                OpenWindow();
            }

            break;

        default:
            return;
        }

        // Reload unigrid
        gridElem.ClearSelectedItems();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Пример #16
0
    /// <summary>
    /// Loads contact groups of merged contacts into checkboxlist.
    /// </summary>
    private void LoadContactGroups()
    {
        if (!RequestHelper.IsPostBack())
        {
            StringBuilder idList = new StringBuilder("(");
            foreach (DataRow dr in mergedAccounts.Tables[0].Rows)
            {
                idList.Append(dr["AccountID"] + ",");
            }
            // Remove last comma
            idList.Remove(idList.Length - 1, 1);
            idList.Append(")");

            // Remove site contact groups
            string addWhere = null;
            if (parentAccount.AccountSiteID == 0)
            {
                addWhere = " AND ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL)";
            }

            string where = "ContactGroupMemberType = 1 AND ContactGroupMemberRelatedID IN " + idList.ToString() + " AND ContactGroupMemberContactGroupID NOT IN (SELECT ContactGroupMemberContactGroupID FROM OM_ContactGroupMember WHERE ContactGroupMemberRelatedID = " + parentAccount.AccountID + " AND ContactGroupMemberType = 1)" + addWhere;

            // Limit selection of contact groups according to current user's persmissions
            if (!CMSContext.CurrentUser.UserSiteManagerAdmin)
            {
                bool readModifySite = ContactGroupHelper.AuthorizedReadContactGroup(parentAccount.AccountSiteID, false) && ContactGroupHelper.AuthorizedModifyContactGroup(parentAccount.AccountSiteID, false);
                bool readGlobal     = ContactGroupHelper.AuthorizedReadContactGroup(UniSelector.US_GLOBAL_RECORD, false) && ContactGroupHelper.AuthorizedModifyContactGroup(UniSelector.US_GLOBAL_RECORD, false);
                if (!readModifySite && !readGlobal)
                {
                    tabContactGroups.Visible    = false;
                    tabContactGroups.HeaderText = null;
                }
                else if (readModifySite && !readGlobal)
                {
                    where = SqlHelperClass.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID = " + CMSContext.CurrentSiteID + ")");
                }
                else if (!readModifySite && readGlobal)
                {
                    where = SqlHelperClass.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL)");
                }
                else
                {
                    where = SqlHelperClass.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL OR ContactGroupSiteID = " + CMSContext.CurrentSiteID + ")");
                }
            }

            // Get contact group relations
            DataSet result = ContactGroupMemberInfoProvider.GetRelationships(where, null, -1, "DISTINCT ContactGroupMemberContactGroupID");

            if (!DataHelper.DataSourceIsEmpty(result))
            {
                ListItem         contactGroup;
                ContactGroupInfo cg;
                foreach (DataRow dr in result.Tables[0].Rows)
                {
                    contactGroup          = new ListItem();
                    contactGroup.Value    = ValidationHelper.GetString(dr["ContactGroupMemberContactGroupID"], "0");
                    contactGroup.Selected = true;

                    // Fill in checkbox list
                    cg = ContactGroupInfoProvider.GetContactGroupInfo(ValidationHelper.GetInteger(dr["ContactGroupMemberContactGroupID"], 0));
                    if (cg != null)
                    {
                        contactGroup.Text = HTMLHelper.HTMLEncode(cg.ContactGroupDisplayName);
                        chkContactGroups.Items.Add(contactGroup);
                    }
                }
            }
            else
            {
                tabContactGroups.Visible    = false;
                tabContactGroups.HeaderText = null;
            }
        }
    }
Пример #17
0
    /// <summary>
    /// Mass operation button "OK" click.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        string resultMessage = string.Empty;

        // Get where condition depending on mass action selection
        string where;
        List <string> contactIds = null;

        What what = (What)ValidationHelper.GetInteger(drpWhat.SelectedValue, 0);

        switch (what)
        {
        // All items
        case What.All:
            // Get all contacts with scores based on filter condition
            var contacts = GetContactsWithScore();

            if (!DataHelper.DataSourceIsEmpty(contacts))
            {
                // Get array list with IDs
                contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true);
            }
            break;

        // Selected items
        case What.Selected:
            // Get selected IDs from unigrid
            contactIds = gridElem.SelectedItems;
            break;
        }

        // Prepare where condition
        if ((contactIds != null) && (contactIds.Count > 0))
        {
            where = SqlHelper.GetWhereCondition <int>("ContactID", contactIds, false);
        }
        else
        {
            where = "0=1";
        }

        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)
            {
                ContactInfoProvider.UpdateContactStatus(statusId, where);
                resultMessage = GetString("om.contact.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) && (contactIds != null))
            {
                // Add each selected contact to the contact group, skip contacts that are already members of the group
                foreach (string item in contactIds)
                {
                    int contactId = ValidationHelper.GetInteger(item, 0);
                    if (contactId > 0)
                    {
                        ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual);
                    }
                }
                // Get contact group to show result message with its display name
                ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId);
                if (group != null)
                {
                    resultMessage = String.Format(GetString("om.contact.massaction.addedtogroup"), group.ContactGroupDisplayName);
                }
            }
            break;

        default:
            return;
        }

        if (!string.IsNullOrEmpty(resultMessage))
        {
            lblInfo.Text    = resultMessage;
            lblInfo.Visible = true;
        }

        // Reload unigrid
        gridElem.ClearSelectedItems();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Пример #18
0
    /// <summary>
    /// Mass operation button "OK" click.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        string resultMessage = string.Empty;

        // 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 = gridElem.WhereCondition;
            break;

        // Selected items
        case What.Selected:
            where = SqlHelperClass.GetWhereCondition <int>("ContactID", (string[])gridElem.SelectedItems.ToArray(typeof(string)), 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(hdnIdentificator.Value, -1);
            // If status ID is 0, the status will be removed
            if (statusId >= 0)
            {
                ContactInfoProvider.UpdateContactStatus(statusId, where);
                resultMessage = GetString("om.contact.massaction.statuschanged");
            }
            break;

        // Action 'Add to contact group'
        case Action.AddToGroup:
            // Get contact group ID from hidden field
            int groupId = ValidationHelper.GetInteger(hdnIdentificator.Value, 0);
            if (groupId > 0)
            {
                ArrayList contactIds = null;
                switch (what)
                {
                // All items
                case What.All:
                    // Get selected IDs based on where condition
                    DataSet contacts = ContactInfoProvider.GetContacts(where, null, 0, "ContactID");
                    if (!DataHelper.DataSourceIsEmpty(contacts))
                    {
                        // Get array list with IDs
                        contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true);
                    }
                    break;

                // Selected items
                case What.Selected:
                    // Get selected IDs from unigrid
                    contactIds = gridElem.SelectedItems;
                    break;
                }

                if (contactIds != null)
                {
                    int contactId = 0;
                    // Add each selected contact to the contact group, skip contacts that are already members of the group
                    foreach (string item in contactIds)
                    {
                        contactId = ValidationHelper.GetInteger(item, 0);
                        if (contactId > 0)
                        {
                            ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual);
                        }
                    }
                    // Get contact group to show result message with its display name
                    ContactGroupInfo group = ContactGroupInfoProvider.GetContactGroupInfo(groupId);
                    if (group != null)
                    {
                        resultMessage = String.Format(GetString("om.contact.massaction.addedtogroup"), group.ContactGroupDisplayName);
                    }
                }
            }
            break;

        // Merge click
        case Action.Merge:
            DataSet selectedContacts = ContactHelper.GetContactListInfos(null, where, null, -1, null);
            if (!DataHelper.DataSourceIsEmpty(selectedContacts))
            {
                // Get selected contact ID from hidden field
                int contactID = ValidationHelper.GetInteger(hdnIdentificator.Value, -1);
                // If contact ID is 0 then new contact must be created
                if (contactID == 0)
                {
                    int siteID;
                    if (filter.DisplaySiteSelector || filter.DisplayGlobalOrSiteSelector)
                    {
                        siteID = filter.SelectedSiteID;
                    }
                    else
                    {
                        siteID = SiteID;
                    }

                    SetDialogParameters(selectedContacts, ContactHelper.GetNewContact(ContactHelper.MERGED, true, siteID));
                }
                // Selected contact to be merged into
                else if (contactID > 0)
                {
                    SetDialogParameters(selectedContacts, ContactInfoProvider.GetContactInfo(contactID));
                }
                OpenWindow();
            }

            break;

        default:
            return;
        }

        if (!string.IsNullOrEmpty(resultMessage))
        {
            lblInfo.Text    = resultMessage;
            lblInfo.Visible = true;
        }

        // Reload unigrid
        gridElem.ClearSelectedItems();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Пример #19
0
    /// <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>("ContactID", 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)
            {
                ContactInfoProvider.UpdateContactStatus(statusId, where);
                ShowConfirmation(GetString("om.contact.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)
            {
                var contactGroup = ContactGroupInfoProvider.GetContactGroupInfo(groupId);

                if (contactGroup == null)
                {
                    RedirectToAccessDenied(GetString("general.invalidparameters"));
                    return;
                }

                IEnumerable <string> contactIds = null;

                switch (what)
                {
                // All items
                case What.All:
                    // Get selected IDs based on where condition
                    DataSet contacts = ContactInfoProvider.GetContacts().Where(where).Column("ContactID");
                    if (!DataHelper.DataSourceIsEmpty(contacts))
                    {
                        // Get array list with IDs
                        contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactID", true);
                    }
                    break;

                // Selected items
                case What.Selected:
                    // Get selected IDs from unigrid
                    contactIds = gridElem.SelectedItems;
                    break;
                }

                if (contactIds != null)
                {
                    // Add each selected contact to the contact group, skip contacts that are already members of the group
                    foreach (string item in contactIds)
                    {
                        int contactId = item.ToInteger(0);

                        if (contactId > 0)
                        {
                            ContactGroupMemberInfoProvider.SetContactGroupMemberInfo(groupId, contactId, ContactGroupMemberTypeEnum.Contact, MemberAddedHowEnum.Manual);
                        }
                    }
                    // Show result message with contact group's display name
                    ShowConfirmation(string.Format(GetString("om.contact.massaction.addedtogroup"), HTMLHelper.HTMLEncode(ResHelper.LocalizeString(contactGroup.ContactGroupDisplayName))));
                }
            }
            break;

        default:
            return;
        }

        // Reload unigrid
        gridElem.ResetSelection();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Пример #20
0
    /// <summary>
    /// Loads contact groups of merged contacts into checkboxlist.
    /// </summary>
    private void LoadContactGroups()
    {
        if (!RequestHelper.IsPostBack())
        {
            StringBuilder idList = new StringBuilder("(");
            foreach (DataRow dr in mMergedContacts.Tables[0].Rows)
            {
                idList.Append(dr["ContactID"] + ",");
            }
            // Remove last comma
            idList.Remove(idList.Length - 1, 1);
            idList.Append(")");

            // Remove site contact groups for global contact
            string addWhere = null;
            if (mParentContact.ContactSiteID == 0)
            {
                addWhere = " AND ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL)";
            }

            string where = " ContactGroupMemberType = 0 AND ContactGroupMemberRelatedID IN " + idList + " AND ContactGroupMemberContactGroupID NOT IN (SELECT ContactGroupMemberContactGroupID FROM OM_ContactGroupMember WHERE ContactGroupMemberRelatedID = " + mParentContact.ContactID + " AND ContactGroupMemberType = 0)" + addWhere;

            // Show only manually added contact groups
            where = SqlHelper.AddWhereCondition(where, "ContactGroupMemberFromManual = 1");

            // Limit selection of contact groups according to current user's permissions
            if (!MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
            {
                bool readModifySite   = ContactGroupHelper.AuthorizedReadContactGroup(mParentContact.ContactSiteID, false) && ContactGroupHelper.AuthorizedModifyContactGroup(mParentContact.ContactSiteID, false);
                bool readModifyGlobal = ContactGroupHelper.AuthorizedReadContactGroup(UniSelector.US_GLOBAL_RECORD, false) && ContactGroupHelper.AuthorizedModifyContactGroup(UniSelector.US_GLOBAL_RECORD, false);

                if (!readModifySite && !readModifyGlobal)
                {
                    tabContactGroups.Visible    = false;
                    tabContactGroups.HeaderText = null;
                }
                else if (readModifySite && !readModifyGlobal)
                {
                    where = SqlHelper.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID = " + SiteContext.CurrentSiteID + ")");
                }
                else if (!readModifySite && readModifyGlobal)
                {
                    where = SqlHelper.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL)");
                }
                else
                {
                    where = SqlHelper.AddWhereCondition(where, " ContactGroupMemberContactGroupID IN (SELECT ContactGroupID FROM OM_ContactGroup WHERE ContactGroupSiteID IS NULL OR ContactGroupSiteID = " + SiteContext.CurrentSiteID + ")");
                }
            }

            // Get contact group relations
            DataSet result = ContactGroupMemberInfoProvider.GetRelationships().Where(where).Column("ContactGroupMemberContactGroupID").Distinct();

            if (!DataHelper.DataSourceIsEmpty(result))
            {
                ListItem         contactGroup;
                ContactGroupInfo cg;
                foreach (DataRow dr in result.Tables[0].Rows)
                {
                    contactGroup          = new ListItem();
                    contactGroup.Value    = ValidationHelper.GetString(dr["ContactGroupMemberContactGroupID"], "0");
                    contactGroup.Selected = true;
                    cg = ContactGroupInfoProvider.GetContactGroupInfo(ValidationHelper.GetInteger(dr["ContactGroupMemberContactGroupID"], 0));
                    if (cg != null)
                    {
                        contactGroup.Text = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(cg.ContactGroupDisplayName));
                        chkContactGroups.Items.Add(contactGroup);
                    }
                }
            }
            else
            {
                tabContactGroups.Visible    = false;
                tabContactGroups.HeaderText = null;
            }
        }
    }