Gossamer Forum
Home : Products : Links 2.0 : Customization :

Can't Create AltCategory MULTIPLE Select Box

Quote Reply
Can't Create AltCategory MULTIPLE Select Box
Hi

I installed the multi-cat mod/templates a long time ago, but it would never build a MULTIPLE select box for AltCategories on add.html, modify.html. It only builds a single.

In db.utils, I have:
Code:
sub build_select_field {
# --------------------------------------------------------
# Builds a SELECT field based on information found
# in the database definition.
#
my ($column, $value, $name, $mult) = @_;
my ($size, %values);

$name | | ($name = $column);
$size | | ($size = 1);

if (! exists $db_select_fields{$column}) {
$db_select_fields{$db_cols[$db_category]} = $db_select_fields{'Mult-Related'} = join (",", &category_list);
}
if (! exists $db_select_fields{$column} && $column eq "AltCategories" && exists $db_select_fields{'Category'}) {
$db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = $db_select_fields{'Category'}}
elsif (! exists $db_select_fields{$column} && $column eq "AltCategories" && ! exists $db_select_fields{'Category'}) {
$db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = join (",", &category_list);}
if ($mult) {
@fields = split (/\,/, $db_select_fields{"Mult-$column"});
%values = map { $_ => 1 } split (/\Q$db_delim\E/, $value);
}
else {
@fields = split (/\,/, $db_select_fields{$column});
$values{$value}++;
}
($#fields >= 0) or return "error building select field: no select fields specified in config for field '$column'!";

$output = qq|<SELECT NAME="$name" $mult SIZE=$size><OPTION>---|;
foreach $field (@fields) {
$values{$field} ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
return $output;
}

and

Code:
sub build_html_record_form {
#--------------------------------------------------------
# Builds a record form based on the config information.
#
my ($output, $field, $multiple, $name);
($_[0] eq "multiple") and ($multiple = 1) and shift;
my (%rec) = @_;
$output = "<p><table border=1>";
# Go through a little hoops to only load category list when absolutely neccessary.
if ($in{'db'} eq 'links') {
exists $db_select_fields{$db_cols[$db_category]}
or ($db_select_fields{$db_cols[$db_category]} = join (",", &category_list));
($db_select_fields{$db_cols[$db_alt]} = $db_select_fields{'Mult-AltCategories'} = join (",", &category_list));
}
else {
$db_select_fields{'Related'} or
($db_select_fields{'Related'} = $db_select_fields{'Mult-Related'} = join ",", &category_list);
}
foreach $field (@db_cols) {
# Set the field name to field-key if we are doing multiple forms.
$multiple ? ($name = "$field-$rec{$db_key}") : ($name = $field);
if ($db_select_fields{"Mult-$field"}) {$output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_select_field($field, $rec{$field}, $name, "MULTIPLE SIZE=5") . "</td></tr>\n";}
elsif ($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}, $name) . "</td></tr>\n"; }
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}, $name) . "</td></tr>\n"; }
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}, $name) . "</td></tr>\n"; }
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 wrap="virtual" name="$name" cols="$1" rows="$2">$rec{$field}</textarea></td></tr>\n~;}
elsif ($db_form_len{$field} == -1) {$output = qq~<input type=hidden name="$field" value="$rec{$field}">\n$output~; }
else {$output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><input type=text name="$name" value="$rec{$field}" size="$db_form_len{$field}" maxlength="$db_lengths{$field}"></td></tr>\n~;}
}
$output .= "</table></p>\n";
return $output;
}

In site_html_templates.pl, I have:
Code:
sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
&html_print_headers;
my $category = shift;

if (!@exclude_categories) {
my $category = &build_select_field ("Category", "$in{'Category'}");
my $altcategories = &build_select_field ("AltCategories", "$in{'AltCategories'}", "AltCategories", "MULTIPLE Size=3");
}
else {
($category = &get_cat_select_list);
($altcategories = &get_altcat_select_list);
}


print &load_template ('add.html', {
AltCategories => $altcategories,
Category => $category,
category => $category,
%globals
});
}

