private void btnSave_Click(object sender, EventArgs e)
    {
        if (userIsAuthorized && (activityId > 0))
        {
            ActivityInfo ai = ActivityInfoProvider.GetActivityInfo(activityId);
            EditedObject = ai;
            ai.ActivityComment = txtComment.Value;
            ai.ActivityTitle = TextHelper.LimitLength(txtTitle.Text, 250, String.Empty);
            ai.ActivityURLReferrer = txtURLRef.Text;
            ai.ActivityURL = txtURL.Text;

            // Get changed columns
            List<string> changes = ai.ChangedColumns();

            // Save activity info
            ActivityInfoProvider.SetActivityInfo(ai);
            
            if ((changes != null) && (changes.Count > 0))
            {
                // Get IDs of scores where activity's contact exceeded score limit
                DataSet limitScores = ScoreInfoProvider.GetScoresWhereContactExceededLimit(ai.ActivityActiveContactID);

                // Recalculate scoring groups
                ScoreInfoProvider.RecalculateScores(ai.ActivityType, RuleTypeEnum.Activity, ai.ActivityActiveContactID, ai.ActivitySiteID);

                // Check if contact gained enough points and alternatively send notification e-mail
                ScoreInfoProvider.CheckScoringLimits(ContactInfoProvider.GetContactInfo(ai.ActivityActiveContactID), limitScores);
            }


            // Reload form (due to "view URL" button)
            LoadData();
        }
    }
Exemple #2
0
    /// <summary>
    /// Contact items selected event handler.
    /// </summary>
    protected void ContactSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        CheckAuthorization();

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

        // Get added items
        string[] newItems = newValues.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (string item in newItems)
        {
            int contactID = ValidationHelper.GetInteger(item, 0);
            ContactInfo contact = ContactInfoProvider.GetContactInfo(contactID);
            mSubscriptionService.Subscribe(contact, mNewsletter, new SubscribeSettings
            {
                AllowOptIn = false,
                SendConfirmationEmail = false,
                RemoveAlsoUnsubscriptionFromAllNewsletters = false,
            });
        }

        contactsSelector.Value = null;
        UniGridSubscribers.ReloadData();
        pnlUpdate.Update();
    }
Exemple #3
0
    void UniSelector_OnItemsSelected(object sender, EventArgs e)
    {
        try
        {
            int contactId             = ValidationHelper.GetInteger(ucSelector.Value, 0);
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);
            var infoObj = ContactInfoProvider.GetContactInfo(contactId);
            if (WorkflowStepInfoProvider.CanUserStartAutomationProcess(CurrentUser, SiteInfoProvider.GetSiteName(infoObj.ContactSiteID)))
            {
                using (CMSActionContext context = new CMSActionContext())
                {
                    context.AllowAsyncActions = false;

                    manager.StartProcess(infoObj, ProcessID);
                }
            }
        }
        catch (ProcessRecurrenceException ex)
        {
            ShowError(ex.Message);
        }
        catch (Exception ex)
        {
            LogAndShowError("Automation", "STARTPROCESS", ex);
        }

        listContacts.ReloadData();
        pnlUpdate.Update();
    }
    protected void EditForm_OnAfterValidate(object sender, EventArgs e)
    {
        // Test if selected date is not empty
        if (ValidationHelper.GetString(EditForm.GetFieldValue("ActivityCreated"), String.Empty) == String.Empty)
        {
            ShowError(GetString("om.sctivity.selectdatetime"));
            StopProcessing = true;
        }

        // Ignore contact selector value when there is contactId in query string (contact selector should be hidden in this case due to its visibility condition)
        int queryContactID = QueryHelper.GetInteger("ContactID", 0);

        if (queryContactID > 0)
        {
            mContact = ContactInfoProvider.GetContactInfo(queryContactID);
        }
        else
        {
            int contactID = ValidationHelper.GetInteger(EditForm.GetFieldValue("ActivityContactID"), 0);
            mContact = ContactInfoProvider.GetContactInfo(contactID);
        }

        // Test if selected contact exists
        if (mContact == null)
        {
            ShowError(GetString("om.activity.contactdoesnotexist"));
            StopProcessing = true;
        }
    }
