<?php

/*
	This php file acts as an intermediary for anyone to download the agenda files.
	It also allows us to send back a recommended filename for the pdf to the browser.
*/
require_once "./database.php";
//get the id provided as a get parameter
$agenda = Database::getMostRecentAgenda();
if (!isset($agenda['id'])) {
    header("Location: ../index.html?error=download");
    exit;
}
$id = $agenda['id'];
//if the result from getAgendaFromID is false then the id is invalid
$fileName = "./uploads/Agenda{$id}.pdf";
if (!file_exists($fileName)) {
    header("Location: ../index.html?error=download");
    exit;
}
//tell browser to expect pdf file as response
header("Content-type:application/pdf");
//Set the timezone to Phoenix to stop warnings from timezone not being set...
date_default_timezone_set('America/Phoenix');
//get the date that the file was created and turn it into unix time
$phpdate = strtotime($agenda['uploadDate']);
//turn the unix time into a date for filename
$mysqldate = date('m_d_Y', $phpdate);
//tell the browser that the filename to download the file as is Agenda_ followed by date the agenda was added to database
header("Content-Disposition:attachment;filename='Agenda{$mysqldate}.pdf'");
//output the files contents to the browser, allowing user to download file
Example #2
0
<?php

/*
	JSON/AJAX Handler
*/
require_once "./database.php";
require_once "./session.php";
//returns the most recent agenda if agenda=first or all archived agendas if agenda=archived
//each agenda returned has a download attribute that contains the link for downloading the pdf for that agenda
if (isset($_GET['agenda'])) {
    if ($_GET['agenda'] === "first") {
        echo json_encode(Database::withDownloadLinks(array(Database::getMostRecentAgenda())));
    } else {
        if ($_GET['agenda'] === "archived") {
            echo json_encode(Database::withDownloadLinks(Database::getAgendas(1)));
        }
    }
} else {
    if (isset($_GET['roster'])) {
        if ($_GET['roster'] === "all") {
            echo json_encode(Database::getEntireRoster());
        } else {
            echo json_encode(Database::getRosterFromID($_GET['roster']));
        }
    } else {
        if (isset($_GET['blog'])) {
            $response = $_GET['blog'];
            if ($response === "first") {
                $data = array(Database::getMostRecentPost());
                $data = Database::convertDateOfBlogPosts($data);
                echo json_encode($data);