Browse Source

Maintenance in config and checkbox in CP settings

Vova Tkach 5 years ago
parent
commit
f12a9a28a8

+ 7 - 0
engine/modules/module_settings.go

@@ -80,6 +80,13 @@ func (this *Modules) RegisterModule_Settings() *Module {
 							`</div>`
 					},
 				},
+				{
+					Kind:    builder.DFKCheckBox,
+					Caption: "Maintenance",
+					Name:    "maintenance",
+					Value:   utils.IntToStr((*wrap.Config).Engine.Maintenance),
+					Hint:    "Close web site for maintenance",
+				},
 				{
 					Kind:   builder.DFKSubmit,
 					Value:  "Save",

+ 18 - 0
engine/modules/module_settings_act_general.go

@@ -12,13 +12,23 @@ func (this *Modules) RegisterAction_SettingsGeneral() *Action {
 		WantAdmin: true,
 	}, func(wrap *wrapper.Wrapper) {
 		pf_module_at_home := utils.Trim(wrap.R.FormValue("module-at-home"))
+		pf_maintenance := utils.Trim(wrap.R.FormValue("maintenance"))
 
 		if !utils.IsNumeric(pf_module_at_home) {
 			wrap.MsgError(`Must be integer number`)
 			return
 		}
 
+		if pf_maintenance == "" {
+			pf_maintenance = "0"
+		}
+		if !utils.IsNumeric(pf_maintenance) {
+			wrap.MsgError(`Must be integer number`)
+			return
+		}
+
 		pfi_module_at_home := utils.StrToInt(pf_module_at_home)
+		pfi_maintenance := utils.StrToInt(pf_maintenance)
 
 		// Correct values
 		if pfi_module_at_home < 0 {
@@ -28,7 +38,15 @@ func (this *Modules) RegisterAction_SettingsGeneral() *Action {
 			pfi_module_at_home = 2
 		}
 
+		if pfi_maintenance < 0 {
+			pfi_maintenance = 0
+		}
+		if pfi_maintenance > 1 {
+			pfi_maintenance = 1
+		}
+
 		(*wrap.Config).Engine.MainModule = pfi_module_at_home
+		(*wrap.Config).Engine.Maintenance = pfi_maintenance
 
 		if err := wrap.ConfigSave(); err != nil {
 			wrap.MsgError(err.Error())

+ 3 - 1
engine/wrapper/config/config.go

@@ -7,7 +7,8 @@ import (
 
 type Config struct {
 	Engine struct {
-		MainModule int
+		MainModule  int
+		Maintenance int
 	}
 	Blog struct {
 		Pagination struct {
@@ -81,6 +82,7 @@ func ConfigNew() *Config {
 
 func (this *Config) configDefault() {
 	this.Engine.MainModule = 0
+	this.Engine.Maintenance = 0
 
 	this.Blog.Pagination.Index = 5
 	this.Blog.Pagination.Category = 5