[freeside-commits] branch FREESIDE_2_3_BRANCH updated. fd27bcec7ff4b225b13951494607c6877df69b24

Ivan ivan at 420.am
Wed May 2 13:33:16 PDT 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  fd27bcec7ff4b225b13951494607c6877df69b24 (commit)
      from  7abae1137cfd0830f108cd65fff01370c42e3028 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit fd27bcec7ff4b225b13951494607c6877df69b24
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed May 2 13:33:15 2012 -0700

    allow agent override to NO of global payment_receipt set to YES, RT#17468

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index efe2de5..f3174a7 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -183,7 +183,7 @@ sub exists {
   my $self = shift;
   return $self->_usecompat('exists', @_) if use_confcompat;
 
-  my($name, $agentnum)=@_;
+  #my($name, $agentnum)=@_;
 
   carp "FS::Conf->exists(". join(', ', @_). ") called"
     if $DEBUG > 1;
@@ -191,6 +191,54 @@ sub exists {
   defined($self->_config(@_));
 }
 
+#maybe this should just be the new exists instead of getting a method of its
+#own, but i wanted to avoid possible fallout
+
+sub config_bool {
+  my $self = shift;
+  return $self->_usecompat('exists', @_) if use_confcompat;
+
+  my($name,$agentnum,$agentonly) = @_;
+
+  carp "FS::Conf->config_bool(". join(', ', @_). ") called"
+    if $DEBUG > 1;
+
+  #defined($self->_config(@_));
+
+  #false laziness w/_config
+  my $hashref = { 'name' => $name };
+  local $FS::Record::conf = undef;  # XXX evil hack prevents recursion
+  my $cv;
+  my @a = (
+    ($agentnum || ()),
+    ($agentonly && $agentnum ? () : '')
+  );
+  my @l = (
+    ($self->{locale} || ()),
+    ($self->{localeonly} && $self->{locale} ? () : '')
+  );
+  # try with the agentnum first, then fall back to no agentnum if allowed
+  foreach my $a (@a) {
+    $hashref->{agentnum} = $a;
+    foreach my $l (@l) {
+      $hashref->{locale} = $l;
+      $cv = FS::Record::qsearchs('conf', $hashref);
+      if ( $cv ) {
+        if ( $cv->value eq '0'
+               && ($hashref->{agentnum} || $hashref->{locale} )
+           ) 
+        {
+          return 0; #an explicit false override, don't continue looking
+        } else {
+          return 1;
+        }
+      }
+    }
+  }
+  return 0;
+
+}
+
 =item config_orbase KEY SUFFIX
 
 Returns the configuration value or values (depending on context) for 
@@ -269,8 +317,13 @@ sub touch {
   return $self->_usecompat('touch', @_) if use_confcompat;
 
   my($name, $agentnum) = @_;
-  unless ( $self->exists($name, $agentnum) ) {
-    $self->set($name, '', $agentnum);
+  #unless ( $self->exists($name, $agentnum) ) {
+  unless ( $self->config_bool($name, $agentnum) ) {
+    if ( $agentnum && $self->exists($name) && $self->config($name,$agentnum) eq '0' ) {
+      $self->delete($name, $agentnum);
+    } else {
+      $self->set($name, '', $agentnum);
+    }
   }
 }
 
@@ -357,6 +410,31 @@ sub delete {
   }
 }
 
+#maybe this should just be the new delete instead of getting a method of its
+#own, but i wanted to avoid possible fallout
+
+sub delete_bool {
+  my $self = shift;
+  return $self->_usecompat('delete', @_) if use_confcompat;
+
+  my($name, $agentnum) = @_;
+
+  warn "[FS::Conf] DELETE $name\n" if $DEBUG;
+
+  my $cv = FS::Record::qsearchs('conf', { name     => $name,
+                                          agentnum => $agentnum,
+                                          locale   => $self->{locale},
+                                        });
+
+  if ( $cv ) {
+    my $error = $cv->delete;
+    die $error if $error;
+  } elsif ( $agentnum ) {
+    $self->set($name, '0', $agentnum);
+  }
+
+}
+
 =item import_config_item CONFITEM DIR 
 
   Imports the item specified by the CONFITEM (see L<FS::ConfItem>) into
@@ -1398,6 +1476,7 @@ and customer address. Include units.',
     'description' => 'Send payment receipts.',
     'type'        => 'checkbox',
     'per_agent'   => 1,
+    'agent_bool'  => 1,
   },
 
   {
diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm
index ef30809..b535ba7 100644
--- a/FS/FS/cust_pay.pm
+++ b/FS/FS/cust_pay.pm
@@ -582,7 +582,7 @@ sub send_receipt {
 
   my $conf = new FS::Conf;
 
-  return '' unless $conf->exists('payment_receipt', $cust_main->agentnum);
+  return '' unless $conf->config_bool('payment_receipt', $cust_main->agentnum);
 
   my @invoicing_list = $cust_main->invoicing_list_emailonly;
   return '' unless @invoicing_list;
diff --git a/httemplate/config/config-process.cgi b/httemplate/config/config-process.cgi
index 3dcb1d3..f1cbb18 100644
--- a/httemplate/config/config-process.cgi
+++ b/httemplate/config/config-process.cgi
@@ -47,7 +47,7 @@
           '</pre></font>';
 
 %     } elsif ( $type eq 'checkbox' ) {
-%       if ( $conf->exists($i->key, $agentnum) ) {
+%       if ( $conf->config_bool($i->key, $agentnum) ) {
           configCell.style.backgroundColor = '#00ff00';
           configCell.innerHTML = 'YES';
 %       } else {
@@ -184,7 +184,7 @@ foreach my $type ( ref($i->type) ? @{$i->type} : $i->type ) {
 }
 # warn @touch;
 $conf->touch($_, $agentnum) foreach @touch;
-$conf->delete($_, $agentnum) foreach @delete;
+$conf->delete_bool($_, $agentnum) foreach @delete;
 
 if (scalar(@error)) {
   $cgi->param('error', join(' ', @error));
diff --git a/httemplate/config/config-view.cgi b/httemplate/config/config-view.cgi
index 02acd58..02a24ad 100644
--- a/httemplate/config/config-view.cgi
+++ b/httemplate/config/config-view.cgi
@@ -211,7 +211,7 @@ invoice language options:
 %   } elsif ( $type eq 'checkbox' ) {
 
             <tr>
-              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->exists($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
+              <td id="<% $agentnum.$i->key.$n %>" bgcolor="#<% $conf->config_bool($i->key, $agentnum) ? '00ff00">YES' : 'ff0000">NO' %></td>
             </tr>
 
 %   } elsif ( $type eq 'select' && $i->select_hash ) {
diff --git a/httemplate/config/config.cgi b/httemplate/config/config.cgi
index 6a1eaec..a4f9890 100644
--- a/httemplate/config/config.cgi
+++ b/httemplate/config/config.cgi
@@ -40,12 +40,14 @@ Setting <b><% $key %></b>
 <table><tr><td>
 
 % my $n = 0;
+% my $submit = 0;
 % foreach my $type (@types) {
 %   if ( $type eq '' ) {
 
   <font color="#ff0000">no type</font>
 
 %   } elsif ( $type eq 'image' ) { 
+%     $submit++;
 
   <% $conf->exists($key, $agentnum)
        ? 'Current image<br>'.
@@ -59,24 +61,37 @@ Setting <b><% $key %></b>
   New image filename <input type="file" name="<% "$key$n" %>">
 
 %   } elsif ( $type eq 'binary' ) { 
+%     $submit++;
 
   Filename <input type="file" name="<% "$key$n" %>">
 
 %   } elsif ( $type eq 'textarea' ) { 
+%     $submit++;
 
   <textarea name="<% "$key$n" %>" rows=12 cols=78 wrap="off"><% join("\n", $conf->config($key, $agentnum)) |h %></textarea>
 
 %   } elsif ( $type eq 'checkbox' ) { 
+%
+%     if ( $agentnum && $conf->exists($key) && ! $agent_bool ) {
 
-  <input name="<% "$key$n" %>" type="checkbox" value="1"
-    <% $conf->exists($key, $agentnum) ? 'CHECKED' : '' %> >
+        <input name="<% "$key$n" %>" type="checkbox" value="1" CHECKED DISABLED>
+        <FONT SIZE="-1"><I>(global setting cannot yet be overridden)</I></FONT>
 
-%   } elsif ( $type eq 'text' )  { 
+%     } else {
+%       $submit++;
 
-  <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>">
+        <input name="<% "$key$n" %>" type="checkbox" value="1"
+          <% $conf->config_bool($key, $agentnum) ? 'CHECKED' : '' %> >
+%     }
 
-%   } elsif ( $type eq 'select' || $type eq 'selectmultiple' )  { 
+%   } elsif ( $type eq 'text' )  {
+%     $submit++;
 
+  <input name="<% "$key$n" %>" type="text" value="<% $conf->exists($key, $agentnum) ? $conf->config($key, $agentnum) : '' |h %>">
+
+%   } elsif ( $type eq 'select' || $type eq 'selectmultiple' )  {
+%     $submit++;
+ 
   <select name="<% "$key$n" %>" <% $type eq 'selectmultiple' ? 'MULTIPLE' : '' %>>
 
 %
@@ -131,7 +146,8 @@ Setting <b><% $key %></b>
 
   </select>
 
-%   } elsif ( $type eq 'select-sub' ) { 
+%   } elsif ( $type eq 'select-sub' ) {
+%     $submit++;
 
   <select name="<% "$key$n" %>" <% $config_item->multiple ? 'MULTIPLE' : '' %>>
 
@@ -167,8 +183,8 @@ Setting <b><% $key %></b>
 
   </select>
 
-%   } elsif ( $type eq 'editlist' ) { 
-%
+%   } elsif ( $type eq 'editlist' ) {
+%     $submit++;
   <script>
     function doremove<% "$key$n" %>() {
       fromObject = document.OneTrueForm.<% "$key$n" %>;
@@ -284,6 +300,7 @@ Setting <b><% $key %></b>
   </tr></table>
 
 %   } elsif ( $element_types{$type} ) {
+%     $submit++;
 %
 %     my %opt = ( 'element_name' => "$key$n",
 %                 'empty_label'  => ' ',
@@ -313,7 +330,10 @@ Setting <b><% $key %></b>
 % }
 </tr>
 </table>
-<INPUT TYPE="submit" VALUE="<% $title %>">
+
+% if ( $submit ) {
+  <INPUT TYPE="submit" VALUE="<% $title %>">
+% }
 </FORM>
 
 </BODY>
@@ -365,5 +385,6 @@ my $config_item = $confitems{$key};
 my $description = $config_item->description;
 my $config_type = $config_item->type;
 my @types = ref($config_type) ? @$config_type : ($config_type);
+my $agent_bool = $config_item->agent_bool;
 
 </%init>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm                        |   85 ++++++++++++++++++++++++++++++++-
 FS/FS/cust_pay.pm                    |    2 +-
 httemplate/config/config-process.cgi |    4 +-
 httemplate/config/config-view.cgi    |    2 +-
 httemplate/config/config.cgi         |   39 ++++++++++++----
 5 files changed, 116 insertions(+), 16 deletions(-)




More information about the freeside-commits mailing list