/// <summary> /// Page_Load runs when the control is loaded /// </summary> /// <remarks> /// </remarks> protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { if (Null.IsNull(ProfileUserId)) { Visible = false; return; } var template = Convert.ToString(ModuleContext.Settings["ProfileTemplate"]); if (string.IsNullOrEmpty(template)) { template = Localization.GetString("DefaultTemplate", LocalResourceFile); } var editUrl = Globals.NavigateURL(ModuleContext.PortalSettings.ActiveTab.TabID, "Profile", "userId=" + ProfileUserId, "pageno=1"); var profileUrl = Globals.NavigateURL(ModuleContext.PortalSettings.ActiveTab.TabID, "Profile", "userId=" + ProfileUserId, "pageno=2"); if (template.Contains("[BUTTON:EDITPROFILE]")) { if (IncludeButton && IsUser) { string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnPrimaryAction\">{1}</a>", profileUrl, LocalizeString("Edit")); template = template.Replace("[BUTTON:EDITPROFILE]", editHyperLink); } buttonPanel.Visible = false; } else { buttonPanel.Visible = IncludeButton; editLink.NavigateUrl = editUrl; } if (template.Contains("[HYPERLINK:EDITPROFILE]")) { if (IsUser) { string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnSecondaryAction\">{1}</a>", profileUrl, LocalizeString("Edit")); template = template.Replace("[HYPERLINK:EDITPROFILE]", editHyperLink); } } if (template.Contains("[HYPERLINK:MYACCOUNT]")) { if (IsUser) { string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnSecondaryAction\">{1}</a>", editUrl, LocalizeString("MyAccount")); template = template.Replace("[HYPERLINK:MYACCOUNT]", editHyperLink); } buttonPanel.Visible = false; } if (!IsUser && buttonPanel.Visible) { buttonPanel.Visible = false; } if (ProfileUser.Profile.ProfileProperties.Cast <ProfilePropertyDefinition>().Count(profProperty => profProperty.Visible) == 0) { noPropertiesLabel.Visible = true; profileOutput.Visible = false; } else { var token = new TokenReplace { User = ProfileUser, AccessingUser = ModuleContext.PortalSettings.UserInfo }; profileOutput.InnerHtml = token.ReplaceEnvironmentTokens(template); noPropertiesLabel.Visible = false; profileOutput.Visible = true; } var propertyAccess = new ProfilePropertyAccess(ProfileUser); var profileResourceFile = "~/DesktopModules/Admin/Security/App_LocalResources/Profile.ascx"; StringBuilder sb = new StringBuilder(); bool propertyNotFound = false; var dataType = new ListController().GetListEntryInfo("DataType", "RichText"); foreach (ProfilePropertyDefinition property in ProfileUser.Profile.ProfileProperties) { string value = propertyAccess.GetProperty(property.PropertyName, String.Empty, Thread.CurrentThread.CurrentUICulture, ModuleContext.PortalSettings.UserInfo, Scope.DefaultSettings, ref propertyNotFound); var clientName = Localization.GetSafeJSString(property.PropertyName); sb.Append("self['" + clientName + "'] = ko.observable("); sb.Append("\""); value = Localization.GetSafeJSString(Server.HtmlDecode(value)); if (property.DataType == dataType.EntryID) { value = value.Replace("\r", string.Empty).Replace("\n", string.Empty); } sb.Append(value + "\"" + ");"); sb.Append('\n'); sb.Append("self['" + clientName + "Text'] = '"); sb.Append(clientName + "';"); sb.Append('\n'); } string email = (ProfileUserId == ModuleContext.PortalSettings.UserId || ModuleContext.PortalSettings.UserInfo.IsInRole(ModuleContext.PortalSettings.AdministratorRoleName)) ? ProfileUser.Email : String.Empty; sb.Append("self.Email = ko.observable('"); sb.Append(email + "');"); sb.Append('\n'); sb.Append("self.EmailText = '"); sb.Append(LocalizeString("Email") + "';"); sb.Append('\n'); ProfileProperties = sb.ToString(); } catch (Exception exc) { //Module failed to load Exceptions.ProcessModuleLoadException(this, exc); } }
public override void RenderValuesToHtmlInsideDataSet(DataSet ds, int moduleId, bool noScript) { var fields = new ArrayList(); //List of columns that contains eMail addresses var tableData = ds.Tables[DataSetTableName.Data]; var tokenReplace = new TokenReplace { ModuleId = moduleId }; foreach (DataRow row in ds.Tables[DataSetTableName.Fields].Rows) { if (row[FieldsTableColumn.Type].ToString() == Name) { var fieldId = (int)row[FieldsTableColumn.Id]; var field = new FieldSetting { Title = row[FieldsTableColumn.Title].ToString(), OutputFormat = row[FieldsTableColumn.OutputSettings].AsString(), AsLink = !GetFieldSetting("NoLink", fieldId, ds).AsBoolean() }; fields.Add(field); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Original, typeof(string))); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Caption, typeof(string))); } } if (fields.Count > 0) { foreach (DataRow row in tableData.Rows) { foreach (FieldSetting field in fields) { //Link shown to the user //Link readable by browsers var strUrl = row[field.Title].ToString().Trim(); //strip optional parameter like subject or body for display: var strLink = strUrl.IndexOf("?", System.StringComparison.Ordinal) != -1 ? strUrl.Substring(0, strUrl.IndexOf("?", System.StringComparison.Ordinal)) : strUrl; if (strLink != string.Empty) { var strCaption = field.OutputFormat; if (!string.IsNullOrEmpty(strCaption)) { strCaption = string.Format(tokenReplace.ReplaceEnvironmentTokens(strCaption, row), strLink); } else { strCaption = strLink; } string strFieldvalue; if (strCaption != string.Empty && field.AsLink) { strFieldvalue = string.Format("<a href=\"mailto:{0}\">{1}</a>", HttpUtility.UrlEncode(strUrl), strCaption); } else { strFieldvalue = strLink; } row[field.Title] = noScript ? strFieldvalue : (Globals.CloakText(strFieldvalue)); row[field.Title + DataTableColumn.Appendix_Caption] = strCaption; row[field.Title + DataTableColumn.Appendix_Original] = strUrl; } } } } }
/// <summary>Send bulkmail to all recipients according to settings</summary> /// <returns>Number of emails sent, null.integer if not determinable</returns> /// <remarks>Detailed status report is sent by email to sending user</remarks> public int SendMails() { EnsureNotDisposed(); int recipients = 0; int messagesSent = 0; int errors = 0; try { //send to recipients string body = _body; if (BodyFormat == MailFormat.Html) //Add Base Href for any images inserted in to the email. { var host = PortalAlias.Contains("/") ? PortalAlias.Substring(0, PortalAlias.IndexOf('/')) : PortalAlias; body = "<html><head><base href='http://" + host + "'><title>" + Subject + "</title></head><body>" + body + "</body></html>"; } string subject = Subject; string startedAt = DateTime.Now.ToString(CultureInfo.InvariantCulture); bool replaceTokens = !SuppressTokenReplace && (_tokenReplace.ContainsTokens(Subject) || _tokenReplace.ContainsTokens(_body)); bool individualSubj = false; bool individualBody = false; var mailErrors = new StringBuilder(); var mailRecipients = new StringBuilder(); switch (AddressMethod) { case AddressMethods.Send_TO: case AddressMethods.Send_Relay: //optimization: if (replaceTokens) { individualBody = (_tokenReplace.Cacheability(_body) == CacheLevel.notCacheable); individualSubj = (_tokenReplace.Cacheability(Subject) == CacheLevel.notCacheable); if (!individualBody) { body = _tokenReplace.ReplaceEnvironmentTokens(body); } if (!individualSubj) { subject = _tokenReplace.ReplaceEnvironmentTokens(subject); } } foreach (UserInfo user in Recipients()) { recipients += 1; if (individualBody || individualSubj) { _tokenReplace.User = user; _tokenReplace.AccessingUser = user; if (individualBody) { body = _tokenReplace.ReplaceEnvironmentTokens(_body); } if (individualSubj) { subject = _tokenReplace.ReplaceEnvironmentTokens(Subject); } } string recipient = AddressMethod == AddressMethods.Send_TO ? user.Email : RelayEmailAddress; string mailError = Mail.SendMail(_sendingUser.Email, recipient, "", "", ReplyTo.Email, Priority, subject, BodyFormat, Encoding.UTF8, body, LoadAttachments(), _smtpServer, _smtpAuthenticationMethod, _smtpUsername, _smtpPassword, _smtpEnableSSL); if (!string.IsNullOrEmpty(mailError)) { mailErrors.Append(mailError); mailErrors.AppendLine(); errors += 1; } else { mailRecipients.Append(user.Email); mailRecipients.Append(BodyFormat == MailFormat.Html ? "<br />" : Environment.NewLine); messagesSent += 1; } } break; case AddressMethods.Send_BCC: var distributionList = new StringBuilder(); messagesSent = Null.NullInteger; foreach (UserInfo user in Recipients()) { recipients += 1; distributionList.Append(user.Email + "; "); mailRecipients.Append(user.Email); mailRecipients.Append(BodyFormat == MailFormat.Html ? "<br />" : Environment.NewLine); } if (distributionList.Length > 2) { if (replaceTokens) { //no access to User properties possible! var tr = new TokenReplace(Scope.Configuration); body = tr.ReplaceEnvironmentTokens(_body); subject = tr.ReplaceEnvironmentTokens(Subject); } else { body = _body; subject = Subject; } string mailError = Mail.SendMail(_sendingUser.Email, _sendingUser.Email, "", distributionList.ToString(0, distributionList.Length - 2), ReplyTo.Email, Priority, subject, BodyFormat, Encoding.UTF8, body, LoadAttachments(), _smtpServer, _smtpAuthenticationMethod, _smtpUsername, _smtpPassword, _smtpEnableSSL); if (mailError == string.Empty) { messagesSent = 1; } else { mailErrors.Append(mailError); errors += 1; } } break; } if (mailErrors.Length > 0) { mailRecipients = new StringBuilder(); } SendConfirmationMail(recipients, messagesSent, errors, subject, startedAt, mailErrors.ToString(), mailRecipients.ToString()); } catch (Exception exc) //send mail failure { Logger.Error(exc); Debug.Write(exc.Message); } finally { foreach (var attachment in _attachments) { attachment.Dispose(); } } return(messagesSent); }
protected override void Render(HtmlTextWriter writer) { if (ItemTemplate == "") { return; } writer.Write(HeaderTemplate); // Filters if (Filters == null) { Filters = new Dictionary <string, string>(); } var additionalFilters = new Dictionary <string, string>(); additionalFilters.Add("Records", PageSize.ToString()); additionalFilters.Add("PageIndex", PageIndex.ToString()); additionalFilters.Add("Rowsize", RowSize.ToString()); additionalFilters.Add("SortBy", SortBy); additionalFilters.Add("SortAscending", SortAscending.ToString()); // Currently Not Used by the SPROC var filterUser = Filters.ContainsKey("UserId") && Filters["UserId"] != null ? new UserInfo() { UserID = int.Parse(Filters["UserId"]) } : new UserInfo() { PortalID = _currentUser.PortalID }; var role = Filters.ContainsKey("RoleId") && Filters["RoleId"] != null ? new UserRoleInfo() { RoleID = int.Parse(Filters["RoleId"]) } : null; var relationship = Filters.ContainsKey("RelationshipTypeId") && Filters["RelationshipTypeId"] != null ? new RelationshipType() { RelationshipTypeId = int.Parse(Filters["RelationshipTypeId"]) } : null; foreach (var filter in Filters.Where(filter => !additionalFilters.ContainsKey(filter.Key))) { additionalFilters.Add(filter.Key, filter.Value); } var row = 0; var users = new DataTable(); //users.Load(_relationshipController.GetUsersAdvancedSearch(_currentUser, filterUser, role, relationship, Filters, additionalFilters)); if (users.Rows.Count > 0) { foreach (DataRow user in users.Rows) { //Row Header writer.Write(string.IsNullOrEmpty(AlternatingRowHeaderTemplate) || row % 2 == 0 ? RowHeaderTemplate : AlternatingRowHeaderTemplate); var tokenReplace = new TokenReplace(); var tokenKeyValues = new Dictionary <string, string>(); foreach (var col in user.Table.Columns.Cast <DataColumn>().Where(col => !tokenKeyValues.ContainsKey(col.ColumnName))) { tokenKeyValues.Add(col.ColumnName, user[col.ColumnName].ToString()); } var listItem = string.IsNullOrEmpty(AlternatingItemTemplate) || row % 2 == 0 ? ItemTemplate : AlternatingItemTemplate; listItem = tokenReplace.ReplaceEnvironmentTokens(listItem, tokenKeyValues, "Member"); writer.Write(listItem); //Row Footer writer.Write(string.IsNullOrEmpty(AlternatingRowFooterTemplate) || row % 2 == 0 ? RowFooterTemplate : AlternatingRowFooterTemplate); row++; } } writer.Write(FooterTemplate); }
public override void RenderValuesToHtmlInsideDataSet(DataSet ds, int moduleId, bool noScript) { if (ds != null) { var fields = new ArrayList(); //List of columns that contains URLs var tableData = ds.Tables[DataSetTableName.Data]; var tokenReplace = new TokenReplace { ModuleId = moduleId }; foreach (DataRow row in ds.Tables[DataSetTableName.Fields].Rows) { if (row[FieldsTableColumn.Type].ToString() == Name) { var fieldId = (int)row[FieldsTableColumn.Id]; var field = new FieldSettings { Title = row[FieldsTableColumn.Title].ToString(), OutputFormat = row[FieldsTableColumn.OutputSettings].AsString(), Abbreviate = GetFieldSetting("Abbreviate", fieldId, ds).AsBoolean(), ShowOpenInNewWindow = GetFieldSetting("ShowOpenInNewWindow", fieldId, ds).AsBoolean(), EnforceDownload = GetFieldSetting("EnforceDownload", fieldId, ds).AsBoolean() }; fields.Add(field); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Url, typeof(string))); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Caption, typeof(string))); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Original, typeof(string))); } } if (fields.Count > 0) { var portalSettings = PortalController.GetCurrentPortalSettings(); foreach (DataRow row in tableData.Rows) { foreach (FieldSettings field in fields) { var strFieldvalue = string.Empty; var strFileId = row[field.Title].ToString(); var openInNewWindow = !field.ShowOpenInNewWindow || UrlUtil.OpenUrlInNewWindow(strFileId); strFileId = UrlUtil.StripURL(strFileId); var strUrl = ""; //Link readable by browsers var strCaption = string.Empty; if (strFileId != string.Empty) { strUrl = HttpUtility.HtmlEncode(Globals.LinkClick(strFileId, portalSettings.ActiveTab.TabID, moduleId)); var fName = ""; var strDisplayName = ""; if (strFileId.Like("FileID=*")) { var f = FileManager.Instance.GetFile(int.Parse(UrlUtils.GetParameterValue(strFileId))); if (f != null) { fName = f.FileName; if (field.Abbreviate) { strDisplayName = (f.Folder + fName); } else { strDisplayName = fName; } } } else { fName = Globals.ResolveUrl(strUrl); strDisplayName = field.Abbreviate ? fName.Substring(Convert.ToInt32(fName.LastIndexOf("/", StringComparison.Ordinal) + 1)) : fName; } strCaption = field.OutputFormat; strCaption = string.IsNullOrEmpty(strCaption) ? fName : tokenReplace.ReplaceEnvironmentTokens(strCaption, row); if (field.EnforceDownload) { strUrl += "&forcedownload=true"; } strFieldvalue = string.Format("<!--{0}--><a href=\"{1}\" {2}>{3}</a>", strDisplayName, strUrl, (openInNewWindow ? " target=\"_blank\"" : ""), strCaption); } row[field.Title] = strFieldvalue; row[field.Title + DataTableColumn.Appendix_Caption] = strCaption; row[field.Title + DataTableColumn.Appendix_Original] = strFileId; row[field.Title + DataTableColumn.Appendix_Url] = strUrl; } } } } }
public override void RenderValuesToHtmlInsideDataSet(DataSet ds, int moduleId, bool noScript) { if (ds != null) { var fields = new ArrayList(); var tableData = ds.Tables[DataSetTableName.Data]; var tokenReplace = new TokenReplace { ModuleId = moduleId }; foreach (DataRow row in ds.Tables[DataSetTableName.Fields].Rows) { if (row[FieldsTableColumn.Type].ToString() == Name) { var fieldId = (int)row[FieldsTableColumn.Id]; var field = new FieldSetting { Title = row[FieldsTableColumn.Title].ToString(), TokenText = GetFieldSetting("TokenText", fieldId, ds).AsString(), ShowUserName = GetFieldSetting("ShowUserName", fieldId, ds).AsBoolean(), OpenInNewWindow = GetFieldSetting("OpenInNewWindow", fieldId, ds).AsBoolean() }; fields.Add(field); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Url, typeof(string))); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Original, typeof(string))); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Caption, typeof(string))); } } if (fields.Count > 0) { PortalSettings portalSettings = null; if (HttpContext.Current != null) { portalSettings = PortalController.GetCurrentPortalSettings(); } var mc = new ModuleController(); var settings = mc.GetModuleSettings(moduleId); foreach (DataRow row in tableData.Rows) { foreach (FieldSetting field in fields) { var strFieldvalue = string.Empty; //Link showed to the user var link = row[field.Title].ToString(); //set caption: var caption = field.TokenText; var url = string.Empty; //Link readable by browsers link = UrlUtil.StripURL(link); if (link != string.Empty) //valid link { //var isLink = true; var intUser = Convert.ToInt32(-1); if (link.Like("userid=*") && portalSettings != null) { try { intUser = int.Parse(link.Substring(7)); tokenReplace.User = new UserController().GetUser(portalSettings.PortalId, intUser); } catch { } } if (intUser == -1) { tokenReplace.User = new UserInfo { Username = "******" }; } if (caption == string.Empty) { caption = field.ShowUserName ? "[User:DisplayName]" : "[User:UserName]"; } caption = tokenReplace.ReplaceEnvironmentTokens(caption, row); if (caption == string.Empty) //DisplayName empty { caption = tokenReplace.ReplaceEnvironmentTokens("[User:username]"); } url = HttpUtility.HtmlEncode(Globals.LinkClick(link, portalSettings.ActiveTab.TabID, moduleId)); strFieldvalue = string.Format("<!--{1}--><a href=\"{0}\"{2}>{1}</a>", url, caption, (field.OpenInNewWindow ? " target=\"_blank\"" : "")); } row[field.Title] = strFieldvalue; row[field.Title + DataTableColumn.Appendix_Original] = link; row[field.Title + DataTableColumn.Appendix_Url] = url; row[field.Title + DataTableColumn.Appendix_Caption] = caption; } } } } }
/// <summary> /// Page_Load runs when the control is loaded /// </summary> /// <remarks> /// </remarks> protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { if (Null.IsNull(ProfileUserId)) { Visible = false; return; } var template = Convert.ToString(ModuleContext.Settings["ProfileTemplate"]); if (string.IsNullOrEmpty(template)) { template = Localization.GetString("DefaultTemplate", LocalResourceFile); } var editUrl = _navigationManager.NavigateURL(ModuleContext.PortalSettings.ActiveTab.TabID, "Profile", "userId=" + ProfileUserId, "pageno=1"); var profileUrl = _navigationManager.NavigateURL(ModuleContext.PortalSettings.ActiveTab.TabID, "Profile", "userId=" + ProfileUserId, "pageno=2"); if (template.Contains("[BUTTON:EDITPROFILE]")) { if (IncludeButton && IsUser) { string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnPrimaryAction\">{1}</a>", profileUrl, LocalizeString("Edit")); template = template.Replace("[BUTTON:EDITPROFILE]", editHyperLink); } buttonPanel.Visible = false; } else { buttonPanel.Visible = IncludeButton; editLink.NavigateUrl = editUrl; } if (template.Contains("[HYPERLINK:EDITPROFILE]")) { if (IsUser) { string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnSecondaryAction\">{1}</a>", profileUrl, LocalizeString("Edit")); template = template.Replace("[HYPERLINK:EDITPROFILE]", editHyperLink); } } if (template.Contains("[HYPERLINK:MYACCOUNT]")) { if (IsUser) { string editHyperLink = String.Format("<a href=\"{0}\" class=\"dnnSecondaryAction\">{1}</a>", editUrl, LocalizeString("MyAccount")); template = template.Replace("[HYPERLINK:MYACCOUNT]", editHyperLink); } buttonPanel.Visible = false; } if (!IsUser && buttonPanel.Visible) { buttonPanel.Visible = false; } if (ProfileUser.Profile.ProfileProperties.Cast <ProfilePropertyDefinition>().Count(profProperty => profProperty.Visible) == 0) { noPropertiesLabel.Visible = true; profileOutput.Visible = false; pnlScripts.Visible = false; } else { if (template.IndexOf("[PROFILE:PHOTO]") > -1) { var profileImageHandlerBasedURL = UserController.Instance?.GetUserProfilePictureUrl(ProfileUserId, 120, 120); template = template.Replace("[PROFILE:PHOTO]", profileImageHandlerBasedURL); } var token = new TokenReplace { User = ProfileUser, AccessingUser = ModuleContext.PortalSettings.UserInfo }; profileOutput.InnerHtml = token.ReplaceEnvironmentTokens(template); noPropertiesLabel.Visible = false; profileOutput.Visible = true; } var propertyAccess = new ProfilePropertyAccess(ProfileUser); StringBuilder sb = new StringBuilder(); bool propertyNotFound = false; foreach (ProfilePropertyDefinition property in ProfileUser.Profile.ProfileProperties) { var displayDataType = ProfilePropertyAccess.DisplayDataType(property).ToLowerInvariant(); string value = propertyAccess.GetProperty(property.PropertyName, String.Empty, Thread.CurrentThread.CurrentUICulture, ModuleContext.PortalSettings.UserInfo, Scope.DefaultSettings, ref propertyNotFound); var clientName = Localization.GetSafeJSString(property.PropertyName); sb.Append("self['" + clientName + "'] = ko.observable("); sb.Append("\""); if (!string.IsNullOrEmpty(value)) { value = Localization.GetSafeJSString(displayDataType == "richtext" ? value : Server.HtmlDecode(value)); value = value .Replace("\r", string.Empty) .Replace("\n", " ") .Replace(";", string.Empty) .Replace("://", ":||") //protect http protocols won't be replaced in next step .Replace("//", string.Empty) .Replace(":||", "://"); //restore http protocols } sb.Append(value + "\"" + ");"); sb.Append('\n'); sb.Append("self['" + clientName + "Text'] = '"); sb.Append(clientName + "';"); sb.Append('\n'); } string email = (ProfileUserId == ModuleContext.PortalSettings.UserId || ModuleContext.PortalSettings.UserInfo.IsInRole(ModuleContext.PortalSettings.AdministratorRoleName)) ? ProfileUser.Email : String.Empty; sb.Append("self.Email = ko.observable('"); email = Localization.GetSafeJSString(Server.HtmlDecode(email)); email = email.Replace(";", string.Empty).Replace("//", string.Empty); sb.Append(email + "');"); sb.Append('\n'); sb.Append("self.EmailText = '"); sb.Append(LocalizeString("Email") + "';"); sb.Append('\n'); ProfileProperties = sb.ToString(); } catch (Exception exc) { //Module failed to load Exceptions.ProcessModuleLoadException(this, exc); } }
public override void RenderValuesToHtmlInsideDataSet(DataSet ds, int moduleId, bool noScript) { var fields = new ArrayList(); var tableData = ds.Tables[DataSetTableName.Data]; var tokenReplace = new TokenReplace { ModuleId = moduleId }; foreach (DataRow row in ds.Tables[DataSetTableName.Fields].Rows) { if (row[FieldsTableColumn.Type].ToString() == Name) { var fieldId = (int)row[FieldsTableColumn.Id]; var field = new FieldSetting { Title = row[FieldsTableColumn.Title].ToString(), AltCaption = GetFieldSetting("AltCaption", fieldId, ds).AsString(), AsLink = GetFieldSetting("AsLink", fieldId, ds).AsBoolean(), Width = GetFieldSetting("Width", fieldId, ds).AsInt(), Height = GetFieldSetting("Height", fieldId, ds).AsInt(), }; fields.Add(field); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Url, typeof(string))); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Caption, typeof(string))); tableData.Columns.Add(new DataColumn(field.Title + DataTableColumn.Appendix_Original, typeof(string))); } } if (fields.Count > 0) { var portalSecurity = new PortalSecurity(); var portalId = Null.NullInteger; if (HttpContext.Current != null) { var portalSettings = PortalController.GetCurrentPortalSettings(); portalId = portalSettings.PortalId; } var cache = new Dictionary <string, ImageFields>(); foreach (DataRow row in ds.Tables[DataSetTableName.Data].Rows) { foreach (FieldSetting setting in fields) { var altCaption = GetAltAttributeForImage(row, setting, tokenReplace); var storedValue = row[setting.Title].ToString(); ImageFields imageFields; if (cache.ContainsKey(storedValue)) { imageFields = cache[storedValue]; } else { imageFields = GetImageFields(storedValue, setting, portalId); cache[storedValue] = imageFields; } row[setting.Title] = String.Format(imageFields.Value, altCaption); row[setting.Title + DataTableColumn.Appendix_Caption] = altCaption; row[setting.Title + DataTableColumn.Appendix_Original] = imageFields.Original; row[setting.Title + DataTableColumn.Appendix_Url] = imageFields.Url; } } } }
void FillTypeColumns(int moduleId, TokenReplace objTokenReplace, PortalSettings portalSettings, TabController tabCtrl, DataRow row, FieldSetting field) { var link = row[field.Title].ToString(); //Link showed to the user bool openInNewWindow; if (field.ShowOpenInNewWindow) //mit URL gepeicherten Wert lesen { openInNewWindow = UrlUtil.OpenUrlInNewWindow(link); } else { switch (Globals.GetURLType(UrlUtil.StripURL(link))) { case TabType.File: openInNewWindow = true; break; case TabType.Tab: //link to internal tab openInNewWindow = false; break; default: openInNewWindow = link.Like(Globals.ApplicationMapPath + "*"); break; } } //set caption: var caption = field.OutputFormat; if (!string.IsNullOrEmpty(caption)) { caption = objTokenReplace.ReplaceEnvironmentTokens(caption, row); } var isLink = true; var url = ""; //Link readable by browsers link = UrlUtil.StripURL(link); if (link != string.Empty) { switch (Globals.GetURLType(link)) { case TabType.Tab: var tab = tabCtrl.GetTab(int.Parse(link), portalSettings.PortalId, false); if (tab != null) { if (caption == string.Empty) { if (!field.Abbreviate) { var strPath = string.Empty; if (tab.BreadCrumbs != null && tab.BreadCrumbs.Count > 0) { foreach (TabInfo b in tab.BreadCrumbs) { var strLabel = b.TabName; if (strPath != string.Empty) { strPath += string.Format( "<img src=\"{0}/images/breadcrumb.gif\" border=\"0\" alt=\"Spacer\"/>", Globals.ApplicationPath); } strPath += strLabel; } } caption = tab.TabPath.Replace("//", string.Format( "<img src=\"{0}/images/breadcrumb.gif\" border=\"0\" alt=\"Spacer\"/>", Globals.ApplicationPath)); } else { caption = tab.TabName; } } url = field.EnforceDownload ? Globals.LinkClick(link, portalSettings.ActiveTab.TabID, moduleId) : Globals.NavigateURL(int.Parse(link)); } else { caption = Localization.GetString("PageNotFound.ErrorMessage", Globals.ResolveUrl( string.Format("~{0}{1}/SharedResources.resx", Definition.PathOfModule, Localization.LocalResourceDirectory))); url = string.Empty; isLink = false; } break; case TabType.File: if (caption == string.Empty) { if (link.ToLowerInvariant().StartsWith("fileid=")) { var file = FileManager.Instance.GetFile(int.Parse(link.Substring(7))); if (file != null) { if (!field.Abbreviate) { caption = file.Folder + file.FileName; } else { caption = file.FileName; } } } else if (field.Abbreviate && link.IndexOf("/", StringComparison.Ordinal) > -1) { caption = link.Substring(Convert.ToInt32(link.LastIndexOf("/", StringComparison.Ordinal) + 1)); } else { caption = link; } } url = Globals.LinkClick(link, portalSettings.ActiveTab.TabID, moduleId); break; case TabType.Url: case TabType.Normal: if (caption == string.Empty) { if (field.Abbreviate && link.IndexOf("/", StringComparison.Ordinal) > -1) { caption = link.Substring(Convert.ToInt32(link.LastIndexOf("/", StringComparison.Ordinal) + 1)); } else { caption = link; } } if (!field.TrackDownloads) { url = link; } break; } if (field.EnforceDownload) { url += "&forcedownload=true"; } string strFieldvalue; if (isLink) { strFieldvalue = string.Format("<!--{1}--><a href=\"{0}\"{2}>{1}</a>", HttpUtility.HtmlEncode(url), caption, (openInNewWindow ? " target=\"_blank\"" : "")); } else { strFieldvalue = caption; } row[field.Title] = strFieldvalue; row[field.Title + DataTableColumn.Appendix_Caption] = caption; row[field.Title + DataTableColumn.Appendix_Original] = link; row[field.Title + DataTableColumn.Appendix_Url] = url; } }
/// ----------------------------------------------------------------------------- /// <summary> /// Executes a report and returns the results /// </summary> /// <param name="objReport">The ReportInfo object</param> /// <param name="cacheKey">The cache key for the module</param> /// <param name="bypassCache">A boolean indicating that the cache should be bypassed</param> /// <param name="hostModule">The module that is hosting the report</param> /// <param name="fromCache">A boolean indicating if the data was retrieved from the cache</param> /// <exception cref="System.ArgumentNullException"> /// The value of <paramref name="objReport" /> was null (Nothing in Visual Basic) /// </exception> /// <history> /// [anurse] 08/25/2007 Created /// </history> /// ----------------------------------------------------------------------------- public static DataTable ExecuteReport(ReportInfo objReport, string cacheKey, bool bypassCache, PortalModuleBase hostModule, ref bool fromCache) { try { fromCache = false; if (ReferenceEquals(objReport, null)) { throw new ArgumentNullException("objReport"); } if (string.IsNullOrEmpty(objReport.DataSource)) { return(null); // If there's no data source, there's no report } // Check the cache DataTable results = null; if (!bypassCache) { results = DataCache.GetCache(cacheKey) as DataTable; if (results != null) { fromCache = true; return(results); } } // Get an instance of the data source //DotNetNuke.Modules.Reports.DataSources.IDataSource dataSource = GetDataSource(objReport.DataSourceClass) as DataSources.IDataSource; var dataSource = GetDataSource(objReport.DataSourceClass); // Create an extension context var moduleFolder = string.Empty; if (hostModule != null) { moduleFolder = hostModule.TemplateSourceDirectory; } var ctxt = new ExtensionContext(moduleFolder, "DataSource", objReport.DataSource); // Load Parameters IDictionary <string, object> parameters = BuildParameters(hostModule, objReport); if (objReport.CacheDuration != 0) { // Check the app setting if (!"True".Equals( WebConfigurationManager.AppSettings[ReportsConstants.APPSETTING_AllowCachingWithParameters], StringComparison.InvariantCulture)) { parameters.Clear(); } } // Execute the report dataSource.Initialize(ctxt); results = dataSource.ExecuteReport(objReport, hostModule, parameters).ToTable(); results.TableName = "QueryResults"; // Check if the converters were run if (!dataSource.CanProcessConverters) { // If not, run them the slow way :( foreach (DataRow row in results.Rows) { foreach (DataColumn col in results.Columns) { if (!objReport.Converters.ContainsKey(col.ColumnName)) { continue; } var list = objReport.Converters[col.ColumnName]; foreach (var converter in list) { row[col] = ApplyConverter(row[col], converter.ConverterName, converter.Arguments); } } } } // Do the token replace if specified if (objReport.TokenReplace) { var localTokenReplacer = new TokenReplace(); foreach (DataColumn col in results.Columns) { // Process each column of the resultset if (col.DataType == typeof(string)) { // We want to replace the data, we don't mind that it is marked as readonly if (col.ReadOnly) { col.ReadOnly = false; } var maxLength = col.MaxLength; var resultText = ""; foreach (DataRow row in results.Rows) { resultText = localTokenReplacer.ReplaceEnvironmentTokens(Convert.ToString(row[col].ToString())); // Don't make it too long if (resultText.Length > maxLength) { resultText = resultText.Substring(0, maxLength); } row[col] = resultText; } } } } // Cache it, if not asked to bypass the cache if (!bypassCache && results != null) { DataCache.SetCache(cacheKey, results); } // Return the results return(results); } catch (DataSourceException) { throw; //Catch ex As Exception // If hostModule IsNot Nothing Then // Throw New DataSourceException("UnknownError.Text", hostModule.LocalResourceFile, ex, ex.Message) // Else // Throw // End If } }