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 $HTML::Mason::Commands::r ) { #Mason
83 ## is this the correct pacakge for $r ??? for 1.0x and 1.1x ?
84 if ( $header =~ /^Content-Type$/ ) {
85 $HTML::Mason::Commands::r->content_type($value);
87 $HTML::Mason::Commands::r->header_out( $header => $value );
90 die "http_header called in unknown environment";
93 die "http_header called not running under mod_perl";
98 =item menubar ITEM, URL, ...
100 Returns an HTML menubar.
104 sub menubar { #$menubar=menubar('Main Menu', '../', 'Item', 'url', ... );
106 carp 'FS::CGI::menubar deprecated; include /elements/menubar.html instead';
108 my($item,$url,@html);
110 ($item,$url)=splice(@_,0,2);
111 next if $item =~ /^\s*Main\s+Menu\s*$/i;
112 push @html, qq!<A HREF="$url">$item</A>!;
119 This is depriciated. Don't use it.
121 Sends an HTML error message.
126 #warn "idiot depriciated";
128 # my $cgi = &FS::UID::cgi();
129 # if ( $cgi->isa('CGI::Base') ) {
131 # &CGI::Base::SendHeaders;
133 # print $cgi->header( @FS::CGI::header );
138 <TITLE>Error processing your request</TITLE>
139 <META HTTP-Equiv="Cache-Control" Content="no-cache">
140 <META HTTP-Equiv="Pragma" Content="no-cache">
141 <META HTTP-Equiv="Expires" Content="0">
145 <H4>Error processing your request</H4>
147 Your request could not be processed because of the following error:
157 This is depriciated. Don't use it.
159 Sends an HTML error message, then exits.
164 warn "eidiot depriciated";
165 $HTML::Mason::Commands::r->send_http_header
166 if defined $HTML::Mason::Commands::r;
173 You probably shouldn't use this; but if you must:
175 If running under mod_perl, calles Apache::exit, otherwise, calls exit.
180 if (exists $ENV{MOD_PERL}) {
182 if ( defined $HTML::Mason::Commands::m ) { #Mason
183 #$HTML::Mason::Commands::m->flush_buffer();
184 $HTML::Mason::Commands::m->abort();
185 die "shouldn't fall through to here (mason \$m->abort didn't)";
187 #??? well, it is $ENV{MOD_PERL}
188 warn "running under unknown mod_perl environment; trying Apache::exit()";
199 Returns current URL with LEVEL levels of path removed from the end (default 0).
205 my $cgi = &FS::UID::cgi;
206 my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
207 $url_string =~ s/\?.*//;
208 my $url = new URI::URL ( $url_string );
209 my(@path)=$url->path_components;
211 $url->path_components(@path);
212 my $x = $url->as_string;
213 $x .= '/' unless $x =~ /\/$/;
222 # better to start with the client-provided URL
223 my $cgi = &FS::UID::cgi;
224 my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
225 $url_string =~ s/\?.*//;
227 #even though this is kludgy
228 $url_string =~ s{ / index\.html /? $ }
233 (browse|config|docs|edit|graph|misc|search|view|pref|rt|elements)
241 #elements because of progress-popup.html...
242 #XXX remove anything from elements that is called directly & prevent
243 #those pages from being served up
245 $url_string .= '/' unless $url_string =~ /\/$/;
253 Returns HTML tag for beginning a table.
259 carp 'FS::CGI::table deprecated; include /elements/table.html instead';
263 qq!<TABLE BGCOLOR="$col" BORDER=1 WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">!;
265 '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
271 Returns HTML tag for beginning an (invisible) table.
277 my $cellspacing = shift || 0;
278 my $width = ( scalar(@_) && shift ) ? '' : 'WIDTH="100%"'; #bah
280 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing $width>!;
282 qq!<TABLE BORDER=0 CELLSPACING=$cellspacing $width>!;
288 This is getting silly.
294 my $cellspacing = shift || 0;
296 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
298 '<TABLE BORDER CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
303 =item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT, NOBALANCE_FLAG, URL
305 Sheesh. I should just switch to Mason.
310 use FS::Record qw(qsearchs);
314 my $countrydefault = shift || 'US';
315 my $nobalance = shift;
318 my $cust_main = ref($arg) ? $arg
319 : qsearchs('cust_main', { 'custnum' => $arg } )
320 or die "unknown custnum $arg";
324 $html = qq!View <A HREF="$url?! . $cust_main->custnum . '">'
327 $html .= 'Customer #<B>'. $cust_main->custnum. '</B></A>'.
328 ' - <B><FONT COLOR="#'. $cust_main->statuscolor. '">'.
329 ucfirst($cust_main->status). '</FONT></B>'.
330 ntable('#e8e8e8'). '<TR><TD VALIGN="top">'. ntable("#cccccc",2).
331 '<TR><TD ALIGN="right" VALIGN="top">Billing<BR>Address</TD><TD BGCOLOR="#ffffff">'.
332 $cust_main->getfield('last'). ', '. $cust_main->first. '<BR>';
334 $html .= $cust_main->company. '<BR>' if $cust_main->company;
335 $html .= $cust_main->address1. '<BR>';
336 $html .= $cust_main->address2. '<BR>' if $cust_main->address2;
337 $html .= $cust_main->city. ', '. $cust_main->state. ' '. $cust_main->zip. '<BR>';
338 $html .= $cust_main->country. '<BR>'
339 if $cust_main->country && $cust_main->country ne $countrydefault;
341 $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
342 if ( $cust_main->daytime && $cust_main->night ) {
344 $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
345 ' '. $cust_main->daytime.
346 '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
347 ' '. $cust_main->night;
348 } elsif ( $cust_main->daytime || $cust_main->night ) {
349 $html .= $cust_main->daytime || $cust_main->night;
351 if ( $cust_main->fax ) {
352 $html .= '<BR>Fax '. $cust_main->fax;
355 $html .= '</TD></TR></TABLE></TD>';
357 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
359 my $pre = $cust_main->ship_last ? 'ship_' : '';
361 $html .= '<TD VALIGN="top">'. ntable("#cccccc",2).
362 '<TR><TD ALIGN="right" VALIGN="top">Service<BR>Address</TD><TD BGCOLOR="#ffffff">'.
363 $cust_main->get("${pre}last"). ', '.
364 $cust_main->get("${pre}first"). '<BR>';
365 $html .= $cust_main->get("${pre}company"). '<BR>'
366 if $cust_main->get("${pre}company");
367 $html .= $cust_main->get("${pre}address1"). '<BR>';
368 $html .= $cust_main->get("${pre}address2"). '<BR>'
369 if $cust_main->get("${pre}address2");
370 $html .= $cust_main->get("${pre}city"). ', '.
371 $cust_main->get("${pre}state"). ' '.
372 $cust_main->get("${pre}ship_zip"). '<BR>';
373 $html .= $cust_main->get("${pre}country"). '<BR>'
374 if $cust_main->get("${pre}country")
375 && $cust_main->get("${pre}country") ne $countrydefault;
377 $html .= '</TD></TR><TR><TD></TD><TD BGCOLOR="#ffffff">';
379 if ( $cust_main->get("${pre}daytime") && $cust_main->get("${pre}night") ) {
381 $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ).
382 ' '. $cust_main->get("${pre}daytime").
383 '<BR>'. ( FS::Msgcat::_gettext('night') || 'Night' ).
384 ' '. $cust_main->get("${pre}night");
385 } elsif ( $cust_main->get("${pre}daytime")
386 || $cust_main->get("${pre}night") ) {
387 $html .= $cust_main->get("${pre}daytime")
388 || $cust_main->get("${pre}night");
390 if ( $cust_main->get("${pre}fax") ) {
391 $html .= '<BR>Fax '. $cust_main->get("${pre}fax");
394 $html .= '</TD></TR></TABLE></TD>';
397 $html .= '</TR></TABLE>';
399 $html .= '<BR>Balance: <B>$'. $cust_main->balance. '</B><BR>'
402 # last payment might be good here too?
415 small_custview sooooo doesn't belong here. i should just switch to Mason.