public bool CanAccess(DataRow memberRow, string Property, Control ctrl)
        {
            if ((int)memberRow["MemberId"] != WebContext.Profile.UserId)
            {
                int privacy = (int)memberRow["Privacy"];

                switch (CheckMemberProperty(Property, privacy))
                {
                case PrivacyOptions.OnlyMe:
                    return(false);

                case PrivacyOptions.Friends:
                    lw.Base.CustomPage page = ctrl.Page as lw.Base.CustomPage;

                    DataTable MyFriends = FriendsManager.GetMyFriends(page);

                    if (MyFriends.Select(string.Format("FriendId={0} and Status=1", memberRow["MemberId"])).Length == 0)
                    {
                        return(false);
                    }
                    break;

                default:
                    break;
                }
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// Returns the current logged in user with his profile
        /// </summary>
        /// <param name="ctrl">Any control on the current page or the page itself</param>
        /// <param name="GetWithProfile">Flag if set to true it will read from MemberView if false it will read from Members</param>
        /// <returns>DataRow Logged In Member</returns>
        public static DataRow LoggedInUser(Control ctrl, bool GetWithProfile)
        {
            lw.Base.CustomPage page = null;
            if (ctrl != null)
            {
                page = ctrl.Page as lw.Base.CustomPage;
            }

            if (page != null)
            {
                if (page.PageContext[cte.LoggedInUserContextKey] != null)
                {
                    return(page.PageContext[cte.LoggedInUserContextKey] as DataRow);
                }
            }

            if (WebContext.Profile.UserLogged)
            {
                MembersManager mMgr = new MembersManager();

                DataTable members;

                if (GetWithProfile)
                {
                    members = mMgr.GetMembersWithProfile(string.Format("MemberId={0}", WebContext.Profile.UserId));
                }
                else
                {
                    members = mMgr.GetMembers(string.Format("MemberId={0}", WebContext.Profile.UserId));
                }

                if (members.Rows.Count > 0)
                {
                    if (page != null)
                    {
                        page.PageContext[cte.LoggedInUserContextKey] = members.Rows[0];
                    }
                    return(members.Rows[0]);
                }
            }
            else
            {
                SignOut();
            }
            return(null);
        }
示例#3
0
        public static DataTable GetMyFriends(lw.Base.CustomPage page)
        {
            DataTable MyFriends = null;

            if (page.PageContext["Friends"] != null)
            {
                MyFriends = page.PageContext["Friends"] as DataTable;
            }
            if (MyFriends == null)
            {
                FriendsManager fMgr = new FriendsManager();
                MyFriends = fMgr.GetFriendsRawData(WebContext.Profile.UserId);
                page.PageContext["Friends"] = MyFriends;
            }

            return(MyFriends);
        }
示例#4
0
        public override void DataBind()
        {
            if (!this.Visible)
            {
                return;
            }

            if (CategoryDetails == null)
            {
                //If the article is not found or it's status is set to no display
                //this.Page.Response.StatusCode = 404;
                //this.Page.Response.StatusDescription = "404 Not Found";

                return;
            }

            if (Bound)
            {
                return;
            }
            Bound = true;

            DataItem = CategoryDetails;

            if (OverridePageTitle)
            {
                Config cfg = new Config();

                lw.Base.CustomPage page = this.Page as lw.Base.CustomPage;
                if (page != null)
                {
                    if (!String.IsNullOrEmpty(CategoryDetails.Name))
                    {
                        page.CustomTitle = string.Format("{0} - {1}",
                                                         StringUtils.StripOutHtmlTags(CategoryDetails.Name),
                                                         cfg.GetKey("SiteName"));
                    }
                }
            }
            base.DataBind();
        }
示例#5
0
        public DataView GetItemPrices(int ItemId, lw.Base.CustomPage page)
        {
            ProductsDS.ItemPricesDataTable allPrices;
            if (page.PageContext[cte.ItemPricesContext] == null)
            {
                string itemIds = page.PageContext[cte.ItemIdsContext].ToString();
                string cond    = "";
                if (!String.IsNullOrWhiteSpace(itemIds))
                {
                    cond = "ItemId in  (" + itemIds.Substring(0, itemIds.Length - 1) + ")";
                }
                allPrices = GetItemPrices(cond);
                page.PageContext[cte.ItemPricesContext] = allPrices;
            }
            else
            {
                allPrices = page.PageContext[cte.ItemPricesContext] as ProductsDS.ItemPricesDataTable;
            }

            return(new DataView(allPrices, "ItemId=" + ItemId.ToString(), "", DataViewRowState.CurrentRows));
        }
示例#6
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;

            lw.Base.CustomPage page = this.Page as lw.Base.CustomPage;

            string action = Attributes["action"];

            if (action != "")
            {
                try
                {
                    action = Page.ResolveClientUrl(action);
                    Attributes["action"] = action;
                }
                catch
                {
                }
            }
            if (!_valuesSet)
            {
                this.SetValues(this);
                _valuesSet = true;
            }


            if (_ajaxSubmit)
            {
                page.RegisterLoadScript("init-forms", "lw.ajaxForms.init();");
            }

            base.DataBind();
        }
示例#7
0
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (!_bound)
            {
                this.DataBind();
            }



            if (memberRow == null)
            {
                return;
            }


            MembersManager mMgr = new MembersManager();


            //why we have to get the member row again??? i couldn't find a reason.
            //memberRow = mMgr.GetMemberProfile((int)memberRow["MemberId"]);


            string picture = "";

            if (memberRow["Picture"] != System.DBNull.Value &&
                !String.IsNullOrEmpty(memberRow["Picture"].ToString()))
            {
                picture = memberRow["Picture"].ToString();
            }
            int MemberId = (int)memberRow["MemberId"];
            int privacy  = 0;

            if (memberRow["Privacy"] != DBNull.Value)
            {
                privacy = (int)memberRow["Privacy"];
            }

            string image = "";

            PrivacySettingsManager psMgr = new PrivacySettingsManager();

            if (MemberId != WebContext.Profile.UserId)
            {
                switch (psMgr.CheckMemberProperty("ProfilePicture", privacy))
                {
                case PrivacyOptions.OnlyMe:
                    picture = "";
                    break;

                case PrivacyOptions.Friends:
                    lw.Base.CustomPage page = this.Page as lw.Base.CustomPage;

                    DataTable MyFriends = FriendsManager.GetMyFriends(page);

                    if (MyFriends.Select(string.Format("FriendId={0} and Status=1", memberRow["MemberId"])).Length == 0)
                    {
                        picture = "";
                    }
                    break;

                default:
                    break;
                }
                if (!Visible)
                {
                    return;
                }
            }

            if (picture != "")
            {
                if (useGUID)
                {
                    image = string.Format("{0}/{2}/{1}",
                                          MembersSettings.MemberPicturesFolder, picture, StringUtils.ToURL(memberRow["Geuid"]));
                }
                else
                {
                    image = string.Format("{0}/{2}/{1}",
                                          MembersSettings.MemberPicturesFolder, picture, StringUtils.ToURL(memberRow["UserName"]));
                }
            }
            else
            {
                if (NoPicture != "")
                {
                    image     = NoPicture;
                    this._Src = NoPicture;
                }

                else
                {
                    if (NoFPicture != "" && NoMPicture != "")
                    {
                        Gender?_gender = Gender.Male;
                        try
                        {
                            _gender = (lw.Members.Gender)Enum.Parse(typeof(lw.Members.Gender), memberRow["Gender"].ToString());
                        }
                        catch
                        {
                        }


                        if (_gender == lw.Members.Gender.Male)
                        {
                            image     = NoMPicture;
                            this._Src = NoMPicture;
                        }
                        else
                        {
                            image     = NoFPicture;
                            this._Src = NoFPicture;
                        }
                    }
                }
            }

            //this.Alt = memberRow["Name"].ToString();
            this.Alt = memberRow["FirstName"].ToString() + " " + memberRow["LastName"].ToString();

            switch (MemberImageType)
            {
            case ImageType.Crop:
            case ImageType.Resize:
                if (_width > 0)
                {
                    if (MemberImageType == ImageType.Resize)
                    {
                        this._Src = string.Format("{4}/prv/handlers/ImageResizer.ashx?src={0}&width={1}&height={2}&fillColor={3}",
                                                  image, _Width, _Height, FillColor.ToArgb(), WebContext.Root);
                    }
                    else
                    {
                        this._Src = string.Format("{4}/prv/handlers/ImageCropper.ashx?src={0}&width={1}&height={2}&fillColor={3}",
                                                  image, _Width, _Height, FillColor.ToArgb());
                    }
                }
                else
                {
                    this._Src = string.Format("{0}/{1}", WebContext.Root, image);
                }
                break;

            case ImageType.NewResize:
                this._Src = string.Format("{3}prv/handlers/ResizeImage.ashx?img={0}&w={1}&h={2}",
                                          image, _Width, _Height, WebContext.Root);
                break;

            case ImageType.Large:
                this._Src = image;
                break;

            case ImageType.Medium:
                if (picture != "")
                {
                    this._Src = image.ToLower().Replace(".jpg", "-m.jpg");
                }
                else
                {
                    this._Src = NoPicture;
                }
                break;

            case ImageType.Thumb:
                if (picture != "")
                {
                    this._Src = image.ToLower().Replace(".jpg", "-s.jpg?" + DateTime.Now.ToFileTime());                             // Datetime added to prevent cashing
                }
                else
                {
                    this._Src = NoPicture;
                }
                break;

            default:
                break;
            }
            if (this._Src != "")
            {
                this.Src = WebContext.Root + "/" + this._Src;
                base.Render(writer);
            }
        }
