예제 #1
0
 public void UpdateRepositoryObject(int ItemId, string UserName, RepositoryInfo objRepository)
 {
     DataProvider.Instance().UpdateRepositoryObject(ItemId, UserName, objRepository.Name, objRepository.Description, objRepository.Author, objRepository.AuthorEMail, objRepository.FileSize, objRepository.PreviewImage, objRepository.Image, objRepository.FileName,
                                                    objRepository.Approved, objRepository.ShowEMail, objRepository.Summary, objRepository.SecurityRoles);
 }
예제 #2
0
        private void Page_Load(System.Object sender, System.EventArgs e)
        {
            //Read the querystring params to determine the image to create a thumbnail
            string ImageId        = Request.QueryString["id"];
            string ModuleId       = Request.QueryString["mid"];
            int    imageHeight    = int.TryParse(Request.QueryString["h"], out imageHeight) ? imageHeight : 0;
            int    imageWidth     = int.TryParse(Request.QueryString["w"], out imageWidth) ? imageWidth : 0;
            string strPathToImage = "";
            string strExtension   = "";
            bool   b_UseIcon      = false;
            string sNoImage       = null;
            bool   bIsURL         = false;

            PortalSettings   _portalSettings   = (PortalSettings)HttpContext.Current.Items["PortalSettings"];
            ModuleController _moduleController = new ModuleController();

            RepositoryController repository    = new RepositoryController();
            RepositoryInfo       objRepository = null;

            objRepository = repository.GetSingleRepositoryObject(Convert.ToInt32(ImageId));


            if (!string.IsNullOrEmpty(ImageId))
            {
                if ((objRepository != null))
                {
                    if (string.IsNullOrEmpty(objRepository.Image))
                    {
                        // no image, display an icon or generic image based on module settings
                        var moduleController = new ModuleController();
                        var moduleInfo       = moduleController.GetModule(int.Parse(ModuleId));
                        var settings         = moduleInfo.ModuleSettings;

                        if (!string.IsNullOrEmpty(Convert.ToString(settings["noimage"])))
                        {
                            strPathToImage = _portalSettings.HomeDirectory + Convert.ToString(settings["noimage"]);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(Convert.ToString(settings["useicon"])))
                            {
                                if (Convert.ToString(settings["useicon"]) == "Yes")
                                {
                                    // get the file type
                                    if ((objRepository != null))
                                    {
                                        strExtension = Strings.Replace(Path.GetExtension(objRepository.FileName), ".", "");
                                        if (File.Exists(MapPath(_portalSettings.HomeDirectory + strExtension + ".jpg")))
                                        {
                                            strPathToImage = _portalSettings.HomeDirectory + strExtension + ".jpg";
                                            b_UseIcon      = true;
                                        }
                                        if (File.Exists(MapPath(_portalSettings.HomeDirectory + strExtension + ".gif")))
                                        {
                                            strPathToImage = _portalSettings.HomeDirectory + strExtension + ".gif";
                                            b_UseIcon      = true;
                                        }
                                        if (File.Exists(MapPath(_portalSettings.HomeDirectory + strExtension + ".png")))
                                        {
                                            strPathToImage = _portalSettings.HomeDirectory + strExtension + ".png";
                                            b_UseIcon      = true;
                                        }
                                    }
                                    else
                                    {
                                        strPathToImage = _portalSettings.HomeDirectory + "Repository\\noImage.jpg";
                                    }
                                    if (b_UseIcon == false)
                                    {
                                        strPathToImage = _portalSettings.HomeDirectory + "Repository\\noImage.jpg";
                                    }
                                }
                                else
                                {
                                    strPathToImage = _portalSettings.HomeDirectory + "Repository\\noImage.jpg";
                                }
                            }
                            else
                            {
                                strPathToImage = _portalSettings.HomeDirectory + "Repository\\noImage.jpg";
                            }
                        }
                        strPathToImage = Request.MapPath(strPathToImage);
                    }
                    else
                    {
                        // we have an image, display it
                        if (objRepository.Image.ToLower().StartsWith("fileid="))
                        {
                            strPathToImage = oRepositoryBusinessController.ConvertFileIDtoPath(_portalSettings.PortalId, int.Parse(objRepository.Image.Substring(7)));
                        }
                        else
                        {
                            oRepositoryBusinessController.SetRepositoryFolders(objRepository.ModuleId);
                            if (objRepository.Approved == oRepositoryBusinessController.IS_APPROVED)
                            {
                                if (string.IsNullOrEmpty(objRepository.CreatedByUser))
                                {
                                    strPathToImage = oRepositoryBusinessController.g_AnonymousFolder + "\\" + objRepository.Image;
                                }
                                else
                                {
                                    if (oRepositoryBusinessController.g_UserFolders)
                                    {
                                        strPathToImage = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser.ToString() + "\\" + objRepository.Image;
                                    }
                                    else
                                    {
                                        strPathToImage = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.Image;
                                    }
                                }
                            }
                            else
                            {
                                strPathToImage = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.Image;
                            }
                        }
                    }
                }
            }
            else
            {
                // no image id, then we display the "No Image" image for this module
                var    moduleController = new ModuleController();
                var    moduleInfo       = moduleController.GetModule(int.Parse(ModuleId));
                var    settings         = moduleInfo.ModuleSettings;
                string noImageURL       = Convert.ToString(settings["noimage"]);
                if (System.Text.RegularExpressions.Regex.IsMatch(noImageURL.ToLower(), "(http|https|ftp|gopher)://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?"))
                {
                    strPathToImage = noImageURL;
                    bIsURL         = true;
                }
                else
                {
                    strPathToImage = Server.MapPath(_portalSettings.HomeDirectory + noImageURL);
                }
            }

            // determine the image type
            string imageType = strPathToImage.Substring(strPathToImage.LastIndexOf(".")).ToUpper();

            System.Drawing.Image fullSizeImg = null;
            if (bIsURL)
            {
                System.Net.WebClient wc = new System.Net.WebClient();
                Stream wStream          = null;
                wStream     = wc.OpenRead(strPathToImage);
                fullSizeImg = System.Drawing.Image.FromStream(wStream);
                wStream.Close();
            }
            else
            {
                fullSizeImg = System.Drawing.Image.FromFile(strPathToImage);
            }

            int fullHeight = fullSizeImg.Height;
            int fullWidth  = fullSizeImg.Width;

            if (imageWidth > 0 & imageHeight == 0)
            {
                // calc the height based on the width ratio
                imageHeight = (imageWidth * fullHeight) / fullWidth;
            }

            if (imageHeight > 0 & imageWidth == 0)
            {
                // calc the width based on the height ratio
                imageWidth = (imageHeight * fullWidth) / fullHeight;
            }

            if ((imageHeight == 0 & imageWidth == 0) | b_UseIcon)
            {
                imageHeight = fullHeight;
                imageWidth  = fullWidth;
            }

            Response.Clear();
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            System.Drawing.Image thumbNailImg = null;

            if (imageWidth < fullWidth | imageHeight < fullHeight)
            {
                // we are producing a resized image, most probably a thumbnail

                System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = null;
                dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
                thumbNailImg  = fullSizeImg.GetThumbnailImage(imageWidth, imageHeight, dummyCallBack, IntPtr.Zero);

                switch (imageType)
                {
                case ".JPG":
                    Response.ContentType = "image/jpeg";
                    thumbNailImg.Save(Response.OutputStream, ImageFormat.Jpeg);
                    break;

                case ".GIF":
                    Response.ContentType = "image/gif";
                    thumbNailImg.Save(Response.OutputStream, ImageFormat.Gif);
                    break;

                case ".PNG":
                    MemoryStream stmMemory = new MemoryStream();
                    Response.ContentType = "image/png";
                    thumbNailImg.Save(stmMemory, System.Drawing.Imaging.ImageFormat.Png);
                    stmMemory.WriteTo(Response.OutputStream);
                    break;
                }
            }
            else
            {
                // we are serving out the full size image
                // if the settings indicate to use a watermark, add the watermark to the image
                var moduleController = new ModuleController();
                var moduleInfo       = moduleController.GetModule(int.Parse(ModuleId));
                var settings         = moduleInfo.ModuleSettings;

                string watermarkText = "";

                // to avoid GIF image issues, create a new blank canvas and copy the image.
                Bitmap   newImage = new Bitmap(fullSizeImg.Width, fullSizeImg.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                Graphics canvas   = Graphics.FromImage(newImage);
                canvas.DrawImage(fullSizeImg, new Rectangle(new Point(0, 0), fullSizeImg.Size));

                // check to see if we need to overlay a watermark

                if (!string.IsNullOrEmpty(Convert.ToString(settings["watermark"])))
                {
                    watermarkText = Convert.ToString(settings["watermark"]);

                    SizeF StringSizeF      = default(SizeF);
                    float DesiredWidth     = 0;
                    Font  wmFont           = null;
                    float RequiredFontSize = 0;
                    float Ratio            = 0;
                    wmFont       = new Font("Verdana", 6, FontStyle.Bold);
                    DesiredWidth = fullSizeImg.Width * 0.75f;

                    StringSizeF      = canvas.MeasureString(watermarkText, wmFont);
                    Ratio            = StringSizeF.Width / wmFont.SizeInPoints;
                    RequiredFontSize = DesiredWidth / Ratio;
                    wmFont           = new Font("Verdana", RequiredFontSize, FontStyle.Bold);

                    int wmLeft = (newImage.Width - canvas.MeasureString(watermarkText, wmFont).ToSize().Width) / 2;
                    int wmTop  = (newImage.Height - canvas.MeasureString(watermarkText, wmFont).ToSize().Height) / 2;

                    canvas.DrawString(watermarkText, wmFont, new SolidBrush(Color.FromArgb(128, 255, 255, 255)), wmLeft, wmTop);
                }

                switch (imageType)
                {
                case ".JPG":
                    Response.ContentType = "image/jpeg";
                    newImage.Save(Response.OutputStream, ImageFormat.Jpeg);
                    break;

                case ".GIF":
                    Response.ContentType = "image/gif";
                    newImage.Save(Response.OutputStream, ImageFormat.Gif);
                    break;

                case ".PNG":
                    MemoryStream stmMemory = new MemoryStream();
                    Response.ContentType = "image/png";
                    newImage.Save(stmMemory, System.Drawing.Imaging.ImageFormat.Png);
                    stmMemory.WriteTo(Response.OutputStream);
                    break;
                }
            }
        }
