Gossamer Forum
Home : Products : DBMan : Installation :

Bug or Feature?

Quote Reply
Bug or Feature?
I noticed when adding a new record, I could change the auto ID number from the default.count file.

Example:
I create a new record which gets record #33 added from the count file.
I can change it to #123 and add the record.
Checking the count file reveals that it is now set to 123, skipping all the records from 33 to 123.
Is there a way to make that non editable except to maybe the admin?

Also, I added some extra checkboxes to the demo record and it wont let me create records. It keeps giving me an error about maxlength 3. How does the maxlength setting apply to the checkboxes?
Quote Reply
Re: Bug or Feature? In reply to
 
Code:
|;
if ($per_admin) {
print qq|<TR><TD>Record ID:</TD>
<TD><input type="text" name="ID" value="$rec{'ID'}" size="10"></TD></TR>|;
}
else {
print qq|<input type="hidden" name="ID" value="$rec{'ID'}">|;
}
print qq|

Quote:
How does the maxlength setting apply to the checkboxes?

The maxlength refers to the value entered into the field when you check the box. In the demo, the checkbox definition is:

Popular => 'Yes'

and, since 'Yes' is three characters long, the maxlength works.

If your checkbox was, for example

Language => 'English'

you'd need to make the maxlength for that field 7, because 'English' is 7 characters long.



------------------
JPD
Quote Reply
Re: Bug or Feature? In reply to
I got around it setting the maxlength to 255.
I figured that should hold me for however many checkboxes I put in there.

Another question I have is on the popup lists.

I wanted to have one that accepts multiple selections.
I got something to work pretty good by duplicating the build_select_field subroutine in the db.cgi and called it build_mselect_field with the changes to the html codes to allow me to select multiple items in the list.

I did something similar with the build_select_field_from_db making a build_mselect_field_from_db variant with the html changes.

And finaly in the build_html_record_form subroutine, added an appropriate line when to use the build_mselect_field.

Also in the default.cfg duplicated the db_select_fields as db_mselect_fields even though I could have probably used the same.

Now, everything seems to go fine adding a record.

Whatever was selected is displayed SELECTED|SELECTED2|ETC|ETC when viewing the record.

Where a problem comes in is modifing. None of the selections are hilighted as is with the single choice popup menus.

How can I get it to read the items and make sure they are selected in the modify mode.
Quote Reply
Re: Bug or Feature? In reply to
That's great! Could you share your subroutines?

Regarding displaying it on the modify screen, here's a thought, although it's completely untried. Instead of

$field eq $value ?

it might work if you used

$value =~ /$field/ ?

As long as none of your fields completely contain another one, you'd be all right. (What did she say?!?!?!)

You would run into trouble if you had one that was, say, "JPD" and another one that was "JPDeni." If "JPD" had been selected previously, they would both be highlighted on your modify screen.

As I say, I'm not really sure this will work, but what can it hurt to give it a try? Smile


------------------
JPD
Quote Reply
Re: Bug or Feature? In reply to
Sure, i'd be happy to share. Not much to them though.

Though I did notice searching doesnt work quite right either. I can select one item in the popup and it searches fine. If i select more than one it doesn't work.

Just need to test something before posting the code.
Code:
bold in the middle of code
Quote Reply
Re: Bug or Feature? In reply to
Ahh excellent Smile
Basicly the subroutines I created are copies of build_select_field and build_select_field_from_db

Just copy those subs and add what I indicate below in bold. Actualy, you could probably just cut&paste right from your browser.

