Quote:
Originally Posted by stivens
Yes i am trying to do both, show the pop up and send the email. the job runs every 15 min. it is not a report, it is an alert to remind the user the pending task he has at the time the job runs. the user should be online all day. the problem here is there is no way to find out if the user is online running a cron job is it?
|
If you want to do both, just run the cron once a day (send one mail per day) and after the user gets the popup (if he does) you mark in his `users` table a flag "gotTheMaiToday" = date(Y-m-d) and every time you check if `gotTheMaiToday` is NOT today ( != date(Y-m-d) )
You also can know if the user is online in a cron job, but you will have a margin of error.
After he is loggedIn you can show the popup and you also mark a flag - a new column in the users table (let's say "LastAction" - datetime, default = 0) so at every user action (every page he will access) - you can have this in your config file or, some file that is everywhere - you update the `LastAction`. Something like this
PHP Code:
<?php # any action he takes, any page he visits # this can be in some common (config) file if( ISLOGGEDIN ) { executeQuery ( ' UPDATE `users` SET `LastAction`=NOW() WHERE userId="hisIDFromSession" ' ) }
In the cron, check if the user was online in the last (let's say) 15 minutes.
If he doesn't do anything for 15 minutes that means he's not active anymore.
So, you have
Code:
SELECT `userId` FROM `users`
WHERE CURRENT_DATE < DATE_ADD(LastAction, INTERVAL 15 MINUTE)
And you get a list (of IDs) with all users that are on-line.
Last edited by vectorialpx; 02-15-2012 at 05:22 AM..
Reason: add code
|