There are a couple ways to do this. The simplest way would be to create a global that gives you a list of the current subscribed forums, then simply pass all of them, as well as the new one.
global:
my $current = shift;
my @subscribed = $DB->table('ForumSubscriber')->select(
forum_id_fk => {
user_id_fk => $USER->{user_id}
}
)->fetchall_list;
my %ret;
for (@subscribed) {
if ($_ == $current) { $ret{subscribed} = 1 }
else { push @{$ret{subscribed_to}}, $_ }
}
\%ret;
}The code above grabs all the subscribed forum ids and returns them, but if the forum_id you pass in is found, it returns a "subscribed" variable if it was found and DOESN'T return that ID in the list (allowing you to unsubscribe by simply not adding the ID).
So, in a template, you'd do something like:
<a href=".........gforum.cgi?<%loop subscribed_to
%>subscribe=<%loop_value%>;<%endloop
%><%unless subscribed%>subscribe=<%forum_id%>;<%endunless
%>do=user_pro......"><%if subscribed
%>Unsubscribe<%else
%>Subscribe<%endif%></a>
Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
global:
Code:
sub { my $current = shift;
my @subscribed = $DB->table('ForumSubscriber')->select(
forum_id_fk => {
user_id_fk => $USER->{user_id}
}
)->fetchall_list;
my %ret;
for (@subscribed) {
if ($_ == $current) { $ret{subscribed} = 1 }
else { push @{$ret{subscribed_to}}, $_ }
}
\%ret;
}
So, in a template, you'd do something like:
Code:
<%global($forum_id)%> <a href=".........gforum.cgi?<%loop subscribed_to
%>subscribe=<%loop_value%>;<%endloop
%><%unless subscribed%>subscribe=<%forum_id%>;<%endunless
%>do=user_pro......"><%if subscribed
%>Unsubscribe<%else
%>Subscribe<%endif%></a>
Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com