Time Clock Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sarbz
Forum Newbie
Posts: 6
Joined: Mon Jun 13, 2005 9:21 am

Time Clock Help

Post by sarbz »

Hello,

This is my first post here. So far, I've been learning php by using and editing pre-written scripts. I'm now looking for a time-clock script for employees to punch in and out with on my company's intranet.

I've searched everywhere, and can't find anything that will work. I've found several scripts for tracking project times, but nothing that offers a simple "punch-in" & "punch-out" solution.

If anyone can point me in the right direction, I'd appreciate it. I know enough to edit code, but not enough to write my own from scratch. My intranet is hosted on a pc with php 5, and mysql 4.1.

Thanks!
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post by Sphen001 »

Hi,

If you need what I think you do, you're looking to record the times a person logs on, and logs out. What you could do is set up a script that gets the current time, and store it in a database. Then do the same when the user logs out, and compare the two times, and determine the time in between.

The login script could be something like this

Code: Select all

<?php

// Get time logged on, as well as username, etc later

$time_in = microtime();
?>
Do the same for the logging out

Code: Select all

<?php

$time_out = microtime();

// Get the total time logged in

$total_time = $time_out - $time_in;

// $total_time is the amount of time spent logged in.  You'll have to change it in to a meaningful time using the date() function
?>
Hope this helps :D

Sphen001
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Here's some sample code that should do what you want

Code: Select all

$curr_time = time();
$user = $_POST['username'];

if(isset($_POST['punch_out']))
{
  $query = "INSERT INTO timeclock (time,username,punch_out) VALUES ('$curr_time','$user','1')";
}
else if(isset($_POST['punch_in']))
{
  $query = "INSERT INTO timeclock (time,username,punch_in) VALUES('$curr_time','$user','1')";
}

$result = mysql_query($query);
Of course there's some stuff to do like setup your connection, do some error checking, and output the form the user would submit, but that's the general idea of the logic.

Your table could look something like this:

Code: Select all

+-----------+---------+------+---------+
| Field     | Type    | Null | Default |
+-----------+---------+------+---------+
| time      | int     | No   |         |
| username  | varchar | No   |         |
| punch_in  | bool    | No   | 0       |
| punch_out | bool    | No   | 0       |
+-----------+---------+------+---------+
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
sarbz
Forum Newbie
Posts: 6
Joined: Mon Jun 13, 2005 9:21 am

Post by sarbz »

Just had a meeting with the "powers that be", and they want something more complex now:(

Here's what they want in a web-based time-clock system:

-punch in and out with pin number specific to an employee
-rounding of time to the 1/4 hour.(ie: 8:07=8:00, 8:08=8:15)
-seperate groups of employess (departments)
-supervisor's have access to only their department's employees' time data
-supervisor's can change in and out times after employees punch in or out
-some way to record an edit made by a supervisor
-ability for supervisors to mark days as vacations or sick days.

They also want to be able to view reports on all of this data.

I should probably post this in the job hunt section now, since I believe it's beyond my capabilities and I can't find anything that does what I want.

If anyone is interested, let me know. I'm sure this could be quite a profitable system. I know of several companies that would purchase something like this.
SabbeRubbish
Forum Newbie
Posts: 10
Joined: Fri May 20, 2005 7:15 am
Location: Belgium

Post by SabbeRubbish »

sarbz wrote:I should probably post this in the job hunt section now, since I believe it's beyond my capabilities and I can't find anything that does what I want.
If you need it soon, that's probably the best idea.
But if you have a few months left, why not start learning about some database design and build up your application bit by bit? (I mean one bit at a time, not literally bit by bit :wink:)
It'll be so much more rewarding for you that way :)
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Yeah, what ^ said. This really isn't that hard of a project at all. I'd do it, but I'm really busy with two other jobs. A project like this is just one that takes time.
sarbz
Forum Newbie
Posts: 6
Joined: Mon Jun 13, 2005 9:21 am

Post by sarbz »

Unfortunately, it has to be completed fairly soon :(

I'll have to keep looking for something that's been written already. If I can't find anything this week, they're going to sub the job out to a consulting firm (who will then sub it out to another firm, and then a sales rep, and then finally it will get to a programmer).

Thanks for all the input!
sarbz
Forum Newbie
Posts: 6
Joined: Mon Jun 13, 2005 9:21 am

Post by sarbz »

Anyone know what something like this would cost to have made?
Post Reply