4 use vars qw(@EXPORT_OK @ISA);
8 #use CGI::Carp qw(fatalsToBrowser);
12 @EXPORT_OK = qw( header menubar idiot eidiot popurl rooturl table itable ntable
17 FS::CGI - Subroutines for the web interface
21 use FS::CGI qw(header menubar idiot eidiot popurl);
23 print header( 'Title', '' );
24 print header( 'Title', menubar('item', 'URL', ... ) );
26 idiot "error message";
27 eidiot "error message";
29 $url = popurl; #returns current url
30 $url = popurl(3); #three levels up
34 Provides a few common subroutines for the web interface.
40 =item header TITLE, MENUBAR
42 Returns an HTML header.
48 carp 'FS::CGI::header deprecated; include /elements/header.html instead';
50 my($title,$menubar,$etc)=@_; #$etc is for things like onLoad= etc.
51 $etc = '' unless defined $etc;
59 <META HTTP-Equiv="Cache-Control" Content="no-cache">
60 <META HTTP-Equiv="Pragma" Content="no-cache">
61 <META HTTP-Equiv="Expires" Content="0">
63 <BODY BGCOLOR="#e8e8e8"$etc>
65 <CENTER>$title</CENTER>
69 $x .= $menubar. "<BR><BR>" if $menubar;
80 my ( $header, $value ) = @_;
81 if ( defined $HTML::Mason::Commands::r ) { #Mason + apache
82 if ( $header =~ /^Content-Type$/ ) {
83 $HTML::Mason::Commands::r->content_type($value);
85 $HTML::Mason::Commands::r->header_out( $header => $value );
87 } elsif ( defined $HTML::Mason::Commands::m ) {
88 $HTML::Mason::Commands::m->notes(lc("header-$header"), $value);
90 warn "http_header($header, $value) called with no way to set headers\n";
94 =item menubar ITEM, URL, ...
96 Returns an HTML menubar.
100 sub menubar { #$menubar=menubar('Main Menu', '../', 'Item', 'url', ... );
102 carp 'FS::CGI::menubar deprecated; include /elements/menubar.html instead';
104 my($item,$url,@html);
106 ($item,$url)=splice(@_,0,2);
107 next if $item =~ /^\s*Main\s+Menu\s*$/i;
108 push @html, qq!<A HREF="$url">$item</A>!;
115 This is depriciated. Don't use it.
117 Sends an HTML error message.
122 #warn "idiot depriciated";
124 # my $cgi = &FS::UID::cgi();
125 # if ( $cgi->isa('CGI::Base') ) {
127 # &CGI::Base::SendHeaders;
129 # print $cgi->header( @FS::CGI::header );
134 <TITLE>Error processing your request</TITLE>
135 <META HTTP-Equiv="Cache-Control" Content="no-cache">
136 <META HTTP-Equiv="Pragma" Content="no-cache">
137 <META HTTP-Equiv="Expires" Content="0">
141 <H4>Error processing your request</H4>
143 Your request could not be processed because of the following error:
153 This is depriciated. Don't use it.
155 Sends an HTML error message, then exits.
160 warn "eidiot depriciated";
161 $HTML::Mason::Commands::r->send_http_header
162 if defined $HTML::Mason::Commands::r;
169 You probably shouldn't use this; but if you must:
171 If running under mod_perl, calles Apache::exit, otherwise, calls exit.
176 if (exists $ENV{MOD_PERL}) {
178 if ( defined $HTML::Mason::Commands::m ) { #Mason
179 #$HTML::Mason::Commands::m->flush_buffer();
180 $HTML::Mason::Commands::m->abort();
181 die "shouldn't fall through to here (mason \$m->abort didn't)";
183 #??? well, it is $ENV{MOD_PERL}
184 warn "running under unknown mod_perl environment; trying Apache::exit()";
193 =item popurl LEVEL [URL]
195 Returns current (or, optionally, passed) URL with LEVEL levels of path removed
196 from the end (default 0).
207 my $cgi = &FS::UID::cgi;
208 $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
211 $url_string =~ s/\?.*//;
212 my $url = new URI::URL ( $url_string );
213 my(@path)=$url->path_components;
215 $url->path_components(@path);
216 my $x = $url->as_string;
217 $x .= '/' unless $x =~ /\/$/;
230 # better to start with the client-provided URL
232 $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
235 $url_string =~ s/\?.*//;
237 #even though this is kludgy
238 $url_string =~ s{ / index\.html /? $ }
243 (browse|config|docs|edit|graph|misc|search|view|loginout|pref|rt|torrus)
250 $url_string .= '/' unless $url_string =~ /\/$/;
258 Returns HTML tag for beginning a table.
264 carp 'FS::CGI::table deprecated; include /elements/table.html instead';
268 qq!<TABLE BGCOLOR="$col" BORDER=1 WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">!;
270 '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
276 Returns HTML tag for beginning an (invisible) table.
282 my $cellspacing = shift || 0;
283 my $width = ( scalar(@_) && shift ) ? '' : 'WIDTH="100%"'; #bah
285 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing $width>!;
287 qq!<TABLE BORDER=0 CELLSPACING=$cellspacing $width>!;
293 This is getting silly.
299 my $cellspacing = shift || 0;
301 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
303 '<TABLE BORDER CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';