Hey all, I've made an hour registration program for my dad using PHP.
It works great, but there is one little problem.
There's an intranet site that is run on the server that takes care of inserting coffeebreaks and such (if the time is 12:30, then the current "jobs" will be shut down for 30 mins. So if it's 13:00 all these jobs continue... just to give you an example:
09:00 - user logs in and starts work
12:30 - program on server sees that it is 12:30 and closes all the current jobs.
13:00 - program on server sees that it is 13:00 and restarts all the jobs.
16:30 - program on server sees that it is 16:30 and closes all jobs (since it's the end of the day).
The entries in the database are now:
09:00 -> 12:30 user working
13:00 -> 16:30 user working
Hope this is clear to you.
The problem is that my javascript page, that checks the time and goes to another page running the php script doesn't always go there.
The problem that happens is that the jobs won't be stopped, so instead of stopping at 12:30 and restarting at 13:00, it doesn't do anything.. it just keeps counting.
The real downside to this is that if the javascript doesn't go to the site with the shutdown php at 16:30, all jobs are stretched untill the other morning... But my program is not 24 hour compliant (big mistake on my side there...), so you can work NEGATIVE if the time isn't stopped (had it happen more than once... since there are already 500+ entries in the db, so you work from 10:00 to 08:00 resulting in -2 hours)
Ok, some more blah blah. This is the code that I use on the javascript page (that checks time and goes to another page):
/////////code//////////////
<script language="javascript" type="text/javascript">
function clock(){
now = new Date
document.time.clock.value = checkNum(now.getHours()).toString() + ":" + checkNum(now.getMinutes()).toString() + ":" + checkNum(now.getSeconds()).toString()
if (document.time.clock.value == "12:30:00")
{
location.href = "stoptijd.php?id=pauze";
}
if (document.time.clock.value == "12:30:01")
{
location.href = "stoptijd.php?id=pauze";
}
if (document.time.clock.value == "12:30:02")
{
location.href = "stoptijd.php?id=pauze";
}
if (document.time.clock.value == "13:00:00")
{
location.href = "stoptijd.php?id=pauzevoorbij";
}
if (document.time.clock.value == "13:00:01")
{
location.href = "stoptijd.php?id=pauzevoorbij";
}
if (document.time.clock.value == "13:00:02")
{
location.href = "stoptijd.php?id=pauzevoorbij";
}
if (document.time.clock.value == "16:30:00")
{
location.href = "stoptijd.php?id=werkklaar";
}
if (document.time.clock.value == "16:30:01")
{
location.href = "stoptijd.php?id=werkklaar";
}
if (document.time.clock.value == "16:30:02")
{
location.href = "stoptijd.php?id=werkklaar";
}
setTimeout("clock()",1000)
}
function checkNum(num){ if(num < 10) return "0" + num; else return num; }
</script>
<script language="JavaScript">
<!-- Start Hide
function goto_url(val) {
url = "" + val;
document.location.href = url;
}
// End Hide -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" background="background.gif" link="#FF0000" vlink="#FF0000" alink="#FF0000" leftmargin="1" topmargin="1" marginwidth="0" marginheight="0" onLoad="clock()">
Dit venster NOOIT afsluiten...<br>
Het is nu:<form name="time" action=stoptime.php>
<input type="text" name="clock">
</form>
//////////code////////////
as you can see, I already entered more checks, but it still doesn't work (it goes to the other page when it's 12:30:00, 12:30:01 etc and then on the other site there's a 5 second delay before it goes back to this site, so it won't go there twice)
But my question is (finally!): How can I make sure that the program is run every time and not just skips a few times... Could I add a header no cache or something (don't think that that will work though)..
Thanks for reading this ultra long message...
Menno