Gossamer Forum
Home : Products : Gossamer Links : Discussions :

mutlpile categories add modify form

Quote Reply
mutlpile categories add modify form
hi,
the use the following global my add/modify.it works perfectly. Also when people select to place their links in multiple categories, it will do this.however when they go to modify that link, only one category shows as selected them to modify form. how can I change this so that it shows all the categories that the link is associated with in the multiple select form
sub {
my $catid = shift;
my $show_count = $_[0];
my $in_id = $IN->param('CatLinks.CategoryID') || $IN->param('ID');
my $table = $DB->table('Category') || return $GT::SQL::error;
my $back;

$table->select_options('ORDER BY Full_Name') || return $GT::SQL::error;
my $cond = GT::SQL::Condition->new('menuShow','=','Yes');
my $sth = $table->select( ['ID','Full_Name','Number_of_Links'], $cond) || return $GT::SQL::error;

while (my ($id,$full_name,$numberoflinks) = $sth->fetchrow_array) {
my $full_name2;
my @cut = split /\//, $full_name;
for (my $i=0; $i < $#cut; $i++) {
$full_name2 .= "&nbsp;&nbsp;&nbsp;";
}
$full_name2 .= $cut[$#cut];
if ($show_count) {
$full_name2 .= " ($numberoflinks)";
}
$back .= "<option value=\"$id\"";
if ($in_id == $id) { $back .= "selected=\"selected\""; }
$back .= ">$full_name2</option>";
}
my $send_back = qq|<select MULTIPLE SIZE="5" name="CatLinks.CategoryID"><option value="">------</option>$back</select>|;
return $send_back;
}
cheers,
Quote Reply
Re: [ajiimd] mutlpile categories add modify form In reply to
Try something like this... I think that should help

sub {
my ($rec) = @_;
my $id = $rec->{ID};
my $db = $DB->table('CatLinks');
my @sids = $db->select ( ['CategoryID'], { 'LinkID' => $id } )->fetchall_list;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name ASC');
my $sth = $cat_db->select ( { 'Description' => 'SUB1' }, ['ID', 'Full_Name'] );
my $output;
$output .= "<SELECT MULTIPLE SIZE='7' name='CatLinks.CategoryID' class='button'>";
$output .= "<option value=''>-------</option>";
while (my ($cid,$name) = $sth->fetchrow_array) {
$output .= "<option value='$cid'";
foreach my $sid (@sids) {
if ($sid eq $cid) {
$output .= " selected";
}
}
$output .= ">$name</option>";
}
$output .= "</SELECT>";
return $output;
}
Quote Reply
Re: [Jonze] mutlpile categories add modify form In reply to
thanks, it works!!!

i made few revisions just to change the look of the output

sub {
my ($rec) = @_;
my $id = $rec->{ID};
my $db = $DB->table('CatLinks');
my @sids = $db->select ( ['CategoryID'], { 'LinkID' => $id } )->fetchall_list;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name ASC');
my $cond = GT::SQL::Condition->new('menuShow','=','Yes');
my $sth = $cat_db->select (['ID', 'Full_Name'], $cond);
my $output;
$output .= "<SELECT MULTIPLE SIZE='7' name='CatLinks.CategoryID' class='button'>";
while (my ($cid,$name) = $sth->fetchrow_array) {
my $full_name2;
my @cut = split /\//, $name;
for (my $i=0; $i < $#cut; $i++) {
$full_name2 .= "&nbsp;&nbsp;&nbsp;";
}
$full_name2 .= $cut[$#cut];


$output .= "<option value='$cid'";
foreach my $sid (@sids) {
if ($sid eq $cid) {
$output .= " selected";
}
}
$output .= ">$full_name2</option>";
}
$output .= "</SELECT>";
return $output;
}
Quote Reply
Re: [ajiimd] mutlpile categories add modify form In reply to
Not a problem...glad I could help! Wink

Gotta try to give back a little when I can.
Quote Reply
Re: [Jonze] mutlpile categories add modify form In reply to
is there any way to change the global to show a list of categorys associated with the link as a liston the detail page?
thanks
Quote Reply
Re: [Jonze] mutlpile categories add modify form In reply to
sub {
my ($rec) = @_;
my $id = $rec->{ID};
my $db = $DB->table('CatLinks');
my @sids = $db->select ( ['CategoryID'], { 'LinkID' => $id } )->fetchall_list;
my $cat_db = $DB->table('Category');
$cat_db->select_options ('ORDER BY Full_Name ASC');

my $sth = $cat_db->select (['ID', 'Full_Name'], { FatherID => $field });
my $output;
$output .= "<SELECT MULTIPLE SIZE='7' name='CatLinks.CategoryID' class='button'>";
while (my ($cid,$name) = $sth->fetchrow_array) {
my $full_name2;
my @cut = split /\//, $name;
for (my $i=0; $i < $#cut; $i++) {
$full_name2 .= "&nbsp;&nbsp;&nbsp;";
}
$full_name2 .= $cut[$#cut];
$output .= "<option value='$cid'";
foreach my $sid (@sids) {
if ($sid eq $cid) {
$output .= " selected";
}
}
$output .= ">$full_name2</option>";
}
$output .= "</SELECT>";
return $output;
}


how do i get this to work