Gossamer Forum
Home : Products : Gossamer List : Discussion :

Subscription list

Quote Reply
Subscription list
Is there anyway to create or to access a page (users logged in with community), that displays any glist subscriptions they have.

What I would like to have is a page where community users can select what newsletters to subscribe to or unsubscribe from, a simple tickbox list where users can easily manage their differenet subscriptions, how can I do that?

Thanks
Quote Reply
Re: [demon] Subscription list In reply to
Hi,

The global template below will handle this matter:

Code:
sub {
my ($lids, $email) = @_;

return unless $lids;
lib->import('PATH_TO_GLIST/private/lib');
require GT::SQL;
require GT::SQL::Condition;
my $db = GT::SQL->new('PATH_TO_GLIST/private/defs');
my %hash;
if ($email) {
my $subs_db = $db->table('Subscribers');
my $sth = $subs_db->select(['sub_list_id_fk'], { sub_email => $email });
while (my ($lid) = $sth->fetchrow_array) {
$hash{$lid} ||= 1;
}
}
my @lids = split(',', $lids);
my $db_list = $db->table('Lists');
$db_list->select_options('ORDER BY lst_title');
my $lists = $db_list->select(GT::SQL::Condition->new(lst_id => 'IN' => \@lids))->fetchall_hashref;
if (%hash) {
foreach (@$lists) {
$_->{checked} = 1 if (exists $hash{$_->{lst_id}});
}
}
return { loop_glist_lists => $lists, lists => $lids };
}

Now, you can use the global in user_include_profile.html or user_signup.html form like:
<%global_name('list_id1,list_id2,...', $comm_email)%>
<%loop loop_glist_lists%>
<input name="app_glist_subscribed" value="<%lst_id%>" <%if checked%>checked<%endif%>
<%endloop%>

list_id1, list_id2 are list ID that you want to display on the user profile form.

Hope thats help.

TheStone.

B.

Last edited by:

TheStone: Jan 4, 2005, 10:11 AM
Quote Reply
Re: [TheStone] Subscription list In reply to
Thanks for your reply! Thats great!

You mention that it can be used in: user_include_profile.html or user_signup.html

Does that mean I can NOT use this on any other page. Could I not create a seperate page which only shows subscriptions and nothing else. Much like a profile page but only with subscriptions that users could access when they have logged in.

Thanks again!
Quote Reply
Re: [demon] Subscription list In reply to
That's global template, so it can be used only in communty templates, otherwise it won't work.

TheStone.

B.
Quote Reply
Re: [TheStone] Subscription list In reply to
Ok... you mean it has to be called / go through community.cgi to work?

How then can I create a new page that only displays the subscriptions? Is there anyway to use say the profile template, but with a <%if subscription%> so that only the subscription part is shown..

Maybe something by clicking on the normal profile link, ie to update your profile.. but with a extra bit at the end maybe.. ?subscription or something.. that then makes sure that it only displays the subscription information..

Or soemthing similiar.. Any ideas? Without chaning the community script!?

It would be extremly usefull to have a seperate page with ONLY subscriptions on it..

Thanks

Bjorn
Quote Reply
Re: [demon] Subscription list In reply to
Yes, you can do that in the profile template:

<%if subscription%>
<%include subscription.html%>
<%else%>
user profile here
<%endif%>

Now you can use community.cgi?do=user_profile;subscription=1 to display this part.

TheStone.

B.
Quote Reply
Re: [TheStone] Subscription list In reply to
Great! Thats excellent, just what I need.

Thanks for your help.
Quote Reply
Re: [TheStone] Subscription list In reply to
One last question, with using that. Will that mean users can tick off or on / ie subscribe to or remove from lists on that page or will it only display subscriptions?

I presume then that the last <%endif%> tag needs to be before the submit button which users would press to update the profile details in a normal case.

