also in agent edit, fix form getting submitted before customer search can complete...
[freeside.git] / httemplate / edit / agent.cgi
1 <% include("/elements/header.html","$action Agent", menubar(
2   'View all agents' => $p. 'browse/agent.cgi',
3 )) %>
4
5 <% include('/elements/error.html') %>
6
7 <FORM METHOD   = POST
8       ACTION   = "<%popurl(1)%>process/agent.cgi"
9       onSubmit = "return check_agent_custnum_search(this)"
10 >
11
12 <SCRIPT TYPE="text/javascript">
13   function check_agent_custnum_search(what) {
14     while ( agent_custnum_search_active ) {
15       // javascript needs ambien
16     }
17     return true;
18   }
19 </SCRIPT>
20
21 <INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $agent->agentnum %>">
22 Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %>
23
24 <% &ntable("#cccccc", 2, '') %>
25
26   <TR>
27     <TH ALIGN="right">Agent</TH>
28     <TD><INPUT TYPE="text" NAME="agent" SIZE=32 VALUE="<% $agent->agent %>"></TD>
29   </TR>
30
31   <TR>
32     <TH ALIGN="right">Agent type</TH>
33     <TD>
34       <SELECT NAME="typenum" SIZE=1>
35 %       foreach my $agent_type (qsearch('agent_type',{})) { 
36
37           <OPTION VALUE="<% $agent_type->typenum %>"<% ( $agent->typenum && ( $agent->typenum == $agent_type->typenum ) ) ? ' SELECTED' : '' %>>
38     <% $agent_type->getfield('typenum') %>: <% $agent_type->getfield('atype') %>
39 %       } 
40   
41       </SELECT>
42     </TD>
43   </TR>
44
45   <TR>
46     <TH ALIGN="right">Master customer</TH>
47     <TD>
48       <% include('/elements/search-cust_main.html',
49                    'field_name'  => 'agent_custnum',
50                    'curr_value'  => $agent->agent_custnum,
51                    'find_button' => 1,
52                 )
53       %>
54     </TD>
55   </TR>
56
57   <TR>
58     <TD ALIGN="right">Disable</TD>
59     <TD><INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $agent->disabled eq 'Y' ? ' CHECKED' : '' %>></TD>
60   </TR>
61
62 % if ( $conf->exists('agent-invoice_template') ) {
63
64   <% include('/elements/tr-select-invoice_template.html',
65                'label'      => 'Invoice template',
66                'field'      => 'invoice_template',
67                'curr_value' => $agent->invoice_template,
68             )
69   %>
70
71 % } else {
72
73   <INPUT TYPE="hidden" NAME="invoice_template" VALUE="<% $agent->invoice_template %>">
74
75 % }
76
77 % if ( $conf->config('ticket_system') ) {
78 %    my $default_queueid = $conf->config('ticket_system-default_queueid');
79 %    my $default_queue = FS::TicketSystem->queue($default_queueid);
80 %    $default_queue = "(default) $default_queueid: $default_queue"
81 %      if $default_queueid;
82 %    my %queues = FS::TicketSystem->queues();
83 %    my @queueids = sort { $a <=> $b } keys %queues;
84 %  
85
86     <TR>
87       <TD ALIGN="right">Ticketing queue</TD>
88       <TD>
89         <SELECT NAME="ticketing_queueid">
90           <OPTION VALUE=""><% $default_queue %>
91 % foreach my $queueid ( @queueids ) { 
92
93             <OPTION VALUE="<% $queueid %>" <% $agent->ticketing_queueid == $queueid ? ' SELECTED' : '' %>><% $queueid %>: <% $queues{$queueid} %>
94 % } 
95
96         </SELECT>
97       </TD>
98     </TR>
99 % } 
100
101   <TR>
102     <TD ALIGN="right">Access Groups</TD>
103     <TD><% include('/elements/checkboxes-table.html',
104                      'source_obj'   => $agent,
105                      'link_table'   => 'access_groupagent',
106                      'target_table' => 'access_group',
107                      'name_col'     => 'groupname',
108                      'target_link'  => $p. 'edit/access_group.html?',
109                   )
110         %>
111     </TD>
112   </TR>
113
114 </TABLE>
115
116 <BR>
117 <INPUT TYPE="submit" VALUE="<% $agent->agentnum ? "Apply changes" : "Add agent" %>">
118
119 </FORM>
120
121 <% include('/elements/footer.html') %>
122
123 <%init>
124
125 die "access denied"
126   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
127
128 my $agent;
129 if ( $cgi->param('error') ) {
130   $agent = new FS::agent ( {
131     map { $_, scalar($cgi->param($_)) } fields('agent')
132   } );
133 } elsif ( $cgi->keywords ) {
134   my($query) = $cgi->keywords;
135   $query =~ /^(\d+)$/;
136   $agent = qsearchs( 'agent', { 'agentnum' => $1 } );
137 } else { #adding
138   $agent = new FS::agent {};
139 }
140 my $action = $agent->agentnum ? 'Edit' : 'Add';
141
142 my $conf = new FS::Conf;
143
144 </%init>