RT#17480: Freeside Cancel Reason [small fixes]
[freeside.git] / httemplate / misc / reason-merge.html
1 % if ($success) {
2 <% include('/elements/header-popup.html', 'Reason Merge Success') %>
3 <SCRIPT>
4 window.top.location.reload()
5 </SCRIPT>
6 % } else {
7 <% include('/elements/header-popup.html', 'Merge Reasons') %>
8 %   if ($error) {
9 <P STYLE="color: red;"><% emt($error) %></P>
10 %   }
11 %   if (@reasons > 1) {
12 <P>
13 The following reasons will be merged into one.
14 Please select one reason to merge the others into.
15 </P>
16 <FORM METHOD="POST" ACTION="<% "${p}misc/reason-merge.html" %>">
17 <P>
18 %     foreach my $reason (@reasons) {
19 <INPUT TYPE="hidden" NAME="reasonnum" VALUE="<% $reason->reasonnum %>">
20 <INPUT TYPE="radio" NAME="destreasonnum" VALUE="<% $reason->reasonnum %>">
21 <% $reason->reason %><BR>
22 %     }
23 <P>
24 <P>Caution: merging reasons cannot be undone!</P>
25 <P><INPUT TYPE="submit" NAME="process_merge" value="Merge"></P>
26 </FORM>
27 %   } else {
28 <BUTTON TYPE="button" onClick="parent.cClick();">Close</BUTTON>
29 %   }
30 % }
31
32 <%init>
33 my @reasonnums = $cgi->param('reasonnum');
34 my $destreasonnum = $cgi->param('destreasonnum');
35
36 my $error;
37 my $class;
38 my @reasons;
39 my $destreason;
40 foreach my $reasonnum (@reasonnums) {
41   unless ($reasonnum =~ /^\d+$/) {
42     $error = "Invalid reasonnum $reasonnum.";
43     last;
44   }
45   my $reason = qsearchs('reason',{ 'reasonnum' => $reasonnum });
46   unless ($reason) {
47     $error = "Reason $reasonnum could not be loaded.";
48     last;
49   }
50   my $reasontype = $reason->reasontype;
51   $class ||= $reasontype->class;
52   if ($class ne $reasontype->class) {
53     $error = "Selected reasons must have the same reason type class.";
54     last;
55   }
56   push(@reasons, $reason);
57   $destreason = $reason if $reasonnum eq $destreasonnum;
58 }
59
60 unless ($error) {
61   $error = "No reasons selected." unless @reasons;
62   $error = "Select two or more reasons to merge." unless @reasons > 1;
63 }
64
65 @reasons = () if $error;
66
67 my $success = 0;
68 if ($cgi->param('process_merge') && !$error) {
69   if ($destreason) {
70     $error = $destreason->merge(\@reasons);
71     $success = 1 unless $error;
72   } else {
73     $error = "No destination reason selected.";
74   }
75 }
76
77 </%init>