3 # Copyright (c) 2004 Kristian Hoffmann <khoff@fire2wire.com>
4 # Based on the original RT::URI::base and RT::URI::fsck_com_rt.
6 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
8 # (Except where explictly superceded by other copyright notices)
10 # This work is made available to you under the terms of Version 2 of
11 # the GNU General Public License. A copy of that license should have
12 # been provided with this software, but in any event can be snarfed
15 # This work is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # General Public License for more details.
20 # Unless otherwise specified, all modifications, corrections or
21 # extensions to this work which alter its source code become the
22 # property of Best Practical Solutions, LLC when submitted for
23 # inclusion in the work.
27 package RT::URI::freeside;
29 use base qw( RT::URI::base );
31 use vars qw( $IntegrationType $URL );
41 URI handler for Freeside URIs. See http://www.freeside.biz/ for more
42 information on Freeside.
45 =head1 Public subroutines
49 =item FreesideGetConfig CONFKEY
51 Subroutine that returns the freeside's configuration value(s) for CONFKEY
56 sub FreesideGetConfig { return undef; }
61 Returns the URL for freeside's web interface.
65 sub FreesideURL { return $URL; }
70 Returns a string describing the freeside version being used.
74 sub FreesideVersion { return undef; }
79 A wrapper for the FS::cust_main::smart_search subroutine.
83 sub smart_search { return undef; }
88 A wrapper for the FS::CGI::small_custview subroutine.
92 sub small_custview { return 'Freeside integration error!</A>'; }
97 =head1 Private methods
101 =item _FreesideGetRecord
103 Method returns a hashref of the freeside record referenced in the URI.
104 Must be called after ParseURI.
108 sub _FreesideGetRecord { return undef; }
111 =item _FreesideURIPrefix
113 Method that returns the URI prefix for freeside URIs.
117 sub _FreesideURIPrefix {
120 return($self->Scheme . '://freeside');
124 =item _FreesideURILabel
126 Method that returns a short string describing the customer referenced
131 sub _FreesideURILabel {
135 #$RT::Logger->debug("Called _FreesideURILabel()");
137 return unless (exists($self->{'fstable'}) and
138 exists($self->{'fspkey'}));
141 my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
143 #if ($table ne 'cust_main') {
144 # warn "FS::${table} not currently supported";
148 my $rec = $self->_FreesideGetRecord();
150 if (ref($rec) eq 'HASH' && $table eq 'cust_main') {
151 my $name = $rec->{'last'} . ', ' . $rec->{'first'};
152 $name = $rec->{'company'} . " ($name)" if $rec->{'company'};
153 $label = "$pkey: $name";
154 } elsif ( $table eq 'cust_svc' && ref($rec) && $rec->{'_object'} ) {
156 my($l,$v) = $rec->{'_object'}->label;
159 $label = "$pkey: $table";
162 if ($label and !$@) {
170 =item _FreesideURILabelLong
172 Method that returns a longer string describing the customer referenced
177 sub _FreesideURILabelLong {
181 return $self->_FreesideURILabel();
187 =head1 Public methods
198 my $uriprefix = $self->_FreesideURIPrefix;
199 if ($uri =~ /^$uriprefix\/(\w+)\/(\d*)$/) {
205 #way too noisy, using this prefix is normal usage# cluck "bad URL $uri";
209 $self->{'scheme'} = $self->Scheme;
215 $self->{'uri'} = "${uriprefix}/${table}/${pkey}";
216 $self->{'fstable'} = $table;
217 $self->{'fspkey'} = $pkey;
220 my $url = $self->FreesideURL();
223 $self->{'href'} = "${url}/view/${table}.cgi?${pkey}";
225 $self->{'href'} = $self->{'uri'};
240 return($self->{'href'} || $self->{'uri'});
250 Return a "pretty" string representing the URI object.
252 This is meant to be used like this:
254 % $re = $uri->Resolver;
255 <A HREF="<% $re->HREF %>"><% $re->AsString %></A>
262 if ($prettystring = $self->_FreesideURILabel) {
263 return $prettystring;
271 Return a longer (HTML) string representing the URI object.
278 if ($prettystring = $self->_FreesideURILabelLong || $self->_FreesideURILabel){
279 return $prettystring;
285 $IntegrationType ||= 'Internal';
286 eval "require RT::URI::freeside::${RT::URI::freeside::IntegrationType}";
289 $@ !~ qr(^Can't locate RT/URI/freeside/${RT::URI::freeside::IntegrationType}.pm)) {