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::cust_main::email_search subroutine.
92 sub email_search { return undef; }
97 A wrapper for the FS::CGI::small_custview subroutine.
101 sub small_custview { return 'Freeside integration error!</A>'; }
106 =head1 Private methods
110 =item _FreesideGetRecord
112 Method returns a hashref of the freeside record referenced in the URI.
113 Must be called after ParseURI.
117 sub _FreesideGetRecord { return undef; }
120 =item _FreesideURIPrefix
122 Method that returns the URI prefix for freeside URIs.
126 sub _FreesideURIPrefix {
129 return($self->Scheme . '://freeside');
133 =item _FreesideURILabel
135 Method that returns a short string describing the customer referenced
140 sub _FreesideURILabel {
144 #$RT::Logger->debug("Called _FreesideURILabel()");
146 return unless (exists($self->{'fstable'}) and
147 exists($self->{'fspkey'}));
150 my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
152 #if ($table ne 'cust_main') {
153 # warn "FS::${table} not currently supported";
157 my $rec = $self->_FreesideGetRecord();
159 if (ref($rec) eq 'HASH' && $table eq 'cust_main') {
160 my $name = $rec->{'last'} . ', ' . $rec->{'first'};
161 $name = $rec->{'company'} . " ($name)" if $rec->{'company'};
162 $label = "$pkey: $name";
163 } elsif ( $table eq 'cust_svc' && ref($rec) && $rec->{'_object'} ) {
165 my($l,$v) = $rec->{'_object'}->label;
168 $label = "$pkey: $table";
171 if ($label and !$@) {
179 =item _FreesideURILabelLong
181 Method that returns a longer string describing the customer referenced
186 sub _FreesideURILabelLong {
190 return $self->_FreesideURILabel();
196 =head1 Public methods
207 my $uriprefix = $self->_FreesideURIPrefix;
208 if ($uri =~ /^$uriprefix\/(\w+)\/(\d*)$/) {
214 #way too noisy, using this prefix is normal usage# cluck "bad URL $uri";
218 $self->{'scheme'} = $self->Scheme;
224 $self->{'uri'} = "${uriprefix}/${table}/${pkey}";
225 $self->{'fstable'} = $table;
226 $self->{'fspkey'} = $pkey;
229 my $url = $self->FreesideURL();
232 $self->{'href'} = "${url}/view/${table}.cgi?${pkey}";
234 $self->{'href'} = $self->{'uri'};
249 return($self->{'href'} || $self->{'uri'});
259 Return a "pretty" string representing the URI object.
261 This is meant to be used like this:
263 % $re = $uri->Resolver;
264 <A HREF="<% $re->HREF %>"><% $re->AsString %></A>
271 if ($prettystring = $self->_FreesideURILabel) {
272 return $prettystring;
280 Return a longer (HTML) string representing the URI object.
287 if ($prettystring = $self->_FreesideURILabelLong || $self->_FreesideURILabel){
288 return $prettystring;
294 $IntegrationType ||= 'Internal';
295 eval "require RT::URI::freeside::${RT::URI::freeside::IntegrationType}";
298 $@ !~ qr(^Can't locate RT/URI/freeside/${RT::URI::freeside::IntegrationType}.pm)) {
304 Return a hashref of customer information, including all fields from
305 C<cust_main> as well as:
307 - AgentName: the name of the customer's agent
308 - CustomerClass: the name of the customer's class
309 - CustomerTags: an arrayref of tags attached to the customer, each
310 as a hashref with keys "name", "desc", and "color".
311 - Referral: the name of the customer's advertising source.
315 sub CustomerInfo { {} }