topic_tool_acl.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from .tool.func import *
  2. def topic_tool_acl(topic_num = 1):
  3. with get_db_connect() as conn:
  4. curs = conn.cursor()
  5. if admin_check(3) != 1:
  6. return re_error('/error/3')
  7. ip = ip_check()
  8. time = get_time()
  9. topic_num = str(topic_num)
  10. curs.execute(db_change("select title, sub from rd where code = ?"), [topic_num])
  11. rd_d = curs.fetchall()
  12. if not rd_d:
  13. return redirect('/')
  14. if flask.request.method == 'POST':
  15. admin_check(3, 'topic_acl_set (code ' + topic_num + ')')
  16. curs.execute(db_change("select id from topic where code = ? order by id + 0 desc limit 1"), [topic_num])
  17. topic_check = curs.fetchall()
  18. if topic_check:
  19. acl_data = flask.request.form.get('acl', '')
  20. acl_data_view = flask.request.form.get('acl_view', '')
  21. curs.execute(db_change("update rd set acl = ? where code = ?"), [
  22. acl_data,
  23. topic_num
  24. ])
  25. curs.execute(db_change("select set_data from topic_set where thread_code = ? and set_name = 'thread_view_acl'"), [topic_num])
  26. db_data = curs.fetchall()
  27. if db_data:
  28. curs.execute(db_change("update topic_set set set_data = ? where thread_code = ?"), [
  29. acl_data_view,
  30. topic_num
  31. ])
  32. else:
  33. curs.execute(db_change("insert into topic_set (thread_code, set_name, set_id, set_data) values (?, 'thread_view_acl', '1', ?)"), [
  34. topic_num,
  35. acl_data_view
  36. ])
  37. curs.execute(db_change("insert into topic (id, data, date, ip, top, code) values (?, ?, ?, ?, '1', ?)"), [
  38. str(int(topic_check[0][0]) + 1),
  39. 'acl change ' + acl_data,
  40. time,
  41. ip,
  42. topic_num
  43. ])
  44. rd_plus(topic_num, time)
  45. return redirect('/thread/' + topic_num)
  46. else:
  47. acl_list = get_acl_list()
  48. acl_html_list = ''
  49. acl_html_list_view = ''
  50. curs.execute(db_change("select acl from rd where code = ?"), [topic_num])
  51. topic_acl_get = curs.fetchall()
  52. for data_list in acl_list:
  53. if topic_acl_get and topic_acl_get[0][0] == data_list:
  54. check = 'selected="selected"'
  55. else:
  56. check = ''
  57. acl_html_list += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
  58. curs.execute(db_change("select set_data from topic_set where thread_code = ? and set_name = 'thread_view_acl'"), [topic_num])
  59. db_data = curs.fetchall()
  60. for data_list in acl_list:
  61. if db_data and db_data[0][0] == data_list:
  62. check = 'selected="selected"'
  63. else:
  64. check = ''
  65. acl_html_list_view += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
  66. return easy_minify(flask.render_template(skin_check(),
  67. imp = [load_lang('topic_acl_setting'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  68. data = '''
  69. <form method="post">
  70. <a href="/acl/TEST#exp">(''' + load_lang('reference') + ''')</a>
  71. <h2>''' + load_lang('thread_acl') + '''</h2>
  72. <select name="acl">
  73. ''' + acl_html_list + '''
  74. </select>
  75. <h2>''' + load_lang('view_acl') + ''' (''' + load_lang('beta') + ''')</h2>
  76. <select name="acl_view">
  77. ''' + acl_html_list_view + '''
  78. </select>
  79. <hr class="main_hr">
  80. <button type="submit">''' + load_lang('save') + '''</button>
  81. </form>
  82. ''',
  83. menu = [['thread/' + topic_num + '/tool', load_lang('return')]]
  84. ))