thanks alot for qucik feedback if u modify this code i will be very grateful i wasted full 2days to sort out this problem but unable to find ...
PHP Code:
<?
include("../settings.php");
/* Connecting, selecting database */
$link = mysql_connect("$dbhost", "$dbuser", "$dbpw")
or die("Could not connect");
mysql_select_db("$dbuser") or die("Could not select database");
$query = "SELECT kunde,projektnr from emp_kunde";
$result = mysql_query($query) or die("Query failed: $query");
$kunden = array();
$projekt = array();
while ($row = mysql_fetch_assoc($result))
{
array_push($kunden, $row["kunde"]);
array_push($projekt, $row["projektnr"]);
}
$query = "SELECT hvorgang,uvorgang,status,soll from emp_details ";
$result = mysql_query($query) or die("Query failed: $query");
$getrow= mysql_fetch_array($result);
$hvorgang = array();
$uvorgang = array();
$status = array();
while ($row = mysql_fetch_assoc($result))
{
array_push($hvorgang, $row["hvorgang"]);
array_push($uvorgang, $row["uvorgang"]);
array_push($status, $row["status"]);
}
$kunden = array_unique($kunden);
$hprojekt = array_unique($projekt);
$haupt = array_unique($hvorgang);
$unter = array_unique($uvorgang);
$hstatus = array_unique($status);
if (isset($HTTP_POST_VARS["von"]))
{
$nr = $HTTP_POST_VARS["nr"];
$datum = $HTTP_POST_VARS["datum"];
$von = $HTTP_POST_VARS["von"];
$bis = $HTTP_POST_VARS["bis"];
$kunde = $HTTP_POST_VARS["kunde"];
$projekt = $HTTP_POST_VARS["projekt"];
$hVorgang = $HTTP_POST_VARS["hvorgang"];
$uVorgang = $HTTP_POST_VARS["uvorgang"];
$text = $HTTP_POST_VARS["text"];
$ist = $HTTP_POST_VARS["ist"];
$soll = $HTTP_POST_VARS["soll"];
$status = $HTTP_POST_VARS["status"];
$query = "INSERT INTO t_emp";
$query.="(nr,datum,von,bis,kunde,projekt,hvorgang,uvorgang,text,ist,soll,status) values ";
$query.="('$nr','$datum','$von','$bis','$kunde','$projekt','$hVorgang','$uVorgang','$text','$ist','$soll','$status')";
mysql_query($query) or die("Query failed: Insert new row");
$updatePK = "UPDATE key_generator set id = $nr where name = 't_emp'";
mysql_query($updatePK) or die("Query failed: Update field 'nr' (PK)");
}
/// this is the place to get soll value but problem is nr. filed always incremented by 2
$query = "SELECT * FROM t_emp order by nr DESC";
$result = mysql_query($query) or die("Query failed: Fetch all rows");
$query = "SELECT id from key_generator where name = 't_emp'";
$pkResult = mysql_query($query) or die("Query failed: Get last Id");
$row = mysql_fetch_assoc($pkResult);
$pk = $row[id];
$pk++;
function fillDD($min, $max, $selected) //selected format 12:30
{
$sel_bits = explode(":", $selected);
for($i=$min; $i<24; $i++) {
//$i = sprintf('%02d', $i); # set $i to be padded with a 0's up to 2 characters
for($j=$max; $j<60; $j+=5) {
$j = sprintf('%02d', $j); # set $j to be padded with a 0's up to 2 characters
if($i == $sel_bits[0] && $j == $sel_bits[1]) {
print("<option SELECTED value='$i:$j'>$i:$j</option>\n");
}
else {
print("<option value='$i:$j'>$i:$j</option>\n");
}
}//for($j)
} //for($i)
}
$arrDay = array ("So", "Mo", "Di", "Mi", "Do", "Fr","Sa");
$D=$arrDay[date(w)];
?>
[code]
<html>
<head>
<title>Log-Zeiterfassung</title>
<link rel="stylesheet" type="text/css" href="../styles/styles.css" />
<script language="JavaScript" src="date-picker.js"></script>
<SCRIPT LANGUAGE="JavaScript" src="log.js"></script>
<SCRIPT language="JavaScript">
function calculateIst()
{
var time =document.forms["tstest"].elements["von"].value.split(":");
vontime=parseInt(time[0]*60)+parseInt(time[1]);
var time1 =document.forms["tstest"].elements["bis"].value.split(":");
bistime=parseInt(time1[0]*60) +parseInt(time1[1])
diff=(bistime-vontime)
if(diff<0){
alert("assure that bis is greater than von")
return false
}
min=(diff%60)
hrs=(diff-min)/60
if (hrs<=9)
hrs="0"+hrs
if(min<=9)
min="0"+min
document.forms["tstest"].elements["ist"].value =hrs + ":" + min;
}
</script>
</head>
<form name="tstest" action="log.phtml" method="post">
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" class="mybar">
<table border="1" cellspacing="0" cellpadding="0" style="width:100%" name="rsTable" id="rsTable" cols="11">
<tr bgcolor="#cccccc">
<!--<th> </th> -->
<!--<th nowrap>Nr.</th>-->
<th width="70">Datum</th>
<th width="71">Von</th>
<th width="71">Bis</th>
<th width="54">Kunde</th>
<th width="71">Projekt</th>
<th width="94">H-Vorgang</th>
<th width="93">U-Vorgang</th>
<th width="150">Text</th>
<th width="40">IST</th>
<th width="40">Soll</th>
<th width="53">Status</th>
<th width="66"> </th>
</tr>
<? if (!isset($HTTP_POST_VARS["Save"])) { ?>
<tr>
<!--<td><a href="edit.phtml"><img src="../img/edit.gif" border="1"></a></td> -->
<input size="1" type="hidden" name="nr" value="<?= $pk ?>">
<td nowrap align="center">
<input size="7" type="text" name="datum" value="<?=$D?> <?= date("d.m.y") ?>">
<a href="javascript:show_calendar('tstest.datum');"><img src="../img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> </td>
<td nowrap align="center">
<select name="von">
<?if( isset($von) ){
fillDD(0, 0, $bis);
}else{
//Lets try & select the closest time to now.
$mins = date('i');
$mins -= ($mins % 5); //subtracts the remainder when divided by 5, from the original number
fillDD(0, 0, date('H') . ":" . $mins);
} ?>
</select>
<img src="../img/clock.gif" onclick="inputTime();calculateIst()" width="16" height="16" alt="Clock"></td>
<td nowrap align="center">
<!--<input type="text" size="1" class="button" name="clock">-->
<select name="bis" onchange="calculateIst()">
<option value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
</select>
<img src="../img/clock.gif" onclick="insertTime();calculateIst()" width="16" height="16" alt="Clock"></td>
<td nowrap align="center">
<select name="kunde" onchange="redirect(this.options.selectedIndex)">
<? foreach($kunden as $value) { ?>
<option value="<?= $value ?>" <? if ($HTTP_POST_VARS['kunde'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
<? } ?>
</select></td>
<td nowrap align="center">
<select name="projekt">
<? foreach($hprojekt as $value) { ?>
<option value="<?= $value ?>" <? if ($HTTP_POST_VARS['projekt'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
<? } ?>
</select></td>
<td nowrap align="center">
<select name="hvorgang" onchange="redirect1(this.options.selectedIndex)">
<? foreach($haupt as $value) { ?>
<option value="<?= $value ?>" <? if ($HTTP_POST_VARS['hvorgang'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
<? } ?>
</select> </td>
<td nowrap align="center">
<select name="uvorgang">
<? foreach($unter as $value) { ?>
<option value="<?= $value ?>" <? if ($HTTP_POST_VARS['uvorgang'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
<? } ?>
</select> </td>
<td nowrap align="center">
<textarea name="text" WRAP=SOFT class="mybar" id="tar" cols="20" rows="1" onfocus="tarea();" onblur="tarea();" title=""></textarea>
<img src="../img/edit.gif" onclick="window.open('thewindow.html','newWin','width=150,height=130,top=525,left=800,dependent=yes,alwaysRaised=yes,resizable=1')" width="16" height="16" border="0" alt="Edit Text"></td>
<td nowrap bgcolor="#cccccc" align="center"><input size="1" type="text" value="00:00" name="ist" readonly></td>
<td nowrap bgcolor="#cccccc" align="center"><input size="1" type="text" name="soll" value="<?= $getrow["soll"] ?>" readonly></td>
<td nowrap align="center">
<select name="status">
<? foreach($hstatus as $value) { ?>
<option selected value="<?= $value ?>"><?= $value ?></option>
<? } ?>
</select> </td>
<td nowrap align="center"><input type="button" value="Save" name="Save" border="1" onclick="go();"></td>
</tr>
<? } ?>
<? while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$output = wordwrap($line['text'], 20,"<br />", 1);
?>
<tr bgcolor="#FACB84">
<!--<td> </td>-->
<!-- <td><?= $line["nr"] ?></td> -->
<td align="center"><?= $line["datum"] ?></td>
<td align="center"><?= $line["von"] ?></td>
<td align="center"><?= $line["bis"] ?></td>
<td align="center"><?= $line["kunde"] ?></td>
<td align="center"><?= $line["projekt"] ?></td>
<td align="center"><?= $line["hvorgang"] ?></td>
<td align="center"><?= $line["uvorgang"] ?></td>
<td align="center"><?echo $output;?></td>
<td align="center"><?= $line["ist"] ?></td>
<td align="center"><?= $line["soll"] ?></td>
<td align="center"><?= $line["status"] ?></td>
</tr>
<? } ?>
</table>
</body>
<script language="javascript" src="triplecombo.js"></script>
</form>
<script language="JavaScript">
function go(){
var myindex=document.forms["tstest"].bis.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time from bis drop-down menu is selected.");
}
else {
document.tstest.submit(); }
}//submit go()
/*var times = new Array ();
function createArray() {
for (i=0; i<document.tstest.bis.length; i++) {
times[times.length] = new Option(document.tstest.bis[i].value, document.tstest.bis[i].value);
}
} */
var x = 0;
function insertTime() {
time = new Date();
hour = time.getHours();
minute = time.getMinutes();
hour = time.getHours().toString().length < 2 ? "0"+hour : hour;
minute = minute.toString().length < 2 ? "0"+minute : minute;
if (x==1) {
document.tstest.bis.options[document.tstest.bis.length-1] = null;
}
var anOption = new Option(hour+":"+minute, hour+":"+minute);
document.tstest.bis.options[document.tstest.bis.options.length] = anOption
x = 1;
document.tstest.bis.options.selectedIndex = document.tstest.bis.options.length-1;
}
var y = 0;
function inputTime() {
time = new Date();
hour = time.getHours();
minute = time.getMinutes();
hour = time.getHours().toString().length < 2 ? "0"+hour : hour;
minute = minute.toString().length < 2 ? "0"+minute : minute;
if (y==1) {
document.tstest.von.options[document.tstest.von.length-1] = null;
}
var anOption = new Option(hour+":"+minute, hour+":"+minute);
document.tstest.von.options[document.tstest.von.options.length] = anOption
y = 1;
document.tstest.von.options.selectedIndex = document.tstest.von.options.length-1;
}
function tarea()
{
if(document.getElementById)
{
if(document.getElementById("tar").rows == 3)
{
document.getElementById("tar").rows = 1
a = document.getElementById("tar").value
//a = a.substring(10)
if(a)
{
document.getElementById("tar").title = a
}
else
{
document.getElementById("tar").title = ''
}
}
else
{
document.getElementById("tar").rows = 3
document.getElementById("tar").title = ''
}
}
}
</script>
</html>
[/code]
<?
mysql_free_result($result);
mysql_close($link);
?>
|