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;
33 @ISA = qw/RT::URI::base/;
42 URI handler for freeside URIs. See http://www.sisd.com/freeside/ for
43 more information on freeside.
48 sub FreesideURIPrefix {
51 return($self->Scheme . '://freeside');
55 sub FreesideURILabel {
59 return(undef) unless (exists($self->{'fstable'}) and
60 exists($self->{'fspkey'}));
63 my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
67 use FS::Record qw(qsearchs qsearch dbdef);
68 eval "use FS::$table;";
71 my $dbdef = dbdef or die "No dbdef";
72 my $pkeyfield = $dbdef->table($table)->primary_key
73 or die "No primary key for table $table";
75 my $rec = qsearchs($table, { $pkeyfield => $pkey })
76 or die "Record with $pkeyfield == $pkey does not exist in table $table";
78 if ($table =~ /^svc_/) {
79 if ($rec->can('cust_svc')) {
80 my $cust_svc = $rec->cust_svc or die '$rec->cust_svc failed';
81 my ($svc, $tag, $svcdb) = $cust_svc->label;
82 $label = "Freeside service ${svc}: ${tag}";
84 } elsif ($table eq 'cust_main') {
85 my ($last, $first, $company) = map { $rec->getfield($_) }
86 qw(last first company);
87 $label = "Freeside customer ${last}, ${first}";
88 $label .= ($company ne '') ? " with ${company}" : '';
90 $label = "Freeside ${table}, ${pkeyfield} == ${pkey}";
111 my $uriprefix = $self->FreesideURIPrefix;
112 if ($uri =~ /^$uriprefix\/(\w+)\/(\d+)$/) {
115 $self->{'scheme'} = $self->Scheme;
120 $self->{'uri'} = "${uriprefix}/${table}/${pkey}";
121 $self->{'fstable'} = $table;
122 $self->{'fspkey'} = $pkey;
128 use FS::CGI qw(popurl);
137 $self->{'href'} = $self->{'uri'};
139 $self->{'href'} = "${p}view/${table}.cgi?${pkey}";
154 return($self->{'href'} || $self->{'uri'});
164 Return a "pretty" string representing the URI object.
166 This is meant to be used like this:
168 % $re = $uri->Resolver;
169 <A HREF="<% $re->HREF %>"><% $re->AsString %></A>
176 if ($prettystring = $self->FreesideURILabel) {
177 return $prettystring;
183 eval "require RT::URI::base_Vendor";
184 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI/base_Vendor.pm});
185 eval "require RT::URI::base_Local";
186 die $@ if ($@ && $@ !~ qr{^Can't locate RT/URI/base_Local.pm});