private string GetAlbumName(int picID)
        {
            var t = new Item();
            var tc = new ItemController();
            t = tc.GetItem(picID, ModuleId);
            return t.ItemTitle;

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                // Add confirmation to Multiple Delete Button
                ClientAPI.AddButtonConfirm(btnDeleteSelected, Localization.GetString("ConfirmMultiDelete", LocalResourceFile));

                if (!Page.IsPostBack)
                {
                    //check if we have an ID passed in via a querystring parameter, if so, load that item to edit.
                    //ItemId is defined in the ItemModuleBase.cs file
                    if (ItemId > 0)
                    {
                        //Set multi panel view false
                        SetPanels(false);
                        LoadSingleView();

                        var tc = new ItemController();
                        //get 1 item
                        var t = tc.GetItem(ItemId, ModuleId);
                        if (t != null)
                        {
                            imgDisplayPhoto.ImageUrl = "~/" + Settings["BaseFolderPath"].ToString() + "/thm_" + t.ItemFileName;
                            txtTitle.Text = t.ItemTitle;
                            txtFileName.Text = t.ItemFileName;
                            txtDescription.Text = t.ItemDescription;

                            if (t.AlbumID != 0) ddlAlbumID.SelectedValue = t.AlbumID.ToString();
                            else ddlAlbumID.SelectedValue = "0";

                            if (t.ItemKind == "album") rblItemKind.SelectedIndex = 1;
                            else rblItemKind.SelectedIndex = 0;

                            txtThisPictureID.Text = t.ItemId.ToString();
                        }
                    }
                    else
                    {
                        //No ID so display all the pictures
                        LoadGalleryList();
                        LoadAlbumList();
                        SetPanels(true);
                    }
                }
                else
                {
                    //page is a postback.
                    //Cancel and Submit commands should come here.
                    //set panels and buttons
                    SetPanels(true);
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected void RecreateThumbnails()
        {
            //Get all items from db
            var tc = new ItemController();
            IEnumerable<Item> dblist = tc.GetItems(ModuleId);
            foreach (Item picture in dblist)
            {
                string thumbName = "thm_" + picture.ItemFileName;
                //replace old thumbnail with new thumbnail
                // Get image
                System.Drawing.Image image = System.Drawing.Image.FromFile(PicturePath + "\\"+ picture.ItemFileName);

                //Delete thumbnail




                float x = image.Width;
                float y = image.Height;
                float scale = x / y;
                int newx = 120;
                int newy = Convert.ToInt32(120 / scale);
                if (newy > 120)
                {
                    newy = 120;
                    newx = Convert.ToInt32(120 * scale);
                }
                //create thumbnail
                System.Drawing.Image thumb = image.GetThumbnailImage(newx, newy, () => false, IntPtr.Zero);
                thumb.Save(PicturePath + "\\thm_" + picture.ItemFileName);



            }
            

        }
        protected void RescanDirectory()
        {
            //Increase timeout
            Server.ScriptTimeout = 600;

            //get list of files
            IEnumerable<FileInfo> filelist = FileUtility.GetSafeFileList(PicturePath, GetExcludedFiles(), GetSortOrder());

            int filelistcount = filelist.Count();
            //If there are any process them
            if (filelistcount > 0)
            {
                //get list from db
                var tc = new ItemController();
                IEnumerable<Item> dblist = tc.GetItems(ModuleId);

                foreach (FileInfo file in filelist)
                {
                    bool isinDB = false;

                    //see if this file is in dm
                    foreach (Item picture in dblist)
                    {
                        if (file.FileName.Contains("thm_") || file.FileName == picture.ItemFileName)
                        {
                            isinDB = true;
                            break;
                        }
                    }
                    if (!isinDB)  //picture is not in db so add it and create thumbnail
                    {
                        Item addPic = new Item();
                        //check for bad filename
                        string goodFileName = RemoveCharactersFromString(file.FileName," '&#<>");
                        if(goodFileName != file.FileName)
                        {
                            //rename the file and use goodfilename instead of file.filename

                            string myPath = Server.MapPath("portals/" + PortalId + "/Gallery/Nano/" + ModuleId + "/");
                            string myOldPath = myPath + file.FileName;
                            string myNewPath = myPath + goodFileName;

                            System.IO.FileInfo f = new System.IO.FileInfo(myOldPath);

                            f.CopyTo(myNewPath);

                            f.Delete();

                        }
                        addPic.ItemFileName = goodFileName;
                        addPic.ItemTitle = goodFileName;
                        addPic.ItemKind = "";
                        addPic.AlbumID = 0;
                        addPic.ItemDescription = "New Picture";
                        addPic.CreatedOnDate = DateTime.Now;
                        addPic.LastModifiedOnDate = DateTime.Now;
                        addPic.LastModifiedByUserId = UserId;
                        addPic.ModuleId = ModuleId;

                        //add to db
                        var tc1 = new ItemController();
                        tc1.CreateItem(addPic);

                        // Get image
                        System.Drawing.Image image = System.Drawing.Image.FromFile(PicturePath + "\\" + goodFileName);

                        float x = image.Width;
                        float y = image.Height;
                        float scale = x / y;
                        int newx = 120;
                        int newy = Convert.ToInt32(120 / scale);
                        if (newy > 120)
                        {
                            newy = 120;
                            newx = Convert.ToInt32(120 * scale);
                        }
                        //create thumbnail
                        System.Drawing.Image thumb = image.GetThumbnailImage(newx, newy, () => false, IntPtr.Zero);
                        thumb.Save(PicturePath + "\\thm_" + goodFileName);
                    }
                }
            }
            //Reload page
            Response.Redirect(DotNetNuke.Common.Globals.NavigateURL());
        }
        private void WriteOutnanoGalleryConstructors()
        {
            //Create the javascript
            var sb = new StringBuilder();

            sb.Append("<script>");
            sb.Append(Environment.NewLine);
            sb.Append("$(document).ready(function (){ ");
            sb.Append(Environment.NewLine);
            string contentNameID = "contentGalleryMLN" + ModuleId.ToString();
            sb.Append("var " + contentNameID + "=[");
            sb.Append(Environment.NewLine);

            // get items for this module from db
            var tc = new ItemController();
            IEnumerable<Item> dblist = tc.GetItems(ModuleId);   // Get all the items for this module from DB

            int _items = dblist.Count();                       //get number of pictures
            if (_items > 0)                               //If there are any process them
            {
                for (int ii = 0; ii < _items; ii++)
                {
                    Item _picture = new Item();
                    //get a single item
                    _picture = dblist.ElementAt(ii);               
                    sb.Append("{src:'" + _picture.ItemFileName + "',");
                    sb.Append("srct:'thm_" + _picture.ItemFileName + "',");
                    sb.Append("title: '" + _picture.ItemTitle + "',");
                    sb.Append("description: '" + _picture.ItemDescription + "',");
                    sb.Append("ID: " + _picture.ItemId.ToString() + ",");
                    if (_picture.AlbumID != 0) sb.Append("albumID: " + _picture.AlbumID.ToString() + ",");
                    if (_picture.ItemKind == "album") sb.Append("kind: '" + _picture.ItemKind + "'");
                    sb.Append("},"); //close item definition  //add a comma after the } to add more items
                    sb.Append(Environment.NewLine);
                }
            }
            //close array list
            sb.Append("];");                     
            sb.Append(Environment.NewLine);

            //Add gallery settings
            string divNameID = "\"#nanoGalleryMLN" + ModuleId.ToString() + "\"";
            sb.Append("jQuery(" + divNameID + ").nanoGallery({");
            sb.Append(Environment.NewLine);
            sb.Append("items: " + contentNameID + ",");
            if (Settings.Contains("ThumbnailWidth")) sb.Append("thumbnailWidth: " + Settings["ThumbnailWidth"].ToString() + ",");
            if (Settings.Contains("ThumbnailHeight")) sb.Append("thumbnailHeight: " + Settings["ThumbnailHeight"].ToString() + ",");
            if (Settings.Contains("MaxItemsPerLine")) sb.Append("maxItemsPerLine: " + Settings["MaxItemsPerLine"].ToString() + ",");
            if (Settings.Contains("PaginationMaxLinesPerPage")) sb.Append("paginationMaxLinesPerPage: " + Settings["PaginationMaxLinesPerPage"].ToString() + ",");
            if (Settings.Contains("Theme")) sb.Append("theme: " + Settings["Theme"].ToString() + ",");
            if (Settings.Contains("BreadcrumbAutoHideTopLevel")) sb.Append("breadcrumbAutoHideTopLevel: " + Settings["BreadcrumbAutoHideTopLevel"].ToString() + ",");
            if (Settings.Contains("ThumbnailHoverEffect1"))
            {
                if (Settings["ThumbnailHoverEffect1"].ToString() != "none")
                {
                    sb.Append("thumbnailHoverEffect: '");

                    if (Settings["ThumbnailHoverEffect1"].ToString() != "none")
                    {
                        sb.Append(Settings["ThumbnailHoverEffect1"].ToString());
                    }
                    if (Settings["ThumbnailHoverEffect2"].ToString() != "none" && Settings["ThumbnailHoverEffect1"].ToString() != "none")
                    {
                        sb.Append("," + Settings["ThumbnailHoverEffect2"].ToString());
                    }
                    if (Settings["ThumbnailHoverEffect3"].ToString() != "none" && Settings["ThumbnailHoverEffect2"].ToString() != "none" && Settings["ThumbnailHoverEffect1"].ToString() != "none")
                    {
                        sb.Append("," + Settings["ThumbnailHoverEffect3"].ToString());
                    }
                    sb.Append("',");
                }
            }
            //sb.Append("paginationDots: true,");
            if (Settings.Contains("PaginationDots")) sb.Append("paginationDots: " + Settings["PaginationDots"].ToString() + ",");

            //colorScheme
            if (Settings.Contains("ColorScheme")) sb.Append("colorScheme: " + Settings["ColorScheme"].ToString() + ",");

            //locationHash
            if (Settings.Contains("LocationHash")) sb.Append("locationHash: " + Settings["LocationHash"].ToString() + ",");
            //thumbnailGutterWidth    thumbnailGutterHeight
            if (Settings.Contains("ThumbnailGutterWidth")) sb.Append("thumbnailGutterWidth: " + Settings["ThumbnailGutterWidth"].ToString() + ",");
            if (Settings.Contains("ThumbnailGutterHeight")) sb.Append("thumbnailGutterHeight: " + Settings["ThumbnailGutterHeight"].ToString() + ",");

            //thumbnailLabel.itemsCount
            //this is a more advanced option todo later
            //if (Settings.Contains("CountDisplay")) sb.Append("thumbnailLabel.itemsCount: " + Settings["CountDisplay"].ToString() + ",");

            sb.Append("viewerDisplayLogo: false,");
            //sb.AppendFormat("'changeSpeed': {0}, ", objSetting.ChangeSpeed);   ////example
            sb.AppendFormat("itemsBaseURL: '/{0}',", Settings["BaseFolderPath"].ToString());
            //add comma to add more items
            //Last line does not have a comma!!!
            sb.Append("useTags: false");
            sb.Append("})");

            sb.Append(Environment.NewLine);
            sb.Append("});");
            sb.Append(Environment.NewLine);
            sb.Append("</script>");

            phScript.Controls.Add(new LiteralControl(sb.ToString()));
        }
        protected void btnAddToAlbum_Click(object sender, EventArgs e)
        {
            if (ddlAlbumList.SelectedValue != "0")
            {
                List<string> addlist = new List<string>();
                GetCheckedList(addlist);

                //update list in db
                if (addlist.Count > 0)
                {
                    var tc = new ItemController();
                    foreach (string id in addlist)
                    {
                        var t = new Item();
                        t = tc.GetItem(Convert.ToInt32(id), ModuleId);
                        //make the AlbumID = what is in the ddList
                        t.AlbumID = Convert.ToInt32(ddlAlbumList.SelectedValue);
                        tc.UpdateItem(t);
                    }
                }
            }
        }
        protected void btnDeleteSelected_Click(object sender, EventArgs e)
        {

            List<string> deletelist = new List<string>();
            GetCheckedList(deletelist);

            if (deletelist.Count > 0)
            {
                var tc = new ItemController();
                foreach (string id in deletelist)
                {
                    //Delete File and thumnail
                    Item t = tc.GetItem(Convert.ToInt32(id), ModuleId);
                    //Delete from filesystem
                    DeletePicThumb(t);
                    
                    //Delete from db
                    tc.DeleteItem(Convert.ToInt32(id), ModuleId);
                }
            }
        }
        protected void lvGalleryList_ItemCommand(object sender, System.Web.UI.WebControls.ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                var tc = new ItemController();
                Item t = tc.GetItem(Convert.ToInt32(e.CommandArgument), ModuleId);
                //Delete from file system
                DeletePicThumb(t);

                //Delete from Database
                tc.DeleteItem(Convert.ToInt32(e.CommandArgument), ModuleId);

                //reload listview
                LoadGalleryList();
                SetPanels(true);
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var t = new Item();
            var tc = new ItemController();

            if (ItemId > 0)
            {
                t = tc.GetItem(ItemId, ModuleId);
                t.ItemTitle = txtTitle.Text.Trim();
                t.ItemFileName = txtFileName.Text.Trim();
                t.ItemDescription = txtDescription.Text.Trim();
                t.ItemKind = rblItemKind.SelectedValue;

                if (ddlAlbumID.SelectedValue != "0") t.AlbumID = Convert.ToInt32(ddlAlbumID.SelectedValue);
                else t.AlbumID = 0;

                t.LastModifiedByUserId = UserId;
                t.LastModifiedOnDate = DateTime.Now;
            }
            else
            {
                //make sure there are no ' in title or description
                string newTitle = txtTitle.Text.Trim();
                string newDescription = txtDescription.Text.Trim();
                newTitle = newTitle.Replace("'", "");
                newDescription = newDescription.Replace("'", "");

                t = new Item()
                {
                    CreatedByUserId = UserId,
                    CreatedOnDate = DateTime.Now,

                    ItemTitle = newTitle,
                    ItemFileName = txtFileName.Text.Trim(),
                    ItemDescription = newDescription,
                    ItemKind = "",
                    AlbumID = 0
                };
            }
            t.LastModifiedOnDate = DateTime.Now;
            t.LastModifiedByUserId = UserId;
            t.ModuleId = ModuleId;
            if (t.ItemId > 0)
            {
                tc.UpdateItem(t);
            }
            else
            {
                tc.CreateItem(t);
            }
            //reload
            LoadGalleryList();
            LoadAlbumList();
            SetPanels(true);
        }
Example #10
0
        private void LoadGalleryList()
        {

            //Load all pictures into a listview for editing
            var tc = new ItemController();
            var t = tc.GetItems(ModuleId);
            lvGalleryList.DataSource = t;
            //set lines per page
            if (Settings.Contains("EditLinesPerPage")) dbPictureList.PageSize = Convert.ToInt32(Settings["EditLinesPerPage"].ToString());
            lvGalleryList.DataBind();
        }
Example #11
0
        private void LoadSingleView()
        {
            //set radio buttons
            System.Web.UI.WebControls.ListItem rb1 = new System.Web.UI.WebControls.ListItem("Picture", "");
            System.Web.UI.WebControls.ListItem rb2 = new System.Web.UI.WebControls.ListItem("Album", "album");

            rblItemKind.Items.Add(rb1);
            rblItemKind.Items.Add(rb2);

            //Fil ddl with available albums
            ddlAlbumID.Items.Add(new System.Web.UI.WebControls.ListItem("None", "0"));
            var tc = new ItemController();
            var Items = tc.GetItems(ModuleId);

            foreach (Item pc in Items)
            {
                if (pc.ItemKind == "album")
                {
                    ddlAlbumID.Items.Add(new System.Web.UI.WebControls.ListItem(pc.ItemTitle, pc.ItemId.ToString()));
                }
            }
        }
Example #12
0
        protected void LoadAlbumList()
        {
            //Fil ddl with available albums
            ddlAlbumList.Items.Add(new System.Web.UI.WebControls.ListItem("None", "0"));
            var tc = new ItemController();
            var Items = tc.GetItems(ModuleId);

            foreach (Item pc in Items)
            {
                if (pc.ItemKind == "album")
                {
                    ddlAlbumList.Items.Add(new System.Web.UI.WebControls.ListItem(pc.ItemTitle, pc.ItemId.ToString()));
                }
            }
        }