Пример #1
0
        /// <summary>
        /// Handles save button click.
        /// </summary>
        protected void Save_Click(object sender, System.EventArgs e)
        {
            if (MedalImage.SelectedIndex <= 0)
            {
                PageContext.AddLoadMessage("Medal image must be specified!");
                return;
            }
            else if (SmallMedalImage.SelectedIndex <= 0)
            {
                PageContext.AddLoadMessage("Small medal image must be specified!");
                return;
            }

            // data
            object     medalID = null;
            object     imageURL, smallImageURL, ribbonURL = null, smallRibbonURL = null;
            object     ribbonWidth = null, ribbonHeight = null;
            Size       imageSize;
            MedalFlags flags = new MedalFlags(0);

            // retrieve medal ID, use null if we are creating new one
            if (Request.QueryString["m"] != null)
            {
                medalID = Request.QueryString["m"];
            }

            // flags
            flags.ShowMessage     = ShowMessage.Checked;
            flags.AllowRibbon     = AllowRibbon.Checked;
            flags.AllowReOrdering = AllowReOrdering.Checked;
            flags.AllowHiding     = AllowHiding.Checked;

            // get medal images
            imageURL      = MedalImage.SelectedValue;
            smallImageURL = SmallMedalImage.SelectedValue;
            if (RibbonImage.SelectedIndex > 0)
            {
                ribbonURL = RibbonImage.SelectedValue;
            }
            if (SmallRibbonImage.SelectedIndex > 0)
            {
                smallRibbonURL = SmallRibbonImage.SelectedValue;

                imageSize    = GetImageSize(smallRibbonURL.ToString());
                ribbonWidth  = imageSize.Width;
                ribbonHeight = imageSize.Height;
            }

            // get size of small image
            imageSize = GetImageSize(smallImageURL.ToString());

            // save medal
            DB.medal_save(PageContext.PageBoardID, medalID, Name.Text, Description.Text, Message.Text, Category.Text, imageURL, ribbonURL,
                          smallImageURL, smallRibbonURL, imageSize.Width, imageSize.Height, ribbonWidth, ribbonHeight, SortOrder.Text, flags.BitValue);

            // go back to medals administration
            YafBuildLink.Redirect(ForumPages.admin_medals);
        }
Пример #2
0
        /// <summary>
        /// Handles save button click.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (this.MedalImage.SelectedIndex <= 0)
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITMEDAL", "MSG_IMAGE"), MessageTypes.warning);
                return;
            }

            if (this.SmallMedalImage.SelectedIndex <= 0)
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITMEDAL", "MSG_SMALL_IMAGE"),
                    MessageTypes.warning);
                return;
            }

            // data
            string ribbonUrl = null, smallRibbonUrl = null;

            // flags
            var flags = new MedalFlags(0)
            {
                ShowMessage     = this.ShowMessage.Checked,
                AllowRibbon     = this.AllowRibbon.Checked,
                AllowReOrdering = false,
                AllowHiding     = this.AllowHiding.Checked
            };

            // get medal images
            var imageUrl      = this.MedalImage.SelectedItem.Text;
            var smallImageUrl = this.SmallMedalImage.SelectedItem.Text;

            if (this.RibbonImage.SelectedIndex > 0)
            {
                ribbonUrl = this.RibbonImage.SelectedItem.Text;
            }

            if (this.SmallRibbonImage.SelectedIndex > 0)
            {
                smallRibbonUrl = this.SmallRibbonImage.SelectedItem.Text;
            }

            // save medal
            this.GetRepository <Medal>().Save(
                this.CurrentMedalId,
                this.Name.Text,
                this.Description.Text,
                this.Message.Text,
                this.Category.Text,
                imageUrl,
                ribbonUrl,
                smallImageUrl,
                smallRibbonUrl,
                flags.BitValue);

            // go back to medals administration
            this.Get <LinkBuilder>().Redirect(ForumPages.Admin_Medals);
        }
Пример #3
0
        /// <summary>
        /// Handles save button click.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveClick([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (this.MedalImage.SelectedIndex <= 0)
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITMEDAL", "MSG_IMAGE"), MessageTypes.warning);
                return;
            }

            if (this.SmallMedalImage.SelectedIndex <= 0)
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITMEDAL", "MSG_SMALL_IMAGE"),
                    MessageTypes.warning);
                return;
            }

            if (this.SortOrder.Text.Trim().Length == 0)
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_VALUE"), MessageTypes.warning);
                return;
            }

            if (!ValidationHelper.IsValidPosShort(this.SortOrder.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(
                    this.GetText("ADMIN_EDITFORUM", "MSG_POSITIVE_VALUE"),
                    MessageTypes.warning);
                return;
            }

            if (!byte.TryParse(this.SortOrder.Text.Trim(), out var sortOrder))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_CATEGORY"), MessageTypes.warning);
                return;
            }

            // data
            string ribbonUrl = null, smallRibbonUrl = null;
            short? ribbonWidth = null, ribbonHeight = null;
            Size   imageSize;

            // flags
            var flags = new MedalFlags(0)
            {
                ShowMessage     = this.ShowMessage.Checked,
                AllowRibbon     = this.AllowRibbon.Checked,
                AllowReOrdering = this.AllowReOrdering.Checked,
                AllowHiding     = this.AllowHiding.Checked
            };

            // get medal images
            var imageUrl      = this.MedalImage.SelectedItem.Text;
            var smallImageUrl = this.SmallMedalImage.SelectedItem.Text;

            if (this.RibbonImage.SelectedIndex > 0)
            {
                ribbonUrl = this.RibbonImage.SelectedItem.Text;
            }

            if (this.SmallRibbonImage.SelectedIndex > 0)
            {
                smallRibbonUrl = this.SmallRibbonImage.SelectedItem.Text;

                imageSize    = this.GetImageSize(smallRibbonUrl);
                ribbonWidth  = imageSize.Width.ToType <short>();
                ribbonHeight = imageSize.Height.ToType <short>();
            }

            // get size of small image
            imageSize = this.GetImageSize(smallImageUrl);

            // save medal
            this.GetRepository <Medal>().Save(
                this.CurrentMedalId,
                this.Name.Text,
                this.Description.Text,
                this.Message.Text,
                this.Category.Text,
                imageUrl,
                ribbonUrl,
                smallImageUrl,
                smallRibbonUrl,
                (short)imageSize.Width,
                (short)imageSize.Height,
                ribbonWidth,
                ribbonHeight,
                sortOrder,
                flags.BitValue);

            // go back to medals administration
            BuildLink.Redirect(ForumPages.Admin_Medals);
        }
