2012-08-15 11:51:25 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2012-08-18 02:06:43 +02:00
|
|
|
type Status struct {
|
2013-07-19 00:37:07 +02:00
|
|
|
Search string
|
|
|
|
User string
|
|
|
|
IsAdmin bool
|
|
|
|
Notif []Notification
|
|
|
|
Home bool
|
|
|
|
About bool
|
|
|
|
News bool
|
|
|
|
Upload bool
|
|
|
|
Stats bool
|
|
|
|
Help bool
|
2012-08-18 02:06:43 +02:00
|
|
|
}
|
|
|
|
|
2012-08-19 02:29:34 +02:00
|
|
|
func GetStatus(w http.ResponseWriter, r *http.Request) Status {
|
|
|
|
var s Status
|
|
|
|
sess := GetSession(r)
|
|
|
|
sess.Save(w, r)
|
|
|
|
s.User = sess.User
|
2013-07-19 00:37:07 +02:00
|
|
|
s.IsAdmin = sess.IsAdmin()
|
2012-08-19 02:29:34 +02:00
|
|
|
s.Notif = sess.Notif
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2012-10-24 21:08:34 +02:00
|
|
|
var templates = template.Must(template.ParseFiles(TEMPLATE_PATH+"header.html",
|
|
|
|
TEMPLATE_PATH+"footer.html",
|
2013-05-09 09:42:03 +02:00
|
|
|
TEMPLATE_PATH+"404.html",
|
2012-10-24 21:08:34 +02:00
|
|
|
TEMPLATE_PATH+"index.html",
|
|
|
|
TEMPLATE_PATH+"about.html",
|
2013-07-17 01:08:44 +02:00
|
|
|
TEMPLATE_PATH+"news.html",
|
|
|
|
TEMPLATE_PATH+"edit_news.html",
|
2012-10-24 21:08:34 +02:00
|
|
|
TEMPLATE_PATH+"book.html",
|
|
|
|
TEMPLATE_PATH+"search.html",
|
|
|
|
TEMPLATE_PATH+"upload.html",
|
|
|
|
TEMPLATE_PATH+"new.html",
|
|
|
|
TEMPLATE_PATH+"read.html",
|
|
|
|
TEMPLATE_PATH+"edit.html",
|
2012-10-28 18:47:44 +01:00
|
|
|
TEMPLATE_PATH+"settings.html",
|
2013-05-05 01:39:28 +02:00
|
|
|
TEMPLATE_PATH+"stats.html",
|
2013-06-01 04:56:35 +02:00
|
|
|
TEMPLATE_PATH+"help.html",
|
2012-10-24 21:08:34 +02:00
|
|
|
))
|
2012-08-15 11:51:25 +02:00
|
|
|
|
2012-10-24 21:08:34 +02:00
|
|
|
func loadTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
|
2012-08-15 12:00:44 +02:00
|
|
|
err := templates.ExecuteTemplate(w, tmpl+".html", data)
|
2012-08-15 11:51:25 +02:00
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|