module_index_act_modify.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package modules
  2. import (
  3. "golang-fave/engine/wrapper"
  4. "golang-fave/utils"
  5. )
  6. func (this *Modules) RegisterAction_IndexModify() *Action {
  7. return this.newAction(AInfo{
  8. WantDB: true,
  9. Mount: "index-modify",
  10. WantAdmin: true,
  11. }, func(wrap *wrapper.Wrapper) {
  12. pf_id := wrap.R.FormValue("id")
  13. pf_name := wrap.R.FormValue("name")
  14. pf_alias := wrap.R.FormValue("alias")
  15. pf_content := wrap.R.FormValue("content")
  16. pf_meta_title := wrap.R.FormValue("meta_title")
  17. pf_meta_keywords := wrap.R.FormValue("meta_keywords")
  18. pf_meta_description := wrap.R.FormValue("meta_description")
  19. pf_active := wrap.R.FormValue("active")
  20. if pf_active == "" {
  21. pf_active = "0"
  22. }
  23. if !utils.IsNumeric(pf_id) {
  24. wrap.MsgError(`Inner system error`)
  25. return
  26. }
  27. if pf_name == "" {
  28. wrap.MsgError(`Please specify page name`)
  29. return
  30. }
  31. if pf_alias == "" {
  32. pf_alias = utils.GenerateAlias(pf_name)
  33. }
  34. if !utils.IsValidAlias(pf_alias) {
  35. wrap.MsgError(`Please specify correct page alias`)
  36. return
  37. }
  38. if pf_id == "0" {
  39. // Add new page
  40. _, err := wrap.DB.Exec(
  41. `INSERT INTO pages SET
  42. user = ?,
  43. name = ?,
  44. alias = ?,
  45. content = ?,
  46. meta_title = ?,
  47. meta_keywords = ?,
  48. meta_description = ?,
  49. datetime = ?,
  50. active = ?
  51. ;`,
  52. wrap.User.A_id,
  53. pf_name,
  54. pf_alias,
  55. pf_content,
  56. pf_meta_title,
  57. pf_meta_keywords,
  58. pf_meta_description,
  59. utils.UnixTimestampToMySqlDateTime(utils.GetCurrentUnixTimestamp()),
  60. pf_active,
  61. )
  62. if err != nil {
  63. wrap.MsgError(err.Error())
  64. return
  65. }
  66. wrap.Write(`window.location='/cp/';`)
  67. } else {
  68. // Update page
  69. _, err := wrap.DB.Exec(
  70. `UPDATE pages SET
  71. name = ?,
  72. alias = ?,
  73. content = ?,
  74. meta_title = ?,
  75. meta_keywords = ?,
  76. meta_description = ?,
  77. active = ?
  78. WHERE
  79. id = ?
  80. ;`,
  81. pf_name,
  82. pf_alias,
  83. pf_content,
  84. pf_meta_title,
  85. pf_meta_keywords,
  86. pf_meta_description,
  87. pf_active,
  88. utils.StrToInt(pf_id),
  89. )
  90. if err != nil {
  91. wrap.MsgError(err.Error())
  92. return
  93. }
  94. wrap.Write(`window.location='/cp/index/modify/` + pf_id + `/';`)
  95. }
  96. })
  97. }