4 use vars qw(@EXPORT_OK @ISA);
8 #use CGI::Carp qw(fatalsToBrowser);
12 @EXPORT_OK = qw(header menubar idiot eidiot popurl 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.
47 my($title,$menubar,$etc)=@_; #$etc is for things like onLoad= etc.
49 $etc = '' unless defined $etc;
57 <META HTTP-Equiv="Cache-Control" Content="no-cache">
58 <META HTTP-Equiv="Pragma" Content="no-cache">
59 <META HTTP-Equiv="Expires" Content="0">
61 <BODY BGCOLOR="#e8e8e8"$etc>
67 $x .= $menubar. "<BR><BR>" if $menubar;
78 my ( $header, $value ) = @_;
79 if (exists $ENV{MOD_PERL}) {
80 if ( defined $main::Response
81 && $main::Response->isa('Apache::ASP::Response') ) { #Apache::ASP
82 if ( $header =~ /^Content-Type$/ ) {
83 $main::Response->{ContentType} = $value;
85 $main::Response->AddHeader( $header => $value );
87 } elsif ( defined $HTML::Mason::Commands::r ) { #Mason
88 ## is this the correct pacakge for $r ??? for 1.0x and 1.1x ?
89 if ( $header =~ /^Content-Type$/ ) {
90 $HTML::Mason::Commands::r->content_type($value);
92 $HTML::Mason::Commands::r->header_out( $header => $value );
95 die "http_header called in unknown environment";
98 die "http_header called not running under mod_perl";
103 =item menubar ITEM, URL, ...
105 Returns an HTML menubar.
109 sub menubar { #$menubar=menubar('Main Menu', '../', 'Item', 'url', ... );
110 my($item,$url,@html);
112 ($item,$url)=splice(@_,0,2);
113 push @html, qq!<A HREF="$url">$item</A>!;
120 This is depriciated. Don't use it.
122 Sends an HTML error message.
127 #warn "idiot depriciated";
129 # my $cgi = &FS::UID::cgi();
130 # if ( $cgi->isa('CGI::Base') ) {
132 # &CGI::Base::SendHeaders;
134 # print $cgi->header( @FS::CGI::header );
139 <TITLE>Error processing your request</TITLE>
140 <META HTTP-Equiv="Cache-Control" Content="no-cache">
141 <META HTTP-Equiv="Pragma" Content="no-cache">
142 <META HTTP-Equiv="Expires" Content="0">
146 <H4>Error processing your request</H4>
148 Your request could not be processed because of the following error:
158 This is depriciated. Don't use it.
160 Sends an HTML error message, then exits.
165 warn "eidiot depriciated";
166 $HTML::Mason::Commands::r->send_http_header
167 if defined $HTML::Mason::Commands::r;
174 You probably shouldn't use this; but if you must:
176 If running under mod_perl, calles Apache::exit, otherwise, calls exit.
181 if (exists $ENV{MOD_PERL}) {
183 if ( defined $main::Response
184 && $main::Response->isa('Apache::ASP::Response') ) { #Apache::ASP
185 $main::Response->End();
188 } elsif ( defined $HTML::Mason::Commands::m ) { #Mason
189 #$HTML::Mason::Commands::m->flush_buffer();
190 $HTML::Mason::Commands::m->abort();
191 die "shouldn't fall through to here (mason \$m->abort didn't)";
193 #??? well, it is $ENV{MOD_PERL}
194 warn "running under unknown mod_perl environment; trying Apache::exit()";
205 Returns current URL with LEVEL levels of path removed from the end (default 0).
211 my $cgi = &FS::UID::cgi;
212 my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url;
213 $url_string =~ s/\?.*//;
214 my $url = new URI::URL ( $url_string );
215 my(@path)=$url->path_components;
217 $url->path_components(@path);
218 my $x = $url->as_string;
219 $x .= '/' unless $x =~ /\/$/;
225 Returns HTML tag for beginning a table.
232 qq!<TABLE BGCOLOR="$col" BORDER=1 WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">!;
234 '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
240 Returns HTML tag for beginning an (invisible) table.
246 my $cellspacing = shift || 0;
248 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing WIDTH="100%">!;
250 qq!<TABLE BORDER=0 CELLSPACING=$cellspacing WIDTH="100%">!;
256 This is getting silly.
262 my $cellspacing = shift || 0;
264 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
266 '<TABLE BORDER CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
271 =item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT
273 Sheesh. I should just switch to Mason.
278 use FS::Record qw(qsearchs);
282 my $countrydefault = shift || 'US';
284 my $cust_main = ref($arg) ? $arg
285 : qsearchs('cust_main', { 'custnum' => $arg } )
286 or die "unknown custnum $arg";
288 my $html = 'Customer #<B>'. $cust_main->custnum. '</B>'.
289 ntable('#e8e8e8'). '<TR><TD>'. ntable("#cccccc",2).
290 '<TR><TD ALIGN="right" VALIGN="top">Billing<BR>Address</TD><TD BGCOLOR="#ffffff">'.
291 $cust_main->getfield('last'). ', '. $cust_main->first. '<BR>';
293 $html .= $cust_main->company. '<BR>' if $cust_main->company;
294 $html .= $cust_main->address1. '<BR>';
295 $html .= $cust_main->address2. '<BR>' if $cust_main->address2;
296 $html .= $cust_main->city. ', '. $cust_main->state. ' '. $cust_main->zip. '<BR>';
297 $html .= $cust_main->country. '<BR>'
298 if $cust_main->country && $cust_main->country ne $countrydefault;
300 $html .= '</TD></TR></TABLE></TD>';
302 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
304 my $pre = $cust_main->ship_last ? 'ship_' : '';
306 $html .= '<TD>'. ntable("#cccccc",2).
307 '<TR><TD ALIGN="right" VALIGN="top">Service<BR>Address</TD><TD BGCOLOR="#ffffff">'.
308 $cust_main->get("${pre}last"). ', '.
309 $cust_main->get("${pre}first"). '<BR>';
310 $html .= $cust_main->get("${pre}company"). '<BR>'
311 if $cust_main->get("${pre}company");
312 $html .= $cust_main->get("${pre}address1"). '<BR>';
313 $html .= $cust_main->get("${pre}address2"). '<BR>'
314 if $cust_main->get("${pre}address2");
315 $html .= $cust_main->get("${pre}city"). ', '.
316 $cust_main->get("${pre}state"). ' '.
317 $cust_main->get("${pre}ship_zip"). '<BR>';
318 $html .= $cust_main->get("${pre}country"). '<BR>'
319 if $cust_main->get("${pre}country")
320 && $cust_main->get("${pre}country") ne $countrydefault;
322 $html .= '</TD></TR></TABLE></TD>';
325 $html .= '</TR></TABLE>';
327 $html .= '<BR>Balance: <B>$'. $cust_main->balance. '</B><BR>';
329 # last payment might be good here too?
342 small_custview sooooo doesn't belong here. i should just switch to Mason.