#!/usr/local/bin/python3.3
import cgi
import cgitb
import pymysql
import datetime
import gviz_api
import DAPRfunctions as dapr
import DAPRfunctionsBED as daprBED

#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
    
    
    form = cgi.FieldStorage()
    
    bid = form.getvalue('bid')
    cname = form.getvalue('cname')
    
    bed = daprBED.BEDfile(bid)

    
    print("Content-type: text/plain")
    print()
        
    
    if bid != None:
        col_values = bed.get_bed_col(cname)
        
        table_desc = [("peakID"),(cname)]
        
        data_table = gviz_api.DataTable(table_desc)
        data_table.LoadData(col_values)
        
        print(data_table.ToJSon()) 

else:
    print("Location: login.py")
    print("Content-type: text/html\n")
