2003-03-27 00:07:02 +00:00
|
|
|
#!/usr/bin/perl -wT
|
2001-05-29 04:01:48 +00:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Owen Taylor <otaylor@redhat.com>
|
2002-01-25 22:40:04 +00:00
|
|
|
# Gervase Markham <gerv@gerv.net>
|
2002-07-24 23:23:00 +00:00
|
|
|
# David Fallon <davef@tetsubo.com>
|
2003-01-15 06:48:17 +00:00
|
|
|
# Tobias Burnus <burnus@net-b.de>
|
2001-05-29 04:01:48 +00:00
|
|
|
|
|
|
|
use strict;
|
2002-02-13 02:27:24 +00:00
|
|
|
|
2002-01-20 01:44:52 +00:00
|
|
|
use lib qw(.);
|
|
|
|
|
2005-08-10 01:30:41 +00:00
|
|
|
require "globals.pl";
|
2001-05-29 04:01:48 +00:00
|
|
|
|
2004-03-27 03:51:44 +00:00
|
|
|
use Bugzilla::Constants;
|
|
|
|
|
2005-10-30 21:31:29 +00:00
|
|
|
my $user = Bugzilla->login(LOGIN_REQUIRED);
|
2002-06-17 09:39:00 +00:00
|
|
|
|
2003-05-05 01:15:38 +00:00
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-10-26 16:15:50 +00:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-10-24 23:11:56 +00:00
|
|
|
my $template = Bugzilla->template;
|
|
|
|
my $vars = {};
|
2003-05-05 01:15:38 +00:00
|
|
|
|
2004-03-06 09:08:46 +00:00
|
|
|
my $action = $cgi->param('action') || "";
|
2001-05-29 04:01:48 +00:00
|
|
|
|
2002-01-25 22:40:04 +00:00
|
|
|
if ($action eq "show") {
|
2002-12-08 23:57:23 +00:00
|
|
|
# Read in the entire quip list
|
2005-10-26 16:15:50 +00:00
|
|
|
my $quipsref = $dbh->selectall_arrayref(
|
|
|
|
"SELECT quipid, userid, quip, approved FROM quips");
|
2002-12-08 23:57:23 +00:00
|
|
|
|
|
|
|
my $quips;
|
|
|
|
my @quipids;
|
2005-10-26 16:15:50 +00:00
|
|
|
foreach my $quipref (@$quipsref) {
|
|
|
|
my ($quipid, $userid, $quip, $approved) = @$quipref;
|
2003-01-15 06:48:17 +00:00
|
|
|
$quips->{$quipid} = {'userid' => $userid, 'quip' => $quip,
|
|
|
|
'approved' => $approved};
|
2002-12-08 23:57:23 +00:00
|
|
|
push(@quipids, $quipid);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $users;
|
2005-10-26 16:15:50 +00:00
|
|
|
my $sth = $dbh->prepare("SELECT login_name FROM profiles WHERE userid = ?");
|
2002-12-08 23:57:23 +00:00
|
|
|
foreach my $quipid (@quipids) {
|
2003-01-15 06:48:17 +00:00
|
|
|
my $userid = $quips->{$quipid}{'userid'};
|
2005-02-28 16:36:42 +00:00
|
|
|
if ($userid && not defined $users->{$userid}) {
|
2005-10-26 16:15:50 +00:00
|
|
|
($users->{$userid}) = $dbh->selectrow_array($sth, undef, $userid);
|
2002-12-08 23:57:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$vars->{'quipids'} = \@quipids;
|
|
|
|
$vars->{'quips'} = $quips;
|
|
|
|
$vars->{'users'} = $users;
|
2003-01-06 07:53:15 +00:00
|
|
|
$vars->{'show_quips'} = 1;
|
2002-12-08 23:57:23 +00:00
|
|
|
}
|
|
|
|
|
2002-01-25 22:40:04 +00:00
|
|
|
if ($action eq "add") {
|
2005-03-10 16:21:35 +00:00
|
|
|
(Param('quip_list_entry_control') eq "closed") &&
|
|
|
|
ThrowUserError("no_new_quips");
|
|
|
|
|
2002-01-25 22:40:04 +00:00
|
|
|
# Add the quip
|
2005-03-10 16:21:35 +00:00
|
|
|
my $approved =
|
|
|
|
(Param('quip_list_entry_control') eq "open") || (UserInGroup('admin')) || 0;
|
2004-03-06 09:08:46 +00:00
|
|
|
my $comment = $cgi->param("quip");
|
2002-10-01 22:41:09 +00:00
|
|
|
$comment || ThrowUserError("need_quip");
|
2005-10-26 16:15:50 +00:00
|
|
|
trick_taint($comment); # Used in a placeholder below
|
2002-01-25 22:40:04 +00:00
|
|
|
|
2005-10-26 16:15:50 +00:00
|
|
|
$dbh->do("INSERT INTO quips (userid, quip, approved) VALUES (?, ?, ?)",
|
2005-10-30 21:31:29 +00:00
|
|
|
undef, ($user->id, $comment, $approved));
|
2002-01-25 22:40:04 +00:00
|
|
|
|
|
|
|
$vars->{'added_quip'} = $comment;
|
|
|
|
}
|
|
|
|
|
2003-01-15 06:48:17 +00:00
|
|
|
if ($action eq 'approve') {
|
|
|
|
# Read in the entire quip list
|
2005-10-26 16:15:50 +00:00
|
|
|
my $quipsref = $dbh->selectall_arrayref("SELECT quipid, approved FROM quips");
|
|
|
|
|
2003-01-15 06:48:17 +00:00
|
|
|
my %quips;
|
2005-10-26 16:15:50 +00:00
|
|
|
foreach my $quipref (@$quipsref) {
|
|
|
|
my ($quipid, $approved) = @$quipref;
|
2003-01-15 06:48:17 +00:00
|
|
|
$quips{$quipid} = $approved;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @approved;
|
|
|
|
my @unapproved;
|
|
|
|
foreach my $quipid (keys %quips) {
|
2004-03-06 09:08:46 +00:00
|
|
|
my $form = $cgi->param('quipid_'.$quipid) ? 1 : 0;
|
2003-01-15 06:48:17 +00:00
|
|
|
if($quips{$quipid} ne $form) {
|
|
|
|
if($form) { push(@approved, $quipid); }
|
|
|
|
else { push(@unapproved, $quipid); }
|
|
|
|
}
|
|
|
|
}
|
2005-10-26 16:15:50 +00:00
|
|
|
$dbh->do("UPDATE quips SET approved = 1 WHERE quipid IN (" .
|
2003-01-15 06:48:17 +00:00
|
|
|
join(",", @approved) . ")") if($#approved > -1);
|
2005-10-26 16:15:50 +00:00
|
|
|
$dbh->do("UPDATE quips SET approved = 0 WHERE quipid IN (" .
|
2003-01-15 06:48:17 +00:00
|
|
|
join(",", @unapproved) . ")") if($#unapproved > -1);
|
|
|
|
$vars->{ 'approved' } = \@approved;
|
|
|
|
$vars->{ 'unapproved' } = \@unapproved;
|
|
|
|
}
|
|
|
|
|
2002-12-08 23:57:23 +00:00
|
|
|
if ($action eq "delete") {
|
2005-03-09 16:18:03 +00:00
|
|
|
UserInGroup("admin")
|
|
|
|
|| ThrowUserError("auth_failure", {group => "admin",
|
|
|
|
action => "delete",
|
|
|
|
object => "quips"});
|
2004-03-06 09:08:46 +00:00
|
|
|
my $quipid = $cgi->param("quipid");
|
2002-12-08 23:57:23 +00:00
|
|
|
ThrowCodeError("need_quipid") unless $quipid =~ /(\d+)/;
|
|
|
|
$quipid = $1;
|
|
|
|
|
2005-10-26 16:15:50 +00:00
|
|
|
($vars->{'deleted_quip'}) = $dbh->selectrow_array(
|
|
|
|
"SELECT quip FROM quips WHERE quipid = ?",
|
|
|
|
undef, $quipid);
|
|
|
|
$dbh->do("DELETE FROM quips WHERE quipid = ?", undef, $quipid);
|
2002-12-08 23:57:23 +00:00
|
|
|
}
|
|
|
|
|
2003-05-05 01:15:38 +00:00
|
|
|
print $cgi->header();
|
2002-04-24 07:24:50 +00:00
|
|
|
$template->process("list/quips.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|