Esempio n. 1
0
        public SubGroupMember(Core core, SubUserGroup group, long userId)
            : base(core)
        {
            this.db = db;

            SelectQuery query = GetSelectQueryStub(core, UserLoadOptions.All);
            query.AddCondition("user_keys.user_id", userId);
            query.AddCondition("sub_group_members.sub_group_id", group.SubGroupId);

            DataTable memberTable = db.Query(query);

            if (memberTable.Rows.Count == 1)
            {
                loadMemberInfo(memberTable.Rows[0]);
                loadUserInfo(memberTable.Rows[0]);
                loadUserIcon(memberTable.Rows[0]);
            }
            else
            {
                throw new InvalidUserException();
            }
        }
        void AccountSubGroupsManage_Create(object sender, ModuleModeEventArgs e)
        {
            SetTemplate("account_group_subgroup_create");

            TextBox titleTextBox = new TextBox("title");
            titleTextBox.MaxLength = 64;
            titleTextBox.Script.OnChange = "UpdateSlug()";
            Form.AddFormField(titleTextBox);

            TextBox slugTextBox = new TextBox("slug");
            slugTextBox.MaxLength = 64;
            Form.AddFormField(slugTextBox);

            TextBox descriptionTextBox = new TextBox("description");
            descriptionTextBox.IsFormatted = true;
            descriptionTextBox.Lines = 4;
            Form.AddFormField(descriptionTextBox);

            RadioList groupTypeRadioList = new RadioList("group-type");

            groupTypeRadioList.Add(new RadioListItem(groupTypeRadioList.Name, "open", "Open Group"));
            groupTypeRadioList.Add(new RadioListItem(groupTypeRadioList.Name, "request", "Request Group"));
            groupTypeRadioList.Add(new RadioListItem(groupTypeRadioList.Name, "closed", "Closed Group"));
            groupTypeRadioList.Add(new RadioListItem(groupTypeRadioList.Name, "private", "Private Group"));
            Form.AddFormField(groupTypeRadioList);

            switch (e.Mode)
            {
                case "create":
                    break;
                case "edit":
                    long id = core.Functions.FormLong("id", core.Functions.RequestLong("id", 0));

                    if (id > 0)
                    {
                        try
                        {
                            subUserGroup = new SubUserGroup(core, id);
                        }
                        catch (InvalidSubGroupException)
                        {
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }

                    if (subUserGroup.Parent.Owner.Id != Owner.Id)
                    {
                        core.Functions.Generate403();
                        return;
                    }

                    if (!Form.IsFormSubmission)
                    {
                        titleTextBox.Script.OnChange = string.Empty;
                        titleTextBox.Value = subUserGroup.DisplayName;
                        descriptionTextBox.Value = subUserGroup.Description;

                        switch (subUserGroup.SubGroupType)
                        {
                            case "OPEN":
                                groupTypeRadioList.SelectedKey = "open";
                                break;
                            case "REQUEST":
                                groupTypeRadioList.SelectedKey = "request";
                                break;
                            case "CLOSED":
                                groupTypeRadioList.SelectedKey = "closed";
                                break;
                            case "PRIVATE":
                                groupTypeRadioList.SelectedKey = "private";
                                break;
                        }
                    }

                    slugTextBox.Value = subUserGroup.Key;
                    slugTextBox.IsDisabled = true;

                    template.Parse("S_GROUP_ID", subUserGroup.Id.ToString());
                    template.Parse("EDIT", "TRUE");
                    break;
            }

            template.Parse("S_TITLE", titleTextBox);
            template.Parse("S_SLUG", slugTextBox);
            template.Parse("S_DESCRIPTION", descriptionTextBox);

            template.Parse("S_TYPE_OPEN", groupTypeRadioList["open"]);
            template.Parse("S_TYPE_REQUEST", groupTypeRadioList["request"]);
            template.Parse("S_TYPE_CLOSED", groupTypeRadioList["closed"]);
            template.Parse("S_TYPE_PRIVATE", groupTypeRadioList["private"]);

            SaveMode(new ModuleModeHandler(AccountSubGroupsManage_Save));
        }
        void AccountSubGroupsManage_Save(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            switch (e.Mode)
            {
                case "create":
                    try
                    {
                        subUserGroup = SubUserGroup.Create(core, (UserGroup)Owner, core.Http.Form["title"], core.Http.Form["slug"], core.Http.Form["description"], core.Http.Form["group-type"]);

                        SetRedirectUri(BuildUri());
                        core.Display.ShowMessage("Group Created", "The group has been created");
                    }
                    catch (FieldTooLongException ex)
                    {
                        switch (ex.FieldName)
                        {
                            case "sub_group_name":
                            case "sub_group_name_display":
                                SetError("The group name is too long, please choose another");
                                break;
                            case "sub_group_abstract":
                                SetError("The group description is too long, please use a shorter description");
                                break;
                            default:
                                // Generic error occured
                                core.Functions.ThrowError();
                                break;
                        }
                    }
                    catch (GroupNameNotUniqueException)
                    {
                        SetError("A group with the same name already exists");
                    }
                    catch (Exception ex)
                    {
                        DisplayError(ex.ToString());
                    }
                    break;
                case "edit":

                    string groupType = core.Http.Form["group-type"];
                    switch (groupType.ToLower())
                    {
                        case "open":
                            groupType = "OPEN";
                            break;
                        case "request":
                            groupType = "REQUEST";
                            break;
                        case "closed":
                            groupType = "CLOSED";
                            break;
                        case "private":
                            groupType = "PRIVATE";
                            break;
                        default:
                            return;
                    }

                    subUserGroup.Title = core.Http.Form["title"];
                    subUserGroup.Description = core.Http.Form["description"];
                    subUserGroup.SubGroupType = groupType;

                    subUserGroup.Update();

                    break;
            }
        }
        void AccountSubGroupsManage_Members(object sender, ModuleModeEventArgs e)
        {
            SetTemplate("account_group_subgroup_members");

            long id = core.Functions.RequestLong("id", 0);

            if (id <= 0)
            {
                return;
            }

            try
            {
                subUserGroup = new SubUserGroup(core, id);
            }
            catch (InvalidSubGroupException)
            {
                return;
            }

            if (subUserGroup.CanEditItem())
            {
                List<SubGroupMember> leaders = subUserGroup.GetLeaders();
                List<SubGroupMember> awaiting = subUserGroup.GetMembersWaitingApproval();
                List<SubGroupMember> members = subUserGroup.GetMembers(core.TopLevelPageNumber, 25);

                UserSelectBox newUserSelectBox = new UserSelectBox(core, "usernames");
                newUserSelectBox.SelectMultiple = false;
                //Form.AddFormField(newUserSelectBox);

                YesNoList makeLeaderYesNoList = new YesNoList(core, "make-leader");
                makeLeaderYesNoList.SelectedKey = "no";
                //Form.AddFormField(makeLeaderYesNoList);

                YesNoList makeDefaultYesNoList = new YesNoList(core, "make-default");
                makeDefaultYesNoList.SelectedKey = "no";
                //Form.AddFormField(makeDefaultYesNoList);

                template.Parse("SUBGROUP_DISPLAY_NAME", subUserGroup.DisplayName);
                template.Parse("S_USERNAMES", newUserSelectBox);
                template.Parse("S_MAKE_LEADER", makeLeaderYesNoList);
                template.Parse("S_MAKE_DEFAULT_GROUP", makeDefaultYesNoList);
                template.Parse("S_GROUP_ID", subUserGroup.Id.ToString());

                foreach (SubGroupMember member in leaders)
                {
                    CheckBox memberCheckBox = new CheckBox("check[" + member.Id.ToString() + "]");

                    VariableCollection memberVariableCollection = template.CreateChild("leader_list");
                    memberVariableCollection.Parse("DISPLAY_NAME", member.DisplayName);
                    memberVariableCollection.Parse("JOINED_DATE", core.Tz.DateTimeToDateString(member.GetJoinedDate(core.Tz)));
                    memberVariableCollection.Parse("S_MARK", memberCheckBox);

                    if (member.IsDefaultGroup)
                    {
                        memberVariableCollection.Parse("DEFAULT_GROUP", core.Prose.GetString("YES"));
                    }
                    else
                    {
                        memberVariableCollection.Parse("DEFAULT_GROUP", core.Prose.GetString("NO"));
                    }
                }

                foreach (SubGroupMember member in awaiting)
                {
                    CheckBox memberCheckBox = new CheckBox("check[" + member.Id.ToString() + "]");

                    VariableCollection memberVariableCollection = template.CreateChild("awaiting_list");
                    memberVariableCollection.Parse("DISPLAY_NAME", member.DisplayName);
                    memberVariableCollection.Parse("JOINED_DATE", core.Tz.DateTimeToDateString(member.GetJoinedDate(core.Tz)));
                    memberVariableCollection.Parse("S_MARK", memberCheckBox);

                    if (member.IsDefaultGroup)
                    {
                        memberVariableCollection.Parse("DEFAULT_GROUP", core.Prose.GetString("YES"));
                    }
                    else
                    {
                        memberVariableCollection.Parse("DEFAULT_GROUP", core.Prose.GetString("NO"));
                    }
                }

                foreach (SubGroupMember member in members)
                {
                    CheckBox memberCheckBox = new CheckBox("check[" + member.Id.ToString() + "]");

                    VariableCollection memberVariableCollection = template.CreateChild("member_list");
                    memberVariableCollection.Parse("DISPLAY_NAME", member.DisplayName);
                    memberVariableCollection.Parse("JOINED_DATE", core.Tz.DateTimeToDateString(member.GetJoinedDate(core.Tz)));
                    memberVariableCollection.Parse("S_MARK", memberCheckBox);

                    if (member.IsDefaultGroup)
                    {
                        memberVariableCollection.Parse("DEFAULT_GROUP", core.Prose.GetString("YES"));
                    }
                    else
                    {
                        memberVariableCollection.Parse("DEFAULT_GROUP", core.Prose.GetString("NO"));
                    }
                }

            }
            else
            {
                return;
            }

            Save(AccountSubGroupsManage_Members_AddNew);
        }
Esempio n. 5
0
        public static void Show(object sender, ShowPageEventArgs e)
        {
            e.Template.SetTemplate("Groups", "viewsubgroup");

            SubUserGroup subgroup;

            try
            {
                subgroup = new SubUserGroup(e.Core, e.Core.PagePathParts[1].Value);
            }
            catch (InvalidSubGroupException)
            {
                e.Core.Functions.Generate404();
                return;
            }

            e.Template.Parse("U_FILTER_ALL", subgroup.Uri);
            e.Template.Parse("U_FILTER_BEGINS_A", subgroup.GetUri("a"));
            e.Template.Parse("U_FILTER_BEGINS_B", subgroup.GetUri("b"));
            e.Template.Parse("U_FILTER_BEGINS_C", subgroup.GetUri("c"));
            e.Template.Parse("U_FILTER_BEGINS_D", subgroup.GetUri("d"));
            e.Template.Parse("U_FILTER_BEGINS_E", subgroup.GetUri("e"));
            e.Template.Parse("U_FILTER_BEGINS_F", subgroup.GetUri("f"));
            e.Template.Parse("U_FILTER_BEGINS_G", subgroup.GetUri("g"));
            e.Template.Parse("U_FILTER_BEGINS_H", subgroup.GetUri("h"));
            e.Template.Parse("U_FILTER_BEGINS_I", subgroup.GetUri("i"));
            e.Template.Parse("U_FILTER_BEGINS_J", subgroup.GetUri("j"));
            e.Template.Parse("U_FILTER_BEGINS_K", subgroup.GetUri("k"));
            e.Template.Parse("U_FILTER_BEGINS_L", subgroup.GetUri("l"));
            e.Template.Parse("U_FILTER_BEGINS_M", subgroup.GetUri("m"));
            e.Template.Parse("U_FILTER_BEGINS_N", subgroup.GetUri("n"));
            e.Template.Parse("U_FILTER_BEGINS_O", subgroup.GetUri("o"));
            e.Template.Parse("U_FILTER_BEGINS_P", subgroup.GetUri("p"));
            e.Template.Parse("U_FILTER_BEGINS_Q", subgroup.GetUri("q"));
            e.Template.Parse("U_FILTER_BEGINS_R", subgroup.GetUri("r"));
            e.Template.Parse("U_FILTER_BEGINS_S", subgroup.GetUri("s"));
            e.Template.Parse("U_FILTER_BEGINS_T", subgroup.GetUri("t"));
            e.Template.Parse("U_FILTER_BEGINS_U", subgroup.GetUri("u"));
            e.Template.Parse("U_FILTER_BEGINS_V", subgroup.GetUri("v"));
            e.Template.Parse("U_FILTER_BEGINS_W", subgroup.GetUri("w"));
            e.Template.Parse("U_FILTER_BEGINS_X", subgroup.GetUri("x"));
            e.Template.Parse("U_FILTER_BEGINS_Y", subgroup.GetUri("y"));
            e.Template.Parse("U_FILTER_BEGINS_Z", subgroup.GetUri("z"));

            List<SubGroupMember> awaitingApproval = subgroup.GetMembersWaitingApproval();

            foreach (SubGroupMember member in awaitingApproval)
            {
                VariableCollection approvalVariableCollection = e.Core.Template.CreateChild("approval_list");

                approvalVariableCollection.Parse("U_MEMBER", member.Uri);
                approvalVariableCollection.Parse("DISPLAY_NAME", member.DisplayName);
                approvalVariableCollection.Parse("LOCATION", member.Profile.Country);
                approvalVariableCollection.Parse("JOINED", e.Core.Tz.DateTimeToDateString(member.GetJoinedDate(e.Core.Tz)));
            }

            if (awaitingApproval.Count > 0)
            {
                e.Core.Template.Parse("IS_WAITING_APPROVAL", "TRUE");
            }

            List<SubGroupMember> leaders = subgroup.GetLeaders();

            foreach (SubGroupMember member in leaders)
            {
                VariableCollection leaderVariableCollection = e.Core.Template.CreateChild("leader_list");

                leaderVariableCollection.Parse("U_MEMBER", member.Uri);
                leaderVariableCollection.Parse("DISPLAY_NAME", member.DisplayName);
                leaderVariableCollection.Parse("LOCATION", member.Profile.Country);
                leaderVariableCollection.Parse("JOINED", e.Core.Tz.DateTimeToDateString(member.GetJoinedDate(e.Core.Tz)));
            }

            List<SubGroupMember> members = subgroup.GetMembers(e.Page.TopLevelPageNumber, 20, e.Core.Functions.GetFilter());
            // TODO, cache
            long memberCount = members.Count; // e.Db.LastQueryRows;

            foreach (SubGroupMember member in members)
            {
                VariableCollection memberVariableCollection = e.Core.Template.CreateChild("member_list");

                memberVariableCollection.Parse("U_MEMBER", member.Uri);
                memberVariableCollection.Parse("DISPLAY_NAME", member.DisplayName);
                memberVariableCollection.Parse("LOCATION", member.Profile.Country);
                memberVariableCollection.Parse("JOINED", e.Core.Tz.DateTimeToDateString(member.GetJoinedDate(e.Core.Tz)));

                /*if (string.IsNullOrEmpty(member.UserThumbnail))
                {
                    memberVariableCollection.Parse("I_DISPLAY_PIC", string.Empty);
                }
                else
                {
                    Image displayPic = new Image("display-pic[" + member.Id.ToString() + "]", member.UserThumbnail);
                    memberVariableCollection.Parse("I_DISPLAY_PIC", displayPic);
                }*/
            }

            if (e.Core.Session.IsLoggedIn)
            {
                if (subgroup.IsSubGroupMember(e.Core.Session.LoggedInMember.ItemKey))
                {
                    if (!subgroup.IsSubGroupLeader(e.Core.Session.LoggedInMember))
                    {
                        e.Template.Parse("U_LEAVE", subgroup.LeaveUri);
                    }
                }
                else
                {
                    if (subgroup.SubGroupType == "OPEN" || subgroup.SubGroupType == "REQUEST")
                    {
                        e.Template.Parse("U_JOIN", subgroup.JoinUri);
                    }
                }
            }

            e.Core.Display.ParsePagination(subgroup.GetUri(e.Core.Functions.GetFilter()), e.Page.TopLevelPageNumber, (int)(Math.Ceiling(memberCount / 20.0)));
        }