/// <summary>
 /// Create the FileLibraryDetailsData object
 /// </summary>
 /// <param name="lang"></param>
 /// <param name="controlId"></param>
 /// <returns></returns>
 protected FileLibraryDetailsData createFileDetails(CmsLanguage lang, string controlId)
 {
     FileLibraryDetailsData submitted = new FileLibraryDetailsData();
     submitted.CategoryId = PageUtils.getFromForm(controlId + "categoryId", 0);
     submitted.Author = PageUtils.getFromForm(controlId + "author", "");
     submitted.Description = PageUtils.getFromForm(controlId + "description", "");
     submitted.EventPageId = PageUtils.getFromForm(controlId + "eventPageId", -1);
     return submitted;
 }
        /// <summary>
        /// Handle the form submit for changing file details
        /// </summary>
        /// <param name="page"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="controlId"></param>
        /// <returns></returns>
        protected string handleFormSubmit(CmsPage page, int identifier, CmsLanguage lang, string controlId)
        {
            if (PageUtils.getFromForm(controlId + "action", "") != "update")
                return "";

            FileLibraryDetailsData fileData = createFileDetails(lang, controlId);
            if (db.updateDetailsData(page, identifier, lang, fileData) == false)
                return formatErrorMsg("There was a database problem while saving the record.");
            else
                return formatNormalMsg("Record updated.");
        }
            public static FileAggItem FromFileLibraryDetailsData(FileLibraryDetailsData sourceDetails, List <FileLibraryCategoryData> categoryList, CmsUrlFormat pageLinkUrlFormat, CmsUrlFormat fileLinkUrlFormat)
            {
                CmsPage  detailsPage     = CmsContext.getPageById(sourceDetails.DetailsPageId);
                string   PageDisplayURL  = detailsPage.getUrl(sourceDetails.Lang, pageLinkUrlFormat);
                string   FileDownloadURL = FileLibraryDetailsData.getDownloadUrl(detailsPage, sourceDetails.Identifier, sourceDetails.Lang, sourceDetails.FileName, fileLinkUrlFormat);
                string   Title           = detailsPage.getTitle(sourceDetails.Lang);
                string   Description     = sourceDetails.Description;
                string   CategoryName    = FileLibraryCategoryData.getCategoryFromList(categoryList, sourceDetails.CategoryId).CategoryName;
                DateTime lastModified    = detailsPage.LastUpdatedDateTime;

                return(new FileAggItem(PageDisplayURL, FileDownloadURL, Title, Description, CategoryName, lastModified));
            }
        /// <summary>
        /// Under edit mode, render the right hand side of the file details page as form (HTML INPUT or TEXTAREA, etc...)
        /// </summary>
        /// <param name="detailsPage"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <param name="controlId"></param>
        /// <returns></returns>
        protected string renderRightPaneForm(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData fileData, string controlId, CmsUrlFormat fileUrlFormat)
        {
            string        fName = fileData.FileName;
            StringBuilder html  = new StringBuilder();

            html.Append("<div style=\"float: left;\" class=\"listing\">" + EOL);

            html.Append(renderDiv(getFileText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, fileUrlFormat)));

            string cssClass                  = "fileLibrary_categoryId";
            string popupCategory             = FileLibraryCategoryData.getEditPopupAnchor(lang, cssClass, getEditText(lang));
            string htmlId                    = controlId + "categoryId";
            NameValueCollection categoryColl = new NameValueCollection();

            foreach (FileLibraryCategoryData c in categoryList)
            {
                categoryColl.Add(c.CategoryId.ToString(), c.CategoryName);
            }
            string selectCategory = getCategoryOption(lang, controlId, fileData.CategoryId);

            html.Append(renderDiv(getCategoryText(lang) + " " + popupCategory, selectCategory));

            htmlId = controlId + "author";
            html.Append(renderDiv(getAuthorText(lang), PageUtils.getInputTextHtml(htmlId, htmlId, fileData.Author, 30, 50)));

            htmlId = controlId + "description";
            html.Append(renderDiv(getDocumentAbstractText(lang), PageUtils.getTextAreaHtml(htmlId, htmlId, fileData.Description, 25, 5)));

            if (getFileTypeName(fileData).EndsWith("graphic", StringComparison.CurrentCultureIgnoreCase))
            {
                string imgPreviewUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(FileLibraryDetailsData.getDownloadUrl(detailsPage, identifier, lang, fName, fileUrlFormat), 200, -1);
                string imgTag        = "<img border=\"0\" src=\"" + imgPreviewUrl + "\"></a>";
                html.Append(renderDiv(getImagePreviewText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, imgTag, "_blank", "", fileUrlFormat)));
            }

            bool eventRequired = FileLibraryCategoryData.isEventRequired(categoryList, fileData.CategoryId);

            if (eventRequired || fileData.EventPageId >= 0)
            {
                htmlId = controlId + "eventPageId";
                html.Append(renderDiv(getAttachedEventText(lang), getEventOption(lang, controlId, fileData.EventPageId, eventRequired)));
            }

            WebPortalUser u = WebPortalUser.FetchUser(fileData.CreatedBy, CmsPortalApplication.GetInstance());
            string        uploadPersonName = (u == null) ? fileData.CreatedBy : u.FullName;

            html.Append(renderDiv(getUploadedByText(lang), uploadPersonName));

            html.Append(renderDiv(getLastUpdatedText(lang), detailsPage.LastUpdatedDateTime.ToString("MMMM d yyyy h:mm tt")));

            html.Append("</div>" + EOL);
            return(html.ToString());
        }
 protected void rowToData(DataRow dr, FileLibraryDetailsData entity)
 {
     entity.DetailsPageId = Convert.ToInt32(dr["PageId"]);
     entity.Identifier    = Convert.ToInt32(dr["Identifier"]);
     entity.Lang          = new CmsLanguage(dr["LangCode"].ToString());
     entity.FileName      = dr["FileName"].ToString();
     entity.CategoryId    = Convert.ToInt32(dr["CategoryId"]);
     entity.Author        = dr["Author"].ToString();
     entity.Description   = dr["Description"].ToString();
     entity.CreatedBy     = dr["CreatedBy"].ToString();
     entity.EventPageId   = Convert.ToInt32(dr["EventPageId"]);
 }
        public override Rss.RssItem[] GetRssFeedItems(CmsPage page, CmsPlaceholderDefinition placeholderDefinition, CmsLanguage langToRenderFor)
        {
            
            Rss.RssItem rssItem = CreateAndInitRssItem(page, langToRenderFor);

            FileLibraryDetailsData fileData = db.fetchDetailsData(page, placeholderDefinition.Identifier, langToRenderFor, true);
            rssItem.Description = fileData.Description;
            rssItem.Author = fileData.Author;
            string controlId = "fileLibrary_" + page.Id.ToString() + "_" + placeholderDefinition.Identifier.ToString() + "_" + langToRenderFor.shortCode + "_";
            rssItem.Guid = new Rss.RssGuid(controlId);

            return new Rss.RssItem[] { rssItem };
        }
        protected void datasetToList(DataSet ds, List <FileLibraryDetailsData> list)
        {
            if (this.hasRows(ds) == false)
            {
                return;
            }

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                FileLibraryDetailsData entity = new FileLibraryDetailsData();
                rowToData(dr, entity);
                list.Add(entity);
            }
        }
        /// <summary>
        /// Render a "Back to" link
        /// </summary>
        /// <param name="pageToGoBackTo"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <returns></returns>
        protected string renderBackLinks(CmsPage pageToGoBackTo, CmsLanguage lang, FileLibraryDetailsData fileData)
        {
            StringBuilder html = new StringBuilder();
            string link = "<p><a class=\"backToPrev\" href=\"{0}\">{1} {2} {3}</a></p>" + EOL;
            string backTo = getBackToText(lang);
            string tab = getTabText(lang);

            string backUrl = pageToGoBackTo.getUrl(lang);
            html.Append(String.Format(link, new string[] { backUrl, backTo, getOverviewText(lang), tab }));

            Dictionary<string, string> linkParams = new Dictionary<string,string>();
            linkParams.Add("catId", fileData.CategoryId.ToString());
            backUrl = pageToGoBackTo.getUrl(linkParams, lang);
            html.Append(String.Format(link, new string[] { backUrl, backTo, fileData.getCategoryName(categoryList), tab }));

            return html.ToString();
        }
        /// <summary>
        /// Render the file details page in view mode
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="page"></param>
        /// <param name="identifier"></param>
        /// <param name="langToRenderFor"></param>
        /// <param name="paramList"></param>
        public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            UpdateFileLibraryCommandsInEditMenu(page);
            addCssAndScript(page);
            StringBuilder html = new StringBuilder();
            categoryList = db.fetchCategoryList(langToRenderFor);            

            FileLibraryDetailsData fileData = db.fetchDetailsData(page, identifier, langToRenderFor, true);
            CmsUrlFormat fileUrlFormat = CmsUrlFormat.RelativeToRoot;

            html.Append(renderBackLinks(page, langToRenderFor, fileData));
            html.Append(checkEventAttached(page, identifier, langToRenderFor, fileData));
            html.Append("<p style=\"padding: 0.5em;\">" + EOL);
            html.Append(renderLeftPane(page, identifier, langToRenderFor, fileData, fileUrlFormat));
            html.Append(renderRightPane(page, identifier, langToRenderFor, fileData, fileUrlFormat));
            html.Append("</p>" + EOL);
            writer.Write(html.ToString());
        }
        /// <summary>
        /// Render right hand side of the file details page (all details)
        /// </summary>
        /// <param name="detailsPage"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <returns></returns>
        protected string renderRightPane(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData fileData, CmsUrlFormat fileUrlFormat)
        {
            string        fName = fileData.FileName;
            StringBuilder html  = new StringBuilder();

            html.Append("<div style=\"float: left;\" class=\"listing\">" + EOL);

            html.Append(renderDiv(getFileText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, fileUrlFormat)));
            html.Append(renderDiv(getCategoryText(lang), fileData.getCategoryName(categoryList)));

            html.Append(renderDiv(getAuthorText(lang), fileData.Author));
            html.Append(renderDiv(getDocumentAbstractText(lang), StringUtils.nl2br(fileData.Description)));

            if (getFileTypeName(fileData).EndsWith("graphic", StringComparison.CurrentCultureIgnoreCase))
            {
                string imgPreviewUrl = CmsContext.UserInterface.ShowThumbnailPage.getThumbDisplayUrl(FileLibraryDetailsData.getDownloadUrl(detailsPage, identifier, lang, fName, fileUrlFormat), 200, -1);
                string imgTag        = "<img border=\"0\" src=\"" + imgPreviewUrl + "\"></a>";
                html.Append(renderDiv(getImagePreviewText(lang), FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, imgTag, "_blank", "", fileUrlFormat)));
            }

            bool eventRequired = FileLibraryCategoryData.isEventRequired(categoryList, fileData.CategoryId);

            if (eventRequired)
            {
                string eventHtml = "(n/a)";
                if (fileData.EventPageId > -1)
                {
                    CmsPage eventPage = CmsContext.getPageById(fileData.EventPageId);
                    eventHtml = "<a href=\"" + eventPage.getUrl(lang) + "\">" + eventPage.getTitle(lang) + "</a>" + EOL;
                }
                html.Append(renderDiv(getAttachedEventText(lang), eventHtml));
            }

            WebPortalUser u = WebPortalUser.FetchUser(fileData.CreatedBy, CmsPortalApplication.GetInstance());
            string        uploadPersonName = (u == null) ? fileData.CreatedBy : u.FullName;

            html.Append(renderDiv(getUploadedByText(lang), uploadPersonName));

            html.Append(renderDiv(getLastUpdatedText(lang), detailsPage.LastUpdatedDateTime.ToString("MMMM d yyyy h:mm tt")));

            html.Append("</div>" + EOL);
            return(html.ToString());
        }
        /// <summary>
        /// Render the file details page in edit mode
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="page"></param>
        /// <param name="identifier"></param>
        /// <param name="langToRenderFor"></param>
        /// <param name="paramList"></param>
        public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            string controlId = "fileLibrary_" + page.Id.ToString() + "_" + identifier.ToString() + "_" + langToRenderFor.shortCode + "_";

            addCssAndScript(page);
            StringBuilder html = new StringBuilder();
            categoryList = db.fetchCategoryList(langToRenderFor);            

            html.Append(handleFormSubmit(page, identifier, langToRenderFor, controlId));
            FileLibraryDetailsData fileData = db.fetchDetailsData(page, identifier, langToRenderFor, false);
            CmsUrlFormat fileUrlFormat = CmsUrlFormat.RelativeToRoot;
            
            html.Append("<p style=\"padding: 0.5em;\">" + EOL);
            html.Append(renderLeftPane(page, identifier, langToRenderFor, fileData, fileUrlFormat));
            html.Append(renderRightPaneForm(page, identifier, langToRenderFor, fileData, controlId, fileUrlFormat));
            html.Append(PageUtils.getHiddenInputHtml(controlId + "action", "update") + EOL);
            html.Append("</p>" + EOL);
            writer.Write(html.ToString());
        }
        /// <summary>
        /// Render left hand side of the file details page (file icon and size)
        /// </summary>
        /// <param name="detailsPage"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <returns></returns>
        protected string renderLeftPane(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData fileData, CmsUrlFormat fileUrlFormat)
        {            
            string fName = fileData.FileName;
            StringBuilder html = new StringBuilder();
            html.Append("<div style=\"float: left; text-align: center;\">" + EOL);

            string iconTag = IconUtils.getIconTag(CmsContext.ApplicationPath, true, fileData.fileExtension);
            html.Append(renderDiv(FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, iconTag, "_blank", "", fileUrlFormat)));

            html.Append(renderDiv(FileLibraryDetailsData.getDownloadAnchorHtml(detailsPage, identifier, lang, fName, getDownloadText(lang), "_blank", "downloadLink", fileUrlFormat)));

            html.Append("<p style=\"font-style: italic; font-size: smaller;\">(" + getLinkOpensNewWindowText(lang) + ")</p>" + EOL);

            html.Append(renderDiv(getFileTypeName(fileData)));
            long size = FileLibraryDetailsData.getFileSize(detailsPage, identifier, lang, fName);
            html.Append(renderDiv(StringUtils.formatFileSize(size)));

            html.Append("</div>" + EOL);
            return html.ToString();
        }
        public FileLibraryDetailsData fetchDetailsData(CmsPage page, int identifier, CmsLanguage lang, bool createIfNotExist)
        {
            if (page.ID < 0 || identifier < 0)
            {
                return(new FileLibraryDetailsData());
            }

            StringBuilder sql = new StringBuilder("SELECT PageId,Identifier,LangCode,FileName,CategoryId,Author,Description,LastModified,CreatedBy,EventPageId FROM ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" WHERE PageId=" + page.ID.ToString());
            sql.Append(" AND LangCode='" + lang.shortCode + "'");
            sql.Append(" AND Identifier=" + identifier.ToString());
            sql.Append(" AND Deleted is null;");

            FileLibraryDetailsData entity = new FileLibraryDetailsData();
            DataSet ds = this.RunSelectQuery(sql.ToString());

            if (this.hasSingleRow(ds))
            {
                DataRow dr = ds.Tables[0].Rows[0];
                rowToData(dr, entity);
            }
            else
            {
                if (createIfNotExist)
                {
                    if (insertDetailsData(page, identifier, lang, entity) == false)
                    {
                        throw new Exception("fetchDetailsData() database error: Error creating new placeholder");
                    }
                }
                else
                {
                    throw new Exception("fetchDetailsData() database error: placeholder does not exist");
                }
            }
            return(entity);
        }
        /// <summary>
        /// Select the latest uploaded files to show on overview tab
        /// </summary>
        /// <param name="pageArray"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public List <FileLibraryDetailsData> fetchLatestUpload(CmsPage[] pageArray, int identifier, CmsLanguage lang, int count)
        {
            List <FileLibraryDetailsData> list = new List <FileLibraryDetailsData>();

            if (pageArray.Length == 0)
            {
                return(list);
            }

            StringBuilder pageId = new StringBuilder();

            foreach (CmsPage p in pageArray)
            {
                pageId.Append(p.ID.ToString() + ",");
            }
            pageId.Remove(pageId.Length - 1, 1);

            StringBuilder sql = new StringBuilder("SELECT PageId,Identifier,LangCode,FileName,CategoryId,Author,Description,LastModified,CreatedBy,EventPageId FROM ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" WHERE PageId IN (" + pageId.ToString() + ")");
            sql.Append(" AND Identifier=" + identifier.ToString());
            sql.Append(" AND LangCode='" + dbEncode(lang.shortCode) + "'");
            sql.Append(" ORDER BY PageId DESC");
            sql.Append(" LIMIT 0, " + count + ";");
            DataSet ds = this.RunSelectQuery(sql.ToString());

            if (this.hasRows(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    FileLibraryDetailsData entity = new FileLibraryDetailsData();
                    rowToData(dr, entity);
                    list.Add(entity);
                }
            }
            return(list);
        }
        public List <FileLibraryDetailsData> fetchDetailsData(CmsPage page)
        {
            StringBuilder sql = new StringBuilder("SELECT PageId,Identifier,LangCode,FileName,CategoryId,Author,Description,LastModified,CreatedBy,EventPageId FROM ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" WHERE PageId=" + page.ID.ToString());
            sql.Append(" AND Deleted IS NULL");
            sql.Append(" ORDER BY FileName, LangCode;");

            List <FileLibraryDetailsData> list = new List <FileLibraryDetailsData>();
            DataSet ds = this.RunSelectQuery(sql.ToString());

            if (this.hasRows(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    FileLibraryDetailsData entity = new FileLibraryDetailsData();
                    rowToData(dr, entity);
                    list.Add(entity);
                }
            }
            return(list);
        }
        /// <summary>
        /// Get the dependencies for FileLibrary
        /// </summary>
        /// <returns></returns>
        public override CmsDependency[] getDependencies()
        {
            List <CmsDependency> ret = new List <CmsDependency>();

            ret.Add(CmsFileDependency.UnderAppPath("images/_system/calendar/arrowLeft.jpg", new DateTime(2011, 3, 1)));
            ret.Add(CmsFileDependency.UnderAppPath("images/_system/arrowDown.jpg", new DateTime(2011, 3, 1)));

            ret.Add(CmsFileDependency.UnderAppPath("js/_system/FileLibrary/FileLibrary.js"));
            ret.Add(CmsFileDependency.UnderAppPath("js/_system/FileLibrary/FileLibraryCategory.js"));
            ret.Add(new CmsPageDependency(CmsConfig.getConfigValue("DeleteFileLibraryPath", "/_admin/actions/deleteFileLibrary"), CmsConfig.Languages));

            // -- database tables
            ret.Add(new CmsDatabaseTableDependency(@"
                CREATE TABLE `FileLibraryAggregator` (
                  `PageId` int(10) unsigned NOT NULL,
                  `Identifier` int(10) unsigned NOT NULL,
                  `LangCode` varchar(5) NOT NULL,
                  `NumFilesOverview` int(11) NOT NULL,
                  `NumFilesPerPage` int(11) NOT NULL,
                  `Deleted` datetime DEFAULT NULL,
                  PRIMARY KEY (`PageId`,`Identifier`,`LangCode`)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
            "));
            ret.Add(new CmsDatabaseTableDependency(@"
                CREATE TABLE  `filelibrarydetails` (
                  `PageId` int(10) unsigned NOT NULL,
                  `Identifier` int(10) unsigned NOT NULL,
                  `LangCode` varchar(5) NOT NULL,
                  `Filename` varchar(255) NOT NULL,
                  `CategoryId` int(11) NOT NULL,
                  `Author` varchar(255) NOT NULL DEFAULT '',
                  `Description` text NOT NULL,
                  `LastModified` datetime NOT NULL,
                  `CreatedBy` varchar(255) NOT NULL,
                  `EventPageId` int(11) NOT NULL DEFAULT '-1',
                  `Deleted` datetime DEFAULT NULL,
                  PRIMARY KEY (`PageId`,`Identifier`,`LangCode`)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
            "));
            ret.Add(new CmsDatabaseTableDependency(@"
                CREATE TABLE  `filelibrarycategory` (
                  `CategoryId` int(11) NOT NULL,
                  `LangCode` varchar(5) NOT NULL,
                  `EventRequired` int(1) NOT NULL DEFAULT '0',
                  `CategoryName` varchar(255) NOT NULL,
                  `SortOrdinal` int(11) NOT NULL DEFAULT '0',
                  PRIMARY KEY (`CategoryId`,`LangCode`)
                ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
            "));

            // -- REQUIRED config entries
            ret.Add(new CmsConfigItemDependency("FileLibrary.DetailsTemplateName"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.NumEventsInList"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.OverviewText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.NewUploadText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.CategoryText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.FileNameText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.AttachedEventText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.AttachToEventText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.FileText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.SeeFileDetailsText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.BackToText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.TabText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.DownloadText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.LinkOpensNewWindowText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.AuthorText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.DocumentAbstractText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.UploadedByText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.LastUpdatedText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.ImagePreviewText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.EditText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.DateTimeText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.EventCategoryText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.DescriptionText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.AddFileText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.MaxFileSizeText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.UploadButtonText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.EventNotAttachedText"));
            ret.Add(new CmsConfigItemDependency("FileLibrary.PageText"));

            // make sure that all files associated with FileLibraryDetails placeholder are live.
            Dictionary <CmsPage, CmsPlaceholderDefinition[]> phDefsDict = CmsContext.getAllPlaceholderDefinitions("FileLibraryDetails", CmsContext.HomePage, CmsContext.PageGatheringMode.FullRecursion);

            foreach (CmsPage page in phDefsDict.Keys)
            {
                foreach (CmsPlaceholderDefinition phDef in phDefsDict[page])
                {
                    foreach (CmsLanguage lang in CmsConfig.Languages)
                    {
                        FileLibraryDetailsData fileData = db.fetchDetailsData(page, phDef.Identifier, lang, true);
                        if (fileData.FileName != "")
                        {
                            string filenameOnDisk = FileLibraryDetailsData.getTargetNameOnDisk(page, phDef.Identifier, lang, fileData.FileName);
                            ret.Add(new CmsFileDependency(filenameOnDisk));
                            if (fileData.EventPageId >= 0) // make sure that the linked event page exists.
                            {
                                ret.Add(new CmsPageDependency(fileData.EventPageId, new CmsLanguage[] { lang }));
                            }
                        }
                    } // foreach lang
                }     // foreach placeholder definition
            }         // foreach page

            return(ret.ToArray());
        }
        public List <FileLibraryDetailsData> fetchDetailsData(CmsPage[] pageArray, int identifier, CmsLanguage lang, FileLibraryCategoryData category, int offset, int count)
        {
            List <FileLibraryDetailsData> list = new List <FileLibraryDetailsData>();

            if (pageArray.Length == 0)
            {
                return(list);
            }

            List <string> pageIds = new List <string>();

            foreach (CmsPage p in pageArray)
            {
                pageIds.Add(p.ID.ToString());
            }

            StringBuilder sql = new StringBuilder("SELECT PageId,Identifier,LangCode,FileName,CategoryId,Author,Description,LastModified,CreatedBy,EventPageId FROM ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" WHERE ");
            sql.Append(" PageId IN(" + string.Join(",", pageIds.ToArray()) + ")");
            if (identifier >= 0)
            {
                sql.Append(" AND Identifier=" + identifier.ToString());
            }
            sql.Append(" AND LangCode='" + dbEncode(lang.shortCode) + "'");
            if (category != null)
            {
                sql.Append(" AND CategoryId=" + category.CategoryId);
            }
            sql.Append(" AND Deleted IS NULL");

            if (category != null)
            {
                sql.Append(" ORDER BY PageId DESC");
            }
            else
            {
                sql.Append(" ORDER BY CategoryId DESC");
            }

            if (count > -1)
            {
                sql.Append(" LIMIT " + offset + "," + count + "");
            }
            else
            {
                sql.Append(";");
            }

            DataSet ds = this.RunSelectQuery(sql.ToString());

            if (this.hasRows(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    FileLibraryDetailsData entity = new FileLibraryDetailsData();
                    rowToData(dr, entity);
                    list.Add(entity);
                }
            }
            return(list);
        }
        /// <summary>
        /// Display an error message if event is required, but no event attached.
        /// </summary>
        /// <param name="page"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="fileData"></param>
        /// <returns></returns>
        protected string checkEventAttached(CmsPage page, int identifier, CmsLanguage lang, FileLibraryDetailsData fileData)
        {
            bool eventRequired = fileData.isEventRequired(categoryList);

            if (eventRequired && fileData.EventPageId == -1)
            {
                return(formatErrorMsg(getEventNotAttachedText(lang)));
            }

            return("");
        }
        /// <summary>
        /// Update `FileLibraryDetails` (FileName and CreatedBy will not be changed)
        /// </summary>
        /// <param name="page"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool updateDetailsData(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData entity)
        {
            StringBuilder sql = new StringBuilder("UPDATE ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" SET CategoryId=" + entity.CategoryId.ToString() + ",");
            sql.Append(" Author='" + dbEncode(entity.Author) + "',");
            sql.Append(" Description='" + dbEncode(entity.Description) + "',");
            sql.Append(" LastModified=" + dbEncode(DateTime.Now) + ",");
            sql.Append(" EventPageId=" + entity.EventPageId.ToString());
            sql.Append(" WHERE PageId=" + detailsPage.ID.ToString());
            sql.Append(" AND LangCode='" + lang.shortCode + "'");
            sql.Append(" AND Identifier=" + identifier.ToString());

            int affected = this.RunUpdateQuery(sql.ToString());

            return(affected > 0);
        }
        /// <summary>
        /// Insert file library details data
        /// </summary>
        /// <param name="page"></param>
        /// <param name="identifier"></param>
        /// <param name="lang"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool insertDetailsData(CmsPage detailsPage, int identifier, CmsLanguage lang, FileLibraryDetailsData entity)
        {
            StringBuilder sql = new StringBuilder("INSERT INTO ");

            sql.Append(DETAILS_TABLE);
            sql.Append(" (PageId,Identifier,LangCode,FileName,CategoryId,Author,Description,LastModified,CreatedBy,EventPageId) VALUES (");
            sql.Append(detailsPage.ID.ToString() + ",");
            sql.Append(identifier.ToString() + ",'");
            sql.Append(dbEncode(lang.shortCode) + "','");
            sql.Append(dbEncode(entity.FileName) + "',");
            sql.Append(entity.CategoryId.ToString() + ",'");
            sql.Append(dbEncode(entity.Author) + "','");
            sql.Append(dbEncode(entity.Description) + "',");
            sql.Append(dbEncode(DateTime.Now) + ",'");
            sql.Append(dbEncode(entity.CreatedBy) + "',");
            sql.Append(entity.EventPageId.ToString() + ");");

            int affected = this.RunUpdateQuery(sql.ToString());

            if (affected > 0)
            {
                entity.DetailsPageId = detailsPage.ID;
                entity.Identifier    = identifier;
                entity.Lang          = lang;
                return(detailsPage.setLastUpdatedDateTimeToNow());
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Get the name according to file extension
        /// </summary>
        /// <param name="fileData"></param>
        /// <returns></returns>
        protected string getFileTypeName(FileLibraryDetailsData fileData)
        {
            string ext = System.IO.Path.GetExtension(fileData.FileName);

            return(FileUtils.getFileTypeDescription(ext));
        }
Exemple #22
0
 public static string GetFileStorageDirectoryUrl(CmsPage page, int identifier, CmsLanguage language)
 {
     return(FileLibraryDetailsData.getFileStorageFolderUrl(page, identifier, language));
 }