•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 427,805 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,849 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 8834 | Replies: 4
•
•
Join Date: Jan 2007
Posts: 12
Reputation:
Rep Power: 2
Solved Threads: 0
hello,
I am building a mysql/php/javascript based online timesheet system which allows users to assign themselves predefined projects and then select one of the projects assigned to them and add hours for a particular date to the database - i can get the add to work fine, but i need to be able to amend the hours once they have been entered (i.e. go back to the same form, read the existing hours in and then allow the user to edit them via the form then update the database record)
I have a javascript based calendar which changes the content of an anchor tag without refreshing the page i.e.
initially:-
<a id="tag">12/12/2007</a>
then click "change date" the calendar pops up, you can click a date and then it closes the calendar popup and updates the content of the <a> tag WITHOUT refreshing the page. The fact that it doesnt refresh the page is important and needs to stay this way.
I need to be able to read the content of the <a> tag when it changes and read it into a php variable (which in turn affects an SQL statement)
it would be nice to ba able update the $date variable (which is initially set using $_GET ['date']. onchange() of the <a> tag's content. but i dont think you can do this!
Here is the code for my page, im sure its pretty messy and does things in an over complicated way, but it works (so far)!:
I am building a mysql/php/javascript based online timesheet system which allows users to assign themselves predefined projects and then select one of the projects assigned to them and add hours for a particular date to the database - i can get the add to work fine, but i need to be able to amend the hours once they have been entered (i.e. go back to the same form, read the existing hours in and then allow the user to edit them via the form then update the database record)
I have a javascript based calendar which changes the content of an anchor tag without refreshing the page i.e.
initially:-
<a id="tag">12/12/2007</a>
then click "change date" the calendar pops up, you can click a date and then it closes the calendar popup and updates the content of the <a> tag WITHOUT refreshing the page. The fact that it doesnt refresh the page is important and needs to stay this way.
I need to be able to read the content of the <a> tag when it changes and read it into a php variable (which in turn affects an SQL statement)
it would be nice to ba able update the $date variable (which is initially set using $_GET ['date']. onchange() of the <a> tag's content. but i dont think you can do this!
Here is the code for my page, im sure its pretty messy and does things in an over complicated way, but it works (so far)!:
<?php
ob_start();
session_start();
$connect = mysql_connect('localhost', 'root', '');
if(!$connect){
die("sql connection error");
}
$username = $_SESSION['username'];
mysql_select_db('timesheet');
$sqlUser = "select * from user where Username='".$_SESSION['username']."';";
$queryUser = mysql_query($sqlUser);
?>
<html>
<head>
<title>Impetus online project timesheet</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script>
function readDate(elem){
var ele = document.getElementById(elem);
var childNodes = ele.childNodes[0];
var element = childNodes.nodeValue
document.hours.date.value=element;
}
function getDate(){
var todaysDate;
var currentTime = new Date();
var day = currentTime.getDate();
var month = currentTime.getMonth()+1;
var year = currentTime.getFullYear();
todaysDate= window.location ="addHours.php?date="+day+"/"+month+"/"+year;
return todaysDate;
}
</script>
</head>
<body>
<script type='text/JavaScript' src='scw.js'></script>
<!-- start of container table -->
<table class="tablestyle" width="800px" align="center" border="1">
<tr>
<td align="center" class="cellstyle"><img src="img/impetuslogo.png"></td>
</tr>
<tr><td class="cellstyle">
<!-- start of content table -->
<table align="center" width="100%" border="0">
<tr>
<td align="center" colspan="2"><h1>Welcome to the Impetus Online Timesheet</h1></td>
</tr>
<tr>
<td rowspan="5" width="20%" class="tablestyle1" valign="top">
<!-- start of nav table -->
<table width="100%">
<?php if(isset($_SESSION['username'])){?>
<tr>
<td class="cellstyle1" align="center">
<?php
echo 'Hello '.$username;
?>
</td>
</tr>
<tr>
<td align="center" class="cellstyle1">
<a href="yourProjects.php">Your Projects</a>
</td>
</tr>
<tr>
<td align="center" class="cellstyle1">
<a href="#">Your Hours</a>
</td>
</tr>
<tr>
<td align="center" class="cellstyle1">
<a onclick="return getDate();" href="#">Add Hours</a>
</td>
</tr>
<tr>
<td align="center" class="cellstyle1">
<a href="#">Create a Report</a>
</td>
</tr>
<tr>
<td align="center" class="cellstyle1">
<a href="addProject.php">Add a new Project</a>
</td>
</tr>
</table>
<!-- end of nav table -->
</td>
<td class="tablestyle1">
<!-- start of inner content table -->
<table width="100%" border="0">
<tr>
<td colspan="4">
<p>Select the project you wish to add hours for - Please note you can change the projects you are enrolled on in <b>"Your Projects"</b>.</p>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td width="10%">
<p><b>Project:</b></p>
</td>
<form name="projName" action="addHours.php" method="get">
<input type="hidden" id="hiddendate" name="hiddendate">
<?php
$projectName= Array();
$counter=0;
$date=$_GET['date'];
while($row = mysql_fetch_array($queryUser)) {
for($i=0;$i<15;$i++){
$projectName[$i] = $row['Project'.($i+1)];
if($projectName[$i]!=="" && isset($projectName[$i])){
if($counter>=3){
echo'
</tr><tr><td></td>
<td>
<a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
</td>
';
$counter=0;
}
else if($counter<3){
echo'
<td>
<a href="addHours.php?projectName='.$projectName[$i].'&date='.$date.'">'.$projectName[$i].'</a>
</td>
';
$counter++;
}
}
//else{echo'empty';}
}
}
$explodedGet = explode("%20", $_GET['projectName']);
for($t=0;$t<count($explodedGet);$t++){
$trim= $trim.$explodedGet[$t]." ";
}
$pName= rtrim($trim);
if(isset($pName) && $pName!==""){
?>
</tr>
<tr>
<td colspan="2" align="center">
<p>Add your hours for <a id='aTest'><?php echo $date; ?></a></p>
</td>
<td colspan="2" align="center">
<a href='javascript:scwShow(scwID("aTest"),scwID("aTest"));' :mrgreen:***THIS IS WHRE THE CALENDAR IS CALLED ***:mrgreen: onclick=>Click here to change the date</a>
</td>
</tr>
<tr>
<td colspan="4">
<table width="100%">
<tr>
<td colspan="2" height="30px">
Currently Select Project: <b><?php echo $pName; ?></b>
</td>
</tr>
<tr>
<td width="30%">
<p>Type of work</p>
</td>
<td width="30%">
<p>Hours</p>
</td>
<td width="40%">
<p>Notes</p>
</td>
</tr>
</form>
<form name="hours" method="get" action="addHoursDB.php">
<input type="hidden" name="date" value="bolocks">
<?php
:mrgreen:***this function checks to see if a record already exists for the username, date and project that are currently selected ***:mrgreen:
function exists(){
$sqlexists = "select Date from day where Username='".$_SESSION['username']."';";
if($existsQuery = mysql_query($sqlexists) or die("there was an error")){
//echo'inside if statement';
while($check = mysql_fetch_array($existsQuery)){
$datecheck = $check['Date'];
//echo'inside while loop';
if($date == $datecheck){
$exists = true;
//echo'the record already exists';
break;
}
else if($date !==$datecheck){
$exists = false;
}
}
}
return exists;
}
if(exists()==false){
echo'<tr><td colspan="4">You have not added any hours for this project on this date yet, so you have been taken into the "normal mode"</td></tr>';
$sqlProject = "select * from project where ProjectName like '%".$pName."%';";
$queryProject = mysql_query($sqlProject) or die(mysql_error());
$workType= Array();
while($proj = mysql_fetch_array($queryProject)){
//echo'here';
for($r=0;$r<10;$r++){
//echo "WorkType: ".$proj['WorkType1'];
$workType[$r] = $proj['WorkType'.($r+1)];
if(isset($workType[$r]) && $workType[$r]!==""){
echo'
<tr>
<td>
<p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
</td>
<td>
<p>Hrs: <select name="hoursHours'.($r+1).'"><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option></select> Mins: <select name="hoursMins'.($r+1).'"><option>0</option><option>15</option><option>30</option><option>45</option></select></p>
</td>
<td>
<p><textarea rows="4" cols="30" name="notes'.($r+1).'"></textarea></p>
</td>
</tr>
';
}
else{break;}
}
}
}
else if(exists()==true){
echo'<tr><td colspan="4">You have already added hours for this project on this date, so you have been taken into the "amend mode"</td></tr>';
$_SESSION['dayexists']='true';
$sqlProject = "select * from day where Date='".$Date."' AND ProjectName like '%".$pName."%' AND Username='".$_SESSION['username']."';";
$queryProject = mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
mysql_query($sqlProject) or die("EXISTS ERROR ".mysql_error());
$workType= Array();
while($proj = mysql_fetch_array($queryProject)){
echo'here';
for($r=0;$r<10;$r++){
//echo "WorkType: ".$proj['WorkType1'];
$workType[$r] = $proj['WorkType'.($r+1)];
if(isset($workType[$r]) && $workType[$r]!==""){
echo'
<tr>
<td>
<p>'.$workType[$r].'</p><input type="hidden" name="WorkType'.($r+1).'" value="'.$workType[$r].'">
</td>