Exemple #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get contact ID
        contactId = QueryHelper.GetInteger("contactId", 0);
        if (contactId == 0)
        {
            RequestHelper.EndResponse();
        }

        // Check contact's existence
        ContactInfo contact = ContactInfoProvider.GetContactInfo(contactId);

        EditedObject = contact;

        // Initialize unigrid
        var dateTimeService = Service <IDateTimeNowService> .Entry();

        var whereCondition = new WhereCondition().WhereEquals("ContactID", contactId)
                             .WhereEquals("ScoreID", QueryHelper.GetInteger("scoreid", 0))
                             .WhereNotExpired(dateTimeService.GetDateTimeNow());

        gridElem.WhereCondition        = whereCondition.ToString(true);
        gridElem.Pager.DefaultPageSize = PAGESIZE;
        gridElem.Pager.ShowPageSize    = false;
        gridElem.FilterLimit           = PAGESIZE;
        gridElem.OnExternalDataBound  += UniGrid_OnExternalDataBound;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get contact ID
        contactId = QueryHelper.GetInteger("contactId", 0);
        if (contactId == 0)
        {
            RequestHelper.EndResponse();
        }

        // Check contact's existence
        ContactInfo contact = ContactInfoProvider.GetContactInfo(contactId);

        EditedObject = contact;

        // Prevent accessing issues from sites other than current site
        if (contact.ContactSiteID != SiteContext.CurrentSiteID)
        {
            RedirectToResourceNotAvailableOnSite("Contact with ID " + contactId);
        }

        // Initialize unigrid
        gridElem.WhereCondition        = string.Format("ContactID={0} AND ScoreID={1} AND (Expiration IS NULL OR (DATEDIFF(d, getdate(), Expiration) >= 0))", contactId, QueryHelper.GetInteger("scoreid", 0));
        gridElem.Pager.DefaultPageSize = PAGESIZE;
        gridElem.Pager.ShowPageSize    = false;
        gridElem.FilterLimit           = PAGESIZE;
        gridElem.OnExternalDataBound  += UniGrid_OnExternalDataBound;
    }
Exemple #7
0
    protected void EditForm_OnBeforeValidate(object sender, EventArgs e)
    {
        // Check emptyness
        if (String.IsNullOrEmpty(ValidationHelper.GetString(ucContact.Value, null)))
        {
            ShowErrorMessage("om.activity.contactmissing", true);
            return;
        }

        // Check if selected contact exists
        EditForm.ParentObject = ContactInfoProvider.GetContactInfo(ucContact.ContactID);
        if (EditForm.ParentObject == null)
        {
            ShowErrorMessage("om.activity.contactdoesnotexist", true);
            return;
        }

        // Check selected date
        if (dtCreated.SelectedDateTime == DateTimeHelper.ZERO_TIME)
        {
            ShowErrorMessage("om.sctivity.selectdatetime", true);
            return;
        }

        // Check if manual creation of activity of this type is allowed
        string activityType = tsType.SelectedValue;

        if (String.IsNullOrEmpty(activityType) || !ActivityTypeInfoProvider.GetActivityTypeEnabled(activityType))
        {
            ShowErrorMessage("om.activity.manualcreationisnotallowed", true);
            return;
        }
    }
Exemple #8
0
    /// <summary>
    /// Sets visibility of buttons that are connected to merged contact - split button and link to his parent.
    /// </summary>
    private void SetButtonsVisibility()
    {
        // Find out if current contact is merged into another site or global contact
        bool mergedIntoSite   = ValidationHelper.GetInteger(EditForm.Data["ContactMergedWithContactID"], 0) != 0;
        bool mergedIntoGlobal = ValidationHelper.GetInteger(EditForm.Data["ContactGlobalContactID"], 0) != 0 &&
                                ContactHelper.AuthorizedReadContact(UniSelector.US_GLOBAL_RECORD, false);
        bool globalContactsVisible = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSCMGlobalContacts") || CurrentUser.IsGlobalAdministrator;

        if (mergedIntoSite || (mergedIntoGlobal && globalContactsVisible))
        {
            if (mergedIntoSite)
            {
                parentContact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(EditForm.Data["ContactMergedWithContactID"], 0));
                headingMergedInto.ResourceString = "om.contact.mergedintosite";
            }
            else
            {
                parentContact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(EditForm.Data["ContactGlobalContactID"], 0));
                headingMergedInto.ResourceString = "om.contact.mergedintoglobal";
            }

            lblMergedIntoContactName.Text = HTMLHelper.HTMLEncode(ContactInfoProvider.GetContactFullName(parentContact));

            string contactDetailDialogURL = UIContextHelper.GetElementDialogUrl(ModuleName.ONLINEMARKETING, "EditContact", parentContact.ContactID);
            string openDialogScript       = ScriptHelper.GetModalDialogScript(contactDetailDialogURL, "ContactDetail");

            btnMergedContact.IconCssClass  = "icon-edit";
            btnMergedContact.OnClientClick = openDialogScript;
            btnMergedContact.ToolTip       = GetString("om.contact.viewdetail");
        }
        else
        {
            panelMergedContactDetails.Visible = btnSplit.Visible = false;
        }
    }
