module_settings_act_general.go 1.3 KB

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