<?php

require "config.inc.php";
if (!isset($_GET['rpm'])) {
   die("missing arg.");
}
$name = $_GET['rpm'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<title>Packages in Fedora</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
                <link rel="stylesheet" type="text/css" media="screen" href="css/rpmphp.css"/>
		<!--<link rel="stylesheet" type="text/css" media="print" href="css/rpmphp-print.css">-->
		<link rel="shortcut icon" href="images/favicon.ico"/>
		<link rel="icon" href="images/favicon.ico"/>
	</head>

	<body>
		<div id="wrapper">
<?php
include '_header.php';
?>
			<div id="fedora-content">
				<div id="ariane">
					<p>You are here: </p>
					<ul>
						<li><a href="./">Reports home</a></li>
						<li><a href="#">Package detail</a></li>
					</ul>
				</div>
<?php
if (!$name) {
   echo "<h1>Enter a package name</h1>\n";
} else {
   try {
      $db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS);

      $sql = "SELECT rpm.*
         FROM rpm
         INNER JOIN repo ON (repo.main=rpm.repo_main AND repo.sub=rpm.repo_sub)
         WHERE rpm.name='$name'
         ORDER BY repo.id DESC";
      $resrpm = $db->query($sql);
      $rpm = ($resrpm ? $resrpm->fetchObject() : false);

      $sql = "SELECT * FROM upstream WHERE name = '$name'";
      $resup=$db->query($sql);
      $up = ($resup ? $resup->fetchObject() : false);

      $sql = "SELECT * FROM acls WHERE name = '$name'";
      $resown=$db->query($sql);
      $owner = ($resown ? $resown->fetchObject() : false);

      if (!$rpm) {
         echo "<h1>$name not found</h1>\n";
      } else {
         echo "<h1>Package: $name</h1>\n";
         echo "<table id=\"upstream\">\n";
         echo "<caption>Upstream info</caption>\n";
         $i=0;

         if ($rpm->summary) {
            echo "<tr class='".($i%2 ? 'odd' : 'even')."'><th>"; $i++;
            echo "Summary: </th><td><strong>". $rpm->summary . "</strong></td></tr>\n";
         } else if ($owner->summary) {
            echo "<tr class='".($i%2 ? 'odd' : 'even')."'><th>"; $i++;
            echo "Summary: </th><td><strong>". $owner->summary . "</strong></td></tr>\n";
         }
         if ($rpm->url) {
            echo "<tr class='".($i%2 ? 'odd' : 'even')."'><th>"; $i++;
            echo "URL: </th><td><strong><a href='".$rpm->url."'>". $rpm->url . "</a></strong></td></tr>\n";
         }
         if ($up && $up->type) {
            echo "<tr class='".($i%2 ? 'odd' : 'even')."'><th>"; $i++;
            echo "Type: </th><td><strong>". $up->type . "</strong></td></tr>\n";
         }
         if ($up && $up->channel) {
            echo "<tr class='".($i%2 ? 'odd' : 'even')."'><th>"; $i++;
            echo "Channel: </th><td><strong>". $up->channel . "</strong></td></tr>\n";
         }
         if ($up && $up->stable) {
            echo "<tr class='".($i%2 ? 'odd' : 'even')."'><th>"; $i++;
            echo "Stable version: </th><td><strong>". $up->stable . "</strong></td></tr>\n";
         }
         if ($up && $up->unstable && $up->stable!=$up->unstable) {
            echo "<tr class='".($i%2 ? 'odd' : 'even')."'><th>"; $i++;
            echo "Unstable version: </th><td><strong>". $up->unstable . "</strong>";
            if ($up->state) {
               echo " (". $up->state . ")\n";
            }
            echo "</td></tr>\n";
         }
         if ($owner && $owner->owner) {
            echo "<tr class=\"".($i%2 ? 'odd' : 'even')."\"><th>"; $i++;
            echo "Owner: </th><td><strong>". $owner->owner . "</strong>";
            if ($owner->cc) {
               echo " (". $owner->cc . ")\n";
            }
            echo "</td></tr>\n";
         }
         echo "<tr class=\"".($i%2 ? 'odd' : 'even')."\"><th>ViewVC: </th>"; $i++;
         echo "<td><a href=\"http://cvs.fedoraproject.org/viewvc/rpms/$name/\">http://cvs.fedoraproject.org/viewvc/rpms/$name/</a>";
         echo "</td></tr>\n";

         echo "</table>";

         echo "<table id=\"list-packages\">\n";
         echo "<caption>Packages available in Fedora Repositories</caption>\n";
         $prev=false;
         do {
            echo "<tr class='".($i%2 ? 'odd' : 'even')."'>"; $i++;
            echo "<td><strong>".($rpm->repo_main==$prev ? "&nbsp;" : $prev=$rpm->repo_main)."</strong></td>";
            echo "<td>".$rpm->repo_sub."</td>";
            echo "<td>".($rpm->epoch ? $rpm->epoch.":" : "").$rpm->ver."-".$rpm->rel."</td>";
            echo "</tr>\n";
         } while ($rpm = $resrpm->fetchObject());
         echo "</table>";
      }
   }
   catch(PDOException $e) {
      printf("%s ERREUR : %s\n", date("r"),  $e->getMessage());
   }
}
?>


        <!-- document END -->
        </div>

		<!-- content END -->
<?php
include '_footer.php';
?>
		</div>
	</body>
</html>