time Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zuzupus
Forum Commoner
Posts: 70
Joined: Thu Jul 17, 2003 4:54 am

time Problem

Post by zuzupus »

hi,
i used 2 time fields name von and bis when i submit the form i get time like this according to system time let say
Datum Von Bis Save --on click submit in same form
Th 17.07.03 10:59 10:59---new time i get once form submits
Th 17.07.03 10:59 23:40

if you see the above result its wrong for Von time fiels as it shows .is it possible to get Bis time in Von field when form submits and get new field
<td >
<input size="7" type="text" name="datum" value="<?=$D?> <?= date("d.m.y") ?>">
</td>
<td>
<select name="von">
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>// due to this echo function i get system time is it possible to get selected time from bis in new field of von
<? fillDD(0, 0, -1); ?>
</select>
</td>
<td>
<select name="bis" onchange="calculateIst()">
<option value="<?=date('H:i')?>"><? echo (date('H:i'));> </option>
<? fillDD(0, 0, -1); ?>
</select>
</td>
<td>
<input type="submit" value="S" name="Save" border="1" >
</td>
</tr>
still any problem to understood http://server2.vitodesign.com/scripts/diff.phtml

or any other way of script will welcome

if anybody sort out this problem will be appreciable

thanks
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

Here: http://www.pscript.de/forum/showboard.php?id=11 is a nice german php board, might be interesting for you ...


concerning your question, i don't really understand what you want ...

either explain it a bit better or post it in the other forum with all of your code (please use code tags), then I'll see you there ... ;o)
zuzupus
Forum Commoner
Posts: 70
Joined: Thu Jul 17, 2003 4:54 am

Post by zuzupus »

how i can get time which i selected from bis field on von field on the very next time when i clcik on save button

for eg

Von Bis
12:20 23:40 u can see from the url which i already posted
if u clearly notice this link u will see the new line VOn showing time 13:03
instead of 23:40 as i used echo (date('H:i')) thats why im getting always system time

thats why i asked any modification in php so that i can ge something like

13:25 15
23:40 13:25
12:20 23:40


hope this is clear for u[/url]
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

okay i think i got it, you need to print <option selected ... after the form is submittet where $_POST['bis_datum']==$(the value "fillDD(0, 0, -1);" prints)

so this comparison must take place in the function fillDD(). If $_POST['bis_datum'] is not set (first call of the script), then print this line before calling the function: <option value="<?=date('H:i')?>"><? echo (date('H:i'));> </option>
zuzupus
Forum Commoner
Posts: 70
Joined: Thu Jul 17, 2003 4:54 am

Post by zuzupus »

could you please modify this script as im totally newbie in PHP if possible just send me modify lines of code

thanks for ur understanding
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

i can only do this if you post the whole code
zuzupus
Forum Commoner
Posts: 70
Joined: Thu Jul 17, 2003 4:54 am

Post by zuzupus »

Code: Select all

