Gossamer Forum
Home : Products : DBMan : Installation :

Calling entries depending on current Date

Quote Reply
Calling entries depending on current Date
Hello!

How can I call entries (dates) depending on the current date. I'm thinking of a event-database, which displays the current day automaticly.

TIA
Markus
Quote Reply
Re: Calling entries depending on current Date In reply to
There would be a couple of ways to do this, depending on what you wanted to do.

If your entries are for, say, a calendar sort of thing, which had the full current date in it, you could create a link by the following:

Code:
# be sure to close off any print qq| statements first!
$date = &get_date;
print qq|
<a href="$db_script_link_url&Date=$date&view_records=1">
See today's events</a>
|;

If you were doing a "this date in history" thing, it would be a little more of a problem, since any dates before 1970 won't work with the built-in date routine. If you're doing this, I'll work with you on it, but there's no point going into it unless I have to. Smile


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





Quote Reply
Re: Calling entries depending on current Date In reply to
Hi!

First, thank you for the very quick response - works's great!! But I've got two more questions:
1. How can I call this feature via URL e.g. /cgi-bin/db.cgi?db=test&date ...
2. and how can I get a output for the current date and e.g. the next 6 days (upcoming events) via URL ???

Thank you
Markus
Quote Reply
Re: Calling entries depending on current Date In reply to
You can't call it by a URL from a static web page, since there is no way to determine the current date on a static web page. Unless there's something in Java or something else that would do it.

Wait a minute. Maybe you can. You could, if you wanted, make a change to db.cgi that would do it automatically. Pardon me while I ponder this a bit first. (Ponder, ponder, ponder.)

Okay. I think I got it.

Open up db.cgi and find sub query.

After

local (%sortby);

add

Code:
if ($in{'today'}) {
$in{'Date'} = &get_date;
}
elsif ($in{'future'}) {
$in{'Date-lt'} = &get_date(time() + ($in{'future'} * 86400));
$in{'Date-gt'} = &get_date(time() - 86400);
}

The last line of the code above makes sure that you don't get events that are outdated. If you don't want it to show today's events, change it to

Code:
$in{'Date-gt'} = &get_date;

A little further down in sub query, you'll need to fix a bug in the script. (unless you recently downloaded DBMan. Alex may have fixed it.)

Look for

Code:
if ($in{"$column-gt"} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and
(&date_to_unix($in{$column}) or return "Invalid date format: '$in{$column-gt}'");
push(@search_gt_fields, $i); }
if ($in{"$column-lt"} !~ /^\s*$/) { ($db_sort{$column} eq 'date') and
(&date_to_unix($in{$column}) or return "Invalid date format: '$in{$column-lt}'");
push(@search_lt_fields, $i); }

