/// <summary> /// Delete the file from disk (rename the file) /// </summary> /// <param name="detailsPage"></param> /// <returns></returns> protected string deleteFileFromDisk(CmsPage detailsPage, CmsLanguage language) { FileLibraryDb db = new FileLibraryDb(); List <FileLibraryDetailsData> fileList = db.fetchDetailsData(detailsPage); if (fileList.Count == 0) { return(""); } foreach (FileLibraryDetailsData f in fileList) { try { string newFileName = "Deleted." + DateTime.Now.ToString("yyyyMMdd.HH.mm.ss.") + f.FileName; string oldFileNameOnDisk = FileLibraryDetailsData.getTargetNameOnDisk(detailsPage, f.Identifier, language, f.FileName); string newFileNameOnDisk = FileLibraryDetailsData.getTargetNameOnDisk(detailsPage, f.Identifier, language, newFileName); if (File.Exists(oldFileNameOnDisk)) { File.Move(oldFileNameOnDisk, newFileNameOnDisk); } } catch (Exception ex) { return("Error deleting file from disk (" + f.FileName + ": " + ex.Message + ")."); } } return(""); }
/// <summary> /// Create the jQuery FullCalendar event object for an event with a file attached. /// </summary> /// <param name="c"></param> /// <param name="f"></param> public FullCalendarEvent(EventCalendarDb.EventCalendarDetailsData c, FileLibraryDetailsData attachedFile, List <EventCalendarDb.EventCalendarCategoryData> categoryHaystack) { CmsPage page = CmsContext.getPageById(attachedFile.DetailsPageId); id = "EventFile_" + attachedFile.DetailsPageId.ToString(); title = attachedFile.FileName; start = c.StartDateTime.AddSeconds(1); // show below the event end = c.EndDateTime.AddSeconds(1); // show below the event allDay = true; url = page.getUrl(attachedFile.Lang); EventCalendarDb.EventCalendarCategoryData category = EventCalendarDb.EventCalendarCategoryData.GetFromHaystack(categoryHaystack, c.CategoryId); backgroundColor = category.ColorHex; borderColor = "black"; textColor = "white"; }
/// <summary> /// Render the html to display an attached file /// </summary> /// <param name="lang"></param> /// <param name="f"></param> /// <param name="u"></param> /// <returns></returns> protected string renderAttachedFile(CmsLanguage lang, FileLibraryDetailsData f, WebPortalUser u, CmsUrlFormat fileUrlFormat) { CmsPage detailsFilePage = CmsContext.getPageById(f.DetailsPageId); if (detailsFilePage.Zone.canRead(u) || detailsFilePage.Zone.canWrite(u)) { string iconTag = IconUtils.getIconTag(CmsContext.ApplicationPath, false, f.fileExtension); string urlDownload = FileLibraryDetailsData.getDownloadAnchorHtml(detailsFilePage, f.Identifier, lang, f.FileName, f.FileName, "_blank", "", fileUrlFormat); string urlPage = detailsFilePage.getUrl(lang); urlPage = "  <a href=\"" + urlPage + "\" class=\"rightArrowLink\">" + getSeeFileDetailsText(lang) + "</a>"; return(iconTag + " " + urlDownload + urlPage); } return(""); }
/// <summary> /// A user can read the calendar page does not mean he/she can read the files /// attached to events. Hence, the CmsPage for a file is read in order to /// check the zone of the attached file. /// </summary> /// <param name="f"></param> /// <returns></returns> protected bool userHasAuthority(FileLibraryDetailsData f) { CmsPage filePage = CmsContext.getPageById(f.DetailsPageId); return(filePage.currentUserCanRead); }