Пример #4
0
        /// <summary>
        /// The setup user profile info.
        /// </summary>
        /// <param name="userID">The user id.</param>
        /// <param name="user">The user.</param>
        /// <param name="userData">The user data.</param>
        /// <param name="userDisplayName">The user display name.</param>
        private void SetupUserProfileInfo(
            int userID,
            [NotNull] MembershipUser user,
            [NotNull] IUserData userData,
            [NotNull] string userDisplayName)
        {
            this.UserLabel1.UserID = userData.UserID;

            if (this.PageContext.IsAdmin && userData.DisplayName != user.UserName)
            {
                this.Name.Text = this.HtmlEncode("{0} ({1})".FormatWith(userData.DisplayName, user.UserName));
            }
            else
            {
                this.Name.Text = this.HtmlEncode(userDisplayName);
            }

            this.Joined.Text =
                "{0}".FormatWith(this.Get <IDateTime>().FormatDateLong(Convert.ToDateTime(userData.Joined)));

            // vzrus: Show last visit only to admins if user is hidden
            if (!this.PageContext.IsAdmin && Convert.ToBoolean(userData.DBRow["IsActiveExcluded"]))
            {
                this.LastVisit.Text    = this.GetText("COMMON", "HIDDEN");
                this.LastVisit.Visible = true;
            }
            else
            {
                this.LastVisitDateTime.DateTime = userData.LastVisit;
                this.LastVisitDateTime.Visible  = true;
            }

            if (this.User != null && userData.RankName.IsSet())
            {
                this.RankTR.Visible = true;
                this.Rank.Text      = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.RankName));
            }

            if (this.User != null && userData.Profile.Location.IsSet())
            {
                this.LocationTR.Visible = true;
                this.Location.Text      = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.Location));
            }

            if (this.User != null && userData.Profile.Country.Trim().IsSet() && !userData.Profile.Country.Equals("N/A"))
            {
                this.CountryTR.Visible = true;
                this.CountryLabel.Text =
                    this.HtmlEncode(
                        this.Get <IBadWordReplace>().Replace(this.GetText("COUNTRY", userData.Profile.Country.Trim())));

                this.CountryFlagImage.Src = this.Get <ITheme>()
                                            .GetItem(
                    "FLAGS",
                    "{0}_MEDIUM".FormatWith(userData.Profile.Country.Trim()),
                    YafForumInfo.GetURLToContent("images/flags/{0}.png".FormatWith(userData.Profile.Country.Trim())));

                this.CountryFlagImage.Alt = userData.Profile.Country.Trim();
                this.CountryFlagImage.Attributes.Add("title", this.CountryLabel.Text);
            }

            if (this.User != null && userData.Profile.Region.IsSet())
            {
                this.RegionTR.Visible = true;

                try
                {
                    var tag =
                        "RGN_{0}_{1}".FormatWith(
                            userData.Profile.Country.Trim().IsSet()
                                ? userData.Profile.Country.Trim()
                                : this.Get <ILocalization>().Culture.Name.Remove(0, 3).ToUpperInvariant(),
                            userData.Profile.Region);
                    this.RegionLabel.Text =
                        this.HtmlEncode(this.Get <IBadWordReplace>().Replace(this.GetText("REGION", tag)));
                }
                catch (Exception)
                {
                    this.RegionTR.Visible = false;
                }
            }

            if (this.User != null && userData.Profile.City.IsSet())
            {
                this.CityTR.Visible = true;
                this.CityLabel.Text = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.City));
            }

            if (this.User != null && userData.Profile.Location.IsSet())
            {
                this.LocationTR.Visible = true;
                this.Location.Text      = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.Location));
            }

            if (this.User != null && userData.Profile.RealName.IsSet())
            {
                this.RealNameTR.Visible = true;
                this.RealName.InnerText = this.HtmlEncode(
                    this.Get <IBadWordReplace>().Replace(userData.Profile.RealName));
            }

            if (this.User != null && userData.Profile.Interests.IsSet())
            {
                this.InterestsTR.Visible = true;
                this.Interests.InnerText =
                    this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.Interests));
            }

            if (this.User != null && (userData.Profile.Gender > 0))
            {
                string imagePath = string.Empty;
                string imageAlt  = string.Empty;

                this.GenderTR.Visible = true;
                switch (userData.Profile.Gender)
                {
                case 1:
                    imagePath = this.PageContext.Get <ITheme>().GetItem("ICONS", "GENDER_MALE", null);
                    imageAlt  = this.GetText("USERGENDER_MAS");
                    break;

                case 2:
                    imagePath = this.PageContext.Get <ITheme>().GetItem("ICONS", "GENDER_FEMALE", null);
                    imageAlt  = this.GetText("USERGENDER_FEM");
                    break;
                }

                this.Gender.InnerHtml =
                    @"<a><img src=""{0}"" alt=""{1}"" title=""{1}"" /></a>&nbsp;{1}".FormatWith(imagePath, imageAlt);
            }

            if (this.User != null && userData.Profile.Occupation.IsSet())
            {
                this.OccupationTR.Visible = true;
                this.Occupation.InnerText =
                    this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.Occupation));
            }

            this.ThanksFrom.Text =
                LegacyDb.user_getthanks_from(userData.DBRow["userID"], this.PageContext.PageUserID).ToString();
            int[] thanksToArray = LegacyDb.user_getthanks_to(userData.DBRow["userID"], this.PageContext.PageUserID);
            this.ThanksToTimes.Text      = thanksToArray[0].ToString();
            this.ThanksToPosts.Text      = thanksToArray[1].ToString();
            this.ReputationReceived.Text = YafReputation.GenerateReputationBar(userData.Points.Value, userData.UserID);

            if (this.Get <YafBoardSettings>().ShowUserOnlineStatus)
            {
                this.OnlineStatusImage1.UserID  = userID;
                this.OnlineStatusImage1.Visible = true;

                var suspended = userData.DBRow["Suspended"].ToType <DateTime?>();

                if (suspended.HasValue && suspended.Value > DateTime.UtcNow)
                {
                    this.ThemeImgSuspended.LocalizedTitle =
                        this.GetText("POSTS", "USERSUSPENDED")
                        .FormatWith(this.Get <IDateTime>().FormatDateTimeShort(suspended.Value));

                    this.ThemeImgSuspended.Visible  = true;
                    this.OnlineStatusImage1.Visible = false;
                }
                else
                {
                    this.ThemeImgSuspended.Visible = false;
                }
            }
            else
            {
                this.ThemeImgSuspended.Visible  = false;
                this.OnlineStatusImage1.Visible = false;
            }

            if (this.User != null && userData.Profile.XMPP.IsSet())
            {
                this.XmppTR.Visible = true;
                this.lblxmpp.Text   = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.XMPP));
            }

            if (this.User != null && userData.Profile.AIM.IsSet())
            {
                this.AimTR.Visible = true;
                this.lblaim.Text   = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.AIM));
            }

            if (this.User != null && userData.Profile.ICQ.IsSet())
            {
                this.IcqTR.Visible = true;
                this.lblicq.Text   = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.ICQ));
            }

            if (this.User != null && userData.Profile.MSN.IsSet())
            {
                this.MsnTR.Visible = true;
                this.lblmsn.Text   = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.MSN));
            }

            if (this.User != null && userData.Profile.Skype.IsSet())
            {
                this.SkypeTR.Visible = true;
                this.lblskype.Text   = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.Skype));
            }

            if (this.User != null && userData.Profile.YIM.IsSet())
            {
                this.YimTR.Visible = true;
                this.lblyim.Text   = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.YIM));
            }

            var loadHoverCardJs = false;

            if (this.User != null && userData.Profile.Facebook.IsSet())
            {
                this.FacebookTR.Visible = true;
                this.lblfacebook.Text   = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.Facebook));

                if (this.Get <YafBoardSettings>().EnableUserInfoHoverCards)
                {
                    this.lblfacebook.Attributes.Add("data-hovercard", this.lblfacebook.Text);
                    this.Facebook.Attributes.Add("data-hovercard", this.lblfacebook.Text);

                    this.lblfacebook.CssClass += " Facebook-HoverCard";
                    this.Facebook.CssClass    += " Facebook-HoverCard";

                    loadHoverCardJs = true;
                }
            }

            if (this.User != null && userData.Profile.Twitter.IsSet())
            {
                this.TwitterTR.Visible = true;
                this.lbltwitter.Text   = this.HtmlEncode(this.Get <IBadWordReplace>().Replace(userData.Profile.Twitter));

                if (this.Get <YafBoardSettings>().EnableUserInfoHoverCards&& Config.IsTwitterEnabled)
                {
                    this.lbltwitter.Attributes.Add("data-hovercard", this.lbltwitter.Text);
                    this.Twitter.Attributes.Add("data-hovercard", this.lbltwitter.Text);

                    this.lbltwitter.CssClass += " Twitter-HoverCard";
                    this.Twitter.CssClass    += " Twitter-HoverCard";

                    loadHoverCardJs = true;
                }
            }

            if (loadHoverCardJs && this.Get <YafBoardSettings>().EnableUserInfoHoverCards&& Config.IsTwitterEnabled)
            {
                var hoverCardLoadJs = new StringBuilder();

                hoverCardLoadJs.Append(
                    JavaScriptBlocks.HoverCardLoadJs(
                        ".Facebook-HoverCard",
                        "Facebook",
                        this.GetText("DEFAULT", "LOADING_FB_HOVERCARD").ToJsString(),
                        this.GetText("DEFAULT", "ERROR_FB_HOVERCARD").ToJsString()));

                hoverCardLoadJs.Append(
                    JavaScriptBlocks.HoverCardLoadJs(
                        ".Twitter-HoverCard",
                        "Twitter",
                        this.GetText("DEFAULT", "LOADING_TWIT_HOVERCARD").ToJsString(),
                        this.GetText("DEFAULT", "ERROR_TWIT_HOVERCARD").ToJsString(),
                        "{0}{1}resource.ashx?twitterinfo=".FormatWith(
                            BaseUrlBuilder.BaseUrl.TrimEnd('/'),
                            BaseUrlBuilder.AppPath)));

                // Setup Hover Card JS
                YafContext.Current.PageElements.RegisterJsBlockStartup(
                    "hovercardtwitterfacebookjs",
                    hoverCardLoadJs.ToString());
            }

            if (this.User != null && userData.Profile.Birthday >= DateTimeHelper.SqlDbMinTime())
            {
                this.BirthdayTR.Visible = true;
                this.Birthday.Text      =
                    this.Get <IDateTime>()
                    .FormatDateLong(userData.Profile.Birthday.AddMinutes((double)(-userData.TimeZone)));
            }
            else
            {
                this.BirthdayTR.Visible = false;
            }

            // Show User Medals
            if (this.Get <YafBoardSettings>().ShowMedals)
            {
                var userMedalsTable = this.Get <YafDbBroker>().UserMedals(this.UserId);

                if (userMedalsTable.Rows.Count <= 0)
                {
                    this.MedalsRow.Visible = false;

                    return;
                }

                var ribbonBar = new StringBuilder(500);
                var medals    = new StringBuilder(500);

                DataRow    r;
                MedalFlags f;

                int i     = 0;
                int inRow = 0;

                // do ribbon bar first
                while (userMedalsTable.Rows.Count > i)
                {
                    r = userMedalsTable.Rows[i];
                    f = new MedalFlags(r["Flags"]);

                    // do only ribbon bar items first
                    if (!r["OnlyRibbon"].ToType <bool>())
                    {
                        break;
                    }

                    // skip hidden medals
                    if (!f.AllowHiding || !r["Hide"].ToType <bool>())
                    {
                        if (inRow == 3)
                        {
                            // add break - only three ribbons in a row
                            ribbonBar.Append("<br />");
                            inRow = 0;
                        }

                        var title = "{0}{1}".FormatWith(
                            r["Name"],
                            f.ShowMessage ? ": {0}".FormatWith(r["Message"]) : string.Empty);

                        ribbonBar.AppendFormat(
                            "<img src=\"{0}{5}/{1}\" width=\"{2}\" height=\"{3}\" alt=\"{4}\" title=\"{4}\" />",
                            YafForumInfo.ForumClientFileRoot,
                            r["SmallRibbonURL"],
                            r["SmallRibbonWidth"],
                            r["SmallRibbonHeight"],
                            title,
                            YafBoardFolders.Current.Medals);

                        inRow++;
                    }

                    // move to next row
                    i++;
                }

                // follow with the rest
                while (userMedalsTable.Rows.Count > i)
                {
                    r = userMedalsTable.Rows[i];
                    f = new MedalFlags(r["Flags"]);

                    // skip hidden medals
                    if (!f.AllowHiding || !r["Hide"].ToType <bool>())
                    {
                        medals.AppendFormat(
                            "<img src=\"{0}{6}/{1}\" width=\"{2}\" height=\"{3}\" alt=\"{4}{5}\" title=\"{4}{5}\" />",
                            YafForumInfo.ForumClientFileRoot,
                            r["SmallMedalURL"],
                            r["SmallMedalWidth"],
                            r["SmallMedalHeight"],
                            r["Name"],
                            f.ShowMessage ? ": {0}".FormatWith(r["Message"]) : string.Empty,
                            YafBoardFolders.Current.Medals);
                    }

                    // move to next row
                    i++;
                }

                this.MedalsPlaceHolder.Text = "{0}<br />{1}".FormatWith(ribbonBar, medals);
                this.MedalsRow.Visible      = true;
            }
        }
