-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzb_bill.cgi
92 lines (75 loc) · 2.14 KB
/
zb_bill.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
#encoding=utf-8
# Author: Simon Xie(Simon)
# E-mail: simon.xie@cbsinteractive.com
# Created Time: 2014-07-06
import UI_template
print 'Content-type:text/html\n'
print
import cgi
import time
import datetime
import db_handle
from db_handle import *
from zb_module import *
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# variables
form = cgi.FieldStorage()
home_time = form.getvalue('home_time')
session = form.getvalue('session')
bill_time=time.time()
if float(bill_time) - float(home_time) >60:
print "This page has been opened for so long, please refresh!"
jump_page("zb_add.cgi?session=%s"%session)
sys.exit()
#ids is the string including other users' id
ids = form.getvalue('ids')
#check_list is listing everybody, non-relavent with checkbox.
check_list=[]
# bill is the dict:: key=>debtor_id, vaule=>1
bill={}
for x in range(10):
print "<br>"
check_list=ids.split("_")[:-1]
for e in check_list:
if form.getvalue(e):
bill[e]=form.getvalue(e)
my_name=form.getvalue('my_name')
# fileds needed in table zb_share
#bill_id
debtor_number = len(bill.keys())
# bill.keys() will be the list of the debtor_ids
# fileds needed in table zb_bills
location = form.getvalue('location')
timestamp = str(datetime.datetime.today()).split('.')[0]
people_number = debtor_number + 1
total_amount = float(form.getvalue('total'))
payer_id = form.getvalue('my_name_id')
everage = "%.2f"%(total_amount / people_number)
# db stuffs
mysql_bill_a(timestamp,people_number,total_amount,int(payer_id),float(everage),session,location)
bill_id = mysql_show("*","zb_bills","timestamp",timestamp)[0][0]
mysql_share_a(bill_id,debtor_number,bill.keys())
# print the bootstrap template
UI_template.bootstrap("Bill bill bill",session)
#test
print check_list
print """
<br>location: %s
<br>timestamp: %s
<br>people_number: %s
<br>total_amount: %s
<br>payer_id: %s
<br>everage: %s
<br>debtors: %s
<br>bill_id: %s
"""%(location,timestamp,people_number,total_amount,payer_id,everage,bill.keys(),bill_id)
print "<a href='zb_home.cgi?session=%s'>Back</a>"%session
jump_page("zb_details.cgi?session=%s"%session)
# tag endings
print """
</body>
</html>
"""