Exemple #9
0
    /// <summary>
    /// Sets primary and secondary contacts.
    /// </summary>
    private bool AssignContacts()
    {
        ContactInfo        contact        = null;
        AccountContactInfo accountContact = null;

        // Assign primary contact to account and/or assign role
        if (primaryContact.ContactID > 0)
        {
            contact = ContactInfoProvider.GetContactInfo(primaryContact.ContactID);
            if (contact != null)
            {
                // Check if contact <-> account relation is already created
                accountContact = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, primaryContact.ContactID);

                // Update relation
                if (accountContact != null)
                {
                    accountContact.ContactRoleID = contactRolePrimary.ContactRoleID;
                }
                AccountContactInfoProvider.SetAccountContactInfo(accountContact);
            }
            // Selected contact doesn't exist
            else
            {
                ShowError(GetString("om.contact.primarynotexists"));
                return(false);
            }
        }

        // Assign secondary contact to account and/or assign role
        if (secondaryContact.ContactID > 0)
        {
            contact = ContactInfoProvider.GetContactInfo(secondaryContact.ContactID);
            if (contact != null)
            {
                // Check if contact <-> account relation is already created
                accountContact = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, secondaryContact.ContactID);

                // Update relation
                if (accountContact != null)
                {
                    accountContact.ContactRoleID = contactRoleSecondary.ContactRoleID;
                }
                AccountContactInfoProvider.SetAccountContactInfo(accountContact);
            }
            else
            {
                ShowError(GetString("om.contact.secondarynotexists"));
                return(false);
            }
        }

        return(true);
    }