And, on add.html, etc., I have:
Code:
<tr>
<td align="right" valign="top" width="30%"><b><font size="2" face="Tahoma">Additional Category:</font></b></td>
<td align="left" width="69%"><font face="Arial" size="2">
<%AltCategories%>
</font></td>
</tr>

I've tried these threads:
www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/000960.html
www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/002153.html
www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/003679.html

But, still, I can't figure out the bug. If anyone has any ideas, I would be very grateful for any help. Sorry about all the code, I've tried everything I can think of.

Thanks.


[This message has been edited by DogTags (edited January 19, 2000).]
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Remember under your assumed other identity in this forum...You asked about how to reduce the number of alternative categories users can select from the AltCategories field???

Wink

(Actually it was in three or more Threads that you asked about this.)

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
http://www.anthrotech.com
Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
----------------------





Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Oh, yeah. Actually, that was referring to widgetz' code to limit the number of altcats selected by users. In fact, I know that you posted a topic asking for this code, and I posted it for you.

I hope you see the difference between getting a MULTIPLE box to work and limiting the number of alternates that a link owner can sign up for. For instance, if you put a limit of 5 categories, then if a link owner tries to sign up for 6, then they get an error message (I guess).

And, just to prove that I'm a nice guy (at least my mother thinks so!), I'm gonna post those codes again in case you're still interested. Here they are:

Code:
@data = split("~~", $field);
($#data+1 > 5) and &error("too many") and return;

Here's the thread:
http://www.gossamer-threads.com/...um3/HTML/003679.html

Thanks, again. It's off to db.utils...
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Dog Tags,

Here is what I have in the db_utils.pl file and in the site_html_templates.pl file. I really hope this codes work...THEY should...Because it works for me on my site...look at:

vlib.anthrotech.com/bin/add.cgi
vlib.anthrotech.com/bin/modify.cgi

1) sub build_select_field - db_utils.pl:

Code:
sub build_select_field {
# --------------------------------------------------------
# Builds a SELECT field based on information found
# in the database definition.
#
my ($column, $value, $name, $mult) = @_;
my ($size, %values, $field_clean);

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

if (! exists $db_select_fields{$column}) {
$db_select_fields{$db_cols[$db_category]} = $db_select_fields{'Mult-Related'} = join (",", &category_list);
}

# New codes added for the Multiple Category Mod
# Written by elms
# Thread: http://www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/000960.html
# Added December 16,1999

if (! exists $db_select_fields{$column} && $column eq "AltCategories" && exists $db_select_fields{'Category'}) {
$db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = $db_select_fields{'Category'}
}
elsif (! exists $db_select_fields{$column} && $column eq "AltCategories" && ! exists $db_select_fields{'Category'}) {
$db_select_fields{$db_cols[$db_alt_cat]} = $db_select_fields{'Mult-AltCategories'} = join (",", &category_list);
}

# End New codes for Multiple Category Mod

if ($mult) {
@fields = split (/\,/, $db_select_fields{"Mult-$column"});
%values = map { $_ => 1 } split (/\Q$db_delim\E/, $value);
}
else {
@fields = split (/\,/, $db_select_fields{$column});
$values{$value}++;
}
($#fields >= 0) or return "error building select field: no select fields specified in config for field '$column'!";

$output = qq|<SELECT NAME="$name" $mult SIZE=$size><OPTION>---|;

foreach $field (@fields) {
$field_clean = &build_clean($field);
$values{$field} ?
($output .= qq|<OPTION VALUE="$field" SELECTED>$field_clean\n|) :
($output .= qq|<OPTION VALUE="$field">$field_clean|);
}
$output .= "</SELECT>";
return $output;
}

2) sub build_html_record_form in db_utils.pl file:

