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