The following is from the db.cgi file.
Code:
sub build_mselect_field {
# --------------------------------------------------------
# Builds a MULTI SELECT field based on information found
# in the database definition. Parameters are the column to build
# and a default value (optional).

my ($column, $value) = @_;
my (@fields, $ouptut);

@fields = split (/\,/, $db_mselect_fields{$column});
if ($#fields == -1) {
$output = "error building select field: no select fields specified in config for field '$column'!";
}
else {
$output = qq|<SELECT MULTIPLE SIZE="3" NAME="$column"><OPTION>---|;
foreach $field (@fields) {
$field eq $value ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
}
return $output;
}

sub build_mselect_field_from_db {
# --------------------------------------------------------
# Builds a MULTI SELECT field from the database.

my ($column, $value, $name) = @_;
my (@fields, $field, @selectfields, @lines, $line, $ouptut);
my ($fieldnum, $found, $i) = 0;

$name &#0124; &#0124; ($name = $column);

for ($i = 0; $i <= $#db_cols; $i++) {
if ($column eq $db_cols[$i]) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
return "error building select field: no fields specified!";
}

open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

$output = qq|<SELECT MULTIPLE SIZE="3"

------------------
Disclaimer
Wolfy has had no training and claims no knowledge in the art of CGI Scripting or PERL. Only by one semester of Pascal, Wolfy can, or believes he can, see the basic logical structures in the scrip. That which he cannot cut&paste, he fudges. :)
Quote Reply
Re: Bug or Feature? In reply to
Damn.. it all didn't fit.
Heres the other sub in the db.cgi.. again.. copy and change what is bold.

sub build_mselect_field_from_db {
# --------------------------------------------------------
# Builds a MULTI SELECT field from the database.

my ($column, $value, $name) = @_;
my (@fields, $field, @selectfields, @lines, $line, $ouptut);
my ($fieldnum, $found, $i) = 0;

$name &#0124; &#0124; ($name = $column);

for ($i = 0; $i <= $#db_cols; $i++) {
if ($column eq $db_cols[$i]) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
return "error building select field: no fields specified!";
}

open (DB, "<$db_file_name") or &cgierr("unable to open $db_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

$output = qq|<SELECT MULTIPLE SIZE="3"
Quote Reply
Re: Bug or Feature? In reply to
The only other change in the db.cgi file is a bit further down in the sub build_html_record_form.
There is a big set of if..then conditions. The line to be added is in bold.

Code:
sub build_html_record_form {
# --------------------------------------------------------
# Builds a record form based on the config information.
#
my (%rec) = @_;
my ($output, $field);

$output = "<p><table border=0>";
foreach $field (@db_cols) {
if ($db_select_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_select_field($field, $rec{$field}) . "</td></tr>"; }
elsif ($db_mselect_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_mselect_field($field, $rec{$field}) . "</td></tr>"; }
elsif ($db_radio_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_radio_field($field, $rec{$field}) . "</td></tr>"; }
elsif ($db_checkbox_fields{$field}) { $output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_checkbox_field ($field, $rec{$field}) . "</td></tr>"; }
elsif ($db_form_len{$field} =~ /(\d+)x(\d+)/) {
$output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><textarea name="$field" cols="$1" rows="$2">$rec{$field}</textarea></td></tr>~; }
elsif ($db_form_len{$field} == -1) { $output = qq~<input type=hidden name="$field" value="$rec{$field}">$output~; }
elsif ($db_form_len{$field} == -2) { $per_admin ? ($output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><input type=text name="$field" value="$rec{$field}" maxlength="$db_lengths{$field}"></td></tr>~) :
($output = qq~<input type=hidden name="$field" value="$rec{$field}">$output~); }
else { $output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><input type=text name="$field" value="$rec{$field}" size="$db_form_len{$field}" maxlength="$db_lengths{$field}"></td></tr>~; }
}
$output .= "</table></p>\n";
return $output;
}


The other change I made was in the test.cfg file where i duplicated the %db_select_fields section and just changed the name to %db_mselect_fields which you'll notice was used in the build_html_record_form statement.

I'll wait till you take a look at this before trying any additional suggestions to get the selection working in searching and modifying.


------------------
Disclaimer
Wolfy has had no training and claims no knowledge in the art of CGI Scripting or PERL. Only by one semester of Pascal, Wolfy can, or believes he can, see the basic logical structures in the scrip. That which he cannot cut&paste, he fudges. :)
Quote Reply
Re: Bug or Feature? In reply to
Geez.. now that i've screwed up everyones browsers. Smile

The database in its current form can be accesset at
www.pixelworld.com/cgi-bin/db/db.cgi?db=test
Quote Reply
Re: Bug or Feature? In reply to
Wolfy, you can edit your posts ya know Wink