예제 #1
0
        protected string GetClientSideSettings()
        {
            string tmid = "-1";

            if ((UserId > -1))
            {
                tmid = TabModuleId.ToString(CultureInfo.InvariantCulture);
            }
            return(string.Format("allowIconSizeChange: {0}, allowDetailChange: {1}, selectedSize: '{2}', showDetails: '{3}', tabModuleID: {4}, showTooltip: {5}",
                                 AllowSizeChange.ToString(CultureInfo.InvariantCulture).ToLower(),
                                 AllowViewChange.ToString(CultureInfo.InvariantCulture).ToLower(),
                                 DefaultSize,
                                 DefaultView,
                                 tmid,
                                 ShowTooltip.ToString(CultureInfo.InvariantCulture).ToLower()));
        }
        private Hashtable TokenSettings()
        {
            if (_sqlviewproTokens != null)
            {
                return(_sqlviewproTokens);
            }

            var tokens = new Hashtable
            {
                { "MODULEID", EffectiveModuleId.ToString() },
                { "MODULEFOLDER", ControlPath.Remove(ControlPath.Length - 1) },                     // remove last / character to be consistent with resolveurl
                { "TABMODULEID", TabModuleId.ToString() },
                { "PAGEURL", Request.Url.AbsoluteUri },
                { "IMAGEURL", ResolveUrl("~/images") },
                { "CDATASTART", "<![CDATA[" },
                { "CDATAEND", "]]>" }
            };

            _sqlviewproTokens = tokens;
            return(_sqlviewproTokens);
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            int    i       = -1;
            string content = string.Empty;
            string title   = string.Empty;

            DateTime todayAdjusted = Utilities.GetCurrentPortalTime();

            if (MyConfiguration.EnableUserTimeConversion)
            {
                todayAdjusted = Utilities.ConvertPortalToUserTime(todayAdjusted);
            }

            try
            {
                ContentDejourController cdc = new ContentDejourController();
                if (!(string.IsNullOrEmpty(Request.QueryString["KeyID"])))
                {
                    int keyID = 0;
                    if (int.TryParse(Request.QueryString["KeyID"], out keyID))
                    {
                        CurrentItem = cdc.GetContent(keyID, ModuleId);
                    }
                }

                if (CurrentItem.KeyID == -1)
                {
                    switch (MyConfiguration.SelectBy)
                    {
                    case Enums.SelectBy.Month:
                        Months = (new MonthArray()).AddMonth(todayAdjusted.Month);
                        break;

                    case Enums.SelectBy.DayofMonth:
                        Days = (new DayArray()).AddDay(todayAdjusted.Day);
                        break;

                    case Enums.SelectBy.DayofYear:
                        Days = new DayArray(todayAdjusted.DayOfYear | DayArray.ModeFlag);
                        break;

                    case Enums.SelectBy.MonthAndDayofMonth:
                        Months = (new MonthArray()).AddMonth(todayAdjusted.Month);
                        Days   = (new DayArray()).AddDay(todayAdjusted.Day);
                        break;

                    case Enums.SelectBy.DayofWeek:
                        DaysofWeek = (new DayofWeekArray()).AddDay(Convert.ToInt32(todayAdjusted.DayOfWeek));
                        break;

                    case Enums.SelectBy.MonthAndDayofWeek:
                        Months     = (new MonthArray()).AddMonth(todayAdjusted.Month);
                        DaysofWeek = (new DayofWeekArray()).AddDay(Convert.ToInt32(todayAdjusted.DayOfWeek));
                        break;

                    case Enums.SelectBy.TimeSpan:
                        Time = Convert.ToInt32(todayAdjusted.TimeOfDay.TotalMinutes);
                        break;

                    case Enums.SelectBy.DateSpan:
                        Today = new DateInteger(todayAdjusted.Date, false);
                        break;

                    case Enums.SelectBy.DateAndTimeSpan:
                        Today = new DateInteger(todayAdjusted.Date, false);
                        Time  = Convert.ToInt32(todayAdjusted.TimeOfDay.TotalMinutes);
                        break;

                    case Enums.SelectBy.Random:
                        //Do nothing as they will be handled below
                        break;
                    }

                    if (!(string.IsNullOrEmpty(MyConfiguration.ProfilePropertyName)))
                    {
                        string tmp = null;
                        if (UserId == -1)
                        {
                            tmp = "<Unauthenticated>";
                        }
                        else
                        {
                            ProfilePropertyDefinition ppd = UserInfo.Profile.GetProperty(MyConfiguration.ProfilePropertyName);
                            if (ppd == null)
                            {
                                tmp = string.Empty;
                            }
                            else
                            {
                                tmp = ppd.PropertyValue;
                                if (tmp == null)
                                {
                                    if (string.IsNullOrEmpty(ppd.DefaultValue))
                                    {
                                        tmp = "<Default>";
                                    }
                                    else
                                    {
                                        tmp = ppd.DefaultValue;
                                    }
                                }
                            }
                        }
                        ProfilePropertyValue = tmp;
                    }

                    if (!(string.IsNullOrEmpty(Request.QueryString["GroupId"])))
                    {
                        int.TryParse(Request.QueryString["GroupId"], out _GroupID);
                    }

                    if (MyConfiguration.MultipleHandling == Enums.MultipleHandling.TimeSpan)
                    {
                        Time = Convert.ToInt32(todayAdjusted.TimeOfDay.TotalMinutes);
                    }

                    // get ContentDejourInfo object(s)
                    ContentsDejour = cdc.GetContents(ModuleId, Months, Days, DaysofWeek, Today, Time, MyConfiguration.CategoryID, GroupID, ProfilePropertyValue, MyConfiguration.IncludeDisabled);

                    if (ContentsDejour.Count > 1)
                    {
                        int minViews    = int.MaxValue;
                        int leastViewed = 0;
                        switch (MyConfiguration.MultipleHandling)
                        {
                        case Enums.MultipleHandling.Random:
                            i = (new Random()).Next(0, ContentsDejour.Count);
                            break;

                        case Enums.MultipleHandling.First:
                            i = 0;
                            break;

                        case Enums.MultipleHandling.Sequential:
                        case Enums.MultipleHandling.LeastViewed:
                            System.Web.HttpCookie cookie = Request.Cookies["ContentDejour" + TabModuleId.ToString()];
                            int[] views = new int[ContentsDejour.Count + 1];
                            if (cookie != null)
                            {
                                i = int.Parse(cookie.Values["LastViewed"]);
                                for (int j = 0; j < ContentsDejour.Count; j++)
                                {
                                    string v = cookie.Values[j.ToString()];
                                    if (string.IsNullOrEmpty(v))
                                    {
                                        views[j] = 0;
                                    }
                                    else
                                    {
                                        views[j] = int.Parse(v);
                                    }
                                    if (views[j] < minViews)
                                    {
                                        leastViewed = j;
                                        minViews    = views[j];
                                    }
                                }
                            }
                            if (MyConfiguration.MultipleHandling == Enums.MultipleHandling.Sequential)
                            {
                                i = (i + 1) % ContentsDejour.Count;
                            }
                            else
                            {
                                i = leastViewed;
                            }
                            views[i]++;
                            cookie = new HttpCookie("ContentDejour" + TabModuleId.ToString());
                            cookie.Values["LastViewed"] = i.ToString();
                            for (int j = 0; j < views.Length; j++)
                            {
                                cookie.Values[j.ToString()] = views[j].ToString();
                            }
                            cookie.Expires = todayAdjusted.Date.AddMinutes(Convert.ToDouble(ContentsDejour[i].EndTime));
                            Response.Cookies.Add(cookie);
                            break;

                        case Enums.MultipleHandling.Last:
                            i = ContentsDejour.Count - 1;
                            break;

                        case Enums.MultipleHandling.TimeSpan:
                            ContentsDejour.Sort(new ContentDejourInfoComparer("TimeDuration ASC"));
                            i = 0;
                            break;
                        }
                    }
                    else if ((ContentsDejour.Count == 1) && ContentsDejour[0].IsWithinTimeSpan(todayAdjusted.TimeOfDay))
                    {
                        i = 0;
                    }
                }
                else
                {
                    ContentsDejour.Add(CurrentItem);
                    if (ContentsDejour.Count == 1)
                    {
                        i = 0;
                    }
                }

                if (i == -1)
                {
                    if (MyConfiguration.HideWhenNoContent && !IsEditable)
                    {
                        ContainerControl.Visible = false;
                    }
                    else
                    {
                        lnkEdit.Visible      = false;
                        divContent.InnerHtml = LocalizeSharedResource("NO_CONTENT");
                    }
                }
                else
                {
                    KeyID   = ContentsDejour[i].KeyID;
                    title   = Server.HtmlDecode(ContentsDejour[i].Title);
                    content = HttpUtility.HtmlDecode(ContentsDejour[i].DesktopHTML);
                    TokenReplace tr = null;
                    if (MyConfiguration.ReplaceTokens)
                    {
                        tr               = new TokenReplace(ContentsDejour[i]);
                        tr.ModuleId      = ModuleId;
                        tr.AccessingUser = UserInfo;
                        tr.DebugMessages = !(PortalSettings.UserMode == PortalSettings.Mode.View);
                        content          = tr.ReplaceEnvironmentTokens(content);
                        title            = tr.ReplaceEnvironmentTokens(title);
                    }
                    // set edit link
                    if (IsEditable)
                    {
                        lnkEdit.NavigateUrl = EditUrl("KeyID", KeyID.ToString());
                        lnkEdit.Visible     = true;
                    }
                    else
                    {
                        lnkEdit.Visible = false;
                    }
                    // add content to module
                    divContent.InnerHtml = Globals.ManageUploadDirectory(content, PortalSettings.HomeDirectory);
                    // replace module title if so specified in settings
                    if (MyConfiguration.ReplaceTitle && !(string.IsNullOrEmpty(title)))
                    {
                        ModuleConfiguration.ModuleTitle = title;
                    }
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }