2 <SCRIPT TYPE="text/javascript">
3 function sh_add<% $name %>()
6 if (document.getElementById('<% $name %>').selectedIndex == 0){
7 <% $controlledbutton ? $controlledbutton.'.disabled = true;' : ';' %>
9 <% $controlledbutton ? $controlledbutton.'.disabled = false;' : ';' %>
12 %if ($curuser->access_right($access_right)){
14 if (document.getElementById('<% $name %>').selectedIndex ==
15 (document.getElementById('<% $name %>').length - 1)) {
16 document.getElementById('new<% $name %>').disabled = false;
17 document.getElementById('new<% $name %>').style.display = 'inline';
18 document.getElementById('new<% $name %>Label').style.display = 'inline';
19 document.getElementById('new<% $name %>T').disabled = false;
20 document.getElementById('new<% $name %>T').style.display = 'inline';
21 document.getElementById('new<% $name %>TLabel').style.display = 'inline';
23 document.getElementById('new<% $name %>').disabled = true;
24 document.getElementById('new<% $name %>').style.display = 'none';
25 document.getElementById('new<% $name %>Label').style.display = 'none';
26 document.getElementById('new<% $name %>T').disabled = true;
27 document.getElementById('new<% $name %>T').style.display = 'none';
28 document.getElementById('new<% $name %>TLabel').style.display = 'none';
37 <TD ALIGN="right">Reason</TD>
39 <SELECT id="<% $name %>" name="<% $name %>" onFocus="sh_add<% $name %>()" onChange="sh_add<% $name %>()">
40 <OPTION VALUE="" <% ($init_reason eq "") ? 'SELECTED' : '' %>>Select Reason...</OPTION>
41 % foreach my $reason (@reasons) {
42 <OPTION VALUE="<% $reason->reasonnum %>" <% ($init_reason == $reason->reasonnum) ? 'SELECTED' : '' %>><% $reason->reasontype->type %> : <% $reason->reason %></OPTION>
44 % if ($curuser->access_right($access_right)) {
45 <OPTION VALUE="-1" <% ($init_reason == -1) ? 'SELECTED' : '' %>>Add new reason</OPTION>
52 % my @types = qsearch( 'reason_type', { 'class' => $class } );
53 % if (scalar(@types) < 1) { # we should never reach this
56 <P>No reason types. Go add some. </P>
59 % }elsif (scalar(@types) == 1) {
62 <P id="new<% $name %>TLabel" style="display:<% $display %>">Reason Type</P>
65 <P id="new<% $name %>T" disabled="<% $disabled %>" style="display:<% $display %>"><% $types[0]->type %>
66 <INPUT type="hidden" name="new<% $name %>T" value="<% $types[0]->typenum %>">
74 <P id="new<% $name %>TLabel" style="display:<% $display %>">Reason Type</P>
77 <SELECT id="new<% $name %>T" name="new<% $name %>T" disabled="<% $disabled %>" style="display:<% $display %>">
78 % for my $type (@types) {
79 <OPTION VALUE="<% $type->typenum %>" <% ($init_type == $type->typenum) ? 'SELECTED' : '' %>><% $type->type %></OPTION>
88 <P id="new<% $name %>Label" style="display:<% $display %>">New Reason</P>
90 <TD><INPUT id="new<% $name %>" name="new<% $name %>" type="text" value="<% $init_newreason |h %>" disabled="<% $disabled %>" style="display:<% $display %>"></TD>
94 my($name, $class, $init_reason, $init_type, $init_newreason, $controlledbutton) = @_;
95 my($access_right, $display, $disabled);
98 $access_right='Add on-the-fly cancel reason';
99 }elsif ($class eq 'S') {
100 $access_right='Add on-the-fly suspend reason';
101 }elsif ($class eq 'R') {
102 $access_right='Add on-the-fly credit reason';
104 print "illegal class: $class";
107 if ($init_reason == -1){
116 "WHERE class = '$class' and (disabled = '' OR disabled is NULL)";
118 my @reasons = qsearch({
121 extra_sql => $extra_sql,
122 addl_from => 'LEFT JOIN reason_type '.
123 ' ON reason_type.typenum = reason.reason_type',
124 order_by => 'ORDER BY reason_type.type ASC, reason.reason ASC',
127 my $curuser = $FS::CurrentUser::CurrentUser;