<?
         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))
         &#123;
          array_push($kunden, $row&#1111;"kunde"]);
          array_push($projekt, $row&#1111;"projektnr"]);
         &#125;
         $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))
         &#123;
          array_push($hvorgang, $row&#1111;"hvorgang"]);
          array_push($uvorgang, $row&#1111;"uvorgang"]);
          array_push($status, $row&#1111;"status"]);
         &#125;
         $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&#1111;"datum"]))
        &#123;
  	        $nr = $HTTP_POST_VARS&#1111;"nr"];
	        $datum = $HTTP_POST_VARS&#1111;"datum"];
	        $von = $HTTP_POST_VARS&#1111;"von"];
	        $bis = $HTTP_POST_VARS&#1111;"bis"];
	        $kunde = $HTTP_POST_VARS&#1111;"kunde"];
	        $projekt = $HTTP_POST_VARS&#1111;"projekt"];
	        $hVorgang = $HTTP_POST_VARS&#1111;"hvorgang"];
	        $uVorgang = $HTTP_POST_VARS&#1111;"uvorgang"];
	        $text = $HTTP_POST_VARS&#1111;"text"];
	        $ist = $HTTP_POST_VARS&#1111;"ist"];
	        $soll = $HTTP_POST_VARS&#1111;"soll"];
                 $status = $HTTP_POST_VARS&#1111;"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)");

        &#125;
                /// 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&#1111;id];
	        $pk++;

                 function fillDD($min, $max, $selected)
                 &#123;
    			for($i=$min; $i<24; $i++) &#123;
       			//$i = sprintf('%02d', $i); # set $i to be padded with a 0's  up to 2 characters
       			for($j=$max; $j<60; $j+=5) &#123;
                 	$j = sprintf('%02d', $j); # set $j to be padded with a 0's up to 2 characters
                 	if($i == $selected && $j == $selected) &#123;
                 	         print("<option SELECTED value='$i:$j'>$i:$j</option>\n");
                 	&#125;
                		else &#123;
	                   print("<option value='$i:$j'>$i:$j</option>\n");
	                 &#125;
                         &#125;//for($j)
                         &#125; //for($i)
               &#125;

                $arrDay = array ("So", "Mo", "Di", "Mi", "Do", "Fr","Sa");
                $D=$arrDay&#1111;date(w)];

?>


<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()
                    &#123;
                             var time =document.forms&#1111;"tstest"].elements&#1111;"von"].value.split(":");
                                 vontime=parseInt(time&#1111;0]*60)+parseInt(time&#1111;1]);
	                    var time1 =document.forms&#1111;"tstest"].elements&#1111;"bis"].value.split(":");
                                 bistime=parseInt(time1&#1111;0]*60) +parseInt(time1&#1111;1])
                	  		diff=(bistime-vontime)
                                 if(diff<0)&#123;
                	     		alert("assure that bis is greater than von")
	                        return false
	                        &#125;
	                        min=(diff%60)
	                        hrs=(diff-min)/60
	                        if (hrs<=9)
	                        hrs="0"+hrs
	                        if(min<=9)
	                        min="0"+min
	   		     document.forms&#1111;"tstest"].elements&#1111;"ist"].value =hrs + ":" + min;
                    &#125;

               </script>


	</head>

  <form name="tstest" action="log.phtml" method="post">
      <body leftmargin="0" topmargin="0"  marginwidth="0" marginheight="0" class="mybar" onload="createArray()">
      <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1 width=100% name="rsTable" id=rsTable cols=12>
             <tr bgcolor="#cccccc">
                         <!--<th>&nbsp;</th> -->
                         <!--<th nowrap>Nr.</th>-->
                         <th nowrap>Datum</th>
                         <th nowrap>Von</th>
                         <th nowrap>Bis</th>
                         <th nowrap>Kunde</th>
                         <th nowrap>Projekt</th>
			<th nowrap>H-Vorgang</th>
			<th nowrap>U-Vorgang</th>
			<th nowrap>Text</th>
			<th nowrap>IST</th>
			<th nowrap>Soll</th>
                         <th nowrap>Status</th>
                         <th nowrap>&nbsp;</th>
	     </tr>
                    <? if (!isset($HTTP_POST_VARS&#1111;"Save"])) &#123; ?>
		<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">
                                     <option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
				    <? fillDD(0, 0, -1); ?>
                            </select>
                         </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>
                            <input type="button"  name="now" size="1" value=">" onclick="insertTime();calculateIst()">
                         </td>
			<td nowrap align="center">
                             <select name="kunde" onchange="redirect(this.options.selectedIndex)">
                                 <? foreach($kunden as  $value) &#123; ?>
                                 <option  value="<?= $value ?>"><?= $value ?></option>
                                 <? &#125; ?>
                             </select>
                         </td>
			<td nowrap align="center">
                             <select name="projekt">
                                 <? foreach($hprojekt as  $value) &#123; ?>
                                 <option  value="<?= $value ?>"><?= $value ?></option>
                                 <? &#125; ?>
                             </select>
                         </td>
                         <td nowrap align="center">
                             <select name="hvorgang" onchange="redirect1(this.options.selectedIndex)">
                                 <? foreach($haupt as  $value) &#123; ?>
                                 <option value="<?= $value ?>"><?= $value ?></option>
                                 <? &#125; ?>
                             </select>
                         </td>
			<td nowrap align="center">
                             <select name="uvorgang">
                                 <? foreach($unter as  $value) &#123; ?>
                                 <option value="<?= $value ?>"><?= $value ?></option>
                                 <? &#125; ?>
	                    </select>
                         </td>
			<td nowrap align="center">
                             <textarea name="text" class="mybar" id="tar" cols="15" rows="1" onfocus="tarea();" onblur="tarea();" title=""></textarea>
                              <input type="hidden" size="1" name="remLen"  value="20">
                             <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"></a>
                         </td>
			<td bgcolor="#cccccc" align="center"><input size="1" type="text" value="00:00" name="ist" readonly></td>
			<td bgcolor="#cccccc" align="center"><input size="1" type="text" name="soll" value="<?= $getrow&#1111;"soll"] ?>" readonly></td>
                         <td nowrap align="center">
                             <select name="status">
                                  <? foreach($hstatus as  $value) &#123; ?>
                                 <option selected value="<?= $value ?>"><?= $value ?></option>
                                 <? &#125; ?>
	                    </select>
                         </td>
                         <td nowrap align="center">
			<input type="button"  value="S" name="Save" border="1" onclick="go();">
			</td>
		  </tr>

	           <? &#125; ?>

                    <? while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) &#123; ?>
                    <!--<? $date = explode(' ', $line&#1111;"datum"]); ?>-->

		   <tr bgcolor="#FACB84">
			<!--<td>&nbsp;</td>-->
                        <!-- <td><?= $line&#1111;"nr"] ?></td> -->
			<td nowrap align="center"><?= $line&#1111;"datum"] ?></td>
			<td nowrap align="center"><?= $line&#1111;"von"] ?></td>
                         <td nowrap align="center"><?= $line&#1111;"bis"] ?></td>
                         <td nowrap align="center"><?= $line&#1111;"kunde"] ?></td>
			<td nowrap align="center"><?= $line&#1111;"projekt"] ?></td>
			<td nowrap align="center"><?= $line&#1111;"hvorgang"] ?></td>
			<td nowrap align="center"><?= $line&#1111;"uvorgang"] ?></td>
			<td nowrap align="center"><?= $line&#1111;"text"] ?></td>
			<td nowrap align="center"><?= $line&#1111;"ist"] ?></td>
			<td nowrap align="center"><?= $line&#1111;"soll"] ?></td>
                         <td nowrap align="center"><?= $line&#1111;"status"] ?></td>
		  </tr>
	<? &#125; ?>
           </table>
           <!--<table border=0 cellpadding=2 cellspacing=0>
           <tr><td align=center valign=bottom colspan=2>
           <!--<input type="button" class="button" value="Close" name="Close" border="1" onClick="window.close();"> -->
           <!--<input type="reset" class="button" value="Reset" name="Reset" border="1" onclick="tstest.reset();return false;"> -->
           <!--<input type="button" class="button" value="Print" name="Print" border="1" onClick="window.print();"></td></tr>
           </table> -->

	</body>
         <script language="javascript" src="triplecombo.js"></script>

        </form>

           <script language="JavaScript">
            function go()&#123;
            var myindex=document.forms&#1111;"tstest"].bis.selectedIndex;
	   if (myindex==0) &#123;
	   alert("\nPlease be sure that time from bis drop-down menu is selected.");
            &#125;
            else &#123;
            document.tstest.submit(); &#125;
            &#125;//submit go()
            var times = new Array ();
	   function createArray() &#123;
	     for (i=0; i<document.tstest.bis.length; i++) &#123;
	   		times&#1111;times.length] = new Option(document.tstest.bis&#1111;i].value, document.tstest.bis&#1111;i].value);
	     &#125;
	    &#125;
             var x = 0;
             function insertTime() &#123;
			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) &#123;
			document.tstest.bis.options&#1111;document.tstest.bis.length-1] = null;
		        &#125;
                         var anOption = new Option(hour+":"+minute, hour+":"+minute);
			document.tstest.bis.options&#1111;document.tstest.bis.options.length] = anOption
			x = 1;
			document.tstest.bis.options.selectedIndex = document.tstest.bis.options.length-1;

		&#125;

             function tarea()
	    &#123;
         	if(document.getElementById)
	         &#123;
	                 if(document.getElementById("tar").rows == 5)
	                 &#123;
	                         document.getElementById("tar").rows = 1
	                         a = document.getElementById("tar").value
	                         //a = a.substring(10)

	                         if(a)
	                         &#123;
	                                 document.getElementById("tar").title =  a
	                         &#125;
	                         else
	                         &#123;
	                                 document.getElementById("tar").title = ''
	                         &#125;
	                 &#125;
	                 else
	                 &#123;
	                         document.getElementById("tar").rows = 5
	                         document.getElementById("tar").title = ''
	                 &#125;
	         &#125;
	    &#125;


           </script>

</html>

<?
    mysql_free_result($result);
    mysql_close($link);
?>
?>
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

okay, when calling the function to fill up the from-elements, just type this:
if ($_POST['bis_datum']!="") {
fillDD(0, 0, $_POST['bis-datum']);
} else {
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>// due to this echo function i get system time is it possible to get selected time from bis in new field of von
<? fillDD(0, 0, -1); ?>
}
zuzupus
Forum Commoner
Posts: 70
Joined: Thu Jul 17, 2003 4:54 am

Post by zuzupus »

sorry its still not working----but below code works :)

<td nowrap align="center">
<select name="von">
<? fillDD(0, 0, $bis); ?>
</select>
</td>

function fillDD($min, $max, $selected)
{
$sel_bits = explode(":", $selected);
for($i=$min; $i<24; $i++) {
for($j=$max; $j<60; $j+=5) {
$j = sprintf('%02d', $j);
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)
}
when i use this piece of code then it works fine let say when select time from Von field Bis
12:55 23:55
10:05 12:55
it works fine but when i login every time instead of getting Von time as 23:55 i get 0:00 :(
but if wont login or refresh then it works smoothely

hope u will figure it out what the falw in this code and where shall i have to put----


thanks in advance
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

zuzupus wrote:<td nowrap align="center">
<select name="von">
<? fillDD(0, 0, $bis); ?>
</select>
</td>
only do this if $bis is set!

if (isset($bis)) {
<? fillDD(0, 0, $bis); ?>
} else {
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
}
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

nachtrag:

this code won't work either since it's pseudo copy paste code, you gotta put it right yourself ...
zuzupus
Forum Commoner
Posts: 70
Joined: Thu Jul 17, 2003 4:54 am

Post by zuzupus »

<td nowrap align="center">
<select name="von">
<?if( isset($bis) ){
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>
</td>

above code works fine but when i close the browser and login as second time i get von time as system time instead of 11:00 in bis field

hope it will be clear for u the result in form show like this when i login second time in same date,for more clear


sys time 10:45 instead of systime it must be 11:00 //login second time or 10:55 11:00 refresh
10:30 10:55

thanks for understanding
Post Reply