RT# 74959 - Fixed edit location link to acually save location
[freeside.git] / httemplate / edit / svc_forward.cgi
1 <% include('/elements/header.html', "Mail Forward $action") %>
2
3 <% include('/elements/error.html') %>
4
5 Service #<% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
6 Service: <B><% $part_svc->svc %></B><BR><BR>
7
8 <FORM ACTION="process/svc_forward.cgi" METHOD="POST">
9
10 <% include('elements/svc_forward.html',
11      'conf'    => $conf,
12      'svcnum'  => $svcnum,
13      'pkgnum'  => $pkgnum,
14      'svcpart' => $svcpart,
15      'srcsvc'  => $srcsvc,
16      'dstsvc'  => $dstsvc,
17      'src'     => $src,
18      'dst'     => $dst,
19      'email'   => \%email,
20    ) %>
21
22 <BR><INPUT TYPE="submit" VALUE="Submit">
23 </FORM>
24
25 <% include('/elements/footer.html') %>
26
27 <%init>
28
29 die "access denied"
30   unless $FS::CurrentUser::CurrentUser->access_right('Provision customer service'); #something else more specific?
31
32 my $conf = new FS::Conf;
33
34 my($svcnum, $pkgnum, $svcpart, $part_svc, $svc_forward);
35 if ( $cgi->param('error') ) {
36   $svc_forward = new FS::svc_forward ( {
37     map { $_, scalar($cgi->param($_)) } fields('svc_forward')
38   } );
39   $svcnum = $svc_forward->svcnum;
40   $pkgnum = $cgi->param('pkgnum');
41   $svcpart = $cgi->param('svcpart');
42   $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
43   die "No part_svc entry!" unless $part_svc;
44
45 } elsif ( $cgi->param('pkgnum') && $cgi->param('svcpart') ) { #adding
46
47   $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum';
48   $pkgnum = $1;
49   $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart';
50   $svcpart = $1;
51
52   $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
53   die "No part_svc entry!" unless $part_svc;
54
55   $svc_forward = new FS::svc_forward({});
56
57   $svcnum='';
58
59   $svc_forward->set_default_and_fixed;
60
61 } else { #editing
62
63   my($query) = $cgi->keywords;
64
65   $query =~ /^(\d+)$/ or die "unparsable svcnum";
66   $svcnum=$1;
67   $svc_forward=qsearchs('svc_forward',{'svcnum'=>$svcnum})
68     or die "Unknown (svc_forward) svcnum!";
69
70   my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum})
71     or die "Unknown (cust_svc) svcnum!";
72
73   $pkgnum=$cust_svc->pkgnum;
74   $svcpart=$cust_svc->svcpart;
75   
76   $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart});
77   die "No part_svc entry!" unless $part_svc;
78
79 }
80 my $action = $svc_forward->svcnum ? 'Edit' : 'Add';
81
82 my %email;
83
84 if ($pkgnum) {
85
86   #find all possible user svcnums (and emails)
87
88   my $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
89   die "Specified package not found" unless $cust_pkg;
90   %email = $cust_pkg->forward_emails('svc_forward' => $svc_forward);
91
92 } elsif ( $action eq 'Add' ) {
93
94   die "\$action eq Add, but \$pkgnum is null!\n";
95
96 } else {
97
98   use FS::cust_pkg;
99   %email = FS::cust_pkg->forward_emails('svc_forward' => $svc_forward);
100
101 }
102
103 my($srcsvc,$dstsvc,$dst)=(
104   $svc_forward->srcsvc,
105   $svc_forward->dstsvc,
106   $svc_forward->dst,
107 );
108 my $src = $svc_forward->dbdef_table->column('src') ? $svc_forward->src : '';
109
110 </%init>