Example #1
0
    /// <summary>
    /// OnBeforeSave event handler.
    /// </summary>
    private void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Set site ID
        if (SiteID > 0)
        {
            EditForm.Data["AccountSiteID"] = SiteID;
        }
        else
        {
            EditForm.Data["AccountSiteID"] = null;
        }

        // Repairs (none) selector value
        string[] editforms = { "AccountCountryID", "accountprimarycontactid", "accountsecondarycontactid", "accountsubsidiaryofid", "accountstatusid" };
        foreach (string editFormName in editforms)
        {
            if (ValidationHelper.GetInteger(EditForm.Data[editFormName], 0) <= 0)
            {
                EditForm.Data[editFormName] = null;
            }
        }

        int subsidiaryID = ValidationHelper.GetInteger(EditForm.EditedObject.GetValue("accountsubsidiaryofid"), -1);

        // When subsidiary account does not exist anymore, reset UI form Subsidiary of field
        if (AccountInfoProvider.GetAccountInfo(subsidiaryID) == null)
        {
            EditForm.EditedObject.SetValue("accountsubsidiaryofid", null);
            ((UniSelector)EditForm.FieldControls["accountsubsidiaryofid"]).Reload(true);
        }

        AssignContacts();
    }
Example #2
0
    /// <summary>
    /// Initializes headquarters selector
    /// </summary>
    private void InitHeadquarters()
    {
        mMergedAccounts.Tables[0].DefaultView.Sort      = "AccountSubsidiaryOfID";
        mMergedAccounts.Tables[0].DefaultView.RowFilter = "AccountSubsidiaryOfID > 0";
        DataTable table = mMergedAccounts.Tables[0].DefaultView.ToTable(true, new string[]
        {
            "AccountSubsidiaryOfID",
            "SubsidiaryOfName"
        });

        // Preselect headquarters with data from parent
        if (mParentAccount.AccountSubsidiaryOfID > 0)
        {
            accountSelector.Value = mParentAccount.AccountSubsidiaryOfID;
        }
        // Preselect account status with data from merged accounts only if single value exists in merged items
        else if ((table.Rows != null) && (table.Rows.Count > 0))
        {
            accountSelector.Value = ValidationHelper.GetInteger(table.Rows[0][0], 0);
        }

        AccountInfo ai   = AccountInfoProvider.GetAccountInfo(mParentAccount.AccountSubsidiaryOfID);
        string      name = ai == null ? null : ai.AccountName;

        DisplayTooltip(imgAccountHeadquarters, table, "SubsidiaryOfName", name, FieldDataType.Unknown);
    }
 /// <summary>
 /// Unigrid button clicked.
 /// </summary>
 protected void gridElem_OnAction(string actionName, object actionArgument)
 {
     // Perform 'remove' action
     if (actionName == "remove")
     {
         // Delete the object
         int         accountId = ValidationHelper.GetInteger(actionArgument, 0);
         AccountInfo account   = AccountInfoProvider.GetAccountInfo(accountId);
         if (account != null)
         {
             // User has no permission to modify site accounts
             if (((account.AccountSiteID > 0) && !modifySiteAccounts) || !ContactGroupHelper.AuthorizedModifyContactGroup(cgi.ContactGroupSiteID, false))
             {
                 CMSPage.RedirectToCMSDeskAccessDenied(ModuleEntry.CONTACTMANAGEMENT, "ModifyAccounts");
             }
             // User has no permission to modify global accounts
             else if ((account.AccountSiteID == 0) && !modifyGlobalAccounts || !ContactGroupHelper.AuthorizedModifyContactGroup(cgi.ContactGroupSiteID, false))
             {
                 CMSPage.RedirectToCMSDeskAccessDenied(ModuleEntry.CONTACTMANAGEMENT, "ModifyGlobalAccounts");
             }
             // User has permission
             else
             {
                 // Get the relationship object
                 ContactGroupMemberInfo mi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, accountId, ContactGroupMemberTypeEnum.Account);
                 if (mi != null)
                 {
                     ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(mi);
                 }
             }
         }
     }
 }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StopProcessing)
        {
            Visible = false;
        }
        else
        {
            // Display info label that account is merged into site account
            if ((ai != null) && (mergedIntoSite))
            {
                parentAI = AccountInfoProvider.GetAccountInfo(ai.AccountMergedWithAccountID);
                lblMergedInto.ResourceString = "om.account.mergedintosite";
            }
            // Display info that account is merged into global account
            else if ((ai != null) && (mergedIntoGlobal))
            {
                parentAI = AccountInfoProvider.GetAccountInfo(ai.AccountGlobalAccountID);
                lblMergedInto.ResourceString = "om.account.mergedintoglobal";
            }
            // Don't display any info
            else
            {
                lblMergedInto.Visible = false;
            }

            // Set basic properties
            pnlGeneral.GroupingText  = GetString("general.general");
            pnlAddress.GroupingText  = GetString("contentmenu.address");
            pnlContacts.GroupingText = GetString("om.contact.list");
            pnlNotes.GroupingText    = GetString("om.account.notes");
            btnStamp.OnClientClick   = "AddStamp('" + htmlNotes.ClientID + "'); return false;";
            Reload();
            RegisterScripts();

            primaryContact.OnSelectionChanged   += (s, ea) => SetContactRoleID((FormEngineUserControl)s, contactRolePrimary);
            secondaryContact.OnSelectionChanged += (s, ea) => SetContactRoleID((FormEngineUserControl)s, contactRoleSecondary);

            // Display 'changes saved' or 'split' label
            if (!RequestHelper.IsPostBack())
            {
                if (QueryHelper.GetBoolean("saved", false))
                {
                    ShowChangesSaved();
                }
                else if (QueryHelper.GetBoolean("split", false))
                {
                    ShowConfirmation(GetString("om.account.splitted"));
                }
            }
        }
    }
    /// <summary>
    /// Delete items.
    /// </summary>
    private void DeleteItems()
    {
        // Delete the accounts
        foreach (string accountId in accountIds)
        {
            var ai = AccountInfoProvider.GetAccountInfo(ValidationHelper.GetInteger(accountId, 0));
            if (ai != null)
            {
                // Display name of deleted account
                AddLog(ai.AccountName);

                // Delete account with its dependencies
                AccountHelper.Delete(ai, chkBranches.Checked);
            }
        }
    }
 /// <summary>
 /// UniGrid button clicked.
 /// </summary>
 private void gridElem_OnAction(string actionName, object actionArgument)
 {
     if (actionName == "remove")
     {
         if (AccountHelper.AuthorizedModifyAccount(SiteID, true))
         {
             int         relationId   = ValidationHelper.GetInteger(actionArgument, 0);
             AccountInfo editedObject = AccountInfoProvider.GetAccountInfo(relationId);
             if (editedObject != null)
             {
                 editedObject.AccountSubsidiaryOfID = 0;
                 AccountInfoProvider.SetAccountInfo(editedObject);
             }
         }
     }
 }
    /// <summary>
    /// Unigrid button clicked.
    /// </summary>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        // Perform 'remove' action
        if (actionName == "remove")
        {
            // Delete the object
            int         accountId = ValidationHelper.GetInteger(actionArgument, 0);
            AccountInfo account   = AccountInfoProvider.GetAccountInfo(accountId);
            if (account != null)
            {
                CheckModifyPermissions();

                // Get the relationship object
                ContactGroupMemberInfo mi = ContactGroupMemberInfoProvider.GetContactGroupMemberInfoByData(cgi.ContactGroupID, accountId, ContactGroupMemberTypeEnum.Account);
                if (mi != null)
                {
                    ContactGroupMemberInfoProvider.DeleteContactGroupMemberInfo(mi);
                }
            }
        }
    }
