Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / edit / agent.cgi
index 830862f..c4963e4 100755 (executable)
@@ -1,18 +1,30 @@
 <% include("/elements/header.html","$action Agent", menubar(
-  'Main Menu' => $p,
   'View all agents' => $p. 'browse/agent.cgi',
 )) %>
-% if ( $cgi->param('error') ) { 
 
-<FONT SIZE="+1" COLOR="#ff0000">Error: <% $cgi->param('error') %></FONT>
-% } 
+<% include('/elements/error.html') %>
+
+<FORM METHOD   = POST
+      ACTION   = "<%popurl(1)%>process/agent.cgi"
+      onSubmit = "return check_agent_custnum_search(this)"
+>
 
+<SCRIPT TYPE="text/javascript">
+  function check_agent_custnum_search(what) {
+    while ( agent_custnum_search_active ) {
+      // javascript needs ambien
+    }
+    return true;
+  }
+</SCRIPT>
 
-<FORM ACTION="<%popurl(1)%>process/agent.cgi" METHOD=POST>
 <INPUT TYPE="hidden" NAME="agentnum" VALUE="<% $agent->agentnum %>">
-Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %>
 
-<% &ntable("#cccccc", 2, '') %>
+<FONT CLASS="fsinnerbox-title">
+  Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %>
+</FONT>
+
+<TABLE CLASS="fsinnerbox">
 
   <TR>
     <TH ALIGN="right">Agent</TH>
@@ -23,7 +35,7 @@ Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %>
     <TH ALIGN="right">Agent type</TH>
     <TD>
       <SELECT NAME="typenum" SIZE=1>
-%       foreach my $agent_type (qsearch('agent_type',{})) { 
+%       foreach my $agent_type ( qsearch('agent_type', { 'disabled'=>'' }) ) { 
 
           <OPTION VALUE="<% $agent_type->typenum %>"<% ( $agent->typenum && ( $agent->typenum == $agent_type->typenum ) ) ? ' SELECTED' : '' %>>
     <% $agent_type->getfield('typenum') %>: <% $agent_type->getfield('atype') %>
@@ -34,17 +46,56 @@ Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %>
   </TR>
 
   <TR>
+    <TH ALIGN="right">Master customer</TH>
+    <TD>
+      <% include('/elements/search-cust_main.html',
+                   'field_name'  => 'agent_custnum',
+                   'curr_value'  => $agent->agent_custnum,
+                   'find_button' => 1,
+                )
+      %>
+    </TD>
+  </TR>
+
+% if ( $conf->exists('selfservice-agent_login') ) {
+
+    <TR>
+      <TH ALIGN="right">Username</TH>
+      <TD><INPUT TYPE="text" NAME="username" SIZE=16 VALUE="<% $agent->username %>"></TD>
+    </TR>
+
+    <TR>
+      <TH ALIGN="right">Password</TH>
+      <TD><INPUT TYPE="password" NAME="_password" SIZE=16 VALUE="<% $agent->_password %>"></TD>
+    </TR>
+
+% } else {
+
+    <INPUT TYPE="hidden" NAME="username" VALUE="<% $agent->username |h %>">
+    <INPUT TYPE="hidden" NAME="_password" VALUE="<% $agent->_password |h %>">
+
+% }
+
+  <TR>
     <TD ALIGN="right">Disable</TD>
     <TD><INPUT TYPE="checkbox" NAME="disabled" VALUE="Y"<% $agent->disabled eq 'Y' ? ' CHECKED' : '' %>></TD>
   </TR>
 
+% if ( $conf->exists('agent-invoice_template') ) {
+
   <% include('/elements/tr-select-invoice_template.html',
                'label'      => 'Invoice template',
                'field'      => 'invoice_template',
                'curr_value' => $agent->invoice_template,
             )
   %>
-  
+
+% } else {
+
+  <INPUT TYPE="hidden" NAME="invoice_template" VALUE="<% $agent->invoice_template %>">
+
+% }
+
 % if ( $conf->config('ticket_system') ) {
 %    my $default_queueid = $conf->config('ticket_system-default_queueid');
 %    my $default_queue = FS::TicketSystem->queue($default_queueid);
@@ -70,8 +121,55 @@ Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %>
 % } 
 
 </TABLE>
+<BR>
+
+<FONT CLASS="fsinnerbox-title"><% mt('Access Groups') |h %></FONT>
+<TABLE CLASS="fsinnerbox">
+
+  <TR>
+    <TD><% include('/elements/checkboxes-table.html',
+                     'source_obj'   => $agent,
+                     'link_table'   => 'access_groupagent',
+                     'target_table' => 'access_group',
+                     'name_col'     => 'groupname',
+                     'target_link'  => $p. 'edit/access_group.html?',
+                  )
+        %>
+    </TD>
+  </TR>
+
+</TABLE>
+<BR>
+
+<& /elements/table-commissions.html,
+     'source_obj'   => $agent,
+     'link_table'   => 'agent_pkg_class',
+     #'target_table' => 'pkg_class',
+&>
+<BR>
+
+% if ( $conf->config('currencies') ) {
+
+    <FONT CLASS="fsinnerbox-title"><% mt('Currencies') |h %></FONT>
+    <TABLE CLASS="fsinnerbox">
+      <TR>
+        <TD>
+          <& /elements/checkboxes-table-name.html,
+               'link_table' => 'agent_currency',
+               'name_col'   => 'currency',
+               'names_list' => [ map [ $_, {label=>"$_: ".code2currency($_)} ],
+                                   $conf->config('currencies')
+                               ],
+          &>
+        </TD>
+      </TR>
+    </TABLE>
+
+% }
 
 <BR>
+
+
 <INPUT TYPE="submit" VALUE="<% $agent->agentnum ? "Apply changes" : "Add agent" %>">
 
 </FORM>
@@ -80,6 +178,9 @@ Agent #<% $agent->agentnum ? $agent->agentnum : "(NEW)" %>
 
 <%init>
 
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+
 my $agent;
 if ( $cgi->param('error') ) {
   $agent = new FS::agent ( {
@@ -97,5 +198,3 @@ my $action = $agent->agentnum ? 'Edit' : 'Add';
 my $conf = new FS::Conf;
 
 </%init>
-
-