display customer agent, class, tag in ticket search, #8784
[freeside.git] / rt / lib / RT / URI / freeside.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 2004 Kristian Hoffmann <khoff@fire2wire.com>
4 # Based on the original RT::URI::base and RT::URI::fsck_com_rt.
5
6 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
7
8 # (Except where explictly superceded by other copyright notices)
9
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
13 # from www.gnu.org.
14
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.
19
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.
24
25
26 # END LICENSE BLOCK
27 package RT::URI::freeside;
28
29 use base qw( RT::URI::base );
30 use strict;
31 use vars qw( $IntegrationType $URL );
32 use Carp qw( cluck );
33
34
35 =head1 NAME
36
37 RT::URI::freeside
38
39 =head1 DESCRIPTION
40
41 URI handler for Freeside URIs.  See http://www.freeside.biz/ for more
42 information on Freeside.
43
44
45 =head1 Public subroutines
46
47 =over 4
48
49 =item FreesideGetConfig CONFKEY
50
51 Subroutine that returns the freeside's configuration value(s) for CONFKEY
52 as a scalar or list.
53
54 =cut
55
56 sub FreesideGetConfig { return undef; }
57
58
59 =item FreesideURL
60
61 Returns the URL for freeside's web interface.
62
63 =cut
64
65 sub FreesideURL { return $URL; }
66
67
68 =item FreesideVersion
69
70 Returns a string describing the freeside version being used.
71
72 =cut
73
74 sub FreesideVersion { return undef; }
75
76
77 =item smart_search
78
79 A wrapper for the FS::cust_main::smart_search subroutine.
80
81 =cut
82
83 sub smart_search { return undef; }
84
85
86 =item email_search
87
88 A wrapper for the FS::cust_main::email_search subroutine.
89
90 =cut
91
92 sub email_search { return undef; }
93
94
95 =item small_custview
96
97 A wrapper for the FS::CGI::small_custview subroutine.
98
99 =cut
100
101 sub small_custview { return 'Freeside integration error!</A>'; }
102
103
104 =back
105
106 =head1 Private methods
107
108 =over 4
109
110 =item _FreesideGetRecord
111
112 Method returns a hashref of the freeside record referenced in the URI.
113 Must be called after ParseURI.
114
115 =cut
116
117 sub _FreesideGetRecord { return undef; }
118
119
120 =item _FreesideURIPrefix
121
122 Method that returns the URI prefix for freeside URIs.
123
124 =cut
125
126 sub _FreesideURIPrefix {
127
128   my $self = shift;
129   return($self->Scheme . '://freeside');
130
131 }
132
133 =item _FreesideURILabel
134
135 Method that returns a short string describing the customer referenced
136 in the URI.
137
138 =cut
139
140 sub _FreesideURILabel {
141
142   my $self = shift;
143
144   #$RT::Logger->debug("Called _FreesideURILabel()");
145
146   return unless (exists($self->{'fstable'}) and
147                  exists($self->{'fspkey'}));
148
149   my $label;
150   my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
151
152   #if ($table ne 'cust_main') {
153   #  warn "FS::${table} not currently supported";
154   #  return;
155   #}
156
157   my $rec = $self->_FreesideGetRecord();
158
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'} ) {
164     #Internal only
165     my($l,$v) = $rec->{'_object'}->label;
166     $label = "$l: $v";
167   } else {
168     $label = "$pkey: $table";
169   }
170
171   if ($label and !$@) {
172     return($label);
173   } else {
174     return;
175   }
176
177 }
178
179 =item _FreesideURILabelLong
180
181 Method that returns a longer string describing the customer referenced
182 in the URI.
183
184 =cut
185
186 sub _FreesideURILabelLong {
187
188   my $self = shift;
189
190   return $self->_FreesideURILabel();
191
192 }
193
194 =back
195
196 =head1 Public methods
197
198 =over 4
199
200 =cut
201
202 sub ParseURI { 
203     my $self = shift;
204     my $uri = shift;
205     my ($table, $pkey);
206
207     my $uriprefix = $self->_FreesideURIPrefix;
208     if ($uri =~ /^$uriprefix\/(\w+)\/(\d*)$/) {
209
210       $table = $1;
211       $pkey = $2;
212
213       unless ( $pkey ) {
214         #way too noisy, using this prefix is normal usage# cluck "bad URL $uri";
215         return(undef);
216       }
217
218       $self->{'scheme'} = $self->Scheme;
219
220     } else {
221       return(undef);
222     }
223
224     $self->{'uri'} = "${uriprefix}/${table}/${pkey}";
225     $self->{'fstable'} = $table;
226     $self->{'fspkey'} = $pkey;
227
228
229     my $url = $self->FreesideURL();
230
231     if ($url ne '') {
232       $self->{'href'} = "${url}/view/${table}.cgi?${pkey}";
233     } else {
234       $self->{'href'} = $self->{'uri'};
235     }
236
237     $self->{'uri'};
238
239 }
240
241 sub Scheme { 
242     my $self = shift;
243     return('freeside');
244
245 }
246
247 sub HREF {
248     my $self = shift;
249     return($self->{'href'} || $self->{'uri'});
250 }
251
252 sub IsLocal {
253     my $self = shift;
254     return undef;
255 }
256
257 =item AsString
258
259 Return a "pretty" string representing the URI object.
260
261 This is meant to be used like this:
262
263  % $re = $uri->Resolver;
264  <A HREF="<% $re->HREF %>"><% $re->AsString %></A>
265
266 =cut
267
268 sub AsString {
269     my $self = shift;
270     my $prettystring;
271     if ($prettystring = $self->_FreesideURILabel) {
272       return $prettystring;
273     } else {
274       return $self->URI;
275     }
276 }
277
278 =item AsStringLong
279
280 Return a longer (HTML) string representing the URI object.
281
282 =cut
283
284 sub AsStringLong {
285     my $self = shift;
286     my $prettystring;
287     if ($prettystring = $self->_FreesideURILabelLong || $self->_FreesideURILabel){
288       return $prettystring;
289     } else {
290       return $self->URI;
291     }
292 }
293
294 $IntegrationType ||= 'Internal';
295 eval "require RT::URI::freeside::${RT::URI::freeside::IntegrationType}";
296 warn $@ if $@;
297 if ($@ &&
298     $@ !~ qr(^Can't locate RT/URI/freeside/${RT::URI::freeside::IntegrationType}.pm)) {
299   die $@;
300 };
301
302 =item AgentName
303
304 Return the name of the customer's agent.
305
306 =cut
307
308 sub AgentName { undef }
309
310 =item CustomerClass
311
312 Return the name of the customer's class.
313
314 =cut
315
316 sub CustomerClass { undef }
317
318 =item CustomerTags
319
320 Return the list of tags attached to the customer.  Each tag is returned
321 as a hashref with keys "name", "desc", and "color".
322
323 =cut
324
325 sub CustomerTags { ( ) }
326
327 =back
328
329 =cut
330
331 1;