Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / httemplate / elements / contact.html
index b3e5353..7b6c853 100644 (file)
@@ -2,20 +2,20 @@
 
   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
 
-  <TABLE>
+  <TABLE STYLE="display:inline">
     <TR>
-%     if ( @contact_class ) {
+%     if ( @contact_class && ! $opt{name_only} ) {
         <TD>
           <SELECT NAME="<%$name%>_classnum" <% $onchange %>>
             <OPTION VALUE="">
 %           my $classnum = scalar($cgi->param($name.'_classnum'))
-%                            || $contact->classnum;
+%                            || $X_contact->classnum;
 %           foreach my $contact_class (@contact_class) {
               <OPTION VALUE="<% $contact_class->classnum %>"
                  <% ($contact_class->classnum == $classnum) ? 'SELECTED' : '' %>
               ><% $contact_class->classname |h %>
 %           }
-          <SELECT><BR>
+          </SELECT><BR>
           <FONT SIZE="-1">Type</FONT>
         </TD>
 %     } else {
@@ -31,7 +31,7 @@
 %           'phonetypenum' => $1,
 %         });
 %         if ( $contact_phone ) {
-%           $value = $contact_phone->phonenum;
+%           $value = $contact_phone->phonenum_pretty;
 %           $value .= 'x'.$contact_phone->extension
 %             if $contact_phone->extension;
 %           $value = '+'. $contact_phone->countrycode. " $value"
 %         }
 %       } elsif ( $field eq 'emailaddress' ) {
 %         $value = join(', ', map $_->emailaddress, $contact->contact_email);
+%       } elsif ( $field eq 'password' ) {
+%          $value = $contact->get('_password') ? '********' : '';
+%       } elsif ( $field eq 'selfservice_access'
+%              or $field eq 'comment'
+%              or $field eq 'invoice_dest'
+%              or $field eq 'message_dest' ) {
+%         $value = $X_contact->get($field);
 %       } else {
 %         $value = $contact->get($field);
 %       }
 
         <TD>
-          <INPUT TYPE  = "text"
-                 NAME  = "<%$name%>_<%$field%>"
-                 ID    = "<%$id%>_<%$field%>"
-                 SIZE  = "<% $size{$field} || 15 %>"
-                 VALUE = "<% scalar($cgi->param($name."_$field"))
-                             || $value |h %>"
-                 <% $onchange %>
-          ><BR>
+%         if ( $field eq 'selfservice_access' ) {
+
+            <SELECT NAME = "<%$name%>_<%$field%>"
+                    ID   = "<%$id%>_<%$field%>"
+                    STYLE = "width: 140px"
+            >
+              <OPTION VALUE="" <% !$value ? 'SELECTED' : '' %>>Disabled
+%             if ( $value || $self_base_url ) {
+                <OPTION VALUE="<% $value eq 'Y' ? 'Y' : 'E' %>" <% $value eq 'Y' ? 'SELECTED' : '' %>>Enabled
+%               if ( $value eq 'Y' && $self_base_url ) {
+                  <OPTION VALUE="R">Re-email
+%               }
+%             }
+            </SELECT>
+% #password form
+%         } elsif ( $field eq 'password') {
+            <INPUT TYPE  = "text"
+                   NAME  = "<%$name%>_<%$field%>"
+                   ID    = "changepw<%$id%>_<%$field%>"
+                   SIZE  = "<% $size{$field} || 14 %>"
+                   VALUE = ""
+                   placeholder = "<% $value |h %>"
+            >
+%           my $contactnum = $curr_value ? $curr_value : '0';
+            <& '/elements/validate_password.html',
+             'fieldid'    => "changepw".$id."_password",
+             'svcnum'     => '',
+             'contactnum' => $contactnum,
+             'submitid'   => "submit",
+           &>
+
+            <SCRIPT TYPE="text/javascript">
+                    var selfService = document.getElementById("<%$id%>_selfservice_access").value;
+
+                    if (selfService !== "Y") { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
+                    document.getElementById("<%$id%>_selfservice_access").onchange = function() {
+                      if (this.value == "P" || this.value == "E" || this.value =="Y") {
+                        document.getElementById("changepw<%$id%>_password").disabled = '';
+                      }
+                      else { document.getElementById("changepw<%$id%>_password").disabled = 'true'; }
+                      return false;
+                    }
+            </SCRIPT>
+%         } elsif ( $field eq 'invoice_dest' || $field eq 'message_dest' ) {
+%           my $curr_value = $cgi->param($name . '_' . $field);
+%           $curr_value = $value if !defined($curr_value);
+            <& select.html,
+                field         => $name . '_' . $field,
+                curr_value    => $curr_value,
+                options       => [ '', 'Y' ],
+                option_labels => { '' => 'no', 'Y' => 'yes' },
+                style         => 'width: 100%',
+            &>
+%         } else {
+            <INPUT TYPE  = "text"
+                   NAME  = "<%$name%>_<%$field%>"
+                   ID    = "<%$id%>_<%$field%>"
+                   SIZE  = "<% $size{$field} || 14 %>"
+                   VALUE = "<% scalar($cgi->param($name . '_' . $field))
+                               || $value |h %>"
+                   <% $onchange %>
+            >
+%         }
+          <BR>
           <FONT SIZE="-1"><% $label{$field} %></FONT>
+%       if ( $field eq 'password' ) {
+          <div id="changepw<%$id%>_<%$field%>_result"></div>
+%       }
         </TD>
 %     }
     </TR>
 
 my( %opt ) = @_;
 
+my $conf = new FS::Conf;
+
+my $self_base_url = $conf->config('selfservice_server-base_url');
+
 my $name = $opt{'element_name'} || $opt{'field'} || 'contactnum';
 my $id = $opt{'id'} || 'contactnum';
 
@@ -81,24 +151,51 @@ if ( $opt{'onchange'} ) {
 my @contact_class = qsearch('contact_class', { 'disabled' => '' });
 
 my $contact;
+my $X_contact;
 if ( $curr_value ) {
   $contact = qsearchs('contact', { 'contactnum' => $curr_value } );
+  if ( $opt{'custnum'} ) {
+    $X_contact = qsearchs('cust_contact', {
+                            'contactnum' => $curr_value,
+                            'custnum'    => $opt{'custnum'},
+                 });
+  } elsif ( $opt{'prospectnum'} ) {
+    $X_contact = qsearchs('prospect_contact', {
+                   'contactnum'  => $curr_value,
+                   'prospectnum' => $opt{'prospectnum'},
+                 });
+    $opt{'for_prospect'} = 1;
+  } else {
+    die 'neither custnum nor prospectnum specified';
+  }
 } else {
   $contact = new FS::contact {};
+  if ($opt{'for_prospect'}) {
+    $X_contact = new FS::prospect_contact;
+  } else {
+    $X_contact = new FS::cust_contact;
+  }
 }
 
 my %size = ( 'title' => 12 );
 
 tie my %label, 'Tie::IxHash',
-  'first'        => 'First name',
-  'last'         => 'Last name',
-  'title'        => 'Title/Position',
-  'emailaddress' => 'Email',
+  'first'              => 'First name',
+  'last'               => 'Last name',
+  'title'              => 'Title/Position',
+  'emailaddress'       => 'Email'
 ;
 
+unless ($opt{'for_prospect'}) {
+  $label{'invoice_dest'} = 'Send&nbsp;invoices';
+  $label{'message_dest'} = 'Send&nbsp;messages';
+  $label{'selfservice_access'} = 'Self-service';
+  $label{'password'} = 'Password';
+}
+
 my $first = 0;
 foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
-  next if $phone_type->typename eq 'Home';
+  next if $phone_type->typename =~ /^(Home|Fax)$/;
   my $f = 'phonetypenum'.$phone_type->phonetypenum;
   $label{$f} = $phone_type->typename. ' phone';
   $size{$f} = $first++ ? 10 : 15;
@@ -106,6 +203,6 @@ foreach my $phone_type ( qsearch({table=>'phone_type', order_by=>'weight'}) ) {
 
 $label{'comment'} = 'Comment';
 
-my @fields = keys %label;
+my @fields = $opt{'name_only'} ? qw( first last ) : keys %label;
 
 </%init>