Advertisement
j7sx

p1

Apr 27th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. #!/usr/bin/python
  2. #--*--coding: utf-8--*--
  3.  
  4. import MySQLdb
  5. import user
  6. from dbconfig import read_param, game_server
  7. from premium_user import isPremiumUser
  8.  
  9. status, username = user.isAuth()
  10. premium_account = isPremiumUser()
  11.  
  12. if status:
  13.     if premium_account:
  14.         print """<script>
  15.        var sel = document.getElementById("char_select");
  16.        var txt = sel.options[sel.selectedIndex].text;"""
  17.         print """<script>
  18.        function SelectDefault()
  19.        {
  20.           document.getElementById("char_select").options[0].selected=true;
  21.        }
  22.  
  23.        function sel()
  24.        {
  25.          var sel_elem = document.getElementById("char_select");
  26.          var txt = sel_elem.options[sel_elem.selectedIndex].text;
  27.          //print txt
  28.        }"""
  29.         db_config = game_server()
  30.         db = MySQLdb.connect(**db_config)
  31.         cursor = db.cursor()
  32.         cursor.execute("SELECT char_name from characters WHERE account_name=%s", (username))
  33.         all_characters = cursor.fetchall() #кортеж из кортежей
  34.         all_char = range(len(all_characters)) #range(2) будет [0, 1]
  35.         print "<center>"
  36.         print "<select  name=\"char_select\" id=\"char_select\" OnChange=\'sel()\'>"
  37.         j = 0
  38.         for char_name in all_char:
  39.             j+=1
  40.             i = all_characters[char_name][0]
  41.             print "<option value=\"%s\">%s</option>" % (j, i)
  42.         print "</select><br></center>"
  43.         print """<script>SelectDefault();</script>"""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement