Ejemplo n.º 1
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 permissions
            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(ResHelper.LocalizeString(cg.ContactGroupDisplayName));
                        chkContactGroups.Items.Add(contactGroup);
                    }
                }
            }
            else
            {
                tabContactGroups.Visible = false;
                tabContactGroups.HeaderText = null;
            }
        }
    }
Ejemplo n.º 2
0
    private void StartNewProcess(What what, string where)
    {
        try
        {
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

            List <string> contactIds = null;

            switch (what)
            {
            case What.All:
                // Get selected IDs based on where condition
                DataSet contacts = ContactGroupMemberInfoProvider.GetRelationships().Where(where).Column("ContactGroupMemberRelatedID");
                if (!DataHelper.DataSourceIsEmpty(contacts))
                {
                    contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactGroupMemberRelatedID", true);
                }
                break;

            case What.Selected:
                contactIds = gridElem.SelectedItems;
                break;
            }

            if (contactIds != null)
            {
                string error = String.Empty;
                using (CMSActionContext context = new CMSActionContext())
                {
                    context.AllowAsyncActions = false;
                    int processId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0);

                    foreach (string contactId in contactIds)
                    {
                        var contact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(contactId, 0));

                        try
                        {
                            manager.StartProcess(contact, processId);
                        }
                        catch (ProcessRecurrenceException ex)
                        {
                            error += "<div>" + ex.Message + "</div>";
                        }
                    }
                }

                if (String.IsNullOrEmpty(error))
                {
                    string confirmation = GetString(what == What.All ? "ma.process.started" : "ma.process.startedselected");
                    ShowConfirmation(confirmation);
                }
                else
                {
                    ShowError(GetString("ma.process.error"), error, null);
                }
            }
        }
        catch (Exception ex)
        {
            LogAndShowError("Automation", "STARTPROCESS", ex);
        }
    }
Ejemplo n.º 3
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;
            }
        }
    }