Gossamer Forum
Home : Products : DBMan : Customization :

Add to favorites...

Quote Reply
Add to favorites...
Hi,

I would like to have a feature that will let users add a record to their favorites. When they want to see all their favorites, they click on "My Favorites", and all the records they added will be listed.

Here is an example:
I'm searching a site that sells cars. I get 200 results for "Nissan Maxima". There are some that I have interest in, but I still want to browse the rest of the results. So I click on "Add To Favorites" next to the car I'm interested in, and continue browsing the rest of the results. When I'm ready to see all my selections I click on "My Favorites" and I see all the records I was interested in.

You can see an example of this at http://www.classifieds2000.com . They use the word "Hot List" not "Favorites".

I hope you understand my question. Let me know if you need more info.

As always, Thank You
Eli
Quote Reply
Re: Add to favorites... In reply to
I understand what you want. Mart has done something similar with adding records to a "Preferences" database. You might try doing a search on both of the DBMan forums for it.


------------------
JPD





Quote Reply
Re: Add to favorites... In reply to
Hi,

Thanks for the reply.

What words do you suggest I search for?

Thanks
Eli
Quote Reply
Re: Add to favorites... In reply to
I can't find it. If I run across it I'll let you know.

Did you want users to add the records to their "Favorites" one at a time, or to be able to select checkboxes, or to just have a button to add the entire current list to their favorites?

I'm sorta starting to think of how to do it, but it might take me a little while. In the meantime, maybe Mart will come by and have some suggestions.


------------------
JPD





Quote Reply
Re: Add to favorites... In reply to
I think it would be just fine if it's one at a time. There would be small button next to the record labeled "Add To Favorites".

Thanks
Eli
Quote Reply
Re: Add to favorites... In reply to
Okay. I'll see what I can come up with after I get something to eat. (I'm starting to fade already from hunger! Smile )


------------------
JPD





Quote Reply
Re: Add to favorites... In reply to
 Smile I know the feeling. Enjoy your meal.
Quote Reply
Re: Add to favorites... In reply to
I started on this, but then I realized I had a question.

You say that it's okay to have just a button with the record that says "Add To Favorites". Where do you want the script to go after that? Do you want a confirmation screen that it was added or do you want to return to the search results page?



------------------
JPD





Quote Reply
Re: Add to favorites... In reply to
I would like them to go back to the search results.

Thanks
Eli
Quote Reply
Re: Add to favorites... In reply to
Hi,
This is how I've done this:
I've create a new db and ofcourse another .cfg, also a new sub in the script, 'add_preference', from where a userid of a record is changed in the userid of the one who is watching it, also the added-date is change there in the 'today-date', (useful for the autodelete-mod). By each record_long display, a link only displayed, when a registered user is watching. This link will add the record to the preference-list of the user. I've setup this with a maximum adding records of 10 per user and the records fall out in 7 days. Make sence???

You might try it at http://www.autorandstad.nl (in Dutch...)

Goodluck.
Greetings,
--------
Mart.
Quote Reply
Re: Add to favorites... In reply to
This is what I've come up with. I couldn't figure out how to go back to the search list, though. Sorry.

In your .cfg file, add the following:

Code:
$db_favorites = $db_script_path . "/favorite.db";

Create a blank file -- favorite.db -- in your directory. chmod to 666.

In db.cgi, with the other "elsif" statements, add

Code:
elsif ($in{'add_favorites'}) { if ($per_view) { &add_to_favorites; } else { &html_unauth; } }
elsif ($in{'view_favorites'}) { if ($per_view) { &view_favorites; } else { &html_unauth; } }

In db.cgi, add the following subroutines:

Code:
sub add_to_favorites {
#---------------------------------------

open (FAVE, "<$db_favorites") or &cgierr("error in add_to_favorites. unable to open favorites file: $db_favorites.
\nReason: $!");
if ($db_use_flock) { flock(FAVE, 1); }
LINE: while (<FAVE> ) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
$line = $_; chomp ($line);
@data = &split_decode($line);
if ($data[0] eq "$in{$db_key}-$db_userid") {
$message = "That item is already in your favorites list";
}
}
close FAVE;
unless ($message) {
open (FAVE, ">>$db_favorites") or &cgierr("error in add_to_favorites. unable to open favorites file: $db_favorites.
\nReason: $!");
if ($db_use_flock) {
flock(FAVE, 2) or &cgierr("unable to get exclusive lock on $db_favorites.
\nReason: $!");
}
$date = &get_date();
print FAVE "$in{$db_key}-$db_userid|$date";
close FAVE; # automatically removes file lock
$message = "Item added to favorites list";
}
&html_favorite_success($message);
}

sub view_favorites {
# --------------------------------------------------------

open (FAVE, "<$db_favorites") or &cgierr("error in view_favorites. unable to open favorites file: $db_favorites.
\nReason: $!");
if ($db_use_flock) { flock(FAVE, 1); }
@flines = <FAVE>;
close FAVE;
foreach $fline (@flines) {
@data = &split_decode($fline);
if ($data[0] =~ /(.+)-$db_userid/) {
$in{$db_key} .= "$1|";
}
}
chop $in{$db_key};
$in{'re'} = 1;
$in{'ww'} = 1;
my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure("No favorites on file");
}
}

In html.pl, sub footer, add

Code:
print qq!| <A HREF="$db_script_link_url&view_favorites=1">View Favorites</A> ! if ($per_view);

In html.pl, add the following subroutine:

Code:
sub html_favorite_success {
# --------------------------------------------------------
# This page let's the user know that the records were successfully
# deleted.

my $message = shift;

$page_title = "Favorite added";
&html_page_top;

# < -- Start page text -- >
print qq|
<$font>$message</font><P>
<$font>Please use the back button on your browser to return to your search results.</font>
|;
# < -- End page text -->

&html_footer;
&html_page_bottom;
}

(This is assuming you're using one or the other of my html.pl files. If not, you'll need to work out your own top and bottom of page formatting.)

In sub html_record, include a link

Code:
<a href="$db_script_link_url&$db_key=$rec{$db_key}&add_favorites=1">Add to your list of favorites</a>

The mod writes to a small database, which has only two fields --
the key, consisting of the $db_key value for the record and the userid
the date. (You didn't say you wanted the date, but I thought I'd go ahead and put it in there.)

When the user clicks the "View Favorites" link, the script looks through the "favorites.db" for anything with the userid as part of the field. When it finds the record, it takes out the part that is not part of the userid and adds it to a search term, with a |. It then sets re=1, which causes the search to look for records whose key value is any one on the list.

At least that's what it's supposed to do. I haven't tested it.


------------------
JPD







[This message has been edited by JPDeni (edited August 29, 1999).]