diff --git a/scripts/cgi-bin/info.py b/scripts/cgi-bin/info.py index 76b28b5d0..15526beec 100755 --- a/scripts/cgi-bin/info.py +++ b/scripts/cgi-bin/info.py @@ -13,6 +13,7 @@ DefaultTitle = "Vinyambar Datenbank" dbname = "vinyambar" From = "accounts@vinyambar.de" smtpserver = 'localhost' +Errors = "" # define a new function called Display # it takes one parameter - a string to Display @@ -22,8 +23,8 @@ def Display(Content, Title=DefaultTitle): TemplateInput = TemplateHandle.read() TemplateHandle.close() # close the file - for key in Form.keys(): - Content=Content+"
"+str(key)+"="+str(Form[key]) +# for key in Form.keys(): +# Content=Content+"
"+str(key)+"="+str(Form[key]) # this defines an exception string in case our # template file is messed up @@ -36,122 +37,25 @@ def Display(Content, Title=DefaultTitle): print "Content-Type: text/html\n\n" print SubResult[0] + return -def ShowInfo(custid, Password): - db = MySQLdb.connect(db=dbname) - cursor = db.cursor() - cursor.execute("select max(date), max(id) from transactions") - lastdate, id = cursor.fetchone() - - query=("select info, firstname, lastname, email, address, city, country, phone, sum(t.balance), status "+ - "from users u, transactions t "+ - "where u.id=t.user and u.id="+str(custid)+" and u.password='"+Password+"' "+ - "GROUP BY u.id") - - #print query - results = cursor.execute(query); - if results > 0: - - output = "
Letzte Aktualisierung: "+str(lastdate)[0:10]+"
\n" - while results>0: - results = results - 1 - row = cursor.fetchone() - line = "" - line = line + "\n" - line = line + "\n" - line = line + "\n" - line = line + "\n" - line = line + "\n" - line = line + "\n" - line = line + "\n" - line = line + "\n" - output = output + line; - - output=output+"
Vorname
Nachname
EMail Adresse
Adresse
Wohnort
Telefon
Kontostand"+str(row[8])+" EUR
Status"+row[9]+"
" - - query = ("select games.name, races.name, s.status, s.faction "+ - "from races, games, subscriptions s "+ - "where s.race=races.race and s.game=games.id "+ - "and s.user="+str(custid)+" "); - - results = cursor.execute(query); - - output=output+"

Anmeldungen

\n
\n" - output=output+"\n" - while results>0: - results = results - 1 - row = cursor.fetchone() - line = "" - line = line + '\n' - line = line + '\n' - line = line + '\n' - line = line + '\n' - line = line + '\n' - line = line + '\n' - output=output+line - - output=output+"
SpielRasseStatusParteiAn-/Abmelden
'+row[0]+''+row[1]+''+row[2]+''+row[3]+'' - if row[2]=='ACTIVE': - line = line + '' - if row[2]=='CANCELLED': - line = line + '' - line = line + '
" - - query="select date, balance, text from transactions, descriptions where descriptions.handle=transactions.description and user="+str(custid)+" ORDER BY date" - results = cursor.execute(query); - - output=output+"

Transaktionen

