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
13 small_custview myexit http_header);
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 (exists $ENV{MOD_PERL}) {
82 if ( defined $main::Response
83 && $main::Response->isa('Apache::ASP::Response') ) { #Apache::ASP
84 if ( $header =~ /^Content-Type$/ ) {
85 $main::Response->{ContentType} = $value;
87 $main::Response->AddHeader( $header => $value );
89 } elsif ( defined $HTML::Mason::Commands::r ) { #Mason
90 ## is this the correct pacakge for $r ??? for 1.0x and 1.1x ?
91 if ( $header =~ /^Content-Type$/ ) {
92 $HTML::Mason::Commands::r->content_type($value);
94 $HTML::Mason::Commands::r->header_out( $header => $value );
97 die "http_header called in unknown environment";
100 die "http_header called not running under mod_perl";
105 =item menubar ITEM, URL, ...
107 Returns an HTML menubar.
111 sub menubar { #$menubar=menubar('Main Menu', '../', 'Item', 'url', ... );
113 carp 'FS::CGI::menubar deprecated; include /elements/menubar.html instead';
115 my($item,$url,@html);
117 ($item,$url)=splice(@_,0,2);
118 next if $item =~ /^\s*Main\s+Menu\s*$/i;
119 push @html, qq!<A HREF="$url">$item</A>!;
126 This is depriciated. Don't use it.
128 Sends an HTML error message.
133 #warn "idiot depriciated";
135 # my $cgi = &FS::UID::cgi();
136 # if ( $cgi->isa('CGI::Base') ) {
138 # &CGI::Base::SendHeaders;
140 # print $cgi->header( @FS::CGI::header );
145 <TITLE>Error processing your request</TITLE>
146 <META HTTP-Equiv="Cache-Control" Content="no-cache">
147 <META HTTP-Equiv="Pragma" Content="no-cache">
148 <META HTTP-Equiv="Expires" Content="0">
152 <H4>Error processing your request</H4>
154 Your request could not be processed because of the following error:
164 This is depriciated. Don't use it.
166 Sends an HTML error message, then exits.
171 warn "eidiot depriciated";
172 $HTML::Mason::Commands::r->send_http_header
173 if defined $HTML::Mason::Commands::r;
180 You probably shouldn't use this; but if you must:
182 If running under mod_perl, calles Apache::exit, otherwise, calls exit.
187 if (exists $ENV{MOD_PERL}) {
189 if ( defined $main::Response
190 && $main::Response->isa('Apache::ASP::Response') ) { #Apache::ASP
191 $main::Response->End();
194 } elsif ( defined $HTML::Mason::Commands::m ) { #Mason
195 #$HTML::Mason::Commands::m->flush_buffer();
196 $HTML::Mason::Commands::m->abort();
197 die "shouldn't fall through to here (mason \$m->abort didn't)";
199 #??? well, it is $ENV{MOD_PERL}
200 warn "running under unknown mod_perl environment; trying Apache::exit()";
211 Returns current URL with LEVEL levels of path removed from the end (default 0).
217 my $cgi = &FS::UID::cgi;
218 my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
219 $url_string =~ s/\?.*//;
220 my $url = new URI::URL ( $url_string );
221 my(@path)=$url->path_components;
223 $url->path_components(@path);
224 my $x = $url->as_string;
225 $x .= '/' unless $x =~ /\/$/;
234 # better to start with the client-provided URL
235 my $cgi = &FS::UID::cgi;
236 my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
237 $url_string =~ s/\?.*//;
239 #even though this is kludgy
243 (browse|config|docs|edit|graph|misc|search|view|pref|rt)
251 $url_string .= '/' unless $url_string =~ /\/$/;
259 Returns HTML tag for beginning a table.
265 carp 'FS::CGI::table deprecated; include /elements/table.html instead';
269 qq!<TABLE BGCOLOR="$col" BORDER=1 WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">!;
271 '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
277 Returns HTML tag for beginning an (invisible) table.
283 my $cellspacing = shift || 0;
284 my $width = ( scalar(@_) && shift ) ? '' : 'WIDTH="100%"'; #bah
286 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing $width>!;
288 qq!<TABLE BORDER=0 CELLSPACING=$cellspacing $width>!;
294 This is getting silly.
300 my $cellspacing = shift || 0;
302 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
304 '<TABLE BORDER CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
309 =item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT, NOBALANCE_FLAG, URL
311 Sheesh. I should just switch to Mason.
316 use FS::Record qw(qsearchs);
320 my $countrydefault = shift || 'US';
321 my $nobalance = shift;
324 my $cust_main = ref($arg) ? $arg
325 : qsearchs('cust_main', { 'custnum' => $arg } )
326 or die "unknown custnum $arg";
330 $html = qq!View <A HREF="$url?! . $cust_main->custnum . '">'
333 $html .= 'Customer #<B>'. $cust_main->custnum. '</B></A>'.
334 ' - <B><FONT COLOR="'. $cust_main->statuscolor. '">'.
335 ucfirst($cust_main->status). '</FONT></B>'.
336 ntable('#e8e8e8'). '<TR><TD VALIGN="top">'. ntable("#cccccc",2).
337 '<TR><TD ALIGN="right" VALIGN="top">Billing<BR>Address</TD><TD BGCOLOR="#ffffff">'.
338 $cust_main->getfield('last'). ', '. $cust_main->first. '<BR>';
340 $html .= $cust_main->company. '<BR>' if $cust_main->company;
341 $html .= $cust_main->address1. '<BR>';
342 $html .= $cust_main->address2. '<BR>' if $cust_main->address2;
343 $html .= $cust_main->city. ', '. $cust_main->state. ' '. $cust_main->zip. '<BR>';
344 $html .= $cust_main->country. '<BR>'
345 if $cust_main->country && $cust_main->country ne $countrydefault;
347 $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
348 if ( $cust_main->daytime && $cust_main->night ) {
350 $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
351 ' '. $cust_main->daytime.
352 '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
353 ' '. $cust_main->night;
354 } elsif ( $cust_main->daytime || $cust_main->night ) {
355 $html .= $cust_main->daytime || $cust_main->night;
357 if ( $cust_main->fax ) {
358 $html .= '<BR>Fax '. $cust_main->fax;
361 $html .= '</TD></TR></TABLE></TD>';
363 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
365 my $pre = $cust_main->ship_last ? 'ship_' : '';
367 $html .= '<TD VALIGN="top">'. ntable("#cccccc",2).
368 '<TR><TD ALIGN="right" VALIGN="top">Service<BR>Address</TD><TD BGCOLOR="#ffffff">'.
369 $cust_main->get("${pre}last"). ', '.
370 $cust_main->get("${pre}first"). '<BR>';
371 $html .= $cust_main->get("${pre}company"). '<BR>'
372 if $cust_main->get("${pre}company");
373 $html .= $cust_main->get("${pre}address1"). '<BR>';
374 $html .= $cust_main->get("${pre}address2"). '<BR>'
375 if $cust_main->get("${pre}address2");
376 $html .= $cust_main->get("${pre}city"). ', '.
377 $cust_main->get("${pre}state"). ' '.
378 $cust_main->get("${pre}ship_zip"). '<BR>';
379 $html .= $cust_main->get("${pre}country"). '<BR>'
380 if $cust_main->get("${pre}country")
381 && $cust_main->get("${pre}country") ne $countrydefault;
383 $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
385 if ( $cust_main->get("${pre}daytime") && $cust_main->get("${pre}night") ) {
387 $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
388 ' '. $cust_main->get("${pre}daytime").
389 '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
390 ' '. $cust_main->get("${pre}night");
391 } elsif ( $cust_main->get("${pre}daytime")
392 || $cust_main->get("${pre}night") ) {
393 $html .= $cust_main->get("${pre}daytime")
394 || $cust_main->get("${pre}night");
396 if ( $cust_main->get("${pre}fax") ) {
397 $html .= '<BR>Fax '. $cust_main->get("${pre}fax");
400 $html .= '</TD></TR></TABLE></TD>';
403 $html .= '</TR></TABLE>';
405 $html .= '<BR>Balance: <B>$'. $cust_main->balance. '</B><BR>'
408 # last payment might be good here too?
421 small_custview sooooo doesn't belong here. i should just switch to Mason.