示例#8
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;

            _page = this.Page as lw.Base.CustomPage;


            this.SelectCommand = "select Top " + Top + " * from " + TableName;
            string cond = "";

            if (Status != null)
            {
                cond = " where Status = " + (int)Status;
            }
            else
            {
                cond = " where 1=1 ";
            }

            if (!string.IsNullOrEmpty(Condition))
            {
                cond += string.Format(" and {0}", Condition);
            }

            if (MemberId != null && String.Compare(WebContext.Profile.dbUserName, Config.GetFromWebConfig("Admin"), true) != 0 && NetworkBound)
            {
                cond += " and NetworkId in (select NetworkId from MemberNetworks where MemberId={0}";
                if (onlyPreferred != null && onlyPreferred.Value)
                {
                    cond += " and Prefered=1";
                }
                cond += ")";
                cond  = string.Format(cond, memberId);
            }

            if (ParentId != null)
            {
                cond += " and ParentId=" + _parentId.Value.ToString();
            }

            if (!string.IsNullOrWhiteSpace(ParentUniqueName) && (ParentId == null))
            {
                NetworksManager nMgr       = new NetworksManager();
                var             parentName = nMgr.GetNetwork(ParentUniqueName);
                int?            pId        = null;
                if (parentName != null)
                {
                    pId = parentName.NetworkId;
                }
                if (pId != null)
                {
                    cond += " and ParentId = " + pId;
                }
            }

            if (CMSMode != null && CMSMode.Value)
            {
                string q           = WebContext.Request["q"];
                string netDateFrom = WebContext.Request["DateFrom"];
                string netDateTo   = WebContext.Request["DateTo"];

                if (!string.IsNullOrWhiteSpace(q))
                {
                    cond += string.Format(" and (Name like '%{0}%' or UniqueName like '%{0}%')", StringUtils.SQLEncode(q));
                }

                if (!string.IsNullOrWhiteSpace(netDateFrom) && !string.IsNullOrWhiteSpace(netDateTo))
                {
                    cond += string.Format(" and DateCreated between '{0}' and '{1}'", DateTime.Parse(netDateFrom), DateTime.Parse(netDateTo));
                }
                else if (!string.IsNullOrWhiteSpace(netDateFrom))
                {
                    cond += string.Format(" and DateCreated >= '{0}'", DateTime.Parse(netDateFrom));
                }
                else if (!string.IsNullOrWhiteSpace(netDateTo))
                {
                    cond += string.Format(" and DateCreated <= '{0}'", DateTime.Parse(netDateTo));
                }
            }

            if (!string.IsNullOrWhiteSpace(OrderBy))
            {
                cond += " Order By " + OrderBy;
            }

            this.SelectCommand += cond;

            base.DataBind();
        }
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;

            lw.Base.CustomPage page = this.Page as lw.Base.CustomPage;

            string GroupName = page.GetQueryValue("CommentTitle");

            if (!StringUtils.IsNullOrWhiteSpace(GroupName))
            {
                String[] Split = GroupName.Split('-');
                CommentId = Int32.Parse(Split[Split.Length - 1]);
            }


            if (ChildComments)
            {
                object obj = DataBinder.Eval(this.NamingContainer, "DataItem.CommentId");

                if (obj != null)
                {
                    ParentId = (int)obj;
                }
            }

            if (ParentId == -1)
            {
                object relationValue = DataBinder.Eval(this.NamingContainer, "DataItem." + cte.CommentsRelateTo);

                if (relationValue != null)
                {
                    RelationId = (int)relationValue;
                }
            }
            GenerateSelectCommand(int.Parse(Top), 0);

            this.Visible = HasViewPermission;


            if (InheritPermission)
            {
                GroupCommentsDataSource parentDataSource = null;
                Control parent = this.Parent;
                do
                {
                    parentDataSource = parent as GroupCommentsDataSource;
                    if (parentDataSource != null)
                    {
                        break;
                    }

                    parent = parent.Parent;
                }while (parent != null);

                if (parentDataSource != null)
                {
                    _hasWritePermission  = parentDataSource.HasWritePermission;
                    _hasViewPermission   = parentDataSource.HasViewPermission;
                    _hasDeletePermission = parentDataSource.HasDeletePermission;
                }
            }

            base.DataBind();
        }
示例#10
0
        void bind()
        {
            if (_bound)
            {
                return;
            }

            if (!String.IsNullOrWhiteSpace(_boundTo))
            {
                DataObj = DataBinder.Eval(this.NamingContainer, "DataItem");
                _bound  = DataObj != null;

                if (!String.IsNullOrWhiteSpace(_namingFrom))
                {
                    string name = _namingFormat;
                    name = String.Format(name,
                                         ControlUtils.GetBoundedDataField(this.NamingContainer, _namingFrom)
                                         );
                    this.ID = name;
                    this.Attributes["name"] = name;
                }
            }
            else
            {
                _bound = true;
            }

            if (!_bound)
            {
                return;
            }

            lw.DataControls.CustomDataSource dataSrc = null;

            if (!String.IsNullOrWhiteSpace(source))
            {
                Control ctrl = Page.FindControl(source);
                if (ctrl != null)
                {
                    dataSrc = ctrl as CustomDataSource;
                }
            }

            if (dataSrc != null)
            {
                DataSource = dataSrc.Data;
            }

            base.DataBind();

            if (!String.IsNullOrWhiteSpace(_boundTo))
            {
                object obj = ControlUtils.GetBoundedDataField(this.NamingContainer, _boundTo);
                if (obj != null)
                {
                    this.Value = String.Format(_format, obj).Trim();
                }
            }

            lw.Base.CustomPage page = this.Page as lw.Base.CustomPage;

            if (ValueFromQuery)
            {
                string val = page.GetQueryValue(this.ID);
                if (!String.IsNullOrWhiteSpace(val))
                {
                    this.Value = val;
                }
            }
        }