\n
\n" - output=output+"\n" - while results>0: - results = results - 1 - row = cursor.fetchone() - line = "" - line = line + "\n" - line = line + "\n" - line = line + "\n" - line = line + "\n" - output=output+line - - output=output+"
DatumBetragVerwendung
"+str(row[0])[0:10]+""+str(row[1])+" EUR"+row[2]+"
" - output=output+'
' - output=output+'' - output=output+'' - output=output+"
" - else: - output = "Die Kundennummer oder das angegebene Passwort sind nicht korrekt." - db.close() - Display(output, "Kundendaten #"+str(custid)) - -def Save(custid, Password): - validkeys=['email','address','lastname','firstname','city','password','phone'] - values='id='+str(custid) - for key in Form.keys(): - if key in validkeys: - values=values+", "+key+"='"+Form[key].value+"'" +def SendTransfer(userid, factionid, game): db = MySQLdb.connect(db=dbname) cursor=db.cursor() - cursor.execute('UPDATE users SET '+values+' where id='+str(custid)) - - nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='ACTIVE' and s.user="+str(custid) + " and s.game=g.id") - while nfactions > 0: - game, sid, faction = cursor.fetchone() - if Form.has_key("cancel_"+faction): - update = db.cursor() - update.execute("UPDATE subscriptions set status='CANCELLED' where id="+str(sid)) - nfactions = nfactions - 1 - - nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='CANCELLED' and s.user="+str(custid) + " and s.game=g.id") - while nfactions > 0: - game, sid, faction = cursor.fetchone() - if Form.has_key("activate_"+faction): - update = db.cursor() - update.execute("UPDATE subscriptions set status='ACTIVE' where id="+str(sid)) - nfactions = nfactions - 1 - + cursor.execute("select email, firstname from users where id="+str(userid)) + email, firstname = cursor.fetchone() + Msg="From: "+From+"\nTo: "+email+"\nSubject: Vinambar Passwort\n\n" + Msg=Msg+"Hallo, "+firstname+"\n" + Msg=Msg+"Ein Spieler hat Dir seine Partei " + factionid + " im Spiel " + game + "\n" + Msg=Msg+"übertragen. Um die Partei zu übernehmen, gehe bitte auf die Webseite \n" + Msg=Msg+"http://www.vinyambar.de/accounts.shtml, und akzeptiere dort den Transfer.\n" + server=smtplib.SMTP(smtpserver) + server.sendmail(From, email, Msg) + server.close() db.close() - ShowInfo(custid, Password) -# Display("Noch nicht implementiert", "Daten speichern für Kunde #"+str(custid)) + return + def SendPass(email): try: @@ -173,6 +77,187 @@ def SendPass(email): except: Display('
Beim Versenden des Passwortes ist ein Fehler aufgetreten.
Eventuell ist die email-Adresse unbekannt
', 'Kundendaten für '+email) + +def ShowInfo(custid, Password): + global Errors + db = MySQLdb.connect(db=dbname) + cursor = db.cursor() + cursor.execute("select max(date), max(id) from transactions") + lastdate, id = cursor.fetchone() + + query=("select firstname, lastname, email, address, city, country, phone, status "+ + "from users "+ + "where id="+str(custid)+" and password='"+Password+"' ") + + #print query + results = cursor.execute(query); + if results != 0: + + output = '
Letzter Buchungstag: '+str(lastdate)[0:10]+'
\n' + firstname, lastname, email, address, city, country, phone, status = cursor.fetchone() + + query = "SELECT sum(balance) from transactions where user="+str(custid) + transactions = cursor.execute(query) + balance = 0.00 + if transactions != 0: + balance = cursor.fetchone()[0] + if balance == None: + balance=0.00 + + line = ""+Errors+"" + line = line + "\n" + line = line + "\n" + if email==None: + email="" + line = line + "\n" + if address==None: + address="" + line = line + "\n" + if city==None: + city="" + line = line + "\n" + if phone==None: + phone="" + line = line + "\n" + line = line + "\n" + line = line + "\n" + output = output + line; + + output=output+"
Vorname
Nachname
EMail Adresse
Adresse
Wohnort
Telefon
Kontostand"+str(balance)+" EUR
Status"+status+"
" + + output=output+"

Partien