Exemple #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Show/hide campaign selector
        fCampaignSelection.Visible = CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.WebAnalytics", "read");

        // Get parent contact
        if (mergedIntoSite)
        {
            parentContact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(this.EditForm.Data["ContactMergedWithContactID"], 0));
            lblMergedInto.ResourceString = "om.contact.mergedintosite";
        }
        else if (mergedIntoGlobal)
        {
            parentContact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(this.EditForm.Data["ContactGlobalContactID"], 0));
            lblMergedInto.ResourceString = "om.contact.mergedintoglobal";
        }
        else
        {
            lblMergedInto.Visible = false;
        }

        // Register scripts
        RegisterScripts();

        // Initialize properties
        pnlGeneral.GroupingText  = GetString("general.general");
        pnlPersonal.GroupingText = GetString("om.contact.personal");
        pnlSettings.GroupingText = GetString("om.contact.settings");
        pnlAddress.GroupingText  = GetString("general.address");
        pnlNotes.GroupingText    = GetString("om.contact.notes");
        btnStamp.OnClientClick   = "AddStamp('" + htmlNotes.CurrentEditor.ClientID + "'); return false;";

        // Initialize redirection URL
        string url = "Frameset.aspx?contactid={%EditedObject.ID%}&saved=1";

        url = URLHelper.AddParameterToUrl(url, "siteid", this.SiteID.ToString());
        if (ContactHelper.IsSiteManager)
        {
            url = URLHelper.AddParameterToUrl(url, "issitemanager", "1");
        }
        EditForm.RedirectUrlAfterCreate = url;

        if (!RequestHelper.IsPostBack() && QueryHelper.GetBoolean("split", false))
        {
            DisplayInfo(GetString("om.contact.splitted"));
        }

        if (userSelector.SiteID <= 0)
        {
            userSelector.WhereCondition = "UserName NOT LIKE N'public'";
            userSelector.ShowSiteFilter = true;
        }
        userSelector.ReloadData();
    }
    private void ucSelectCustomer_Changed(object sender, EventArgs e)
    {
        // Check permissions
        if (ContactHelper.AuthorizedModifyContact(ci.ContactSiteID, true))
        {
            // Load value form dynamic control
            string values = null;
            if (ucSelectCustomer != null)
            {
                values = ValidationHelper.GetString(ucSelectCustomer.GetValue("OnlineMarketingValue"), null);
            }

            if (!String.IsNullOrEmpty(values))
            {
                // Store users one by one
                string[] customerIds   = values.Split(';');
                int      currentSiteID = SiteContext.CurrentSiteID;
                foreach (string customerId in customerIds)
                {
                    // Check if user ID is valid
                    int customerIdInt = ValidationHelper.GetInteger(customerId, 0);
                    if (customerIdInt <= 0)
                    {
                        continue;
                    }

                    // Only allow adding customers on the same site as contact or registered customers
                    var customer = BaseAbstractInfoProvider.GetInfoById(PredefinedObjectType.CUSTOMER, customerIdInt);
                    if ((customer == null) || ((customer.Generalized.ObjectSiteID != currentSiteID) && !customer.IsGlobal))
                    {
                        continue;
                    }

                    // Add new relation
                    int parentId = (ci.ContactMergedWithContactID == 0)
                   ? ci.ContactID
                   : ci.ContactMergedWithContactID;

                    ContactMembershipInfoProvider.SetRelationship(customerIdInt, MemberTypeEnum.EcommerceCustomer, ci.ContactID, parentId, true);
                    ci = ContactInfoProvider.GetContactInfo(contactId);
                }

                // When contact was merged then refresh complete page
                if ((ci != null) && (ci.ContactMergedWithContactID > 0))
                {
                    Page.Response.Redirect(RequestContext.URL.ToString(), true);
                }
                else
                {
                    gridElem.ReloadData();
                }
            }
        }
    }
Exemple #12
0
        private void SubscribeContactWithEmailToNewsletter(string contactEmail, string newsletterCodeName)
        {
            var contact    = ContactInfoProvider.GetContactInfo(contactEmail);
            var newsletter = NewsletterInfo.Provider.Get(newsletterCodeName, site.SiteID);
            var fullName   = string.Format("{0} {1}", contact.ContactFirstName, contact.ContactLastName);

            var subscriber = CreateSubscriber(contact.ContactEmail, contact.ContactFirstName, contact.ContactLastName, fullName, contact);

            AssignSubscriberToNewsletter(newsletter.NewsletterID, subscriber);
            mNewsletterActivityGenerator.GenerateNewsletterSubscribeActivity(newsletter, subscriber.SubscriberID, contact.ContactID, site.SiteID);
        }
