Gossamer Forum
Home : Products : Links 2.0 : Customization :

Need help with Mod

Quote Reply
Need help with Mod
I need to modify Links to skip or delete a record if a particular date field (I added $db_enddate) has expired. Anyone know how to do this?

Thanks,

-Ryan

[This message has been edited by Ryan (edited February 14, 1999).]
Quote Reply
Re: Need help with Mod In reply to
Ryan,

You didn't say whether you were using Links 1 or 2. Here is something you can try using Links v1 and should be easily modified to use with Links v2. In site_html.pl:

Quote:
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like. It's a little complex looking just because we have to
# check for blank entries..

my (%rec) = @_;
my $enddate = int(&date_to_unix($rec{$db_enddate}));
my $cutoff = int(&date_to_unix($date));

# Ouput the link only if it is equal to or greater than today's date. Otherwise,
# it has expired.
if ($endate => $cutoff) { $output = qq|
<ul type=disc><li><$font><a href="$build_jump_url?$db_key=$rec{$db_key}">$rec{'Title'}</a></font>|;

if ($rec{'Description'}) { $output .= qq| <$font>- $rec{'Description'}</font>\n|; }
if ($rec{'isNew'} eq "Yes") { $output .= qq| <$font_new><i><b>new</b></i></font>|; }
if ($rec{'isPopular'} eq "Yes") { $output .= qq| <$font_pop><i><b>pop</b></i></font>|; }

$output .= qq| <$font_date><em>(Added: $rec{'Date'} Hits: $rec{'Hits'})</em></font><br>
</ul>
|;
}
else {
$output = "";
}
return $output;
}



I am not exactly sure if this works because I haven't tested it, but it looks right to me. If anyone sees any error in this, please speak up.

I hope this helps.


------------------
Bob Connors
bobsie@orphanage.com
www.orphanage.com/goodstuff/
goodstufflists.home.ml.org/




[This message has been edited by Bobsie (edited February 14, 1999).]

[This message has been edited by Bobsie (edited February 14, 1999).]
Quote Reply
Re: Need help with Mod In reply to
Thanks a lot Bob. I'm using one of the betas for Links 2. I'll play around with the code. I'd rather come up with something to delete expired entries in nhp-build.cgi. No sense in keeping them.

By the way, how do I delete a record?

&delete_records($rec{$db_enddate});

does not seem to work. I got an error message. I did add the require to db.pl in nph-build.cgi

Thanks again,

-Ryan

[This message has been edited by Ryan (edited February 14, 1999).]
Quote Reply
Re: Need help with Mod In reply to
 
Quote:
By the way, how do I delete a record?
&delete_records($rec{$db_enddate});
does not seem to work. I got an error message. I did add the require to db.pl in
nph-build.cgi

The sub delete_records requires $rec{'ID'} as it searchs on the ID number. I wouldn't do this in nph-build.cgi though. I would put it in sub site_html_link, site_html.pl or site_html_templates.pl since that is where you discover the record has expired. You could include the call to that routine as part of the "else" portion of the code I gave you.

Regardless, I would be very careful with this deletion code being used while you are building pages. It could result in strange things happening.

It might be better just to open a text file and write the expired links to it and then, using that file, manually delete the links after the build is done. Or write a routine for nph-build.cgi that will delete expired records after the build is done (as the last thing it does or, check for expired links and delete them before the build starts. I just wouldn't do it during the build process.

As a matter of fact, the last thing I said is probably the best solution. If you could write the code to check for and delete any expired records before the build process begins, it would solve a lot of your problems doing what you want to do. You wouldn't need the mod I gave you at all.

I hope this gives you some ideas.



------------------
Bob Connors
bobsie@orphanage.com
www.orphanage.com/goodstuff/
goodstufflists.home.ml.org/