module_settings_act_general.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. pf_mod_enabled_blog := utils.Trim(wrap.R.FormValue("mod-enabled-blog"))
  14. pf_mod_enabled_shop := utils.Trim(wrap.R.FormValue("mod-enabled-shop"))
  15. if !utils.IsNumeric(pf_module_at_home) {
  16. wrap.MsgError(`Must be integer number`)
  17. return
  18. }
  19. if pf_maintenance == "" {
  20. pf_maintenance = "0"
  21. }
  22. if !utils.IsNumeric(pf_maintenance) {
  23. wrap.MsgError(`Must be integer number`)
  24. return
  25. }
  26. if pf_mod_enabled_blog == "" {
  27. pf_mod_enabled_blog = "0"
  28. }
  29. if !utils.IsNumeric(pf_mod_enabled_blog) {
  30. wrap.MsgError(`Must be integer number`)
  31. return
  32. }
  33. if pf_mod_enabled_shop == "" {
  34. pf_mod_enabled_shop = "0"
  35. }
  36. if !utils.IsNumeric(pf_mod_enabled_shop) {
  37. wrap.MsgError(`Must be integer number`)
  38. return
  39. }
  40. pfi_module_at_home := utils.StrToInt(pf_module_at_home)
  41. pfi_maintenance := utils.StrToInt(pf_maintenance)
  42. pfi_mod_enabled_blog := utils.StrToInt(pf_mod_enabled_blog)
  43. pfi_mod_enabled_shop := utils.StrToInt(pf_mod_enabled_shop)
  44. // Correct values
  45. if pfi_module_at_home < 0 {
  46. pfi_module_at_home = 0
  47. }
  48. if pfi_module_at_home > 2 {
  49. pfi_module_at_home = 2
  50. }
  51. if pfi_maintenance < 0 {
  52. pfi_maintenance = 0
  53. }
  54. if pfi_maintenance > 1 {
  55. pfi_maintenance = 1
  56. }
  57. if pfi_mod_enabled_blog < 0 {
  58. pfi_mod_enabled_blog = 0
  59. }
  60. if pfi_mod_enabled_blog > 1 {
  61. pfi_mod_enabled_blog = 1
  62. }
  63. if pfi_mod_enabled_shop < 0 {
  64. pfi_mod_enabled_shop = 0
  65. }
  66. if pfi_mod_enabled_shop > 1 {
  67. pfi_mod_enabled_shop = 1
  68. }
  69. (*wrap.Config).Engine.MainModule = pfi_module_at_home
  70. (*wrap.Config).Engine.Maintenance = pfi_maintenance
  71. (*wrap.Config).Modules.Enabled.Blog = pfi_mod_enabled_blog
  72. (*wrap.Config).Modules.Enabled.Shop = pfi_mod_enabled_shop
  73. if err := wrap.ConfigSave(); err != nil {
  74. wrap.MsgError(err.Error())
  75. return
  76. }
  77. wrap.ResetCacheBlocks()
  78. // Reload current page
  79. wrap.Write(`window.location.reload(false);`)
  80. })
  81. }