示例#11
0
        public override void DataBind()
        {
            if (this._bound)
            {
                return;
            }
            _bound = true;

            lw.Base.CustomPage page = this.Page as lw.Base.CustomPage;

            DataTable MyFriends = FriendsManager.GetMyFriends(page);

            this.HRef = "javascript:";

            DataRow memberRow = DataBinder.Eval(this.NamingContainer, "DataItem") as DataRow;

            if (memberRow == null)
            {
                DataRowView memberRowView = DataBinder.Eval(this.NamingContainer, "DataItem") as DataRowView;
                if (memberRowView != null)
                {
                    memberRow = memberRowView.Row;
                }
            }
            if (memberRow == null)
            {
                return;
            }

            _memberId = (int)memberRow["MemberId"];

            if (lw.WebTools.WebContext.Profile.UserId == _memberId)
            {
                this.Visible = false;
                return;
            }
            DataView friendView = new DataView(MyFriends,
                                               string.Format("MemberId={0}", _memberId),
                                               "", DataViewRowState.CurrentRows);

            DataView myFriendView = new DataView(MyFriends,
                                                 string.Format("FriendId={0}", _memberId),
                                                 "", DataViewRowState.CurrentRows);

            int privacy = (int)memberRow["Privacy"];

            if (friendView.Count > 0)
            {
                if ((Int16)friendView[0]["Status"] == (Int16)FriendStatus.Approved)
                {
                    if ((Int16)myFriendView[0]["Status"] == (Int16)FriendStatus.Pending)
                    {
                        this.Attributes.Add("onclick", string.Format("lw.members.acceptFriend('{0}', this)", memberRow["GeuId"]));
                        this.InnerHtml = string.Format(Format, AcceptFriendText);
                    }
                    else
                    {
                        this.Attributes.Add("onclick", string.Format("lw.members.unfriend('{0}', this)", memberRow["GeuId"]));
                        this.InnerHtml = string.Format(Format, UnFriendText);
                    }
                }
                else
                {
                    if ((Int16)friendView[0]["Status"] == (Int16)FriendStatus.Pending)
                    {
                        _tag           = "span";
                        this.InnerHtml = string.Format(Format, PendingFriendText);
                    }
                    else
                    {
                        friendView = new DataView(MyFriends,
                                                  string.Format("FriendId={0} and Status={1}", _memberId, (Int16)FriendStatus.Pending),
                                                  "", DataViewRowState.CurrentRows);
                        if (friendView.Count > 0)
                        {
                            this.InnerHtml = string.Format(Format, AcceptFriendText);
                            this.Attributes.Add("onclick", string.Format("lw.members.acceptFriend('{0}', this)", memberRow["GeuId"]));
                        }
                    }
                }
            }
            else
            {
                this.Attributes.Add("onclick", string.Format("lw.members.addFriend('{0}', this)", memberRow["GeuId"]));
                this.InnerHtml = string.Format(Format, AddToFriendsText);
            }
            this.ID = this.UniqueID;
        }
