Ejemplo n.º 1
0
    /// <summary>
    /// Updates the current Group or creates new if no GroupID is present.
    /// </summary>
    public void SaveData()
    {
        if (!CheckPermissions("cms.groups", CMSAdminControl.PERMISSION_MANAGE, this.GroupID))
        {
            return;
        }

        // Trim display name and code name
        string displayName = this.txtDisplayName.Text.Trim();
        string codeName    = ValidationHelper.GetCodeName(this.txtCodeName.Text.Trim(), null, 89, true, true);

        this.txtCodeName.Text = codeName;

        // Validate form entries
        string errorMessage = ValidateForm(displayName, codeName);

        if (errorMessage == "")
        {
            txtCodeName.Text    = codeName;
            txtDisplayName.Text = displayName;

            GroupInfo group = null;

            try
            {
                bool newGroup = false;
                // Update existing item
                if ((this.GroupID) > 0 && (gi != null))
                {
                    group = gi;
                }
                else
                {
                    group    = new GroupInfo();
                    newGroup = true;
                }

                if (group != null)
                {
                    if (displayName != group.GroupDisplayName)
                    {
                        // Refresh a breadcrumb if used in the tabs layout
                        ScriptHelper.RefreshTabHeader(Page, string.Empty);
                    }

                    if (this.DisplayAdvanceOptions)
                    {
                        // Update Group fields
                        group.GroupDisplayName = displayName;
                        group.GroupName        = codeName;
                        group.GroupNodeGUID    = ValidationHelper.GetGuid(this.groupPageURLElem.Value, Guid.Empty);
                    }

                    if ((AllowChangeGroupDisplayName) && (IsLiveSite))
                    {
                        group.GroupDisplayName = displayName;
                    }

                    group.GroupDescription                        = this.txtDescription.Text;
                    group.GroupAccess                             = GetGroupAccess();
                    group.GroupSiteID                             = this.SiteID;
                    group.GroupApproveMembers                     = GetGroupApproveMembers();
                    group.GroupSendJoinLeaveNotification          = this.chkJoinLeave.Checked;
                    group.GroupSendWaitingForApprovalNotification = this.chkWaitingForApproval.Checked;
                    this.groupPictureEdit.UpdateGroupPicture(group);

                    // If new group was created
                    if (newGroup)
                    {
                        // Set columns GroupCreatedByUserID and GroupApprovedByUserID to current user
                        CurrentUserInfo user = CMSContext.CurrentUser;
                        if (user != null)
                        {
                            group.GroupCreatedByUserID  = user.UserID;
                            group.GroupApprovedByUserID = user.UserID;
                            group.GroupApproved         = true;
                        }
                    }

                    if ((!IsLiveSite) && (group.GroupNodeGUID == Guid.Empty))
                    {
                        plcStyleSheetSelector.Visible = false;
                    }

                    // Save theme
                    int selectedSheetID = ValidationHelper.GetInteger(ctrlSiteSelectStyleSheet.Value, 0);
                    if (plcStyleSheetSelector.Visible)
                    {
                        if (group.GroupNodeGUID != Guid.Empty)
                        {
                            // Save theme for every site culture
                            ArrayList cultures = CultureInfoProvider.GetSiteCultureCodes(CMSContext.CurrentSiteName);
                            if (cultures != null)
                            {
                                TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
                                // Return class name of selected tree node
                                TreeNode treeNode = tree.SelectSingleNode(group.GroupNodeGUID, TreeProvider.ALL_CULTURES, CMSContext.CurrentSiteName);
                                if (treeNode != null)
                                {
                                    // Return all culture version of node
                                    DataSet ds = tree.SelectNodes(CMSContext.CurrentSiteName, null, TreeProvider.ALL_CULTURES, false, treeNode.NodeClassName, "NodeGUID ='" + group.GroupNodeGUID + "'", String.Empty, -1, false);
                                    if (!DataHelper.DataSourceIsEmpty(ds))
                                    {
                                        // Loop trhough all nodes
                                        foreach (DataRow dr in ds.Tables[0].Rows)
                                        {
                                            // Create node and set treeprovider for user validation
                                            TreeNode node = TreeNode.New(dr, ValidationHelper.GetString(dr["className"], String.Empty));;
                                            node.TreeProvider = tree;
                                            // Update stylesheet id if set
                                            if (selectedSheetID == 0)
                                            {
                                                node.SetValue("DocumentStylesheetID", -1);
                                            }
                                            else
                                            {
                                                node.DocumentStylesheetID = selectedSheetID;
                                            }
                                            node.Update();
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if ((!IsLiveSite) && (group.GroupNodeGUID != Guid.Empty))
                    {
                        plcStyleSheetSelector.Visible = true;
                    }

                    if (plcOnline.Visible)
                    {
                        // On-line marketing setting is visible => set flag according to checkbox
                        group.GroupLogActivity = chkLogActivity.Checked;
                    }
                    else
                    {
                        // On-line marketing setting is not visible => set flag to TRUE as default value
                        group.GroupLogActivity = true;
                    }

                    // Save Group in the database
                    GroupInfoProvider.SetGroupInfo(group);
                    this.groupPictureEdit.GroupInfo = group;

                    // Flush cached information
                    CMSContext.CurrentDocument           = null;
                    CMSContext.CurrentPageInfo           = null;
                    CMSContext.CurrentDocumentStylesheet = null;

                    // Display information on success
                    this.lblInfo.Text    = GetString("general.changessaved");
                    this.lblInfo.Visible = true;

                    // If new group was created
                    if (newGroup)
                    {
                        this.GroupID = group.GroupID;
                        this.RaiseOnSaved();
                    }
                }
            }
            catch (Exception ex)
            {
                // Display error message
                this.lblError.Text    = GetString("general.erroroccurred") + " " + ex.Message;
                this.lblError.Visible = true;
            }
        }
        else
        {
            // Display error message
            this.lblError.Text    = errorMessage;
            this.lblError.Visible = true;
        }
    }