Example #8
0
    /// <summary>
    /// Delete items.
    /// </summary>
    private void DeleteItems()
    {
        // Set long timeout so that mass delete can finish successfully
        SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder(ConnectionHelper.GetConnection().DataConnection.ConnectionString);

        connectionString.ConnectTimeout = SQL_TIMEOUT;
        using (var cs = new CMSConnectionScope(connectionString.ToString(), true))
        {
            // Delete the accounts
            AccountInfo ai = null;
            foreach (string accountId in accountIds)
            {
                ai = AccountInfoProvider.GetAccountInfo(ValidationHelper.GetInteger(accountId, 0));
                if (ai != null)
                {
                    // Display name of deleted account
                    AddLog(ai.AccountName);

                    // Delete account with its dependencies
                    AccountHelper.Delete(ai, chkChildren.Checked, chkBranches.Checked);
                }
            }
        }
    }
Example #9
0
    /// <summary>
    /// Sets visibility of buttons that are connected to merged account - split button and link to his parent.
    /// </summary>
    private void SetButtonsVisibility()
    {
        // Find out if current account is merged into another site or account contact
        bool mergedIntoSite   = ValidationHelper.GetInteger(EditForm.Data["AccountMergedWithAccountID"], 0) != 0;
        bool mergedIntoGlobal = ValidationHelper.GetInteger(EditForm.Data["AccountGlobalAccountID"], 0) != 0 &&
                                AccountHelper.AuthorizedReadAccount(UniSelector.US_GLOBAL_RECORD, false);
        bool globalAccountsVisible = SettingsKeyInfoProvider.GetBoolValue(SiteContext.CurrentSiteName + ".CMSCMGlobalAccounts") || CurrentUser.IsGlobalAdministrator;

        if ((mergedIntoGlobal && globalAccountsVisible) || mergedIntoSite)
        {
            // Get parent account
            if (mergedIntoSite)
            {
                parentAccount = AccountInfoProvider.GetAccountInfo(ValidationHelper.GetInteger(EditForm.Data["AccountMergedWithAccountID"], 0));
                headingMergedInto.ResourceString = "om.account.mergedintosite";
            }
            else
            {
                parentAccount = AccountInfoProvider.GetAccountInfo(ValidationHelper.GetInteger(EditForm.Data["AccountGlobalAccountID"], 0));
                headingMergedInto.ResourceString = "om.account.mergedintoglobal";
            }

            lblMergedIntoAccountName.Text = HTMLHelper.HTMLEncode(parentAccount.AccountName.Trim());

            string accountDetailDialogURL = UIContextHelper.GetElementDialogUrl(ModuleName.ONLINEMARKETING, "EditAccount", parentAccount.AccountID, "isSiteManager=" + ContactHelper.IsSiteManager);
            string openDialogScript       = ScriptHelper.GetModalDialogScript(accountDetailDialogURL, "AccountDetail");

            btnMergedAccount.IconCssClass  = "icon-edit";
            btnMergedAccount.OnClientClick = openDialogScript;
            btnMergedAccount.ToolTip       = GetString("om.account.viewdetail");
        }
        else
        {
            panelMergedAccountDetails.Visible = btnSplit.Visible = false;
        }
    }
