Commit 548b15c4 authored by Mikhail Babynichev's avatar Mikhail Babynichev 😊
Browse files

updates;3

parent dcc3fdf1
Loading
Loading
Loading
Loading

football-cms-v3

deleted100644 → 0
−14.8 MiB

File deleted.

handlers/add.go

0 → 100644
+22 −0
Original line number Diff line number Diff line
package handlers

func handler_add(ctx *macaron.Context) {
	var match dbstr.Match
	db.First(&match, "Active = ?", 1)
	if match.Active != 0 {
		ctx.Redirect("/error")
	} else {
		key := ctx.Req.Request.URL.Query()
		if len(key) < 3{
			ctx.HTML(200, "add")
		} else if key["team1"] == nil && key["team2"] == nil && key["stadium"] == nil {
			ctx.HTML(200, "add")
		} else {
			team1 := strings.Join(key["team1"], " ")
			team2 := strings.Join(key["team2"], " ")
			stadium := strings.Join(key["stadium"], " ")
			db.Create(&dbstr.Match{Team1: team1, Team2: team2, Stadium: stadium, Active: 1})
			ctx.Redirect("/")
		}
	}
}
 No newline at end of file

handlers/edit.go

0 → 100644
+21 −0
Original line number Diff line number Diff line
package handlers

func handler_edit(ctx *macaron.Context) {
	var match dbstr.Match
	db.First(&match, "Active = ?", 1)
	if match.Active != 0 {
		r := ctx.Req.Request
		r.ParseForm()                     // Parses the request body
    	arr1 := r.Form.Get("arr1") // x will be "" if parameter is not set
    	arr2 := r.Form.Get("arr2")
    	if len(arr1) > 0 && len(arr2) > 0 {
			db.Model(&match).Update("Arr1", arr1)
			db.Model(&match).Update("Arr2", arr2)
			ctx.Redirect("/")
		} else {
			ctx.Redirect("/error")
		}
	} else {
		ctx.Redirect("/error")	
	}
}
 No newline at end of file

handlers/edit_main.go

0 → 100644
+35 −0
Original line number Diff line number Diff line
package handlers

func handler_edit_main(ctx *macaron.Context) {
	var match dbstr.Match
	db.First(&match, "Active = ?", 1)
	if match.Active != 0 {
		key := ctx.Req.Request.URL.Query()
		if len(key) < 5{
			ctx.Data["Matchinfo"] = match
			ctx.HTML(200, "medit")
		} else if key["team1"] == nil && key["team2"] == nil && key["stadium"] == nil && key["score1"] == nil && key["score2"] == nil {
			ctx.Data["Matchinfo"] = match
			ctx.HTML(200, "medit")
		} else {
			team1 := strings.Join(key["team1"], " ")
			team2 := strings.Join(key["team2"], " ")

			stadium := strings.Join(key["stadium"], " ")

			score1, _ := strconv.Atoi(strings.Join(key["score1"], " "))
			score2, _ := strconv.Atoi(strings.Join(key["score2"], " "))

			db.Model(&match).Update("Team1", team1)
			db.Model(&match).Update("Team2", team2)

			db.Model(&match).Update("Stadium", stadium)

			db.Model(&match).Update("Score1", score1)
			db.Model(&match).Update("Score2", score2)
			ctx.Redirect("/")
		}
	} else {
		ctx.Redirect("/error")
	}
}
 No newline at end of file

handlers/end_match.go

0 → 100644
+12 −0
Original line number Diff line number Diff line
package handlers

func handler_end(ctx *macaron.Context) {
	var match dbstr.Match
	db.First(&match, "Active = ?", 1)
	if match.Active != 0 {
		db.Model(&match).Update("Active", 0)
		ctx.Redirect("/")
	} else {
		ctx.Redirect("/error")
	}
}
 No newline at end of file
Loading