username:" . "$this->password@" . "$this->hostname/" . "$this->database"); } } // Connect to database $connect = new Writer(); $writer = DB::connect($connect->connect()); if (DB::iserror($writer)) { die("cannot connect as writer: " . $writer->getMessage()); } // Fetch config details for this user (currently a3ncrr!) $login = "a3ncrr"; $userQuery = "select * from clockuser where login = '" . $login . "';"; $userRes = $writer->query($userQuery); if (PEAR::isError($userRes)) { print("$userQuery"); die("Query error: " . $userRes->getMessage()); } if (($userRes->numRows()) != 1) { die(($userRes->numRows()) . ' records for login name (' . $login . ') in database.'); } $userRow = $userRes->fetchRow(DB_FETCHMODE_ASSOC); if (DB::isError($userRow)) { die('fetchRow: ' . $userRow->getMessage()); } $today = date('Y-m-d'); $now = date('H:i:s'); $periodQuery = "SELECT * from clockperiod" . " where start <= '" . $today . "' and end >= '" . $today . "' ;"; $periodRes = $writer->query($periodQuery); if (PEAR::isError($periodRes)) { print("$periodQuery"); die("Query error: " . $periodRes->getMessage()); } if ($periodRes->numRows() != 1) { die("Cannot find period start/end for " . $periodQuery); } $periodRow = $periodRes->fetchRow(DB_FETCHMODE_ASSOC); if (DB::isError($periodRow)) { die('fetchRow: ' . $periodRow->getMessage()); } $toDateQuery = "SELECT * from clockevent" . " where user = " . $userRow['id'] . " and date >= '" . $periodRow['start'] . "' and date <= '" . $periodRow['end'] . "' order by date,time asc;"; $toDateRes = $writer->query($toDateQuery); if (PEAR::isError($toDateRes)) { print("$toDateQuery"); die("Query error: " . $toDateRes->getMessage()); } $clockQuery = "SELECT * from clockevent" . " where user = " . $userRow['id'] . " and date = '" . $today . "' order by time desc;"; $clockRes = $writer->query($clockQuery); if (PEAR::isError($clockRes)) { print("$clockQuery"); die("Query error: " . $clockRes->getMessage()); } //echo "Got ". $clockRes->numRows() . " rows from " . $clockQuery; if ($clockRes->numRows() < 1) { $clocked = "out"; } else { $clockRow = $clockRes->fetchRow(DB_FETCHMODE_ASSOC); if (DB::isError($clockRow)) { die('fetchRow: ' . $clockRow->getMessage()); } $clocked = ($clockRow['event']==="start")?"in":"out"; } $newEvent = ($clocked === "in")? "out" : "in"; ?> Clock In/Out

School of Computing Science Timeclock

Clock In/Out
Period to date () fetchrow(DB_FETCHMODE_ASSOC)) { if ( $workingDate != $row['date'] ) { echo ""; echo "" ; echo "" ; echo $timeList ; echo ""; $workingDate = $row['date']; $inOut = "out"; $timeList = ""; $worked = 0; } if ($row['type'] === NULL) { if ($row['event'] === 'start') { if ($inOut == 'out') { $inOut = 'in'; $startTime = strtotime($row['time']); $timeList = $timeList . "\n"; } } if ($row['event'] === 'end') { if ($inOut == 'in') { $inOut = 'out'; $timeList = $timeList . "\n"; $worked += ( strtotime($row['time']) - $startTime ); } } } /* `id` int(10) unsigned NOT NULL auto_increment, `user` int(5) NOT NULL, `date` date NOT NULL, `time` time default NULL, `event` enum('start','end') NOT NULL, `type` enum('sick','holiday') default NULL, `descr` varchar(255) default NULL, */ } echo ""; echo "" ; echo "" ; echo $timeList ; echo ""; ?>
Date Hours In/Out times
" . $workingDate . "" . $worked . "
" . $row['time'] . "" . $row['time'] . "
" . $workingDate . "" . $worked . "
Administration Timeclock Administration