Gossamer Forum
Home : Products : DBMan : Customization :

where to block a record from showing up if condition is met

Quote Reply
where to block a record from showing up if condition is met
Hi, I've got a database of articles. It includes a 'publish date' field and a 'stick to publish date' box. Now, the box is 'on' on default. If a user adds an article, he can put it in to show up in the future, say 2 weeks from now.

I know how to compare the date with todays date, but where exactly and how do I put it in the code. I guess it needs to be done at query in db.cgi, but I'm not sure... Because, if the field is set (when doing a search) to 'on' I don't want the record to be included in search results. That would happen if I'd put it in sub html_record in html.pl

To compare the dates I found this:

Code:
$compare1 = &get_date;
$compare2 = &date_to_unix($rec{'Date2'});

if ($compare1 >= $compare2) {
include it in the search results;
}


Has anybody seen something like this already explained in the forum?

Any help is appreciated.

Lex
Quote Reply
Re: [Lex] where to block a record from showing up if condition is met In reply to
Here's my solution if anybody is ever interested:

in db.cgi where you get the 'next line if' (to not include the record in the 'found records') I inserted this (underneath first next LINE) (so the first two lines underneath are already in your db.cgi):

Code:
# If we are only allowed to view/mod our own record, then let's check here.

next LINE if ($restricted and ($db_userid ne $values[$auth_user_field]));

# we check if the publish date is in the future and if the checkbox is clicked that says we should stick to it
if ($in{'view_records'}) {
my $compare2 = &date_to_unix($values[$PublishDate_field]);
my $sum = ($compare1-$compare2);
if ($sum < 0) {
next LINE if ($values[$SticktoDate_field] eq "yes")
}
}



A bit above this, before it says 'foreach field' I inserted:


Code:
my $compare1 = &date_to_unix(&get_date);
(so it wouldn't have to call the function for each record)

For this to work you need te set the PublishDate_field and SticktoDate_field in your .cfg file, like this:

$PublishDate_field = 13; # (if that's your field number)

"if ($in{'view_records'})" is there so it's only doing this when viewing records, not when modifying or anything else.

Maybe somebody likes it...

Have fun,
Lex

Last edited by:

Lex: Oct 3, 2003, 1:10 PM
Quote Reply
Re: [Lex] where to block a record from showing up if condition is met In reply to
That's really cool... I often get lost when attempting to hack the db.cgi.