/// <summary> /// Initializes group selector. /// </summary> private void HandleGroupsSelection() { // Display group selector only when group module is present if (ModuleEntry.IsModuleRegistered(ModuleEntry.COMMUNITY) && ModuleEntry.IsModuleLoaded(ModuleEntry.COMMUNITY) && (groupsSelector != null)) { // Global libraries item into group selector if (GlobalLibraries != AvailableLibrariesEnum.None) { // Add special item groupsSelector.SetValue("UseDisplayNames", true); groupsSelector.SetValue("DisplayGlobalValue", true); groupsSelector.SetValue("SiteID", SiteID); groupsSelector.SetValue("GlobalValueText", GetString("dialogs.media.globallibraries")); groupsSelector.IsLiveSite = IsLiveSite; } else { groupsSelector.SetValue("DisplayGlobalValue", false); } // If all groups should be displayed switch (Groups) { case AvailableGroupsEnum.All: // Set condition to load only groups realted to the current site groupsSelector.SetValue("WhereCondition", String.Format("(GroupSiteID={0})", SiteID)); break; case AvailableGroupsEnum.OnlyCurrentGroup: // Load only current group and disable control int groupId = ModuleCommands.CommunityGetCurrentGroupID(); groupsSelector.SetValue("WhereCondition", String.Format("(GroupID={0})", groupId)); break; case AvailableGroupsEnum.OnlySingleGroup: if (!string.IsNullOrEmpty(GroupName)) { groupsSelector.SetValue("WhereCondition", String.Format("(GroupName = N'{0}' AND GroupSiteID={1})", SqlHelperClass.GetSafeQueryString(GroupName, false), SiteID)); } break; case AvailableGroupsEnum.None: // Just '(none)' displayed in the selection if (GlobalLibraries == AvailableLibrariesEnum.None) { groupsSelector.SetValue("DisplayNoneWhenEmpty", true); groupsSelector.SetValue("EnabledGroups", false); } groupsSelector.SetValue("WhereCondition", String.Format("({0})", SqlHelperClass.NO_DATA_WHERE)); break; } // Reload group selector based on recently passed settings ((IDataUserControl)groupsSelector).ReloadData(true); } else { plcGroupSelector.Visible = false; } }
/// <summary> /// Returns true if group permissions should be checked and specified permission is allowed in current group. /// Also returns true if group permissions should not be checked. /// </summary> /// <param name="permissionName">Permission to check (createpages, editpages, deletepages)</param> protected bool CheckGroupPermission(string permissionName) { if (CheckGroupPermissions && !MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin)) { // Get current group ID int groupId = ModuleCommands.CommunityGetCurrentGroupID(); if (groupId > 0) { // Returns true if current user is authorized for specified action in current group return(ModuleCommands.CommunityCheckGroupPermission(permissionName, groupId) || MembershipContext.AuthenticatedUser.IsGroupAdministrator(groupId)); } return(false); } return(true); }
/// <summary> /// Returns true if group permissions should be checked and specified permission is allowed in current group. /// Also returns true if group permissions should not be checked. /// </summary> /// <param name="permissionName">Permission to check (createpages, editpages, deletepages)</param> protected bool CheckGroupPermission(string permissionName) { if (CheckGroupPermissions && !CMSContext.CurrentUser.IsGlobalAdministrator) { // Get current group ID int groupId = ModuleCommands.CommunityGetCurrentGroupID(); if (groupId > 0) { // Returns true if current user is authorized for specified action in current group return(ModuleCommands.CommunityCheckGroupPermission(permissionName, groupId) || CMSContext.CurrentUser.IsGroupAdministrator(groupId)); } return(false); } return(true); }
/// <summary> /// Initializes control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { srcPosts.SiteName = SiteName; srcPosts.ForumName = ForumName; srcPosts.WhereCondition = WhereCondition; srcPosts.OrderBy = OrderBy; srcPosts.TopN = SelectTopN; srcPosts.FilterName = ValidationHelper.GetString(GetValue("WebPartControlID"), ID); srcPosts.SourceFilterName = FilterName; srcPosts.CacheItemName = CacheItemName; srcPosts.CacheDependencies = CacheDependencies; srcPosts.CacheMinutes = CacheMinutes; srcPosts.SelectOnlyApproved = SelectOnlyApproved; srcPosts.CheckPermissions = CheckPermissions; srcPosts.SelectedColumns = Columns; srcPosts.ShowGroupPosts = ShowGroupPosts && String.IsNullOrEmpty(ForumName); // Set data source groupid according to group name if (!String.IsNullOrEmpty(GroupName)) { if (GroupName == PredefinedObjectType.COMMUNITY_CURRENT_GROUP) { srcPosts.GroupID = ModuleCommands.CommunityGetCurrentGroupID(); } else { GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfoByName(GroupName, SiteName); if (gi != null) { srcPosts.GroupID = ValidationHelper.GetInteger(gi.GetValue("GroupID"), 0); } else { srcPosts.StopProcessing = true; } } } } }
/// <summary> /// Reloads control. /// </summary> /// <param name="forceReload">Forces nested CMSForm to reload if true</param> public void ReloadData(bool forceReload) { if (!mFormLoaded || forceReload) { // Check License LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.UserContributions); if (!StopProcessing) { // Set document manager mode if (NewDocument) { DocumentManager.Mode = FormModeEnum.Insert; DocumentManager.ParentNodeID = NodeID; DocumentManager.NewNodeClassID = ClassID; DocumentManager.CultureCode = CultureCode; DocumentManager.SiteName = SiteName; } else if (NewCulture) { DocumentManager.Mode = FormModeEnum.InsertNewCultureVersion; DocumentManager.NodeID = NodeID; DocumentManager.CultureCode = CultureCode; DocumentManager.SiteName = SiteName; DocumentManager.SourceDocumentID = CopyDefaultDataFromDocumentID; } else { DocumentManager.Mode = FormModeEnum.Update; DocumentManager.NodeID = NodeID; DocumentManager.SiteName = SiteName; DocumentManager.CultureCode = CultureCode; } ScriptHelper.RegisterDialogScript(Page); titleElem.TitleText = String.Empty; pnlSelectClass.Visible = false; pnlEdit.Visible = false; pnlInfo.Visible = false; pnlNewCulture.Visible = false; pnlDelete.Visible = false; // If node found, init the form if (NewDocument || (Node != null)) { // Delete action if (Delete) { // Delete document pnlDelete.Visible = true; titleElem.TitleText = GetString("Content.DeleteTitle"); chkAllCultures.Text = GetString("ContentDelete.AllCultures"); chkDestroy.Text = GetString("ContentDelete.Destroy"); lblQuestion.Text = GetString("ContentDelete.Question"); btnYes.Text = GetString("general.yes"); // Prevent button double-click btnYes.Attributes.Add("onclick", string.Format("document.getElementById('{0}').disabled=true;this.disabled=true;{1};", btnNo.ClientID, ControlsHelper.GetPostBackEventReference(btnYes, string.Empty, true, false))); btnNo.Text = GetString("general.no"); DataSet culturesDS = CultureSiteInfoProvider.GetSiteCultures(SiteName); if ((DataHelper.DataSourceIsEmpty(culturesDS)) || (culturesDS.Tables[0].Rows.Count <= 1)) { chkAllCultures.Visible = false; chkAllCultures.Checked = true; } if (Node.IsLink) { titleElem.TitleText = GetString("Content.DeleteTitleLink") + " \"" + HTMLHelper.HTMLEncode(Node.NodeName) + "\""; lblQuestion.Text = GetString("ContentDelete.QuestionLink"); chkAllCultures.Checked = true; plcCheck.Visible = false; } else { titleElem.TitleText = GetString("Content.DeleteTitle") + " \"" + HTMLHelper.HTMLEncode(Node.NodeName) + "\""; } } // New document or edit action else { if (NewDocument) { titleElem.TitleText = GetString("Content.NewTitle"); } // Document type selection if (NewDocument && (ClassID <= 0)) { // Use parent node TreeNode parentNode = DocumentManager.ParentNode; if (parentNode != null) { // Select document type pnlSelectClass.Visible = true; // Apply document type scope string whereCondition = DocumentTypeScopeInfoProvider.GetScopeClassWhereCondition(parentNode); var parentClassId = ValidationHelper.GetInteger(parentNode.GetValue("NodeClassID"), 0); var siteId = SiteInfoProvider.GetSiteID(SiteName); // Get the allowed child classes DataSet ds = AllowedChildClassInfoProvider.GetAllowedChildClasses(parentClassId, siteId) .Where(whereCondition) .OrderBy("ClassID") .Columns("ClassName", "ClassDisplayName", "ClassID"); ArrayList deleteRows = new ArrayList(); if (!DataHelper.DataSourceIsEmpty(ds)) { // Get the unwanted classes string allowed = AllowedChildClasses.Trim().ToLowerCSafe(); if (!string.IsNullOrEmpty(allowed)) { allowed = String.Format(";{0};", allowed); } var userInfo = MembershipContext.AuthenticatedUser; string className = null; // Check if the user has 'Create' permission per Content bool isAuthorizedToCreateInContent = userInfo.IsAuthorizedPerResource("CMS.Content", "Create"); bool hasNodeAllowCreate = (userInfo.IsAuthorizedPerTreeNode(parentNode, NodePermissionsEnum.Create) != AuthorizationResultEnum.Allowed); foreach (DataRow dr in ds.Tables[0].Rows) { className = ValidationHelper.GetString(DataHelper.GetDataRowValue(dr, "ClassName"), String.Empty).ToLowerCSafe(); // Document type is not allowed or user hasn't got permission, remove it from the data set if ((!string.IsNullOrEmpty(allowed) && (!allowed.Contains(";" + className + ";"))) || (CheckPermissions && CheckDocPermissionsForInsert && !isAuthorizedToCreateInContent && !userInfo.IsAuthorizedPerClassName(className, "Create") && (!userInfo.IsAuthorizedPerClassName(className, "CreateSpecific") || !hasNodeAllowCreate))) { deleteRows.Add(dr); } } // Remove the rows foreach (DataRow dr in deleteRows) { ds.Tables[0].Rows.Remove(dr); } } // Check if some classes are available if (!DataHelper.DataSourceIsEmpty(ds)) { // If number of classes is more than 1 display them in grid if (ds.Tables[0].Rows.Count > 1) { ds.Tables[0].DefaultView.Sort = "ClassDisplayName"; lblError.Visible = false; lblInfo.Visible = true; lblInfo.Text = GetString("Content.NewInfo"); DataSet sortedResult = new DataSet(); sortedResult.Tables.Add(ds.Tables[0].DefaultView.ToTable()); gridClass.DataSource = sortedResult; gridClass.ReloadData(); } // else show form of the only class else { ClassID = ValidationHelper.GetInteger(DataHelper.GetDataRowValue(ds.Tables[0].Rows[0], "ClassID"), 0); ReloadData(true); return; } } else { // Display error message lblError.Visible = true; lblError.Text = GetString("Content.NoAllowedChildDocuments"); lblInfo.Visible = false; gridClass.Visible = false; } } else { pnlInfo.Visible = true; lblFormInfo.Text = GetString("EditForm.DocumentNotFound"); } } // Insert or update of a document else { // Display the form pnlEdit.Visible = true; // Try to get GroupID if group context exists int currentGroupId = ModuleCommands.CommunityGetCurrentGroupID(); btnDelete.Attributes.Add("style", "display: none;"); btnRefresh.Attributes.Add("style", "display: none;"); // CMSForm initialization formElem.NodeID = Node.NodeID; formElem.SiteName = SiteName; formElem.CultureCode = CultureCode; formElem.ValidationErrorMessage = ValidationErrorMessage; formElem.IsLiveSite = IsLiveSite; // Set group ID if group context exists formElem.GroupID = currentGroupId; // External editing is allowed for live site only if the permissions are checked or user is global administrator or for group context - user is group administrator formElem.AllowExternalEditing = !IsLiveSite || CheckPermissions || MembershipContext.AuthenticatedUser.IsGlobalAdministrator || MembershipContext.AuthenticatedUser.IsGroupAdministrator(currentGroupId); // Set the form mode if (NewDocument) { ci = DataClassInfoProvider.GetDataClassInfo(ClassID); if (ci == null) { throw new Exception(String.Format("[CMSAdminControls/EditForm.aspx]: Class ID '{0}' not found.", ClassID)); } string classDisplayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ci.ClassDisplayName)); titleElem.TitleText = GetString("Content.NewTitle") + ": " + classDisplayName; // Set default template ID formElem.DefaultPageTemplateID = TemplateID > 0 ? TemplateID : ci.ClassDefaultPageTemplateID; // Set document owner formElem.OwnerID = OwnerID; formElem.FormMode = FormModeEnum.Insert; string newClassName = ci.ClassName; string newFormName = newClassName + ".default"; if (!String.IsNullOrEmpty(AlternativeFormName)) { // Set the alternative form full name formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName); } if (newFormName.ToLowerCSafe() != formElem.FormName.ToLowerCSafe()) { formElem.FormName = newFormName; } } else if (NewCulture) { formElem.FormMode = FormModeEnum.InsertNewCultureVersion; // Default data document ID formElem.CopyDefaultDataFromDocumentId = CopyDefaultDataFromDocumentID; ci = DataClassInfoProvider.GetDataClassInfo(Node.NodeClassName); formElem.FormName = Node.NodeClassName + ".default"; if (!String.IsNullOrEmpty(AlternativeFormName)) { // Set the alternative form full name formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName); } } else { formElem.FormMode = FormModeEnum.Update; ci = DataClassInfoProvider.GetDataClassInfo(Node.NodeClassName); formElem.FormName = String.Empty; if (!String.IsNullOrEmpty(AlternativeFormName)) { // Set the alternative form full name formElem.AlternativeFormFullName = GetAltFormFullName(ci.ClassName); } } // Allow the CMSForm formElem.StopProcessing = false; ReloadForm(); formElem.LoadForm(true); } } } // New culture version else { // Switch to new culture version mode DocumentManager.Mode = FormModeEnum.InsertNewCultureVersion; DocumentManager.NodeID = NodeID; DocumentManager.CultureCode = CultureCode; DocumentManager.SiteName = SiteName; if (Node != null) { // Offer a new culture creation pnlNewCulture.Visible = true; titleElem.TitleText = GetString("Content.NewCultureVersionTitle") + " (" + HTMLHelper.HTMLEncode(MembershipContext.AuthenticatedUser.PreferredCultureCode) + ")"; lblNewCultureInfo.Text = GetString("ContentNewCultureVersion.Info"); radCopy.Text = GetString("ContentNewCultureVersion.Copy"); radEmpty.Text = GetString("ContentNewCultureVersion.Empty"); radCopy.Attributes.Add("onclick", "ShowSelection();"); radEmpty.Attributes.Add("onclick", "ShowSelection()"); AddScript( "function ShowSelection() { \n" + " if (document.getElementById('" + radCopy.ClientID + "').checked) { document.getElementById('divCultures').style.display = 'block'; } \n" + " else { document.getElementById('divCultures').style.display = 'none'; } \n" + "} \n" ); btnOk.Text = GetString("ContentNewCultureVersion.Create"); // Load culture versions SiteInfo si = SiteInfoProvider.GetSiteInfo(Node.NodeSiteID); if (si != null) { lstCultures.Items.Clear(); DataSet nodes = TreeProvider.SelectNodes(si.SiteName, Node.NodeAliasPath, TreeProvider.ALL_CULTURES, false, null, null, null, 1, false); foreach (DataRow nodeCulture in nodes.Tables[0].Rows) { ListItem li = new ListItem(); li.Text = CultureInfoProvider.GetCultureInfo(nodeCulture["DocumentCulture"].ToString()).CultureName; li.Value = nodeCulture["DocumentID"].ToString(); lstCultures.Items.Add(li); } if (lstCultures.Items.Count > 0) { lstCultures.SelectedIndex = 0; } } } else { pnlInfo.Visible = true; lblFormInfo.Text = GetString("EditForm.DocumentNotFound"); } } } // Set flag that the form is loaded mFormLoaded = true; } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (StopProcessing) { // Do nothing } else { if (!String.IsNullOrEmpty(TransformationName)) { repLatestPosts.ItemTemplate = TransformationHelper.LoadTransformation(this, TransformationName); repLatestPosts.HideControlForZeroRows = HideControlForZeroRows; repLatestPosts.ZeroRowsText = ZeroRowsText; // Set data source groupid according to group name if (!String.IsNullOrEmpty(GroupName)) { if (GroupName == PredefinedObjectType.COMMUNITY_CURRENT_GROUP) { forumDataSource.GroupID = ModuleCommands.CommunityGetCurrentGroupID(); } else { GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfoByName(GroupName, SiteName); if (gi != null) { forumDataSource.GroupID = ValidationHelper.GetInteger(gi.GetValue("GroupID"), 0); } else { forumDataSource.StopProcessing = true; } } } if (!forumDataSource.StopProcessing) { forumDataSource.TopN = SelectTopN; forumDataSource.OrderBy = "PostThreadLastPostTime DESC"; forumDataSource.CacheItemName = CacheItemName; forumDataSource.CacheDependencies = CacheDependencies; forumDataSource.CacheMinutes = CacheMinutes; forumDataSource.SelectOnlyApproved = false; forumDataSource.SiteName = SiteName; forumDataSource.ShowGroupPosts = ShowGroupPosts && String.IsNullOrEmpty(ForumGroups); forumDataSource.SelectedColumns = Columns; #region "Complete where condition" string where = ""; // Get groups part of where condition string[] groups = ForumGroups.Split(';'); foreach (string group in groups) { if (group != "") { if (where != "") { where += " OR "; } where += "(GroupName = N'" + SqlHelper.GetSafeQueryString(group, false) + "')"; } } where = "(" + (where == "" ? "(GroupName NOT LIKE 'AdHoc%')" : "(" + where + ")") + " AND (PostLevel = 0))"; // Append where condition and set PostLevel to 0 (only threads are needed) // and filter out AdHoc forums if (!String.IsNullOrEmpty(WhereCondition)) { where += " AND (" + WhereCondition + ")"; } #endregion forumDataSource.WhereCondition = where; forumDataSource.CheckPermissions = true; repLatestPosts.DataSourceControl = forumDataSource; repLatestPosts.DataBind(); } } } }
/// <summary> /// Initializes the control properties. /// </summary> protected void SetupControl() { if (this.StopProcessing) { // Do nothing } else { if (!String.IsNullOrEmpty(this.TransformationName)) { this.repMostActiveThread.ItemTemplate = CMSDataProperties.LoadTransformation(this, this.TransformationName, false); this.repMostActiveThread.HideControlForZeroRows = this.HideControlForZeroRows; this.repMostActiveThread.ZeroRowsText = this.ZeroRowsText; // Set data source groupid according to group name if (!String.IsNullOrEmpty(this.GroupName)) { if (this.GroupName == CMSConstants.COMMUNITY_CURRENT_GROUP) { this.forumDataSource.GroupID = ModuleCommands.CommunityGetCurrentGroupID(); } else { GeneralizedInfo gi = ModuleCommands.CommunityGetGroupInfoByName(this.GroupName, this.SiteName); if (gi != null) { this.forumDataSource.GroupID = ValidationHelper.GetInteger(gi.GetValue("GroupID"), 0); } else { forumDataSource.StopProcessing = true; } } } if (!forumDataSource.StopProcessing) { this.forumDataSource.TopN = this.SelectTopN; this.forumDataSource.OrderBy = "PostThreadPosts DESC"; this.forumDataSource.CacheItemName = this.CacheItemName; this.forumDataSource.CacheDependencies = this.CacheDependencies; this.forumDataSource.CacheMinutes = this.CacheMinutes; this.forumDataSource.FilterName = ValidationHelper.GetString(this.GetValue("WebPartControlID"), this.ClientID); this.forumDataSource.SelectOnlyApproved = false; this.forumDataSource.SiteName = this.SiteName; this.forumDataSource.ShowGroupPosts = this.ShowGroupPosts && String.IsNullOrEmpty(ForumGroups); #region "Complete where condition" string where = ""; // Get groups part of where condition string[] groups = this.ForumGroups.Split(';'); foreach (string group in groups) { if (group != "") { if (where != "") { where += " OR "; } where += "(GroupName = N'" + SqlHelperClass.GetSafeQueryString(group, false) + "')"; } } where = "(" + (where == "" ? "(GroupName NOT LIKE 'AdHoc%')" : "(" + where + ")") + " AND (PostLevel = 0))"; // Append where condition and set PostLevel to 0 (only threads are needed) // and filter out AdHoc forums if (!String.IsNullOrEmpty(this.WhereCondition)) { where += " AND (" + this.WhereCondition + ")"; } #endregion this.forumDataSource.WhereCondition = where; this.forumDataSource.CheckPermissions = true; this.repMostActiveThread.DataSource = this.forumDataSource.DataSource; if (!DataHelper.DataSourceIsEmpty(this.repMostActiveThread.DataSource)) { this.repMostActiveThread.DataBind(); } } } } }