summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--all.php443
-rw-r--r--smarty/templates/rpmphp/all.tpl104
2 files changed, 308 insertions, 239 deletions
diff --git a/all.php b/all.php
index 2b32a5b..32596d3 100644
--- a/all.php
+++ b/all.php
@@ -1,248 +1,213 @@
<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Package in Fedora repositories
+ *
+ * PHP version 5
+ *
+ * Copyright © 2010 Remi Collet
+ *
+ * This file is part of rpmphp.
+ *
+ * rpmphp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * rpmphp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with rpmphp. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Main
+ * @package RPMPHP
+ *
+ * @author Remi Collet <unknown@unknwown.com>
+ * @author Johan Cwiklinski <johan@x-tnd.be>
+ * @copyright 2010 Remi Collet
+ * @license http://www.gnu.org/licenses/agpl-3.0-standalone.html AGPL License 3.0 or (at your option) any later version
+ * @link http://github.com/remicollet/rpmphp/
+ * @since The begining of times.
+*/
+require 'main.inc.php';
$what=(isset($_GET["what"]) ? $_GET["what"] : false);
-require "config.inc.php";
-
-function listRepos($db){
- $repos = array();
- $res=$db->query("SELECT * FROM repo WHERE active=1 ORDER BY ID");
- if ($res) while ($repo = $res->fetchObject()) {
- $repos[$repo->main][$repo->sub]=$repo;
- }
- // echo "<pre>"; print_r($repos);echo "</pre>";
- foreach($repos as $repomain) {
- foreach ($repomain as $repo) {
- /*printf ("<th align='left'>%s</th>", $repo->main);*/
- $repos[$repo->main][$repo->sub] = $repo;
- break;
- }
- }
- return $repos;
+$ariane[] = array(
+ 'url' => '#',
+ 'text' => 'Packages in Fedora repositories'
+);
+$smarty->assign('ariane', $ariane);
+
+$smarty->assign('what', $what);
+$smarty->assign('page_title', 'All packages in Fedora repositories');
+
+/**
+* Retrieve packages informations
+*
+* @param Object $db A reference to the database
+*
+* @return array
+*/
+function report ($db)
+{
+ global $what, $smarty;
+ $packages = null;
+ $repos = listRepos($db);
+ $smarty->assign('repos', $repos);
+
+
+ if (substr($what,0,1)=='%') {
+ $sql=sprintf("SELECT DISTINCT name FROM rpm WHERE SUBSTRING(name,1,1)='%s' ORDER BY name", substr($what,1,1));
+ } else {
+ $sql=sprintf("SELECT DISTINCT name FROM acls WHERE owner='%s' ORDER BY name", $what);
+ }
+ //echo "<p>SQL=$sql</p>";
+
+ $i=0;
+ $res=$db->query($sql);
+ if ($res) {
+ while ($desc = $res->fetchObject()) {
+ $package = null;
+ $rpmname = $desc->name;
+
+ $sql2="SELECT DISTINCT owner FROM acls WHERE name LIKE '$rpmname'";
+ $res2=$db->query($sql2);
+ $dispowner="";
+ $owners=array();
+ if ( $res2 ) {
+ while ($owner= $res2->fetchObject()) {
+ $owners[] = $owner->owner;
+ }
+ }
+
+ $sql3 = "SELECT * FROM rpm WHERE name LIKE '$rpmname'";
+ $res3=$db->query($sql3);
+ $rpm = ($res3 ? $res3->fetchObject() : false);
+
+ if ($rpm) {
+ $url = $rpm->url;
+ $des = htmlentities($rpm->summary);
+
+ $rpms=array();
+ do {
+ $rpms[$rpm->repo_main."-".$rpm->repo_sub]=$rpm;
+ } while ($rpm = $res3->fetchObject());
+
+ $package['name'] = $rpmname;
+ $package['description'] = $des;
+ $package['owners'] = $owners;
+
+ $versions = null;
+ foreach($repos as $repomain) {
+ $display="";
+ $class="";
+ foreach ($repomain as $repo) {
+ if (isset($rpms[$repo->main."-".$repo->sub])) {
+ $rpm=$rpms[$repo->main."-".$repo->sub];
+
+ $maxver = (isset($rpms["rawhide-"]) ? $rpms["rawhide-"]->ver : "");
+
+ switch ($repo->sub) {
+ case "base":
+ if (isset($rpms[$repo->main."-updates"])) {
+ $display .= sprintf(
+ "%s-%s<br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ } else {
+ $display .= sprintf(
+ "<strong>%s</strong>-%s<br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ $class = ($rpm->ver == $maxver ? "check" : "attn");
+ }
+ break;
+ case "":
+ $display .= sprintf(
+ "<strong>%s</strong>-%s<br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ break;
+ case "updates":
+ $display .= sprintf(
+ "<strong>%s</strong>-%s <small>(updates)</small><br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ $class = ($rpm->ver == $maxver ? "check" : "attn");
+ break;
+ case "testing":
+ $display .= sprintf(
+ "%s-%s <small>(testing)</small><br/>",
+ $rpm->ver,
+ $rpm->rel
+ );
+ $class = ($rpm->ver == $maxver ? "info" : "attn");
+ break;
+ }
+ } // RPM exists
+ } // sub repo
+
+ $versions[] = array(
+ 'class' => ($class && $maxver) ? $class : '',
+ 'display' => $display
+ );
+ $package['versions'] = $versions;
+ } // mainrepo
+
+ $i++;
+ $packages[] = $package;
+ }
+ } // each Line
+ }
+ return $packages;
}
-function Report ($db, $repos) {
- global $what;
-
- /*$repos=array();
- $res=$db->query("SELECT * FROM repo WHERE active=1 ORDER BY ID");
- if ($res) while ($repo = $res->fetchObject()) {
- $repos[$repo->main][$repo->sub]=$repo;
- }*/
-
- if (substr($what,0,1)=='%') {
- $sql=sprintf("SELECT DISTINCT name FROM rpm WHERE SUBSTRING(name,1,1)='%s' ORDER BY name", substr($what,1,1));
- } else {
- $sql=sprintf("SELECT DISTINCT name FROM acls WHERE owner='%s' ORDER BY name", $what);
- }
- //echo "<p>SQL=$sql</p>";
-
- /*echo "<table id='fedora-list-packages'>\n";
- echo "<tr class='odd'><th>Package</th><th>Owner(s)</th>";
-
- foreach($repos as $repomain) {
- foreach ($repomain as $repo) {
- printf ("<th align='left'>%s</th>", $repo->main);
- break;
- }
- }
- echo "</tr>\n";*/
-
- $i=0;
- $res=$db->query($sql);
- if ($res) while ($desc = $res->fetchObject()) {
- $rpmname = $desc->name;
-
- $sql2="SELECT DISTINCT owner FROM acls WHERE name LIKE '$rpmname'";
- $res2=$db->query($sql2);
- $dispowner="";
- if ($res2) while ($owner= $res2->fetchObject()) {
- if ($dispowner) $dispowner .= "<br/>";
- $dispowner .= sprintf ("<a href=\"%s?what=%s\">%s</a>", $_SERVER["PHP_SELF"], $owner->owner, $owner->owner);
- }
-
- $sql3 = "SELECT * FROM rpm WHERE name LIKE '$rpmname'";
- $res3=$db->query($sql3);
- $rpm = ($res3 ? $res3->fetchObject() : false);
-
- if ($rpm) {
- $url = $rpm->url;
- $des = htmlentities($rpm->summary);
-
- $rpms=array();
- do {
- $rpms[$rpm->repo_main."-".$rpm->repo_sub]=$rpm;
- } while ($rpm = $res3->fetchObject());
-
- printf ("<tr class=\"%s\">\n\t<td><a href=\"zoom.php?rpm=%s\" title=\"%s\">%s</a></td>\n\t<td>%s</td>\n",
- ($i%2 ? "odd" : "even"), $rpmname, $des, $rpmname, $dispowner);
-
-
- foreach($repos as $repomain) {
- $display="";
- $class="";
- foreach ($repomain as $repo) {
- if (isset($rpms[$repo->main."-".$repo->sub])) {
- $rpm=$rpms[$repo->main."-".$repo->sub];
-
- $maxver = (isset($rpms["rawhide-"]) ? $rpms["rawhide-"]->ver : "");
-
- switch ($repo->sub) {
- case "base":
- if (isset($rpms[$repo->main."-updates"])) {
- $display .= sprintf("%s-%s<br/>", $rpm->ver, $rpm->rel);
- } else {
- $display .= sprintf("<strong>%s</strong>-%s<br/>", $rpm->ver, $rpm->rel);
- $class = ($rpm->ver == $maxver ? "check" : "attn");
- }
- break;
- case "":
- $display .= sprintf("<strong>%s</strong>-%s<br/>", $rpm->ver, $rpm->rel);
- break;
- case "updates":
- $display .= sprintf("<strong>%s</strong>-%s <small>(updates)</small><br/>", $rpm->ver, $rpm->rel);
- $class = ($rpm->ver == $maxver ? "check" : "attn");
- break;
- case "testing":
- $display .= sprintf("%s-%s <small>(testing)</small><br/>", $rpm->ver, $rpm->rel);
- $class = ($rpm->ver == $maxver ? "info" : "attn");
- break;
- }
- } // RPM exists
- } // sub repo
-
- if ($class && $maxver) {
- printf("\t<td class=\"%s\">%s</td>\n", $class, $display);
- } else if ($display) {
- printf("\t<td>%s</td>\n", $display);
- } else {
- echo "\t<td>&nbsp;</td>\n";
- }
- } // mainrepo
-
- echo "</tr>\n";
- $i++;
- }
- } // each Line
-}
-?>
-<!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="#">All packages</a></li>
- </ul>
- </div>
- <div id="filter">
- <form action='<?php echo $_SERVER["PHP_SELF"]; ?>' method='get'>
- <fieldset>
- <legend>Filter packages</legend>
- <label for="what">Criteria: </label>
- <select name="what" id="what">
- <optgroup label="Pakages">
-<?php
try {
- $db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS);
-
- $sql="SELECT DISTINCT CONCAT('%',SUBSTRING(name,1,1)) as init FROM rpm ORDER BY init";
- $res=$db->query($sql);
- if ($res)while ($start = $res->fetchObject()) {
- printf("\t\t\t\t\t\t\t\t\t<option value=\"%s\" %s>Start with %s</option>\n", $start->init, ($what==$start->init ? " selected=\"selected\"" : ""), substr($start->init,1));
- } else {
- echo "\t\t\t\t\t\t\t\t\t<option value=\"remi\">remi</option>\n";
- }
-?>
- </optgroup>
- <optgroup label="Owner">
-<?php
- $sql="SELECT DISTINCT owner FROM acls ORDER BY owner";
- $res=$db->query($sql);
- if ($res)while ($owner = $res->fetchObject()) {
- printf("\t\t\t\t\t\t\t\t\t<option value=\"%s\" %s>%s</option>\n", $owner->owner, ($what==$owner->owner ? " selected=\"selected\"" : ""), $owner->owner);
- } else {
- echo "\t\t\t\t\t\t\t\t\t<option value=\"remi\">remi</option>\n";
- }
-?>
- </optgroup>
- </select>
- <input type="submit" value="Filter" />
- </fieldset>
- </form>
- </div>
-<?php
- $sql='SELECT MAX(stamp) AS stamp FROM repo';
- $res=$db->query($sql);
- if ($res && $row=$res->fetchObject()) {
- printf("<p>Repositories last updated %s.</p>", date("r", $row->stamp));
- }
-
-?>
- <h1>Packages in Fedora</h1>
- <table id="list-packages">
- <thead>
- <tr>
- <th>Package</th>
- <th>Owner(s)</th>
-<?php
- $repos = listRepos($db);
- $repos_k = array_keys($repos);
- foreach ( $repos_k as $r ) {
-?>
- <th><?php echo $r; ?></th>
-<?php
- }
-?>
-
- </tr>
- </thead>
- <tbody>
-<?php
- if ($what) Report($db, $repos);
- else echo "<tr><td colspan=\"" . (count($repos) + 3) . "\"><h2>Choose a criteria from the filter menu</h2></td></tr>";
- //echo "<pre>"; print_r($rpms); echo "</pre>";
+ $db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS);
+
+ $sql="SELECT DISTINCT CONCAT('%',SUBSTRING(name,1,1)) as init FROM rpm ORDER BY init";
+ $res=$db->query($sql);
+ if ( $res ) {
+ while ( $s = $res->fetchObject() ) {
+ $starts_with[] = $s;
+ }
+ $smarty->assign('starts_with', $starts_with);
+ }
+
+ $sql="SELECT DISTINCT owner FROM acls ORDER BY owner";
+ $res=$db->query($sql);
+ if ( $res ) {
+ while ( $owner = $res->fetchObject() ) {
+ $owners[] = $owner;
+ }
+ $smarty->assign('owners', $owners);
+ }
+
+ $sql='SELECT MAX(stamp) AS stamp FROM repo';
+ $res=$db->query($sql);
+ if ($res && $row=$res->fetchObject()) {
+ $smarty->assign('repositories_update', date("r", $row->stamp));
+ }
+
+ $smarty->assign('packages', report($db));
} catch(PDOException $e) {
-?>
- <tr>
- <td colspan="<?php echo count($repos_k) + 3; ?>">
-<?php
- printf("%s ERREUR : %s\n", date("r"), $e->getMessage());
-?>
- </td>
- </tr>
-<?php
+ $smarty->assign(
+ 'error',
+ sprintf("%s ERREUR : %s\n", date("r"), $e->getMessage())
+ );
}
-?>
- </tbody>
- </table>
- <ul id="legend">
- <li>Legend: </li>
- <li><strong>Upstream</strong>: bold if stable. </li>
- <li><strong>Repo</strong>: bold for latest release.</li>
- <li class='check'>Lastest released (stable if exists)</li>
- <li class='info'>Lastest in testing</li>
- <li class='attn'>Lastest not available</li>
- </ul>
- </div><!-- /fedora-content -->
-<?php
-include '_footer.php';
-?>
- </div>
- </body>
-</html>
+$page_content = $smarty->fetch('all.tpl');
+$smarty->assign('page_content', $page_content);
+$smarty->display('main.tpl');
+
+?> \ No newline at end of file
diff --git a/smarty/templates/rpmphp/all.tpl b/smarty/templates/rpmphp/all.tpl
new file mode 100644
index 0000000..8d9c20a
--- /dev/null
+++ b/smarty/templates/rpmphp/all.tpl
@@ -0,0 +1,104 @@
+{*
+ * All page template
+ *
+ * Copyright © 2010 Remi Collet
+ *
+ * This file is part of rpmphp.
+ *
+ * rpmphp is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * rpmphp is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with rpmphp. If not, see <http://www.gnu.org/licenses/>.
+*}
+ <p id="repositories_update">Repositories last updated {$repositories_update}.</p>
+ <div id="filter">
+ <form action="all.php" method="get">
+ <fieldset>
+ <legend>Filter {$type|upper} packages</legend>
+ <label for="what">Criteria: </label>
+ <select name="what" id="what">
+ <optgroup label="Pakages">
+{foreach from=$starts_with item=s}
+ <option value="{$s->init}"{if $what eq $s->init} selected="selected"{/if}>Start with {$s->init|substr:1:2}</option>
+{foreachelse}
+ <option value="remi">remi</option>
+{/foreach}
+ </optgroup>
+ <optgroup label="Owner">
+{foreach from=$owners item=o}
+ <option value="{$o->owner}"{if $what eq $o->owner} selected="selected"{/if}>{$o->owner}</option>
+{foreachelse}
+ <option value="remi">remi</option>
+{/foreach}
+ </optgroup>
+ </select>
+ <input type="submit" value="Filter" />
+ </fieldset>
+ </form>
+ </div><!-- /filter -->
+
+{if $error}
+ <p id="error"><strong>Ooops, an error occured:</strong><br/>{$error}</p>
+{/if}
+
+ <table id="list-packages">
+ <thead>
+ <tr>
+ <th>Package</th>
+ <th>Owner(s)</th>
+{foreach from=$repos key=k item=v}
+ <th>{$k}</th>
+{/foreach}
+ </tr>
+ </thead>
+ <tfoot>
+ <tr>
+ <td colspan="{math equation="x+2" x=$repos|@count}">{$packages|@count} packages found</td>
+ </tr>
+ </tfoot>
+ <tbody>
+{foreach from=$packages item=p name=plist}
+ <tr class="{if $smarty.foreach.plist.iteration % 2 eq 0}even{else}odd{/if}">
+ <td>
+ <a href="zoom.php?rpm={$p.name}" title="{$p.description}">{$p.name}</a>
+ </td>
+ <td>
+ {foreach from=$p.owners item=owner name=ow_it}
+ <a href="?what={$owner}">{$owner}</a>
+ {if not $smarty.foreach.ow_it.last}
+ <br/>
+ {/if}
+ {/foreach}
+ </td>
+ {foreach from=$p.versions key=k item=version}
+ <td{if $version.class} class="{$version.class}"{/if}>
+ {$version.display}
+ </td>
+ {/foreach}
+ </tr>
+{foreachelse}
+ <tr>
+ <td colspan="{math equation="x+2" x=$repos|@count}">
+ <h2>Choose a criteria from the filter menu</h2>
+ </td>
+ </tr>
+{/foreach}
+ </tbody>
+ </table>
+
+ <ul id="legend">
+ <li>Legend: </li>
+ <li><strong>Upstream</strong>: bold if stable. </li>
+ <li><strong>Repo</strong>: bold for latest release.</li>
+ <li class='check'>Lastest released (stable if exists)</li>
+ <li class='info'>Lastest in testing</li>
+ <li class='attn'>Lastest not available</li>
+ </ul>