Attachment 'ucc_camp_register2013.py'

Download

   1 #!/usr/bin/python
   2 
   3 ## target email
   4 orgEmail='committee-only-and-bob@ucc.asn.au'
   5 
   6 foodCost=0
   7 poolCost=0
   8 memberCost=80
   9 nonMemberCost=115
  10 
  11 
  12 
  13 
  14 
  15 #############################
  16 ## things past here like to break
  17 
  18 import cgi,sys,string,os
  19 
  20 sys.stderr = sys.stdout
  21 
  22 form = cgi.FieldStorage()
  23 
  24 name = ""
  25 address = ""
  26 suburb = ""
  27 postcode = ""
  28 phone_h = ""
  29 phone_m = ""
  30 email = ""
  31 food = 0
  32 food_s = 0
  33 food_sp = ""
  34 payment = 0
  35 pool = 0
  36 phone_emerg = ""
  37 
  38 ## first, find out if we need to start loading variables, sending an email or otherwise
  39 
  40 load = 0
  41 
  42 try:
  43 	if form["send"].value == "Submit":
  44 		load = 2
  45 except: pass
  46 try:
  47 	if form["ok"].value == "Submit":
  48 		load = 1
  49 except: pass
  50 
  51 error = 0
  52 if load != 0:
  53 	try: name = form["name"].value
  54 	except:
  55 		if error == 0: error = 1
  56 	try: address = form["address"].value
  57 	except:
  58 		if error == 0: error = 2
  59 	try: suburb = form["suburb"].value
  60 	except:
  61 		if error == 0: error = 3
  62 	try: postcode = form["postcode"].value
  63 	except:
  64 		if error == 0: error = 4
  65 	try: phone_h = form["phone_h"].value
  66 	except:
  67 		if error == 0: error = 5
  68 	try: phone_m = form["phone_m"].value
  69 	except: pass
  70 	try: email = form["email"].value
  71 	except:
  72 		if error == 0: error = 7
  73 #	try: food = int(form["food"].value)
  74 #	except:
  75 #		if error == 0: error = 8
  76 	food = 1
  77 	food_s = 1
  78 	#if food == 1:
  79 	#	try: food_s = int(form["food_s"].value)
  80 	#	except: food_s = 0
  81 	if food == 1 and food_s == 1:
  82 		try: food_sp = form["food_sp"].value
  83 		except:
  84 			food_sp = "None"
  85 			#if error == 0: error = 9
  86 	try: payment = int(form["payment"].value)
  87 	except:
  88 		if error == 0: error = 10
  89 	try: pool = int(form["pool"].value)
  90 	except: pool = 0
  91 
  92 	try: 
  93 		phone_emerg = form["phone_emerg"].value
  94 	except:
  95 		if error == 0:
  96 			error = 11
  97 
  98 errorText = [
  99 '',
 100 'You have not provided a valid name',
 101 'You have not provided a valid address',
 102 'You have not provided a valid suburb',
 103 'You have not provided a valid postcode',
 104 'You have not provided a valid home phonenumber',
 105 ''
 106 'You have not provided a valid email address',
 107 'You have not correctly indicated if you require food',
 108 'You have failed to list your special food requirements',
 109 'You have failed to indicate whether or not you are an UCC member',
 110 'You have not provided an emergency contact phone number'
 111 ]
 112 
 113 
 114 foodNames = ["Providing own food","Food Supplied"]
 115 foodCosts = [0,foodCost]
 116 answer = ["no","yes"]
 117 checked = ['','checked="checked"']
 118 paymentNames = ["UCC member","Non-member (with Event Membership) "]
 119 paymentCosts = [memberCost,nonMemberCost]
 120 poolCosts = [0,poolCost]
 121 
 122 def dollerer(total):
 123 	total = str(total)
 124 	a = string.find(total,'.')
 125 	if a == -1:
 126 		return '$'+total+'.00'
 127 	else:
 128 		return '$'+total[:a]+'.'+total[a+1:]+'0'*(2-len(total[a+1:]))
 129 
 130 if load == 2:
 131 	print "Content-type: text/plain"
 132 	print
 133 	print "The following information has been emailed to the UCC.\n"
 134 	output = ""
 135 	output += "Name: 		"+name
 136 	output += "\n\nAddress:\n"
 137 	output += address+'\n'
 138 	output += suburb+', '+postcode
 139 	output += "\n\nTelephone home:	 "+phone_h
 140 	output += "\nTelephone mobile: "+phone_m
 141 	output += "\nEmergency contact: "+phone_emerg
 142 	output += "\nEmail:		 "+email
 143 #	output += "\n\nfood:		 "+foodNames[food]
 144 #	if food == 1: output += "\nDietary Requirements:	 "+answer[food_s]+"\n"
 145 #	if food == 1 and food_s == 1: output += food_sp
 146 	output += "\nDietary Requirements: " + food_sp
 147 	output += "\n"
 148 	output +=  "\nPayment:	 "+paymentNames[payment] + "\n"
 149 #	output +=  "\npool:		 "+answer[pool]+"\n"
 150 	print output
 151 	
 152 	# let's mail it
 153 	output2 = ""
 154 	output2 += 'The following information was registered for UCC Camp:\n\n'
 155 	output2 += output
 156 	output2 += '\nIf this is incorrect, or you know nothing about this, please contact '+orgEmail
 157 	output2 += "\n\nPlease pay as soon as possible. Payments can be made by dispense (UCC Members only), or using direct debit to the UCC bank account.\n\nBank: Westpac Bank\nAccount Name: The University Computer Club\nAccount Number: 285739\nBSB: 036054\nDescription: Your name, UCC Camp 2013"
 158 	output2 += '\n\nKind Regards\n--the UCC Camp Registration Script'
 159 	
 160 	os.system('echo "'+output2+'" | mail -s "UCC Camp Registration" '+email+' -b '+orgEmail)
 161 	
 162 	open('/home/other/camp/public-html/registered2013','a').write(name+' '+email+' '+phone_h+' '+phone_m+' '+phone_emerg+'\n')
 163 	
 164 	sys.exit()
 165 
 166 address_s = string.split(address,'\n')
 167 address_sh =""
 168 for i in address_s:
 169 	address_sh += i+'<br />'
 170 del(address_s)
 171 food_sp_s = string.split(food_sp,'\n')
 172 food_sp_sh = ""
 173 for i in food_sp_s:
 174 	food_sp_sh += i+'<br />'
 175 del(food_sp_s)
 176 
 177 print "Content-type: text/html"
 178 print
 179 
 180 print '<title>University Computer Club - UCC Camp 2013</title>'
 181 print '<p align="center"><h1>University Computer Club - UCC Camp 2013</h1>'
 182 print '19<sup>th</sup> - 22<sup>th</sup> July, Camp Leshenaultia</p>'
 183 print '<p> Information <a href=http://camp.ucc.asn.au>here</a></p>'
 184 print '<p> <b> Important: </b> Due to a recent change in guild requirements, this event is 18+ only. We apologise for any inconvenience. </p>'
 185 
 186 print '<form method="post" action="ucc_camp_register.py">'
 187 
 188 if load == 1 and error == 0:
 189 	## display the information that they have entered so far...
 190 	print '<p>You have entered the following information to register for UCC Camp</p>'
 191 	print '<table align="center" width="60%">'
 192 	print '<tr><td width="40%" align="right">Name:</td><td width="60%">'
 193 	print name
 194 	print '</td></tr><tr><td width="40%" align="right" valign="top">Address:</td><td width="60%">'
 195 	print address_sh
 196 	print '</td></tr><tr><td width="40%" align="right">Suburb:</td><td width="60%">'
 197 	print suburb
 198 	print '</td></tr><tr><td width="40%" align="right">Postcode:</td><td width="60%">'
 199 	print postcode
 200 	print '</td></tr><tr><td width="40%" align="right">Home phone#</td><td width="60%">'
 201 	print phone_h
 202 	print '</td></tr><tr><td width="40%" align="right">Mobile phone#</td><td width="60%">'
 203 	print phone_m
 204 	print '</td></tr><tr><td width="40%" align="right">Emergency Contact Phone#</td><td width="60%">'
 205 	print phone_emerg
 206 	print '</td></tr><tr><td width="40%" align="right">Email Address:</td><td width="60%">'
 207 	print email
 208 #	print '</td></tr><tr><td width="40%" align="right">Food:</td><td width="60%">'
 209 #	print foodNames[food]
 210 	if True:
 211 #	if food == 1:
 212 		print '</td></tr><tr><td width="40%" align="right">Special Requirements:</td><td width="60%">'
 213 #		print answer[food_s]
 214 #		if food_s == 1:
 215 		print '</td></td><tr><td></td><td width="60%">'
 216 		print food_sp_sh
 217 	print '</td></tr><tr><td width="40%" align="right">Payment:</td><td width="60%">'
 218 	print paymentNames[payment]
 219 #	print '</td></tr><tr><td width="40%" align="right">Pool Use:</td><td width="60%">'
 220 	#print answer[pool]
 221 	print '</td></tr><tr></tr><tr><td width="40%" align="right"><b>Total:</b></td><td width="60%">'
 222 	total = foodCosts[food]+paymentCosts[payment]+poolCosts[pool]
 223 	print dollerer(total)
 224 	print '</td></tr></table><p align="center">'
 225 	print '<input type="submit" name="send" value="Submit"/></p>'
 226 	
 227 if error != 0:
 228 	print '<p align="center"><h3>'
 229 	print errorText[error]
 230 	print '</h3></p>'
 231 
 232 ## now we can attempt to get values
 233 ## also write in the values we know
 234 print '<table align="center" width="60%">'
 235 print '<tr><td width="40%" align="right">Name:</td><td width="60%"><input type="text" name="name" value="'+name+'" /></td></tr>'
 236 print '<tr><td width="40%" align="right" valign="top">Address:</td><td width="60%"><textarea name="address" rows="3" wrap="soft" cols="24">'
 237 print address+'</textarea></td></tr>'
 238 print '<tr><td width="40%" align="right">Suburb:</td><td width="60%"><input type="text" name="suburb" value="'+suburb+'" /></td></tr>'
 239 print '<tr><td width="40%" align="right">Postcode:</td><td width="60%"><input type="text" name="postcode" value="'+postcode+'" /></td></tr>'
 240 print '<tr><td width="40%" align="right">Home Phone#</td><td width="60%"><input type="text" name="phone_h" value="'+phone_h+'" /></td></tr>'
 241 print '<tr><td width="40%" align="right">Mobile Phone#</td><td width="60%"><input type="text" name="phone_m" value="'+phone_m+'" /></td></tr>'
 242 print '<tr><td width="40%" align="right">Emergency Contact Phone#</td><td width="60%"><input type="text" name="phone_emerg" value="'+phone_emerg+'" /></td></tr>'
 243 print '<tr><td width="40%" align="right">Email:</td><td width="60%"><input type="text" name="email" value="'+email+'" /></td></tr>'
 244 print '<tr><td width="40%" align="right" valign="top">Dietary Requirements</td><td width="60%">'
 245 #print '<input type="radio" name="food" value="0" '+checked[1-food]+' />'+foodNames[0]+'<br />'
 246 #print '<input type="radio" name="food" value="1" '+checked[food]+' />'+foodNames[1]+' ('+dollerer(foodCost)+')<br />'
 247 #print '&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" name="food_s" value="1" '+checked[food_s]+' />Special Requirements<br />'
 248 print '&nbsp;&nbsp;&nbsp;&nbsp;<textarea name="food_sp" rows="3" wrap="soft" cols="21">'
 249 print food_sp+'</textarea></td></tr>'
 250 print '<tr><td width="40%" align="right" valign="top">Payment:</td><td width="60%">'
 251 print '<input type="radio" name="payment" value="0" '+checked[1-payment]+' />'+paymentNames[0]+' ('+dollerer(memberCost)+')<br />'
 252 print '<input type="radio" name="payment" value="1" '+checked[payment]+' />'+paymentNames[1]+ '('+dollerer(nonMemberCost)+')<br />'
 253 # print '<input type="checkbox" name="pool" value="1" '+checked[pool]+' />Use of Pool ('+dollerer(poolCost)+')<br />'
 254 #print '<br/>(The pool is not available to us at this time of year)</td></tr>'
 255 print '</table><p align="center"><input type="submit" name="ok" value="Submit" /> <input type="reset" /></p></form>'

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2013-09-04 11:30:06, 20.9 KB) [[attachment:beefstew.ods]]
  • [get | view] (2013-09-04 11:30:34, 21.5 KB) [[attachment:butterchicken.ods]]
  • [get | view] (2013-09-04 11:35:32, 76.1 KB) [[attachment:camp_emp_2012.pdf]]
  • [get | view] (2013-09-04 11:28:47, 1.1 KB) [[attachment:email_to_attendees.txt]]
  • [get | view] (2013-09-04 11:31:31, 720.5 KB) [[attachment:emp_blank.pdf]]
  • [get | view] (2013-09-04 11:31:02, 18.5 KB) [[attachment:food.ods]]
  • [get | view] (2013-09-04 11:37:09, 2.4 KB) [[attachment:guildissues.txt]]
  • [get | view] (2013-09-04 11:29:48, 18.4 KB) [[attachment:peahamsoup.ods]]
  • [get | view] (2013-09-03 11:53:04, 137.7 KB) [[attachment:poster.png]]
  • [get | view] (2013-09-04 11:31:57, 56.2 KB) [[attachment:risk.pdf]]
  • [get | view] (2013-09-04 11:32:17, 54.6 KB) [[attachment:riskassessment_blank.docx]]
  • [get | view] (2013-09-03 12:00:48, 109.2 KB) [[attachment:tux_mussel.svg]]
  • [get | view] (2013-09-04 11:27:01, 9.3 KB) [[attachment:ucc_camp_register2013.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.