Exemple #13
0
    void Process_OnItemsSelected(object sender, EventArgs e)
    {
        try
        {
            int processId             = ValidationHelper.GetInteger(processSelector.Value, 0);
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

            ContactGroupContactListInfo listInfo = new ContactGroupContactListInfo();
            var contacts = listInfo.Generalized.GetData(null, GetWhereCondition(), null, 0, "ContactID", false);
            if (!DataHelper.DataSourceIsEmpty(contacts))
            {
                string error = null;
                using (CMSActionContext context = new CMSActionContext())
                {
                    context.AllowAsyncActions = false;
                    foreach (DataRow row in contacts.Tables[0].Rows)
                    {
                        // Get contact
                        int contactId = ValidationHelper.GetInteger(row[0], 0);
                        var contact   = ContactInfoProvider.GetContactInfo(contactId);

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

                if (string.IsNullOrEmpty(error))
                {
                    ShowConfirmation(GetString("ma.process.started"));
                }
                else
                {
                    ShowError(GetString("ma.process.error"), error, null);
                }
            }
        }
        catch (Exception ex)
        {
            LogAndShowError("Automation", "STARTPROCESS", ex);
        }

        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Exemple #14
0
    /// <summary>
    /// UniGrid action handler.
    /// </summary>
    private void gridElem_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "delete")
        {
            ContactInfo contact = ContactInfoProvider.GetContactInfo(ContactID);

            // Check permission
            if ((contact != null) && ContactHelper.AuthorizedModifyContact(contact.ContactSiteID, true))
            {
                int ipId = ValidationHelper.GetInteger(actionArgument, 0);
                IPInfoProvider.DeleteIPInfo(ipId);
            }
        }
    }
        private void SubscribeContactWithEmailToNewsletter(
            string contactEmail,
            string newsletterCodeName)
        {
            var contactInfo    = ContactInfoProvider.GetContactInfo(contactEmail);
            var newsletterInfo =
                NewsletterInfoProvider.GetNewsletterInfo(newsletterCodeName, SiteContext.CurrentSiteID);
            var fullName   = $"{contactInfo.ContactFirstName} {contactInfo.ContactLastName}";
            var subscriber = CreateSubscriber(contactInfo.ContactEmail, contactInfo.ContactFirstName,
                                              contactInfo.ContactLastName, fullName, contactInfo);

            AssignSubscriberToNewsletter(newsletterInfo.NewsletterID, subscriber);
            _mNewsletterActivityGenerator.GenerateNewsletterSubscribeActivity(newsletterInfo, subscriber.SubscriberID,
                                                                              contactInfo.ContactID, _mSite.SiteID);
        }
 private void AddContactsToSubscribedContactGroup(ContactGroupInfo contactGroup)
 {
     for (var index = 0; index < _mSubscriberNames.Length; ++index)
     {
         if (index % 2 == 0)
         {
             var fromFullName = SubscriberData.CreateFromFullName(_mSubscriberNames[index]);
             AddContactToContactGroup(ContactInfoProvider.GetContactInfo(fromFullName.Email), contactGroup);
             if (index % 10 == 0)
             {
                 CreateGlobalUnsubscription(fromFullName.Email);
             }
         }
     }
 }
    private WhereCondition GetContactWhereCondition()
    {
        var         contactWhere = new WhereCondition();
        ContactInfo contact;

        // Get primary contact WHERE condition
        if (CurrentAccount.AccountPrimaryContactID != 0)
        {
            contact = ContactInfoProvider.GetContactInfo(CurrentAccount.AccountPrimaryContactID);
            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.ContactFirstName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactFirstName", contact.ContactFirstName);
                }
                if (!String.IsNullOrEmpty(contact.ContactMiddleName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactMiddleName", contact.ContactMiddleName);
                }
                if (!String.IsNullOrEmpty(contact.ContactLastName))
                {
                    contactWhere.Or().WhereContains("PrimaryContactLastName", contact.ContactLastName);
                }
            }
        }

        // Get secondary contact WHERE condition
        if (CurrentAccount.AccountSecondaryContactID != 0)
        {
            contact = ContactInfoProvider.GetContactInfo(CurrentAccount.AccountSecondaryContactID);
            if (contact != null)
            {
                if (!String.IsNullOrEmpty(contact.ContactFirstName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactFirstName", contact.ContactFirstName);
                }
                if (!String.IsNullOrEmpty(contact.ContactMiddleName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactMiddleName", contact.ContactMiddleName);
                }
                if (!String.IsNullOrEmpty(contact.ContactLastName))
                {
                    contactWhere.Or().WhereContains("SecondaryContactLastName", contact.ContactLastName);
                }
            }
        }
        return(contactWhere);
    }
    /// <summary>
    /// Sets visibility of buttons that are connected to merged contact - split button and link to his parent.
    /// </summary>
    private void SetButtonsVisibility()
    {
        // Find out if current contact is merged into another site or global contact
        mergedIntoSite    = ValidationHelper.GetInteger(EditForm.Data["ContactMergedWithContactID"], 0) != 0;
        mergedIntoGlobal  = ValidationHelper.GetInteger(EditForm.Data["ContactGlobalContactID"], 0) != 0;
        mergedIntoGlobal &= ContactHelper.AuthorizedModifyContact(UniSelector.US_GLOBAL_RECORD, false);

        if (!ContactHelper.IsSiteManager)
        {
            mergedIntoGlobal &= SettingsKeyProvider.GetBoolValue(CMSContext.CurrentSiteName + ".CMSCMGlobalContacts");
        }

        btnSplit.Visible = mergedIntoGlobal || mergedIntoSite;

        // Get parent contact
        if (mergedIntoSite)
        {
            parentContact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(EditForm.Data["ContactMergedWithContactID"], 0));
            lblMergedInto.ResourceString = "om.contact.mergedintosite";
            lblMergedInto.Visible        = true;
        }
        else if (mergedIntoGlobal)
        {
            parentContact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(EditForm.Data["ContactGlobalContactID"], 0));
            lblMergedInto.ResourceString = "om.contact.mergedintoglobal";
            lblMergedInto.Visible        = true;
        }
        else
        {
            lblMergedInto.Visible = false;
        }

        if (mergedIntoSite || mergedIntoGlobal)
        {
            string contactFullName = parentContact.ContactFirstName + " " + parentContact.ContactMiddleName;
            contactFullName = contactFullName.Trim() + " " + parentContact.ContactLastName;
            ltlButton.Text  = string.Format(@" {0} <img class='UnigridActionButton' style='cursor:pointer;' onclick='EditContact({1});return false;' src='{2}' title='{3}'>",
                                            HTMLHelper.HTMLEncode(contactFullName.Trim()),
                                            parentContact.ContactID,
                                            GetImageUrl("Design/Controls/UniGrid/Actions/contactdetail.png"),
                                            GetString("om.contact.viewdetail"));
            ltlButton.Visible = true;
        }
        else
        {
            ltlButton.Visible = false;
        }
    }
    /// <summary>
    /// On external databound.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        CMSGridActionButton btn;
        ContactInfo         ci;

        switch (sourceName.ToLowerCSafe())
        {
        case "edit":
            btn = (CMSGridActionButton)sender;
            // Ensure accountID parameter value;
            var objectID = ValidationHelper.GetInteger(btn.CommandArgument, 0);
            // Contact detail URL
            string contactURL = UIContextHelper.GetElementDialogUrl(ModuleName.ONLINEMARKETING, "EditContact", objectID);
            // Add modal dialog script to onClick action
            btn.OnClientClick = ScriptHelper.GetModalDialogScript(contactURL, "ContactDetail");
            break;

        case "view":
            btn = (CMSGridActionButton)sender;
            btn.OnClientClick = "ViewScoreDetail(" + btn.CommandArgument + "); return false;";
            break;

        case "#contactfullname":
            ci = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(parameter, 0));
            if (ci != null)
            {
                string fullName = TextHelper.MergeIfNotEmpty(" ", ci.ContactFirstName, ci.ContactMiddleName, ci.ContactLastName);
                return(HTMLHelper.HTMLEncode(fullName));
            }
            return(String.Empty);

        case "#statusdisplayname":
            ci = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(parameter, 0));
            if (ci != null)
            {
                ContactStatusInfo statusInfo = ContactStatusInfoProvider.GetContactStatusInfo(ci.ContactStatusID);
                if (statusInfo != null)
                {
                    return(HTMLHelper.HTMLEncode(statusInfo.ContactStatusDisplayName));
                }
            }
            return(String.Empty);
        }

        return(null);
    }
