public void SetAsCompetitionGroupPhoto(int photoK, bool isCompetitionPhoto) { if (Usr.Current != null && (Usr.Current.IsAdmin || Usr.Current.K == new Photo(photoK).UsrK)) { if (isCompetitionPhoto) { GroupPhoto gp = new GroupPhoto() { PhotoK = photoK, GroupK = Vars.CompetitionGroupK, DateTime = DateTime.Now, AddedByUsrK = Usr.Current.K, ShowOnFrontPage = false }; gp.Update(); } else { try { GroupPhoto gp = new GroupPhoto(Vars.CompetitionGroupK, photoK); gp.Delete(); } catch (BobNotFound) { } } } else { throw new Exception("You don't have permission to do this!"); } }
private void Page_Load(object sender, System.EventArgs e) { Usr.KickUserIfNotLoggedIn("You must be logged in to use this page."); this.SetPageTitle("Add this photo to the group homepage"); PhotoImg.Src = CurrentPhoto.IconPath; PhotoAnchor.HRef = CurrentPhoto.Url(); if (CurrentGroup == null) { GroupPanel.Visible = false; Query q = new Query(); q.TableElement = new Join( new TableElement(TablesEnum.Group), new TableElement(TablesEnum.GroupUsr), QueryJoinType.Inner, new And( new Q(Bobs.Group.Columns.K, GroupUsr.Columns.GroupK, true), new Q(GroupUsr.Columns.Moderator, true), new Q(GroupUsr.Columns.UsrK, Usr.Current.K))); GroupSet gs = new GroupSet(q); if (gs.Count == 0) throw new Exception("No groups!"); else if (gs.Count == 1) Response.Redirect(CurrentPhoto.UrlApp("addtogroup", "groupk", gs[0].K.ToString())); else { GroupRepeater.DataSource = gs; GroupRepeater.DataBind(); } } else { RepeaterPanel.Visible = false; GroupUsr gu = CurrentGroup.GetGroupUsr(Usr.Current); if (gu == null || !gu.Moderator) throw new DsiUserFriendlyException("You can't add a photo to this group!"); if (!Page.IsPostBack) { try { GroupPhoto gp = new GroupPhoto(CurrentGroup.K, CurrentPhoto.K); ShowCheckBox.Checked = gp.ShowOnFrontPage; CaptionTextBox.Text = gp.Caption; } catch { } CaptionCompetitionCheckBox.Visible = Usr.Current.IsAdmin && CurrentGroup.K == Vars.CompetitionGroupK; if (CaptionCompetitionCheckBox.Visible) { CaptionCompetitionCheckBox.Checked = CurrentPhoto.IsInCaptionCompetition; } } } }
public void Update_Click(object o, System.EventArgs e) { GroupUsr gu = CurrentGroup.GetGroupUsr(Usr.Current); if (gu == null || !gu.Moderator) throw new DsiUserFriendlyException("You can't add a photo to this group!"); string caption = Cambro.Misc.Utility.Snip(Cambro.Web.Helpers.Strip(CaptionTextBox.Text, true, true, true, true), 200); try { GroupPhoto gp = new GroupPhoto(CurrentGroup.K, CurrentPhoto.K); if (ShowCheckBox.Checked != gp.ShowOnFrontPage || !caption.Equals(gp.Caption)) { if (ShowCheckBox.Checked != gp.ShowOnFrontPage) { gp.ShowOnFrontPage = ShowCheckBox.Checked; gp.DateTime = DateTime.Now; } gp.Caption = caption; gp.AddedByUsrK = Usr.Current.K; gp.Update(); } } catch (BobNotFound) { if (ShowCheckBox.Checked) { GroupPhoto gp = new GroupPhoto(); gp.GroupK = CurrentGroup.K; gp.PhotoK = CurrentPhoto.K; gp.Caption = caption; gp.DateTime = DateTime.Now; gp.AddedByUsrK = Usr.Current.K; gp.ShowOnFrontPage = true; gp.Update(); } } if (CurrentGroup.K == Vars.CompetitionGroupK && CurrentPhoto.IsInCaptionCompetition != CaptionCompetitionCheckBox.Checked) { CurrentPhoto.IsInCaptionCompetition = CaptionCompetitionCheckBox.Checked; CurrentPhoto.Update(); } Response.Redirect(CurrentGroup.Url()); }
public void MergeAndDelete(Group merge) { if (this.K==merge.K) throw new DsiUserFriendlyException("Can't merge group into itself!"); Cambro.Web.Helpers.WriteAlertHeader(); Cambro.Web.Helpers.WriteAlert("Starting group merge...", true); Cambro.Web.Helpers.WriteAlert("Merging group members...", true); //members Query qGu = new Query(); qGu.QueryCondition=new Q(GroupUsr.Columns.GroupK,merge.K); GroupUsrSet gus = new GroupUsrSet(qGu); int count = 0; foreach (GroupUsr guMerge in gus) { if (count%10==0) Cambro.Web.Helpers.WriteAlert("Merging usr " + guMerge.UsrK + " ("+count+" / "+gus.Count+")..."); try { count++; GroupUsr guMaster = this.GetGroupUsr(guMerge.Usr); if (guMaster == null) { guMaster = new GroupUsr(); guMaster.UsrK = guMerge.UsrK; guMaster.GroupK = this.K; guMaster.Status = guMerge.Status; guMaster.StatusChangeDateTime = guMerge.StatusChangeDateTime; guMaster.StatusChangeUsrK = guMerge.StatusChangeUsrK; guMaster.Owner = guMerge.Owner; guMaster.Moderator = guMerge.Moderator; guMaster.NewsAdmin = guMerge.NewsAdmin; guMaster.MemberAdmin = guMerge.MemberAdmin; guMaster.MemberAdminNewUserEmails = guMerge.MemberAdminNewUserEmails; guMaster.Favourite = guMerge.Favourite; guMaster.InviteMessage = guMerge.InviteMessage; guMaster.InviteUsrK = guMerge.InviteUsrK; guMaster.Update(); guMaster.Usr.UpdateIsGroupModerator(); } else { if (guMaster.StatusPermissionLevel < guMerge.StatusPermissionLevel) { guMaster.Status = guMerge.Status; guMaster.StatusChangeDateTime = guMerge.StatusChangeDateTime; guMaster.StatusChangeUsrK = guMerge.StatusChangeUsrK; guMaster.InviteMessage = guMerge.InviteMessage; guMaster.InviteUsrK = guMerge.InviteUsrK; } if (this.BrandK == 0 || merge.BrandK > 0) { if (guMerge.Owner) guMaster.Owner = true; if (guMerge.Moderator) guMaster.Moderator = true; if (guMerge.NewsAdmin) guMaster.NewsAdmin = true; if (guMerge.MemberAdmin) { guMaster.MemberAdmin = true; guMaster.MemberAdminNewUserEmails = guMerge.MemberAdminNewUserEmails; } } if (guMerge.Favourite) guMaster.Favourite = true; guMaster.Update(); guMaster.Usr.UpdateIsGroupModerator(); } if (guMaster.IsMember) { Mailer m = new Mailer(); m.UsrRecipient = guMerge.Usr; m.Subject = "A group you were in has been merged"; m.Body = "<p><i>" + merge.FriendlyName + "</i> has been merged with <i>" + this.FriendlyName + "</i>. " + "Your membership details have been moved across. If you ever want to exit the group, click the button " + "on the <a href=\"[LOGIN(" + this.Url() + ")]\">group homepage</a>.</p>"; m.RedirectUrl = this.Url(); m.Bulk = true; m.Send(); } if (guMaster.IsMember && CommentAlert.IsEnabled(guMerge.UsrK, guMerge.GroupK, Model.Entities.ObjectType.Group)) CommentAlert.Enable(guMaster.Usr, guMaster.GroupK, Model.Entities.ObjectType.Group); } catch { Cambro.Web.Helpers.WriteAlert("Exception! ... deleting membership for usr " + guMerge.UsrK + " (" + count + " / " + gus.Count + ")..."); guMerge.Delete(); } } Cambro.Web.Helpers.WriteAlert("Done merging usrs..."); //picture if (merge.HasPic && !this.HasPic) { Cambro.Web.Helpers.WriteAlert("Copying picture...", true); try { Utilities.CopyPic(merge, this); } catch { Cambro.Web.Helpers.WriteAlert("Exception while copying picture...", true); } Cambro.Web.Helpers.WriteAlert("Done copying picture...", true); } //recommended events if (this.BrandK == 0) { Cambro.Web.Helpers.WriteAlert("Merging recommended events...", true); Query qEv = new Query(); qEv.QueryCondition = new Q(GroupEvent.Columns.GroupK, merge.K); GroupEventSet ges = new GroupEventSet(qEv); foreach (GroupEvent geMerge in ges) { try { GroupEvent geMaster = new GroupEvent(this.K, geMerge.EventK); } catch (BobNotFound) { GroupEvent geMaster = new GroupEvent(); geMaster.GroupK = this.K; geMaster.EventK = geMerge.EventK; geMaster.Update(); } } Cambro.Web.Helpers.WriteAlert("Done merging recommended events..."); } Cambro.Web.Helpers.WriteAlert("Merging top photos...", true); //top photos Query qPh = new Query(); qPh.QueryCondition=new Q(GroupPhoto.Columns.GroupK,merge.K); GroupPhotoSet gps = new GroupPhotoSet(qPh); foreach (GroupPhoto gpMerge in gps) { try { GroupPhoto gpMaster = new GroupPhoto(this.K,gpMerge.PhotoK); if (!gpMaster.ShowOnFrontPage && gpMerge.ShowOnFrontPage) { gpMaster.Caption=gpMerge.Caption; gpMaster.DateTime=gpMerge.DateTime; gpMaster.AddedByUsrK=gpMerge.AddedByUsrK; gpMaster.ShowOnFrontPage=gpMerge.ShowOnFrontPage; gpMaster.Update(); } } catch (BobNotFound) { GroupPhoto gpMaster = new GroupPhoto(); gpMaster.GroupK=this.K; gpMaster.PhotoK=gpMerge.PhotoK; gpMaster.Caption=gpMerge.Caption; gpMaster.DateTime=gpMerge.DateTime; gpMaster.AddedByUsrK=gpMerge.AddedByUsrK; gpMaster.ShowOnFrontPage=gpMerge.ShowOnFrontPage; gpMaster.Update(); } } Cambro.Web.Helpers.WriteAlert("Done merging top photos..."); //addedbyusrk's if (true) { Cambro.Web.Helpers.WriteAlert("Updating invited users...", true); Update update = new Update(); update.Changes.Add(new Assign(Usr.Columns.AddedByGroupK, this.K)); update.Table = TablesEnum.Usr; update.Where = new Q(Usr.Columns.AddedByGroupK, merge.K); update.Run(); Cambro.Web.Helpers.WriteAlert("Done updating invited users..."); } Cambro.Web.Helpers.WriteAlert("Merging topics (1/4)...", true); //chats if (merge.PrivateChat != this.PrivateChat || merge.ThemeK != this.ThemeK || merge.MusicTypeK != this.MusicTypeK) { Update update = new Update(); update.Table=TablesEnum.Thread; update.Changes.Add(new Assign(Thread.Columns.PrivateGroup,this.PrivateChat)); update.Changes.Add(new Assign(Thread.Columns.ThemeK, this.ThemeK)); update.Changes.Add(new Assign(Thread.Columns.MusicTypeK, this.MusicTypeK)); update.Where=new Q(Thread.Columns.GroupK,merge.K); update.Run(); } Cambro.Web.Helpers.WriteAlert("Done merging topics (1/4)..."); if (true) { Cambro.Web.Helpers.WriteAlert("Merging topics (2/4)...", true); Update update = new Update(); update.Table=TablesEnum.Thread; update.Changes.Add(new Assign(Thread.Columns.UrlFragment,"groups/"+this.UrlName)); update.Changes.Add(new Assign(Thread.Columns.CountryK, this.CountryK)); update.Changes.Add(new Assign(Thread.Columns.PlaceK,this.PlaceK)); update.Where=new And(new Q(Thread.Columns.ParentObjectType,Model.Entities.ObjectType.Group),new Q(Thread.Columns.ParentObjectK,merge.K)); update.Run(); Cambro.Web.Helpers.WriteAlert("Done merging topics (2/4)..."); } if (true) { Cambro.Web.Helpers.WriteAlert("Merging topics (3/4)...", true); Update update = new Update(); update.Table=TablesEnum.Thread; update.Changes.Add(new Assign(Thread.Columns.GroupK,this.K)); update.Where=new Q(Thread.Columns.GroupK,merge.K); update.Run(); Cambro.Web.Helpers.WriteAlert("Done merging topics (3/4)..."); } if (true) { Cambro.Web.Helpers.WriteAlert("Merging topics (4/4)...", true); Update update = new Update(); update.Table=TablesEnum.Thread; update.Changes.Add(new Assign(Thread.Columns.ParentObjectK,this.K)); update.Where=new And(new Q(Thread.Columns.ParentObjectType,Model.Entities.ObjectType.Group),new Q(Thread.Columns.ParentObjectK,merge.K)); update.Run(); Cambro.Web.Helpers.WriteAlert("Done merging topics (4/4)..."); } Cambro.Web.Helpers.WriteAlert("Deleting old group...", true); merge.DeleteAll(null); Cambro.Web.Helpers.WriteAlert("Done deleting old group..."); Cambro.Web.Helpers.WriteAlert("Updating stats...", true); this.UpdateTotalComments(null); this.UpdateTotalMembers(); Cambro.Web.Helpers.WriteAlert("Done updating stats..."); Cambro.Web.Helpers.WriteAlert("Finished merging groups.", true); }