summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2009-05-09 00:39:13 +0000
committerivan <ivan>2009-05-09 00:39:13 +0000
commitf920fdb29a19105c9102d29e532f8cbb40dd1171 (patch)
tree0ca481886abeacd7f46a1189cc4dfc99f22414b3
parent277ef4d5ea367fa4819fde5bed75ede8e53a7d9d (diff)
add ability to configure service labels per-package (still need to actually use the labels), RT#4081
-rw-r--r--FS/FS/Schema.pm1
-rw-r--r--FS/FS/part_svc.pm75
-rw-r--r--FS/FS/part_svc_column.pm5
-rw-r--r--FS/FS/svc_acct.pm18
-rwxr-xr-xhttemplate/browse/part_svc.cgi27
-rwxr-xr-xhttemplate/edit/part_svc.cgi25
6 files changed, 99 insertions, 52 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 5d5331a..e70a12c 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1268,6 +1268,7 @@ sub tables_hashref {
'columnnum', 'serial', '', '', '', '',
'svcpart', 'int', '', '', '', '',
'columnname', 'varchar', '', 64, '', '',
+ 'columnlabel', 'varchar', 'NULL', $char_d, '', '',
'columnvalue', 'varchar', 'NULL', $char_d, '', '',
'columnflag', 'char', 'NULL', 1, '', '',
],
diff --git a/FS/FS/part_svc.pm b/FS/FS/part_svc.pm
index 580038b..e57efe4 100644
--- a/FS/FS/part_svc.pm
+++ b/FS/FS/part_svc.pm
@@ -133,7 +133,8 @@ sub insert {
# fields('part_svc');
foreach my $field (
grep { $_ ne 'svcnum'
- && defined( $self->getfield($svcdb.'__'.$_.'_flag') )
+ && ( defined( $self->getfield($svcdb.'__'.$_.'_flag') )
+ || $self->getfield($svcdb.'__'.$_.'_label') !~ /^\s*$/ )
} (fields($svcdb), @fields)
) {
my $part_svc_column = $self->part_svc_column($field);
@@ -142,20 +143,28 @@ sub insert {
'columnname' => $field,
} );
- my $flag = $self->getfield($svcdb.'__'.$field.'_flag');
- #if ( uc($flag) =~ /^([DFMAX])$/ ) {
- if ( uc($flag) =~ /^([A-Z])$/ ) { #part_svc_column will test it
- my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse}
- || sub { shift };
- $part_svc_column->setfield('columnflag', $1);
- $part_svc_column->setfield('columnvalue',
- &$parser($self->getfield($svcdb.'__'.$field))
- );
+ my $flag = $self->getfield($svcdb.'__'.$field.'_flag');
+ my $label = $self->getfield($svcdb.'__'.$field.'_label');
+ if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) {
+
+ if ( uc($flag) =~ /^([A-Z])$/ ) {
+ my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse}
+ || sub { shift };
+ $part_svc_column->setfield('columnflag', $1);
+ $part_svc_column->setfield('columnvalue',
+ &$parser($self->getfield($svcdb.'__'.$field))
+ );
+ }
+
+ $part_svc_column->setfield('columnlabel', $label)
+ if $label !~ /^\s*$/;
+
if ( $previous ) {
$error = $part_svc_column->replace($previous);
} else {
$error = $part_svc_column->insert;
}
+
} else {
$error = $previous ? $previous->delete : '';
}
@@ -254,7 +263,8 @@ sub replace {
my $svcdb = $new->svcdb;
foreach my $field (
grep { $_ ne 'svcnum'
- && defined( $new->getfield($svcdb.'__'.$_.'_flag') )
+ && ( defined( $new->getfield($svcdb.'__'.$_.'_flag') )
+ || $new->getfield($svcdb.'__'.$_.'_label') !~ /^\s*$/ )
} (fields($svcdb),@fields)
) {
my $part_svc_column = $new->part_svc_column($field);
@@ -263,15 +273,23 @@ sub replace {
'columnname' => $field,
} );
- my $flag = $new->getfield($svcdb.'__'.$field.'_flag');
- #if ( uc($flag) =~ /^([DFMAX])$/ ) {
- if ( uc($flag) =~ /^([A-Z])$/ ) { #part_svc_column will test it
- my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse}
+ my $flag = $new->getfield($svcdb.'__'.$field.'_flag');
+ my $label = $new->getfield($svcdb.'__'.$field.'_label');
+
+ if ( uc($flag) =~ /^([A-Z])$/ || $label !~ /^\s*$/ ) {
+
+ if ( uc($flag) =~ /^([A-Z])$/ ) {
+ my $parser = FS::part_svc->svc_table_fields($svcdb)->{$field}->{parse}
|| sub { shift };
- $part_svc_column->setfield('columnflag', $1);
- $part_svc_column->setfield('columnvalue',
- &$parser($new->getfield($svcdb.'__'.$field))
- );
+ $part_svc_column->setfield('columnflag', $1);
+ $part_svc_column->setfield('columnvalue',
+ &$parser($new->getfield($svcdb.'__'.$field))
+ );
+ }
+
+ $part_svc_column->setfield('columnlabel', $label)
+ if $label !~ /^\s*$/;
+
if ( $previous ) {
$error = $part_svc_column->replace($previous);
} else {
@@ -713,17 +731,16 @@ sub process {
push @fields, 'usergroup' if $svcdb eq 'svc_acct'; #kludge
map {
- if ( $param->{ $svcdb.'__'.$_.'_flag' } =~ /^[MA]$/ ) {
- $param->{ $svcdb.'__'.$_ } =
- delete( $param->{ $svcdb.'__'.$_.'_classnum' } );
+ my $f = $svcdb.'__'.$_;
+ if ( $param->{ $f.'_flag' } =~ /^[MA]$/ ) {
+ $param->{ $f } = delete( $param->{ $f.'_classnum' } );
}
- if ( $param->{ $svcdb.'__'.$_.'_flag' } =~ /^S$/ ) {
- $param->{ $svcdb.'__'.$_} =
- ref($param->{ $svcdb.'__'.$_})
- ? join(',', @{$param->{ $svcdb.'__'.$_ }} )
- : $param->{ $svcdb.'__'.$_ };
+ if ( $param->{ $f.'_flag' } =~ /^S$/ ) {
+ $param->{ $f } = ref($param->{ $f })
+ ? join(',', @{$param->{ $f }} )
+ : $param->{ $f };
}
- ( $svcdb.'__'.$_, $svcdb.'__'.$_.'_flag' );
+ ( $f, $f.'_flag', $f.'_label' );
}
@fields;
@@ -738,7 +755,7 @@ sub process {
my $error;
if ( $param->{'svcpart'} ) {
$error = $new->replace( $old,
- '1.3-COMPAT',
+ '1.3-COMPAT', #totally bunk, as jeff noted
[ 'usergroup' ],
\%exportnums,
$job
diff --git a/FS/FS/part_svc_column.pm b/FS/FS/part_svc_column.pm
index d2b8fd9..f5b39c0 100644
--- a/FS/FS/part_svc_column.pm
+++ b/FS/FS/part_svc_column.pm
@@ -39,6 +39,8 @@ fields are currently supported:
=item columnname - column name in part_svc.svcdb table
+=item columnlabel - label for the column
+
=item columnvalue - default or fixed value for the column
=item columnflag - null or empty (no default), `D' for default, `F' for fixed (unchangeable), `S' for selectable choice, `M' for manual selection from inventory, or `A' for automatic selection from inventory. For virtual fields, can also be 'X' for excluded.
@@ -87,11 +89,12 @@ sub check {
$self->ut_numbern('columnnum')
|| $self->ut_number('svcpart')
|| $self->ut_alpha('columnname')
+ || $self->ut_textn('columnlabel')
|| $self->ut_anything('columnvalue')
;
return $error if $error;
- $self->columnflag =~ /^([DFSMAX])$/
+ $self->columnflag =~ /^([DFSMAX]?)$/
or return "illegal columnflag ". $self->columnflag;
$self->columnflag(uc($1));
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index 955547b..8b5c7b9 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -215,9 +215,9 @@ sub table_info {
'fields' => {
'dir' => 'Home directory',
'uid' => {
- label => 'UID',
- def_label => 'UID (set to fixed and blank for no UIDs)',
- type => 'text',
+ label => 'UID',
+ def_info => 'set to fixed and blank for no UIDs',
+ type => 'text',
},
'slipip' => 'IP address',
# 'popnum' => qq!<A HREF="$p/browse/svc_acct_pop.cgi/">POP number</A>!,
@@ -244,15 +244,14 @@ sub table_info {
},
'_password' => 'Password',
'gid' => {
- label => 'GID',
- def_label => 'GID (when blank, defaults to UID)',
- type => 'text',
+ label => 'GID',
+ def_info => 'when blank, defaults to UID',
+ type => 'text',
},
'shell' => {
- #desc =>'Shell (all service definitions should have a default or fixed shell that is present in the <b>shells</b> configuration file, set to blank for no shell tracking)',
label => 'Shell',
- def_label=> 'Shell (set to blank for no shell tracking)',
- type =>'select',
+ def_info => 'set to blank for no shell tracking',
+ type => 'select',
#select_list => [ $conf->config('shells') ],
select_list => [ $conf ? $conf->config('shells') : () ],
disable_inventory => 1,
@@ -261,7 +260,6 @@ sub table_info {
'finger' => 'Real name', # (GECOS)',
'domsvc' => {
label => 'Domain',
- #def_label => 'svcnum from svc_domain',
type => 'select',
select_table => 'svc_domain',
select_key => 'svcnum',
diff --git a/httemplate/browse/part_svc.cgi b/httemplate/browse/part_svc.cgi
index f1b2836..94afdef 100755
--- a/httemplate/browse/part_svc.cgi
+++ b/httemplate/browse/part_svc.cgi
@@ -55,6 +55,8 @@ function part_export_areyousure(href) {
<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>
+
<TH COLSPAN=2 CLASS="grid" BGCOLOR="#cccccc">Modifier</TH>
</TR>
@@ -65,8 +67,15 @@ function part_export_areyousure(href) {
% my @dfields = $svc_x->fields;
% push @dfields, 'usergroup' if $svcdb eq 'svc_acct'; #kludge
% my @fields =
-% grep { $svc_x->pvf($_)
-% or $_ ne 'svcnum' && $part_svc->part_svc_column($_)->columnflag }
+% grep { my $col = $part_svc->part_svc_column($_);
+% my $def = FS::part_svc->svc_table_fields($svcdb)->{$_};
+% $svc_x->pvf($_)
+% or $_ ne 'svcnum' && (
+% $col->columnflag || ( $col->columnlabel !~ /^\S*$/
+% && $col->columnlabel ne $def->{'label'}
+% )
+% )
+% }
% @dfields ;
% my $rowspan = scalar(@fields) || 1;
% my $url = "${p}edit/part_svc.cgi?". $part_svc->svcpart;
@@ -128,21 +137,25 @@ function part_export_areyousure(href) {
</TD>
% unless ( @fields ) {
-% for ( 1..3 ) {
+% for ( 1..4 ) {
<TD CLASS="grid" BGCOLOR="<% $bgcolor %>"</TD>
% }
% }
%
% my($n1)='';
% foreach my $field ( @fields ) {
-% my $formatter =
-% FS::part_svc->svc_table_fields($svcdb)->{$field}->{format}
-% || sub { shift };
-% my $flag = $part_svc->part_svc_column($field)->columnflag;
%
+% #a few lines of false laziness w/edit/part_svc.cgi
+% my $def = FS::part_svc->svc_table_fields($svcdb)->{$field};
+% my $formatter = $def->{format} || sub { shift };
+%
+% my $part_svc_column = $part_svc->part_svc_column($field);
+% my $label = $part_svc_column->columnlabel || $def->{'label'};
+% my $flag = $part_svc_column->columnflag;
<% $n1 %>
<TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $field %></TD>
+ <TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $label %></TD>
<TD CLASS="grid" BGCOLOR="<% $bgcolor %>"><% $flag{$flag} %></TD>
<TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
diff --git a/httemplate/edit/part_svc.cgi b/httemplate/edit/part_svc.cgi
index deb3c80..7970343 100755
--- a/httemplate/edit/part_svc.cgi
+++ b/httemplate/edit/part_svc.cgi
@@ -122,6 +122,7 @@ that field.
% $html .= include('/elements/table-grid.html', 'cellpadding' => 4 ).
% '<TR>'.
% '<TH CLASS="grid" BGCOLOR="#cccccc">Field</TH>'.
+% '<TH CLASS="grid" BGCOLOR="#cccccc">Label</TH>'.
% '<TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Modifier</TH>'.
% '</TR>';
%
@@ -146,13 +147,15 @@ that field.
%
% foreach my $field (@fields) {
%
-% #my $def = $defs{$layer}{$field};
+% #a few lines of false laziness w/browse/part_svc.cgi
% my $def = FS::part_svc->svc_table_fields($layer)->{$field};
-% my $label = $def->{'def_label'} || $def->{'label'};
+% my $def_info = $def->{'def_info'};
% my $formatter = $def->{'format'} || sub { shift };
+%
% my $part_svc_column = $part_svc->part_svc_column($field);
+% my $label = $part_svc_column->columnlabel || $def->{'label'};
% my $value = &$formatter($part_svc_column->columnvalue);
-% my $flag = $part_svc_column->columnflag;
+% my $flag = $part_svc_column->columnflag;
%
% if ( $bgcolor eq $bgcolor1 ) {
% $bgcolor = $bgcolor2;
@@ -160,9 +163,12 @@ that field.
% $bgcolor = $bgcolor1;
% }
%
-% $html .= qq!<TR><TD CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
-% ( $label || $field ).
+% $html .= qq!<TR><TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor" ALIGN="right">!.
+% ( $def->{'label'} || $field ).
% "</TD>";
+%
+% $html .= qq!<TD ROWSPAN=2 CLASS="grid" BGCOLOR="$bgcolor"><INPUT NAME="${layer}__${field}_label" VALUE="!. encode_entities($label). '" STYLE="text-align:right"></TD>';
+%
% $flag = '' if $def->{type} eq 'disabled';
%
% $html .= qq!<TD CLASS="grid" BGCOLOR="$bgcolor">!;
@@ -302,6 +308,15 @@ that field.
% }
%
% $html .= "</TD></TR>\n";
+
+% $def_info = "($def_info)" if $def_info;
+% $html .=
+% qq!<TR>!.
+% qq! <TD COLSPAN=2 BGCOLOR="$bgcolor" ALIGN="center" !.
+% qq! STYLE="padding:0; border-top: none">!.
+% qq! <FONT SIZE="-1"><I>$def_info</I></FONT>!.
+% qq! </TD>!.
+% qq!</TR>\n!;
%
% } #foreach my $field (@fields) {
%