uprava pozice

This commit is contained in:
2025-10-23 10:19:08 +02:00
parent 00f2953e7f
commit 335aff579c
2 changed files with 23 additions and 1 deletions

View File

@@ -487,6 +487,22 @@ func AdminPositionsHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/admin/positions", http.StatusSeeOther) http.Redirect(w, r, "/admin/positions", http.StatusSeeOther)
return return
} }
if r.PostForm.Has("update") {
// Updating an existing position
positionID := r.FormValue("update")
gps := r.FormValue("gps")
if gps == "" {
http.Error(w, "GPS field cannot be empty", http.StatusBadRequest)
return
}
_, err := db.Exec("UPDATE positions SET gps = ? WHERE id = ?", gps, positionID)
if err != nil {
http.Error(w, "Database error", http.StatusInternalServerError)
return
}
http.Redirect(w, r, "/admin/positions", http.StatusSeeOther)
return
}
// Adding a new position // Adding a new position
gps := r.FormValue("gps") gps := r.FormValue("gps")
clue := r.FormValue("clue") clue := r.FormValue("clue")

View File

@@ -19,7 +19,13 @@
{{range .}} {{range .}}
<tr> <tr>
<td>{{.ID}}</td> <td>{{.ID}}</td>
<td>{{.GPS}}</td> <td>
<form action="/admin/positions" method="post">
<input type="text" name="gps" value="{{.GPS}}">
<input type="hidden" name="update" value="{{.ID}}">
<input type="submit" value="Upravit">
</form>
</td>
<td>{{.Clue}}</td> <td>{{.Clue}}</td>
<td><a href="{{.URL}}">{{.URL}}</a></td> <td><a href="{{.URL}}">{{.URL}}</a></td>
<td> <td>