Example #10
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();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!QueryHelper.ValidateHash("hash") || Parameters == null)
        {
            StopProcessing = true;
            return;
        }

        PageTitle.TitleText = GetString("om.contactrole.select");
        Page.Title          = PageTitle.TitleText;

        // Check if the dialog was opened from mass actions
        isMassAction = Parameters.ContainsKey("ismassaction");
        if (isMassAction)
        {
            siteId = ValidationHelper.GetInteger(Parameters["siteid"], 0);
        }
        else
        {
            int accountContactId = ValidationHelper.GetInteger(Parameters["accountcontactid"], 0);
            aci = AccountContactInfoProvider.GetAccountContactInfo(accountContactId);
            if (aci != null)
            {
                AccountInfo ai = AccountInfoProvider.GetAccountInfo(aci.AccountID);
                if (ai != null)
                {
                    siteId = ai.AccountSiteID;
                }
            }
        }

        // Show all global configuration to authorized users ..
        bool allowGlobal = ConfigurationHelper.AuthorizedReadConfiguration(UniSelector.US_GLOBAL_RECORD, false);

        // .. but just in SiteManager - fake it in CMSDesk so that even Global Admin sees user configuration
        // as Site Admins (depending on settings).
        bool isSiteManager = ValidationHelper.GetBoolean(Parameters["issitemanager"], false);

        allowGlobal &= (isSiteManager || SettingsKeyInfoProvider.GetBoolValue(SiteInfoProvider.GetSiteName(siteId) + ".cmscmglobalconfiguration"));

        bool allowSite;

        if (siteId > 0)
        {
            allowSite = ConfigurationHelper.AuthorizedReadConfiguration(siteId, false);
        }
        else
        {
            allowSite = ConfigurationHelper.AuthorizedReadConfiguration(SiteContext.CurrentSiteID, false);
        }

        // Check read permission
        if ((siteId > 0) && !allowSite && !allowGlobal)
        {
            RedirectToAccessDenied("cms.contactmanagement", "ReadConfiguration");
            return;
        }
        else if ((siteId == 0) && !allowGlobal)
        {
            RedirectToAccessDenied("cms.contactmanagement", "ReadGlobalConfiguration");
            return;
        }

        if (siteId > 0)
        {
            if (allowSite)
            {
                gridElem.WhereCondition = "ContactRoleSiteID = " + siteId;
            }

            // Check if global config is allowed for the site
            if (allowGlobal)
            {
                // Add contact roles from global configuration
                gridElem.WhereCondition = SqlHelper.AddWhereCondition(gridElem.WhereCondition, "ContactRoleSiteID IS NULL", "OR");
            }
        }
        else if ((siteId == 0) && allowGlobal)
        {
            gridElem.WhereCondition = "ContactRoleSiteID IS NULL";
        }

        gridElem.OnExternalDataBound  += gridElem_OnExternalDataBound;
        gridElem.Pager.DefaultPageSize = 10;

        // Display 'Reset' button when 'none' role is allowed
        if (ValidationHelper.GetBoolean(Parameters["allownone"], false))
        {
            btnReset.Visible         = true;
            btnReset.Click          += btn_Click;
            btnReset.CommandArgument = "0";
        }
    }