-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.go
40 lines (37 loc) · 1001 Bytes
/
report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package webserver
import (
"io"
"net/http"
"strconv"
"github.com/rothskeller/wppsvr/report"
"github.com/rothskeller/wppsvr/store"
)
func (ws *webserver) serveReport(w http.ResponseWriter, r *http.Request) {
var (
callsign string
session *store.Session
)
if callsign = checkLoggedIn(w, r); callsign == "" {
return
}
if sid, err := strconv.Atoi(r.FormValue("session")); err == nil {
session = ws.st.GetSession(sid)
}
if session == nil {
http.Error(w, "404 Not Found", http.StatusNotFound)
return
}
if session.Flags&store.Imported != 0 {
// This is a report imported from the old NCO scripts. Display
// its report verbatim.
w.Header().Set("Content-Type", "text/plain")
io.WriteString(w, session.Report)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
if canViewEveryone(callsign) {
io.WriteString(w, report.Generate(ws.st, session).RenderHTML(""))
} else {
io.WriteString(w, report.Generate(ws.st, session).RenderHTML(callsign))
}
}