Make sure the bolded characters above are in the lines. (I separated the lines a bit so you wouldn't have to scroll across the page. You should be able to find the lines.)

Now, when you create your links on your static html page, use

for today:
http://url/to/cgi-bin/dbman/db.cgi?db=default&uid=default&today=1&view_records=1

for dates in the future:
http://url/to/cgi-bin/dbman/db.cgi?db=default&uid=default&future=7&view_records=1

A couple of things to be careful of. First, if you are using a .cfg file other than default.cfg, change the default in the links to the name of your .cfg file. Second, in the "future" link, adjust the number to whatever you want. You should probably set it one more than you really want, though.

That should work, but it is untested. Smile

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







[This message has been edited by JPDeni (edited April 19, 1999).]
Quote Reply
Re: Calling entries depending on current Date In reply to
Hi !

I've got a prob with the modification: my code looks like:


my ($i, $column, @search_fields, @search_gt_fields, @search_lt_fields, $maxhits, $numhits, $nh,
$field, @regexp, $line, @values, $key_match, @hits, @sortedhits, $next_url, $next_hit, $prev_hit,
$first, $last, $upper, $lower, $left, $right, $restricted);
local (%sortby);
if ($in{'today'}) { $in{'Date'} = $get_date;}elsif ($in{'future'}) { $in{'Date-lt'} = $get_date(time() + ($in{'future'} * 86400)); $in{'Date-gt'} = $get_date(time() - 86400);}

# First thing we do is find out what we are searching for. We build a list of fields
# we want to search on in @search_fields.
if ($in{'keyword'}) { # If this is a keyword search, we are searching the same
$i = 0; # thing in all fields. Make sure "match any" option is
$in{'ma'} = "on"; # on, otherwise this will almost always fail.
foreach $column (@db_cols) {
if (($db_sort{$column} eq 'date') or &date_to_unix($in{'keyword'})) { $i++; next; }
if ($i == $auth_user_field) { $i++; next; }
push (@search_fields, $i); # Search every column
$in{$column} = $in{'keyword'}; # Fill %in with keyword we are looking for.
$i++;


but Apache tells me an internal Server error with the following error.log:

syntax error at /usr/local/httpd/htdocs/dbman/db.cgi line 325, near "$get_date("
syntax error at /usr/local/httpd/htdocs/dbman/db.cgi line 325, near "* 86400)"
syntax error at /usr/local/httpd/htdocs/dbman/db.cgi line 325, near "$get_date("
syntax error at /usr/local/httpd/htdocs/dbman/db.cgi line 531, near "}"
Execution of /usr/local/httpd/htdocs/dbman/db.cgi aborted due to compilation errors.

Call me stupid, but I don't see an error ... (no CR's - all ASCII)

Markus

Quote Reply
Re: Calling entries depending on current Date In reply to
I made a typo or two. Sorry.

It's a little hard to read your code with it being all on one line, but I think I figured it out.

All of the $get_dates should be &get_dates. That's what happens when I ponder. Smile

I've changed it in the original code in case someone comes along and is confused.

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







[This message has been edited by JPDeni (edited April 19, 1999).]
Quote Reply
Re: Calling entries depending on current Date In reply to
Hi!

The "today" feature works great, but the "future" feature displays not the coming events nor the current date

Markus
Quote Reply
Re: Calling entries depending on current Date In reply to
aaahhh ...

forgot to write:

the bugfix you've posted gets a server error too, so i've not implemented yet - maybe the reason for the prob in my last posting !?
When I use the "future" funktion, I get "no search terms found"

Markus
(thanks for spending so much time with my probs !!!!)
Quote Reply
Re: Calling entries depending on current Date In reply to
Can you copy the code that you added into a message here on the board so I can see it? I'm fumbling in the dark here, since I'm not sure what you've added and what you haven't.

Quote:
When I use the "future" funktion, I get "no search terms found"

That's because you haven't implemented the function.



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





Quote Reply
Re: Calling entries depending on current Date In reply to
Hello!

I use exact the mod from your mail (sub search routine). To your "dubble date" question: I'm using a second date-format to display dates in a format I need in Germany, because I need daynames. But the search should run on the "standard" dbman format - maybe you know some tricks (I am sure you do ;-) - in my version im must enter the date twice, one in my format, one in the format dbman needs ...

Thanks for your support

Markus

[This message has been edited by Markus Dollinger (edited April 24, 1999).]
Quote Reply
Re: Calling entries depending on current Date In reply to
Hi!

Any new ideas to my prob!? Got my Email with the scripts !?

Greetings
Markus
Quote Reply
Re: Calling entries depending on current Date In reply to
Yes, I did get your email. I've had a migraine all week and I have clients that I'm trying to work with.

I don't think I can help you unless I can look at the script in action. Sometimes I can figure out what the problem is by looking at the script, but it's a whole lot easier if I can see for myself what it's doing. Still, if I get a chance, I'll look more into what it's doing later today.


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





Quote Reply
Re: Calling entries depending on current Date In reply to
Hallo!

Hope you feeling better !? I've got a (raw) running version at: http://www.citygraphix.de/cgi-bin/dbman/db.cgi?db=cal
Login+pw=admin

Greetings
Markus
Quote Reply
Re: Calling entries depending on current Date In reply to
Thanks for putting it up where I can see it.

A couple of questions. Which date are you interested in looking at? You have the date twice on your add form and I'm not sure which one you're trying to find. There's the one which is divided into the "day number" and the month and the one that is, by default, the current date.

The "today" part of it works just fine, if you're using the field that has the full date in it. Have you implemented the "future" part of the code I gave you? If not, please do so I can test it out. Also, add the lines some debugging lines to html_view_failure --

still within the print qq| statement that says there was a problem with the search, add

$in{'Date-gt'}\n
$in{'Date-lt'}\n

That will let me know if the lines are doing what they're supposed to do.



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





Quote Reply
Re: Calling entries depending on current Date In reply to
Okay. Now I understand. I do really need the "debugging" lines to be added, though, so I can see what's going on internally.


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





Quote Reply
Re: Calling entries depending on current Date In reply to
Well, that told me a lot. I'm not quite sure what to do with the information, but I know more now. Smile

I think I know! Smile

Look for sub get_date in db.cgi. (I forgot that there were some changes that needed to be made there. Sorry.)

Right at the beginning of the subroutine, just after the comment lines, add

Code:
my ($time) = @_;
($time) &#0124; &#0124; ($time = time());

Make sure there isn't a space between the two | marks above. (The forum software will put one in.)

Then, on the line that starts with

my ($sec, $min, $hour, $day,

change

localtime(time())

to

localtime($time)

Now it should work.

I'm going to make a list of the things that need to be changed so I don't forget them again. Sorry.



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





Quote Reply
Re: Calling entries depending on current Date In reply to
Hi JPD!

Done! I've the debuggingline are in! In a future search they're only displaying the current date not a date range

Markus
Quote Reply
Re: Calling entries depending on current Date In reply to
Thank You so much! Works perfect!

... but ... one more (the last I swear!!) little question: how can I supress the header and footer for the "default" user. Default users should only see the database entries e.g. on a future=7 query. But they should don't get the option to search, view all, logout nor a header with the search results or the title of the database. In other words, they should only see the result of the query in the format i've defined in sub html_record, nothing less nothing more!

Bye and have a nice day
Markus
Quote Reply
Re: Calling entries depending on current Date In reply to
 
Quote:
one more (the last I swear!!) little question:

That's what they all say! You'll be back!! Wink

If you don't want the footer to show for default users, you can edit sub html_footer to prevent it. Presumably, default users only have permission to view and registered users have permission to search. If I'm right on that, here's the change you need to make:

At the end of the lines that include the links to "View" and "List All", you'll see

if ($per_view);

change that to

unless ($db_userid eq "default");

That should do it.

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