Exemple #20
0
    private void ucSelectCustomer_Changed(object sender, EventArgs e)
    {
        // Check permissions
        if (ContactHelper.AuthorizedModifyContact(ci.ContactSiteID, true))
        {
            // Load value form dynamic control
            string values = null;
            if (ucSelectCustomer != null)
            {
                values = ValidationHelper.GetString(ucSelectCustomer.GetValue("OnlineMarketingValue"), null);
            }

            if (!String.IsNullOrEmpty(values))
            {
                // Store users one by one
                string[] customerIds = values.Split(';');
                foreach (string customerId in customerIds)
                {
                    // Check if user ID is valid
                    int customerIdInt = ValidationHelper.GetInteger(customerId, 0);
                    if (customerIdInt <= 0)
                    {
                        continue;
                    }
                    // Add new relation
                    int parentId = (ci.ContactMergedWithContactID == 0)
                   ? ci.ContactID
                   : ci.ContactMergedWithContactID;

                    MembershipInfoProvider.SetRelationship(customerIdInt, MemberTypeEnum.EcommerceCustomer, ci.ContactID, parentId, true);
                    ci = ContactInfoProvider.GetContactInfo(contactId);
                }

                // When contact was merged then refresh complete page
                if ((ci != null) && (ci.ContactMergedWithContactID > 0))
                {
                    Page.Response.Redirect(URLHelper.Url.ToString(), true);
                }
                else
                {
                    gridElem.ReloadData();
                }
            }
        }
    }
    /// <summary>
    /// Gets instance of <see cref="SubscriberInfo"/> according to the <see cref="NewsletterInfo.NewsletterType"/> of given <paramref name="newsletter"/>.
    /// If <paramref name="newsletter"/> has type <see cref="EmailCommunicationTypeEnum.Newsletter"/>, only returns existing <see cref="SubscriberInfo"/> identified by Guid passed as query parameter.
    /// Otherwise, returns new dummy <see cref="SubscriberInfo"/> filled with the values obtained from the <see cref="ContactInfo"/> identified by Guid passed as query paremeter.
    /// </summary>
    private static SubscriberInfo GetSubscriber(NewsletterInfo newsletter)
    {
        Guid recipientGuid = QueryHelper.GetGuid("recipientguid", Guid.Empty);

        if (newsletter.NewsletterType == EmailCommunicationTypeEnum.Newsletter)
        {
            return(SubscriberInfoProvider.GetSubscriberInfo(recipientGuid, SiteContext.CurrentSiteID));
        }

        var recipient = ContactInfoProvider.GetContactInfo(recipientGuid);

        return(recipient == null ? null : new SubscriberInfo
        {
            SubscriberFirstName = recipient.ContactFirstName,
            SubscriberLastName = recipient.ContactLastName,
            SubscriberEmail = recipient.ContactEmail
        });
    }
