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;
31 use vars qw(@ISA $IntegrationType $URL);
32 @ISA = qw/RT::URI::base/;
41 URI handler for freeside URIs. See http://www.sisd.com/freeside/ for
42 more 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' and $table eq 'cust_main') {
151 my $name = $rec->{'last'} . ', ' . $rec->{'first'};
152 $name = $rec->{'company'} . " ($name)" if $rec->{'company'};
153 $label = "$pkey: $name";
155 $label = "$pkey: $table";
158 if ($label and !$@) {
166 =item _FreesideURILabelLong
168 Method that returns a longer string describing the customer referenced
173 sub _FreesideURILabelLong {
177 return $self->_FreesideURILabel();
183 =head1 Public methods
194 my $uriprefix = $self->_FreesideURIPrefix;
195 if ($uri =~ /^$uriprefix\/(\w+)\/(\d+)$/) {
198 $self->{'scheme'} = $self->Scheme;
203 $self->{'uri'} = "${uriprefix}/${table}/${pkey}";
204 $self->{'fstable'} = $table;
205 $self->{'fspkey'} = $pkey;
208 my $url = $self->FreesideURL();
211 $self->{'href'} = "${url}/view/${table}.cgi?${pkey}";
213 $self->{'href'} = $self->{'uri'};
228 return($self->{'href'} || $self->{'uri'});
238 Return a "pretty" string representing the URI object.
240 This is meant to be used like this:
242 % $re = $uri->Resolver;
243 <A HREF="<% $re->HREF %>"><% $re->AsString %></A>
250 if ($prettystring = $self->_FreesideURILabel) {
251 return $prettystring;
259 Return a longer (HTML) string representing the URI object.
266 if ($prettystring = $self->_FreesideURILabelLong || $self->_FreesideURILabel){
267 return $prettystring;
273 $IntegrationType ||= 'Internal';
274 eval "require RT::URI::freeside::${RT::URI::freeside::IntegrationType}";
277 $@ !~ qr(^Can't locate RT/URI/freeside/${RT::URI::freeside::IntegrationType}.pm)) {