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
|
|
|
|
|
|
|
use vars qw(
|
2002-07-24 23:38:50 +00:00
|
|
|
$userid
|
2002-02-13 02:27:24 +00:00
|
|
|
$template
|
|
|
|
$vars
|
|
|
|
);
|
2001-05-29 04:01:48 +00:00
|
|
|
|
2002-01-20 01:44:52 +00:00
|
|
|
use lib qw(.);
|
|
|
|
|
2001-05-29 04:01:48 +00:00
|
|
|
require "CGI.pl";
|
|
|
|
|
2004-03-27 03:51:44 +00:00
|
|
|
use Bugzilla::Constants;
|
|
|
|
|
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
2002-06-17 09:39:00 +00:00
|
|
|
|
2003-05-05 01:15:38 +00:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
|
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
|
2003-01-15 06:48:17 +00:00
|
|
|
SendSQL("SELECT quipid, userid, quip, approved FROM quips");
|
2002-12-08 23:57:23 +00:00
|
|
|
|
|
|
|
my $quips;
|
|
|
|
my @quipids;
|
|
|
|
while (MoreSQLData()) {
|
2003-01-15 06:48:17 +00:00
|
|
|
my ($quipid, $userid, $quip, $approved) = FetchSQLData();
|
|
|
|
$quips->{$quipid} = {'userid' => $userid, 'quip' => $quip,
|
|
|
|
'approved' => $approved};
|
2002-12-08 23:57:23 +00:00
|
|
|
push(@quipids, $quipid);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $users;
|
|
|
|
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}) {
|
2002-12-08 23:57:23 +00:00
|
|
|
SendSQL("SELECT login_name FROM profiles WHERE userid = $userid");
|
2003-01-28 21:11:44 +00:00
|
|
|
$users->{$userid} = FetchOneColumn();
|
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");
|
2002-01-25 22:40:04 +00:00
|
|
|
|
2003-01-15 06:48:17 +00:00
|
|
|
SendSQL("INSERT INTO quips (userid, quip, approved) VALUES " .
|
|
|
|
'(' . $userid . ', ' . SqlQuote($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
|
|
|
|
SendSQL("SELECT quipid, approved FROM quips");
|
|
|
|
|
|
|
|
my %quips;
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my ($quipid, $approved) = FetchSQLData();
|
|
|
|
$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); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SendSQL("UPDATE quips SET approved = 1 WHERE quipid IN (" .
|
|
|
|
join(",", @approved) . ")") if($#approved > -1);
|
|
|
|
SendSQL("UPDATE quips SET approved = 0 WHERE quipid IN (" .
|
|
|
|
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;
|
|
|
|
|
|
|
|
SendSQL("SELECT quip FROM quips WHERE quipid = $quipid");
|
|
|
|
$vars->{'deleted_quip'} = FetchSQLData();
|
|
|
|
SendSQL("DELETE FROM quips WHERE quipid = $quipid");
|
|
|
|
}
|
|
|
|
|
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());
|