index.cgi 2.12 KB
Newer Older
1
#!/usr/bin/perl -T
2 3 4
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
#
6 7
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
8

9
use 5.10.1;
10
use strict;
11 12
use warnings;

13
use lib qw(. lib);
14

15
use Bugzilla;
16
use Bugzilla::Constants;
17
use Bugzilla::Error;
18 19 20
use Bugzilla::Update;

# Check whether or not the user is logged in
21 22
my $user     = Bugzilla->login(LOGIN_OPTIONAL);
my $cgi      = Bugzilla->cgi;
23
my $template = Bugzilla->template;
24
my $vars     = {};
25 26 27 28

# And log out the user if requested. We do this first so that nothing
# else accidentally relies on the current login.
if ($cgi->param('logout')) {
29 30 31 32 33 34
  Bugzilla->logout();
  $user = Bugzilla->user;
  $vars->{'message'} = "logged_out";

  # Make sure that templates or other code doesn't get confused about this.
  $cgi->delete('logout');
35
}
36 37

# Return the appropriate HTTP response headers.
38
print $cgi->header();
39

40
if ($user->in_group('admin')) {
41 42 43 44 45 46 47 48 49 50

  # If 'urlbase' is not set, display the Welcome page.
  unless (Bugzilla->params->{'urlbase'}) {
    $template->process('welcome-admin.html.tmpl')
      || ThrowTemplateError($template->error());
    exit;
  }

  # Inform the administrator about new releases, if any.
  $vars->{'release'} = Bugzilla::Update::get_notifications();
51 52
}

53
if ($user->id) {
54 55 56 57 58 59 60 61 62 63 64 65 66
  my $dbh = Bugzilla->dbh;
  $vars->{assignee_count} = $dbh->selectrow_array(
    "SELECT COUNT(*) FROM bugs WHERE assigned_to = ?
                             AND resolution = ''", undef, $user->id
  );
  $vars->{reporter_count} = $dbh->selectrow_array(
    "SELECT COUNT(*) FROM bugs WHERE reporter = ?
                             AND resolution = ''", undef, $user->id
  );
  $vars->{requestee_count} = $dbh->selectrow_array(
    'SELECT COUNT(DISTINCT bug_id) FROM flags
                             WHERE requestee_id = ?', undef, $user->id
  );
67 68
}

69
# Generate and return the UI (HTML page) from the appropriate template.
70
$template->process("index.html.tmpl", $vars)
71
  || ThrowTemplateError($template->error());