<?php
include ($_SERVER["DOCUMENT_ROOT"] . "/custom/config/dtt2016.var");
include ($adodb_connect);
$abstractID= isset($_GET["abstractID"]) ? $_GET["abstractID"] : "";
$code=$_GET["code"];
$in_database = 0;

if (is_numeric($abstractID)==true) {
	$abstract = $db->Execute("SELECT Abstract_Title, Abstract, Keywords, Speaker, HTML_Title, HTML_Abstract, HTML_Keywords, dynamic_update FROM Abstracts WHERE ID=$abstractID ");
	if ($abstract->RecordCount() != 0) { 
		$in_database=1;
		$abstract_data=$abstract->fields;
		$authors = $db->execute("SELECT ID, Surname, First_Name, Institution, authornr, Department, No_Stars, index2 FROM Persons, rel_abstract_persons WHERE abstractID = $abstractID AND Persons.ID = authorID ORDER BY authornr");
		$author_row = $authors->fields;
	}
	else {
	$errmsg="Sorry, cannot find abstract ". $abstractID . " in database!";
	}
}

if ($in_database==0) {
	$abstract = $db->Execute("SELECT ID, Abstract_Title, Abstract, Keywords, Speaker, HTML_Title, HTML_Abstract, HTML_Keywords, dynamic_update FROM Abstracts WHERE Code='$code' "); 
	if ($abstract->RecordCount() != 0) { 
		$in_database=1;
		$abstract_data=$abstract->fields;
		$abstractID = $abstract_data["ID"];
		$authors = $db->Execute("SELECT ID, Surname, First_Name, Institution, authornr, Department, Country, No_Stars, index2 FROM Persons, rel_abstract_persons WHERE abstractID = $abstractID AND Persons.ID = authorID ORDER BY authornr");
		$author_row=$authors->fields;
	}
	else {
		if ($code != '') {
			$errmsg="Sorry, no abstract is matching the given code!";
		}
	}
}


