Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Need help with &get_category_list

Quote Reply
Need help with &get_category_list
Hi...I'm trying to make this modification that handles multiple "Link" and "Category" tables as being different sections. I have all the mods completed that separate and build the different sections but can't figure out a couple things. How does the Category list get built?

Code:
Here is the code I am trying:
sub get_category_list {
# --------------------------------------------------------
# Builds a <select> list of category name to category id.
#
my $value = shift;
my $fname = shift | | 'CategoryID';
my $mult = shift | | '';
$mult and ($mult = "MULTIPLE SIZE=4");
my ($query, $sth, $id, $name, $output, $time);
my $cat_table_name_to_use = "$ENV{'REMOTE_USER'}cat";
# Explain: All sections are based on
# the value of REMOTE_USER and their
# respective categories have cat
# following them. IE: Storecat, Calendarcat, etc...

# $output = $CATEGORY_LIST{$value,$fname};
$time = time();

if (!$output) {
if (! $CATDB) {
$CATDB = new Links: : DBSQL $LINKS{admin_root_path} . "/defs/$ENV{'REMOTE_USER'}cat.def";
}
$query = qq!
SELECT ID, Name
FROM $cat_table_name_to_use
ORDER BY Name
!;

$sth = $CATDB->prepare ($query);
$sth->execute() or die "Can't Execute: $DBI::errstr";
$output = "<select $mult name='$fname'><option value=''>----";
while (($id, $name) = $sth->fetchrow_array) {
($id == $value) ? ($output .= "<option value='$id' SELECTED>$name") : ($output .= "<option value='$id'>$name");
}
$output .= "</select>";
$sth->finish;
$CATEGORY_LIST{$value,$fname} = $output;
}
return $output;
}
But the Category list is still showing up as a text input box, is there a different way I need to define the $cat_table_name_to_use?

I am stumped...

[This message has been edited by phoule (edited January 03, 2000).]

[This message has been edited by phoule (edited January 03, 2000).]
Quote Reply
Re: Need help with &get_category_list In reply to
If it's still showing up as a text input box, how are you calling this? If it's from a DBSQL object, make sure you pass in the name of the subroutine as in:

$db->build_html_record_form ( {}, { CategoryID => \&get_category_list } );

the first argument is a name => value hash ref of what you should put in the form, the second argument is a list of options. You can pass field name to subroutine and it will use that to generate a row.

Hope this helps,

Alex
Quote Reply
Re: Need help with &get_category_list In reply to
I understand what you mean...so what your saying is that the admin panel doesn't default to the routine I mentioned? If so where should I be looking to make this change?
Quote Reply
Re: Need help with &get_category_list In reply to
The admin panel uses:

CategoryID => \&build_category_row

Which basically produces a select list from &get_category_list, or a text box depending on the value of:

Quote:
# Set to one to have Links generate a category list, set to 0 to use
# the category id.1
$LINKS{db_gen_category_list} = 1;

in Links.pm. I'd need to see how you are calling this to help more.

Cheers,

Alex
Quote Reply
Re: Need help with &get_category_list In reply to
In Links.pm I have that value set to 1, and if I'm setting a different name to the Table that it is Selecting From, in &get_category_list then it seems like the default the admin uses should be pulling the right info for the categories...

I'm gonna get to work on it tomorrow, and see if I can figure it out...