#python

import os, sys, time

# note that ming.cgi debug does not carry into pypage execution
debug = 0								

def cgi_init():
	"""
	assumes 'data' and 'cgi-bin' are peer directories
	"""
	global l, c, files_dir, SCRIPT
	current = sys.path[0]
	consts = current.split(os.sep)
	consts = (os.sep).join(consts[:consts.index("data")])+os.sep+"cgi-bin"+os.sep+"TheMingServer"
	sys.path.append(consts)

	import Lib3
	l = Lib3.Lib3(debug)
	import Constants
	c = Constants.Constants()
	files_dir = c.FILES_DIR
	SCRIPT = c.CGI_NAME
	return

cgi_init()
l.prn("FILES_DIR",files_dir)

NOTATE = files_dir+os.sep+"gq.notate"
FILE = files_dir+os.sep+"gq.response"

l.set_files(["gq.notate","gq.response"])

try:
	os.remove(NOTATE)
except:
	pass

file_dict = l.get_dict(FILE)
entry_list = []	
dates = file_dict.keys()
for date in dates:
	dict = file_dict[date]
	entry = (dict["id"], dict["author"], dict["title"], time.ctime(float(date)))
	entry_list.append(entry) # comment's id, author, title and formatted date

print '''
<center>
<table width="75%%"><tr><td>

<form action="%s" method=post>

<h4>Comment To Annotate</h4>
''' % SCRIPT

for entry in entry_list:
	print "<input type=\"radio\" name=\"comment\" value=\"%s\"> %s - %s (%s) <br>" % entry

print '''

<h4>Annotation</h4>
<p><textarea cols="80" name="note" rows="20" wrap="soft">

</textarea>

<hr>
<h4>Submit</h4>

When you are finished, submit your request.
<input type="hidden" name="incoming" value="token">
<input type="hidden" name="file" value="gq.notate">
<input type="hidden" name="page" value="sites/ming-cgi/server/private/notate/result/result">
<input type="submit" name="submit" value="here.">
</form>

</td></tr></table>
'''

	