if ($abstract_data["dynamic_update"] == "no") {
    header("Location: " . $dtturl . "/abstracts/html/". $abstractID . ".html" );
    exit(0);
}
else {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html lang="en">
<head>
<title>Abstract 
<?php
echo htmlentities($author_row["First_Name"]) . " " . htmlentities($author_row["Surname"]) . " (ID: " . $abstractID . ") - ";
echo ($dtt_year);
?>
</title>
<link type="text/css" rel="stylesheet" href="<?php echo $dtt_css ?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php include ($dropdown_head);?>
</head>
<body bgcolor="#f8fbd0">
<?php include($dropdown_body); ?>
 <table align="center" border="0" cellpadding="0" cellspacing="0" width="780">
  <tr>
  <td>
<?php include($dropdown_menu); ?>
<p>&nbsp;</p>

<table cellpadding="0" cellspacing="0" border="0" width="100%" >
<tr>
<td><img src="/dtt_logo.gif" alt="Logo Tropentag" width="100" hspace="10"></td>
<td><h3 align="center">Tropentag, <?php echo date("F j - ",$dtt_day1) . date("j, Y",$dtt_day3) . " in " . $dtt_city;?><br><br>
&quot;<?php echo $dtt_theme_htm; ?>&quot;</h3>
</td>
</tr>
</table>


<hr width="100%">
<?php
if ($in_database == 0) {
    echo "<h3 align = \"center\"><b>" . $errmsg . "</b></h3>";
	echo "<hr width=\"100%\">";
}
else {

    $contact_person_hd = $db->Execute("SELECT Surname, First_Name, LaTeX_Surname, LaTeX_First_Name, Institution, Department, Street, City, ZIP, Country, Email, Street_private, City_private, ZIP_private, Country_private, showAddress FROM Persons p , Abstracts a WHERE a.ID = $abstractID AND a.Contact_Person = p.ID " );
    $contact_person = $contact_person_hd->fields;

    $add_Name = htmlentities($contact_person["First_Name"]) . " " . htmlentities($contact_person["Surname"]);

    $Institution_CA = htmlentities($contact_person["Institution"]);

    $add_Institution = (($Institution_CA == '') ? '' : ( ', ' . $Institution_CA));

    $Department_CA = htmlentities($contact_person["Department"]);
    $add_Department = (($Department_CA == '') ? '' : ( ', ' . $Department_CA));

    $delimiter = (($contact_person["showAddress"] == "private" ) ? "<br>current address: " : ", ") ; 

    $filler = 0;

    $Street_CA = htmlentities( ($contact_person["showAddress"] == "private") ? $contact_person["Street_private"] : $contact_person["Street"] );
    if ($Street_CA == '') {
	$add_Street = "";
    }
    else {
	$add_Street =  $Street_CA;
	$filler = 1;
    }

    $ZIP = ($contact_person["showAddress"] == "private") ? $contact_person["ZIP_private"] : $contact_person["ZIP"] ;
    $City = ($contact_person["showAddress"] == "private") ? $contact_person["City_private"] : $contact_person["City"] ;
    if ($City == '') {
	$add_City = "";
    }
    else {
	$add_City = ( $filler ==1 ? ', ' : '') . $ZIP . (( $ZIP == "") ? '' :'&nbsp;' ) .  htmlentities($City);
	$filler = 1;
    }

    $Country = ($contact_person["showAddress"] == "private") ? $contact_person["Country_private"] : $contact_person["Country"] ;
    if ($Country == '') {
	$add_Country = "";
    }
    else {
	$add_Country = ( $filler ==1 ? ', ' : '') . htmlentities($Country);
	$filler = 1;
    }

    $Email_CA = $contact_person["Email"];

    $add_Email = (($Email_CA == '') ? '' : ( ', e-mail: ' . substr($Email_CA, 0, strpos($Email_CA, "@")) . "<img src=\"" . $at_image . "\" align=\"absbottom\" border=0 alt=\"@\">" . substr($Email_CA, strpos($Email_CA, "@")+1) ));

    $contact_address = $add_Name . $add_Institution . $add_Department . $delimiter . $add_Street  . $add_City . $add_Country. $add_Email ;

	$entries_hd = $db->Execute("SELECT authorID FROM rel_abstract_persons WHERE abstractID = $abstractID AND No_Stars IS NULL");
	$no_entries= $entries_hd->RecordCount();

	$Speaker = $abstract_data["Speaker"];
	if ($abstract_data["HTML_Title"] != "") {
		$Paper_Title = str_replace("\n" ,"<br>" ,$abstract_data["HTML_Title"]);
	}
	else {
		$Paper_Title = str_replace("\n" ,"<br>" ,htmlentities($abstract_data["Abstract_Title"]));
	}
	if ($abstract_data["HTML_Abstract"] != "") {
		$Abstract = str_replace("\n" ,"<br>" , $abstract_data["HTML_Abstract"]);
	}
	else {
		$Abstract = str_replace("\n" ,"<br>" , htmlentities($abstract_data["Abstract"]));
	}
	if ($abstract_data["HTML_Keywords"] != "") {
		$Keywords = $abstract_data["HTML_Keywords"];
	}
	else {
		$Keywords = htmlentities($abstract_data["Keywords"]);
	}
	$number_of_authors = $authors->RecordCount();
?>

<h2 align="center"><?php echo "$Paper_Title";?></h2>

<div align="center">

<?php 
echo ("<h3>");
$authors->MoveFirst();
$stars= 1;
while(!$authors->EOF) {
    $authorrow= $authors->fields;
  if ($authorrow["authornr"] <> 1) {
    echo ", ";
  }

  if (($authorrow["ID"] ==  $Speaker) && ($number_of_authors > 1) )  {
    echo "<u>";
  }

  echo ($authorrow["First_Name"] . " " . $authorrow["Surname"]) ;

  if (($authorrow["ID"] ==  $Speaker) && ($number_of_authors > 1) )  {
    echo "</u>";
  }

if ($no_entries >1) {

  if ($authorrow["No_Stars"] != '' ) {
print "<sup>" . $authorrow["No_Stars"];
  }
  else {
print "<sup>" . $stars;
    $stars++;
  }

  if ($authorrow["index2"] != '' ) {
      print "," . $authorrow["index2"];      
  }

  print "</sup>";

} //von no_entries >1
 $authors->MoveNext();
}
echo ("</h3></div>\n");

echo ("<p>");
$authors->MoveFirst();
$stars=1;
while(!$authors->EOF) {
    $orgarow=$authors->fields;
    if ($orgarow["No_Stars"] == '') {
	if ($no_entries >1) {
	    if ($orgarow["No_Stars"] == '') {
		print "<sup>" . $stars . "</sup>";
	    }
	    else {
		print "<sup>" . $orgarow["No_Stars"] . "</sup>";
	    }
	}
	echo (htmlentities($orgarow["Institution"])); 
	if ($orgarow["Department"] !=  '') {
	    echo(", " . htmlentities($orgarow["Department"])); 
	}
	if ($orgarow["Country"] !=  '') {
	    echo(", " . $orgarow["Country"]); 
	}
	echo ("<br>\n");
	$stars++;
    }
 $authors->MoveNext();
}
 echo ("</p>\n");
 
     ?>

<p ><br>
</p>
<h3 align="center">Abstract</h3>

<hr width="100%">

<p class=justify><?php echo "$Abstract"; ?></p>

<hr width="100%">
<?php
if ($Keywords <> '') {
  echo "<p><strong>Keywords:</strong> ",$Keywords, "</p><hr width=\"100%\">";
}

  echo "<p><strong>Contact Address:</strong> " . $contact_address . "</p><hr width=\"100%\">";

} // von in database
?>

<a href="https://validator.w3.org/check/referer"><img border="0"
src="/custom/w3c/valid-html32.gif"
alt="Valid HTML 3.2!" height="31" width="88"></a>

</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
$db->Close();
include ($dropdown_foot);
?>
</body>
</html>

<?php
}
?>
