#!/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()

prid = form.getvalue('prid')

q1 = """
select sid, sname from Study join ProjectStudy using(sid) 
where prid="%s"
order by date desc, sname asc;
""" % (prid)


studies = db.runQuery(q1)

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


