Anticipating being asked how to do it, I went ahead and made the subroutines needed. If you replace sub build_html_record and sub build_html_record_form with the subroutines below, you will be able to have admin only select fields, radio fields, checkboxes and textarea fields.
Note that before you use this, you will also have to make a change in your .cfg file. Instead of the size of the textarea being defined in the field length, you will need to set it to either 0 or -2, depending on whether you want it to be visible to everyone or to be an admin only field. Then you will also need to add the lines below:
Code:
# Textarea fields. Field name => WIDTHxHEIGHT
%db_textarea_fields = ( Description => '40x3');
Here's sub build_html_record. It only prints the admin fields if the person has admin permission.
Code:
sub build_html_record {
# --------------------------------------------------------
# Builds a record based on the config information.
#
my (%rec) = @_;
my ($output, $field);
$output = "<p><table border=0 width=450>";
foreach $field (@db_cols) {
next if ($db_form_len{$field} == -1);
if ($db_form_len{$field} == -2) {
if ($per_admin) {
$output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td>
<td width=80%><$font>$rec{$field}</font></td></tr>~;
}
}
else {
$output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td>
<td width=80%><$font>$rec{$field}</font></td></tr>~;
}
}
$output .= "</table></p>\n";
return $output;
}
And here's sub build_html_record_form:
Code:
sub build_html_record_form {
# --------------------------------------------------------
# Builds a record form based on the config information.
#
my (%rec) = @_;
my ($output, $field, @wh);
$output = "<p><table border=0>";
foreach $field (@db_cols) {
if ($db_form_len{$field} == -2) {
if ($per_admin) {
$output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td>
<td width=80%>";
if ($db_select_fields{$field}) {
$output .= &build_select_field($field, $rec{$field});
}
elsif ($db_radio_fields{$field}) {
$output .= &build_radio_field($field, $rec{$field});
}
elsif ($db_checkbox_fields{$field}) {
$output .= &build_checkbox_field ($field, $rec{$field});
}
elsif ($db_textarea_fields{$field}) {
@wh = split(/x/,$db_textarea_fields{$field});
$output .= qq~<textarea name="$field" cols="$wh[0]" rows="$wh[1]">$rec{$field}</textarea>~;
}
else {
$output .= qq~<input type=text name="$field" value="$rec{$field}"
size="$db_form_len{$field}" maxlength="$db_lengths{$field}">~;
}
$output .= "</td></tr>";
}
else {
($output = qq~<input type=hidden name="$field" value="$rec{$field}">$output~);
}
}
elsif ($db_form_len{$field} == -1) {
$output = qq~<input type=hidden
name="$field" value="$rec{$field}">$output~;
}
else {
$output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td>
<td width=80%>";
if ($db_select_fields{$field}) {
$output .= &build_select_field($field, $rec{$field});
}
elsif ($db_radio_fields{$field}) {
$output .= &build_radio_field($field, $rec{$field});
}
elsif ($db_checkbox_fields{$field}) {
$output .= &build_checkbox_field ($field, $rec{$field});
}
elsif ($db_textarea_fields{$field}) {
@wh = split(/x/,$db_textarea_fields{$field});
$output .= qq~<textarea name="$field" cols="$wh[0]" rows="$wh[1]">$rec{$field}</textarea>~;
}
else {
$output .= qq~<input type=text name="$field" value="$rec{$field}"
size="$db_form_len{$field}" maxlength="$db_lengths{$field}">~;
}
$output .= "</td></tr>";
}
}
$output .= "</table></p>\n";
return $output;
}
I hope this helps someone.
------------------
JPD
[This message has been edited by JPDeni (edited February 21, 1999).]