def profResults():


    prof = Professor('', '', '', '', '', '', '', '')

    profid = request.args.get('profid')

    database = Database()
    database.connect()
    prof = database.profSearch(profid)
    database.disconnect()

    titles = prof.getTitles()
    links = prof.getLinks()
    pic = prof.getPicLink()

    html = render_template('profpage.html', profid = profid, prof = prof, pic = pic, titles = titles, links = links)
    response = make_response(html)
    return(response)
def emailResults():
    prof = Professor('', '', '', '', '', '', '', '')

    profid = request.args.get('profid')

    database = Database()
    database.connect()
    prof = database.profSearch(profid)
    database.disconnect()

    year = request.args.get('year')
    type = request.args.get('type')
    areasNum = request.args.getlist('areas')
    areas = []
    for num in areasNum:
        areas.append(prof.getAreas()[int(num)][0].strip('. '))

    if len(areas) > 1:
        for area in areas[:-1]:
            areasFormatted += area
            areasFormatted += ", "
        areasFormatted += ", and "
        areasFormatted += areas[-1]
    else:
        areasFormatted = areas[0]

#start building email
    body1 = "Dear Professor " + str(prof.getName().split()[1]) + ","
    body4 = "Your work in " + str(areasFormatted) + " is inspiring and I would be honored if you advised me for my " + str(type) + ". Please let me know if I can send you information about myself, or if there are other steps that I should take."
    body5 = "Sincerely,"
    body6 = "(Your name here)"

    projNum = request.args.getlist('projs')
    profProjects = prof.getProjects()

#build middle based on if proj exists or not
    if (projNum[0] == 'none'):
        body2 = "I am a " + str(year) + " in the Computer Science department and I am exploring areas of research to do my " + str(type) + ". In this search process, I reviewed academic work in " + str(areasFormatted) + " and want to do research in this field."
        body3 = "Specifically… ******** in this section, discuss something about " + str(areasFormatted) + " that excites you. This could be something that you want to build off of in your own project, or something you hope to work on in the future. Feel free to talk personally about why you might want to work in this area. ********"
    else:
        if int(projNum[0]) >= len(profProjects):
            proj = prof.getTitles()[int(projNum[0]) - len(profProjects)]
        else:
            proj = profProjects[int(projNum[0])][0].strip('. ')

        projFormatted = ""
        for word in proj:
            projFormatted += word

        body2 = "I am a " + str(year) + " in the Computer Science department and I am exploring areas of research to do my " + str(type) + ". In this search process, I reviewed academic work in " + str(areasFormatted) + " and found " + str(projFormatted) + " to be a fascinating project."
        body3 = "Specifically… ******** in this section, discuss something in the paper that excites you. This could be something that you want to build off of in your own project, or something you hope to work on in the future. Feel free to talk personally about why you might want to work in this area. ********"


    subject = "Request for you to be my Advisor"

    mail = "mailto:" + str(prof.getContact()) + "?subject=" + str(subject) + "&body=" + str(body1) + "%0D%0A%0D%0A" + str(body2.replace('&', '%26')) + "%0D%0A%0D%0A" + str(body3) + "%0D%0A%0D%0A" + str(body4) + "%0D%0A%0D%0A" + str(body5) + "%0D%0A%0D%0A" + str(body6)


    html = '<div class="modal-header">'
    html += '<button type="button" class="close" data-dismiss="modal">&times;</button>'
    html += '<h4 class="modal-title">Advisor Email Builder</h4>'
    html += '</div>'
    html += '<input type="hidden" id="profid" value=' + str(profid) + '>'
    html += '<div class="modal-body">'
    html += '<h4>Subject:</h4>'
    html += '<p>' + str(subject) + '</p>'
    html += '<h4>Body:</h4>'
    html += '<p>' + str(body1) + '</p>'
    html += '<p>' + str(body2) + '</p>'
    html += '<p>' + str(body3) + '</p>'
    html += '<p>' + str(body4) + '</p>'
    html += '<p>' + str(body5) + '</p>'
    html += '<p>' + str(body6) + '</p>'
    html += '</div>'
    html += '<div class="modal-footer">'
    html += '<button type="button" class="btn btn-default" style="margin: 2px;" onclick="getBackResponse();">Edit Inputs</button>'
    html += '<a type="button" class="btn btn-primary" href="' + str(mail) + '">Review Email</a>'
    html += '</div>'
    html.encode('utf-8')
    response = make_response(html)

    return(response)
def backResults():
    prof = Professor('', '', '', '', '', '', '', '')

    profid = request.args.get('profid')

    database = Database()
    database.connect()
    prof = database.profSearch(profid)
    database.disconnect()

    html = '<div class="modal-header">'
    html += '<button type="button" class="close" data-dismiss="modal">&times;</button>'
    html += '<h4 class="modal-title">Advisor Email Builder</h4>'
    html += '</div>'
    html += '<div class="modal-body">'
    html += '<p>Enter the information then click generate to build a customized email to Professor ' + str(prof.getName()) + '</p>'
    html += '<form id="emailForm">'
    html += '<input type="hidden" id="profid" value=' + str(profid) + '>'
    html += '<h4>Select Class: </h4>'
    html += '<select name="year" id="year">'
    html += '<option value="Junior">Junior</option>'
    html += '<option value="Senior">Senior</option>'
    html += '</select>'
    html += '<h4>Select Project Type: </h4>'
    html += '<select name="type" id="type">'
    html += '<option value="Independent Work">Independent Work</option>'
    html += '<option value="Thesis">Thesis</option>'
    html += '</select>'
    html += '<h4>Area of Research that interests you most: </h4>'
    html += '<select name="areas" id="areas">'
    areaCount = 0
    for area in prof.getAreas():
        html += '<option value="' + str(areaCount) + '">' + str(area[0].strip('. ')) + '</option>'
        areaCount += 1
    html += '</select>'

    if (prof.getProjects() == 'No projects found.') and (prof.getLinks() == ""):
        html += '<input type="hidden" id="projs" value="none">'
    else:
        html += '<h4>Select the Project or Thesis that Interests you most: </h4>'
        html += '<select name="projs" id="projs" style="width: 500px;">'
        projCount = 0
        if prof.getProjects() != 'No projects found.':
            for proj in prof.getProjects():
                html += '<option value="' + str(projCount) + '">' + str(proj[0].strip('. ')) + '</option>'
                projCount += 1
        if prof.getLinks() != "":
            for title in prof.getTitles():
                html += '<option value="' + str(projCount) + '">' + str(title.strip(',. ')) + '</option>'
                projCount += 1
        html += '</select>'
    html += '</form>'
    html += '</div>'
    html += '<div class="modal-footer">'
    html += '<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>'
    html += '<input type="button" class="btn btn-primary" value="Generate" onclick="getEmailResults();"/>'
    html += '</div>'


    html.encode('utf-8')
    response = make_response(html)

    return(response)