Ejemplo n.º 1
0
        void AccountGroupsEdit_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            short category;
            string title;
            string description;
            string type;
            string homepage = "/profile";

            try
            {
                groupId = long.Parse(core.Http.Form["id"]);
                category = short.Parse(core.Http.Form["category"]);
                title = core.Http.Form["title"];
                description = core.Http.Form["description"];
                type = core.Http.Form["type"];
                homepage = core.Http.Form["homepage"];
            }
            catch
            {
                core.Display.ShowMessage("Error", "An error has occured, go back.");
                return;
            }

            switch (type)
            {
                case "open":
                    type = "OPEN";
                    break;
                case "request":
                    type = "REQUEST";
                    break;
                case "closed":
                    type = "CLOSED";
                    break;
                case "private":
                    type = "PRIVATE";
                    break;
                default:
                    core.Display.ShowMessage("Error", "An error has occured, go back.");
                    return;
            }

            UserGroup thisGroup = new UserGroup(core, groupId);

            if (!thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
            {
                core.Display.ShowMessage("Cannot Edit Group", "You must be an operator of the group to edit it.");
                return;
            }
            else
            {

                // update the public viewcount is necessary
                if (type != "PRIVATE" && thisGroup.GroupType == "PRIVATE")
                {
                    db.BeginTransaction();
                    db.UpdateQuery(string.Format("UPDATE global_categories SET category_groups = category_groups + 1 WHERE category_id = {0}",
                        category));
                }
                else if (type == "PRIVATE" && thisGroup.GroupType != "PRIVATE")
                {
                    db.UpdateQuery(string.Format("UPDATE global_categories SET category_groups = category_groups - 1 WHERE category_id = {0}",
                        category));
                }

                if (homepage != "/profile" && homepage != "/blog")
                {
                    try
                    {
                        Page thisPage = new Page(core, thisGroup, homepage.TrimStart(new char[] { '/' }));
                    }
                    catch (PageNotFoundException)
                    {
                        homepage = "/profile";
                    }
                }

                // save the edits to the group
                db.UpdateQuery(string.Format("UPDATE group_info SET group_name_display = '{1}', group_category = {2}, group_abstract = '{3}', group_type = '{4}', group_home_page = '{5}' WHERE group_id = {0}",
                    thisGroup.GroupId, Mysql.Escape(title), category, Mysql.Escape(description), Mysql.Escape(type), Mysql.Escape(homepage)));

                SetRedirectUri(thisGroup.Uri);
                core.Display.ShowMessage("Group Saved", "You have successfully edited the group.");
                return;
            }
        }
        void AccountGroupsMembershipsManage_ResignOperator_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

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

            if (groupId == 0)
            {
                DisplayGenericError();
                return;
            }

            UserGroup thisGroup = new UserGroup(core, groupId);

            if (core.Display.GetConfirmBoxResult() == ConfirmBoxResult.Yes)
            {
                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    if (thisGroup.Operators > 1)
                    {
                        db.BeginTransaction();
                        long deletedRows = db.UpdateQuery(string.Format("DELETE FROM group_operators WHERE group_id = {0} AND user_id = {1}",
                            thisGroup.GroupId, LoggedInMember.UserId));

                        db.UpdateQuery(string.Format("UPDATE group_info SET group_operators = group_operators - {1} WHERE group_id = {0}",
                            thisGroup.GroupId, deletedRows));

                        SetRedirectUri(thisGroup.Uri);
                        core.Display.ShowMessage("Success", "You successfully resigned as a group operator. You are still a member of the group. You will be redirected in a second.");
                    }
                    else
                    {
                        core.Display.ShowMessage("Cannot resign as operator", "Groups must have at least one operator, you cannot resign from this group at this moment.");
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Error", "An error has occured. You are not an operator of this group, go back.");
                    return;
                }
            }
            else
            {
                SetRedirectUri(thisGroup.Uri);
                core.Display.ShowMessage("Cancelled", "You cancelled resignation from being a group operator.");
            }
        }
        void AccountGroupsMembershipsManage_ApproveMember(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            long userId;

            try
            {
                string[] idString = core.Http.Query["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
            }
            catch
            {
                DisplayGenericError();
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    try
                    {
                        User member = new User(core, userId);

                        if (thisGroup.IsGroupMemberPending(member.ItemKey))
                        {
                            // we can approve the pending membership
                            db.BeginTransaction();
                            long rowsChanged = db.UpdateQuery(string.Format("UPDATE group_members SET group_member_approved = 1, group_member_date_ut = UNIX_TIMESTAMP() WHERE group_id = {0} AND user_id = {1} AND group_member_approved = 0;",
                                thisGroup.GroupId, member.UserId));

                            if (rowsChanged > 0) // committ the change
                            {
                                db.UpdateQuery(string.Format("UPDATE group_info SET group_members = group_members + 1 WHERE group_id = {0}",
                                    thisGroup.GroupId));

                                SetRedirectUri(thisGroup.MemberlistUri);
                                core.Display.ShowMessage("Membership Approved", "You have approved the membership for the user.");
                                return;
                            }
                            else
                            {
                                core.Display.ShowMessage("Not Pending", "This member is not pending membership. They may have cancelled their request, or been approved by another operator.");
                                return;
                            }
                        }
                        else
                        {
                            core.Display.ShowMessage("Not Pending", "This member is not pending membership. They may have cancelled their request, or been approved by another operator.");
                            return;
                        }
                    }
                    catch
                    {
                        core.Display.ShowMessage("Error", "An error has occured, group member does not exist, go back.");
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Not Group Operator", "You must be an operator of the group to approve new memberships.");
                    return;
                }
            }
            catch
            {
                core.Display.ShowMessage("Error", "An error has occured, group does not exist, go back.");
                return;
            }
        }
        void AccountGroupsMembershipsManage_RemoveOfficer(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            long userId;
            string title;

            try
            {
                string[] idString = core.Http.Query["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
                title = UTF8Encoding.UTF8.GetString(Convert.FromBase64String(idString[2]));
            }
            catch
            {
                DisplayGenericError();
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    db.BeginTransaction();
                    long deletedRows = db.UpdateQuery(string.Format("DELETE FROM group_officers WHERE group_id = {0} AND user_id = {1} AND officer_title = '{2}'",
                        groupId, userId, Mysql.Escape(title)));

                    if (deletedRows >= 0)
                    {
                        db.UpdateQuery(string.Format("UPDATE group_info SET group_officers = group_officers - {1} WHERE group_id = {0}",
                            thisGroup.GroupId, deletedRows));

                        SetRedirectUri(thisGroup.Uri);
                        core.Display.ShowMessage("Officer Removed from Group", "You have successfully removed an officer from the group.");
                    }
                    else
                    {
                        core.Display.ShowMessage("Error", "Could not delete officer, they may have already been delted.");
                        return;
                    }
                }
            }
            catch (InvalidGroupException)
            {
                DisplayGenericError();
                return;
            }
        }
        void AccountGroupsMembershipsManage_MakeOperator(object sender, ModuleModeEventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            long userId;

            try
            {
                string[] idString = core.Http.Query["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
            }
            catch
            {
                core.Display.ShowMessage("Error", "An error has occured, go back.");
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    try
                    {
                        User member = new User(core, userId);
                        if (!thisGroup.IsGroupOperator(member.ItemKey))
                        {
                            db.BeginTransaction();
                            db.UpdateQuery(string.Format("INSERT INTO group_operators (group_id, user_id) VALUES ({0}, {1});",
                                thisGroup.GroupId, userId));

                            db.UpdateQuery(string.Format("UPDATE group_info SET group_operators = group_operators + 1 WHERE group_id = {0}",
                                thisGroup.GroupId));

                            SetRedirectUri(thisGroup.Uri);
                            core.Display.ShowMessage("Operator Appointed to Group", "You have successfully appointed an operator to the group.");
                        }
                        else
                        {
                            SetRedirectUri(thisGroup.Uri);
                            core.Display.ShowMessage("Already an Officer", "This member is already an officer.");
                            return;
                        }
                    }
                    catch
                    {
                        DisplayGenericError();
                        return;
                    }
                }
                else
                {
                    SetRedirectUri(thisGroup.Uri);
                    core.Display.ShowMessage("Unauthorised", "You must be the group operator to appoint an operator.");
                    return;
                }
            }
            catch
            {
                DisplayGenericError();
                return;
            }
        }
        void AccountGroupsMembershipsManage_MakeOfficer_Save(object sender, EventArgs e)
        {
            long groupId = 0;
            long userId = 0;
            string title;

            try
            {
                string[] idString = core.Http.Form["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
                title = core.Http.Form["title"];
            }
            catch
            {
                core.Functions.ThrowError();
                return;
            }

            if (string.IsNullOrEmpty(title))
            {
                core.Display.ShowMessage("Officer Title Empty", "The officer title must not be empty, go back and enter an officer title.");
                return;
            }
            else
            {
                if (title.Length < 4)
                {
                    core.Display.ShowMessage("Officer Title Too Short", "The officer title must be at least four characters, go back and enter an officer title.");
                    return;
                }
                else if (title.Length > 24)
                {
                    core.Display.ShowMessage("Officer Title Too Long", "The officer title must be at most twenty four characters, go back and enter an officer title.");
                    return;
                }
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    try
                    {
                        User member = new User(core, userId);

                        if (thisGroup.IsGroupMember(member.ItemKey))
                        {
                            // allow to be an officer to many things
                            db.BeginTransaction();
                            long status = db.UpdateQuery(string.Format("INSERT INTO group_officers (group_id, user_id, officer_title) VALUES ({0}, {1}, '{2}');",
                                thisGroup.GroupId, member.UserId, Mysql.Escape(title)));

                            if (status >= 0)
                            {
                                db.UpdateQuery(string.Format("UPDATE group_info SET group_officers = group_officers + 1 WHERE group_id = {0}",
                                    thisGroup.GroupId));

                                SetRedirectUri(thisGroup.Uri);
                                core.Display.ShowMessage("Officer Appointed to Group", "You have successfully appointed an officer to the group.");
                            }
                            else
                            {
                                core.Display.ShowMessage("Already Officer", "This member is already appointed as this officer.");
                                return;
                            }
                        }
                        else
                        {
                            core.Functions.ThrowError();
                            return;
                        }
                    }
                    catch
                    {
                        core.Functions.ThrowError();
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Unauthorised", "You must be the group operator to appoint an officer.");
                    return;
                }
            }
            catch
            {
                core.Functions.ThrowError();
                return;
            }
        }
        void AccountGroupsMembershipsManage_MakeOfficer(object sender, ModuleModeEventArgs e)
        {
            SetTemplate("account_group_appoint_officer");

            long groupId;
            long userId;

            try
            {
                string[] idString = core.Http.Query["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
            }
            catch
            {
                DisplayGenericError();
                return;
            }

            try
            {
                UserGroup thisGroup = new UserGroup(core, groupId);

                if (thisGroup.IsGroupOperator(LoggedInMember.ItemKey))
                {
                    try
                    {
                        User member = new User(core, userId);

                        if (thisGroup.IsGroupMember(member.ItemKey))
                        {
                            // all ok, don't really need to do much, so let's do it
                            template.Parse("S_ID", string.Format("{0},{1}", groupId, userId));
                            template.Parse("S_USERNAME", member.UserName);
                        }
                        else
                        {
                            core.Functions.ThrowError();
                            return;
                        }
                    }
                    catch
                    {
                        core.Functions.ThrowError();
                        return;
                    }
                }
                else
                {
                    core.Display.ShowMessage("Unauthorised", "You must be the group operator to appoint an operator.");
                    return;
                }
            }
            catch
            {
                core.Functions.ThrowError();
                return;
            }
        }
        void AccountGroupsMembershipsManage_BanMember_Save(object sender, EventArgs e)
        {
            AuthoriseRequestSid();

            long groupId;
            long userId;

            try
            {
                string[] idString = core.Http.Form["id"].Split(new char[] { ',' });
                groupId = long.Parse(idString[0]);
                userId = long.Parse(idString[1]);
            }
            catch
            {
                core.Functions.ThrowError();
                return;
            }

            if (core.Display.GetConfirmBoxResult() == ConfirmBoxResult.Yes)
            {
                try
                {
                    UserGroup group = new UserGroup(core, groupId);

                    if (group.IsGroupOperator(LoggedInMember.ItemKey))
                    {
                        try
                        {
                            GroupMember member = new GroupMember(core, group, userId);

                            member.Ban();

                            core.Display.ShowMessage("Member Banned", "The member has been banned from the group.");
                            return;
                        }
                        catch (InvalidUserException)
                        {
                            DisplayGenericError();
                            return;
                        }
                    }
                    else
                    {
                        core.Display.ShowMessage("Cannot ban member", "Only group operators can ban members from groups.");
                        return;
                    }
                }
                catch (InvalidGroupException)
                {
                    DisplayGenericError();
                    return;
                }
            }
            else
            {
                core.Display.ShowMessage("Cancelled", "You cancelled the banning of this member.");
                return;
            }
        }