From 14d7441b73d32614aa0e086c5f69ac087b939a48 Mon Sep 17 00:00:00 2001 From: Julien Heyman Date: Tue, 7 Aug 2012 23:59:18 +0200 Subject: Bug 319598: Add support for saved tabular and graphical reports r/a=LpSolit --- report.cgi | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'report.cgi') diff --git a/report.cgi b/report.cgi index 83561fde5..5778841b3 100755 --- a/report.cgi +++ b/report.cgi @@ -15,6 +15,8 @@ use Bugzilla::Util; use Bugzilla::Error; use Bugzilla::Field; use Bugzilla::Search; +use Bugzilla::Report; +use Bugzilla::Token; use List::MoreUtils qw(uniq); @@ -34,6 +36,7 @@ if (grep(/^cmd-/, $cgi->param())) { Bugzilla->login(); my $action = $cgi->param('action') || 'menu'; +my $token = $cgi->param('token'); if ($action eq "menu") { # No need to do any searching in this case, so bail out early. @@ -41,6 +44,52 @@ if ($action eq "menu") { $template->process("reports/menu.html.tmpl", $vars) || ThrowTemplateError($template->error()); exit; + +} +elsif ($action eq 'add') { + my $user = Bugzilla->login(LOGIN_REQUIRED); + check_hash_token($token, ['save_report']); + + my $name = clean_text($cgi->param('name')); + my $query = $cgi->param('query'); + + if (my ($report) = grep{ lc($_->name) eq lc($name) } @{$user->reports}) { + $report->set_query($query); + $report->update; + $vars->{'message'} = "report_updated"; + } else { + my $report = Bugzilla::Report->create({name => $name, query => $query}); + $vars->{'message'} = "report_created"; + } + + $user->flush_reports_cache; + + print $cgi->header(); + + $vars->{'reportname'} = $name; + + $template->process("global/message.html.tmpl", $vars) + || ThrowTemplateError($template->error()); + exit; +} +elsif ($action eq 'del') { + my $user = Bugzilla->login(LOGIN_REQUIRED); + my $report_id = $cgi->param('saved_report_id'); + check_hash_token($token, ['delete_report', $report_id]); + + my $report = Bugzilla::Report->check({id => $report_id}); + $report->remove_from_db(); + + $user->flush_reports_cache; + + print $cgi->header(); + + $vars->{'message'} = 'report_deleted'; + $vars->{'reportname'} = $report->name; + + $template->process("global/message.html.tmpl", $vars) + || ThrowTemplateError($template->error()); + exit; } # Sanitize the URL, to make URLs shorter. @@ -209,6 +258,7 @@ $vars->{'width'} = $width if $width; $vars->{'height'} = $height if $height; $vars->{'query'} = $query; +$vars->{'saved_report_id'} = $cgi->param('saved_report_id'); $vars->{'debug'} = $cgi->param('debug'); my $formatparam = $cgi->param('format'); -- cgit v1.2.3-24-g4f1b