Пример #5
0
        private string MatchUserBoxMedals([NotNull] string userBox)
        {
            string filler = string.Empty;
            var    rx     = this.GetRegex(Constants.UserBox.Medals);

            if (this.Get <YafBoardSettings>().ShowMedals)
            {
                DataTable dt = this.Get <YafDbBroker>().UserMedals(this.UserId);

                // vzrus: If user doesn't have we shouldn't render this waisting resources
                if (dt.Rows.Count <= 0)
                {
                    return(rx.Replace(userBox, filler));
                }

                var ribbonBar = new StringBuilder(500);
                var medals    = new StringBuilder(500);

                DataRow    r;
                MedalFlags f;

                int i     = 0;
                int inRow = 0;

                // do ribbon bar first
                while (dt.Rows.Count > i)
                {
                    r = dt.Rows[i];
                    f = new MedalFlags(r["Flags"]);

                    // do only ribbon bar items first
                    if (!r["OnlyRibbon"].ToType <bool>())
                    {
                        break;
                    }

                    // skip hidden medals
                    if (!f.AllowHiding || !r["Hide"].ToType <bool>())
                    {
                        if (inRow == 3)
                        {
                            // add break - only three ribbons in a row
                            ribbonBar.Append("<br />");
                            inRow = 0;
                        }

                        var title = "{0}{1}".FormatWith(
                            r["Name"], f.ShowMessage ? ": {0}".FormatWith(r["Message"]) : string.Empty);

                        ribbonBar.AppendFormat(
                            "<img src=\"{0}{5}/{1}\" width=\"{2}\" height=\"{3}\" alt=\"{4}\" title=\"{4}\" />",
                            YafForumInfo.ForumClientFileRoot,
                            r["SmallRibbonURL"],
                            r["SmallRibbonWidth"],
                            r["SmallRibbonHeight"],
                            title,
                            YafBoardFolders.Current.Medals);

                        inRow++;
                    }

                    // move to next row
                    i++;
                }

                // follow with the rest
                while (dt.Rows.Count > i)
                {
                    r = dt.Rows[i];
                    f = new MedalFlags(r["Flags"]);

                    // skip hidden medals
                    if (!f.AllowHiding || !r["Hide"].ToType <bool>())
                    {
                        medals.AppendFormat(
                            "<img src=\"{0}{6}/{1}\" width=\"{2}\" height=\"{3}\" alt=\"{4}{5}\" title=\"{4}{5}\" />",
                            YafForumInfo.ForumClientFileRoot,
                            r["SmallMedalURL"],
                            r["SmallMedalWidth"],
                            r["SmallMedalHeight"],
                            r["Name"],
                            f.ShowMessage ? ": {0}".FormatWith(r["Message"]) : string.Empty,
                            YafBoardFolders.Current.Medals);
                    }

                    // move to next row
                    i++;
                }

                filler = this.Get <YafBoardSettings>().UserBoxMedals.FormatWith(
                    this.GetText("MEDALS"), ribbonBar, medals);
            }

            // replaces template placeholder with actual medals
            userBox = rx.Replace(userBox, filler);

            return(userBox);
        }
