/// <summary> /// Renders the File Submission column cell /// </summary> /// <param name="renderedCell">The value to render, from the query results.</param> /// <param name="webNameRenderedCell"></param> /// <param name="learnerAssignmentGUID">The GUID of the current assignment</param> /// <param name="hw">The HtmlTextWriter to write to.</param> void RenderFileSubmissionCell(RenderedCell renderedCell, WebNameRenderedCell webNameRenderedCell, Guid learnerAssignmentGUID, HtmlTextWriter hw) { // This is a bit of a hack since the query returns an unlocalized string. Next time the schema is changed would be best // to change to return integer values representing these. No point making a sql change just for this though. if (renderedCell.ToString() == "Submit File(s)") { string baseUrl = "{0}{1}FilesUploadPage.aspx?LearnerAssignmentId={2}&Source={3}"; // Creating a format string from a format string baseUrl = string.Format(CultureInfo.InvariantCulture, baseUrl, "{0}", Constants.SlkUrlPath, "{1}", RawSourceUrl); RenderFileSubmissionCellAsSubmitLink(baseUrl, webNameRenderedCell.SPWebUrl, learnerAssignmentGUID, PageCulture.Format(PageCulture.Resources.AlwpFileSubmissionSubmitText), hw); } else if (renderedCell.ToString() == "Submitted LINK") { RenderFileSubmissionCellAsSubmittedLink( "{0}" + Constants.SlkUrlPath + "SubmittedFiles.aspx?LearnerAssignmentId={1}", webNameRenderedCell, learnerAssignmentGUID, PageCulture.Format(PageCulture.Resources.LearnerAssignmentStatusCompleted), hw); } else if (renderedCell.ToString() == "Submitted") { hw.WriteEncodedText(PageCulture.Format(PageCulture.Resources.LearnerAssignmentStatusCompleted)); } else if (renderedCell.ToString() == "Not Available") { hw.WriteEncodedText(PageCulture.Format(PageCulture.Resources.GradingFileSubmissionNA)); } else { hw.WriteEncodedText(renderedCell.ToString()); } }
/// <summary>Set the score and grade display values.</summary> private void SetUpScoreAndGradeDisplayValues(LearnerAssignmentState learnerAssignmentStatus) { if (AssignmentProperties.HidePoints) { RowScore.Visible = false; } else { if (LearnerAssignmentProperties.SuccessStatus == SuccessStatus.Passed && LearnerAssignmentProperties.FinalPoints.HasValue && LearnerAssignmentProperties.FinalPoints.Value == 0.0 ) { lblScoreValue.Text = string.Empty; } else { if (learnerAssignmentStatus != LearnerAssignmentState.Final) { if (AssignmentProperties.PointsPossible.HasValue) { lblScoreValue.Text = PageCulture.Format(PageCulture.Resources.LobbyPointsNoValuePointsPossible, AssignmentProperties.PointsPossible); } else { lblScoreValue.Text = PageCulture.Format(PageCulture.Resources.LobbyPointsNoValue, LearnerAssignmentProperties.FinalPoints); } } else { string finalPoints = PageCulture.Resources.LobbyPointsNoValue; if (LearnerAssignmentProperties.FinalPoints.HasValue) { finalPoints = LearnerAssignmentProperties.FinalPoints.Value.ToString(CultureInfo.CurrentCulture); } if (AssignmentProperties.PointsPossible.HasValue) { lblScoreValue.Text = PageCulture.Format(PageCulture.Resources.LobbyPointsValuePointsPossible, finalPoints, AssignmentProperties.PointsPossible); } else { lblScoreValue.Text = PageCulture.Format(PageCulture.Resources.LobbyPointsValue, finalPoints); } } } } if (SlkStore.Settings.UseGrades) { labelGradeValue.Text = LearnerAssignmentProperties.Grade; } else { RowGrade.Visible = false; } }
public void SaveCulture(PageCultureBinding Model, string UserID) { using (var _c = db) { Can(Model.SiteID, UserID, _c); var _PageCulture = _c.PageCultures.Where(m => m.PageID == Model.PageID && m.CultureID == Model.CultureID).SingleOrDefault(); if (_PageCulture == null) { _PageCulture = new PageCulture(Model); _c.PageCultures.Add(_PageCulture); var _Page = _c.Pages.Where(m => m.PageID == Model.PageID).SingleOrDefault(); _Page.Alias = Model.PageAlias; } else { _PageCulture.SetValues(Model); _PageCulture.Page.Alias = Model.PageAlias; } //VERIFY FriendlyUrl is Unique if (_c.PageCultures.Where(m => (Model.FriendlyUrl != null ? m.FriendlyUrl.ToLower().Equals(Model.FriendlyUrl.ToLower()) : m.FriendlyUrl.Equals("")) && m.PageID != Model.PageID && m.Page.SiteID == Model.SiteID).Any()) { throw new RuleException("Ya existe una seccion con el FriendlyUrl /" + Model.FriendlyUrl); } _c.SaveChanges(); //SAVE OPEN GRAPH DATA var _OdataID = new OGraphBLL().SaveOGraph(Model.OGraph, Model.SiteID, UserID); if (_OdataID != 0) { var _OdataModel = _c.PageCulturesOGraphs.Where(m => m.PageID == Model.PageID && m.CultureID == Model.CultureID).FirstOrDefault(); if (_OdataModel != null) { _OdataModel.OGraphID = _OdataID; } else { _OdataModel = new PageCultureOGraph { CultureID = Model.CultureID, PageID = Model.PageID, OGraphID = _OdataID }; _c.PageCulturesOGraphs.Add(_OdataModel); } } _c.SaveChanges(); } }
private void PopulateSiteListControl(List <WebListItem> webList) { HyperLink hl = null; HtmlGenericControl li = null; HtmlGenericControl ul = new HtmlGenericControl("ul"); try { foreach (WebListItem webListItem in webList) { li = new HtmlGenericControl("li"); li.Attributes.Add("title", PageCulture.Format(PageCulture.Resources.ActionsMRUToolTip, Server.HtmlEncode(webListItem.Title))); hl = new HyperLink(); hl.NavigateUrl = AssignmentSiteUrl(webListItem.Url); hl.Text = Server.HtmlEncode(webListItem.Title); li.Controls.Add(hl); hl = null; if (newSite.HasValue && newSite.Value.Equals(webListItem.SPWebGuid)) { HtmlImage img = new HtmlImage(); img.Src = "Images/NewIcon.gif"; li.Controls.Add(img); } ul.Controls.Add(li); li = null; } siteList.Controls.Add(ul); ul = null; } catch { if (hl != null) { hl.Dispose(); } if (li != null) { li.Dispose(); } if (ul != null) { ul.Dispose(); } throw; } }
private void SetUpButtons(AssignmentView view) { SetUpSlkBeginButtonAction(view); // Set up delete button if (AssignmentProperties.CreatedById.Equals(LearnerAssignmentProperties.LearnerId) && !AssignmentProperties.HasInstructors) { slkButtonDelete.Text = PageCulture.Resources.LobbyDeleteAssignmentText; slkButtonDelete.ToolTip = PageCulture.Resources.LobbyDeleteToolTip; slkButtonDelete.OnClientClick = PageCulture.Format("javascript: return confirm('{0}');", PageCulture.Resources.LobbyDeleteMessage); slkButtonDelete.ImageUrl = Constants.ImagePath + Constants.DeleteIcon; } else { slkButtonDelete.Visible = false; } // Set up submit button if (AssignmentProperties.HasInstructors) { slkButtonSubmit.Text = PageCulture.Resources.LobbySubmitText; slkButtonSubmit.ToolTip = PageCulture.Resources.LobbySubmitToolTip; slkButtonSubmit.OnClientClick = PageCulture.Format("javascript: return confirm('{0}');", PageCulture.Resources.LobbySubmitMessage); slkButtonSubmit.ImageUrl = Constants.ImagePath + Constants.SubmitIcon; } else { slkButtonSubmit.Text = PageCulture.Resources.LobbyMarkasCompleteText; slkButtonSubmit.ToolTip = PageCulture.Resources.LobbyMarkasCompleteToolTip; slkButtonSubmit.OnClientClick = PageCulture.Format("javascript: return confirm('{0}');", PageCulture.Resources.LobbyMarkasCompleteMessage); slkButtonSubmit.ImageUrl = Constants.ImagePath + Constants.MarkCompleteIcon; } slkButtonBegin.AccessKey = PageCulture.Resources.LobbyBeginAccessKey; slkButtonDelete.AccessKey = PageCulture.Resources.LobbyDeleteAccessKey; slkButtonSubmit.AccessKey = PageCulture.Resources.LobbySubmitAccessKey; }
void CheckAndDisplayFile() { ResourceFileName.Text = Server.HtmlEncode(SPFile.Name); DocLibLink.NavigateUrl = SPList.DefaultViewUrl; DocLibLink.Text = Server.HtmlEncode(SPList.Title); // Make sure that the package isn't checked out. //Using LoginName instead of Sid as Sid may be empty while using FBA #if SP2007 if (SPFile.CheckOutStatus != SPFile.SPCheckOutStatus.None && SPFile.CheckedOutBy.LoginName.Equals(SPWeb.CurrentUser.LoginName)) #else if (SPFile.CheckOutType != SPFile.SPCheckOutType.None && SPFile.CheckedOutByUser.LoginName.Equals(SPWeb.CurrentUser.LoginName)) #endif { // If it's checked out by the current user, show an error. throw new SafeToDisplayException(PageCulture.Resources.ActionsCheckedOutError); } // no minor versions or limited version number warnings if (!SPList.EnableVersioning || SPList.MajorVersionLimit != 0 || SPList.MajorWithMinorVersionsLimit != 0) { if (SlkStore.Settings.AutoVersionLibrariesIfUnversioned) { SlkStore.VersionLibrary((SPDocumentLibrary)SPList); Response.Redirect(Request.RawUrl, true); } else { errorBanner.AddError(ErrorType.Warning, PageCulture.Format(PageCulture.Resources.ActionsVersioningOff, Server.HtmlEncode(SPList.Title))); } } // If the current file isn't a published version, show a warning. // If the document library doesn't have minor versions, the file is NEVER SPFileLevel.Published if (SPList.EnableMinorVersions) { if (SPFile.Level == SPFileLevel.Draft) { errorBanner.AddError(ErrorType.Warning, PageCulture.Resources.ActionsDraftVersion); } } if (!IsPostBack) { // get information about the package: populate the "Organizations" row // (as applicable) in the UI, and set <title> and <description> to the text // of the title and description to display string title, description; if (NonELearning) { // non-e-learning content... // set <title> and <description> title = SPFile.Title; if (String.IsNullOrEmpty(title)) { title = Path.GetFileNameWithoutExtension(SPFile.Name); } description = string.Empty; // hide the "Organizations" row organizationRow.Visible = false; organizationRowBottomLine.Visible = false; } else { // e-learning content... // set <packageInformation> to refer to information about the package title = package.Title; description = package.Description; // populate the drop-down list of organizations; hide the entire row containing that drop-down if there's only one organization if (package.Organizations.Count <= 1) { organizationRow.Visible = false; organizationRowBottomLine.Visible = false; } else { foreach (OrganizationNodeReader nodeReader in package.Organizations) { string id = nodeReader.Id; organizationList.Items.Add(new ListItem(Server.HtmlEncode(GetDefaultTitle(nodeReader.Title, id)), id)); } ListItem defaultOrganization = organizationList.Items.FindByValue(package.DefaultOrganizationId.ToString(CultureInfo.InvariantCulture)); if (defaultOrganization != null) { defaultOrganization.Selected = true; } } } // copy <title> to the UI lblTitle.Text = Server.HtmlEncode(title); lblDescription.Text = SlkUtilities.GetCrlfHtmlEncodedText(description); } // if the package has warnings, tell the user if (package.Warnings != null) { StringBuilder sb = new StringBuilder(); sb.Append(PageCulture.Resources.ActionsWarning); sb.AppendLine("<br />"); sb.Append("<a href=\"javascript: __doPostBack('showWarnings','');\">"); if (ShowWarnings) { sb.Append(PageCulture.Resources.ActionsHideDetails); } else { sb.Append(PageCulture.Resources.ActionsShowDetails); } sb.AppendLine("</a>"); if (ShowWarnings) { sb.AppendLine("<ul style=\"margin-top:0;margin-bottom:0;margin-left:24;\">"); using (XmlReader xmlReader = package.Warnings.CreateReader()) { XPathNavigator root = new XPathDocument(xmlReader).CreateNavigator(); foreach (XPathNavigator error in root.Select("/Warnings/Warning")) { sb.Append("<li>"); sb.Append(Server.HtmlEncode(error.Value)); sb.AppendLine("</li>"); } } sb.Append("</ul>\n"); } errorBanner.AddHtmlErrorText(ErrorType.Warning, sb.ToString()); } }
private List <WebListItem> GetSiteList() { // code to iterate through user's list of SPWebs bool addCurrentToList = true; int mruItems = SlkStore.Settings.UserWebListMruSize; int itemMax; int listCount; ReadOnlyCollection <SlkUserWebListItem> userWebList = SlkStore.FetchUserWebList(); foreach (SlkUserWebListItem webListItem in userWebList) { if (SPWeb.ID.Equals(webListItem.SPWebGuid)) { addCurrentToList = false; break; } } if (addCurrentToList) { listCount = userWebList.Count + 1; } else { listCount = userWebList.Count; } if (!ShowAllSites && listCount > mruItems) { itemMax = mruItems; lnkMRUShowAll.Visible = true; lnkMRUShowAll.Text = PageCulture.Resources.ActionslnkMRUShowAll; } else { itemMax = listCount; lnkMRUShowAll.Visible = false; } List <WebListItem> webList = new List <WebListItem>(itemMax); if (addCurrentToList) { itemMax--; } for (int i = 0; i < itemMax && i < userWebList.Count; i++) { bool previousValue = SPSecurity.CatchAccessDeniedException; SPSecurity.CatchAccessDeniedException = false; try { SlkUserWebListItem item = userWebList[i]; using (SPSite site = new SPSite(item.SPSiteGuid, SPContext.Current.Site.Zone)) { using (SPWeb web = site.OpenWeb(item.SPWebGuid)) { if (SPWeb.ID.Equals(item.SPWebGuid)) { webList.Add(new WebListItem(item, web.Url, PageCulture.Format("{0} {1}", web.Title, PageCulture.Resources.ActionslblMRUCurrentSite))); } else { webList.Add(new WebListItem(item, web.Url, web.Title)); } } } } catch (UnauthorizedAccessException) { // the user doesn't have permission to access this site, so ignore it continue; } catch (System.Data.SqlClient.SqlException) { // site is in another web application and this web application's app pool user doesn't have access continue; } catch (FileNotFoundException) { // the site doesn't exist continue; } finally { SPSecurity.CatchAccessDeniedException = previousValue; } } if (addCurrentToList) { webList.Add(new WebListItem(SPWeb.Site.ID, SPWeb.ID, DateTime.Now, SPWeb.Url, PageCulture.Format("{0} {1}", SPWeb.Title, PageCulture.Resources.ActionslblMRUCurrentSite))); } webList.Sort(); return(webList); }
protected void addButton_Click(object sender, EventArgs e) { // user clicked "Add" button (after clicking "Add a site to this list") bool showAddSite = true; bool previousValue = SPSecurity.CatchAccessDeniedException; SPSecurity.CatchAccessDeniedException = false; try { string destinationUrl = txtNewSite.Text.Trim(); Uri destinationUri = new Uri(destinationUrl); using (SPSite site = new SPSite(destinationUri.AbsoluteUri)) { using (SPWeb destinationWeb = site.OpenWeb()) { // check if the site is a valid Slk site SlkStore destinationSlkStore; try { destinationSlkStore = SlkStore.GetStore(destinationWeb); } catch (SlkNotConfiguredException) { errorBanner.AddHtmlErrorText(ErrorType.Warning, PageCulture.Format(PageCulture.Resources.ActionsNotEnabled, Server.HtmlEncode(destinationUrl))); DisplayAddSite(); return; } // check if the user is an instructor on that site if (!destinationSlkStore.IsInstructor(destinationWeb)) { errorBanner.AddHtmlErrorText(ErrorType.Warning, PageCulture.Format(PageCulture.Resources.ActionsNotInstructor, Server.HtmlEncode(destinationUrl))); DisplayAddSite(); return; } // check if the site is already in the list ReadOnlyCollection <SlkUserWebListItem> userWebList = SlkStore.FetchUserWebList(); foreach (SlkUserWebListItem webListItem in userWebList) { if (destinationWeb.ID.Equals(webListItem.SPWebGuid)) { errorBanner.AddHtmlErrorText(ErrorType.Info, PageCulture.Format(PageCulture.Resources.ActionsAlreadyInList, Server.HtmlEncode(destinationWeb.Title))); break; } } // add the web to the list SlkStore.AddToUserWebList(destinationWeb); //local slkstore ShowAllSites = false; txtNewSite.Text = string.Empty; newSite = destinationWeb.ID; showAddSite = false; } } } catch (UriFormatException) { // the url is an invalid format errorBanner.AddHtmlErrorText(ErrorType.Warning, PageCulture.Format(PageCulture.Resources.ActionsInvalidSite, Server.HtmlEncode(txtNewSite.Text))); } catch (UnauthorizedAccessException) { // the user doesn't have permission to access this site, so show an error message errorBanner.AddHtmlErrorText(ErrorType.Warning, PageCulture.Format(PageCulture.Resources.ActionsInvalidSite, Server.HtmlEncode(txtNewSite.Text))); } catch (FileNotFoundException) { errorBanner.AddHtmlErrorText(ErrorType.Warning, PageCulture.Format(PageCulture.Resources.ActionsInvalidSite, Server.HtmlEncode(txtNewSite.Text))); } finally { SPSecurity.CatchAccessDeniedException = previousValue; } if (showAddSite) { DisplayAddSite(); } }
/// <summary>Formats a date for display.</summary> /// <param name="date">The date to format.</param> /// <returns>A formatted string.</returns> protected string FormatDateForDisplay(DateTime date) { return(PageCulture.Format(PageCulture.Resources.LongDateShortTime, date)); }
/// <summary> /// Renders a column header, i.e. the label at the top of a column in the query results. /// </summary> /// /// <param name="columnDef">The <c>ColumnDefinition</c> of the column being rendered.</param> /// /// <param name="columnIndex">The zero-based index of this column.</param> /// /// <param name="ascendingSort"><c>true</c> if this column is currently being sorted on in an /// ascending order; <c>false</c> if this column is currently being sorted on in a /// descending order; <c>null</c> if this column is not being sorted on.</param> /// /// <param name="hw">The <c>HtmlTextWriter</c> to write to.</param> /// private void RenderColumnHeader(ColumnDefinition columnDef, int columnIndex, bool?ascendingSort, HtmlTextWriter hw) { // render the "<th>" element for this column header hw.AddAttribute(HtmlTextWriterAttribute.Class, "ms-vh2"); hw.AddAttribute(HtmlTextWriterAttribute.Nowrap, "true"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "border-left: none; padding-left: 6px;"); using (new HtmlBlock(HtmlTextWriterTag.Th, 1, hw)) { // render the "<div>" element containing the column header hw.WriteLine(); hw.AddAttribute(HtmlTextWriterAttribute.Style, "position: relative; left: 0px; top: 0px; width: 100%;"); using (new HtmlBlock(HtmlTextWriterTag.Div, 1, hw)) { // render the "<table>" element containing the column header hw.AddAttribute(HtmlTextWriterAttribute.Class, "ms-unselectedtitle"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width: 100%;height: 100%;"); hw.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); using (new HtmlBlock(HtmlTextWriterTag.Table, 0, hw)) { using (new HtmlBlock(HtmlTextWriterTag.Tr, 0, hw)) { hw.AddAttribute(HtmlTextWriterAttribute.Class, "ms-vb"); hw.AddAttribute(HtmlTextWriterAttribute.Nowrap, "true"); hw.AddAttribute(HtmlTextWriterAttribute.Style, "width:100%;"); using (new HtmlBlock(HtmlTextWriterTag.Td, 0, hw)) { // write the "<a>" element which, when clicked, causes the query list // to be re-sorted as follows: if the clicked-on column header is the // one currently sorted on, then the sort is reversed, otherwise the // results are sorted in ascending order on the clicked-on column int newSort; if (ascendingSort != null) { if (ascendingSort.Value) { newSort = -(columnIndex + 1); // switch to descending sort } else { newSort = columnIndex + 1; // switch to ascending sort } } else { newSort = columnIndex + 1; } hw.AddAttribute(HtmlTextWriterAttribute.Title, PageCulture.Format(PageCulture.Resources.QueryResultsSortBy, columnDef.Title)); hw.AddAttribute(HtmlTextWriterAttribute.Href, GetAdjustedQueryString(QueryStringKeys.Sort, newSort.ToString(CultureInfo.InvariantCulture))); hw.AddAttribute(HtmlTextWriterAttribute.Style, "color:Gray;"); hw.AddAttribute("onclick", string.Format(CultureInfo.InvariantCulture, "sort({0}); return false;", newSort)); using (new HtmlBlock(HtmlTextWriterTag.A, 0, hw)) { // write the column title hw.WriteEncodedText(columnDef.Title); // write the sort ascending/descending icon, if we're currently // sorting on this column if (ascendingSort != null) { hw.AddAttribute(HtmlTextWriterAttribute.Src, (ascendingSort.Value ? "/_layouts/images/sort.gif" : "/_layouts/images/rsort.gif")); hw.AddAttribute(HtmlTextWriterAttribute.Alt, "Sort Ascending"); hw.AddAttribute(HtmlTextWriterAttribute.Border, "0"); HtmlBlock.WriteFullTag(HtmlTextWriterTag.Img, 0, hw); } } } } } } } }
protected void ResolveSPWebName(Guid spWebGuid, Guid spSiteGuid, out string spWebName, out string spWebUrl) { //Restore previously assigned value bool previousValue = SPSecurity.CatchAccessDeniedException; // To check the user permission to access this site. SPSecurity.CatchAccessDeniedException = false; // if <m_spWebNameMap> wasn't initialized, initialize it now if (m_spWebNameMap == null) { m_spWebNameMap = new Dictionary <Guid, WebNameAndUrl>(100); } WebNameAndUrl webNameAndUrl; // if the web name is in the dictionary, return it if (m_spWebNameMap.TryGetValue(spWebGuid, out webNameAndUrl)) { spWebName = webNameAndUrl.Name; spWebUrl = webNameAndUrl.Url; return; } try { using (SPSite spSite = new SPSite(spSiteGuid, SPContext.Current.Site.Zone)) { using (SPWeb spWeb = spSite.OpenWeb(spWebGuid)) { spWebName = spWeb.Title; spWebUrl = spWeb.Url; } } } catch (SqlException) { //The database the site is in is not accessible //Add the site to unknown site collection m_unknownSiteCount++; //increment the Site Count by 1; spWebName = PageCulture.Format(PageCulture.Resources.AlwpUnknownSite, m_unknownSiteCount); spWebUrl = null; } catch (FileNotFoundException) { //The Site does not exist : SPWeb not available. //Add the site to unknown site collection m_unknownSiteCount++; //increment the Site Count by 1; spWebName = PageCulture.Format(PageCulture.Resources.AlwpUnknownSite, m_unknownSiteCount); spWebUrl = null; } catch (UnauthorizedAccessException) { // the user doesn't have permission to access this site. //Set the SPWeb Title as Unknown Site # m_unknownSiteCount++; //increment the Site Count by 1; spWebName = PageCulture.Format(PageCulture.Resources.AlwpUnknownSite, m_unknownSiteCount); spWebUrl = null; } finally { //assign back previously assigned value SPSecurity.CatchAccessDeniedException = previousValue; } // update the collection webNameAndUrl = new WebNameAndUrl(); webNameAndUrl.Name = spWebName; webNameAndUrl.Url = spWebUrl; m_spWebNameMap[spWebGuid] = webNameAndUrl; }