part 1 of #1160: associate users w/customers, manual editing
[freeside.git] / rt / lib / RT / Interface / Web_Vendor.pm
1 # Copyright (c) 2004 Ivan Kohler <ivan-rt@420.am>
2 # Copyright (c) 2008 Freeside Internet Services, Inc.
3 #
4 # This work is made available to you under the terms of Version 2 of
5 # the GNU General Public License. A copy of that license should have
6 # been provided with this software, but in any event can be snarfed
7 # from www.gnu.org.
8
9 # This work is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # General Public License for more details.
13
14 =head1 NAME
15
16 RT::Interface::Web_Vendor
17
18 =head1 SYNOPSIS
19
20 =head1 DESCRIPTION
21
22 Freeside vendor overlay for RT::Interface::Web.
23
24 =begin testing
25
26 use_ok(RT::Interface::Web_Vendor);
27
28 =end testing
29
30 =cut
31
32 #package RT::Interface::Web;
33 #use strict;
34
35 package HTML::Mason::Commands;
36 use strict;
37
38 =head2 ProcessTicketCustomers 
39
40 =cut
41
42 sub ProcessTicketCustomers {
43     my %args = (
44         TicketObj => undef,
45         ARGSRef   => undef,
46         @_
47     );
48     my @results = ();
49
50     my $Ticket  = $args{'TicketObj'};
51     my $ARGSRef = $args{'ARGSRef'};
52
53     ### false laziness w/RT::Interface::Web::ProcessTicketLinks
54     # Delete links that are gone gone gone.
55     foreach my $arg ( keys %$ARGSRef ) {
56         if ( $arg =~ /DeleteLink-(.*?)-(DependsOn|MemberOf|RefersTo)-(.*)$/ ) {
57             my $base   = $1;
58             my $type   = $2;
59             my $target = $3;
60
61             push @results,
62               "Trying to delete: Base: $base Target: $target  Type $type";
63             my ( $val, $msg ) = $Ticket->DeleteLink( Base   => $base,
64                                                      Type   => $type,
65                                                      Target => $target );
66
67             push @results, $msg;
68
69         }
70
71     }
72     ###
73
74     my @delete_custnums =
75       map  { /^Ticket-AddCustomer-(\d+)$/; $1 }
76       grep { /^Ticket-AddCustomer-(\d+)$/ && $ARGSRef->{$_} }
77       keys %$ARGSRef;
78
79     my @custnums = map  { /^Ticket-AddCustomer-(\d+)$/; $1 }
80                    grep { /^Ticket-AddCustomer-(\d+)$/ && $ARGSRef->{$_} }
81                    keys %$ARGSRef;
82
83     foreach my $custnum ( @custnums ) {
84       my( $val, $msg ) =
85         $Ticket->AddLink( 'Type'   => 'MemberOf',
86                           'Target' => "freeside://freeside/cust_main/$custnum",
87                         );
88       push @results, $msg;
89     }
90
91     return @results;
92
93 }
94
95 #false laziness w/above... eventually it should go away in favor of this
96 sub ProcessObjectCustomers {
97     my %args = (
98         Object => undef,
99         ARGSRef   => undef,
100         @_
101     );
102     my @results = ();
103
104     my $Object  = $args{'Object'};
105     my $ARGSRef = $args{'ARGSRef'};
106
107     ### false laziness w/RT::Interface::Web::ProcessTicketLinks
108     # Delete links that are gone gone gone.
109     foreach my $arg ( keys %$ARGSRef ) {
110         if ( $arg =~ /DeleteLink-(.*?)-(DependsOn|MemberOf|RefersTo)-(.*)$/ ) {
111             my $base   = $1;
112             my $type   = $2;
113             my $target = $3;
114
115             push @results,
116               "Trying to delete: Base: $base Target: $target  Type $type";
117             my ( $val, $msg ) = $Object->DeleteLink( Base   => $base,
118                                                      Type   => $type,
119                                                      Target => $target );
120
121             push @results, $msg;
122
123         }
124
125     }
126     ###
127
128     my @delete_custnums =
129       map  { /^Object-AddCustomer-(\d+)$/; $1 }
130       grep { /^Object-AddCustomer-(\d+)$/ && $ARGSRef->{$_} }
131       keys %$ARGSRef;
132
133     my @custnums = map  { /^Object-AddCustomer-(\d+)$/; $1 }
134                    grep { /^Object-AddCustomer-(\d+)$/ && $ARGSRef->{$_} }
135                    keys %$ARGSRef;
136
137     foreach my $custnum ( @custnums ) {
138       my( $val, $msg ) =
139         $Object->AddLink( 'Type'   => 'MemberOf',
140                           'Target' => "freeside://freeside/cust_main/$custnum",
141                         );
142       push @results, $msg;
143     }
144
145     return @results;
146
147 }
148
149 1;
150