Пример #6
0
        /// <summary>
        /// Bind data for this control.
        /// </summary>
        private void BindData()
        {
            // load available images from images/medals folder
            using (var dt = new DataTable("Files"))
            {
                // create structure
                dt.Columns.Add("FileID", typeof(long));
                dt.Columns.Add("FileName", typeof(string));
                dt.Columns.Add("Description", typeof(string));

                // add blank row
                DataRow dr = dt.NewRow();
                dr["FileID"]      = 0;
                dr["FileName"]    = "../spacer.gif"; // use blank.gif for Description Entry
                dr["Description"] = this.GetText("ADMIN_EDITMEDAL", "SELECT_IMAGE");
                dt.Rows.Add(dr);

                // add files from medals folder
                var dir =
                    new DirectoryInfo(
                        this.Request.MapPath("{0}{1}".FormatWith(YafForumInfo.ForumServerFileRoot, YafBoardFolders.Current.Medals)));
                FileInfo[] files = dir.GetFiles("*.*");

                long nFileID = 1;

                foreach (FileInfo file in from file in files
                         let sExt = file.Extension.ToLower()
                                    where sExt == ".png" || sExt == ".gif" || sExt == ".jpg"
                                    select file)
                {
                    dr                = dt.NewRow();
                    dr["FileID"]      = nFileID++;
                    dr["FileName"]    = file.Name;
                    dr["Description"] = file.Name;
                    dt.Rows.Add(dr);
                }

                // medal image
                this.MedalImage.DataSource     = dt;
                this.MedalImage.DataValueField = "FileName";
                this.MedalImage.DataTextField  = "Description";

                // ribbon bar image
                this.RibbonImage.DataSource     = dt;
                this.RibbonImage.DataValueField = "FileName";
                this.RibbonImage.DataTextField  = "Description";

                // small medal image
                this.SmallMedalImage.DataSource     = dt;
                this.SmallMedalImage.DataValueField = "FileName";
                this.SmallMedalImage.DataTextField  = "Description";

                // small ribbon bar image
                this.SmallRibbonImage.DataSource     = dt;
                this.SmallRibbonImage.DataValueField = "FileName";
                this.SmallRibbonImage.DataTextField  = "Description";
            }

            // bind data to controls
            this.DataBind();

            // load existing medal if we are editing one
            if (this.Request.QueryString.GetFirstOrDefault("m") != null)
            {
                // load users and groups who has been assigned this medal
                this.UserList.DataSource = LegacyDb.user_medal_list(null, this.Request.QueryString.GetFirstOrDefault("m"));
                this.UserList.DataBind();
                this.GroupList.DataSource = LegacyDb.group_medal_list(null, this.Request.QueryString.GetFirstOrDefault("m"));
                this.GroupList.DataBind();

                // enable adding users/groups
                this.AddUserRow.Visible  = true;
                this.AddGroupRow.Visible = true;

                using (DataTable dt = this.GetRepository <Medal>().List(this.Request.QueryString.GetFirstOrDefaultAs <int>("m")))
                {
                    // get data row
                    DataRow row = dt.Rows[0];

                    // load flags
                    var flags = new MedalFlags(row["Flags"]);

                    // set controls
                    this.Name.Text               = row["Name"].ToString();
                    this.Description.Text        = row["Description"].ToString();
                    this.Message.Text            = row["Message"].ToString();
                    this.Category.Text           = row["Category"].ToString();
                    this.SortOrder.Text          = row["SortOrder"].ToString();
                    this.ShowMessage.Checked     = flags.ShowMessage;
                    this.AllowRibbon.Checked     = flags.AllowRibbon;
                    this.AllowHiding.Checked     = flags.AllowHiding;
                    this.AllowReOrdering.Checked = flags.AllowReOrdering;

                    // select images
                    this.SelectImage(this.MedalImage, this.MedalPreview, row["MedalURL"]);
                    this.SelectImage(this.RibbonImage, this.RibbonPreview, row["RibbonURL"]);
                    this.SelectImage(this.SmallMedalImage, this.SmallMedalPreview, row["SmallMedalURL"]);
                    this.SelectImage(this.SmallRibbonImage, this.SmallRibbonPreview, row["SmallRibbonURL"]);
                }

                using (DataTable dt = LegacyDb.group_list(this.PageContext.PageBoardID, null))
                {
                    this.AvailableGroupList.DataSource     = dt;
                    this.AvailableGroupList.DataTextField  = "Name";
                    this.AvailableGroupList.DataValueField = "GroupID";
                    this.AvailableGroupList.DataBind();
                }
            }
            else
            {
                // set all previews on blank image
                var spacerPath = "{0}images/spacer.gif".FormatWith(YafForumInfo.ForumClientFileRoot);

                this.MedalPreview.Src       = spacerPath;
                this.RibbonPreview.Src      = spacerPath;
                this.SmallMedalPreview.Src  = spacerPath;
                this.SmallRibbonPreview.Src = spacerPath;
            }
        }
