#!/usr/local/bin/python3.3

import cgi
import cgitb
import pymysql
import DAPRfunctions as dapr

#dapr.loadConfiguration()

cookie = dapr.get_cookies()
db=dapr.DBConnection()

cgitb.enable()

if cookie:
    print(cookie)
    fname = cookie["fname"].value
    lname = cookie["lname"].value
    name = " ".join((fname, lname))
    admin = cookie["admin"].value
    uid = cookie["uid"].value
    uname = cookie["uname"].value

print("Content-type: text/html\n")

form = cgi.FieldStorage()

sid = form.getvalue('sid')

q1 = """
select eid, title
from Experiment join StudyExperiment using(eid) 
where sid="%s"
order by create_date desc, title asc;
""" % (sid)


studies = db.runQuery(q1)

print("""<option value="0">-- please select an experiment--</option>""")
for row in studies:
    print("<option value=%s>%s</option>" % (row[0], row[1]))


