]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/CGI/Pkgreport.pm
* switch to package_links from htmlizemaintlinks
[debbugs.git] / Debbugs / CGI / Pkgreport.pm
1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 #
5 # [Other people have contributed to this file; their copyrights should
6 # be listed here too.]
7 # Copyright 2008 by Don Armstrong <don@donarmstrong.com>.
8
9
10 package Debbugs::CGI::Pkgreport;
11
12 =head1 NAME
13
14 Debbugs::CGI::Pkgreport -- specific routines for the pkgreport cgi script
15
16 =head1 SYNOPSIS
17
18
19 =head1 DESCRIPTION
20
21
22 =head1 BUGS
23
24 None known.
25
26 =cut
27
28 use warnings;
29 use strict;
30 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
31 use base qw(Exporter);
32
33 use IO::Scalar;
34 use Params::Validate qw(validate_with :types);
35
36 use Debbugs::Config qw(:config :globals);
37 use Debbugs::CGI qw(:url :html :util);
38 use Debbugs::Common qw(:misc :util :date);
39 use Debbugs::Status qw(:status);
40 use Debbugs::Bugs qw(bug_filter);
41 use Debbugs::Packages qw(:mapping);
42
43 use Debbugs::Text qw(:templates);
44
45 use POSIX qw(strftime);
46
47
48 BEGIN{
49      ($VERSION) = q$Revision: 494 $ =~ /^Revision:\s+([^\s+])/;
50      $DEBUG = 0 unless defined $DEBUG;
51
52      @EXPORT = ();
53      %EXPORT_TAGS = (html => [qw(short_bug_status_html pkg_htmlizebugs),
54                               qw(pkg_javascript),
55                               qw(pkg_htmlselectyesno pkg_htmlselectsuite),
56                               qw(buglinklist pkg_htmlselectarch)
57                              ],
58                      misc => [qw(generate_package_info make_order_list),
59                               qw(myurl),
60                               qw(get_bug_order_index determine_ordering),
61                              ],
62                     );
63      @EXPORT_OK = (qw());
64      Exporter::export_ok_tags(keys %EXPORT_TAGS);
65      $EXPORT_TAGS{all} = [@EXPORT_OK];
66 }
67
68 =head2 generate_package_info
69
70      generate_package_info($srcorbin,$package)
71
72 Generates the informational bits for a package and returns it
73
74 =cut
75
76 sub generate_package_info{
77      my %param = validate_with(params => \@_,
78                                spec  => {binary => {type => BOOLEAN,
79                                                     default => 1,
80                                                    },
81                                          package => {type => SCALAR|ARRAYREF,
82                                                     },
83                                          options => {type => HASHREF,
84                                                     },
85                                          bugs    => {type => ARRAYREF,
86                                                     },
87                                         },
88                               );
89
90      my $output_scalar = '';
91      my $output = globify_scalar(\$output_scalar);
92
93      my $package = $param{package};
94
95      my %pkgsrc = %{getpkgsrc()};
96      my $srcforpkg = $package;
97      if ($param{binary} and exists $pkgsrc{$package}
98          and defined $pkgsrc{$package}) {
99           $srcforpkg = $pkgsrc{$package};
100      }
101
102      my $showpkg = html_escape($package);
103      my $maintainers = getmaintainers();
104      my $maint = $maintainers->{$srcforpkg};
105      if (defined $maint) {
106           print {$output} '<p>';
107           print {$output} (($maint =~ /,/)? "Maintainer for $showpkg is "
108                            : "Maintainers for $showpkg are ") .
109                                 package_links(maint => $maint);
110           print {$output} ".</p>\n";
111      }
112      else {
113           print {$output} "<p>No maintainer for $showpkg. Please do not report new bugs against this package.</p>\n";
114      }
115      my @pkgs = getsrcpkgs($srcforpkg);
116      @pkgs = grep( !/^\Q$package\E$/, @pkgs );
117      if ( @pkgs ) {
118           @pkgs = sort @pkgs;
119           if ($param{binary}) {
120                print {$output} "<p>You may want to refer to the following packages that are part of the same source:\n";
121           }
122           else {
123                print {$output} "<p>You may want to refer to the following individual bug pages:\n";
124           }
125           #push @pkgs, $src if ( $src && !grep(/^\Q$src\E$/, @pkgs) );
126           print {$output} scalar package_links(package=>[@pkgs]);
127           print {$output} ".\n";
128      }
129      my @references;
130      my $pseudodesc = getpseudodesc();
131      if ($package and defined($pseudodesc) and exists($pseudodesc->{$package})) {
132           push @references, "to the <a href=\"http://${debbugs::gWebDomain}/pseudo-packages${debbugs::gHTMLSuffix}\">".
133                "list of other pseudo-packages</a>";
134      }
135      else {
136           if ($package and defined $gPackagePages) {
137                push @references, sprintf "to the <a href=\"%s\">%s package page</a>",
138                     html_escape("http://${gPackagePages}/$package"), html_escape("$package");
139           }
140           if (defined $gSubscriptionDomain) {
141                my $ptslink = $param{binary} ? $srcforpkg : $package;
142                push @references, q(to the <a href="http://).html_escape("$gSubscriptionDomain/$ptslink").q(">Package Tracking System</a>);
143           }
144           # Only output this if the source listing is non-trivial.
145           if ($param{binary} and $srcforpkg) {
146                push @references,
147                     "to the source package ".
148                          package_links(src=>$srcforpkg,
149                                        options => $param{options}) .
150                               "'s bug page";
151           }
152      }
153      if (@references) {
154           $references[$#references] = "or $references[$#references]" if @references > 1;
155           print {$output} "<p>You might like to refer ", join(", ", @references), ".</p>\n";
156      }
157      if (defined $param{maint} || defined $param{maintenc}) {
158           print {$output} "<p>If you find a bug not listed here, please\n";
159           printf {$output} "<a href=\"%s\">report it</a>.</p>\n",
160                html_escape("http://${debbugs::gWebDomain}/Reporting${debbugs::gHTMLSuffix}");
161      }
162      if (not $maint and not @{$param{bugs}}) {
163           print {$output} "<p>There is no record of the " . html_escape($package) .
164                ($param{binary} ? " package" : " source package") .
165                     ", and no bugs have been filed against it.</p>";
166      }
167      return $output_scalar;
168 }
169
170
171 =head2 short_bug_status_html
172
173      print short_bug_status_html(status => read_bug(bug => 5),
174                                  options => \%param,
175                                 );
176
177 =over
178
179 =item status -- status hashref as returned by read_bug
180
181 =item options -- hashref of options to pass to package_links (defaults
182 to an empty hashref)
183
184 =item bug_options -- hashref of options to pass to bug_links (default
185 to an empty hashref)
186
187 =item snippet -- optional snippet of information about the bug to
188 display below
189
190
191 =back
192
193
194
195 =cut
196
197 sub short_bug_status_html {
198      my %param = validate_with(params => \@_,
199                                spec   => {status => {type => HASHREF,
200                                                     },
201                                           options => {type => HASHREF,
202                                                       default => {},
203                                                      },
204                                           bug_options => {type => HASHREF,
205                                                           default => {},
206                                                          },
207                                           snippet => {type => SCALAR,
208                                                       default => '',
209                                                      },
210                                          },
211                               );
212
213      my %status = %{$param{status}};
214
215      $status{tags_array} = [sort(split(/\s+/, $status{tags}))];
216      $status{date_text} = strftime('%a, %e %b %Y %T UTC', gmtime($status{date}));
217      $status{mergedwith_array} = [split(/ /,$status{mergedwith})];
218
219      my @blockedby= split(/ /, $status{blockedby});
220      $status{blockedby_array} = [];
221      if (@blockedby && $status{"pending"} ne 'fixed' && ! length($status{done})) {
222           for my $b (@blockedby) {
223                my %s = %{get_bug_status($b)};
224                next if $s{"pending"} eq 'fixed' || length $s{done};
225                push @{$status{blockedby_array}},{bug_num => $b, subject => $s{subject}, status => \%s};
226           }
227      }
228
229      my @blocks= split(/ /, $status{blocks});
230      $status{blocks_array} = [];
231      if (@blocks && $status{"pending"} ne 'fixed' && ! length($status{done})) {
232           for my $b (@blocks) {
233                my %s = %{get_bug_status($b)};
234                next if $s{"pending"} eq 'fixed' || length $s{done};
235                push @{$status{blocks_array}}, {bug_num => $b, subject => $s{subject}, status => \%s};
236           }
237      }
238
239
240      return fill_in_template(template => 'cgi/short_bug_status',
241                              variables => {status => \%status,
242                                            isstrongseverity => \&Debbugs::Status::isstrongseverity,
243                                            html_escape   => \&Debbugs::CGI::html_escape,
244                                            looks_like_number => \&Scalar::Util::looks_like_number,
245                                           },
246                              hole_var  => {'&package_links' => \&Debbugs::CGI::package_links,
247                                            '&bug_links'     => \&Debbugs::CGI::bug_links,
248                                            '&version_url'   => \&Debbugs::CGI::version_url,
249                                            '&secs_to_english' => \&Debbugs::Common::secs_to_english,
250                                            '&strftime'      => \&POSIX::strftime,
251                                           },
252                             );
253
254      my $result = "";
255
256      my $showseverity;
257      if ($status{severity} eq 'normal') {
258           $showseverity = '';
259      }
260      elsif (isstrongseverity($status{severity})) {
261           $showseverity = "Severity: <em class=\"severity\">$status{severity}</em>;\n";
262      }
263      else {
264           $showseverity = "Severity: <em>$status{severity}</em>;\n";
265      }
266
267      $result .= package_links(package => $status{package},
268                               options  => $param{options},
269                              );
270
271      my $showversions = '';
272      if (@{$status{found_versions}}) {
273           my @found = @{$status{found_versions}};
274           $showversions .= join ', ', map {s{/}{ }; html_escape($_)} @found;
275      }
276      if (@{$status{fixed_versions}}) {
277           $showversions .= '; ' if length $showversions;
278           $showversions .= '<strong>fixed</strong>: ';
279           my @fixed = @{$status{fixed_versions}};
280           $showversions .= join ', ', map {s{/}{ }; html_escape($_)} @fixed;
281      }
282      $result .= ' (<a href="'.
283           version_url(package => $status{package},
284                       found   => $status{found_versions},
285                       fixed   => $status{fixed_versions},
286                      ).qq{">$showversions</a>)} if length $showversions;
287      $result .= ";\n";
288
289      $result .= $showseverity;
290      $result .= "Reported by: ".package_links(submitter=>$status{originator},
291                                               class => "submitter",
292                                              );
293      $result .= ";\nOwned by: " . package_links(owner => $status{owner},
294                                                 class => "submitter",
295                                                )
296           if length $status{owner};
297      $result .= ";\nTags: <strong>"
298           . html_escape(join(", ", sort(split(/\s+/, $status{tags}))))
299                . "</strong>"
300                     if (length($status{tags}));
301
302      $result .= (length($status{mergedwith})?";\nMerged with ":"") .
303           bug_links(bug => [split(/ /,$status{mergedwith})],
304                     class => "submitter",
305                    );
306      $result .= (length($status{blockedby})?";\nBlocked by ":"") .
307           bug_links(bug => [split(/ /,$status{blockedby})],
308                     class => "submitter",
309                    );
310      $result .= (length($status{blocks})?";\nBlocks ":"") .
311           bug_links(bug => [split(/ /,$status{blocks})],
312                     class => "submitter",
313                    );
314
315      if (length($status{done})) {
316           $result .= "<br><strong>Done:</strong> " . html_escape($status{done});
317           my $days = bug_archiveable(bug => $status{id},
318                                      status => \%status,
319                                      days_until => 1,
320                                     );
321           if ($days >= 0 and defined $status{location} and $status{location} ne 'archive') {
322                $result .= ";\n<strong>Can be archived" . ( $days == 0 ? " today" : $days == 1 ? " in $days day" : " in $days days" ) . "</strong>";
323           }
324           elsif (defined $status{location} and $status{location} eq 'archived') {
325                $result .= ";\n<strong>Archived.</strong>";
326           }
327      }
328
329      unless (length($status{done})) {
330           if (length($status{forwarded})) {
331                $result .= ";\n<strong>Forwarded</strong> to "
332                     . join(', ',
333                            map {maybelink($_)}
334                            split /\,\s+/,$status{forwarded}
335                           );
336           }
337           # Check the age of the logfile
338           my ($days_last,$eng_last) = secs_to_english(time - $status{log_modified});
339           my ($days,$eng) = secs_to_english(time - $status{date});
340
341           if ($days >= 7) {
342                my $font = "";
343                my $efont = "";
344                $font = "em" if ($days > 30);
345                $font = "strong" if ($days > 60);
346                $efont = "</$font>" if ($font);
347                $font = "<$font>" if ($font);
348
349                $result .= ";\n ${font}$eng old$efont";
350           }
351           if ($days_last > 7) {
352                my $font = "";
353                my $efont = "";
354                $font = "em" if ($days_last > 30);
355                $font = "strong" if ($days_last > 60);
356                $efont = "</$font>" if ($font);
357                $font = "<$font>" if ($font);
358
359                $result .= ";\n ${font}Modified $eng_last ago$efont";
360           }
361      }
362
363      $result .= ".";
364
365      return $result;
366 }
367
368
369 sub pkg_htmlizebugs {
370      my %param = validate_with(params => \@_,
371                                spec   => {bugs => {type => ARRAYREF,
372                                                   },
373                                           names => {type => ARRAYREF,
374                                                    },
375                                           title => {type => ARRAYREF,
376                                                    },
377                                           prior => {type => ARRAYREF,
378                                                    },
379                                           order => {type => ARRAYREF,
380                                                    },
381                                           ordering => {type => SCALAR,
382                                                       },
383                                           bugusertags => {type => HASHREF,
384                                                           default => {},
385                                                          },
386                                           bug_rev => {type => BOOLEAN,
387                                                       default => 0,
388                                                      },
389                                           bug_order => {type => SCALAR,
390                                                        },
391                                           repeatmerged => {type => BOOLEAN,
392                                                            default => 1,
393                                                           },
394                                           include => {type => ARRAYREF,
395                                                       default => [],
396                                                      },
397                                           exclude => {type => ARRAYREF,
398                                                       default => [],
399                                                      },
400                                           this     => {type => SCALAR,
401                                                        default => '',
402                                                       },
403                                           options  => {type => HASHREF,
404                                                        default => {},
405                                                       },
406                                          }
407                               );
408      my @bugs = @{$param{bugs}};
409
410      my @status = ();
411      my %count;
412      my $header = '';
413      my $footer = "<h2 class=\"outstanding\">Summary</h2>\n";
414
415      my @dummy = ($gRemoveAge); #, @gSeverityList, @gSeverityDisplay);  #, $gHTMLExpireNote);
416
417      if (@bugs == 0) {
418           return "<HR><H2>No reports found!</H2></HR>\n";
419      }
420
421      if ( $param{bug_rev} ) {
422           @bugs = sort {$b<=>$a} @bugs;
423      }
424      else {
425           @bugs = sort {$a<=>$b} @bugs;
426      }
427      my %seenmerged;
428
429      my %common = (
430                    'show_list_header' => 1,
431                    'show_list_footer' => 1,
432                   );
433
434      my %section = ();
435      # Make the include/exclude map
436      my %include;
437      my %exclude;
438      for my $include (make_list($param{include})) {
439           next unless defined $include;
440           my ($key,$value) = split /\s*:\s*/,$include,2;
441           unless (defined $value) {
442                $key = 'tags';
443                $value = $include;
444           }
445           push @{$include{$key}}, split /\s*,\s*/, $value;
446      }
447      for my $exclude (make_list($param{exclude})) {
448           next unless defined $exclude;
449           my ($key,$value) = split /\s*:\s*/,$exclude,2;
450           unless (defined $value) {
451                $key = 'tags';
452                $value = $exclude;
453           }
454           push @{$exclude{$key}}, split /\s*,\s*/, $value;
455      }
456
457      foreach my $bug (@bugs) {
458           my %status = %{get_bug_status(bug=>$bug,
459                                         (exists $param{dist}?(dist => $param{dist}):()),
460                                         bugusertags => $param{bugusertags},
461                                         (exists $param{version}?(version => $param{version}):()),
462                                         (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
463                                        )};
464           next unless %status;
465           next if bug_filter(bug => $bug,
466                              status => \%status,
467                              repeat_merged => $param{repeatmerged},
468                              seen_merged => \%seenmerged,
469                              (keys %include ? (include => \%include):()),
470                              (keys %exclude ? (exclude => \%exclude):()),
471                             );
472
473           my $html = "<li>"; #<a href=\"%s\">#%d: %s</a>\n<br>",
474                #bug_url($bug), $bug, html_escape($status{subject});
475           $html .= short_bug_status_html(status  => \%status,
476                                          options => $param{options},
477                                         ) . "\n";
478           push @status, [ $bug, \%status, $html ];
479      }
480      if ($param{bug_order} eq 'age') {
481           # MWHAHAHAHA
482           @status = sort {$a->[1]{log_modified} <=> $b->[1]{log_modified}} @status;
483      }
484      elsif ($param{bug_order} eq 'agerev') {
485           @status = sort {$b->[1]{log_modified} <=> $a->[1]{log_modified}} @status;
486      }
487      for my $entry (@status) {
488           my $key = "";
489           for my $i (0..$#{$param{prior}}) {
490                my $v = get_bug_order_index($param{prior}[$i], $entry->[1]);
491                $count{"g_${i}_${v}"}++;
492                $key .= "_$v";
493           }
494           $section{$key} .= $entry->[2];
495           $count{"_$key"}++;
496      }
497
498      my $result = "";
499      if ($param{ordering} eq "raw") {
500           $result .= "<UL class=\"bugs\">\n" . join("", map( { $_->[ 2 ] } @status ) ) . "</UL>\n";
501      }
502      else {
503           $header .= "<div class=\"msgreceived\">\n<ul>\n";
504           my @keys_in_order = ("");
505           for my $o (@{$param{order}}) {
506                push @keys_in_order, "X";
507                while ((my $k = shift @keys_in_order) ne "X") {
508                     for my $k2 (@{$o}) {
509                          $k2+=0;
510                          push @keys_in_order, "${k}_${k2}";
511                     }
512                }
513           }
514           for my $order (@keys_in_order) {
515                next unless defined $section{$order};
516                my @ttl = split /_/, $order;
517                shift @ttl;
518                my $title = $param{title}[0]->[$ttl[0]] . " bugs";
519                if ($#ttl > 0) {
520                     $title .= " -- ";
521                     $title .= join("; ", grep {($_ || "") ne ""}
522                                    map { $param{title}[$_]->[$ttl[$_]] } 1..$#ttl);
523                }
524                $title = html_escape($title);
525
526                my $count = $count{"_$order"};
527                my $bugs = $count == 1 ? "bug" : "bugs";
528
529                $header .= "<li><a href=\"#$order\">$title</a> ($count $bugs)</li>\n";
530                if ($common{show_list_header}) {
531                     my $count = $count{"_$order"};
532                     my $bugs = $count == 1 ? "bug" : "bugs";
533                     $result .= "<H2 CLASS=\"outstanding\"><a name=\"$order\"></a>$title ($count $bugs)</H2>\n";
534                }
535                else {
536                     $result .= "<H2 CLASS=\"outstanding\">$title</H2>\n";
537                }
538                $result .= "<div class=\"msgreceived\">\n<UL class=\"bugs\">\n";
539                $result .= "\n\n\n\n";
540                $result .= $section{$order};
541                $result .= "\n\n\n\n";
542                $result .= "</UL>\n</div>\n";
543           } 
544           $header .= "</ul></div>\n";
545
546           $footer .= "<div class=\"msgreceived\">\n<ul>\n";
547           for my $i (0..$#{$param{prior}}) {
548                my $local_result = '';
549                foreach my $key ( @{$param{order}[$i]} ) {
550                     my $count = $count{"g_${i}_$key"};
551                     next if !$count or !$param{title}[$i]->[$key];
552                     $local_result .= "<li>$count $param{title}[$i]->[$key]</li>\n";
553                }
554                if ( $local_result ) {
555                     $footer .= "<li>$param{names}[$i]<ul>\n$local_result</ul></li>\n";
556                }
557           }
558           $footer .= "</ul>\n</div>\n";
559      }
560
561      $result = $header . $result if ( $common{show_list_header} );
562      $result .= $footer if ( $common{show_list_footer} );
563      return $result;
564 }
565
566 sub pkg_javascript {
567      return fill_in_template(template=>'cgi/pkgreport_javascript',
568                             );
569 }
570
571 sub pkg_htmlselectyesno {
572      my ($name, $n, $y, $default) = @_;
573      return sprintf('<select name="%s"><option value=no%s>%s</option><option value=yes%s>%s</option></select>', $name, ($default ? "" : " selected"), $n, ($default ? " selected" : ""), $y);
574 }
575
576 sub pkg_htmlselectsuite {
577      my $id = sprintf "b_%d_%d_%d", $_[0], $_[1], $_[2];
578      my @suites = ("stable", "testing", "unstable", "experimental");
579      my %suiteaka = ("stable", "etch", "testing", "lenny", "unstable", "sid");
580      my $defaultsuite = "unstable";
581
582      my $result = sprintf '<select name=dist id="%s">', $id;
583      for my $s (@suites) {
584           $result .= sprintf '<option value="%s"%s>%s%s</option>',
585                $s, ($defaultsuite eq $s ? " selected" : ""),
586                     $s, (defined $suiteaka{$s} ? " (" . $suiteaka{$s} . ")" : "");
587      }
588      $result .= '</select>';
589      return $result;
590 }
591
592 sub pkg_htmlselectarch {
593      my $id = sprintf "b_%d_%d_%d", $_[0], $_[1], $_[2];
594      my @arches = qw(alpha amd64 arm hppa i386 ia64 m68k mips mipsel powerpc s390 sparc);
595
596      my $result = sprintf '<select name=arch id="%s">', $id;
597      $result .= '<option value="any">any architecture</option>';
598      for my $a (@arches) {
599           $result .= sprintf '<option value="%s">%s</option>', $a, $a;
600      }
601      $result .= '</select>';
602      return $result;
603 }
604
605 sub myurl {
606      my %param = @_;
607      return html_escape(pkg_url(map {exists $param{$_}?($_,$param{$_}):()}
608                                 qw(archive repeatmerged mindays maxdays),
609                                 qw(version dist arch package src tag maint submitter)
610                                )
611                        );
612 }
613
614 sub make_order_list {
615      my $vfull = shift;
616      my @x = ();
617
618      if ($vfull =~ m/^([^:]+):(.*)$/) {
619           my $v = $1;
620           for my $vv (split /,/, $2) {
621                push @x, "$v=$vv";
622           }
623      }
624      else {
625           for my $v (split /,/, $vfull) {
626                next unless $v =~ m/.=./;
627                push @x, $v;
628           }
629      }
630      push @x, "";               # catch all
631      return @x;
632 }
633
634 sub get_bug_order_index {
635      my $order = shift;
636      my $status = shift;
637      my $pos = -1;
638
639      my %tags = ();
640      %tags = map { $_, 1 } split / /, $status->{"tags"}
641           if defined $status->{"tags"};
642
643      for my $el (@${order}) {
644           $pos++;
645           my $match = 1;
646           for my $item (split /[+]/, $el) {
647                my ($f, $v) = split /=/, $item, 2;
648                next unless (defined $f and defined $v);
649                my $isokay = 0;
650                $isokay = 1 if (defined $status->{$f} and $v eq $status->{$f});
651                $isokay = 1 if ($f eq "tag" && defined $tags{$v});
652                unless ($isokay) {
653                     $match = 0;
654                     last;
655                }
656           }
657           if ($match) {
658                return $pos;
659                last;
660           }
661      }
662      return $pos + 1;
663 }
664
665 sub buglinklist {
666      my ($prefix, $infix, @els) = @_;
667      return '' if not @els;
668      return $prefix . bug_linklist($infix,'submitter',@els);
669 }
670
671
672 # sets: my @names; my @prior; my @title; my @order;
673
674 sub determine_ordering {
675      my %param = validate_with(params => \@_,
676                               spec => {cats => {type => HASHREF,
677                                                },
678                                        param => {type => HASHREF,
679                                                 },
680                                        ordering => {type => SCALARREF,
681                                                    },
682                                        names    => {type => ARRAYREF,
683                                                    },
684                                        pend_rev => {type => BOOLEAN,
685                                                     default => 0,
686                                                    },
687                                        sev_rev  => {type => BOOLEAN,
688                                                     default => 0,
689                                                    },
690                                        prior    => {type => ARRAYREF,
691                                                    },
692                                        title    => {type => ARRAYREF,
693                                                    },
694                                        order    => {type => ARRAYREF,
695                                                    },
696                                       },
697                              );
698      $param{cats}{status}[0]{ord} = [ reverse @{$param{cats}{status}[0]{ord}} ]
699           if ($param{pend_rev});
700      $param{cats}{severity}[0]{ord} = [ reverse @{$param{cats}{severity}[0]{ord}} ]
701           if ($param{sev_rev});
702
703      my $i;
704      if (defined $param{param}{"pri0"}) {
705           my @c = ();
706           $i = 0;
707           while (defined $param{param}{"pri$i"}) {
708                my $h = {};
709
710                my ($pri) = make_list($param{param}{"pri$i"});
711                if ($pri =~ m/^([^:]*):(.*)$/) {
712                     $h->{"nam"} = $1; # overridden later if necesary
713                     $h->{"pri"} = [ map { "$1=$_" } (split /,/, $2) ];
714                }
715                else {
716                     $h->{"pri"} = [ split /,/, $pri ];
717                }
718
719                ($h->{"nam"}) = make_list($param{param}{"nam$i"})
720                     if (defined $param{param}{"nam$i"});
721                $h->{"ord"} = [ map {split /\s*,\s*/} make_list($param{param}{"ord$i"}) ]
722                     if (defined $param{param}{"ord$i"});
723                $h->{"ttl"} = [ map {split /\s*,\s*/} make_list($param{param}{"ttl$i"}) ]
724                     if (defined $param{param}{"ttl$i"});
725
726                push @c, $h;
727                $i++;
728           }
729           $param{cats}{"_"} = [@c];
730           ${$param{ordering}} = "_";
731      }
732
733      ${$param{ordering}} = "normal" unless defined $param{cats}{${$param{ordering}}};
734
735      sub get_ordering {
736           my @res;
737           my $cats = shift;
738           my $o = shift;
739           for my $c (@{$cats->{$o}}) {
740                if (ref($c) eq "HASH") {
741                     push @res, $c;
742                }
743                else {
744                     push @res, get_ordering($cats, $c);
745                }
746           }
747           return @res;
748      }
749      my @cats = get_ordering($param{cats}, ${$param{ordering}});
750
751      sub toenglish {
752           my $expr = shift;
753           $expr =~ s/[+]/ and /g;
754           $expr =~ s/[a-z]+=//g;
755           return $expr;
756      }
757  
758      $i = 0;
759      for my $c (@cats) {
760           $i++;
761           push @{$param{prior}}, $c->{"pri"};
762           push @{$param{names}}, ($c->{"nam"} || "Bug attribute #" . $i);
763           if (defined $c->{"ord"}) {
764                push @{$param{order}}, $c->{"ord"};
765           }
766           else {
767                push @{$param{order}}, [ 0..$#{$param{prior}[-1]} ];
768           }
769           my @t = @{ $c->{"ttl"} } if defined $c->{ttl};
770           if (@t < $#{$param{prior}[-1]}) {
771                push @t, map { toenglish($param{prior}[-1][$_]) } @t..($#{$param{prior}[-1]});
772           }
773           push @t, $c->{"def"} || "";
774           push @{$param{title}}, [@t];
775      }
776 }
777
778
779
780
781 1;
782
783
784 __END__
785
786
787
788
789
790