summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2015-05-29 23:05:00 -0500
committerJonathan Prykop <jonathan@freeside.biz>2015-05-29 23:05:00 -0500
commit3846acae1c2a7ecb275e400cf3802ada6bc89ed2 (patch)
treec576ed2f5e3b2eb58ff64ac55721706186d25ed7 /httemplate
parentd0ba32be1771276ed7f54c987c0e23cf496108bd (diff)
RT#25929: Customer self-service forward editing
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/edit/elements/svc_forward.html83
-rwxr-xr-xhttemplate/edit/svc_forward.cgi122
2 files changed, 106 insertions, 99 deletions
diff --git a/httemplate/edit/elements/svc_forward.html b/httemplate/edit/elements/svc_forward.html
new file mode 100644
index 000000000..e40ebe807
--- /dev/null
+++ b/httemplate/edit/elements/svc_forward.html
@@ -0,0 +1,83 @@
+<INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $opt{'svcnum'} %>">
+<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $opt{'pkgnum'} %>">
+<INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $opt{'svcpart'} %>">
+
+<SCRIPT TYPE="text/javascript">
+function srcchanged(what) {
+ if ( what.options[what.selectedIndex].value == 0 ) {
+ what.form.src.disabled = false;
+ what.form.src.style.backgroundColor = "white";
+ } else {
+ what.form.src.disabled = true;
+ what.form.src.style.backgroundColor = "lightgrey";
+ }
+}
+function dstchanged(what) {
+ if ( what.options[what.selectedIndex].value == 0 ) {
+ what.form.dst.disabled = false;
+ what.form.dst.style.backgroundColor = "white";
+ } else {
+ what.form.dst.disabled = true;
+ what.form.dst.style.backgroundColor = "lightgrey";
+ }
+}
+</SCRIPT>
+
+<% ntable("#cccccc",2) %>
+
+<TR>
+ <TD ALIGN="right">Email to</TD>
+ <TD>
+% if ( $conf->exists('svc_forward-no_srcsvc') ) {
+ <INPUT NAME="srcsrc" TYPE="hidden" VALUE="0">
+% } else {
+ <SELECT NAME="srcsvc" SIZE=1 onChange="srcchanged(this)">
+% foreach my $somesvc (keys %email) {
+ <OPTION VALUE="<% $somesvc %>"
+ <% $somesvc eq $opt{'srcsvc'} ? 'SELECTED' : '' %>
+ ><% $email{$somesvc} %></OPTION>
+% }
+ <OPTION VALUE="0" <% $opt{'src'} ? 'SELECTED' : '' %>
+ >(other email address)</OPTION>
+ </SELECT>
+% }
+
+% my $src_disabled = $opt{'src'}
+% || $conf->exists('svc_forward-no_srcsvc')
+% || !scalar(%email);
+ <INPUT NAME = "src"
+ TYPE = "text"
+ VALUE = "<% $opt{'src'} %>"
+ <% $src_disabled ? '' : 'DISABLED STYLE="background-color: lightgrey"' %>
+ >
+
+ </TD>
+</TR>
+
+<TR><TD ALIGN="right">Forwards to</TD>
+<TD><SELECT NAME="dstsvc" SIZE=1 onChange="dstchanged(this)">
+% foreach my $somesvc (keys %email) {
+
+ <OPTION<% $somesvc eq $opt{'dstsvc'} ? " SELECTED" : "" %> VALUE="<% $somesvc %>"><% $email{$somesvc} %></OPTION>
+% }
+
+<OPTION <% $opt{'dst'} ? 'SELECTED' : '' %> VALUE="0">(other email address)</OPTION>
+</SELECT>
+<INPUT TYPE="text" NAME="dst" VALUE="<% $opt{'dst'} %>" <% ( $opt{'dst'} || !scalar(%email) ) ? '' : 'DISABLED STYLE="background-color: lightgrey"' %>>
+</TD></TR>
+</TABLE>
+
+<%init>
+
+# This is used directly by selfservice, only use what's passed
+# Do not look up sensitive information here
+
+my %opt = @_;
+
+my $conf = $opt{'conf'};
+$conf ||= new FS::Conf;
+
+my %email;
+%email = %{$opt{'email'}} if ref($opt{'email'}) eq 'HASH';
+
+</%init>
diff --git a/httemplate/edit/svc_forward.cgi b/httemplate/edit/svc_forward.cgi
index 73f6465b9..de56070ec 100755
--- a/httemplate/edit/svc_forward.cgi
+++ b/httemplate/edit/svc_forward.cgi
@@ -6,74 +6,19 @@ Service #<% $svcnum ? "<B>$svcnum</B>" : " (NEW)" %><BR>
Service: <B><% $part_svc->svc %></B><BR><BR>
<FORM ACTION="process/svc_forward.cgi" METHOD="POST">
-<INPUT TYPE="hidden" NAME="svcnum" VALUE="<% $svcnum %>">
-<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">
-<INPUT TYPE="hidden" NAME="svcpart" VALUE="<% $svcpart %>">
-
-<SCRIPT TYPE="text/javascript">
-function srcchanged(what) {
- if ( what.options[what.selectedIndex].value == 0 ) {
- what.form.src.disabled = false;
- what.form.src.style.backgroundColor = "white";
- } else {
- what.form.src.disabled = true;
- what.form.src.style.backgroundColor = "lightgrey";
- }
-}
-function dstchanged(what) {
- if ( what.options[what.selectedIndex].value == 0 ) {
- what.form.dst.disabled = false;
- what.form.dst.style.backgroundColor = "white";
- } else {
- what.form.dst.disabled = true;
- what.form.dst.style.backgroundColor = "lightgrey";
- }
-}
-</SCRIPT>
-
-<% ntable("#cccccc",2) %>
-
-<TR>
- <TD ALIGN="right">Email to</TD>
- <TD>
-% if ( $conf->exists('svc_forward-no_srcsvc') ) {
- <INPUT NAME="srcsrc" TYPE="hidden" VALUE="0">
-% } else {
- <SELECT NAME="srcsvc" SIZE=1 onChange="srcchanged(this)">
-% foreach $_ (keys %email) {
- <OPTION VALUE="<% $_ %>"
- <% $_ eq $srcsvc ? 'SELECTED' : '' %>
- ><% $email{$_} %></OPTION>
-% }
- <OPTION VALUE="0" <% $src ? 'SELECTED' : '' %>
- >(other email address)</OPTION>
- </SELECT>
-% }
-
-% my $src_disabled = $src
-% || $conf->exists('svc_forward-no_srcsvc')
-% || !scalar(%email);
- <INPUT NAME = "src"
- TYPE = "text"
- VALUE = "<% $src %>"
- <% $src_disabled ? '' : 'DISABLED STYLE="background-color: lightgrey"' %>
- >
-
- </TD>
-</TR>
-
-<TR><TD ALIGN="right">Forwards to</TD>
-<TD><SELECT NAME="dstsvc" SIZE=1 onChange="dstchanged(this)">
-% foreach $_ (keys %email) {
-
- <OPTION<% $_ eq $dstsvc ? " SELECTED" : "" %> VALUE="<% $_ %>"><% $email{$_} %></OPTION>
-% }
-
-<OPTION <% $dst ? 'SELECTED' : '' %> VALUE="0">(other email address)</OPTION>
-</SELECT>
-<INPUT TYPE="text" NAME="dst" VALUE="<% $dst %>" <% ( $dst || !scalar(%email) ) ? '' : 'DISABLED STYLE="background-color: lightgrey"' %>>
-</TD></TR>
- </TABLE>
+
+<% include('elements/svc_forward.html',
+ 'conf' => $conf,
+ 'svcnum' => $svcnum,
+ 'pkgnum' => $pkgnum,
+ 'svcpart' => $svcpart,
+ 'srcsvc' => $srcsvc,
+ 'dstsvc' => $dstsvc,
+ 'src' => $src,
+ 'dst' => $dst,
+ 'email' => \%email,
+ ) %>
+
<BR><INPUT TYPE="submit" VALUE="Submit">
</FORM>
@@ -136,44 +81,23 @@ my $action = $svc_forward->svcnum ? 'Edit' : 'Add';
my %email;
-#starting with those currently attached
-foreach my $method (qw( srcsvc_acct dstsvc_acct )) {
- my $svc_acct = $svc_forward->$method();
- $email{$svc_acct->svcnum} = $svc_acct->email if $svc_acct;
-}
-
if ($pkgnum) {
#find all possible user svcnums (and emails)
- #and including the rest for this customer
- my($u_part_svc,@u_acct_svcparts);
- foreach $u_part_svc ( qsearch('part_svc',{'svcdb'=>'svc_acct'}) ) {
- push @u_acct_svcparts,$u_part_svc->getfield('svcpart');
- }
-
- my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
- my($custnum)=$cust_pkg->getfield('custnum');
- my($i_cust_pkg);
- foreach $i_cust_pkg ( qsearch('cust_pkg',{'custnum'=>$custnum}) ) {
- my($cust_pkgnum)=$i_cust_pkg->getfield('pkgnum');
- my($acct_svcpart);
- foreach $acct_svcpart (@u_acct_svcparts) { #now find the corresponding
- #record(s) in cust_svc ( for this
- #pkgnum ! )
- foreach my $i_cust_svc (
- qsearch( 'cust_svc', { 'pkgnum' => $cust_pkgnum,
- 'svcpart' => $acct_svcpart } )
- ) {
- my $svc_acct =
- qsearchs( 'svc_acct', { 'svcnum' => $i_cust_svc->svcnum } );
- $email{$svc_acct->svcnum} = $svc_acct->email;
- }
- }
- }
+ my $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
+ die "Specified package not found" unless $cust_pkg;
+ %email = $cust_pkg->forward_emails('svc_forward' => $svc_forward);
} elsif ( $action eq 'Add' ) {
+
die "\$action eq Add, but \$pkgnum is null!\n";
+
+} else {
+
+ use FS::cust_pkg;
+ %email = FS::cust_pkg->forward_emails('svc_forward' => $svc_forward);
+
}
my($srcsvc,$dstsvc,$dst)=(