Пример #7
0
        /// <summary>
        /// Handles save button click.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Save_Click([NotNull] object sender, [NotNull] EventArgs e)
        {
            if (this.MedalImage.SelectedIndex <= 0)
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITMEDAL", "MSG_IMAGE"), MessageTypes.Warning);
                return;
            }

            if (this.SmallMedalImage.SelectedIndex <= 0)
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITMEDAL", "MSG_SMALL_IMAGE"), MessageTypes.Warning);
                return;
            }

            if (this.SortOrder.Text.Trim().Length == 0)
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_VALUE"), MessageTypes.Warning);
                return;
            }

            byte sortOrder;

            if (!ValidationHelper.IsValidPosShort(this.SortOrder.Text.Trim()))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_POSITIVE_VALUE"), MessageTypes.Warning);
                return;
            }

            if (!byte.TryParse(this.SortOrder.Text.Trim(), out sortOrder))
            {
                this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITFORUM", "MSG_CATEGORY"), MessageTypes.Warning);
                return;
            }

            // data
            int?   medalID = null;
            string ribbonURL = null, smallRibbonURL = null;
            short? ribbonWidth = null, ribbonHeight = null;
            Size   imageSize;
            var    flags = new MedalFlags(0);

            // retrieve medal ID, use null if we are creating new one
            if (this.Request.QueryString.GetFirstOrDefault("m") != null)
            {
                medalID = this.Request.QueryString.GetFirstOrDefaultAs <int>("m");
            }

            // flags
            flags.ShowMessage     = this.ShowMessage.Checked;
            flags.AllowRibbon     = this.AllowRibbon.Checked;
            flags.AllowReOrdering = this.AllowReOrdering.Checked;
            flags.AllowHiding     = this.AllowHiding.Checked;

            // get medal images
            string imageURL      = this.MedalImage.SelectedValue;
            string smallImageURL = this.SmallMedalImage.SelectedValue;

            if (this.RibbonImage.SelectedIndex > 0)
            {
                ribbonURL = this.RibbonImage.SelectedValue;
            }

            if (this.SmallRibbonImage.SelectedIndex > 0)
            {
                smallRibbonURL = this.SmallRibbonImage.SelectedValue;

                imageSize    = this.GetImageSize(smallRibbonURL.ToString());
                ribbonWidth  = imageSize.Width.ToType <short>();
                ribbonHeight = imageSize.Height.ToType <short>();
            }

            // get size of small image
            imageSize = this.GetImageSize(smallImageURL.ToString());

            // save medal
            this.GetRepository <Medal>().Save(
                medalID,
                this.Name.Text,
                this.Description.Text,
                this.Message.Text,
                this.Category.Text,
                imageURL,
                ribbonURL,
                smallImageURL,
                smallRibbonURL,
                (short)imageSize.Width,
                (short)imageSize.Height,
                ribbonWidth,
                ribbonHeight,
                sortOrder,
                flags.BitValue);

            // go back to medals administration
            YafBuildLink.Redirect(ForumPages.admin_medals);
        }
Пример #8
0
        /// <summary>
        /// Show the user medals.
        /// </summary>
        private void ShowUserMedals()
        {
            var key = string.Format(Constants.Cache.UserMedals, this.UserId);

            // get the medals cached...
            var userMedals = this.DataCache.GetOrSet(
                key,
                () => this.GetRepository <Medal>().ListUserMedals(this.UserId),
                TimeSpan.FromMinutes(10));

            if (!userMedals.Any())
            {
                this.MedalsRow.Visible = false;

                return;
            }

            var ribbonBar = new StringBuilder();
            var medals    = new StringBuilder();

            // var inRow = 0;

            // do ribbon bar first
            userMedals.Where(x => x.OnlyRibbon).ForEach(
                medal =>
            {
                var flags = new MedalFlags(medal.Flags);

                // skip hidden medals
                if (flags.AllowHiding && medal.Hide)
                {
                    return;
                }

                var title = $"{medal.Name}{(flags.ShowMessage ? $": {medal.Message}" : string.Empty)}";

                ribbonBar.AppendFormat(
                    "<li class=\"list-inline-item\"><img src=\"{0}{3}/{1}\" alt=\"{2}\" title=\"{2}\" data-bs-toggle=\"tooltip\"></li>",
                    BoardInfo.ForumClientFileRoot,
                    medal.SmallRibbonURL,
                    title,
                    this.Get <BoardFolders>().Medals);
            });

            // follow with the rest
            userMedals.Where(x => !x.OnlyRibbon).ForEach(
                medal =>
            {
                var flags = new MedalFlags(medal.Flags);

                // skip hidden medals
                if (flags.AllowHiding && medal.Hide)
                {
                    return;
                }

                medals.AppendFormat(
                    "<li class=\"list-inline-item\"><img src=\"{0}{4}/{1}\" alt=\"{2}{3}\" title=\"{2}{3}\" data-bs-toggle=\"tooltip\"></li>",
                    BoardInfo.ForumClientFileRoot,
                    medal.SmallMedalURL,
                    medal.Name,
                    flags.ShowMessage ? $": {medal.Message}" : string.Empty,
                    this.Get <BoardFolders>().Medals);
            });

            this.MedalsPlaceHolder.Text = $"<ul class=\"list-inline\">{ribbonBar}{medals}</ul>";
            this.MedalsRow.Visible      = true;
        }
