$pageTitle="Visualizations :: Timelines :: Manage Timelines";
include($_SERVER['DOCUMENT_ROOT'] . "/template/header.php");
echo "
\n";
$errorArray=array();
//take a year, month, and day and format a date for DISPLAY purposes
function format_display_date($y, $m, $d){
//if the month and day are both 1 then we ONLY show the year
if($m==1 && $d==1) return "$y";
//if the month is other than 1 and the day is one we dispay the month as well
if($m>1 && $d==1) return date("M", mktime(0, 0, 0, $m, 1, 2005)) . " " .$y;
//if the day is other than 1 we show the full date
if($d>1) return date("M", mktime(0, 0, 0, $m, 1, 2005)) . " $d, $y";
return false;
}
//let's see if they submitted any values and if so, we validate and process them
if( isset($_GET['type']) && isset($_GET['id']) ){
$type = sanitize($_GET['type']);
$id = sanitize($_GET['id']);
//they submitted data so let's check it
if( ($type=="event" || $type=="people" || $type=="citation") && ( is_numeric($id) && $id>=1 ) ){
//variables appear valid, we can go ahead and try to pull that object up
if($type=="event"){
//let's try to show the event
$mysqlSearchQuery="SELECT id, title, description, span, YEAR(start), MONTH(start), DAY(start), YEAR(end), MONTH(end), DAY(end) FROM TimelineEvents WHERE id=$id LIMIT 1";
$result=database_query($mysqlSearchQuery);
if($result && mysql_num_rows($result)==1){
//display event
$myrow=mysql_fetch_row($result);
echo "$myrow[1]
\n\n";
//print start date
echo format_display_date($myrow[4], $myrow[5], $myrow[6]);
if($myrow[3]==1){
//we are showing a span
echo " to ";
echo format_display_date($myrow[7], $myrow[8], $myrow[9]);
}
echo "\n
\n" . nl2p(convertURLs($myrow[2], "_blank")) . "
\n";
}
else{
$errorArray[]="missingEvent";
}
}
elseif($type=="people"){
//let's try to show the person
$mysqlSearchQuery="SELECT id, name, description, span, YEAR(start), MONTH(start), DAY(start), YEAR(end), MONTH(end), DAY(end) FROM TimelinePeople WHERE id=$id LIMIT 1";
$result=database_query($mysqlSearchQuery);
if($result && mysql_num_rows($result)==1){
//display person
$myrow=mysql_fetch_row($result);
echo "$myrow[1]
\n\n";
//print start date
echo format_display_date($myrow[4], $myrow[5], $myrow[6]);
echo " to ";
if($myrow[3]==1){
//the person is dead
echo format_display_date($myrow[7], $myrow[8], $myrow[9]);
}
else{
//the person is still alive
echo "Present";
}
echo "\n
\n" . nl2p(convertURLs($myrow[2], "_blank")) . "
\n";
}
else{
$errorArray[]="missingPeople";
}
}
elseif($type=="citation"){
//let's try to show the citation
$mysqlSearchQuery="SELECT id, citation, description, YEAR(date), MONTH(date), DAY(date) FROM Citations WHERE date != '0000-00-00 00:00:00' AND id=$id LIMIT 1";
$result=database_query($mysqlSearchQuery);
if($result && mysql_num_rows($result)==1){
//display citation
$myrow=mysql_fetch_row($result);
echo "$myrow[1]
\n\n";
//print date and description
echo "(" . format_display_date($myrow[3], $myrow[4], $myrow[5]) . ") " . $myrow[2];
echo "\n
\n" . nl2p(convertURLs($myrow[2], "_blank")) . "
\n";
}
else{
$errorArray[]="missingCitation";
}
}
else{
//error - something is wrong with the type value
$errorArray[]="invalidType";
}
}
else{
//variables invalid
$errorArray[]="invalidData";
}
}
else{
//they didn't submit anything
$errorArray[]="noData";
}
//if there were errors we need to display messages
if(count($errorArray)>=1){
echo "\n";
echo "
\n";
foreach($errorArray as $e){
if($e=="noData"){
echo "- No data was submitted. Click on timeline items to use this page.
\n";
}
elseif($e=="invalidData"){
echo "- Either the object type or id is invalid. Please go back and try again.
\n";
}
elseif($e=="invalidType"){
echo "- The object type is invalid. Please go back and try again.
\n";
}
elseif($e=="missingEvent"){
echo "- The event you requested could not be found in the database. Please go back and try again.
\n";
}
elseif($e=="missingPeople"){
echo "- The person you requested could not be found in the database. Please go back and try again.
\n";
}
elseif($e=="missingCitation"){
echo "- The citation you requested could not be found in the database. Please go back and try again.
\n";
}
else{
echo "- An error occured. We apologize. Please try again in a few moments.
\n";
}
}
echo "
\n
\n";
}
?>
include($_SERVER['DOCUMENT_ROOT'] . "/template/footer.php"); ?>