PHP Code:
<?php require_once('Connections/timedb.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE timemanagement SET clientname=%s, hoursworked=%s, hoursleft=%s, hoursallocated=%s, username=%s, password=%s WHERE clientid=%s",
GetSQLValueString($_POST['clientname'], "text"),
GetSQLValueString($_POST['hoursworked'], "double"),
GetSQLValueString($_POST['hoursleft'], "double"),
//GetSQLValueString($hoursleft,"double"),
GetSQLValueString($_POST['hoursallocated'], "double"),
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['clientid'], "int"));
mysql_select_db($database_timedb, $timedb);
$Result1 = mysql_query($updateSQL, $timedb) or die(mysql_error());
}
$maxRows_Recordset1 = 1;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_timedb, $timedb);
$query_Recordset1 = "SELECT * FROM timemanagement";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $timedb) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<?php
$first_number = $row_Recordset1['hoursallocated'];
$second_number = $row_Recordset1['hoursworked'];
$sum_total = $first_number - $second_number;
$timepart = explode(".", $sum_total);
$hoursleft = $timepart[0];
$minutesleft = (intval($timepart[1]) / 10) * 60;
$addtoworked = ($_POST['hours'] + $_POST['mins']/60);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<SCRIPT LANGUAGE="JavaScript" src="dectohours.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style4 {font-size: 10}
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; }
-->
</style>
</head>
<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table width="50%" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td width="50%"><span class="style5">Client Name </span></td>
<td width="50%"><select name="select">
<?php do { ?>
<option value="<?php echo $row_Recordset1['clientname']?>"> <?php echo $row_Recordset1['clientname']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows < 10) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" class="style5">Amount of Time Worked </td>
<td width="33%" class="style5"><input name="hoursworked" type="text" id="hoursworked" /></td>
<td width="33%" class="style5">e.g. 1hr 45mins = 1.75 </td>
</tr>
</table></td>
</tr>
<tr>
<td height="20" colspan="2"><span class="style5">This customer currently has <?php echo $hoursleft; ?> hours and <?php echo $minutesleft; ?> minutes left this month on their support contract. If they visit their customer control panel they will be aware of this. </span></td>
</tr>
<tr>
<td height="20" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" class="style5">Allocated Hours per Month </td>
<td width="33%" class="style5"><input name="hoursallocated" type="text" id="hoursallocated" value="<?php echo $row_Recordset1['hoursallocated']; ?>" /></td>
<td width="33%" class="style5">Change contract hours here </td>
</tr>
</table></td>
</tr>
<tr>
<td height="20" colspan="2"><div align="center"><span class="style4"></span><span class="style4">
<input name="submit" type="submit" value="Update record" />
</span></div></td>
</tr>
</table>
<p>
<label></label>
<label></label>
<label></label>
</p>
<p>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="clientid" value="<?php echo $row_Recordset1['clientid']; ?>">
</p>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
The current code gets customer details from the database and gives the decimal hours data in hours and minutes. I require however, that the IT technician can enter new hours into two text fields (hours and minutes) rather than the current one and that this data automatically subtracts the data from the database and adds the data to the 'hours worked'.
Bookmarks