Will try it out..
Quote Reply
Re: [demon] Subscription list In reply to
It will add or remove user email from lists, just make sure the objects below must be in the subscription form:
<%if t%><input type="hidden" name="t" value="<%escape_html t%>"><%endif%>
<input type="hidden" name="do" value="user_profile" />
<input type="hidden" name="user_profile_submit" value="1" />

TheStone.

B.
Quote Reply
Re: [TheStone] Subscription list In reply to
Thanks, I thought it might be needed.
Quote Reply
Re: [TheStone] Subscription list In reply to
Sorry to be a pain..

I tried it, most of it did work. The <%endif%> tags worked fine, so did the URL and show only subscriptions.

But it did not actually display the different lists, it only gave the following error:

Error: Variable 'subscript_list' is not a code reference (subscript_list is what I called the global).

The global you showed, I entered that as a global in LinksSQL since I could not find anywhere to enter a global or either list or community.

The code I used on the user_profile template is (did a small change, see part in red):

<%subscript_list('My Newsletter,Another Newsletter', $comm_email)%>
<%loop loop_glist_lists%>
<input name="app_glist_subscribed" type="checkbox" value="<%lst_id%>" <%if checked%>checked<%endif%>">
<%endloop%>


The Global Code I entered into LinksSQL is:

sub {
my ($lids, $email) = @_;
return unless $lids;
lib->import('PATH_TO_GLIST/private/lib');
require GT::SQL;
require GT::SQL::Condition;
my $db = GT::SQL->new('PATH_TO_GLIST/private/defs');
my %hash;
if ($email) {
my $subs_db = $db->table('Subscribers');
my $sth = $subs_db->select(['sub_list_id_fk'], { sub_email => $email });
while (my ($lid) = $sth->fetchrow_array) {
$hash{$lid} ||= 1;
}
}
my @lids = split(',', $lids);
my $db_list = $db->table('Lists');
$db_list->select_options('ORDER BY lst_title');
my $lists = $db_list->select(GT::SQL::Condition->new(lst_id => 'IN' => \@lids))->fetchall_hashref;
if (%hash) {
foreach (@$lists) {
$_->{checked} = 1 if (exists $hash{$_->{lst_id}});
}
}
return { loop_glist_lists => $lists, lists => $lids };
}

Any idea?

Thanks!
Quote Reply
Re: [demon] Subscription list In reply to
The subscript_list should be a GCommunity global instead, so you can use it in community user_profile template. There are a few things need to be changed with your glist setup info:

- <%subscript_list('My Newsletter,Another Newsletter', $comm_email)%> should be <%subscript_list('list_id1,list_id2,....', $comm_email)%> instead.
-
PATH_TO_GLIST should be the path to GList private/lib.

TheStone.


B.
Quote Reply
Re: [TheStone] Subscription list In reply to
Tried that, there is no errors now and it seems to work.. however it does not show any lists at all.. Only the button on the form is displayed (same button as for user_profile) the check boxes or list that the user is subscribed to does not show up at all. Simply blank.

I got the other stuff sorted out, did get a few errors but it was because it was pointing to the wrong location for glist etc..

Could it be something with the html?

Ive tried:

<%subscript_list('list_id1,list_id2,...', $comm_email)%>
<%loop loop_glist_lists%>
<input name="app_glist_subscribed" value="<%lst_id%>">
<%endloop%>

and also

<%subscript_list('list_id1,list_id2,...', $comm_email)%>
<%loop loop_glist_lists%>
<input name="app_glist_subscribed" value="<%lst_id%>" <%if checked%>checked<%endif%>">
<%endloop%>

AND

<%subscript_list('list_id1,list_id2,...', $comm_email)%>
<%loop loop_glist_lists%>
<input name="app_glist_subscribed" type="checkbox" value="<%lst_id%>" <%if checked%>checked="checked"<%endif%> />
<%endloop%>

Neither of them work..

Any idea? Thanks!
Quote Reply
Re: [demon] Subscription list In reply to
Can you send me the username and password of ssh or telnet via email, I will have a closer look at it?

TheStone.

B.

Last edited by:

TheStone: Jan 11, 2005, 10:46 AM