~ubuntu-branches/ubuntu/hardy/bugzilla/hardy-security

« back to all changes in this revision

Viewing changes to Attachment.pm

  • Committer: Bazaar Package Importer
  • Author(s): Rémi Perrot
  • Date: 2004-04-02 01:13:32 UTC
  • Revision ID: james.westby@ubuntu.com-20040402011332-hxrg0n2szimd7d25
Tags: upstream-2.16.5
Import upstream version 2.16.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode: perl; indent-tabs-mode: nil -*-
 
2
#
 
3
# The contents of this file are subject to the Mozilla Public
 
4
# License Version 1.1 (the "License"); you may not use this file
 
5
# except in compliance with the License. You may obtain a copy of
 
6
# the License at http://www.mozilla.org/MPL/
 
7
#
 
8
# Software distributed under the License is distributed on an "AS
 
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
# implied. See the License for the specific language governing
 
11
# rights and limitations under the License.
 
12
#
 
13
# The Original Code is the Bugzilla Bug Tracking System.
 
14
#
 
15
# The Initial Developer of the Original Code is Netscape Communications
 
16
# Corporation. Portions created by Netscape are
 
17
# Copyright (C) 1998 Netscape Communications Corporation. All
 
18
# Rights Reserved.
 
19
#
 
20
# Contributor(s): Terry Weissman <terry@mozilla.org>
 
21
#                 Myk Melez <myk@mozilla.org>
 
22
 
 
23
############################################################################
 
24
# Module Initialization
 
25
############################################################################
 
26
 
 
27
use diagnostics;
 
28
use strict;
 
29
 
 
30
package Attachment;
 
31
 
 
32
# This module requires that its caller have said "require CGI.pl" to import
 
33
# relevant functions from that script and its companion globals.pl.
 
34
 
 
35
############################################################################
 
36
# Functions
 
37
############################################################################
 
38
 
 
39
sub query
 
40
{
 
41
  # Retrieves and returns an array of attachment records for a given bug. 
 
42
  # This data should be given to attachment/list.atml in an
 
43
  # "attachments" variable.
 
44
  my ($bugid) = @_;
 
45
 
 
46
  my $in_editbugs = &::UserInGroup("editbugs");
 
47
 
 
48
  # Retrieve a list of attachments for this bug and write them into an array
 
49
  # of hashes in which each hash represents a single attachment.
 
50
  &::SendSQL("
 
51
              SELECT attach_id, creation_ts, mimetype, description, ispatch, 
 
52
               isobsolete, submitter_id 
 
53
              FROM attachments WHERE bug_id = $bugid ORDER BY attach_id
 
54
            ");
 
55
  my @attachments = ();
 
56
  while (&::MoreSQLData()) {
 
57
    my %a;
 
58
    my $submitter_id;
 
59
    ($a{'attachid'}, $a{'date'}, $a{'contenttype'}, $a{'description'},
 
60
     $a{'ispatch'}, $a{'isobsolete'}, $submitter_id) = &::FetchSQLData();
 
61
 
 
62
    # Format the attachment's creation/modification date into a standard
 
63
    # format (YYYY-MM-DD HH:MM)
 
64
    if ($a{'date'} =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
 
65
        $a{'date'} = "$1-$2-$3 $4:$5";
 
66
    }
 
67
 
 
68
    # Retrieve a list of status flags that have been set on the attachment.
 
69
    &::PushGlobalSQLState();
 
70
    &::SendSQL(" 
 
71
                SELECT   name 
 
72
                FROM     attachstatuses, attachstatusdefs 
 
73
                WHERE    attach_id = $a{'attachid'} 
 
74
                AND      attachstatuses.statusid = attachstatusdefs.id
 
75
                ORDER BY sortkey
 
76
              ");
 
77
    my @statuses = ();
 
78
    while (&::MoreSQLData()) { 
 
79
      my ($status) = &::FetchSQLData(); 
 
80
      push @statuses , $status;
 
81
    }
 
82
    $a{'statuses'} = \@statuses;
 
83
    &::PopGlobalSQLState();
 
84
 
 
85
    # We will display the edit link if the user can edit the attachment;
 
86
    # ie the are the submitter, or they have canedit.
 
87
    # Also show the link if the user is not logged in - in that cae,
 
88
    # They'll be prompted later
 
89
    $a{'canedit'} = ($::userid == 0 || $submitter_id == $::userid ||
 
90
                     $in_editbugs);
 
91
    push @attachments, \%a;
 
92
  }
 
93
  
 
94
  return \@attachments;  
 
95
}
 
96
 
 
97
1;