/// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        GroupInfo gi = null;

        // Handle event
        switch (actionName)
        {
        case "approve":
            CheckPermissions();
            gi = GroupInfoProvider.GetGroupInfo(ValidationHelper.GetInteger(actionArgument, 0));
            gi.GroupApproved         = true;
            gi.GroupApprovedByUserID = MembershipContext.AuthenticatedUser.UserID;
            GroupInfoProvider.SetGroupInfo(gi);
            break;

        case "reject":
            CheckPermissions();
            gi = GroupInfoProvider.GetGroupInfo(ValidationHelper.GetInteger(actionArgument, 0));
            gi.GroupApproved         = false;
            gi.GroupApprovedByUserID = 0;
            GroupInfoProvider.SetGroupInfo(gi);
            break;
        }

        RaiseOnAction(actionName, actionArgument);
    }
Beispiel #2
0
    /// <summary>
    /// Creates group. Called when the "Create group" button is pressed.
    /// </summary>
    private bool CreateGroup()
    {
        // Create new group object
        GroupInfo newGroup = new GroupInfo();

        // Set the properties
        newGroup.GroupDisplayName      = "My new group";
        newGroup.GroupName             = "MyNewGroup";
        newGroup.GroupSiteID           = CMSContext.CurrentSiteID;
        newGroup.GroupDescription      = "";
        newGroup.GroupApproveMembers   = GroupApproveMembersEnum.AnyoneCanJoin;
        newGroup.GroupAccess           = SecurityAccessEnum.AllUsers;
        newGroup.GroupApproved         = true;
        newGroup.GroupApprovedByUserID = CurrentUser.UserID;
        newGroup.GroupCreatedByUserID  = CurrentUser.UserID;
        newGroup.AllowCreate           = SecurityAccessEnum.GroupMembers;
        newGroup.AllowDelete           = SecurityAccessEnum.GroupMembers;
        newGroup.AllowModify           = SecurityAccessEnum.GroupMembers;
        newGroup.GroupNodeGUID         = Guid.Empty;

        // Save the group
        GroupInfoProvider.SetGroupInfo(newGroup);

        return(true);
    }
Beispiel #3
0
    /// <summary>
    /// Gets and bulk updates groups. Called when the "Get and bulk update groups" button is pressed.
    /// Expects the CreateGroup method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateGroups()
    {
        // Prepare the parameters
        string where = "GroupName LIKE N'MyNewGroup%'";

        // Get the data
        DataSet groups = GroupInfoProvider.GetGroups(where, null);

        if (!DataHelper.DataSourceIsEmpty(groups))
        {
            // Loop through the individual items
            foreach (DataRow groupDr in groups.Tables[0].Rows)
            {
                // Create object from DataRow
                GroupInfo modifyGroup = new GroupInfo(groupDr);

                // Update the properties
                modifyGroup.GroupDisplayName = modifyGroup.GroupDisplayName.ToUpper();

                // Save the changes
                GroupInfoProvider.SetGroupInfo(modifyGroup);
            }

            return(true);
        }

        return(false);
    }
Beispiel #4
0
    public void RaisePostBackEvent(string eventArgument)
    {
        if (!CheckPermissions("cms.groups", PERMISSION_MANAGE, GroupID))
        {
            return;
        }

        string[] args = eventArgument.Split(';');

        if (args.Length == 2)
        {
            // Get info on currently selected item
            int permission = Convert.ToInt32(args[0]);
            int access     = Convert.ToInt32(args[1]);

            GroupInfo group = GroupInfoProvider.GetGroupInfo(GroupID);
            if (group != null)
            {
                // Update forum permission access information
                switch (permission)
                {
                case 0:
                    // Set 'AllowCreate' permission to specified access
                    group.AllowCreate = (SecurityAccessEnum)access;
                    break;

                case 1:
                    // Set 'AllowDelete' permission to specified access
                    group.AllowDelete = ((SecurityAccessEnum)access);
                    break;

                case 2:
                    // Set 'AllowModify' permission to specified access
                    group.AllowModify = (SecurityAccessEnum)access;
                    break;

                default:
                    break;
                }

                // Save changes to the forum
                GroupInfoProvider.SetGroupInfo(group);
            }
        }
    }