示例#12
0
        public override void DataBind()
        {
            if (!_bound)
            {
                _bound = true;

                lw.Base.CustomPage page = this.Page as lw.Base.CustomPage;

                string GroupName = page.GetQueryValue("CommentTitle");

                if (!StringUtils.IsNullOrWhiteSpace(GroupName))
                {
                    String[] Split = GroupName.Split('-');
                    CommentId = Int32.Parse(Split[Split.Length - 1]);
                }

                if (!NoRelations)
                {
                    Comments.Comments_Tables_View table = cMgr.GetTableDetails(TableName);
                    if (table == null)
                    {
                        return;
                    }

                    object relationValue = ControlUtils.GetBoundedDataField(this.NamingContainer, table.RelationField);
                    if (MembersOnly)
                    {
                        this.SelectCommand = cMgr.GetMemberCommentsQueryWithRelations(TableName, (int)relationValue, -1, Top);
                    }
                    else
                    {
                        this.SelectCommand = cMgr.GetCommentsQueryWithRelations(TableName, (int)relationValue, -1, Top);
                    }
                }
                else
                {
                    if (MembersOnly)
                    {
                        if (ChildComments)
                        {
                            object obj = DataBinder.Eval(this.NamingContainer, "DataItem.CommentId");

                            if (obj != null)
                            {
                                ParentId = (int)obj;
                            }
                        }

                        this.SelectCommand  = cMgr.GetMemberCommentsQueryWithNoRelations(TableName, ParentId, Top);
                        this.SelectCommand += string.Format(" And C.Status&{0}={0}", (int)Status.Enabled);

                        if (ChildComments)
                        {
                            this.SelectCommand += string.Format(" And C.CommentId>{0} Order by C.CommentId ASC", 0);
                        }
                        else
                        {
                            if (CommentId != -2)
                            {
                                this.SelectCommand += string.Format("And (CommentId={0} or ParentId={0})", CommentId);
                            }
                        }
                    }
                    else
                    {
                        this.SelectCommand = cMgr.GetCommentsQueryNoRelations(TableName, -1, Top);
                    }
                }
                //TODO: Display Disabled Comments in case an administrator is logged in
                if (!MembersOnly)
                {
                    //this.SelectCommand += String.Format(" And Status&{0}={0}", (int)Status.Enabled);

                    if (!EnablePaging)
                    {
                        this.SelectCommand += " Order By DateCreated DESC";
                    }
                }
            }
            base.DataBind();
        }
示例#13
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }

            _page = this.Page as lw.Base.CustomPage;

            if (this.CategoryId > 0 || this._brandId > 0 || this.Type == CategoryType.Search)
            {
                string q = _page.GetQueryValue("q");


                DataView cats   = null;
                string   search = "1=1";

                if (!String.IsNullOrWhiteSpace(_boundTo))
                {
                    ItemsSource source = _page.FindControlRecursive(_boundTo) as ItemsSource;
                    if (source != null)
                    {
                        string items = source.ItemIds;
                        if (!String.IsNullOrWhiteSpace(items))
                        {
                            search += " and CategoryId in (select CategoryId from ItemCategories where ItemId in (" + items.TrimEnd(',') + "))";
                        }
                    }
                }
                if (q != null && this.Type == CategoryType.Search && q != "")
                {
                    search += string.Format(" and (Name like '%{0}%' or Title like '%{0}%' or Description like '%{0}%')", lw.Utils.StringUtils.SQLEncode(q));
                }
                else
                {
                    if (this._brandId == -1)
                    {
                        cats = pMgr.GetChildrenCategories(CategoryId, search).DefaultView;
                    }
                    else
                    {
                        search += string.Format(" and CategoryId in (Select CategoryId from ItemCategories Where ItemId in (Select ItemId from Items where BrandId={0})) And ParentId <> -1",
                                                _brandId);
                    }
                }

                if (cats == null)
                {
                    cats = pMgr.GetCategories(search).DefaultView;
                }
                cats.RowFilter  = "Status=1";
                cats.Sort       = "SortingOrder";
                this.DataSource = cats;

                base.DataBind();

                for (int i = 0; i < this.Controls.Count; i++)
                {
                    if ((this.Controls[i] as Categories) != null)
                    {
                        this.Controls[i].DataBind();
                    }
                }
            }
        }