5 include( '/elements/tr-select-reason.html',
8 'field' => 'reasonnum',
9 'reason_class' => 'C', # currently 'C', 'R', or 'S'
10 # for cancel, credit, or suspend
13 'cgi' => $cgi, #easiest way for things to be properly "sticky" on errors
16 'control_button' => 'element_name', #button to be enabled when a reason is
20 #deprecated ways to keep things "sticky" on errors
21 # (requires duplicate code in each using file to parse cgi params)
22 'curr_value' => $curr_value,
24 'typenum' => $typenum,
32 <SCRIPT TYPE="text/javascript">
33 function sh_add<% $func_suffix %>()
36 if (document.getElementById('<% $id %>').selectedIndex == 0){
37 <% $controlledbutton ? $controlledbutton.'.disabled = true;' : ';' %>
39 <% $controlledbutton ? $controlledbutton.'.disabled = false;' : ';' %>
42 %if ($curuser->access_right($add_access_right)){
44 if (document.getElementById('<% $id %>').selectedIndex ==
45 (document.getElementById('<% $id %>').length - 1)) {
46 document.getElementById('new<% $id %>').disabled = false;
47 document.getElementById('new<% $id %>').style.display = 'inline';
48 document.getElementById('new<% $id %>Label').style.display = 'inline';
49 document.getElementById('new<% $id %>T').disabled = false;
50 document.getElementById('new<% $id %>T').style.display = 'inline';
51 document.getElementById('new<% $id %>TLabel').style.display = 'inline';
53 document.getElementById('new<% $id %>').disabled = true;
54 document.getElementById('new<% $id %>').style.display = 'none';
55 document.getElementById('new<% $id %>Label').style.display = 'none';
56 document.getElementById('new<% $id %>T').disabled = true;
57 document.getElementById('new<% $id %>T').style.display = 'none';
58 document.getElementById('new<% $id %>TLabel').style.display = 'none';
67 <TD ALIGN="right">Reason</TD>
69 <SELECT id="<% $id %>" name="<% $name %>" onFocus="sh_add<% $func_suffix %>()" onChange="sh_add<% $func_suffix %>()">
70 <OPTION VALUE="" <% ($init_reason eq '') ? 'SELECTED' : '' %>>Select Reason...</OPTION>
71 % foreach my $reason (@reasons) {
72 <OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reasontype->type %> : <% $reason->reason %></OPTION>
74 % if ($curuser->access_right($add_access_right)) {
75 <OPTION VALUE="-1" <% ($init_reason == -1) ? 'SELECTED' : '' %>>Add new reason</OPTION>
82 % my @types = qsearch( 'reason_type', { 'class' => $class } );
83 % if (scalar(@types) < 1) { # we should never reach this
86 <P>No reason types. Go add some. </P>
89 % }elsif (scalar(@types) == 1) {
92 <P id="new<% $name %>TLabel" style="display:<% $display %>">Reason Type</P>
95 <P id="new<% $name %>T" disabled="<% $disabled %>" style="display:<% $display %>"><% $types[0]->type %>
96 <INPUT type="hidden" name="new<% $name %>T" value="<% $types[0]->typenum %>">
104 <P id="new<% $id %>TLabel" style="display:<% $display %>">Reason Type</P>
107 <SELECT id="new<% $id %>T" name="new<% $name %>T" "<% $disabled %>" style="display:<% $display %>">
108 % for my $type (@types) {
109 <OPTION VALUE="<% $type->typenum %>" <% ($init_type == $type->typenum) ? 'SELECTED' : '' %>><% $type->type %></OPTION>
118 <P id="new<% $id %>Label" style="display:<% $display %>">New Reason</P>
120 <TD><INPUT id="new<% $id %>" name="new<% $name %>" type="text" value="<% $init_newreason |h %>" "<% $disabled %>" style="display:<% $display %>"></TD>
127 my $name = $opt{'field'};
128 my $class = $opt{'reason_class'};
132 $init_reason = $opt{'cgi'}->param($name);
134 $init_reason = $opt{'curr_value'};
137 my $controlledbutton = $opt{'control_button'};
139 ( my $func_suffix = $name ) =~ s/\./_/g;
141 my $id = $opt{'id'} || $func_suffix;
143 my( $add_access_right, $access_right );
145 $access_right = 'Cancel customer';
146 $add_access_right = 'Add on-the-fly cancel reason';
147 } elsif ($class eq 'S') {
148 $access_right = 'Suspend customer package';
149 $add_access_right = 'Add on-the-fly suspend reason';
150 } elsif ($class eq 'R') {
151 $access_right = 'Post credit';
152 $add_access_right = 'Add on-the-fly credit reason';
154 die "illegal class: $class";
157 my( $display, $disabled ) = ( 'none', 'DISABLED' );
158 my( $init_type, $init_newreason ) = ( '', '' );
159 if ($init_reason == -1 || ref($init_reason) ) {
164 if ( ref($init_reason) ) {
165 $init_type = $init_reason->{'typenum'};
166 $init_newreason = $init_reason->{'reason'};
168 } elsif ( $opt{'cgi'} ) {
169 $init_type = $opt{'cgi'}->param( "new${name}T" );
170 $init_newreason = $opt{'cgi'}->param( "new$name" );
176 "WHERE class = '$class' and (disabled = '' OR disabled is NULL)";
178 my @reasons = qsearch({
181 extra_sql => $extra_sql,
182 addl_from => 'LEFT JOIN reason_type '.
183 ' ON reason_type.typenum = reason.reason_type',
184 order_by => 'ORDER BY reason_type.type ASC, reason.reason ASC',
187 my $curuser = $FS::CurrentUser::CurrentUser;