<?php

include_once("config.php");

if (isset($_SESSION["user_id"]) && isset($_SESSION["pin"])) { //LOG IN!
	if ($_GET['mode'] == 'add') {
		$id = urlencode(stripslashes($_SESSION["user_id"]));
		$pin = urlencode(stripslashes($_SESSION["pin"]));
		$vaccine = urlencode(stripslashes($_POST['add_vaccine']));
		$givenby = urlencode(stripslashes($_POST['add_given_by']));
		$vaccinedate = urlencode(stripslashes($_POST['add_date']));
		
				
		$params = "id=".$id;
		$params .= "&pin=" . $pin;
		$params .= "&vaccine=".$vaccine;
		$params .= "&givenby=".$givenby;
		$params .= "&vaccinedate=".$vaccinedate;
		

		$results = new xml("amjayaddvc", $params, true);
		if (isset($results->error)) {
			$_SESSION['Err'] = $results->error[0]->row[0]->row[0]->error;
			$template = new template();
		} else {
			$template = new template();
		}
		$template->go302(format_vaccination_url());
	} elseif ($_GET['mode'] == 'edit') {
		$template = new vaccination_page("template_vaccination.html", $_GET['rowid']);
		$template->show();
	} elseif ($_GET['mode'] == 'update') {
		$id = urlencode(stripslashes($_SESSION["user_id"]));
		$pin = urlencode(stripslashes($_SESSION["pin"]));
		$vaccine = urlencode(stripslashes($_POST['edit_vaccine']));
		$givenby = urlencode(stripslashes($_POST['edit_given_by']));
		$vaccinedate = urlencode(stripslashes($_POST['edit_vaccinedate']));
		$vcid = urlencode(stripslashes($_GET['rowid']));
				
		$params = "id=".$id;
		$params .= "&pin=" . $pin;
		$params .= "&vaccine=".$vaccine;
		$params .= "&givenby=".$givenby;
		$params .= "&vaccinedate=".$vaccinedate;
		$params .= "&vcid=".$vcid;
		
		$results = new xml("amjayeditvc", $params, true);
		if (isset($results->error)) {
			$_SESSION['Err'] = $results->error[0]->row[0]->row[0]->error;
			$template = new template();
		} else {
			$template = new template();
		}
		$template->go302(format_vaccination_url());
	} elseif ($_GET['mode'] == 'del') {
		$id = urlencode(stripslashes($_SESSION["user_id"]));
		$pin = urlencode(stripslashes($_SESSION["pin"]));
		$vcid = urlencode(stripslashes($_GET['rowid']));

		$params = "id=".$id;
		$params .= "&pin=" . $pin;
		$params .= "&vcid=".$vcid;
		
		$results = new xml("amjaydelvc", $params, true);
		if (isset($results->error)) {
			$_SESSION['Err'] = $results->error[0]->row[0]->row[0]->error;
			$template = new template();
		} else {
			$template = new template();
		}
		$template->go302(format_vaccination_url());
	} else {
		$template = new vaccination_page("template_vaccination.html");
		$template->show();
	}
} else {
	$template = new template();
	$template->go302(format_login_url(format_vaccination_url()));
}

?>