Code:
sub build_html_record_form {
#--------------------------------------------------------
# Builds a record form based on the config information.
#
my ($output, $field, $multiple, $name);
($_[0] eq "multiple") and ($multiple = 1) and shift;
my (%rec) = @_;
$output = "<p><table border=1>";
# Go through a little hoops to only load category list when absolutely neccessary.
if ($in{'db'} eq 'links') {
exists $db_select_fields{$db_cols[$db_category]}
or ($db_select_fields{$db_cols[$db_category]} = join (",", &category_list));
($db_select_fields{$db_cols[$db_alt]} = $db_select_fields{'Mult-AltCategories'} = join (",", &category_list));
}
else {
$db_select_fields{'Related'} or
($db_select_fields{'Related'} = $db_select_fields{'Mult-Related'} = join ",", &category_list);
}
foreach $field (@db_cols) {
# Set the field name to field-key if we are doing multiple forms.
$multiple ? ($name = "$field-$rec{$db_key}") : ($name = $field);
if ($db_select_fields{"Mult-$field"}) {$output .= "<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%>" . &build_select_field($field, $rec{$field}, $name, "MULTIPLE SIZE=5") . "</td></tr>\n";}
elsif ($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}, $name) . "</td></tr>\n"; }
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}, $name) . "</td></tr>\n"; }
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}, $name) . "</td></tr>\n"; }
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 wrap="virtual" name="$name" cols="$1" rows="$2">$rec{$field}</textarea></td></tr>\n~;}
elsif ($db_form_len{$field} == -1) {$output = qq~<input type=hidden name="$field" value="$rec{$field}">\n$output~; }
else {$output .= qq~<tr><td align=right valign=top width=20%><$font>$field:</font></td><td width=80%><input type=text name="$name" value="$rec{$field}" size="$db_form_len{$field}" maxlength="$db_lengths{$field}"></td></tr>\n~;}
}
$output .= "</table></p>\n";
return $output;
}

3) sub site_html_add_form in the site_html_templates.pl file:

Code:
sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#

my $category = shift;
my $clean_category = &build_clean($category);
$category ?
($category = qq~$clean_category <input type=hidden name="Category" value="$category">~) :
($category = &build_select_field ("Category", "$in{'Category'}"));
my $altcategories = &build_select_field ("AltCategories","$in{'AltCategories'}","AltCategories","MULTIPLE Size=5");
&html_print_headers;
print &load_template ('add.html', {
Category => $category,
AltCategories => $altcategories,
%in,
%globals
});
}


Hope this helps.

BTW: Question?? Why were you asking about getting the selection reduction of AltCategories when you could not even get the original install to work?? Just curious.

Smile

(I really hope this is the LAST Thread that will discuss this matter! Smile)

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
http://www.anthrotech.com
Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
----------------------





Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Hi, Eliot

Sorry, but I'm not sure what you mean by "Why were you asking about getting the selection reduction of AltCategories when you could not even get the original install to work??"

I got everything to work but the MULTIPLE select box. That's been the only problem.

A little while ago, I was asking about reducing Link HTML for the LastLink mod. Is that what you mean?

Sorry if I seem a little daft...let me know if I can help with your question further.

And, as always, thank you so much for your help. I'm gonna dig in right now and see if I can fix this boy...

Much appreciated Smile
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Hi, again, Eliot.

I use Bobsie's Exclude Mod.

Actually, I implemented Joker's Join mod that puts together Loopy's multi-category, elms (who added altcats to add/modify forms), and Bobsie's Exclude mod.

If I recall right, first I put in Loopy's, then I put in elms. I believe that the Multiple worked okay up to this point. Then, I added Joker's mod - I think this might be where it stopped working. It's been a while. I'll contact Joker, and hopefully he'll have some feedback. I noticed that he does not have an AltCat box on his add or modify pages.

elms
www.gossamer-threads.com/scripts/forum/resources/Forum3/HTML/000960.html

Joker
www.concepts2000.com/Directory/Mods/join.html

