module_settings_act_general.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package modules
  2. import (
  3. "golang-fave/engine/utils"
  4. "golang-fave/engine/wrapper"
  5. )
  6. func (this *Modules) RegisterAction_SettingsGeneral() *Action {
  7. return this.newAction(AInfo{
  8. Mount: "settings-general",
  9. WantAdmin: true,
  10. }, func(wrap *wrapper.Wrapper) {
  11. pf_module_at_home := utils.Trim(wrap.R.FormValue("module-at-home"))
  12. pf_maintenance := utils.Trim(wrap.R.FormValue("maintenance"))
  13. if !utils.IsNumeric(pf_module_at_home) {
  14. wrap.MsgError(`Must be integer number`)
  15. return
  16. }
  17. if pf_maintenance == "" {
  18. pf_maintenance = "0"
  19. }
  20. if !utils.IsNumeric(pf_maintenance) {
  21. wrap.MsgError(`Must be integer number`)
  22. return
  23. }
  24. pfi_module_at_home := utils.StrToInt(pf_module_at_home)
  25. pfi_maintenance := utils.StrToInt(pf_maintenance)
  26. // Correct values
  27. if pfi_module_at_home < 0 {
  28. pfi_module_at_home = 0
  29. }
  30. if pfi_module_at_home > 2 {
  31. pfi_module_at_home = 2
  32. }
  33. if pfi_maintenance < 0 {
  34. pfi_maintenance = 0
  35. }
  36. if pfi_maintenance > 1 {
  37. pfi_maintenance = 1
  38. }
  39. (*wrap.Config).Engine.MainModule = pfi_module_at_home
  40. (*wrap.Config).Engine.Maintenance = pfi_maintenance
  41. if err := wrap.ConfigSave(); err != nil {
  42. wrap.MsgError(err.Error())
  43. return
  44. }
  45. wrap.ResetCacheBlocks()
  46. // Reload current page
  47. wrap.Write(`window.location.reload(false);`)
  48. })
  49. }