Пример #9
0
        /// <summary>
        /// Bind data for this control.
        /// </summary>
        private void BindData()
        {
            // load available images from images/medals folder
            using (var dt = new DataTable("Files"))
            {
                // create structure
                dt.Columns.Add("FileID", typeof(long));
                dt.Columns.Add("FileName", typeof(string));
                dt.Columns.Add("Description", typeof(string));

                // add blank row
                var dr = dt.NewRow();
                dr["FileID"]   = 0;
                dr["FileName"] =
                    YafForumInfo.GetURLToContent("images/spacer.gif"); // use spacer.gif for Description Entry
                dr["Description"] = this.GetText("ADMIN_EDITMEDAL", "SELECT_IMAGE");
                dt.Rows.Add(dr);

                // add files from medals folder
                var dir = new DirectoryInfo(
                    this.Request.MapPath($"{YafForumInfo.ForumServerFileRoot}{YafBoardFolders.Current.Medals}"));
                var files = dir.GetFiles("*.*");

                long fileId = 1;

                foreach (var file in from file in files
                         let sExt = file.Extension.ToLower()
                                    where sExt == ".png" || sExt == ".gif" || sExt == ".jpg"
                                    select file)
                {
                    dr                = dt.NewRow();
                    dr["FileID"]      = fileId++;
                    dr["FileName"]    = file.Name;
                    dr["Description"] = file.Name;
                    dt.Rows.Add(dr);
                }

                // medal image
                this.MedalImage.DataSource     = dt;
                this.MedalImage.DataValueField = "FileName";
                this.MedalImage.DataTextField  = "Description";

                // ribbon bar image
                this.RibbonImage.DataSource     = dt;
                this.RibbonImage.DataValueField = "FileName";
                this.RibbonImage.DataTextField  = "Description";

                // small medal image
                this.SmallMedalImage.DataSource     = dt;
                this.SmallMedalImage.DataValueField = "FileName";
                this.SmallMedalImage.DataTextField  = "Description";

                // small ribbon bar image
                this.SmallRibbonImage.DataSource     = dt;
                this.SmallRibbonImage.DataValueField = "FileName";
                this.SmallRibbonImage.DataTextField  = "Description";
            }

            // bind data to controls
            this.DataBind();

            // load existing medal if we are editing one
            if (this.CurrentMedalId.HasValue)
            {
                // load users and groups who has been assigned this medal
                this.UserList.DataSource = this.GetRepository <UserMedal>().ListAsDataTable(null, this.CurrentMedalId);
                this.UserList.DataBind();

                this.GroupList.DataSource =
                    this.GetRepository <Medal>().GroupMedalListAsDataTable(null, this.CurrentMedalId);
                this.GroupList.DataBind();

                using (var dt = this.GetRepository <Medal>().List(this.CurrentMedalId))
                {
                    // get data row
                    var row = dt.Rows[0];

                    // load flags
                    var flags = new MedalFlags(row["Flags"]);

                    // set controls
                    this.Name.Text               = row["Name"].ToString();
                    this.Description.Text        = row["Description"].ToString();
                    this.Message.Text            = row["Message"].ToString();
                    this.Category.Text           = row["Category"].ToString();
                    this.SortOrder.Text          = row["SortOrder"].ToString();
                    this.ShowMessage.Checked     = flags.ShowMessage;
                    this.AllowRibbon.Checked     = flags.AllowRibbon;
                    this.AllowHiding.Checked     = flags.AllowHiding;
                    this.AllowReOrdering.Checked = flags.AllowReOrdering;

                    // select images
                    this.SelectImage(this.MedalImage, this.MedalPreview, row["MedalURL"]);
                    this.SelectImage(this.RibbonImage, this.RibbonPreview, row["RibbonURL"]);
                    this.SelectImage(this.SmallMedalImage, this.SmallMedalPreview, row["SmallMedalURL"]);
                    this.SelectImage(this.SmallRibbonImage, this.SmallRibbonPreview, row["SmallRibbonURL"]);
                }
            }
            else
            {
                // set all previews on blank image
                var spacerPath =
                    YafForumInfo.GetURLToContent("images/spacer.gif"); // use spacer.gif for Description Entry

                this.MedalPreview.Src       = spacerPath;
                this.RibbonPreview.Src      = spacerPath;
                this.SmallMedalPreview.Src  = spacerPath;
                this.SmallRibbonPreview.Src = spacerPath;
            }
        }
Пример #10
0
		/// <summary>
		/// Handles save button click.
		/// </summary>
		protected void Save_Click(object sender, System.EventArgs e)
		{
			if (MedalImage.SelectedIndex <= 0)
			{
				PageContext.AddLoadMessage("Medal image must be specified!");
				return;
			}
			else if (SmallMedalImage.SelectedIndex <= 0)
			{
				PageContext.AddLoadMessage("Small medal image must be specified!");
				return;
			}

			// data
			object medalID = null;
			object imageURL, smallImageURL, ribbonURL = null, smallRibbonURL = null;
			object ribbonWidth = null, ribbonHeight = null;
			Size imageSize;
			MedalFlags flags = new MedalFlags(0);

			// retrieve medal ID, use null if we are creating new one
			if (Request.QueryString["m"] != null) medalID = Request.QueryString["m"];

			// flags
			flags.ShowMessage = ShowMessage.Checked;
			flags.AllowRibbon = AllowRibbon.Checked;
			flags.AllowReOrdering = AllowReOrdering.Checked;
			flags.AllowHiding = AllowHiding.Checked;

			// get medal images
			imageURL = MedalImage.SelectedValue;
			smallImageURL = SmallMedalImage.SelectedValue;
			if (RibbonImage.SelectedIndex > 0) ribbonURL = RibbonImage.SelectedValue;
			if (SmallRibbonImage.SelectedIndex > 0)
			{
				smallRibbonURL = SmallRibbonImage.SelectedValue;

				imageSize = GetImageSize(smallRibbonURL.ToString());
				ribbonWidth = imageSize.Width;
				ribbonHeight = imageSize.Height;
			}

			// get size of small image
			imageSize = GetImageSize(smallImageURL.ToString());			

			// save medal
			DB.medal_save(PageContext.PageBoardID, medalID, Name.Text, Description.Text, Message.Text, Category.Text, imageURL, ribbonURL,
					smallImageURL, smallRibbonURL, imageSize.Width, imageSize.Height, ribbonWidth, ribbonHeight, SortOrder.Text, flags.BitValue);

			// go back to medals administration
			YafBuildLink.Redirect( ForumPages.admin_medals );
		}
