summaryrefslogtreecommitdiffstats
path: root/zoom.php
blob: 11bf489efa2c26bf710a01ef61a29bf5080d4196 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Display informations from a specific package
 *
 * 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 'include/main.php';

$fedcli = new FedoraPkgdb();

$name = $_GET['rpm'];

$smarty->assign('name_required', true);
$smarty->assign('name', $name);
$ariane[] = array(
    'url'   => '#',
    'text'  => 'Package: ' . $name
);
$ajax_infos = '<span class="ajax">(wait for ajax or <a href="' .
    $_SERVER['PHP_SELF'] . '?rpm='.$name.
    '&amp;pkgdb=1">reload with pkgdb</a>)</span>';
$smarty->assign('ajax_infos', $ajax_infos);
$smarty->assign('ariane', $ariane);
$smarty->assign('page_title', 'Package: ' . $name);

/**
* Retrieve people informations for a specific branch
*
* @param array $params Array of parameters
*
* @return string
*/
function getBranchPeople($params)
{
    global $fedpkg;

    $branch = $people = null; // avoid IDE warning
    extract($params);
    $ret = null;
    if (isset($fedpkg[$branch]['owner'])) {
        if ( !$people || $people == '' || $people == 'owner' ) {
            $ret = $fedpkg[$branch]['owner'];
        } else if ( $people == 'people') {
            $ret_tmp = $fedpkg[$branch]['people'];
        }
    }
    if ( $people == 'people') {
        foreach ( $ret_tmp as $r ) {
            if ( $ret !== null ) {
                $ret .= ', ';
            }
            $ret .= $r['username'];
        }
    }
    return $ret;
}
$smarty->register_function('getBranchPeople', 'getBranchPeople');

if ( !isset($name) || !$name ) {
    $smarty->assign('error', 'missing_name');
} else {
    try {
        $db = new PDO ("mysql:dbname=" . MYBASE . ";host=" . MYHOST, MYUSER, MYPASS);

        $sql = "SELECT rpm.*,
            CONCAT(repo.url,rpm.name,'-',rpm.ver,'-',rpm.rel,'.src.rpm') as rpmurl
            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 (isset($owner->name)) {
            // Use exact name (with case) from acl (else pkgdb could fail)
            $name = $owner->name;
            $smarty->assign('name', $name);
            $smarty->assign('page_title', 'Package: ' . $name);
        }

        if (!$rpm) {
            echo "<h1>$name not found</h1>\n";
        } else {
            if ($rpm->summary) {
                $summary['Summary'] = $rpm->summary;
            } else if ($owner->summary) {
                $summary['Summary'] = $owner->summary;
            }
            $summary['Description'] = (
                (isset($fedpkg['devel']['package']['description'])) ?
                $fedpkg['devel']['package']['description'] :
                $ajax_infos
            );
            if ( $rpm->url ) {
                $summary['URL'] = $rpm->url;
            }
            if ($up && $up->type) {
                $summary['Type'] = $up->type;
            }
            if ($up && $up->channel) {
                $summary['Channel'] = $up->channel;
            }
            if ($up && $up->stable) {
                $summary['Stabe version'] = $up->stable;
            }
            if ($up && $up->unstable && $up->stable!=$up->unstable) {
                if ($up->state) {
                    $summary['Unstable version'] = $up->unstable . ' (' .
                        $up->state . ')';
                } else {
                    $summary['Unstable version'] = $up->unstable;
                }
            }
            if ($owner && $owner->owner) {
                if ($owner->cc) {
                    $summary['Owner'] = $owner->owner . ' (' . $owner->cc . ')';
                } else {
                    $summary['Owner'] = $owner->owner;
                }

                // Only when owner (so we have the exact name)
                $summary['Bugzilla'] = 'https://bugzilla.redhat.com/buglist.cgi'.
                    '?bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=ON_QA' .
                    '&amp;component=' . $name;
            }
            $summary['GitWeb']
                = 'http://pkgs.fedoraproject.org/gitweb/?p=' . $name . '.git';

            $summary['PkgDB'] = $fedcli->getPackageURL($name);

            if (isset($_GET['pkgdb'])) {
                $fedpkg = $fedcli->getPackageInfo($name);
            } else {
                $fedpkg = false;
            }
            $i=0;

            $prev=false;
            do {
                $packages[] = $rpm;
                if ( $rpm->repo_main != $prev ) {
                    $prev = $rpm->repo_main;
                }
            } while ( $rpm = $resrpm->fetchObject() );
        }
        $smarty->assign('pkgdb', (isset($_GET['pkgdb']) ? $_GET['pkgdb'] : null));
        $smarty->assign('summary', $summary);
        $smarty->assign('packages', $packages);
        $smarty->assign('fedpkg', $fedpkg);
    } catch(PDOException $e) {
        $smarty->assign(
            'error',
            sprintf("%s ERREUR : %s\n", date("r"), $e->getMessage())
        );
    }
}

$page_content = $smarty->fetch('zoom.tpl');
$smarty->assign('page_content', $page_content);
$smarty->display('main.tpl');
?>