2016-12-03 13:45:08 +00:00
|
|
|
package main
|
2017-03-27 07:09:28 +00:00
|
|
|
|
2017-03-14 10:57:40 +00:00
|
|
|
//import "fmt"
|
2017-03-27 07:09:28 +00:00
|
|
|
import "sync"
|
2017-03-15 08:34:14 +00:00
|
|
|
import "strconv"
|
2017-01-26 13:37:50 +00:00
|
|
|
import "database/sql"
|
|
|
|
import _ "github.com/go-sql-driver/mysql"
|
2016-12-03 13:45:08 +00:00
|
|
|
|
2017-02-04 15:49:24 +00:00
|
|
|
type ForumAdmin struct
|
|
|
|
{
|
|
|
|
ID int
|
|
|
|
Name string
|
|
|
|
Active bool
|
|
|
|
Preset string
|
|
|
|
TopicCount int
|
|
|
|
PresetLang string
|
|
|
|
}
|
|
|
|
|
2016-12-03 13:45:08 +00:00
|
|
|
type Forum struct
|
|
|
|
{
|
|
|
|
ID int
|
|
|
|
Name string
|
2016-12-06 10:26:48 +00:00
|
|
|
Active bool
|
2017-02-04 15:49:24 +00:00
|
|
|
Preset string
|
2017-01-26 13:37:50 +00:00
|
|
|
TopicCount int
|
2016-12-03 13:45:08 +00:00
|
|
|
LastTopic string
|
|
|
|
LastTopicID int
|
|
|
|
LastReplyer string
|
|
|
|
LastReplyerID int
|
|
|
|
LastTopicTime string
|
|
|
|
}
|
2016-12-04 10:44:28 +00:00
|
|
|
|
|
|
|
type ForumSimple struct
|
|
|
|
{
|
|
|
|
ID int
|
|
|
|
Name string
|
2016-12-07 09:34:09 +00:00
|
|
|
Active bool
|
2017-02-04 15:49:24 +00:00
|
|
|
Preset string
|
2017-01-01 15:45:43 +00:00
|
|
|
}
|
2017-01-26 13:37:50 +00:00
|
|
|
|
2017-03-27 07:09:28 +00:00
|
|
|
var forum_update_mutex sync.Mutex
|
2017-02-04 15:49:24 +00:00
|
|
|
func create_forum(forum_name string, active bool, preset string) (int, error) {
|
2017-01-26 13:37:50 +00:00
|
|
|
var fid int
|
|
|
|
err := forum_entry_exists_stmt.QueryRow().Scan(&fid)
|
|
|
|
if err != nil && err != sql.ErrNoRows {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
if err != sql.ErrNoRows {
|
2017-03-27 07:09:28 +00:00
|
|
|
forum_update_mutex.Lock()
|
2017-02-04 15:49:24 +00:00
|
|
|
_, err = update_forum_stmt.Exec(forum_name, active, preset, fid)
|
2017-01-26 13:37:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return fid, err
|
|
|
|
}
|
|
|
|
forums[fid].Name = forum_name
|
|
|
|
forums[fid].Active = active
|
2017-02-04 15:49:24 +00:00
|
|
|
forums[fid].Preset = preset
|
2017-03-27 07:09:28 +00:00
|
|
|
forum_update_mutex.Unlock()
|
2017-01-26 13:37:50 +00:00
|
|
|
return fid, nil
|
|
|
|
}
|
|
|
|
|
2017-02-04 15:49:24 +00:00
|
|
|
res, err := create_forum_stmt.Exec(forum_name, active, preset)
|
2017-01-26 13:37:50 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
fid64, err := res.LastInsertId()
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
2017-02-04 06:19:55 +00:00
|
|
|
fid = int(fid64)
|
2017-01-26 13:37:50 +00:00
|
|
|
|
2017-02-04 15:49:24 +00:00
|
|
|
forums = append(forums, Forum{fid,forum_name,active,preset,0,"",0,"",0,""})
|
2017-01-26 13:37:50 +00:00
|
|
|
return fid, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func delete_forum(fid int) error {
|
|
|
|
_, err := delete_forum_stmt.Exec(fid)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
forums[fid].Name = ""
|
|
|
|
return nil
|
|
|
|
}
|
2017-03-14 10:57:40 +00:00
|
|
|
|
2017-03-15 08:34:14 +00:00
|
|
|
func get_forum(fid int) (forum *Forum, res bool) {
|
|
|
|
if !((fid <= forumCapCount) && (fid >= 0) && forums[fid].Name!="") {
|
|
|
|
return forum, false
|
|
|
|
}
|
|
|
|
return &forums[fid], true
|
|
|
|
}
|
|
|
|
|
|
|
|
func get_forum_copy(fid int) (forum Forum, res bool) {
|
|
|
|
if !((fid <= forumCapCount) && (fid >= 0) && forums[fid].Name!="") {
|
|
|
|
return forum, false
|
|
|
|
}
|
|
|
|
return forums[fid], true
|
|
|
|
}
|
|
|
|
|
2017-03-14 10:57:40 +00:00
|
|
|
func forum_exists(fid int) bool {
|
|
|
|
return (fid <= forumCapCount) && (fid >= 0) && forums[fid].Name!=""
|
|
|
|
}
|
2017-03-15 08:34:14 +00:00
|
|
|
|
|
|
|
func build_forum_url(fid int) string {
|
|
|
|
return "/forum/" + strconv.Itoa(fid)
|
|
|
|
}
|