\n" + games = cursor.execute("select id, name, status, info from games order by id") + while games>0: + games=games-1 + gid, game, status, info = cursor.fetchone() + + line = '\n' + if status=='WAITING': + line = line+'' + elif status=='RUNNING': + query = ("select games.name, races.name, s.status, s.faction "+ + "from races, games, subscriptions s "+ + "where s.race=races.race and s.game="+str(int(gid))+" and s.game=games.id "+ + "and s.user="+str(custid)+" ") + + fcursor = db.cursor() + results = fcursor.execute(query) + if results>0: + while results>0: + results = results - 1 + game, race, status, faction = fcursor.fetchone() + line = line + '" + line = line + "' + else: + continue + else: + continue + output=output+line+'
' + game + ': ' + info + '
' + line = line + 'Ich möchte an diesem Spiel teilnehmen, und bevorzuge folgende Rasse:
\n' + line = line + '' + line = line+'
Partei ' + faction + ', ' + race + ", " + status + "
" + if status=='ACTIVE': + line = line + 'Ich möchte diese Partei aufgeben:
\n' + line = line + 'Ich möchte die Partei an Spieler # übergeben.\n' + elif status=='CANCELLED': + line = line + 'Reaktivieren: \n' + elif status=='TRANSFERED': + line = line + 'Transfer akzeptieren: \n' + line = line+'
\n

\n' + output=output+"

" + + query="select date, balance, text from transactions, descriptions where descriptions.handle=transactions.description and user="+str(custid)+" ORDER BY date" + results = cursor.execute(query); + + if results>0: + output=output+'
\n

Transaktionen

\n\n' + output=output+"\n" + while results>0: + results = results - 1 + row = cursor.fetchone() + line = "" + line = line + "\n" + line = line + "\n" + line = line + "\n" + line = line + "\n" + output=output+line + output=output+"
DatumBetragVerwendung
"+str(row[0])[0:10]+""+str(row[1])+" EUR"+row[2]+"
" + + output=output+'

' + output=output+'' + output=output+'' + output=output+"
" + else: + output = "Die Kundennummer oder das angegebene Passwort sind nicht korrekt." + db.close() + Display(output, "Kundendaten #"+str(custid)) + Errors = "" + +def TransferFaction(sid, faction, newuser, game): + db = MySQLdb.connect(db=dbname) + update = db.cursor() + exist = update.execute("select id from users where id="+str(newuser)) + if exist==1: + update.execute("UPDATE subscriptions set status='TRANSFERED', user=" + str(newuser) + " where id="+str(sid)) + SendTransfer(newuser, faction, game); + db.close() + return + +def Save(custid, Password): + validkeys=['email','address','lastname','firstname','city','password','phone'] + values='id='+str(custid) + for key in Form.keys(): + if key in validkeys: + values=values+", "+key+"='"+Form[key].value+"'" + db = MySQLdb.connect(db=dbname) + cursor=db.cursor() + cursor.execute('UPDATE users SET '+values+' where id='+str(custid)) + + nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='ACTIVE' and s.user="+str(custid) + " and s.game=g.id") + while nfactions > 0: + game, sid, faction = cursor.fetchone() + if Form.has_key("cancel_"+faction): + update = db.cursor() + update.execute("UPDATE subscriptions set status='CANCELLED' where id="+str(sid)) + elif Form.has_key("transfer_"+faction): + newuser = int(Form["transfer_"+faction].value) + TransferFaction(sid, faction, newuser, game) + nfactions = nfactions - 1 + + nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='TRANSFERED' and s.user="+str(custid) + " and s.game=g.id") + while nfactions > 0: + game, sid, faction = cursor.fetchone() + if Form.has_key("accept_"+faction): + update = db.cursor() + update.execute("UPDATE subscriptions set status='ACTIVE' where id="+str(sid)) + nfactions = nfactions - 1 + + nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='CANCELLED' and s.user="+str(custid) + " and s.game=g.id") + while nfactions > 0: + game, sid, faction = cursor.fetchone() + if Form.has_key("activate_"+faction): + update = db.cursor() + update.execute("UPDATE subscriptions set status='ACTIVE' where id="+str(sid)) + nfactions = nfactions - 1 + + db.close() + ShowInfo(custid, Password) +# Display("Noch nicht implementiert", "Daten speichern für Kunde #"+str(custid)) + + Form = cgi.FieldStorage() if Form.has_key("user"):