# -*- 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): Terry Weissman # Contains some global routines used throughout the CGI scripts of Bugzilla. use diagnostics; use strict; use CGI::Carp qw(fatalsToBrowser); require 'globals.pl'; ## ## Utility routines to convert strings ## # Get rid of all the %xx encoding and the like from the given URL. sub url_decode { my ($todecode) = (@_); $todecode =~ tr/+/ /; # pluses become spaces $todecode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; return $todecode; } # Quotify a string, suitable for putting into a URL. sub url_quote { my($toencode) = (@_); $toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; return $toencode; } # Quotify a string, suitable for output as form values sub value_quote { my ($var) = (@_); $var =~ s/\&/\&/g; $var =~ s//\>/g; $var =~ s/\"/\"/g; $var =~ s/\n/\ /g; $var =~ s/\r/\ /g; return $var; } sub url_encode2 { my ($s) = @_; $s =~ s/\%/\%25/g; $s =~ s/\=/\%3d/g; $s =~ s/\?/\%3f/g; $s =~ s/ /\%20/g; $s =~ s/\n/\%0a/g; $s =~ s/\r//g; $s =~ s/\"/\%22/g; $s =~ s/\'/\%27/g; $s =~ s/\|/\%7c/g; $s =~ s/\&/\%26/g; $s =~ s/\+/\%2b/g; return $s; } sub url_encode3 { my ($s) = @_; $s =~ s/\n/\%0a/g; $s =~ s/\r//g; $s =~ s/\"/\%22/g; $s =~ s/\+/\%2b/g; return $s; } ## ## Routines to generate html as part of Bonsai ## # Create the URL that has the correct tree and batch information sub BatchIdPart { my ($initstr) = @_; my ($result, $ro) = ("", Param('readonly')); $initstr = "" unless (defined($initstr) && $initstr); $result = $initstr if (($::TreeID ne "default") || $ro); $result .= "&treeid=$::TreeID" if ($::TreeID ne "default"); $result .= "&batchid=$::BatchID" if ($ro); return $result; } # Create a generic page header for bonsai pages sub PutsHeader { my ($title, $h1, $h2) = (@_); if (!defined $h1) { $h1 = $title; } if (!defined $h2) { $h2 = ""; } print "\n$title\n"; print $::Setup_String if (defined($::Setup_String) && $::Setup_String); print Param("headerhtml") . "\n\n"; print "\n"; print PerformSubsts(Param("bannerhtml"), undef); print "\n"; print " \n"; print " \n"; print "
\n"; print " \n"; print " \n"; print "
\n"; print " $h1\n"; print "
\n"; print " $h2\n"; print "
\n"; print "
\n"; print Param("blurbhtml"); print "
\n"; } # Create a generic page trailer for bonsai pages sub PutsTrailer { my $args = BatchIdPart('?'); my $maintainer = Param('maintainer'); my $email = ''; if ($maintainer) { $email = "
" . ConstructMailTo($maintainer, "Bonsai Comments"); $email .= " with comments/questions about this page.\n"; } print "

Back to the top of Bonsai $email "; } sub GeneratePersonInput { my ($field, $required, $def_value, $extraJavaScript) = (@_); if (!defined $extraJavaScript) { $extraJavaScript = ""; } if ($extraJavaScript ne "") { $extraJavaScript = "onChange=\" $extraJavaScript \""; } return ""; } sub GeneratePeopleInput { my ($field, $def_value) = (@_); return ""; } sub make_options { my ($src,$default,$isregexp) = (@_); my $last = ""; my $popup = ""; my $found = 0; if ($src) { foreach my $item (@$src) { if ($item eq "-blank-" || $item ne $last) { if ($item eq "-blank-") { $item = ""; } $last = $item; if ($isregexp ? $item =~ $default : $default eq $item) { $popup .= "