Exemple #22
0
    /// <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;
            }
        }
    }
    protected void EditForm_OnAfterValidate(object sender, EventArgs e)
    {
        // Test if selected date is not empty
        if (ValidationHelper.GetString(EditForm.GetFieldValue("ActivityCreated"), String.Empty) == String.Empty)
        {
            ShowError(GetString("om.sctivity.selectdatetime"));
            StopProcessing = true;
        }

        // Test if selected contact exists
        int contactID = ValidationHelper.GetInteger(EditForm.GetFieldValue("ActivityActiveContactID"), 0);

        mContact = ContactInfoProvider.GetContactInfo(contactID);
        if (mContact == null)
        {
            ShowError(GetString("om.activity.contactdoesnotexist"));
            StopProcessing = true;
        }
    }
    /// <summary>
    /// On external databound.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Source name</param>
    /// <param name="parameter">Parameter</param>
    private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        ImageButton btn = null;
        ContactInfo ci;

        switch (sourceName.ToLowerCSafe())
        {
        case "edit":
            btn = ((ImageButton)sender);
            // Add ability to open contact details
            btn.Attributes.Add("onClick", "EditContact(" + btn.CommandArgument + "); return false;");
            break;

        case "view":
            btn = (ImageButton)sender;
            btn.Attributes.Add("onClick", "ViewScoreDetail(" + btn.CommandArgument + "); return false;");
            break;

        case "#contactfullname":
            ci = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(parameter, 0));
            if (ci != null)
            {
                return(TextHelper.MergeIfNotEmpty(" ", ci.ContactFirstName, ci.ContactMiddleName, ci.ContactLastName));
            }
            return(String.Empty);

        case "#statusdisplayname":
            ci = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(parameter, 0));
            if (ci != null)
            {
                ContactStatusInfo statusInfo = ContactStatusInfoProvider.GetContactStatusInfo(ci.ContactStatusID);
                if (statusInfo != null)
                {
                    return(HTMLHelper.HTMLEncode(statusInfo.ContactStatusDisplayName));
                }
            }
            return(String.Empty);
        }

        return(null);
    }
    /// <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)
            {
                CheckModifyPermissions();

                // Get the relationship object
                ContactGroupMemberInfo mi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, contactId, ContactGroupMemberTypeEnum.Contact);
                if (mi != null)
                {
                    ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(mi);
                }
            }
        }
    }
    private void UniSelector_OnItemsSelected(object sender, EventArgs e)
    {
        // Check permissions
        if (ContactHelper.AuthorizedModifyContact(ci.ContactSiteID, true))
        {
            string values = ValidationHelper.GetString(selectUser.UniSelector.Value, null);
            if (!String.IsNullOrEmpty(values))
            {
                // Store users one by one
                string[] userIds = values.Split(';');
                foreach (string userId in userIds)
                {
                    // Check if user ID is valid
                    int userIdInt = ValidationHelper.GetInteger(userId, 0);
                    if (userIdInt <= 0)
                    {
                        continue;
                    }
                    // Add new relation
                    int parentId = (ci.ContactMergedWithContactID == 0)
                                       ? ci.ContactID
                                       : ci.ContactMergedWithContactID;
                    MembershipInfoProvider.SetRelationship(userIdInt, MemberTypeEnum.CmsUser, ci.ContactID, parentId, true);

                    // When contact was merged update contact info
                    ci = ContactInfoProvider.GetContactInfo(contactId);
                }

                // When contact was merged then refresh complete page
                if ((ci != null) && (ci.ContactMergedWithContactID > 0))
                {
                    Page.Response.Redirect(URLHelper.Url.ToString(), true);
                }
                else
                {
                    gridElem.ReloadData();
                }
            }
        }
    }
