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);
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;
71 =item menubar ITEM, URL, ...
73 Returns an HTML menubar.
77 sub menubar { #$menubar=menubar('Main Menu', '../', 'Item', 'url', ... );
80 ($item,$url)=splice(@_,0,2);
81 push @html, qq!<A HREF="$url">$item</A>!;
88 This is depriciated. Don't use it.
90 Sends an HTML error message.
95 #warn "idiot depriciated";
97 # my $cgi = &FS::UID::cgi();
98 # if ( $cgi->isa('CGI::Base') ) {
100 # &CGI::Base::SendHeaders;
102 # print $cgi->header( @FS::CGI::header );
107 <TITLE>Error processing your request</TITLE>
108 <META HTTP-Equiv="Cache-Control" Content="no-cache">
109 <META HTTP-Equiv="Pragma" Content="no-cache">
110 <META HTTP-Equiv="Expires" Content="0">
114 <H4>Error processing your request</H4>
116 Your request could not be processed because of the following error:
126 This is depriciated. Don't use it.
128 Sends an HTML error message, then exits.
133 warn "eidiot depriciated";
134 $HTML::Mason::Commands::r->send_http_header
135 if defined $HTML::Mason::Commands::r;
142 You probably shouldn't use this; but if you must:
144 If running under mod_perl, calles Apache::exit, otherwise, calls exit.
149 if (exists $ENV{MOD_PERL}) {
151 if ( defined $main::Response
152 && $main::Response->isa('Apache::ASP::Response') ) { #Apache::ASP
153 $main::Response->End();
156 } elsif ( defined $HTML::Mason::Commands::m ) { #Mason
157 #$HTML::Mason::Commands::m->flush_buffer();
158 $HTML::Mason::Commands::m->abort();
159 die "shouldn't fall through to here (mason \$m->abort didn't)";
161 #??? well, it is $ENV{MOD_PERL}
162 warn "running under unknown mod_perl environment; trying Apache::exit()";
173 Returns current URL with LEVEL levels of path removed from the end (default 0).
179 my $cgi = &FS::UID::cgi;
180 my $url = new URI::URL ( $cgi->isa('Apache') ? $cgi->uri : $cgi->url );
181 my(@path)=$url->path_components;
183 $url->path_components(@path);
184 my $x = $url->as_string;
185 $x .= '/' unless $x =~ /\/$/;
191 Returns HTML tag for beginning a table.
198 qq!<TABLE BGCOLOR="$col" BORDER=1 WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">!;
200 '<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
206 Returns HTML tag for beginning an (invisible) table.
212 my $cellspacing = shift || 0;
214 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing WIDTH="100%">!;
216 qq!<TABLE BORDER=0 CELLSPACING=$cellspacing WIDTH="100%">!;
222 This is getting silly.
228 my $cellspacing = shift || 0;
230 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
232 '<TABLE BORDER CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">';
237 =item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT
239 Sheesh. I should just switch to Mason.
244 use FS::Record qw(qsearchs);
248 my $countrydefault = shift || 'US';
250 my $cust_main = ref($arg) ? $arg
251 : qsearchs('cust_main', { 'custnum' => $arg } )
252 or die "unknown custnum $arg";
254 my $html = 'Customer #<B>'. $cust_main->custnum. '</B>'.
255 ntable('#e8e8e8'). '<TR><TD>'. ntable("#cccccc",2).
256 '<TR><TD ALIGN="right" VALIGN="top">Billing<BR>Address</TD><TD BGCOLOR="#ffffff">'.
257 $cust_main->getfield('last'). ', '. $cust_main->first. '<BR>';
259 $html .= $cust_main->company. '<BR>' if $cust_main->company;
260 $html .= $cust_main->address1. '<BR>';
261 $html .= $cust_main->address2. '<BR>' if $cust_main->address2;
262 $html .= $cust_main->city. ', '. $cust_main->state. ' '. $cust_main->zip. '<BR>';
263 $html .= $cust_main->country. '<BR>'
264 if $cust_main->country && $cust_main->country ne $countrydefault;
266 $html .= '</TD></TR></TABLE></TD>';
268 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
270 my $pre = $cust_main->ship_last ? 'ship_' : '';
272 $html .= '<TD>'. ntable("#cccccc",2).
273 '<TR><TD ALIGN="right" VALIGN="top">Service<BR>Address</TD><TD BGCOLOR="#ffffff">'.
274 $cust_main->get("${pre}last"). ', '.
275 $cust_main->get("${pre}first"). '<BR>';
276 $html .= $cust_main->get("${pre}company"). '<BR>'
277 if $cust_main->get("${pre}company");
278 $html .= $cust_main->get("${pre}address1"). '<BR>';
279 $html .= $cust_main->get("${pre}address2"). '<BR>'
280 if $cust_main->get("${pre}address2");
281 $html .= $cust_main->get("${pre}city"). ', '.
282 $cust_main->get("${pre}state"). ' '.
283 $cust_main->get("${pre}ship_zip"). '<BR>';
284 $html .= $cust_main->get("${pre}country"). '<BR>'
285 if $cust_main->get("${pre}country")
286 && $cust_main->get("${pre}country") ne $countrydefault;
288 $html .= '</TD></TR></TABLE></TD>';
291 $html .= '</TR></TABLE>';
304 small_custview sooooo doesn't belong here. i should just switch to Mason.