topic_tool_acl.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. curs.execute(db_change("update rd set acl = ? where code = ?"), [
  21. acl_data,
  22. topic_num
  23. ])
  24. curs.execute(db_change("insert into topic (id, data, date, ip, top, code) values (?, ?, ?, ?, '1', ?)"), [
  25. str(int(topic_check[0][0]) + 1),
  26. 'acl change ' + acl_data,
  27. time,
  28. ip,
  29. topic_num
  30. ])
  31. rd_plus(topic_num, time)
  32. return redirect('/thread/' + topic_num)
  33. else:
  34. acl_list = get_acl_list()
  35. acl_html_list = ''
  36. curs.execute(db_change("select acl from rd where code = ?"), [topic_num])
  37. topic_acl_get = curs.fetchall()
  38. for data_list in acl_list:
  39. if topic_acl_get and topic_acl_get[0][0] == data_list:
  40. check = 'selected="selected"'
  41. else:
  42. check = ''
  43. acl_html_list += '<option value="' + data_list + '" ' + check + '>' + (data_list if data_list != '' else 'normal') + '</option>'
  44. return easy_minify(flask.render_template(skin_check(),
  45. imp = [load_lang('topic_acl_setting'), wiki_set(), wiki_custom(), wiki_css([0, 0])],
  46. data = '''
  47. <form method="post">
  48. <a href="/acl/TEST#exp">(''' + load_lang('reference') + ''')</a>
  49. <hr>
  50. <select name="acl">
  51. ''' + acl_html_list + '''
  52. </select>
  53. <hr class=\"main_hr\">
  54. <button type="submit">''' + load_lang('save') + '''</button>
  55. </form>
  56. ''',
  57. menu = [['thread/' + topic_num + '/tool', load_lang('return')]]
  58. ))