public static IDictionary GetControls(HttpContext context, Page page, string ownerID, string check, string siteUrl, Control parent)
        {
            string thisID, clickScript, fj = string.Empty;
            bool   isSep1, isSep2, hasSep1, hasSep2, includeFilters = false, isPeop, origPage, doZones;
            int    zoneCount;
            List <KeyValuePair <string, KeyValuePair <List <KeyValuePair <string, CamlOperator> >, bool> > > effectiveFilters = null;

            Type []           types = new Type [] { typeof(WebPartVerb) }, rollTypes = new Type [] { typeof(IDictionary) };
            Type              wpType;
            OrderedDictionary dict = new OrderedDictionary(), ctl, items = null, actionItem, actionItems = null;
            KeyValuePair <JsonSchemaManager, JsonSchemaManager> jsonMans;

            JsonSchemaManager.Schema ctlSchema, actSchema;
            WebPartManager           wpMan = WebPartManager.GetCurrentWebPartManager(page);
            Reflector                   refl;
            SPList                      list;
            List <SystemWebPart>        parts;
            IEnumerable <SystemWebPart> partsEnum;
            WebPartVerb                 wpVerb;

            using (ProductPage ppage = new ProductPage()) {
                jsonMans = JsonSchemaManager.TryGet(ppage, null, true, true, null);
                foreach (JsonSchemaManager jman in new JsonSchemaManager [] { jsonMans.Key, jsonMans.Value })
                {
                    if (jman != null)
                    {
                        if (((ctlSchema = jman.AllSchemas ["PrintControls"]) != null) && ((actSchema = jman.AllSchemas ["PrintActions"]) != null))
                        {
                            foreach (IDictionary launcher in ctlSchema.Instances)
                            {
                                if (launcher != null)
                                {
                                    if (JsonSchemaManager.Bool(launcher [check], true))
                                    {
                                        ctl = MakeSubControl(ownerID + "_" + launcher ["id"], JsonSchemaManager.GetDisplayName(launcher, ctlSchema.Name, false), ctlSchema.GetInstanceDescription(launcher), string.Empty, siteUrl + "/_layouts/images/roxority_PrintZen/printer32.png", items = new OrderedDictionary());
                                        foreach (IDictionary action in actSchema.Instances)
                                        {
                                            if (action != null)
                                            {
                                                items [thisID = (ctl ["id"] + "_" + action ["id"])] = actionItem = MakeSubControl(thisID, JsonSchemaManager.GetDisplayName(action, "PrintActions", false), ctlSchema.GetInstanceDescription(action), string.Empty, siteUrl + "/_layouts/images/lg_icxps.gif", actionItems = new OrderedDictionary());
                                                hasSep1   = hasSep2 = isSep1 = isSep2 = false;
                                                zoneCount = -1;
                                                if (wpMan != null)
                                                {
                                                    if (hasSep2 = hasSep1 = (JsonSchemaManager.Bool(launcher ["pp"], true) && !"n".Equals(action ["mpp"])))
                                                    {
                                                        actionItems [thisID + "_pp"] = MakeSubControl(thisID + "_pp", ProductPage.GetProductResource("PrintPageContent"), ProductPage.GetProductResource("PrintPageContentDesc"), clickScript = PrintZenMenuItem.GetClickScript(context, ownerID, siteUrl, string.Empty, action, SPContext.Current.Web, false, false, null, null, true, false, null, null, Guid.Empty, null, page, false), siteUrl + "/_layouts/images/lg_icgen.gif", null);
                                                    }
                                                    if (JsonSchemaManager.Bool(launcher ["pw"], true) && ((partsEnum = ProductPage.TryEach <SystemWebPart> (wpMan.WebParts)) != null))
                                                    {
                                                        parts = new List <SystemWebPart> (partsEnum);
                                                        parts.Sort((wp1, wp2) => {
                                                            WebPartZoneBase zone1, zone2;
                                                            if ((wp1 == null) && (wp2 == null))
                                                            {
                                                                return(0);
                                                            }
                                                            if (wp1 == null)
                                                            {
                                                                return(-1);
                                                            }
                                                            if (wp2 == null)
                                                            {
                                                                return(1);
                                                            }
                                                            if (((zone1 = wp1.Zone) == null) || ((zone2 = wp2.Zone) == null))
                                                            {
                                                                return((wp1.ZoneIndex == wp2.ZoneIndex) ? wp1.TabIndex.CompareTo(wp2.TabIndex) : wp1.ZoneIndex.CompareTo(wp2.ZoneIndex));
                                                            }
                                                            return((zone1.TabIndex == zone2.TabIndex) ? wp1.ZoneIndex.CompareTo(wp2.ZoneIndex) : zone1.TabIndex.CompareTo(zone2.TabIndex));
                                                        });
                                                        foreach (SystemWebPart wp in parts)
                                                        {
                                                            refl   = new Reflector((wpType = wp.GetType()).Assembly);
                                                            list   = (("Microsoft.SharePoint.WebPartPages.XsltListViewWebPart".Equals(wpType.FullName) || (wp is ListViewWebPart)) ? ((wp is ListViewWebPart) ? (refl.Get(wp, "List") as SPList) : ((SPView)refl.Get(wp, "ContextView")).ParentList) : null);
                                                            isPeop = ((wpType.FullName == "roxority_RollupZen.RollupWebPart") || (wpType.FullName == "roxority_PeopleZen.roxority_UserListWebPart"));
                                                            if (IsPartSupported(action, wp, isPeop, list, out origPage))
                                                            {
                                                                if (hasSep1 && !isSep1)
                                                                {
                                                                    isSep1 = true;
                                                                    actionItems [thisID + "_sep1"] = null;
                                                                }
                                                                hasSep2 = true;
                                                                if (isPeop && (!origPage) && ((wpVerb = refl.Call(wp, "GetPrintVerb", rollTypes, new object [] { action }) as WebPartVerb) != null))
                                                                {
                                                                    clickScript = wpVerb.ClientClickHandler + string.Empty;
                                                                }
                                                                else if ((list != null) && !origPage)
                                                                {
                                                                    clickScript = string.Empty;
                                                                    PrintZenMenuItem.GetFilterInfo(action, "PrintActions", ref clickScript, wp, page, ref includeFilters, ref fj, ref effectiveFilters);
                                                                    if (string.IsNullOrEmpty(clickScript))
                                                                    {
                                                                        clickScript = PrintZenMenuItem.GetClickScript(context, ownerID, siteUrl, string.Empty, action, SPContext.Current.Web, JsonSchemaManager.Bool(action ["view"], true), includeFilters, effectiveFilters, fj, true, false, list, null, ProductPage.GetGuid(refl.Get(wp, "ViewGuid") + string.Empty), PrintZenMenuItem.GetAllPageParams(context, true, null), parent, origPage);
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    clickScript = PrintZenMenuItem.GetClickScript(context, ownerID, siteUrl, string.Empty, action, SPContext.Current.Web, false, false, null, null, true, false, null, null, ProductPage.GetGuid(wp.ID.Substring(2).Replace('_', '-')), PrintZenMenuItem.GetAllPageParams(context, true, null), parent, origPage);
                                                                }
                                                                actionItems [thisID + "_" + wp.ID] = MakeSubControl(thisID + "_" + wp.ID, wp.DisplayTitle, GetPartDesc(wp, refl), clickScript, siteUrl + "/_layouts/roxority_PrintZen/mash.tl.aspx?op=imgoverlay&backimg=" + HttpUtility.UrlEncode("/_layouts/images/roxority_PrintZen/printer32.png") + "&overlay=" + HttpUtility.UrlEncode(string.IsNullOrEmpty(wp.TitleIconImageUrl) ? (string.IsNullOrEmpty(wp.CatalogIconImageUrl) ? "/_layouts/images/itobject.gif" : wp.CatalogIconImageUrl) : wp.TitleIconImageUrl) + "&r=" + ppage.Rnd.Next(), null);
                                                            }
                                                        }
                                                    }
                                                    if (doZones = (JsonSchemaManager.Bool(launcher ["pz"], true) && (!"n".Equals(action ["mwz"])) && ((!JsonSchemaManager.Bool(launcher ["pp"], true)) || (((zoneCount = wpMan.Zones.Count) > 1)))))
                                                    {
                                                        if (zoneCount > 0)
                                                        {
                                                            zoneCount = 0;
                                                            foreach (WebPartZoneBase zone in ProductPage.TryEach <WebPartZoneBase> (wpMan.Zones))
                                                            {
                                                                if (zone.WebParts.Count > (JsonSchemaManager.Bool(launcher ["pw"], true) ? 1 : 0))
                                                                {
                                                                    zoneCount++;
                                                                }
                                                            }
                                                        }
                                                    }
                                                    if (doZones && ((zoneCount < 0) || (zoneCount > 1)))
                                                    {
                                                        foreach (WebPartZoneBase zone in ProductPage.TryEach <WebPartZoneBase> (wpMan.Zones))
                                                        {
                                                            if (zone.WebParts.Count > (JsonSchemaManager.Bool(launcher ["pw"], true) ? 1 : 0))
                                                            {
                                                                if (hasSep2 && !isSep2)
                                                                {
                                                                    isSep2 = true;
                                                                    actionItems [thisID + "_sep2"] = null;
                                                                }
                                                                clickScript = PrintZenMenuItem.GetClickScript(context, ownerID, siteUrl, string.Empty, action, SPContext.Current.Web, false, false, null, null, true, false, null, null, Guid.Empty, null, zone, false);
                                                                actionItems [thisID + "_" + zone.ID] = MakeSubControl(thisID + "_" + zone.ID, ProductPage.GetProductResource("WebPartZone", zone.DisplayTitle), GetZoneDesc(zone), clickScript, siteUrl + "/_layouts/images/lg_icgen.gif", null);
                                                            }
                                                        }
                                                    }
                                                }
                                                if (actionItems.Count == 0)
                                                {
                                                    items.Remove(thisID);
                                                }
                                            }
                                        }
                                        if (items.Count > 0)
                                        {
                                            dict [launcher ["id"]] = ctl;
                                        }
                                    }
                                    if ((items != null) && (items.Count == 1))
                                    {
                                        foreach (DictionaryEntry entry in actionItems)
                                        {
                                            items [entry.Key] = entry.Value;
                                        }
                                        items.RemoveAt(0);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(dict);
        }
예제 #2
0
        internal void AddListViewWebPart(IDictionary action, Guid viewID, ArrayList filters, Hashtable fht)
        {
            string       viewXml, paging, sortProp = string.Empty, sortOrder = string.Empty;
            bool         expGrps = false;
            int          itemID;
            SPList       list;
            SPView       view = null;
            SPQuery      query;
            SPListItem   item;
            SPField      sortField;
            XmlNode      node;
            XmlDocument  doc = new XmlDocument();
            XmlAttribute att;
            SPFolder     folder = null;
            Dictionary <string, string> viewAtts = new Dictionary <string, string> ();
            ViewToolBar     viewToolBar;
            ListViewWebPart lvwp;

            try {
                list = web.Lists [new Guid(Request.QueryString ["l"])];
                PhVals ["List_Title"] = list.Title;
                if (string.IsNullOrEmpty(Title))
                {
                    Title = list.Title;
                }
                try {
                    view = list.Views [viewID];
                } catch {
                }
                if (view == null)
                {
                    view = list.DefaultView;
                }
                PhVals ["View_Title"]    = view.Title;
                PhVals ["Context_Title"] = list.Title + ((string.IsNullOrEmpty(list.Title) || string.IsNullOrEmpty(view.Title)) ? string.Empty : " - ") + view.Title;
                if ((!string.IsNullOrEmpty(view.Title)) && (view.Title != Title))
                {
                    Title = Title + ((string.IsNullOrEmpty(Title) || string.IsNullOrEmpty(view.Title)) ? string.Empty : " - ") + view.Title;
                }
                if ((filters != null) && (filters.Count == 0))
                {
                    filters = null;
                }
                if (ProductPage.Is14)
                {
                    reflector.Set(view, "InlineEdit", "false");
                    reflector.Set(view, "TabularView", false);
                }
                viewAtts ["FailIfEmpty"] = "FALSE";
                viewAtts ["PageType"]    = "DIALOGVIEW";
                viewAtts ["RequiresClientIntegration"] = "FALSE";
                viewAtts ["Threaded"] = "FALSE";
                viewAtts ["Scope"]    = action ["f"] + string.Empty;
                query = BuildQuery(view, viewAtts, view.ViewFields);
                if (!string.IsNullOrEmpty(Request.QueryString ["RootFolder"]))
                {
                    try {
                        folder = list.RootFolder.SubFolders [Request.QueryString ["RootFolder"]];
                    } catch {
                    }
                }
                query.Folder = ((folder == null) ? list.RootFolder : folder);
                sortProp     = Request.QueryString ["SortField"] + string.Empty;
                sortOrder    = Request.QueryString ["SortDir"] + string.Empty;
                if (!string.IsNullOrEmpty(sortProp))
                {
                    doc.LoadXml("<Query>" + query.Query + "</Query>");
                    if ((node = doc.DocumentElement.SelectSingleNode("OrderBy")) == null)
                    {
                        node = doc.DocumentElement.AppendChild(doc.CreateElement("OrderBy"));
                    }
                    node.InnerXml = "<FieldRef Ascending=\"" + ("desc".Equals(sortOrder, StringComparison.InvariantCultureIgnoreCase) ? "FALSE" : "TRUE") + "\" Name=\"" + sortProp + "\"/>";
                    query.Query   = doc.DocumentElement.InnerXml;
                }
                if ((string.IsNullOrEmpty(sortProp) || string.IsNullOrEmpty(sortOrder)) && !string.IsNullOrEmpty(query.Query))
                {
                    doc.LoadXml("<Query>" + query.Query + "</Query>");
                    if ((node = doc.SelectSingleNode("/Query/OrderBy/FieldRef")) != null)
                    {
                        if (string.IsNullOrEmpty(sortProp) && ((att = node.Attributes.GetNamedItem("Name") as XmlAttribute) != null))
                        {
                            sortProp = att.Value;
                        }
                        if (string.IsNullOrEmpty(sortOrder) && ((att = node.Attributes.GetNamedItem("Ascending") as XmlAttribute) != null))
                        {
                            sortProp = ("true".Equals(att.Value, StringComparison.InvariantCultureIgnoreCase) ? "asc" : "desc");
                        }
                    }
                }
                if (string.IsNullOrEmpty(sortProp))
                {
                    sortProp = "Order";
                }
                if (string.IsNullOrEmpty(sortOrder))
                {
                    sortOrder = "asc";
                }
                sortField = ProductPage.GetField(list, sortProp);
                if (PrintZenMenuItem.GetBool(action, "p") && !string.IsNullOrEmpty(paging = string.Join("&", new List <string> (PrintZenMenuItem.GetAllPageParams(Context, true, "p_" + sortProp)).ConvertAll <string> ((pname) => {
                    try {
                        if (pname.Equals("p_" + sortProp, StringComparison.InvariantCultureIgnoreCase) && string.IsNullOrEmpty(Request.QueryString [pname]) && (sortField != null) && int.TryParse(Request.QueryString ["p_ID"], out itemID) && ((item = list.GetItemById(itemID)) != null))
                        {
                            return(pname + "=" + HttpUtility.UrlEncode(item [sortField.Id] + string.Empty));
                        }
                    } catch {
                    }
                    return(pname + "=" + HttpUtility.UrlEncode(Request.QueryString [pname]));
                }).ToArray()).Trim()))
                {
                    query.RowLimit = view.RowLimit;
                    query.ListItemCollectionPosition = new SPListItemCollectionPosition(paging);
                }
                else
                {
                    query.RowLimit = 0;
                }
                if (filters != null)
                {
                    doc.LoadXml(viewXml = view.SchemaXml);
                    if (!string.IsNullOrEmpty(viewXml = ProductPage.ApplyCore(list, viewXml, doc, filters, ref expGrps, false, fht, null)))
                    {
                        doc.LoadXml(viewXml);
                        if ((node = doc.DocumentElement.SelectSingleNode("Query")) != null)
                        {
                            query.Query = node.InnerXml;
                        }
                    }
                }
                if (ProductPage.Is14)
                {
                    reflector.Set(query, "ViewFieldsOnly", true);
                }
                InitWebPart(lvwp = new ListViewWebPart());
                lvwp.ID          = "ListViewWebPart";
                lvwp.WebId       = web.ID;
                reflector.Set(lvwp, "web", web);
                lvwp.ListName = ProductPage.GuidBracedUpper(list.ID);
                reflector.Set(lvwp, "list", list);
                lvwp.ViewFlag          = 9;
                lvwp.ViewContentTypeId = view.ContentTypeId.ToString();
                lvwp.ViewType          = (ViewType)Enum.Parse(typeof(ViewType), view.Type, true);
                lvwp.ViewGuid          = ProductPage.GuidBracedUpper(view.ID);
                reflector.Set(lvwp, "view", view);
                lvwp.ListViewXml = query.ViewXml;
                if (!string.IsNullOrEmpty(Request.QueryString ["RootFolder"]))
                {
                    reflector.Set(lvwp, "rootFolder", Request.QueryString ["RootFolder"]);
                }
                if (!string.IsNullOrEmpty(Request.QueryString ["FolderCTID"]))
                {
                    reflector.Set(lvwp, "folderCtId", Request.QueryString ["FolderCTID"]);
                }
                MainWebPart.Controls.Add(lvwp);
                PhVals ["WebPart_Title"] = lvwp.DisplayTitle;
                if ((viewToolBar = reflector.Get(lvwp, "ToolbarControl") as ViewToolBar) != null)
                {
                    viewToolBar.Visible = false;
                }
            } catch {
            }
        }