Beispiel #5
0
    /// <summary>
    /// Gets and updates group. Called when the "Get and update group" button is pressed.
    /// Expects the CreateGroup method to be run first.
    /// </summary>
    private bool GetAndUpdateGroup()
    {
        // Get the group
        GroupInfo updateGroup = GroupInfoProvider.GetGroupInfo("MyNewGroup", CMSContext.CurrentSiteName);

        if (updateGroup != null)
        {
            // Update the properties
            updateGroup.GroupDisplayName = updateGroup.GroupDisplayName.ToLowerCSafe();

            // Save the changes
            GroupInfoProvider.SetGroupInfo(updateGroup);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Deletes group picture.
    /// </summary>
    /// <param name="gi">GroupInfo</param>
    public static void DeleteOldGroupPicture(GroupInfo gi)
    {
        // Delete old picture if needed
        if (gi.GroupAvatarID != 0)
        {
            // Delete avatar info provider if needed
            AvatarInfo ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(gi.GroupAvatarID);
            if (ai != null)
            {
                if (ai.AvatarIsCustom)
                {
                    AvatarInfoProvider.DeleteAvatarInfo(ai);
                    AvatarInfoProvider.DeleteAvatarFile(ai.AvatarGUID.ToString(), ai.AvatarFileExtension, false, false);
                }

                gi.GroupAvatarID = 0;
                GroupInfoProvider.SetGroupInfo(gi);
            }
        }
    }
Beispiel #7
0
    /// <summary>
    /// Updates the current Group or creates new if no GroupID is present.
    /// </summary>
    public void SaveData()
    {
        if (!CheckPermissions("cms.groups", PERMISSION_MANAGE, GroupID))
        {
            return;
        }

        // Validate form entries
        string errorMessage = ValidateForm();

        if (!String.IsNullOrEmpty(errorMessage))
        {
            // Display error message
            ShowError(errorMessage);
            return;
        }

        try
        {
            bool newGroup = false;

            // Update existing item
            if (groupInfo == null)
            {
                groupInfo = new GroupInfo();
                newGroup  = true;
            }

            // Trim display name and code name
            string displayName = txtDisplayName.Text.Trim();
            string codeName    = txtCodeName.Text.Trim();

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

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

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

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

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

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

            // Save theme
            int selectedSheetID = ValidationHelper.GetInteger(ctrlSiteSelectStyleSheet.Value, 0);
            if (plcStyleSheetSelector.Visible)
            {
                if (groupInfo.GroupNodeGUID != Guid.Empty)
                {
                    // Save theme for every site culture
                    var cultures = CultureSiteInfoProvider.GetSiteCultureCodes(SiteContext.CurrentSiteName);
                    if (cultures != null)
                    {
                        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

                        // Return class name of selected tree node
                        TreeNode treeNode = tree.SelectSingleNode(groupInfo.GroupNodeGUID, TreeProvider.ALL_CULTURES, SiteContext.CurrentSiteName);
                        if (treeNode != null)
                        {
                            // Return all culture version of node
                            DataSet ds = tree.SelectNodes(SiteContext.CurrentSiteName, null, TreeProvider.ALL_CULTURES, false, treeNode.NodeClassName, "NodeGUID ='" + groupInfo.GroupNodeGUID + "'", String.Empty, -1, false);
                            if (!DataHelper.DataSourceIsEmpty(ds))
                            {
                                // Loop through all nodes
                                foreach (DataRow dr in ds.Tables[0].Rows)
                                {
                                    // Create node and set tree provider for user validation
                                    TreeNode node = TreeNode.New(ValidationHelper.GetString(dr["className"], String.Empty), dr);
                                    node.TreeProvider = tree;

                                    // Update stylesheet id if set
                                    if (selectedSheetID == 0)
                                    {
                                        node.DocumentStylesheetID       = 0;
                                        node.DocumentInheritsStylesheet = true;
                                    }
                                    else
                                    {
                                        node.DocumentStylesheetID = selectedSheetID;
                                    }

                                    node.Update();
                                }
                            }
                        }
                    }
                }
            }

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

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

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

            txtDisplayName.Text = groupInfo.GroupDisplayName;
            txtCodeName.Text    = groupInfo.GroupName;

            // Flush cached information
            DocumentContext.CurrentDocument = null;
            DocumentContext.CurrentPageInfo = null;

            // Display information on success
            ShowChangesSaved();

            // If new group was created
            if (newGroup)
            {
                GroupID = groupInfo.GroupID;
                RaiseOnSaved();
            }
        }
        catch (Exception ex)
        {
            // Display error message
            ShowError(GetString("general.saveerror"), ex.Message, null);
        }
    }
    /// <summary>
    /// Updates picture of current group.
    /// </summary>
    /// <param name="gi">Group info object</param>
    public void UpdateGroupPicture(GroupInfo gi)
    {
        AvatarInfo ai = null;

        if (gi != null)
        {
            // Delete avatar if needed
            if (ValidationHelper.GetBoolean(hiddenDeleteAvatar.Value, false))
            {
                DeleteOldGroupPicture(gi);
            }

            // If some file was uploaded
            if ((uplFilePicture.PostedFile != null) && (uplFilePicture.PostedFile.ContentLength > 0) && ImageHelper.IsImage(Path.GetExtension(uplFilePicture.PostedFile.FileName)))
            {
                // Check if this group has some avatar and if so check if is custom
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(gi.GroupAvatarID);
                if ((ai != null) && ai.AvatarIsCustom)
                {
                    ReplaceExistingAvatar(ai);
                }
                else
                {
                    // Delete old picture
                    DeleteOldGroupPicture(gi);
                    ai = CreateNewAvatar();
                }

                AvatarInfoProvider.SetAvatarInfo(ai);

                // Update group info
                gi.GroupAvatarID = ai.AvatarID;
                GroupInfoProvider.SetGroupInfo(gi);


                plcImageActions.Visible = true;
            }
            // If predefined was chosen
            else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value))
            {
                // Delete old picture
                DeleteOldGroupPicture(gi);

                Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid());
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid);

                // Update group info
                if (ai != null)
                {
                    gi.GroupAvatarID = ai.AvatarID;
                    GroupInfoProvider.SetGroupInfo(gi);
                }

                plcImageActions.Visible = true;
            }
            else
            {
                plcImageActions.Visible = false;
            }
        }
        else
        {
            bool pseudoDelete = ValidationHelper.GetBoolean(hiddenDeleteAvatar.Value, false);
            // Try to get avatar info
            if (avatarID != 0)
            {
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(avatarID);
            }

            // If some new picture was uploaded
            if ((uplFilePicture.PostedFile != null) && (uplFilePicture.PostedFile.ContentLength > 0) && ImageHelper.IsImage(Path.GetExtension(uplFilePicture.PostedFile.FileName)))
            {
                // Change delete to false because file will be replaced
                pseudoDelete = false;

                // If some avatar exists and is custom
                if ((ai != null) && (ai.AvatarIsCustom))
                {
                    // Delete file and upload new
                    AvatarInfoProvider.DeleteAvatarFile(ai.AvatarGUID.ToString(), ai.AvatarFileExtension, false, false);
                    ReplaceExistingAvatar(ai);
                }
                else
                {
                    ai = CreateNewAvatar();
                }

                // Update database
                AvatarInfoProvider.SetAvatarInfo(ai);
            }
            // If some predefined avatar was selected
            else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value))
            {
                // Change delete to false because file will be replaced
                pseudoDelete = false;

                // If some avatar exists and is custom
                if ((ai != null) && (ai.AvatarIsCustom))
                {
                    AvatarInfoProvider.DeleteAvatarFile(ai.AvatarGUID.ToString(), ai.AvatarFileExtension, false, false);
                    AvatarInfoProvider.DeleteAvatarInfo(ai);
                }

                Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid());
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid);
            }

            // If file was deleted - not replaced
            if (pseudoDelete)
            {
                // Delete it
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(avatarID);
                if (ai != null)
                {
                    if (ai.AvatarIsCustom)
                    {
                        AvatarInfoProvider.DeleteAvatarInfo(ai);
                    }
                }

                ai       = null;
                avatarID = 0;
                plcImageActions.Visible = false;
                GroupPicture.AvatarID   = 0;
            }

            // Update avatar id
            if (ai != null)
            {
                GroupPicture.AvatarID   = avatarID = ai.AvatarID;
                plcImageActions.Visible = true;
            }
        }
    }