Exemple #27
0
        public void Evaluate_NoContactGroupSelected_ReturnsCorrectResult(int contactId, Constraint result)
        {
            var currentContact = ContactInfoProvider.GetContactInfo(contactId);

            currentContactProvider.GetCurrentContact(Arg.Any <IUserInfo>(), Arg.Any <bool>())
            .Returns(currentContact);

            var evaluatorEmpty = new IsInContactGroupConditionType
            {
                SelectedContactGroups = new List <string>()
            };

            var evaluatorNull = new IsInContactGroupConditionType
            {
                SelectedContactGroups = null
            };

            Assert.Multiple(() =>
            {
                Assert.That(() => evaluatorEmpty.Evaluate(), result);
                Assert.That(() => evaluatorNull.Evaluate(), result);
            });
        }
Exemple #28
0
    /// <summary>
    /// Sets primary and secondary contacts.
    /// </summary>
    private void AssignContacts()
    {
        ContactInfo        contact;
        AccountContactInfo accountContact;

        // Assign primary contact to account and/or assign role
        int contactID     = ValidationHelper.GetInteger(EditForm.EditedObject.GetValue("accountprimarycontactid"), -1);
        int contactRoleID = ValidationHelper.GetInteger(EditForm.FieldControls["accountprimarycontactroleid"].Value, -1);

        if (contactID > 0)
        {
            contact = ContactInfoProvider.GetContactInfo(contactID);
            if (contact != null)
            {
                accountContact = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, contactID);

                // Update relation
                if (accountContact != null)
                {
                    accountContact.ContactRoleID = contactRoleID;
                    AccountContactInfoProvider.SetAccountContactInfo(accountContact);
                }
                else
                {
                    EditForm.EditedObject.SetValue("accountprimarycontactid", null);
                    ((UniSelector)EditForm.FieldControls["accountprimarycontactid"]).Reload(true);
                }
            }
            // Selected contact doesn't exist
            else
            {
                ShowError(GetString("om.contact.primarynotexists"));
                return;
            }
        }

        // Assign secondary contact to account and/or assign role
        contactID     = ValidationHelper.GetInteger(EditForm.EditedObject.GetValue("accountsecondarycontactid"), -1);
        contactRoleID = ValidationHelper.GetInteger(EditForm.FieldControls["accountsecondarycontactroleid"].Value, -1);

        // Assign secondary contact to account and/or assign role
        if (contactID > 0)
        {
            contact = ContactInfoProvider.GetContactInfo(contactID);
            if (contact != null)
            {
                accountContact = AccountContactInfoProvider.GetAccountContactInfo(ai.AccountID, contactID);

                // Update relation
                if (accountContact != null)
                {
                    accountContact.ContactRoleID = contactRoleID;
                    AccountContactInfoProvider.SetAccountContactInfo(accountContact);
                }
                else
                {
                    EditForm.EditedObject.SetValue("accountsecondarycontactid", null);
                    ((UniSelector)EditForm.FieldControls["accountsecondarycontactid"]).Reload(true);
                }
            }
            else
            {
                ShowError(GetString("om.contact.secondarynotexists"));
            }
        }
    }
Exemple #29
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;
                }

                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"), 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.ResetSelection();
        gridElem.ReloadData();
        pnlUpdate.Update();
    }
    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);
        }
    }