<?php
/**************************************************************************\
* phpgwtimetrack - phpGroupWare addon application *
* http://phpgwtimetrack.sourceforge.net *
* Written by Robert Schader <hide@address.com> *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id: index.php,v 1.5 2001/01/16 21:56:53 rschader Exp $ */
$phpgw_info["flags"]["enable_nextmatchs_class"] = "True";
$phpgw_info["flags"]["currentapp"] = "timetrack";
include("../header.inc.php");
if ($submit) {
//echo "Status is: " . $status;
//echo " UID is: " . $uid;
if ( $status == "IN") {
$phpgw->db->query("UPDATE employee_profiles SET inout=2 WHERE con=" . $uid);
} else {
$phpgw->db->query("UPDATE employee_profiles SET inout=1 WHERE con=" . $uid);
}
}
?>
<center><h3><?php echo "Employee In/Out Board"; ?></h3></center>
<? /* Here I have to do my first query, to check the user's checkin status */
/* First, we have to query the accounts table to get the users "con" value */
$phpgw->db->query("select account_id from accounts where account_lid='"
. $phpgw_info["user"]["userid"] . "'");
$phpgw->db->next_record();
$uid = $phpgw->db->f("account_id");
/* Now use the uid to reference the employee_stats.inout field */
$phpgw->db->query("select inout from employee_profiles"
. " where con= " . $uid);
$phpgw->db->next_record();
$status = $phpgw->db->f("inout");
// This part will display basically a form with only a submit
// button with the appropriate text to set in or out status.
// We will then have to add an if($submit) type statement at the
// top of this page, turning off headers, etc.
?>
<form method="POST" action="<?php echo $phpgw->link();?>">
<input type=hidden name=uid value="<?php echo $uid; ?>">
<input type=hidden name=status value="<?php echo $status; ?>">
<center><h4>
<?php echo $phpgw_info["user"]["firstname"] . ", you are currently checked " . $status
. ", Please "; ?>
<input type="submit" name="submit" value="<?php
if ($status == "IN") echo "Check Out";
else echo "Check In"; ?>">
<?php
if ($status == "IN") echo " when you leave work.";
else echo " while you are at work."; ?>
</center></h4>
</form>
<!-- Here we start the first attempt to do our in/out board. Trying to use a table structure
similar to the hr app's printout. Should we try to do this in a portable manner? -->
<?php
$main_locations=2; // All the rest of locations will eventually be treated as "Other"
//For now, to get everything just working, do a single table across the screen and just
// iterate thru the locations.
// For this to work right, the first thing I need to do is fill an array with the location names.
$phpgw->db->query("select * from locations");
while ($phpgw->db->next_record()) {
$loc_id = $phpgw->db->f("location_id");
$n_location[$loc_id] = $phpgw->db->f("location_name");
}
$total_locations = $loc_id; // tested, works
// echo "<center><p>Highest location number is " . $total_locations . "</center></p>";
$locations_per_row = 3; //should probably be in a config or preference file later.
// Inner table width percentages:
$itable_width = floor(100 / $locations_per_row);
$num_rows = ceil($total_locations / $locations_per_row); //need to handle case with odd numbers too.
// test case, see what we get:
// echo "<center><p>Num Rows is: " . $num_rows . "</center></p>";
?>
<table border="0" width="100%">
<?php
for ($row = 0; $row < $num_rows; $row++)
{
echo '<tr valign="top">';
for ($loc = 1; $loc <= $locations_per_row; $loc++)
{
$lid = $loc + ($row * $locations_per_row);
echo '<td width="' . $itable_width . '%">';
echo '<table border="0" valign="top" width="100%">';
echo '<tr><th colspan="3" bgcolor="' . $phpgw_info["theme"]["th_bg"] . '" align="center">'
. $n_location[$lid] . '</th></tr>';
// more td's for this location table go here
// sql query for selecting all users from one location, need to access both
// the accounts and profiles tables using a join, order by, and ?
$loc_sql = "select p.inout, a.account_lastname, a.account_firstname "
. "from employee_profiles as p, accounts as a "
. "where p.con = a.account_id and location_id = " . $lid
. " order by account_lastname, account_firstname";
// Now do a while loop on the resultset and print a row (name, inout) for each result
$phpgw->db->query($loc_sql);
while ($phpgw->db->next_record()) {
$tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);
echo '<tr>';
echo ' <td bgcolor="' . $tr_color . '">' . $phpgw->db->f("account_lastname") . ',</td>';
echo ' <td bgcolor="' . $tr_color . '">' . $phpgw->db->f("account_firstname") . '</td>';
echo ' <td bgcolor="' . $tr_color . '" align="right">' . $phpgw->db->f("inout") . '</td>';
}
// End it with end td and end table when done:
echo '</table></td>';
}
echo '</tr>';
}
echo '</table>';
?>
<?php
$phpgw->common->phpgw_footer();
?>