I wonder if anyone else using the Join Mod is having the same problem (that is, if it's causing the hang up).

Thanks.

[This message has been edited by DogTags (edited January 19, 2000).]
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
I contacted tech help at the Priority Logo Links site (concepts2000.com), and all I was told was to make sure that I had the <%AltCategories%> tag in place.

Well, I already had that, but it's still not building the Multiple Select Box for AltCategories. It only builds a single.

Would anyone have any other ideas?

Thanks.
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Thanks. Smile
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Still nothing. I think the code that is not being read is

db_utils.pl/sub build_select_field
Code:
$output = qq|<SELECT NAME="$name" $mult SIZE=$size><OPTION>---|;
foreach $field (@fields) {
$values{$field} ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
}

It seems like it's not reading that $mult thing.

In fact, I just tried commenting out the following to see if I would get an error or whether the add.html page would be built WITHOUT the Category and Altcategory select boxes:
Code:
$output = qq|<SELECT NAME="$name" $mult SIZE=$size><OPTION>---|;
foreach $field (@fields) {
$values{$field} ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";

but it had No Effect. The Select boxes still showed up, but both as singles, and they had all the categories and altcategories correctly.

Also in db_utils.pl/sub build_select_field,
Code:
my ($column, $value, $name, $mult) = @_;
my ($size, %values);

$name | | ($name = $column);
$size | | ($size = 1);

Does this mean that $size has already been defined as 1 so that no other value is valid? I tried changing $size = 1 to $size = 3, but it didn't seem to matter. Maybe I define $mult differently in there?

I can Exclude just fine, and a visitor can add/modify Altcategories with no problem. The only bug is the Multiple Select box on the forms.

It also appears that the Join Mod has been taken down. I just tried it - www.concepts2000.com/Mods/join.html , but I keep getting a 404. I hope that this is only temporary and that this bug can be fixed.

Thanks for any help. Smile

[This message has been edited by DogTags (edited January 30, 2000).]
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Okay, I think I've got it narrowed down a little more.

In site_html_templates.pl, I have:
Code:
sub site_html_add_form {
# --------------------------------------------------------
# This routine determines how the add form page will look like.
#
&html_print_headers;
my $category = shift;

if (!@exclude_categories) {
my $category = &build_select_field ("Category", "$in{'Category'}");
my $altcategories = &build_select_field ("AltCategories", "$in{'AltCategories'}", "AltCategories", "MULTIPLE Size=3");
}
else {
($category = &get_cat_select_list);
($altcategories = &get_altcat_select_list);
}


print &load_template ('add.html', {
AltCategories => $altcategories,
Category => $category,
category => $category,
%globals
});
}

If I comment out the following:
Code:
my $altcategories = &build_select_field ("AltCategories", "$in{'AltCategories'}", "AltCategories", "MULTIPLE Size=3");
a Single select box still gets built for Altcategories. The result is no different from what I'm currently getting.

But, if I comment out the following by itself:
Code:
($altcategories = &get_altcat_select_list);
No Select box is built.

Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Problem Solved!

It all has to do with how the altcat_sel.txt file is built in /data

In nph-build.cgi, scroll down to the bottom and find
Code:
sub build_category_select_list {
# --------------------------------------------------------
# This subroutine will build a category select list of only desired subcategories.
my ($subcat, @rootcat);
my $cat_select_list = $db_script_path . "/data/cat_sel.txt";
print "\tOpening file: $cat_select_list\n";
open (SELECT, ">$cat_select_list") or
&cgierr ("unable to open $cat_select_list. Reason: $!");

print SELECT qq|<select name="Category">\n <option>---\n|;
foreach $subcat (sort keys %category) {
if ($subcat !~ /^\s*$/) { push (@rootcat, $subcat); }
}
$category = &site_html_cat_select_list (@rootcat) if ($#rootcat >= 0);
print SELECT $category;
print SELECT qq|</select>\n|;

print "\tClosing file.\n";
close SELECT;


my ($subcat, @rootcat);
my $altcat_select_list = $db_script_path . "/data/altcat_sel.txt";
print "\tOpening file: $altcat_select_list\n";
open (SELECT, ">$altcat_select_list") or
&cgierr ("unable to open $altcat_select_list. Reason: $!");

print SELECT qq|<select name="AltCategories">\n <option>---\n|;
foreach $subcat (sort keys %category) {
if ($subcat !~ /^\s*$/) { push (@rootcat, $subcat); }
}
$altcategories = &site_html_cat_select_list (@rootcat) if ($#rootcat >= 0);
print SELECT $altcategories;
print SELECT qq|</select>\n|;

print "\tClosing file.\n";
close SELECT;
}
Find the line in there that reads:
Code:
print SELECT qq|<select name="AltCategories">\n <option>---\n|;

Change it to:
Code:
print SELECT qq|<select name="AltCategories" MULTIPLE Size="3">\n <option>---\n|;

Now, the MULTIPLE on add.html, modify.html is working OK.

This problem only arose AFTER I added the Join Mod, which included Bobsie's Exclude mod. I did NOT have this problem if I used ONLY Loopy's AltCategory Mod and elms' code to add Loopy's to add.html, modify.html, etc.

I'm going to write to Joker, the author of the Join Mod, to tell him about this fix. Hopefully, he'll add this.

HTH

[This message has been edited by DogTags (edited January 30, 2000).]
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Good...Glad you figured it out.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
* Be sure to visit the Resource Center for FAQ's, Modifications and Extra Goodies!!
* Search Forums!
* Say NO to Duplicate Threads. :)
----------------------








Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Sorry, for interrupting such a nice conversation.

But please tell me where did you both find
procedure get_altcat_select_list . Can I get a source?

It is called from site_html_templates.pl

Many thanx in advance.
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
nph-build.cgi
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
AAHHH!! You beat me to it!!!

I've been trying to figure this one out for a week and then it dawned on me that this was the problem and I've just visited to post a reply in my thread and saw this one.

I will post the code to the Joker so he can change his mod when he gets the time.

DUR

I see that you have already done IT!!!



------------------
Regards
MDJ
www.isee-multimedia.co.uk


[This message has been edited by mdj1 (edited February 09, 2000).]
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Eliot.

Worked PERFECT !!!

First time is always the best time!

Mucho Grande! (or somethin' like that! : )

Thanks Eliot!
JbA
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
mdj1

Yep, I hope that Joker adds the correction I found and re-posts the mod, cuz it's great having all those things working together.
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Found another wrinkle with the Exclude Mod

http://www.gossamer-threads.com/...um3/HTML/005155.html

This has to do with pre-selecting the Category and AltCategories in modify.cgi

Smile
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
I just responded to your other Thread...Refer to the Thread Ian posted a week ago that addresses the issue of the Modify Mod.

Regards,

------------------
Eliot Lee....
* Check Resource Center
* Search Forums

Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Hi !!!

I can't create AltCategories in modify_form.

This is my code:

code
--------------------------------------------

sub site_html_modify_form {
# --------------------------------------------------------
# This routine determines how the modify form page will look like.

my %rec = @_;
my $category = &build_select_field ("Categoria", "$rec{'Categoria'}");

&html_print_headers;
print &load_template ('modify.html', {
category => $category,
AltCategories => &build_select_field ("AltCategories", "$rec{'AltCategories'}"),
estado => &build_select_field ("Estado", "$rec{'Estado'}"),
%rec,
%globals
});
}

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

I receive this line instead the build_select_field:

AltCategories: Matérias-Primas/Indústrias/MDF|Serviços


I'm using %rec and my others two select_fields (Categoria and Estado) are wonking perfectly.

What's wrong ???

Any ideas ???

Regards,

Marco Aurélio
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Marco...

Do the following:

1) Put the following codes at the top of your sub site_modify_form:

Code:
my $category = &build_select_field ("Categoria", "$rec{'Categoria'}");
my $altcategories = &build_select_field ("AltCategories","$rec{'AltCategories'}","AltCategories","MULTIPLE Size=5");

2) Then define the tags as follows in this sub:

Code:
categoria => $category,
altcategories => $altcategories,

3) Then in your modify.html template file, add the following codes:

Code:
<%categoria%>

AND

Code:
<%altcategories%>

Regards,



------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Great job Eliot .... you are my savior !

Now all is working perfectly !!!

Best Regards,

Marco Aurélio
Quote Reply
Re: Can't Create AltCategory MULTIPLE Select Box In reply to
Good...You're welcome.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums