From 4fe73c547050003599021850f0c6099f7c224f07 Mon Sep 17 00:00:00 2001 From: "Johan \"Papa\" Cwiklinski" Date: Sun, 30 May 2010 19:28:36 +0200 Subject: Use of smarty to render all page ; apply coding standards, add license ; refs #46,48,47 --- all.php | 443 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 204 insertions(+), 239 deletions(-) (limited to 'all.php') diff --git a/all.php b/all.php index 2b32a5b..32596d3 100644 --- a/all.php +++ b/all.php @@ -1,248 +1,213 @@ . + * + * @category Main + * @package RPMPHP + * + * @author Remi Collet + * @author Johan Cwiklinski + * @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 "
"; print_r($repos);echo "
"; - foreach($repos as $repomain) { - foreach ($repomain as $repo) { - /*printf ("%s", $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 "

SQL=$sql

"; + + $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
", + $rpm->ver, + $rpm->rel + ); + } else { + $display .= sprintf( + "%s-%s
", + $rpm->ver, + $rpm->rel + ); + $class = ($rpm->ver == $maxver ? "check" : "attn"); + } + break; + case "": + $display .= sprintf( + "%s-%s
", + $rpm->ver, + $rpm->rel + ); + break; + case "updates": + $display .= sprintf( + "%s-%s (updates)
", + $rpm->ver, + $rpm->rel + ); + $class = ($rpm->ver == $maxver ? "check" : "attn"); + break; + case "testing": + $display .= sprintf( + "%s-%s (testing)
", + $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 "

SQL=$sql

"; - - /*echo "\n"; - echo ""; - - foreach($repos as $repomain) { - foreach ($repomain as $repo) { - printf ("", $repo->main); - break; - } - } - echo "\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 .= "
"; - $dispowner .= sprintf ("%s", $_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 ("\n\t\n\t\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
", $rpm->ver, $rpm->rel); - } else { - $display .= sprintf("%s-%s
", $rpm->ver, $rpm->rel); - $class = ($rpm->ver == $maxver ? "check" : "attn"); - } - break; - case "": - $display .= sprintf("%s-%s
", $rpm->ver, $rpm->rel); - break; - case "updates": - $display .= sprintf("%s-%s (updates)
", $rpm->ver, $rpm->rel); - $class = ($rpm->ver == $maxver ? "check" : "attn"); - break; - case "testing": - $display .= sprintf("%s-%s (testing)
", $rpm->ver, $rpm->rel); - $class = ($rpm->ver == $maxver ? "info" : "attn"); - break; - } - } // RPM exists - } // sub repo - - if ($class && $maxver) { - printf("\t\n", $class, $display); - } else if ($display) { - printf("\t\n", $display); - } else { - echo "\t\n"; - } - } // mainrepo - - echo "\n"; - $i++; - } - } // each Line -} -?> - - - - Packages in Fedora - - - - - - - - -
- -
-
-

You are here:

- -
-
-
-
- Filter packages - - - -
- -
-query($sql); - if ($res && $row=$res->fetchObject()) { - printf("

Repositories last updated %s.

", date("r", $row->stamp)); - } - -?> -

Packages in Fedora

-
PackageOwner(s)%s
%s%s%s%s 
- - - - - - - - - - - -"; - //echo "
"; print_r($rpms); echo "
"; + $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) { -?> - - - -assign( + 'error', + sprintf("%s ERREUR : %s\n", date("r"), $e->getMessage()) + ); } -?> - -
PackageOwner(s)

Choose a criteria from the filter menu

-getMessage()); -?> -
-
    -
  • Legend:
  • -
  • Upstream: bold if stable.
  • -
  • Repo: bold for latest release.
  • -
  • Lastest released (stable if exists)
  • -
  • Lastest in testing
  • -
  • Lastest not available
  • -
- - - - - +$page_content = $smarty->fetch('all.tpl'); +$smarty->assign('page_content', $page_content); +$smarty->display('main.tpl'); + +?> \ No newline at end of file -- cgit