예제 #3
0
 public int AddRepositoryObject(string UserName, int ModuleId, RepositoryInfo objRepository)
 {
     return(Convert.ToInt32(DataProvider.Instance().AddRepositoryObject(UserName, ModuleId, objRepository.Name, objRepository.Description, objRepository.Author, objRepository.AuthorEMail, objRepository.FileSize, objRepository.PreviewImage, objRepository.Image, objRepository.FileName,
                                                                        objRepository.Approved, objRepository.ShowEMail, objRepository.Summary, objRepository.SecurityRoles)));
 }
예제 #4
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be imported</param>
        /// <history>
        ///		[cnurse]	11/17/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            string catString = null;

            string[] aCategories   = null;
            string   thisCategory  = null;
            int      newCategoryID = 0;
            int      newItemID     = 0;

            System.Collections.Specialized.NameValueCollection categoryMapping = new System.Collections.Specialized.NameValueCollection();
            System.Collections.Specialized.NameValueCollection objectMapping   = new System.Collections.Specialized.NameValueCollection();

            XmlNode xmlDocuments = DotNetNuke.Common.Globals.GetContent(Content, "repository");

            RepositoryController                 RepositoryController         = new RepositoryController();
            RepositoryCategoryController         CategoryController           = new RepositoryCategoryController();
            RepositoryObjectCategoriesController RepositoryCategoryController = new RepositoryObjectCategoriesController();
            RepositoryCommentController          RepositoryCommentController  = new RepositoryCommentController();

            RepositoryObjectCategoriesInfo RepositoryCategory = null;
            RepositoryCommentInfo          RepositoryComment  = null;

            // clear out any existing categories
            foreach (RepositoryCategoryInfo cat in CategoryController.GetRepositoryCategories(ModuleID, -1))
            {
                CategoryController.DeleteRepositoryCategory(cat.ItemId);
            }

            // add the categories
            foreach (XmlNode xmlDocument in xmlDocuments.SelectNodes("category"))
            {
                RepositoryCategoryInfo objCategory = new RepositoryCategoryInfo();
                objCategory.ItemId    = 0;
                objCategory.ModuleId  = ModuleID;
                objCategory.Category  = xmlDocument["category"].InnerText;
                objCategory.Parent    = int.Parse(xmlDocument["parent"].InnerText);
                objCategory.ViewOrder = int.Parse(xmlDocument["vieworder"].InnerText);
                objCategory.Count     = int.Parse(xmlDocument["count"].InnerText);
                if (objCategory.Parent == -1)
                {
                    newCategoryID = CategoryController.AddRepositoryCategory(0, objCategory.ModuleId, objCategory.Category, objCategory.Parent, objCategory.ViewOrder);
                }
                else
                {
                    newCategoryID = CategoryController.AddRepositoryCategory(0, objCategory.ModuleId, objCategory.Category, int.Parse(categoryMapping[objCategory.Parent.ToString()]), objCategory.ViewOrder);
                }
                categoryMapping.Add(xmlDocument["itemid"].InnerText, newCategoryID.ToString());
            }

            // add each item
            foreach (XmlNode xmlDocument in xmlDocuments.SelectNodes("item"))
            {
                RepositoryInfo objDocument = new RepositoryInfo();
                objDocument.ItemId        = 0;
                objDocument.ModuleId      = ModuleID;
                objDocument.CreatedByUser = xmlDocument["createdbyuser"].InnerText;
                objDocument.CreatedDate   = System.DateTime.Parse(xmlDocument["createddate"].InnerText);
                objDocument.UpdatedByUser = xmlDocument["updatedbyuser"].InnerText;
                objDocument.UpdatedDate   = System.DateTime.Parse(xmlDocument["updateddate"].InnerText);
                objDocument.Name          = xmlDocument["name"].InnerText;
                objDocument.Description   = xmlDocument["description"].InnerText;
                objDocument.Author        = xmlDocument["author"].InnerText;
                objDocument.AuthorEMail   = xmlDocument["authoremail"].InnerText;
                objDocument.FileSize      = xmlDocument["filesize"].InnerText;
                objDocument.Downloads     = int.Parse(xmlDocument["downloads"].InnerText);
                objDocument.PreviewImage  = xmlDocument["previewimage"].InnerText;
                objDocument.Image         = xmlDocument["image"].InnerText;
                objDocument.FileName      = xmlDocument["filename"].InnerText;
                objDocument.Clicks        = int.Parse(xmlDocument["clicks"].InnerText);
                objDocument.RatingVotes   = long.Parse(xmlDocument["ratingvotes"].InnerText);
                objDocument.RatingTotal   = long.Parse(xmlDocument["ratingtotal"].InnerText);
                objDocument.RatingAverage = double.Parse(xmlDocument["ratingaverage"].InnerText);
                objDocument.CommentCount  = int.Parse(xmlDocument["commentcount"].InnerText);
                objDocument.Approved      = int.Parse(xmlDocument["approved"].InnerText);
                objDocument.ShowEMail     = int.Parse(xmlDocument["showemail"].InnerText);
                objDocument.Summary       = xmlDocument["summary"].InnerText;
                objDocument.SecurityRoles = xmlDocument["securityroles"].InnerText;
                newItemID = RepositoryController.AddRepositoryObject(objDocument.UpdatedByUser.ToString(), ModuleID, objDocument);
                objectMapping.Add(xmlDocument["itemid"].InnerText, newItemID.ToString());
            }

            // add new items to new categories
            foreach (XmlNode xmlCatDocument in xmlDocuments.SelectNodes("item/categories/category"))
            {
                RepositoryCategory            = new RepositoryObjectCategoriesInfo();
                RepositoryCategory.ItemID     = 0;
                RepositoryCategory.CategoryID = int.Parse(categoryMapping[xmlCatDocument["categoryid"].InnerText]);
                RepositoryCategory.ObjectID   = int.Parse(objectMapping[xmlCatDocument["objectid"].InnerText]);
                RepositoryCategoryController.AddRepositoryObjectCategories(RepositoryCategory);
            }

            // add any comments
            foreach (XmlNode xmlComDocument in xmlDocuments.SelectNodes("item/comments/comment"))
            {
                RepositoryComment               = new RepositoryCommentInfo();
                RepositoryComment.ItemId        = 0;
                RepositoryComment.ObjectId      = int.Parse(objectMapping[xmlComDocument["objectid"].InnerText]);
                RepositoryComment.CreatedByUser = xmlComDocument["createdbyuser"].InnerText;
                RepositoryComment.CreatedDate   = System.DateTime.Parse(xmlComDocument["createddate"].InnerText);
                RepositoryComment.Comment       = xmlComDocument["comment"].InnerText;
                RepositoryCommentController.AddRepositoryComment(0, ModuleID, RepositoryComment.CreatedByUser, RepositoryComment.Comment);
            }
        }
