X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FCGI.pm;h=8b401da363a7f44745169934a0202ae331be8955;hb=3758ad3cb13752bbbebb2c42fcc398bdb1ffdc6a;hp=190c0aa37f1a9ea191fe774d25d21768847b6e8f;hpb=b4d4e05b95414fc334bf80474a0c10f639ac4ba1;p=freeside.git diff --git a/FS/FS/CGI.pm b/FS/FS/CGI.pm index 190c0aa37..8b401da36 100644 --- a/FS/FS/CGI.pm +++ b/FS/FS/CGI.pm @@ -1,7 +1,7 @@ package FS::CGI; use strict; -use vars qw(@EXPORT_OK @ISA @header); +use vars qw(@EXPORT_OK @ISA); use Exporter; use CGI; use URI::URL; @@ -9,8 +9,8 @@ use URI::URL; use FS::UID; @ISA = qw(Exporter); -@EXPORT_OK = qw(header menubar idiot eidiot popurl table itable ntable - small_custview myexit); +@EXPORT_OK = qw(header menubar idiot eidiot popurl rooturl table itable ntable + small_custview myexit http_header); =head1 NAME @@ -44,8 +44,10 @@ Returns an HTML header. =cut sub header { + use Carp; + carp 'FS::CGI::header deprecated; include /elements/header.html instead'; + my($title,$menubar,$etc)=@_; #$etc is for things like onLoad= etc. - #use Carp; $etc = '' unless defined $etc; my $x = < - - $title + +
$title
-

+
END $x .= $menubar. "

" if $menubar; $x; } +=item http_header + +Sets an http header. + +=cut + +sub http_header { + my ( $header, $value ) = @_; + if (exists $ENV{MOD_PERL}) { + if ( defined $main::Response + && $main::Response->isa('Apache::ASP::Response') ) { #Apache::ASP + if ( $header =~ /^Content-Type$/ ) { + $main::Response->{ContentType} = $value; + } else { + $main::Response->AddHeader( $header => $value ); + } + } elsif ( defined $HTML::Mason::Commands::r ) { #Mason + ## is this the correct pacakge for $r ??? for 1.0x and 1.1x ? + if ( $header =~ /^Content-Type$/ ) { + $HTML::Mason::Commands::r->content_type($value); + } else { + $HTML::Mason::Commands::r->header_out( $header => $value ); + } + } else { + die "http_header called in unknown environment"; + } + } else { + die "http_header called not running under mod_perl"; + } + +} + =item menubar ITEM, URL, ... Returns an HTML menubar. @@ -75,9 +109,13 @@ Returns an HTML menubar. =cut sub menubar { #$menubar=menubar('Main Menu', '../', 'Item', 'url', ... ); + use Carp; + carp 'FS::CGI::menubar deprecated; include /elements/menubar.html instead'; + my($item,$url,@html); while (@_) { ($item,$url)=splice(@_,0,2); + next if $item =~ /^\s*Main\s+Menu\s*$/i; push @html, qq!$item!; } join(' | ',@html); @@ -177,7 +215,9 @@ Returns current URL with LEVEL levels of path removed from the end (default 0). sub popurl { my($up)=@_; my $cgi = &FS::UID::cgi; - my $url = new URI::URL ( $cgi->isa('Apache') ? $cgi->uri : $cgi->url ); + my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url; + $url_string =~ s/\?.*//; + my $url = new URI::URL ( $url_string ); my(@path)=$url->path_components; splice @path, 0-$up; $url->path_components(@path); @@ -186,6 +226,31 @@ sub popurl { $x; } +=item rooturl + +=cut + +sub rooturl { + # better to start with the client-provided URL + my $cgi = &FS::UID::cgi; + my $url_string = $cgi->isa('Apache') ? $cgi->uri : $cgi->url; + $url_string =~ s/\?.*//; + + #even though this is kludgy + $url_string =~ + s{ + (browse|config|docs|edit|graph|misc|search|view|pref) + / + (process/)? + ([\w\-\.]+) + $ + } + {}x; + + $url_string; + +} + =item table Returns HTML tag for beginning a table. @@ -193,6 +258,9 @@ Returns HTML tag for beginning a table. =cut sub table { + use Carp; + carp 'FS::CGI::table deprecated; include /elements/table.html instead'; + my $col = shift; if ( $col ) { qq!!; @@ -210,10 +278,11 @@ Returns HTML tag for beginning an (invisible) table. sub itable { my $col = shift; my $cellspacing = shift || 0; + my $width = ( scalar(@_) && shift ) ? '' : 'WIDTH="100%"'; #bah if ( $col ) { - qq!
!; + qq!
!; } else { - qq!
!; + qq!
!; } } @@ -234,7 +303,7 @@ sub ntable { } -=item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT +=item small_custview CUSTNUM || CUST_MAIN_OBJECT, COUNTRYDEFAULT, NOBALANCE_FLAG Sheesh. I should just switch to Mason. @@ -246,14 +315,17 @@ sub small_custview { my $arg = shift; my $countrydefault = shift || 'US'; + my $nobalance = shift; my $cust_main = ref($arg) ? $arg : qsearchs('cust_main', { 'custnum' => $arg } ) or die "unknown custnum $arg"; - my $html = 'Customer #'. $cust_main->custnum. ''. - ntable('#e8e8e8'). '
'. ntable("#cccccc",2). - '
Billing'. + my $html = 'Customer #'. $cust_main->custnum. ''. + ' - '. + ucfirst($cust_main->status). ''. + ntable('#e8e8e8'). '
'. ntable("#cccccc",2). + '
Billing
Address
'. $cust_main->getfield('last'). ', '. $cust_main->first. '
'; $html .= $cust_main->company. '
' if $cust_main->company; @@ -263,14 +335,28 @@ sub small_custview { $html .= $cust_main->country. '
' if $cust_main->country && $cust_main->country ne $countrydefault; + $html .= '
'; + if ( $cust_main->daytime && $cust_main->night ) { + use FS::Msgcat; + $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ). + ' '. $cust_main->daytime. + '
'. ( FS::Msgcat::_gettext('night') || 'Night' ). + ' '. $cust_main->night; + } elsif ( $cust_main->daytime || $cust_main->night ) { + $html .= $cust_main->daytime || $cust_main->night; + } + if ( $cust_main->fax ) { + $html .= '
Fax '. $cust_main->fax; + } + $html .= '
'; if ( defined $cust_main->dbdef_table->column('ship_last') ) { my $pre = $cust_main->ship_last ? 'ship_' : ''; - $html .= ''. ntable("#cccccc",2). - 'Service'. + $html .= ''. ntable("#cccccc",2). + 'Service
Address'. $cust_main->get("${pre}last"). ', '. $cust_main->get("${pre}first"). '
'; $html .= $cust_main->get("${pre}company"). '
' @@ -285,11 +371,33 @@ sub small_custview { if $cust_main->get("${pre}country") && $cust_main->get("${pre}country") ne $countrydefault; + $html .= ''; + + if ( $cust_main->get("${pre}daytime") && $cust_main->get("${pre}night") ) { + use FS::Msgcat; + $html .= ( FS::Msgcat::_gettext('daytime') || 'Day' ). + ' '. $cust_main->get("${pre}daytime"). + '
'. ( FS::Msgcat::_gettext('night') || 'Night' ). + ' '. $cust_main->get("${pre}night"); + } elsif ( $cust_main->get("${pre}daytime") + || $cust_main->get("${pre}night") ) { + $html .= $cust_main->get("${pre}daytime") + || $cust_main->get("${pre}night"); + } + if ( $cust_main->get("${pre}fax") ) { + $html .= '
Fax '. $cust_main->get("${pre}fax"); + } + $html .= ''; } $html .= ''; + $html .= '
Balance: $'. $cust_main->balance. '
' + unless $nobalance; + + # last payment might be good here too? + $html; }