protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterDialogScript(this.Page); ScriptHelper.RegisterApplicationConstants(this.Page); // Get the object type string param = this.ContextMenu.Parameter; string objectType = null; bool groupObject = false; if (param != null) { string[] parms = param.Split(';'); objectType = parms[0]; if (parms.Length == 2) { groupObject = ValidationHelper.GetBoolean(parms[1], false); } } // Get empty info GeneralizedInfo obj = null; if (objectType != null) { obj = CMSObjectHelper.GetReadOnlyObject(objectType); // Get correct info for listings if (obj.TypeInfo.Inherited) { obj = CMSObjectHelper.GetReadOnlyObject(obj.TypeInfo.OriginalObjectType); } obj.ObjectGroupID = groupObject ? 1 : 0; } if (obj == null) { this.Visible = false; return; } CurrentUserInfo curUser = CMSContext.CurrentUser; string curSiteName = CMSContext.CurrentSiteName; string menuId = this.ContextMenu.MenuID; // Relationships if (obj.TypeInfo.HasObjectRelationships) { this.iRelationships.ImageUrl = UIHelper.GetImageUrl(this.Page, "Design/Controls/UniGrid/Actions/Relationships.png"); this.iRelationships.Text = ResHelper.GetString("General.Relationships"); this.iRelationships.Attributes.Add("onclick", "ContextRelationships(GetContextMenuParameter('" + menuId + "'));"); } else { this.iRelationships.Visible = false; } // Export if (obj.TypeInfo.AllowSingleExport) { if (curUser.IsAuthorizedPerResource("cms.globalpermissions", "ExportObjects", curSiteName)) { this.iExport.ImageUrl = UIHelper.GetImageUrl(this.Page, "Design/Controls/UniGrid/Actions/ExportObject.png"); this.iExport.Text = ResHelper.GetString("General.Export"); this.iExport.Attributes.Add("onclick", "ContextExportObject(GetContextMenuParameter('" + menuId + "'), false);"); } else { this.iExport.Visible = false; } if (obj.GUIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN) { if (curUser.IsAuthorizedPerResource("cms.globalpermissions", "BackupObjects", curSiteName)) { this.iBackup.ImageUrl = UIHelper.GetImageUrl(this.Page, "Design/Controls/UniGrid/Actions/BackupObject.png"); this.iBackup.Text = ResHelper.GetString("General.Backup"); this.iBackup.Attributes.Add("onclick", "ContextExportObject(GetContextMenuParameter('" + menuId + "'), true);"); } else { this.iBackup.Visible = false; } if (curUser.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects", curSiteName)) { this.iRestore.ImageUrl = UIHelper.GetImageUrl(this.Page, "Design/Controls/UniGrid/Actions/RestoreObject.png"); this.iRestore.Text = ResHelper.GetString("General.Restore"); this.iRestore.Attributes.Add("onclick", "ContextRestoreObject(GetContextMenuParameter('" + menuId + "'), true);"); } else { this.iRestore.Visible = false; } } else { this.iBackup.Visible = false; this.iRestore.Visible = false; } } else { this.iExport.Visible = false; this.iBackup.Visible = false; this.iRestore.Visible = false; } // Versioning if (obj.AllowRestore && UniGridFunctions.ObjectSupportsDestroy(obj) && curUser.IsAuthorizedPerObject(PermissionsEnum.Destroy, obj.TypeInfo.OriginalObjectType, curSiteName)) { iDestroy.ImageUrl = UIHelper.GetImageUrl(Page, "Design/Controls/UniGrid/Actions/Delete.png"); iDestroy.Text = ResHelper.GetString("security.destroy"); iDestroy.Attributes.Add("onclick", "ContextDestroyObject_" + ClientID + "(GetContextMenuParameter('" + menuId + "'))"); } else { iDestroy.Visible = false; } bool ancestor = iRelationships.Visible; sep1.Visible = iExport.Visible && ancestor; ancestor |= iExport.Visible; sep2.Visible = (iBackup.Visible || iRestore.Visible) && ancestor; ancestor |= (iBackup.Visible || iRestore.Visible); sep3.Visible = iDestroy.Visible && ancestor; this.Visible = iRelationships.Visible || iExport.Visible || iBackup.Visible || iDestroy.Visible; if (Visible) { StringBuilder sb = new StringBuilder(); sb.Append(@" function ContextRelationships(definition) { var url = applicationUrl + 'CMSModules/AdminControls/Pages/ObjectRelationships.aspx?objecttype=' + escape(definition[0]) + '&objectid=' + escape(definition[1]); modalDialog(url, ""relationships"", 900, 600); } function ContextExportObject(definition, backup) { var query = ''; if (backup) { query += '&backup=true'; } modalDialog(applicationUrl + 'CMSModules/ImportExport/SiteManager/ExportObject.aspx?objectType=' + escape(definition[0]) + '&objectId=' + definition[1] + query, 'ExportObject', 750, 200); } function ContextRestoreObject(definition, backup) { var query = ''; if (backup) { query += '&backup=true'; } modalDialog(applicationUrl + 'CMSModules/ImportExport/SiteManager/RestoreObject.aspx?objectType=' + escape(definition[0]) + '&objectId=' + definition[1] + query, 'RestoreObject', 750, 350); }"); // Register general export scripts ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ObjectMenuExportScripts", sb.ToString(), true); sb = new StringBuilder(); sb.Append(@" function ContextDestroyObject_", ClientID, @"(definition) { if(confirm('", ResHelper.GetString("objectversioning.destroyobjectconfirmation"), @"')) { if(UG_DestroyObj_", ContextMenu.ParentElementClientID, @") { var param = definition.toString().split(','); if((param != null) && (param.length == 2)) { UG_DestroyObj_", ContextMenu.ParentElementClientID, @"(param[1]); } } } }"); // Register destroy script for particular menu ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "ObjectMenuDestroyScript_" + ClientID, sb.ToString(), true); } }
/// <summary> /// Empties recycle bin. /// </summary> private void EmptyBin(object parameter) { // Begin log AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", currentCulture)); BinSettingsContainer settings = (BinSettingsContainer)parameter; CurrentUserInfo currentUserInfo = settings.User; SiteInfo currentSite = settings.Site; DataSet recycleBin = null; string where = IsSingleSite ? "VersionObjectSiteID IS NULL" : null; switch (settings.CurrentWhat) { case What.AllObjects: if (currentSite != null) { where = SqlHelper.AddWhereCondition(where, "VersionObjectSiteID = " + currentSite.SiteID, "OR"); } where = GetWhereCondition(where); where = SqlHelper.AddWhereCondition(where, filter.WhereCondition); break; case What.SelectedObjects: List <string> toRestore = ugRecycleBin.SelectedItems; // Restore selected objects if (toRestore.Count > 0) { where = SqlHelper.GetWhereCondition("VersionID", toRestore); } break; } recycleBin = ObjectVersionHistoryInfoProvider.GetRecycleBin(where, null, -1, "VersionID, VersionObjectType, VersionObjectID, VersionObjectDisplayName, VersionObjectSiteID"); try { if (!DataHelper.DataSourceIsEmpty(recycleBin)) { foreach (DataRow dr in recycleBin.Tables[0].Rows) { int versionHistoryId = Convert.ToInt32(dr["VersionID"]); string versionObjType = Convert.ToString(dr["VersionObjectType"]); string objName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(dr["VersionObjectDisplayName"], string.Empty))); string siteName = null; if (currentSite != null) { siteName = currentSite.SiteName; } else { int siteId = ValidationHelper.GetInteger(dr["VersionObjectSiteID"], 0); siteName = SiteInfoProvider.GetSiteName(siteId); } // Check permissions if (!currentUserInfo.IsAuthorizedPerObject(PermissionsEnum.Destroy, versionObjType, siteName)) { CurrentError = String.Format(ResHelper.GetString("objectversioning.Recyclebin.DestructionFailedPermissions", currentCulture), objName); AddLog(CurrentError); } else { AddLog(ResHelper.GetString("general.object", currentCulture) + " '" + objName + "'"); // Destroy the version int versionObjId = ValidationHelper.GetInteger(dr["VersionObjectID"], 0); ObjectVersionManager.DestroyObjectHistory(versionObjType, versionObjId); LogContext.LogEvent(EventType.INFORMATION, "Objects", "DESTROYOBJECT", ResHelper.GetString("objectversioning.Recyclebin.objectdestroyed"), RequestContext.RawURL, currentUserInfo.UserID, currentUserInfo.UserName, 0, null, RequestContext.UserHostAddress, (currentSite != null) ? currentSite.SiteID : 0, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now); } } if (!String.IsNullOrEmpty(CurrentError)) { CurrentError = ResHelper.GetString("objectversioning.recyclebin.errorsomenotdestroyed", currentCulture); AddLog(CurrentError); } else { CurrentInfo = ResHelper.GetString("ObjectVersioning.Recyclebin.DestroyOK", currentCulture); AddLog(CurrentInfo); } } } catch (ThreadAbortException ex) { string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty); if (state != CMSThread.ABORT_REASON_STOP) { // Log error CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", currentCulture); AddLog(CurrentError); // Log to event log LogException("EMPTYINGBIN", ex); } } catch (Exception ex) { // Log error CurrentError = "Error occurred: " + ResHelper.GetString("general.seeeventlog", currentCulture); AddLog(CurrentError); // Log to event log LogException("EMPTYINGBIN", ex); } }
protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterDialogScript(Page); ScriptHelper.RegisterApplicationConstants(Page); // Get the object type string param = ContextMenu.Parameter; string objectType = null; bool groupObject = false; if (param != null) { string[] parms = param.Split(';'); objectType = parms[0]; if (parms.Length == 2) { groupObject = ValidationHelper.GetBoolean(parms[1], false); } } // Get empty info GeneralizedInfo obj = null; if (objectType != null) { obj = CMSObjectHelper.GetReadOnlyObject(objectType); // Get correct info for listings if (obj.TypeInfo.Inherited) { obj = CMSObjectHelper.GetReadOnlyObject(obj.TypeInfo.OriginalObjectType); } } if (obj == null) { Visible = false; return; } CurrentUserInfo curUser = CMSContext.CurrentUser; string curSiteName = CMSContext.CurrentSiteName; string menuId = ContextMenu.MenuID; // Relationships if (obj.TypeInfo.HasObjectRelationships) { iRelationships.ImageUrl = UIHelper.GetImageUrl(Page, "Design/Controls/UniGrid/Actions/Relationships.png"); iRelationships.Text = ResHelper.GetString("General.Relationships"); iRelationships.Attributes.Add("onclick", "ContextRelationships(GetContextMenuParameter('" + menuId + "'));"); } else { iRelationships.Visible = false; } // Export if (obj.TypeInfo.AllowSingleExport) { if (curUser.IsAuthorizedPerResource("cms.globalpermissions", "ExportObjects", curSiteName)) { iExport.ImageUrl = UIHelper.GetImageUrl(Page, "Design/Controls/UniGrid/Actions/ExportObject.png"); iExport.Text = ResHelper.GetString("General.Export"); iExport.Attributes.Add("onclick", "ContextExportObject(GetContextMenuParameter('" + menuId + "'), false);"); } else { iExport.Visible = false; } if (obj.GUIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN) { if (curUser.IsAuthorizedPerResource("cms.globalpermissions", "BackupObjects", curSiteName)) { iBackup.ImageUrl = UIHelper.GetImageUrl(Page, "Design/Controls/UniGrid/Actions/BackupObject.png"); iBackup.Text = ResHelper.GetString("General.Backup"); iBackup.Attributes.Add("onclick", "ContextExportObject(GetContextMenuParameter('" + menuId + "'), true);"); } else { iBackup.Visible = false; } if (curUser.IsAuthorizedPerResource("cms.globalpermissions", "RestoreObjects", curSiteName)) { iRestore.ImageUrl = UIHelper.GetImageUrl(Page, "Design/Controls/UniGrid/Actions/RestoreObject.png"); iRestore.Text = ResHelper.GetString("General.Restore"); iRestore.Attributes.Add("onclick", "ContextRestoreObject(GetContextMenuParameter('" + menuId + "'), true);"); } else { iRestore.Visible = false; } } else { iBackup.Visible = false; iRestore.Visible = false; } } else { iExport.Visible = false; iBackup.Visible = false; iRestore.Visible = false; } // Versioning if (obj.AllowRestore && UniGridFunctions.ObjectSupportsDestroy(obj) && curUser.IsAuthorizedPerObject(PermissionsEnum.Destroy, obj.ObjectType, curSiteName)) { iDestroy.ImageUrl = UIHelper.GetImageUrl(Page, "Design/Controls/UniGrid/Actions/Delete.png"); iDestroy.Text = ResHelper.GetString("security.destroy"); iDestroy.Attributes.Add("onclick", "ContextDestroyObject_" + ClientID + "(GetContextMenuParameter('" + menuId + "'))"); } else { iDestroy.Visible = false; } // Clonning if (obj.AllowClone) { iClone.ImageUrl = UIHelper.GetImageUrl(Page, "Design/Controls/UniGrid/Actions/Clone.png"); iClone.Text = ResHelper.GetString("general.clone"); iClone.Attributes.Add("onclick", "ContextCloneObject" + "(GetContextMenuParameter('" + menuId + "'))"); } else { iClone.Visible = false; } bool ancestor = iRelationships.Visible; sep1.Visible = (iClone.Visible || iDestroy.Visible) && ancestor; ancestor |= (iClone.Visible || iDestroy.Visible); sep2.Visible = (iBackup.Visible || iRestore.Visible || iExport.Visible) && ancestor; Visible = iRelationships.Visible || iExport.Visible || iBackup.Visible || iDestroy.Visible || iClone.Visible; }