diff --git a/data.sql b/data.sql index d9d80d2d..e03870cc 100644 --- a/data.sql +++ b/data.sql @@ -48,6 +48,7 @@ CREATE TABLE `forums`( `name` varchar(100) not null, `active` tinyint DEFAULT 1 not null, `topicCount` int DEFAULT 0 not null, + `preset` varchar(100) DEFAULT '' not null, `lastTopic` varchar(100) DEFAULT '' not null, `lastTopicID` int DEFAULT 0 not null, `lastReplyer` varchar(100) DEFAULT '' not null, diff --git a/forum.go b/forum.go index ac2be0cb..bdc7a07d 100644 --- a/forum.go +++ b/forum.go @@ -2,11 +2,24 @@ package main import "database/sql" import _ "github.com/go-sql-driver/mysql" +type ForumAdmin struct +{ + ID int + Name string + Active bool + Preset string + TopicCount int + + PresetLang string + PresetEmoji string +} + type Forum struct { ID int Name string Active bool + Preset string TopicCount int LastTopic string LastTopicID int @@ -20,25 +33,27 @@ type ForumSimple struct ID int Name string Active bool + Preset string } -func create_forum(forum_name string, active bool) (int, error) { +func create_forum(forum_name string, active bool, preset string) (int, error) { var fid int err := forum_entry_exists_stmt.QueryRow().Scan(&fid) if err != nil && err != sql.ErrNoRows { return 0, err } if err != sql.ErrNoRows { - _, err = update_forum_stmt.Exec(forum_name, active, fid) + _, err = update_forum_stmt.Exec(forum_name, active, preset, fid) if err != nil { return fid, err } forums[fid].Name = forum_name forums[fid].Active = active + forums[fid].Preset = preset return fid, nil } - res, err := create_forum_stmt.Exec(forum_name, active) + res, err := create_forum_stmt.Exec(forum_name, active, preset) if err != nil { return 0, err } @@ -49,7 +64,7 @@ func create_forum(forum_name string, active bool) (int, error) { } fid = int(fid64) - forums = append(forums, Forum{fid,forum_name,active,0,"",0,"",0,""}) + forums = append(forums, Forum{fid,forum_name,active,preset,0,"",0,"",0,""}) return fid, nil } diff --git a/images/forum_manager.PNG b/images/forum_manager.PNG index 3bb160c0..dfd234ad 100644 Binary files a/images/forum_manager.PNG and b/images/forum_manager.PNG differ diff --git a/main.go b/main.go index 028c7d87..968972f2 100644 --- a/main.go +++ b/main.go @@ -78,7 +78,7 @@ func compile_templates() { topics_page := TopicsPage{"Topic List",user,noticeList,topicList,""} topics_tmpl := c.compile_template("topics.html","templates/","TopicsPage", topics_page, varList) - forum_item := Forum{1,"General Forum",true,0,"",0,"",0,""} + forum_item := Forum{1,"General Forum",true,"all",0,"",0,"",0,""} forum_page := ForumPage{"General Forum",user,noticeList,topicList,forum_item,1,1,nil} forum_tmpl := c.compile_template("forum.html","templates/","ForumPage", forum_page, varList) diff --git a/mod_routes.go b/mod_routes.go index 2adf1f69..db9b0787 100644 --- a/mod_routes.go +++ b/mod_routes.go @@ -700,7 +700,8 @@ func route_panel_forums(w http.ResponseWriter, r *http.Request){ var forumList []interface{} for _, forum := range forums { if forum.Name != "" { - forumList = append(forumList,forum) + fadmin := ForumAdmin{forum.ID,forum.Name,forum.Active,forum.Preset,forum.TopicCount,preset_to_lang(forum.Preset),preset_to_emoji(forum.Preset)} + forumList = append(forumList,fadmin) } } pi := Page{"Forum Manager",user,noticeList,forumList,nil} @@ -729,7 +730,7 @@ func route_panel_forums_create_submit(w http.ResponseWriter, r *http.Request){ var active bool fname := r.PostFormValue("forum-name") - fpreset := r.PostFormValue("forum-preset") + fpreset := strip_invalid_preset(r.PostFormValue("forum-preset")) factive := r.PostFormValue("forum-name") if factive == "on" || factive == "1" { active = true @@ -737,7 +738,7 @@ func route_panel_forums_create_submit(w http.ResponseWriter, r *http.Request){ active = false } - fid, err := create_forum(fname,active) + fid, err := create_forum(fname,active,fpreset) if err != nil { InternalError(err,w,r,user) return @@ -866,16 +867,17 @@ func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) { } forum_name := r.PostFormValue("forum-name") + forum_preset := strip_invalid_preset(r.PostFormValue("forum-preset")) forum_active := r.PostFormValue("forum-active") if (fid > forumCapCount) || (fid < 0) || forums[fid].Name=="" { LocalErrorJSQ("The forum you're trying to edit doesn't exist.",w,r,user,is_js) return } - if forum_name == "" && forum_active == "" { + /*if forum_name == "" && forum_active == "" { LocalErrorJSQ("You haven't changed anything!",w,r,user,is_js) return - } + }*/ if forum_name == "" { forum_name = forums[fid].Name @@ -890,7 +892,7 @@ func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) { active = false } - _, err = update_forum_stmt.Exec(forum_name,active,fid) + _, err = update_forum_stmt.Exec(forum_name,active,forum_preset,fid) if err != nil { InternalErrorJSQ(err,w,r,user,is_js) return @@ -902,6 +904,11 @@ func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) { if forums[fid].Active != active { forums[fid].Active = active } + if forums[fid].Preset != forum_preset { + forums[fid].Preset = forum_preset + } + + permmap_to_query(preset_to_permmap(forum_preset),fid) if is_js == "0" { http.Redirect(w,r,"/panel/forums/",http.StatusSeeOther) diff --git a/mysql.go b/mysql.go index e8e82654..75201444 100644 --- a/mysql.go +++ b/mysql.go @@ -361,7 +361,7 @@ func init_database(err error) { } log.Print("Preparing create_forum statement.") - create_forum_stmt, err = db.Prepare("INSERT INTO forums(name,active) VALUES(?,?)") + create_forum_stmt, err = db.Prepare("INSERT INTO forums(name,active,preset) VALUES(?,?,?)") if err != nil { log.Fatal(err) } @@ -374,7 +374,7 @@ func init_database(err error) { } log.Print("Preparing update_forum statement.") - update_forum_stmt, err = db.Prepare("update forums set name = ?, active = ? where fid = ?") + update_forum_stmt, err = db.Prepare("update forums set name = ?, active = ?, preset = ? where fid = ?") if err != nil { log.Fatal(err) } @@ -502,10 +502,10 @@ func init_database(err error) { log.Print("Loading the forums.") log.Print("Adding the uncategorised forum") - forums = append(forums, Forum{0,"Uncategorised",uncategorised_forum_visible,0,"",0,"",0,""}) + forums = append(forums, Forum{0,"Uncategorised",uncategorised_forum_visible,"all",0,"",0,"",0,""}) //rows, err = db.Query("SELECT fid, name, active, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime FROM forums") - rows, err = db.Query("select fid, name, active, topicCount, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime from forums order by fid asc") + rows, err = db.Query("select fid, name, active, preset, topicCount, lastTopic, lastTopicID, lastReplyer, lastReplyerID, lastTopicTime from forums order by fid asc") if err != nil { log.Fatal(err) } @@ -513,8 +513,8 @@ func init_database(err error) { i = 1 for ;rows.Next();i++ { - forum := Forum{0,"",true,0,"",0,"",0,""} - err := rows.Scan(&forum.ID, &forum.Name, &forum.Active, &forum.TopicCount, &forum.LastTopic, &forum.LastTopicID, &forum.LastReplyer, &forum.LastReplyerID, &forum.LastTopicTime) + forum := Forum{ID:0,Name:"",Active:true,Preset:"all"} + err := rows.Scan(&forum.ID, &forum.Name, &forum.Active, &forum.Preset, &forum.TopicCount, &forum.LastTopic, &forum.LastTopicID, &forum.LastReplyer, &forum.LastReplyerID, &forum.LastTopicTime) if err != nil { log.Fatal(err) } diff --git a/permissions.go b/permissions.go index e4542b44..5a74c681 100644 --- a/permissions.go +++ b/permissions.go @@ -299,3 +299,54 @@ func rebuild_forum_permissions(fid int) error { func build_forum_permissions() error { return nil } + +func strip_invalid_preset(preset string) string { + switch(preset) { + case "all": + case "announce": + case "members": + case "staff": + case "admins": + case "archive": + break + default: + return "" + } + return preset +} + +func preset_to_lang(preset string) string { + switch(preset) { + case "all": + return ""//return "Everyone" + case "announce": + return "Announcements" + case "members": + return "Member Only" + case "staff": + return "Staff Only" + case "admins": + return "Admin Only" + case "archive": + return "Archive" + } + return "" +} + +func preset_to_emoji(preset string) string { + switch(preset) { + case "all": + return ""//return "Everyone" + case "announce": + return "📣" + case "members": + return "👪" + case "staff": + return "👮" + case "admins": + return "👑" + case "archive": + return "☠️" + } + return "" +} diff --git a/template_topic.go b/template_topic.go index b369366b..4a9b9cf9 100644 --- a/template_topic.go +++ b/template_topic.go @@ -1,8 +1,8 @@ /* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */ package main +import "io" import "strconv" import "html/template" -import "io" func init() { template_topic_handle = template_topic diff --git a/templates/panel-forums.html b/templates/panel-forums.html index 1d4a1db6..191cb770 100644 --- a/templates/panel-forums.html +++ b/templates/panel-forums.html @@ -1,6 +1,9 @@ {{template "header.html" . }} {{template "panel-menu.html" . }} - +
@@ -9,7 +12,9 @@