Пример #11
0
		/// <summary>
		/// Bind data for this control.
		/// </summary>
		private void BindData()
		{
			// load available images from images/medals folder
			using (DataTable dt = new DataTable("Files"))
			{
				// create structure
				dt.Columns.Add("FileID", typeof(long));
				dt.Columns.Add("FileName", typeof(string));
				dt.Columns.Add("Description", typeof(string));

				// add blank row
				DataRow dr = dt.NewRow();
				dr["FileID"] = 0;
				dr["FileName"] = "../spacer.gif"; // use blank.gif for Description Entry
				dr["Description"] = "Select Medal Image";
				dt.Rows.Add(dr);

				// add files from medals folder
				DirectoryInfo dir = new DirectoryInfo(Request.MapPath(String.Format("{0}images/medals", YafForumInfo.ForumFileRoot)));
				FileInfo[] files = dir.GetFiles("*.*");

				long nFileID = 1;

				foreach (FileInfo file in files)
				{
					string sExt = file.Extension.ToLower();

					// do just images
					if (sExt != ".png" && sExt != ".gif" && sExt != ".jpg")
						continue;

					dr = dt.NewRow();
					dr["FileID"] = nFileID++;
					dr["FileName"] = file.Name;
					dr["Description"] = file.Name;
					dt.Rows.Add(dr);
				}

				// medal image
				MedalImage.DataSource = dt;
				MedalImage.DataValueField = "FileName";
				MedalImage.DataTextField = "Description";

				// ribbon bar image
				RibbonImage.DataSource = dt;
				RibbonImage.DataValueField = "FileName";
				RibbonImage.DataTextField = "Description";

				// small medal image
				SmallMedalImage.DataSource = dt;
				SmallMedalImage.DataValueField = "FileName";
				SmallMedalImage.DataTextField = "Description";

				// small ribbon bar image
				SmallRibbonImage.DataSource = dt;
				SmallRibbonImage.DataValueField = "FileName";
				SmallRibbonImage.DataTextField = "Description";
			}

			// bind data to controls
			DataBind();

			// load existing medal if we are editing one
			if (Request.QueryString["m"] != null)
			{
				// load users and groups who has been assigned this medal
				UserList.DataSource = DB.user_medal_list(null, Request.QueryString["m"]);
				UserList.DataBind();
				GroupList.DataSource = DB.group_medal_list(null, Request.QueryString["m"]);
				GroupList.DataBind();

				// enable adding users/groups
				AddUserRow.Visible = true;
				AddGroupRow.Visible = true;

				using (DataTable dt = YAF.Classes.Data.DB.medal_list(Request.QueryString["m"]))
				{
					// get data row
					DataRow row = dt.Rows[0];

					// load flags
					MedalFlags flags = new MedalFlags(row["Flags"]);

					// set controls
					Name.Text = row["Name"].ToString();
					Description.Text = row["Description"].ToString();
					Message.Text = row["Message"].ToString();
					Category.Text = row["Category"].ToString();
					SortOrder.Text = row["SortOrder"].ToString();
					ShowMessage.Checked = flags.ShowMessage;
					AllowRibbon.Checked = flags.AllowRibbon;
					AllowHiding.Checked = flags.AllowHiding;
					AllowReOrdering.Checked = flags.AllowReOrdering;

					// select images
					SelectImage(MedalImage, MedalPreview, row["MedalURL"]);
					SelectImage(RibbonImage, RibbonPreview, row["RibbonURL"]);
					SelectImage(SmallMedalImage, SmallMedalPreview, row["SmallMedalURL"]);
					SelectImage(SmallRibbonImage, SmallRibbonPreview, row["SmallRibbonURL"]);
				}

				using (DataTable dt = DB.group_list(PageContext.PageBoardID, null))
				{
					// get data row
					DataRow row = dt.Rows[0];

					AvailableGroupList.DataSource = dt;
					AvailableGroupList.DataTextField = "Name";
					AvailableGroupList.DataValueField = "GroupID";
					AvailableGroupList.DataBind();
				}
			}
			else
			{
				// set all previews on blank image
				MedalPreview.Src = String.Format("{0}images/spacer.gif", YafForumInfo.ForumRoot);
				RibbonPreview.Src = String.Format("{0}images/spacer.gif", YafForumInfo.ForumRoot);
				SmallMedalPreview.Src = String.Format("{0}images/spacer.gif", YafForumInfo.ForumRoot);
				SmallRibbonPreview.Src = String.Format("{0}images/spacer.gif", YafForumInfo.ForumRoot);
			}
		}
Пример #12
0
        /// <summary>
        /// Show the user medals.
        /// </summary>
        private void ShowUserMedals()
        {
            var userMedalsTable = this.Get <DataBroker>().UserMedals(this.UserId);

            if (!userMedalsTable.HasRows())
            {
                this.MedalsRow.Visible = false;

                return;
            }

            var ribbonBar = new StringBuilder(500);
            var medals    = new StringBuilder(500);

            DataRow    r;
            MedalFlags f;

            var i     = 0;
            var inRow = 0;

            // do ribbon bar first
            while (userMedalsTable.Rows.Count > i)
            {
                r = userMedalsTable.Rows[i];
                f = new MedalFlags(r["Flags"]);

                // do only ribbon bar items first
                if (!r["OnlyRibbon"].ToType <bool>())
                {
                    break;
                }

                // skip hidden medals
                if (!f.AllowHiding || !r["Hide"].ToType <bool>())
                {
                    if (inRow == 3)
                    {
                        // add break - only three ribbons in a row
                        ribbonBar.Append("<br />");
                        inRow = 0;
                    }

                    var title = $"{r["Name"]}{(f.ShowMessage ? $": {r["Message"]}" : string.Empty)}";

                    ribbonBar.AppendFormat(
                        "<img src=\"{0}{5}/{1}\" width=\"{2}\" height=\"{3}\" alt=\"{4}\" title=\"{4}\" class=\"mr-1\" />",
                        BoardInfo.ForumClientFileRoot,
                        r["SmallRibbonURL"],
                        r["SmallRibbonWidth"],
                        r["SmallRibbonHeight"],
                        title,
                        BoardFolders.Current.Medals);

                    inRow++;
                }

                // move to next row
                i++;
            }

            // follow with the rest
            while (userMedalsTable.Rows.Count > i)
            {
                r = userMedalsTable.Rows[i];
                f = new MedalFlags(r["Flags"]);

                // skip hidden medals
                if (!f.AllowHiding || !r["Hide"].ToType <bool>())
                {
                    medals.AppendFormat(
                        "<img src=\"{0}{6}/{1}\" width=\"{2}\" height=\"{3}\" alt=\"{4}{5}\" title=\"{4}{5}\" class=\"mr-1\" />",
                        BoardInfo.ForumClientFileRoot,
                        r["SmallMedalURL"],
                        r["SmallMedalWidth"],
                        r["SmallMedalHeight"],
                        r["Name"],
                        f.ShowMessage ? $": {r["Message"]}" : string.Empty,
                        BoardFolders.Current.Medals);
                }

                // move to next row
                i++;
            }

            this.MedalsPlaceHolder.Text = $"{ribbonBar}<br />{medals}";
            this.MedalsRow.Visible      = true;
        }
