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