예제 #5
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ExportModule implements the IPortable ExportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be exported</param>
        /// <history>
        ///		[cnurse]	11/17/2004	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        public string ExportModule(int ModuleID)
        {
            string strXML = "";

            oRepositoryBusinessController = new Helpers();

            Entities.Modules.ModuleController objModules = new Entities.Modules.ModuleController();
            Entities.Modules.ModuleInfo       objModule  = objModules.GetModule(ModuleID, Null.NullInteger);

            RepositoryObjectCategoriesController RepositoryItemCategoryController = new RepositoryObjectCategoriesController();
            ArrayList RepositoryItemCategories = null;

            RepositoryCommentController CommentController = new RepositoryCommentController();
            ArrayList Comments = null;

            ArrayList RepositoryObjects = GetRepositoryObjects(ModuleID, "", "Name", oRepositoryBusinessController.IS_APPROVED, -1, "", -1);

            if (RepositoryObjects.Count != 0)
            {
                strXML += "<repository>";

                RepositoryInfo objDocument = null;
                foreach (RepositoryInfo objDocument_loopVariable in RepositoryObjects)
                {
                    objDocument = objDocument_loopVariable;
                    strXML     += "<item>";
                    strXML     += "<itemid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.ItemId.ToString()) + "</itemid>";
                    strXML     += "<moduleid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.ModuleId.ToString()) + "</moduleid>";
                    strXML     += "<createdbyuser>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.CreatedByUser) + "</createdbyuser>";
                    strXML     += "<createddate>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.CreatedDate.ToString()) + "</createddate>";
                    strXML     += "<updatedbyuser>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.UpdatedByUser) + "</updatedbyuser>";
                    strXML     += "<updateddate>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.UpdatedDate.ToString()) + "</updateddate>";
                    strXML     += "<name>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.Name) + "</name>";
                    strXML     += "<description>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.Description) + "</description>";
                    strXML     += "<author>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.Author) + "</author>";
                    strXML     += "<authoremail>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.AuthorEMail) + "</authoremail>";
                    strXML     += "<filesize>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.FileSize) + "</filesize>";
                    strXML     += "<downloads>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.Downloads.ToString()) + "</downloads>";
                    strXML     += "<previewimage>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.PreviewImage) + "</previewimage>";
                    strXML     += "<image>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.Image) + "</image>";
                    strXML     += "<filename>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.FileName) + "</filename>";
                    strXML     += "<clicks>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.Clicks.ToString()) + "</clicks>";
                    strXML     += "<ratingvotes>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.RatingVotes.ToString()) + "</ratingvotes>";
                    strXML     += "<ratingtotal>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.RatingTotal.ToString()) + "</ratingtotal>";
                    strXML     += "<ratingaverage>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.RatingAverage.ToString()) + "</ratingaverage>";
                    strXML     += "<commentcount>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.CommentCount.ToString()) + "</commentcount>";
                    strXML     += "<approved>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.Approved.ToString()) + "</approved>";
                    strXML     += "<showemail>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.ShowEMail.ToString()) + "</showemail>";
                    strXML     += "<summary>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.Summary) + "</summary>";
                    strXML     += "<securityroles>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objDocument.SecurityRoles) + "</securityroles>";

                    Comments = CommentController.GetRepositoryComments(objDocument.ItemId, ModuleID);
                    strXML  += "<comments>";
                    foreach (RepositoryCommentInfo comment in Comments)
                    {
                        strXML += "<comment>";
                        strXML += "<itemid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(comment.ItemId.ToString()) + "</itemid>";
                        strXML += "<createdbyuser>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(comment.CreatedByUser) + "</createdbyuser>";
                        strXML += "<createddate>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(comment.CreatedDate.ToString()) + "</createddate>";
                        strXML += "<objectid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(comment.ObjectId.ToString()) + "</objectid>";
                        strXML += "<comment>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(comment.Comment) + "</comment>";
                        strXML += "</comment>";
                    }
                    strXML += "</comments>";

                    RepositoryItemCategories = RepositoryItemCategoryController.GetRepositoryObjectCategories(objDocument.ItemId);
                    strXML += "<categories>";
                    foreach (RepositoryObjectCategoriesInfo cat in RepositoryItemCategories)
                    {
                        strXML += "<category>";
                        strXML += "<itemid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(cat.ItemID.ToString()) + "</itemid>";
                        strXML += "<objectid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(cat.ObjectID.ToString()) + "</objectid>";
                        strXML += "<categoryid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(cat.CategoryID.ToString()) + "</categoryid>";
                        strXML += "</category>";
                    }
                    strXML += "</categories>";

                    strXML += "</item>";
                }

                RepositoryCategoryController CategoryController = new RepositoryCategoryController();
                ArrayList Arr        = CategoryController.GetRepositoryCategories(ModuleID, -1);
                ArrayList categories = new ArrayList();
                oRepositoryBusinessController.AddCategoryToArrayList(ModuleID, -1, Arr, ref categories);

                foreach (RepositoryCategoryInfo objCategory in categories)
                {
                    strXML += "<category>";
                    strXML += "<itemid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objCategory.ItemId.ToString()) + "</itemid>";
                    strXML += "<moduleid>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objCategory.ModuleId.ToString()) + "</moduleid>";
                    strXML += "<category>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objCategory.Category.ToString()) + "</category>";
                    strXML += "<parent>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objCategory.Parent.ToString()) + "</parent>";
                    strXML += "<vieworder>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objCategory.ViewOrder.ToString()) + "</vieworder>";
                    strXML += "<count>" + DotNetNuke.Common.Utilities.XmlUtils.XMLEncode(objCategory.Count.ToString()) + "</count>";
                    strXML += "</category>";
                }

                strXML += "</repository>";
            }

            return(strXML);
        }
        private void lstObjects_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            Table          objTable        = null;
            LinkButton     objDownloadLink = null;
            ImageButton    objImageButton  = null;
            Button         objButton       = null;
            Label          objLabel        = null;
            Label          lblDetails      = null;
            HyperLink      objHyperLink    = null;
            RepositoryInfo objRepository   = null;

            var       mc       = new ModuleController();
            var       mi       = mc.GetModule(ModuleId);
            Hashtable settings = mi.ModuleSettings;


            if (e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem)
            {
                objRepository = new RepositoryInfo();
                objRepository = e.Item.DataItem as RepositoryInfo;

                objTable = (Table)e.Item.Cells[0].FindControl("ItemButtonTable");

                objDownloadLink      = (LinkButton)objTable.Rows[0].Cells[0].FindControl("btnViewFile");
                objDownloadLink.Text = Localization.GetString("ViewFile", LocalResourceFile);
                if (objRepository.FileName.ToString().Length == 0)
                {
                    objDownloadLink.Visible = false;
                }

                objDownloadLink      = (LinkButton)objTable.Rows[0].Cells[0].FindControl("btnApprove");
                objDownloadLink.Text = Localization.GetString("ApproveFile", LocalResourceFile);

                objDownloadLink      = (LinkButton)objTable.Rows[0].Cells[0].FindControl("btnReject");
                objDownloadLink.Text = Localization.GetString("RejectFile", LocalResourceFile);

                objTable = (Table)e.Item.Cells[0].FindControl("ItemDetailsTable");

                objHyperLink             = (HyperLink)objTable.Rows[0].Cells[0].FindControl("hlImage");
                objHyperLink.Target      = "_blank";
                objHyperLink.NavigateUrl = oRepositoryBusinessController.FormatImageURL(objRepository.ItemId.ToString());
                objHyperLink.ImageUrl    = oRepositoryBusinessController.FormatPreviewImageURL(objRepository.ItemId, ModuleId, 150);

                objLabel      = (Label)objTable.Rows[0].Cells[0].FindControl("lbClickToView");
                objLabel.Text = Localization.GetString("ClickToView", LocalResourceFile);

                if (objRepository.Image.ToString().Length == 0)
                {
                    objLabel.Visible                = false;
                    objHyperLink.Visible            = false;
                    objTable.Rows[0].Cells[0].Width = System.Web.UI.WebControls.Unit.Pixel(0);
                }
                else
                {
                    objLabel.Visible                = true;
                    objHyperLink.Visible            = true;
                    objTable.Rows[0].Cells[0].Width = System.Web.UI.WebControls.Unit.Pixel(150);
                }

                lblDetails = (Label)objTable.Rows[0].Cells[0].FindControl("lblItemDetails");

                if (objRepository.Author.ToString().Length > 0)
                {
                    lblDetails.Text = "<span class='SubHead'>" + Localization.GetString("Author", LocalResourceFile) + " </span>" + objRepository.Author.ToString() + "<br>";
                }
                if (objRepository.AuthorEMail.ToString().Length > 0)
                {
                    lblDetails.Text += "<span class='SubHead'>" + Localization.GetString("AuthorEMail", LocalResourceFile) + " </span><a href='mailto:" + objRepository.AuthorEMail.ToString() + "'>" + objRepository.AuthorEMail.ToString() + "</a><br><br>";
                }
                else
                {
                    if (objRepository.Author.ToString().Length > 0)
                    {
                        lblDetails.Text += "<br>";
                    }
                }

                if (objRepository.FileSize.ToString() != "0")
                {
                    lblDetails.Text += "<span class='SubHead'>" + Localization.GetString("FileSize", LocalResourceFile) + " </span>" + objRepository.FileSize.ToString() + "<br>";
                }

                if (objRepository.Downloads.ToString() != "0")
                {
                    lblDetails.Text += "<span class='SubHead'>" + Localization.GetString("Downloads", LocalResourceFile) + " </span>" + objRepository.Downloads.ToString() + "<br><br>";
                }
                lblDetails.Text += "<span class='SubHead'>" + Localization.GetString("Created", LocalResourceFile) + " </span>" + objRepository.CreatedDate.ToString() + "<br>";
                lblDetails.Text += "<span class='SubHead'>" + Localization.GetString("Updated", LocalResourceFile) + " </span>" + objRepository.UpdatedDate.ToString() + "<br><br>";

                if (objRepository.Description.ToString().Length > 0)
                {
                    lblDetails.Text += "<span class='SubHead'>" + Localization.GetString("Description", LocalResourceFile) + " </span><br>" + objRepository.Description.ToString();
                }
                else
                {
                    lblDetails.Text += "<span class='SubHead'>" + Localization.GetString("Description", LocalResourceFile) + " </span><br>No description";
                }

                objTable = (Table)e.Item.Cells[0].FindControl("tblReject");

                objLabel      = (Label)objTable.Rows[0].Cells[0].FindControl("lbRejectionReason");
                objLabel.Text = Localization.GetString("RejectionReason", LocalResourceFile);

                objButton      = (Button)objTable.Rows[0].Cells[0].FindControl("btnSendRejection");
                objButton.Text = Localization.GetString("SendRejection", LocalResourceFile);
            }
        }
        private void lstObjects_ItemCommand1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            Table       objTable          = null;
            Table       objRejectionTable = null;
            Label       objLabel          = null;
            ImageButton objImageButton    = null;
            DataList    objDataList       = null;
            bool        bMovedFile        = false;
            bool        bMovedImage       = false;

            objTable          = (Table)e.Item.Cells[0].FindControl("ItemDetailsTable");
            objRejectionTable = (Table)objTable.Rows[0].Cells[0].FindControl("tblReject");

            RepositoryController        repository         = new RepositoryController();
            RepositoryCommentController repositoryComments = new RepositoryCommentController();
            RepositoryInfo objRepository = repository.GetSingleRepositoryObject(int.Parse(e.CommandArgument.ToString()));

            string sFileName  = null;
            string sImageName = null;

            try {
                sFileName  = objRepository.FileName;
                sImageName = objRepository.Image;
            } catch (Exception ex) {
                sFileName  = string.Empty;
                sImageName = string.Empty;
            }

            if (sFileName.ToLower().StartsWith("fileid="))
            {
                sFileName = oRepositoryBusinessController.ConvertFileIDtoFileName(PortalId, int.Parse(objRepository.FileName.Substring(7)));
            }
            if (sImageName.ToLower().StartsWith("fileid="))
            {
                sImageName = oRepositoryBusinessController.ConvertFileIDtoFileName(PortalId, int.Parse(objRepository.Image.Substring(7)));
            }

            switch (e.CommandName)
            {
            case "ViewFile":
                // admin wants to view the file
                oRepositoryBusinessController.DownloadFile(e.CommandArgument.ToString());

                break;

            case "Approve":
                repository.ApproveRepositoryObject(objRepository.ItemId);
                string strSourceFilename = "";
                string strImageFilename  = "";
                string strTargetFilename = "";
                oRepositoryBusinessController.SetRepositoryFolders(ModuleId);

                bMovedFile  = false;
                bMovedImage = false;

                // if this is an anonymous upload, move the file to the Anonymous folder,
                // otherwise, move it to the user's folder
                if (!objRepository.FileName.ToLower().StartsWith("fileid="))
                {
                    try {
                        strSourceFilename = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.FileName.ToString();
                        if (string.IsNullOrEmpty(objRepository.CreatedByUser))
                        {
                            strTargetFilename = oRepositoryBusinessController.g_AnonymousFolder + "\\" + objRepository.FileName.ToString();
                        }
                        else
                        {
                            if (oRepositoryBusinessController.g_UserFolders)
                            {
                                if (!Directory.Exists(oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser))
                                {
                                    Directory.CreateDirectory(oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser);
                                }
                                strTargetFilename = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser + "\\" + objRepository.FileName.ToString();
                            }
                            else
                            {
                                strTargetFilename = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.FileName.ToString();
                            }
                        }
                        if (strSourceFilename != strTargetFilename)
                        {
                            File.Copy(strSourceFilename, strTargetFilename, true);
                            File.SetAttributes(strSourceFilename, FileAttributes.Normal);
                            File.Delete(strSourceFilename);
                            bMovedFile = true;
                        }
                    } catch (Exception ex) {
                    }
                }

                if (!objRepository.Image.ToLower().StartsWith("fileid="))
                {
                    // move the image file from the Pending folder to the Users folder
                    try {
                        strImageFilename = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.Image.ToString();
                        if (string.IsNullOrEmpty(objRepository.CreatedByUser))
                        {
                            strTargetFilename = oRepositoryBusinessController.g_AnonymousFolder + "\\" + objRepository.Image.ToString();
                        }
                        else
                        {
                            if (oRepositoryBusinessController.g_UserFolders)
                            {
                                if (!Directory.Exists(oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser))
                                {
                                    Directory.CreateDirectory(oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser);
                                }
                                strTargetFilename = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.CreatedByUser + "\\" + objRepository.Image.ToString();
                            }
                            else
                            {
                                strTargetFilename = oRepositoryBusinessController.g_ApprovedFolder + "\\" + objRepository.Image.ToString();
                            }
                        }
                        if (strImageFilename != strTargetFilename)
                        {
                            File.Copy(strImageFilename, strTargetFilename, true);
                            File.SetAttributes(strImageFilename, FileAttributes.Normal);
                            File.Delete(strImageFilename);
                            bMovedImage = true;
                        }
                    } catch (Exception ex) {
                    }
                }

                UserInfo objModerator = UserController.Instance.GetCurrentUserInfo();
                string   strBody      = "";
                if (((objRepository != null)) & ((objModerator != null)))
                {
                    if (!string.IsNullOrEmpty(objRepository.AuthorEMail.ToString()))
                    {
                        strBody = objRepository.Author.ToString() + "," + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("TheFile", LocalResourceFile) + " (" + sFileName + ") " + Localization.GetString("ThatYouUploadedTo", LocalResourceFile) + " " + PortalSettings.PortalName + " " + Localization.GetString("HasBeenApprovedShort", LocalResourceFile) + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("PortalAddress", LocalResourceFile) + ": " + DotNetNuke.Common.Globals.GetPortalDomainName(PortalAlias.HTTPAlias, Request, false) + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("ThankYou", LocalResourceFile) + Constants.vbCrLf;
                        DotNetNuke.Services.Mail.Mail.SendMail(objModerator.Email, objRepository.AuthorEMail, "", PortalSettings.PortalName + ": " + Localization.GetString("HasBeenApprovedLong", LocalResourceFile), strBody, "", "html", "", "", "",
                                                               "");
                    }
                }

                BindObjectList();

                // sometimes IIS doesn't release a file immediately. So, if we get here and the original
                // source file still exits, try to delete it one more time before we leave.
                if (bMovedFile)
                {
                    try {
                        File.SetAttributes(strSourceFilename, FileAttributes.Normal);
                        File.Delete(strSourceFilename);
                    } catch (Exception ex) {
                    }
                }
                if (bMovedImage)
                {
                    try {
                        File.SetAttributes(strImageFilename, FileAttributes.Normal);
                        File.Delete(strImageFilename);
                    } catch (Exception ex) {
                    }
                }

                break;

            case "Reject":
                if (objRejectionTable.Visible == false)
                {
                    objRejectionTable.Visible = true;
                }
                else
                {
                    objRejectionTable.Visible = false;
                }

                break;

            case "SendRejection":
                UserInfo objSendRejectionModerator = UserController.Instance.GetCurrentUserInfo();
                strBody = "";
                TextBox txtComment       = null;
                string  strFileName      = null;
                string  strImageFileName = null;
                txtComment = (TextBox)objRejectionTable.Rows[1].Cells[0].FindControl("txtReason");
                if (((objRepository != null)) & ((objSendRejectionModerator != null)))
                {
                    if (!string.IsNullOrEmpty(objRepository.AuthorEMail.ToString()))
                    {
                        strBody = objRepository.Author.ToString() + "," + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("TheFile", LocalResourceFile) + " (" + sFileName + ") " + Localization.GetString("ThatYouUploadedTo", LocalResourceFile) + " " + PortalSettings.PortalName + " " + Localization.GetString("HasBeenRejectedShort", LocalResourceFile) + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + Localization.GetString("PortalAddress", LocalResourceFile) + ": " + DotNetNuke.Common.Globals.GetPortalDomainName(PortalAlias.HTTPAlias, Request, false) + Constants.vbCrLf + Constants.vbCrLf;
                        strBody = strBody + txtComment.Text + Constants.vbCrLf + Constants.vbCrLf;
                        DotNetNuke.Services.Mail.Mail.SendMail(objSendRejectionModerator.Email, objRepository.AuthorEMail, "", PortalSettings.PortalName + ": " + Localization.GetString("HasBeenRejectedLong", LocalResourceFile), strBody, "", "html", "", "", "",
                                                               "");
                    }
                }

                // delete the files
                if (!objRepository.FileName.ToLower().StartsWith("fileid="))
                {
                    try {
                        strTargetFilename = "";
                        oRepositoryBusinessController.SetRepositoryFolders(ModuleId);
                        if (!string.IsNullOrEmpty(objRepository.FileName))
                        {
                            strFileName = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.FileName.ToString();
                            if (File.Exists(strFileName))
                            {
                                File.SetAttributes(strFileName, FileAttributes.Normal);
                                File.Delete(strFileName);
                            }
                        }
                    } catch (Exception ex) {
                    }
                }

                if (!objRepository.Image.ToLower().StartsWith("fileid="))
                {
                    try {
                        if (!string.IsNullOrEmpty(objRepository.Image))
                        {
                            strFileName = oRepositoryBusinessController.g_UnApprovedFolder + "\\" + objRepository.Image.ToString();
                            if (File.Exists(strFileName))
                            {
                                File.SetAttributes(strFileName, FileAttributes.Normal);
                                File.Delete(strFileName);
                            }
                        }
                    } catch (Exception ex) {
                    }
                }

                repository.DeleteRepositoryObject(objRepository.ItemId);
                BindObjectList();

                break;
            }
        }