<?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"]));
		$hdl = urlencode(stripslashes($_POST['add_hdl']));
		$ldl = urlencode(stripslashes($_POST['add_ldl']));
		$measuredby = urlencode(stripslashes($_POST['add_measured_by']));
		$readingdate = urlencode(stripslashes($_POST['add_date']));
		$triglycerides = urlencode(stripslashes($_POST['add_triglycerides']));
		$totalchol = urlencode(stripslashes($_POST['add_total_cholesterol']));
				
		$params = "id=".$id;
		$params .= "&pin=" . $pin;
		$params .= "&hdl=".$hdl;
		$params .= "&ldl=".$ldl;
		$params .= "&measuredby=".$measuredby;
		$params .= "&readingdate=".$readingdate;
		$params .= "&triglycerides=".$triglycerides;
		$params .= "&totalchol=".$totalchol;

		$results = new xml("amjayaddchol", $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_cholesterol_url());
	} elseif ($_GET['mode'] == 'edit') {
		$template = new cholesterol_page("template_cholesterol.html", $_GET['rowid']);
		$template->show();
	} elseif ($_GET['mode'] == 'update') {
		$id = urlencode(stripslashes($_SESSION["user_id"]));
		$pin = urlencode(stripslashes($_SESSION["pin"]));
		$hdl = urlencode(stripslashes($_POST['edit_hdl']));
		$ldl = urlencode(stripslashes($_POST['edit_ldl']));
		$measuredby = urlencode(stripslashes($_POST['edit_measured_by']));
		$readingdate = urlencode(stripslashes($_POST['edit_date']));
		$triglycerides = urlencode(stripslashes($_POST['edit_triglycerides']));
		$totalchol = urlencode(stripslashes($_POST['edit_total_cholesterol']));
		$cholid = urlencode(stripslashes($_GET['rowid']));
				
		$params = "id=".$id;
		$params .= "&pin=" . $pin;
		$params .= "&hdl=".$hdl;
		$params .= "&ldl=".$ldl;
		$params .= "&measuredby=".$measuredby;
		$params .= "&readingdate=".$readingdate;
		$params .= "&triglycerides=".$triglycerides;
		$params .= "&totalchol=".$totalchol;
		$params .= "&cholid=".$cholid;
		
		$results = new xml("amjayeditchol", $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_cholesterol_url());
	} elseif ($_GET['mode'] == 'del') {
		$id = urlencode(stripslashes($_SESSION["user_id"]));
		$pin = urlencode(stripslashes($_SESSION["pin"]));
		$cholid = urlencode(stripslashes($_GET['rowid']));

		$params = "id=".$id;
		$params .= "&pin=" . $pin;
		$params .= "&cholid=".$cholid;
		
		$results = new xml("amjaydelchol", $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_cholesterol_url());
	} else {
		$template = new cholesterol_page("template_cholesterol.html");
		$template->show();
	}
} else {
	$template = new template();
	$template->go302(format_login_url(format_cholesterol_url()));
}

?>