Gossamer Forum
Home : Products : DBMan : Installation :

Admin Only Fields

Quote Reply
Admin Only Fields
I have set up the default.cfg file, with two pull down menus being defined as size "-2"; ie Admin Only. HTML autogenerate is on. However, when a default user [w/o admin permissions] wants to add a record to the database, these two pull down menus are still visible. Anyone know what the reasons may be?

-Max
Quote Reply
Re: Admin Only Fields In reply to
If you take a look at sub build_html_record_form in db.cgi, you'll see that the way it builds the form is that it first looks for select fields, radio fields and checkbox fields to see if they're defined. If they are, it prints them out. Then it looks for textare fields and if there are any defined, it prints them. Finally, it checks for whether the field is hidden or admin only, assuming these fields are text fields.

It would take some work, but you could probably change things so that you could have admin only select, radio, checkbox and textarea fields.


------------------
JPD
Quote Reply
Re: Admin Only Fields In reply to
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).]