Esempio n. 1
0
        /// <summary>
        /// Extract information from the query string and assign to our class level variables. Return false if something goes wrong
        /// and the variables cannot be set. This will happen when the query string is in an unexpected format.
        /// </summary>
        /// <param name="queryString">The query string for the current request. Can be populated with HttpContext.Request.Url.Query.</param>
        /// <returns>Returns true if all relevant variables were assigned from the query string; returns false if there was a problem.</returns>
        private bool ExtractQueryStringParms(string queryString)
        {
            if (String.IsNullOrEmpty(queryString))
            {
                return(false);
            }

            if (queryString.StartsWith("?", StringComparison.Ordinal))
            {
                queryString = queryString.Remove(0, 1);
            }

            //aid={0}&secaction={1}
            foreach (string nameValuePair in queryString.Split(new char[] { '&' }))
            {
                string[] nameOrValue = nameValuePair.Split(new char[] { '=' });
                switch (nameOrValue[0])
                {
                case "aid":
                {
                    int aid;
                    if (Int32.TryParse(nameOrValue[1], out aid))
                    {
                        _albumId = aid;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "secaction":
                {
                    int secActionInt;
                    if (Int32.TryParse(nameOrValue[1], out secActionInt))
                    {
                        if (SecurityActionEnumHelper.IsValidSecurityAction((SecurityActions)secActionInt))
                        {
                            _securityAction = (SecurityActions)secActionInt; break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                default: return(false);                        // Unexpected query string parm. Return false so execution is aborted.
                }
            }

            return(true);
        }
        private TreeView GenerateTreeview()
        {
            // We'll use a TreeView instance to generate the appropriate XML structure
            ComponentArt.Web.UI.TreeView tv = new ComponentArt.Web.UI.TreeView();

            string handlerPath = String.Concat(Utils.GalleryRoot, "/handler/gettreeviewxml.ashx");

            IAlbum parentAlbum = AlbumController.LoadAlbumInstance(this._albumId, true);

            string securityActionParm = String.Empty;

            if (SecurityActionEnumHelper.IsValidSecurityAction(this._securityAction))
            {
                securityActionParm = String.Format(CultureInfo.CurrentCulture, "&secaction={0}", (int)this._securityAction);
            }

            foreach (IAlbum childAlbum in parentAlbum.GetChildGalleryObjects(GalleryObjectType.Album, true, !Utils.IsAuthenticated))
            {
                TreeViewNode node = new TreeViewNode();
                node.Text  = Utils.RemoveHtmlTags(childAlbum.Title);
                node.Value = childAlbum.Id.ToString(CultureInfo.InvariantCulture);
                node.ID    = childAlbum.Id.ToString(CultureInfo.InvariantCulture);

                if (!String.IsNullOrEmpty(_navigateUrl))
                {
                    node.NavigateUrl   = Utils.AddQueryStringParameter(_navigateUrl, String.Concat("aid=", childAlbum.Id.ToString(CultureInfo.InvariantCulture)));
                    node.HoverCssClass = "tv0HoverTreeNodeLink";
                }

                bool isUserAuthorized = true;
                if (SecurityActionEnumHelper.IsValidSecurityAction(this._securityAction))
                {
                    isUserAuthorized = Utils.IsUserAuthorized(_securityAction, RoleController.GetGalleryServerRolesForUser(), childAlbum.Id, childAlbum.GalleryId, childAlbum.IsPrivate);
                }
                node.ShowCheckBox = isUserAuthorized && _showCheckbox;
                node.Selectable   = isUserAuthorized;
                if (!isUserAuthorized)
                {
                    node.HoverCssClass = String.Empty;
                }

                if (childAlbum.GetChildGalleryObjects(GalleryObjectType.Album).Count > 0)
                {
                    string handlerPathWithAlbumId = Utils.AddQueryStringParameter(handlerPath, String.Concat("aid=", childAlbum.Id.ToString(CultureInfo.InvariantCulture)));
                    node.ContentCallbackUrl = String.Format(CultureInfo.CurrentCulture, "{0}{1}&sc={2}&nurl={3}", handlerPathWithAlbumId, securityActionParm, node.ShowCheckBox, Utils.UrlEncode(_navigateUrl));
                }

                tv.Nodes.Add(node);
            }

            return(tv);
        }
Esempio n. 3
0
        private TreeView GenerateTreeview()
        {
            // We'll use a TreeView instance to generate the appropriate XML structure
            ComponentArt.Web.UI.TreeView tv = new ComponentArt.Web.UI.TreeView();

            string handlerPath = String.Concat(Util.GalleryRoot, "/handler/gettreeviewxml.ashx");

            IAlbum parentAlbum = Factory.LoadAlbumInstance(this._albumId, true);

            string securityActionParm = String.Empty;

            if (SecurityActionEnumHelper.IsValidSecurityAction(this._securityAction))
            {
                securityActionParm = String.Format(CultureInfo.CurrentCulture, "&secaction={0}", (int)this._securityAction);
            }

            foreach (IAlbum childAlbum in parentAlbum.GetChildGalleryObjects(GalleryObjectType.Album, true))
            {
                TreeViewNode node = new TreeViewNode();
                node.Text  = Util.RemoveHtmlTags(childAlbum.Title);
                node.Value = childAlbum.Id.ToString(CultureInfo.InvariantCulture);
                node.ID    = childAlbum.Id.ToString(CultureInfo.InvariantCulture);

                bool isUserAuthorized = true;
                if (SecurityActionEnumHelper.IsValidSecurityAction(this._securityAction))
                {
                    isUserAuthorized = Util.IsUserAuthorized(_securityAction, RoleController.GetGalleryServerRolesForUser(), childAlbum.Id, childAlbum.IsPrivate);
                }
                node.ShowCheckBox = isUserAuthorized;
                node.Selectable   = isUserAuthorized;
                if (!isUserAuthorized)
                {
                    node.HoverCssClass = String.Empty;
                }

                if (childAlbum.GetChildGalleryObjects(GalleryObjectType.Album).Count > 0)
                {
                    node.ContentCallbackUrl = String.Format(CultureInfo.CurrentCulture, "{0}?aid={1}{2}", handlerPath, childAlbum.Id.ToString(CultureInfo.InvariantCulture), securityActionParm);
                }

                tv.Nodes.Add(node);
            }

            return(tv);
        }
        ///// <summary>
        ///// Render the treeview to two levels - the root album and its direct children. If the AlbumIdsToCheck property
        ///// has items in its collection, make sure every album in the collection is rendered, no matter how deep in the album heirarchy
        ///// they may be. If the albumToSelect parameter is specified, then make sure this album is rendered and
        ///// selected/checked, no matter how deep in the hierarchy it may be.
        ///// </summary>
        //public void BindTreeView()
        //{
        //  //BindTreeView(null);
        //}

        ///// <summary>
        ///// Render the treeview to two levels - the root album and its direct children. If the <see cref="CheckedAlbumIds" /> property
        ///// has items in its collection, make sure every album in the collection is rendered, no matter how deep in the album heirarchy
        ///// they may be. If the <paramref name="albumToSelect" /> parameter is specified, then make sure this album is rendered and
        ///// selected/checked, no matter how deep in the hierarchy it may be.
        ///// </summary>
        ///// <param name="albumToSelect">An album to be selected, checked, and made visible. The treeview is automatically expanded as
        ///// needed to ensure this album is visible.</param>
        //public void BindTreeView(IAlbum albumToSelect)
        //{
        //  //this._albumToSelect = albumToSelect;

        //  //DataBindTreeView();

        //  //this._albumToSelect = null;

        //  //this.AlbumIdsToCheck.Clear();
        //}

        #endregion

        #region Private Methods

        /// <summary>
        /// Gets a JSON-formatted string of data that can be assigned to the data property of a
        /// jsTree jQuery instance.
        /// </summary>
        /// <returns>A string formatted as JSON.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown when one or more business rules
        /// are violated.</exception>
        private string GetTreeData()
        {
            #region Validation

            if (!this.AllowMultiCheck && this.SelectedAlbumIds.Count > 1)
            {
                throw new InvalidOperationException("The property AllowMultiCheck must be false when multiple album IDs have been assigned to the property SelectedAlbumIds.");
            }

            if (!SecurityActionEnumHelper.IsValidSecurityAction(this.RequiredSecurityPermissions))
            {
                throw new InvalidOperationException("The property GalleryServer.Web.Controls.albumtreeview.RequiredSecurityPermissions must be assigned before the TreeView can be rendered.");
            }

            #endregion

            TreeViewOptions tvOptions = new TreeViewOptions()
            {
                SelectedAlbumIds            = SelectedAlbumIds,
                NumberOfLevels              = NumberOfLevels,
                NavigateUrl                 = NavigateUrl,
                EnableCheckboxPlugin        = EnableCheckboxPlugin,
                IncludeAlbum                = IncludeAlbum,
                RequiredSecurityPermissions = RequiredSecurityPermissions,
                AlbumId         = AlbumId,
                RootNodesPrefix = RootNodesPrefix,
                Galleries       = Galleries
            };

            Entity.TreeView tv = AlbumTreeViewBuilder.GetAlbumsAsTreeView(tvOptions);

            //if (_nodesToCheckIds == null)
            //	_nodesToCheckIds = new List<string>(tv.NodesToCheckIdArray.Count);

            //_nodesToCheckIds.AddRange(tv.NodesToCheckIdArray);

            return(tv.ToJson());
        }
Esempio n. 5
0
        private TreeView GenerateTreeview()
        {
            // We'll use a TreeView instance to generate the appropriate JSON structure
            TreeView tv = new TreeView();

            IAlbum parentAlbum = AlbumController.LoadAlbumInstance(this._albumId, true);

            foreach (IAlbum childAlbum in parentAlbum.GetChildGalleryObjects(GalleryObjectType.Album, !Utils.IsAuthenticated).ToSortedList())
            {
                TreeNode node = new TreeNode();
                node.Id     = String.Concat("tv_", childAlbum.Id.ToString(CultureInfo.InvariantCulture));
                node.Text   = Utils.RemoveHtmlTags(childAlbum.Title);
                node.DataId = childAlbum.Id.ToString(CultureInfo.InvariantCulture);

                if (!String.IsNullOrEmpty(_navigateUrl))
                {
                    node.NavigateUrl = Utils.AddQueryStringParameter(_navigateUrl, String.Concat("aid=", childAlbum.Id.ToString(CultureInfo.InvariantCulture)));
                }

                bool isUserAuthorized = true;
                if (SecurityActionEnumHelper.IsValidSecurityAction(this._securityAction))
                {
                    isUserAuthorized = Utils.IsUserAuthorized(_securityAction, RoleController.GetGalleryServerRolesForUser(), childAlbum.Id, childAlbum.GalleryId, childAlbum.IsPrivate, childAlbum.IsVirtualAlbum);
                }

                node.ShowCheckBox = isUserAuthorized && _showCheckbox;
                node.Selectable   = isUserAuthorized;

                if (childAlbum.GetChildGalleryObjects(GalleryObjectType.Album, !Utils.IsAuthenticated).Any())
                {
                    node.HasChildren = true;
                }

                tv.Nodes.Add(node);
            }

            return(tv);
        }
Esempio n. 6
0
        /// <summary>
        /// Extract information from the query string and assign to our class level variables. Return false if something goes wrong
        /// and the variables cannot be set. This will happen when the query string is in an unexpected format.
        /// </summary>
        /// <param name="queryString">The query string for the current request. Can be populated with HttpContext.Request.Url.Query.</param>
        /// <returns>Returns true if all relevant variables were assigned from the query string; returns false if there was a problem.</returns>
        private bool ExtractQueryStringParms(string queryString)
        {
            if (String.IsNullOrEmpty(queryString))
            {
                return(false);
            }

            if (queryString.StartsWith("?", StringComparison.Ordinal))
            {
                queryString = queryString.Remove(0, 1);
            }

            //id={0}&secaction={1}&sc={2}&navurl={3}
            foreach (string nameValuePair in queryString.Split(new char[] { '&' }))
            {
                string[] nameOrValue = nameValuePair.Split(new char[] { '=' });

                if (nameOrValue.Length < 2)
                {
                    return(false);
                }

                switch (nameOrValue[0])
                {
                case "id":
                {
                    int aid;
                    if (Int32.TryParse(nameOrValue[1], out aid))
                    {
                        _albumId = aid;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "secaction":
                {
                    int secActionInt;
                    if (Int32.TryParse(nameOrValue[1], out secActionInt))
                    {
                        if (SecurityActionEnumHelper.IsValidSecurityAction((SecurityActions)secActionInt))
                        {
                            _securityAction = (SecurityActions)secActionInt; break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                case "sc":
                {
                    bool showCheckbox;
                    if (Boolean.TryParse(nameOrValue[1], out showCheckbox))
                    {
                        _showCheckbox = showCheckbox;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "navurl":
                {
                    _navigateUrl = Utils.UrlDecode(nameOrValue[1]).Trim();
                    break;
                }

                default: return(false); // Unexpected query string parm. Return false so execution is aborted.
                }
            }

            return(true);
        }
        /// <summary>
        /// Render the treeview with the first two levels of albums that are viewable to the logged on user.
        /// </summary>
        private void DataBindTreeView()
        {
            #region Validation

            //if (!this.AllowMultiSelect && this.AlbumIdsToCheck.Count > 1)
            //{
            //  throw new InvalidOperationException("The property AllowMultiSelect must be false when multiple album IDs have been assigned to the property AlbumIdsToCheck.");
            //}

            if (!this.AllowMultiCheck && this.AlbumIdsToCheck.Count > 1)
            {
                throw new InvalidOperationException("The property AllowMultiCheck must be false when multiple album IDs have been assigned to the property AlbumIdsToCheck.");
            }

            if (!SecurityActionEnumHelper.IsValidSecurityAction(this.RequiredSecurityPermissions))
            {
                throw new InvalidOperationException("The property GalleryServerPro.Web.Controls.albumtreeview.RequiredSecurityPermissions must be assigned before the TreeView can be rendered.");
            }

            #endregion

            tv.Nodes.Clear();

            foreach (IAlbum rootAlbum in GetRootAlbums())
            {
                // Add root node.
                TreeViewNode rootNode = new TreeViewNode();

                string albumTitle = GetRootAlbumTitle(rootAlbum);
                rootNode.Text     = albumTitle;
                rootNode.ToolTip  = albumTitle;
                rootNode.Value    = rootAlbum.Id.ToString(CultureInfo.InvariantCulture);
                rootNode.ID       = rootAlbum.Id.ToString(CultureInfo.InvariantCulture);
                rootNode.Expanded = true;

                if (!String.IsNullOrEmpty(NavigateUrl))
                {
                    rootNode.NavigateUrl   = String.Format("{0}?aid={1}", NavigateUrl, rootAlbum.Id);
                    rootNode.HoverCssClass = "tv0HoverTreeNodeLink";
                }

                bool isAlbumSelectable = !rootAlbum.IsVirtualAlbum;
                rootNode.ShowCheckBox = isAlbumSelectable && ShowCheckbox;
                rootNode.Selectable   = isAlbumSelectable;
                if (!isAlbumSelectable)
                {
                    rootNode.HoverCssClass = String.Empty;
                }

                // Select and check this node if needed.
                if (isAlbumSelectable && (this._albumToSelect != null) && (rootAlbum.Id == _albumToSelect.Id))
                {
                    tv.SelectedNode  = rootNode;
                    rootNode.Checked = true;
                }

                // Check this node if needed.
                if (this._albumIdsToCheck.Contains(rootAlbum.Id))
                {
                    rootNode.Checked = true;
                }

                tv.Nodes.Add(rootNode);

                // Add the first level of albums below the root album.
                BindAlbumToTreeview(rootAlbum.GetChildGalleryObjects(GalleryObjectType.Album, true, this.GalleryPage.IsAnonymousUser), rootNode, false);

                // Only display the root node if it is selectable or we added any children to it; otherwise, remove it.
                if (!rootNode.Selectable && rootNode.Nodes.Count == 0)
                {
                    tv.Nodes.Remove(rootNode);
                }
            }

            if ((this._albumToSelect != null) && (tv.SelectedNode == null))
            {
                // We have an album we are supposed to select, but we haven't encountered it in the first two levels,
                // so expand the treeview as needed to include this album.
                BindSpecificAlbumToTreeview(this._albumToSelect);
            }

            // Make sure all specified albums are visible and checked.
            foreach (int albumId in this._albumIdsToCheck)
            {
                IAlbum album = Factory.LoadAlbumInstance(albumId, false);
                if (this.GalleryPage.IsUserAuthorized(RequiredSecurityPermissions, album))
                {
                    BindSpecificAlbumToTreeview(album);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Extract information from the query string and assign to our class level variables. Return false if something goes wrong
        /// and the variables cannot be set. This will happen when the query string is in an unexpected format.
        /// </summary>
        /// <param name="queryString">The query string for the current request. Can be populated with HttpContext.Request.Url.Query.</param>
        /// <returns>Returns true if all relevant variables were assigned from the query string; returns false if there was a problem.</returns>
        private bool ExtractQueryStringParms(string queryString)
        {
            if (String.IsNullOrEmpty(queryString))
            {
                return(false);
            }

            if (queryString.StartsWith("?", StringComparison.Ordinal))
            {
                queryString = queryString.Remove(0, 1);
            }

            // id=0&gid=all&secaction=6&sc=false&navurl=&levels=2&includealbum=true&idtoselect%5B%5D=220&idtoselect%5B%5D=99
            foreach (string nameValuePair in queryString.Split(new char[] { '&' }))
            {
                string[] nameOrValue = nameValuePair.Split(new char[] { '=' });

                if (nameOrValue.Length < 2)
                {
                    return(false);
                }

                switch (Utils.UrlDecode(nameOrValue[0]))
                {
                case "id":
                {
                    int aid;
                    if (Int32.TryParse(nameOrValue[1], out aid))
                    {
                        _albumId = aid;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "gid":
                {
                    int gid;
                    if (Int32.TryParse(nameOrValue[1], out gid))
                    {
                        _galleries = new GalleryCollection()
                        {
                            Factory.LoadGallery(gid)
                        };
                    }
                    else if (Utils.UrlDecode(nameOrValue[1]).Trim() == "all")
                    {
                        _galleries = UserController.GetGalleriesCurrentUserCanAdminister();
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "secaction":
                {
                    int secActionInt;
                    if (Int32.TryParse(nameOrValue[1], out secActionInt))
                    {
                        if (SecurityActionEnumHelper.IsValidSecurityAction((SecurityActions)secActionInt))
                        {
                            _securityAction = (SecurityActions)secActionInt; break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                case "sc":
                {
                    bool showCheckbox;
                    if (Boolean.TryParse(nameOrValue[1], out showCheckbox))
                    {
                        _showCheckbox = showCheckbox;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "navurl":
                {
                    _navigateUrl = Utils.UrlDecode(nameOrValue[1]).Trim();
                    break;
                }

                case "levels":
                {
                    int numLevels;
                    if (Int32.TryParse(nameOrValue[1], out numLevels))
                    {
                        _numberOfLevels = numLevels;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "includealbum":
                {
                    bool includeAlbum;
                    if (Boolean.TryParse(nameOrValue[1], out includeAlbum))
                    {
                        _includeAlbum = includeAlbum;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "idtoselect":
                case "idtoselect[]":
                {
                    int idToSelect;
                    if (Int32.TryParse(nameOrValue[1], out idToSelect))
                    {
                        _albumIdsToSelect.Add(idToSelect);
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                default: return(false); // Unexpected query string parm. Return false so execution is aborted.
                }
            }

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Render the treeview with the first two levels of albums that are viewable to the logged on user.
        /// </summary>
        private void DataBindTreeView()
        {
            #region Validation

            //if (!this.AllowMultiSelect && this.AlbumIdsToCheck.Count > 1)
            //{
            //  throw new InvalidOperationException("The property AllowMultiSelect must be false when multiple album IDs have been assigned to the property AlbumIdsToCheck.");
            //}

            if (!this.AllowMultiSelect && this.AlbumIdsToSelect.Count > 1)
            {
                throw new InvalidOperationException("The property AllowMultiSelect must be false when multiple album IDs have been assigned to the property TopLevelAlbumIdsToCheck.");
            }

            if (!SecurityActionEnumHelper.IsValidSecurityAction(this.RequiredSecurityPermissions))
            {
                throw new InvalidOperationException("The property GalleryServerPro.Web.Controls.albumtreeview.RequiredSecurityPermissions must be assigned before the TreeView can be rendered.");
            }

            #endregion

            // Add root node.
            IAlbum rootAlbum = Factory.LoadRootAlbum(this.RequiredSecurityPermissions, this.GalleryPage.GetGalleryServerRolesForUser());

            TreeViewNode rootNode = new TreeViewNode();
            rootNode.Text     = Util.RemoveHtmlTags(rootAlbum.Title);
            rootNode.Value    = rootAlbum.Id.ToString(CultureInfo.InvariantCulture);
            rootNode.ID       = rootAlbum.Id.ToString(CultureInfo.InvariantCulture);
            rootNode.Expanded = true;

            bool isAlbumSelectable = !rootAlbum.IsVirtualAlbum;
            rootNode.ShowCheckBox = isAlbumSelectable;
            rootNode.Selectable   = isAlbumSelectable;
            if (!isAlbumSelectable)
            {
                rootNode.HoverCssClass = String.Empty;
            }

            // Select and check this node if needed.
            if (isAlbumSelectable && (this._albumToSelect != null) && (rootAlbum.Id == _albumToSelect.Id))
            {
                tv.SelectedNode  = rootNode;
                rootNode.Checked = true;
            }

            // Check this node if needed.
            if (this._albumIdsToSelect.Contains(rootAlbum.Id))
            {
                rootNode.Checked = true;
            }

            tv.Nodes.Clear();
            tv.Nodes.Add(rootNode);

            // Add the first level of albums below the root album.
            BindAlbumToTreeview(rootAlbum.GetChildGalleryObjects(GalleryObjectType.Album), rootNode, false);

            if ((this._albumToSelect != null) && (tv.SelectedNode == null))
            {
                // We have an album we are supposed to select, but we haven't encountered it in the first two levels,
                // so expand the treeview as needed to include this album.
                BindSpecificAlbumToTreeview(this._albumToSelect);
            }

            // Make sure all specified albums are visible and checked.
            foreach (int albumId in this._albumIdsToSelect)
            {
                BindSpecificAlbumToTreeview(Factory.LoadAlbumInstance(albumId, false));
            }
        }