#python

import os, sys

# 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)
FILE = files_dir+os.sep+"gq.response"

id = sys.argv[1]
l.prn("id to remove", id)

file_dict = l.get_dict(FILE,"id")
dates = file_dict.keys()
dates.sort()
dates.reverse()
author, title = file_dict[id]["author"], file_dict[id]["title"] 
del file_dict[id]
l.write_data(file_dict, FILE)

print '''<p> The comment "%s" posted by %s has been successfully 
removed. <br/> You should now be redirected to the 
<a href="%s?page=sites/ming-cgi/server/open/response/result">Comments page</a>.</p>''' \
% (title, author, SCRIPT)
print '<meta HTTP-EQUIV="Refresh" CONTENT="0; URL=%s?page=sites/ming-cgi/server/open/response/result">' % SCRIPT

