4 use vars qw(@EXPORT_OK @ISA @header);
8 use CGI::Carp qw(fatalsToBrowser);
12 @EXPORT_OK = qw(header menubar idiot eidiot popurl table itable ntable
15 @header = ( '-Expires' => '-1',
16 '-Pragma' => 'no-cache',
17 '-Cache-Control' => 'no-cache' );
21 FS::CGI - Subroutines for the web interface
25 use FS::CGI qw(header menubar idiot eidiot popurl);
27 print header( 'Title', '' );
28 print header( 'Title', menubar('item', 'URL', ... ) );
30 idiot "error message";
31 eidiot "error message";
33 $url = popurl; #returns current url
34 $url = popurl(3); #three levels up
38 Provides a few common subroutines for the web interface.
44 =item header TITLE, MENUBAR
46 Returns an HTML header.
51 my($title,$menubar,$etc)=@_; #$etc is for things like onLoad= etc.
53 $etc = '' unless defined $etc;
62 <BODY BGCOLOR="#e8e8e8"$etc>
68 $x .= $menubar. "<BR><BR>" if $menubar;
72 =item menubar ITEM, URL, ...
74 Returns an HTML menubar.
78 sub menubar { #$menubar=menubar('Main Menu', '../', 'Item', 'url', ... );
81 ($item,$url)=splice(@_,0,2);
82 push @html, qq!<A HREF="$url">$item</A>!;
89 This is depriciated. Don't use it.
91 Sends headers and an HTML error message.
96 #warn "idiot depriciated";
98 my $cgi = &FS::UID::cgi();
99 # if ( $cgi->isa('CGI::Base') ) {
101 # &CGI::Base::SendHeaders;
103 print $cgi->header( @FS::CGI::header );
108 <TITLE>Error processing your request</TITLE>
112 <H4>Error processing your request</H4>
114 Your request could not be processed because of the following error:
124 This is depriciated. Don't use it.
126 Sends headers and an HTML error message, then exits.
131 warn "eidiot depriciated";
133 if (exists $ENV{MOD_PERL}) {
134 $main::Response->End()
135 if defined $main::Response
136 && $main::Response->isa('Apache::ASP::Response');
146 Returns current URL with LEVEL levels of path removed from the end (default 0).
152 my $cgi = &FS::UID::cgi;
153 my $url = new URI::URL ( $cgi->isa('Apache') ? $cgi->uri : $cgi->url );
154 my(@path)=$url->path_components;
156 $url->path_components(@path);
157 my $x = $url->as_string;
158 $x .= '/' unless $x =~ /\/$/;
164 Returns HTML tag for beginning a table.
171 qq!<TABLE BGCOLOR="$col" BORDER=1 WIDTH="100%">!;
179 Returns HTML tag for beginning an (invisible) table.
185 my $cellspacing = shift || 0;
187 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing WIDTH="100%">!;
189 qq!<TABLE BORDER=0 CELLSPACING=$cellspacing WIDTH="100%">!;
195 This is getting silly.
201 my $cellspacing = shift || 0;
203 qq!<TABLE BGCOLOR="$col" BORDER=0 CELLSPACING=$cellspacing>!;
210 =item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT
212 Sheesh. I should just switch to Mason.
217 use FS::Record qw(qsearchs);
221 my $countrydefault = shift || 'US';
223 my $cust_main = ref($arg) ? $arg
224 : qsearchs('cust_main', { 'custnum' => $arg } )
225 or die "unknown custnum $arg";
227 my $html = 'Customer #<B>'. $cust_main->custnum. '</B>'.
228 ntable('#e8e8e8'). '<TR><TD>'. ntable("#cccccc",2).
229 '<TR><TD ALIGN="right" VALIGN="top">Billing</TD><TD BGCOLOR="#ffffff">'.
230 $cust_main->getfield('last'). ', '. $cust_main->first. '<BR>';
232 $html .= $cust_main->company. '<BR>' if $cust_main->company;
233 $html .= $cust_main->address1. '<BR>';
234 $html .= $cust_main->address2. '<BR>' if $cust_main->address2;
235 $html .= $cust_main->city. ', '. $cust_main->state. ' '. $cust_main->zip. '<BR>';
236 $html .= $cust_main->country. '<BR>'
237 if $cust_main->country && $cust_main->country ne $countrydefault;
239 $html .= '</TD></TR></TABLE></TD>';
241 if ( defined $cust_main->dbdef_table->column('ship_last') ) {
243 my $pre = $cust_main->ship_last ? 'ship_' : '';
245 $html .= '<TD>'. ntable("#cccccc",2).
246 '<TR><TD ALIGN="right" VALIGN="top">Service</TD><TD BGCOLOR="#ffffff">'.
247 $cust_main->get("${pre}last"). ', '.
248 $cust_main->get("${pre}first"). '<BR>';
249 $html .= $cust_main->get("${pre}company"). '<BR>'
250 if $cust_main->get("${pre}company");
251 $html .= $cust_main->get("${pre}address1"). '<BR>';
252 $html .= $cust_main->get("${pre}address2"). '<BR>'
253 if $cust_main->get("${pre}address2");
254 $html .= $cust_main->get("${pre}city"). ', '.
255 $cust_main->get("${pre}state"). ' '.
256 $cust_main->get("${pre}ship_zip"). '<BR>';
257 $html .= $cust_main->get("${pre}country"). '<BR>'
258 if $cust_main->get("${pre}country")
259 && $cust_main->get("${pre}country") ne $countrydefault;
261 $html .= '</TD></TR></TABLE></TD>';
264 $html .= '</TR></TABLE>';
277 small_custview sooooo doesn't belong here. i should just switch to Mason.