tags:

views:

55

answers:

3

in my system i need to get the annual report. how can i get the annual report only once a year. i have a button that generates the report but it should only be once a year. so it shouldn't be a button because that means the report can be gotten more than once a year. any suggestions? i'm using php by the way.

+2  A: 

You might consider creating a table in your database which would flag whether or not they have already viewed the annual report for a given year:

CREATE TABLE annual_report_views (
  id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  viewed DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
);

You would want to insert the date time in the format YYYY-MM-DD HH:II:SS into this table after the user has clicked the button for the first time.

You could then query this table every time the user is on the page containing the annual report button using a variable like so to compare dates:

$date = date('Y-m-d H:i:s', strtotime('-1 year'));

If a date in the table is greater than the date returned from this variable, don't show the button because it's within the last year.

cballou
that's a good idea but what if the button is pressed today (2009) then in january (2010) since it's a new year the button will be displayed again even though it has not been a year yet.
noob
+1  A: 

that's a good idea but what if the button is pressed today (2009) then in january (2010) since it's a new year the button will be displayed again even though it has not been a year yet

Well, the "year" field stores the year the report is about, not the year the button (or whatever) is pressed... So you can tell if the report for e.g. 2009 has already been viewed...

Augenfeind
+1  A: 

I think there's a usability aspect here which needs consideration. You should be able to get the report any time, but you should only be able to get the report for a particular year. The system should be able to determine (based on the date) which is the currently yearly report (and if there's a complete report available, or not).

e.g. otherwise what happens if you hit the button, get your report, and then accidentally bin it ? You're not going to be able to get that report again, are you ?

Brian Agnew
I agree with you on this one, although his line "i have a button that generates the report" could also imply the report is being saved to disk.
cballou