badly placed small_custview all of a sudden causing fatal errors?! wtf
[freeside.git] / rt / lib / RT / URI / freeside / Internal.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 #
28 use strict;
29 no warnings qw(redefine);
30
31 #use vars qw($conf);
32
33 use FS;
34 use FS::UID qw(dbh);
35 use FS::CGI qw(popurl);
36 use FS::UI::Web::small_custview qw(small_custview);
37 use FS::Conf;
38 use FS::Record qw(qsearchs qsearch dbdef);
39 use FS::cust_main;
40 use FS::cust_svc;
41
42 =head1 NAME
43
44 RT::URI::freeside::Internal
45
46 =head1 DESCRIPTION
47
48 Overlay for the RT::URI::freeside URI handler implementing the Internal integration type.
49
50 See L<RT::URI::freeside> for public/private interface documentation.
51
52 =cut
53
54
55
56 sub _FreesideGetRecord {
57
58   my $self = shift;
59   my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
60
61   $RT::Logger->debug("Called _FreesideGetRecord()");
62
63   #eval "use FS::$table;";
64
65   my $dbdef = dbdef;
66   unless ($dbdef) {
67     $RT::Logger->error("Using Internal freeside integration type, ".
68                        "but it doesn't look like we're running under ".
69                        "freeside's Mason handler.");
70     return;
71   }
72
73   my $pkeyfield = $dbdef->table($table)->primary_key;
74   unless ($pkeyfield) {
75     $RT::Logger->error("No primary key for freeside table '$table'");
76     return;
77   }
78
79   my $fsrec = qsearchs($table, { $pkeyfield => $pkey });
80   unless ($fsrec) {
81     $RT::Logger->error("Record with '$pkeyfield' == '$pkey' does " .
82                        "not exist in table $table");
83     return;
84   }
85
86   return { $fsrec->hash, '_object' => $fsrec };
87
88 }
89
90 sub FreesideVersion {
91
92   return $FS::VERSION;
93
94 }
95
96 sub FreesideGetConfig {
97
98   #$conf = new FS::Conf unless ref($conf);
99   my $conf = new FS::Conf;
100
101   return scalar($conf->config(@_));
102
103 }
104
105 sub smart_search { #Subroutine
106
107   return map { { $_->hash } } &FS::cust_main::smart_search(@_);
108
109 }
110
111 sub email_search { #Subroutine
112
113   return map { { $_->hash } } &FS::cust_main::email_search(@_);
114
115 }
116
117 sub small_custview {
118
119   return &FS::UI::Web::small_custview::small_custview(@_);
120
121 }
122
123 sub _FreesideURILabelLong {
124
125   my $self = shift;
126
127   my $table = $self->{'fstable'};
128
129   if ( $table eq 'cust_main' ) {
130
131     my $rec = $self->_FreesideGetRecord();
132     return small_custview( $rec->{'_object'},
133                            scalar(FS::Conf->new->config('countrydefault')),
134                            1 #nobalance
135                          );
136
137   } else {
138
139     return $self->_FreesideURILabel();
140
141   }
142
143 }
144
145 1;