Beispiel #9
0
    /// <summary>
    /// Updates the current Group or creates new if no GroupID is present.
    /// </summary>
    public void SaveData()
    {
        // Check banned IP
        if (!BannedIPInfoProvider.IsAllowed(SiteContext.CurrentSiteName, BanControlEnum.AllNonComplete))
        {
            ShowError(GetString("General.BannedIP"));
            return;
        }

        // Validate form entries
        string errorMessage = ValidateForm();

        if (errorMessage == string.Empty)
        {
            try
            {
                codeName = GetSafeCodeName();
                codeName = GetUniqueCodeName(codeName);

                GroupInfo group = new GroupInfo();
                group.GroupDisplayName    = txtDisplayName.Text;
                group.GroupName           = codeName;
                group.GroupDescription    = txtDescription.Text;
                group.GroupAccess         = GetGroupAccess();
                group.GroupSiteID         = mSiteId;
                group.GroupApproveMembers = GetGroupApproveMembers();

                // Set columns GroupCreatedByUserID and GroupApprovedByUserID to current user
                var user = MembershipContext.AuthenticatedUser;

                if (user != null)
                {
                    group.GroupCreatedByUserID = user.UserID;

                    if ((!RequireApproval) || (CurrentUserIsAdmin()))
                    {
                        group.GroupApprovedByUserID = user.UserID;
                        group.GroupApproved         = true;
                    }
                }

                // Save Group in the database
                GroupInfoProvider.SetGroupInfo(group);

                // Create group admin role
                RoleInfo roleInfo = new RoleInfo();
                roleInfo.DisplayName = "Group admin";
                roleInfo.RoleName    = group.GroupName + "_groupadmin";
                roleInfo.RoleGroupID = group.GroupID;
                roleInfo.RoleIsGroupAdministrator = true;
                roleInfo.SiteID = mSiteId;
                // Save group admin role
                RoleInfoProvider.SetRoleInfo(roleInfo);

                if (user != null)
                {
                    // Set user as member of group
                    GroupMemberInfo gmi = new GroupMemberInfo();
                    gmi.MemberUserID           = user.UserID;
                    gmi.MemberGroupID          = group.GroupID;
                    gmi.MemberJoined           = DateTime.Now;
                    gmi.MemberStatus           = GroupMemberStatus.Approved;
                    gmi.MemberApprovedWhen     = DateTime.Now;
                    gmi.MemberApprovedByUserID = user.UserID;

                    // Save user as member of group
                    GroupMemberInfoProvider.SetGroupMemberInfo(gmi);

                    // Set user as member of admin group role
                    UserRoleInfo userRole = new UserRoleInfo();
                    userRole.UserID = user.UserID;
                    userRole.RoleID = roleInfo.RoleID;

                    // Save user as member of admin group role
                    UserRoleInfoProvider.SetUserRoleInfo(userRole);
                }

                // Clear user session a request
                MembershipContext.AuthenticatedUser.Generalized.Invalidate(false);
                MembershipContext.AuthenticatedUser = null;

                string culture = CultureHelper.EnglishCulture.ToString();
                if (DocumentContext.CurrentDocument != null)
                {
                    culture = DocumentContext.CurrentDocument.DocumentCulture;
                }

                // Copy document
                errorMessage = GroupInfoProvider.CopyGroupDocument(group, GroupTemplateSourceAliasPath, GroupTemplateTargetAliasPath, GroupProfileURLPath, culture, CombineWithDefaultCulture, MembershipContext.AuthenticatedUser, roleInfo);

                if (!String.IsNullOrEmpty(errorMessage))
                {
                    // Display error message
                    ShowError(errorMessage);
                    return;
                }

                // Create group forum
                if (CreateForum)
                {
                    CreateGroupForum(group);

                    // Create group forum search index
                    if (CreateSearchIndexes)
                    {
                        CreateGroupForumSearchIndex(group);
                    }
                }

                // Create group media library
                if (CreateMediaLibrary)
                {
                    CreateGroupMediaLibrary(group);
                }

                // Create search index for group documents
                if (CreateSearchIndexes)
                {
                    CreateGroupContentSearchIndex(group);
                }

                // Display information on success
                ShowConfirmation(GetString("group.group.createdinfo"));

                // If URL is set, redirect user to specified page
                if (!String.IsNullOrEmpty(RedirectToURL))
                {
                    URLHelper.Redirect(ResolveUrl(DocumentURLProvider.GetUrl(RedirectToURL)));
                }

                // After registration message
                if ((RequireApproval) && (!CurrentUserIsAdmin()))
                {
                    ShowConfirmation(SuccessfullRegistrationWaitingForApprovalText);

                    // Send approval email to admin
                    if (!String.IsNullOrEmpty(SendWaitingForApprovalEmailTo))
                    {
                        // Create the message
                        EmailTemplateInfo eti = EmailTemplateProvider.GetEmailTemplate("Groups.WaitingForApproval", SiteContext.CurrentSiteName);
                        if (eti != null)
                        {
                            EmailMessage message = new EmailMessage();
                            if (String.IsNullOrEmpty(eti.TemplateFrom))
                            {
                                message.From = SettingsKeyInfoProvider.GetStringValue(SiteContext.CurrentSiteName + ".CMSSendEmailNotificationsFrom");
                            }
                            else
                            {
                                message.From = eti.TemplateFrom;
                            }

                            MacroResolver resolver = MacroContext.CurrentResolver;
                            resolver.SetAnonymousSourceData(group);
                            resolver.SetNamedSourceData("Group", group);

                            message.Recipients = SendWaitingForApprovalEmailTo;
                            message.Subject    = resolver.ResolveMacros(eti.TemplateSubject);
                            message.Body       = resolver.ResolveMacros(eti.TemplateText);

                            resolver.Settings.EncodeResolvedValues = false;
                            message.PlainTextBody = resolver.ResolveMacros(eti.TemplatePlainText);

                            // Send the message using email engine
                            EmailSender.SendEmail(message);
                        }
                    }
                }
                else
                {
                    string groupPath = SettingsKeyInfoProvider.GetStringValue(SiteContext.CurrentSiteName + ".CMSGroupProfilePath");
                    string url       = String.Empty;

                    if (!String.IsNullOrEmpty(groupPath))
                    {
                        url = DocumentURLProvider.GetUrl(groupPath.Replace("{GroupName}", group.GroupName));
                    }
                    ShowConfirmation(String.Format(SuccessfullRegistrationText, url));
                }

                // Hide form
                if (HideFormAfterRegistration)
                {
                    plcForm.Visible = false;
                }
                else
                {
                    ClearForm();
                }
            }
            catch (Exception ex)
            {
                // Display error message
                ShowError(GetString("general.saveerror"), ex.Message, null);
            }
        }
        else
        {
            // Display error message
            ShowError(errorMessage);
        }
    }
    /// <summary>
    /// Updates picture of current group.
    /// </summary>
    /// <param name="gi">Group info object</param>
    public void UpdateGroupPicture(GroupInfo gi)
    {
        AvatarInfo ai = null;

        if (gi != null)
        {
            // Delete avatar if needed
            if (hiddenDeleteAvatar.Value == "true")
            {
                DeleteOldGroupPicture(gi);
            }

            // If some file was uploaded
            if ((uplFilePicture.PostedFile != null) && (uplFilePicture.PostedFile.ContentLength > 0) && ImageHelper.IsImage(Path.GetExtension(uplFilePicture.PostedFile.FileName)))
            {
                // Check if this grou[ has some avatar and if so check if is custom
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(gi.GroupAvatarID);
                bool isCustom = false;
                if ((ai != null) && ai.AvatarIsCustom)
                {
                    isCustom = true;
                }

                if (isCustom)
                {
                    AvatarInfoProvider.UploadAvatar(ai, uplFilePicture.PostedFile,
                                                    SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarWidth"),
                                                    SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarHeight"),
                                                    SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarMaxSideSize"));
                }
                else
                {
                    // Delete old picture
                    DeleteOldGroupPicture(gi);

                    ai = new AvatarInfo(uplFilePicture.PostedFile,
                                        SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarWidth"),
                                        SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarHeight"),
                                        SettingsKeyProvider.GetIntValue(site.SiteName + ".CMSGroupAvatarMaxSideSize"));

                    ai.AvatarName     = AvatarInfoProvider.GetUniqueAvatarName(GetString("avat.custom") + " " + gi.GroupName);
                    ai.AvatarType     = AvatarTypeEnum.Group.ToString();
                    ai.AvatarIsCustom = true;
                    ai.AvatarGUID     = Guid.NewGuid();
                }

                AvatarInfoProvider.SetAvatarInfo(ai);

                // Update group info
                gi.GroupAvatarID = ai.AvatarID;
                GroupInfoProvider.SetGroupInfo(gi);

                plcImageActions.Visible = true;
            }
            // If predefined was chosen
            else if (!string.IsNullOrEmpty(hiddenAvatarGuid.Value))
            {
                // Delete old picture
                DeleteOldGroupPicture(gi);

                Guid guid = ValidationHelper.GetGuid(hiddenAvatarGuid.Value, Guid.NewGuid());
                ai = AvatarInfoProvider.GetAvatarInfoWithoutBinary(guid);

                // Update group info
                if (ai != null)
                {
                    gi.GroupAvatarID = ai.AvatarID;
                    GroupInfoProvider.SetGroupInfo(gi);
                }

                plcImageActions.Visible = true;
            }
            else
            {
                plcImageActions.Visible = false;
            }
        }
    }
Beispiel #11
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;
        }
    }