Пример #13
0
        /// <summary>
        /// Handles save button click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Save_Click(object sender, EventArgs e)
        {
            if (this.MedalImage.SelectedIndex <= 0)
            {
                PageContext.AddLoadMessage("Medal image must be specified!");
                return;
            }
            else if (this.SmallMedalImage.SelectedIndex <= 0)
            {
                PageContext.AddLoadMessage("Small medal image must be specified!");
                return;
            }
            if (this.SortOrder.Text.Trim().Length == 0)
            {
                PageContext.AddLoadMessage("You must enter a value for sort order.");
                return;
            }

            short sortOrder = 0;

            if (!ValidationHelper.IsValidPosShort(this.SortOrder.Text.Trim()))
            {
                PageContext.AddLoadMessage("The sort order value should be a positive integer from 0 to 32767.");
                return;
            }

            if (!short.TryParse(this.SortOrder.Text.Trim(), out sortOrder))
            {
                PageContext.AddLoadMessage("You must enter an number value from 0 to 32767 for sort order.");
                return;
            }

            // data
            object medalID = null;
            object imageURL, smallImageURL, ribbonURL = null, smallRibbonURL = null;
            object ribbonWidth = null, ribbonHeight = null;
            Size   imageSize;
            var    flags = new MedalFlags(0);

            // retrieve medal ID, use null if we are creating new one
            if (Request.QueryString.GetFirstOrDefault("m") != null)
            {
                medalID = Request.QueryString.GetFirstOrDefault("m");
            }

            // flags
            flags.ShowMessage     = this.ShowMessage.Checked;
            flags.AllowRibbon     = this.AllowRibbon.Checked;
            flags.AllowReOrdering = this.AllowReOrdering.Checked;
            flags.AllowHiding     = this.AllowHiding.Checked;

            // get medal images
            imageURL      = this.MedalImage.SelectedValue;
            smallImageURL = this.SmallMedalImage.SelectedValue;
            if (this.RibbonImage.SelectedIndex > 0)
            {
                ribbonURL = this.RibbonImage.SelectedValue;
            }

            if (this.SmallRibbonImage.SelectedIndex > 0)
            {
                smallRibbonURL = this.SmallRibbonImage.SelectedValue;

                imageSize    = GetImageSize(smallRibbonURL.ToString());
                ribbonWidth  = imageSize.Width;
                ribbonHeight = imageSize.Height;
            }

            // get size of small image
            imageSize = GetImageSize(smallImageURL.ToString());

            // save medal
            DB.medal_save(
                PageContext.PageBoardID,
                medalID,
                this.Name.Text,
                this.Description.Text,
                this.Message.Text,
                this.Category.Text,
                imageURL,
                ribbonURL,
                smallImageURL,
                smallRibbonURL,
                imageSize.Width,
                imageSize.Height,
                ribbonWidth,
                ribbonHeight,
                sortOrder,
                flags.BitValue);

            // go back to medals administration
            YafBuildLink.Redirect(ForumPages.admin_medals);
        }
Пример #14
0
        /// <summary>
        /// Bind data for this control.
        /// </summary>
        private void BindData()
        {
            // load available images from images/medals folder
            using (DataTable dt = new DataTable("Files"))
            {
                // create structure
                dt.Columns.Add("FileID", typeof(long));
                dt.Columns.Add("FileName", typeof(string));
                dt.Columns.Add("Description", typeof(string));

                // add blank row
                DataRow dr = dt.NewRow();
                dr["FileID"]      = 0;
                dr["FileName"]    = "../spacer.gif";              // use blank.gif for Description Entry
                dr["Description"] = "Select Medal Image";
                dt.Rows.Add(dr);

                // add files from medals folder
                DirectoryInfo dir   = new DirectoryInfo(Request.MapPath(String.Format("{0}images/medals", YafForumInfo.ForumFileRoot)));
                FileInfo[]    files = dir.GetFiles("*.*");

                long nFileID = 1;

                foreach (FileInfo file in files)
                {
                    string sExt = file.Extension.ToLower();

                    // do just images
                    if (sExt != ".png" && sExt != ".gif" && sExt != ".jpg")
                    {
                        continue;
                    }

                    dr                = dt.NewRow();
                    dr["FileID"]      = nFileID++;
                    dr["FileName"]    = file.Name;
                    dr["Description"] = file.Name;
                    dt.Rows.Add(dr);
                }

                // medal image
                MedalImage.DataSource     = dt;
                MedalImage.DataValueField = "FileName";
                MedalImage.DataTextField  = "Description";

                // ribbon bar image
                RibbonImage.DataSource     = dt;
                RibbonImage.DataValueField = "FileName";
                RibbonImage.DataTextField  = "Description";

                // small medal image
                SmallMedalImage.DataSource     = dt;
                SmallMedalImage.DataValueField = "FileName";
                SmallMedalImage.DataTextField  = "Description";

                // small ribbon bar image
                SmallRibbonImage.DataSource     = dt;
                SmallRibbonImage.DataValueField = "FileName";
                SmallRibbonImage.DataTextField  = "Description";
            }

            // bind data to controls
            DataBind();

            // load existing medal if we are editing one
            if (Request.QueryString["m"] != null)
            {
                // load users and groups who has been assigned this medal
                UserList.DataSource = DB.user_medal_list(null, Request.QueryString["m"]);
                UserList.DataBind();
                GroupList.DataSource = DB.group_medal_list(null, Request.QueryString["m"]);
                GroupList.DataBind();

                // enable adding users/groups
                AddUserRow.Visible  = true;
                AddGroupRow.Visible = true;

                using (DataTable dt = YAF.Classes.Data.DB.medal_list(Request.QueryString["m"]))
                {
                    // get data row
                    DataRow row = dt.Rows[0];

                    // load flags
                    MedalFlags flags = new MedalFlags(row["Flags"]);

                    // set controls
                    Name.Text               = row["Name"].ToString();
                    Description.Text        = row["Description"].ToString();
                    Message.Text            = row["Message"].ToString();
                    Category.Text           = row["Category"].ToString();
                    SortOrder.Text          = row["SortOrder"].ToString();
                    ShowMessage.Checked     = flags.ShowMessage;
                    AllowRibbon.Checked     = flags.AllowRibbon;
                    AllowHiding.Checked     = flags.AllowHiding;
                    AllowReOrdering.Checked = flags.AllowReOrdering;

                    // select images
                    SelectImage(MedalImage, MedalPreview, row["MedalURL"]);
                    SelectImage(RibbonImage, RibbonPreview, row["RibbonURL"]);
                    SelectImage(SmallMedalImage, SmallMedalPreview, row["SmallMedalURL"]);
                    SelectImage(SmallRibbonImage, SmallRibbonPreview, row["SmallRibbonURL"]);
                }

                using (DataTable dt = DB.group_list(PageContext.PageBoardID, null))
                {
                    // get data row
                    DataRow row = dt.Rows[0];

                    AvailableGroupList.DataSource     = dt;
                    AvailableGroupList.DataTextField  = "Name";
                    AvailableGroupList.DataValueField = "GroupID";
                    AvailableGroupList.DataBind();
                }
            }
            else
            {
                // set all previews on blank image
                MedalPreview.Src       = String.Format("{0}images/spacer.gif", YafForumInfo.ForumRoot);
                RibbonPreview.Src      = String.Format("{0}images/spacer.gif", YafForumInfo.ForumRoot);
                SmallMedalPreview.Src  = String.Format("{0}images/spacer.gif", YafForumInfo.ForumRoot);
                SmallRibbonPreview.Src = String.Format("{0}images/spacer.gif", YafForumInfo.ForumRoot);
            }
        }