<?php 
$tag = isset($_GET["tag"]) ? $_GET["tag"] : '';
if (!isValidTag($tag)) {
    $message = "The tag that was requested (<code>" . htmlentities($tag) . "</code>) is not a valid tag. You can request a new tag.";
    printError($message);
} elseif (!tagExists($tag)) {
    $message = "The tag that was requested (<code>" . $tag . "</code>) does not exist in the Stacks project. You can request a new tag.";
    printError($message);
} else {
    $meta = json_decode(file_get_contents("http://" . $_SERVER["HTTP_HOST"] . href("data/tag/" . $tag . "/meta")));
    if (in_array($meta->type, array("lemma", "proposition", "remark", "remarks", "theorem"))) {
        print "<p>You can suggest a slogan for <a href='" . href("tag/" . $tag) . "'>tag <code>" . $tag . "</code></a> (label: <code style='font-size: .9em'>" . $meta->label . "</code>), located in<br>";
        $id = explode(".", $meta->book_id);
        print "&nbsp&nbsp;Chapter " . $id[0] . ": " . parseAccents($meta->chapter_name) . "<br>";
        print "&nbsp&nbsp;Section " . $id[1] . ": " . parseAccents($meta->section_name);
        printStatement($tag);
        printForm($tag);
        $slogans = getSlogans($tag);
        if (!empty($slogans) or $meta->slogan != "") {
            printSlogans($slogans, $meta->slogan);
        }
    } else {
        $message = "The tag that was requested (<code>" . $tag . "</code>) is of type <code>" . $meta->type . "</code>, but it is impossible to write slogans for tags of this type.";
        printError($message);
    }
}
?>

<script type="text/javascript" src="slogan.js"></script>
<?php 
if (isset($_SESSION["tag"]) && isset($_GET["tag"])) {
				<?php 
$con = getConnection();
if (isset($_GET['compID'])) {
    $selectedCompID = $_GET['compID'];
}
/*creates the table and applies the headings listed below*/
echo "<table border = '1' cellspacing = '5' width = '70%'>";
echo '<tr><th> &nbsp Start Date &nbsp</th>
						  <th> &nbsp Return Date &nbsp </th>
						  <th> &nbsp Cost &nbsp &euro; &nbsp</th>
					 </tr>';
/*Call function to transfer data to table*/
if (isset($_GET['compID'])) {
    /*selects the data from the specified table*/
    $sql = "SELECT Rental.CompanyID, RentalDate, ActualReturnDate, TotalCostOfRental, \r\n\t\t\t\t   Company.CompanyID \r\n\t\t\t\t   From Company INNER JOIN Rental \r\n\t\t\t\t   ON Company.CompanyID = Rental.CompanyID \r\n\t\t\t\t   WHERE Rental.DeleteFlag = '0'\r\n\t\t\t\t   AND Rental.CompanyID = '{$selectedCompID}'";
    printStatement($con, $sql);
}
function printStatement($con, $sql)
{
    $result = mysqli_query($con, $sql);
    if (!$result) {
        die("An Error in the SQL Query: " . mysql_error());
    }
    while ($row = mysqli_fetch_array($result)) {
        echo "<tr>\r\n\t\t\t\t\t\t  <td>" . $row['RentalDate'] . "</td>\r\n\t\t\t\t\t\t  <td>" . $row['ActualReturnDate'] . "</td>\r\n\t\t\t\t\t\t  <td>" . $row['TotalCostOfRental'] . "</td>\r\n\t\t\t\t\t\t  </tr>";
    }
    echo "</table>";
}
mysqli_close($con);
?>
			</div>