<?php
include "scrinit.php";
include $menu;
date_default_timezone_set("Europe/Athens");
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">

function addRow(tableID) 
		{

			var table = document.getElementById(tableID);
			var rowCount = table.rows.length;
			var row = table.insertRow(rowCount);
			var rc=rowCount-1;
			var colCount = table.rows[rowCount-1].cells.length;

			for(var i=0; i<colCount; i++) 
			{

				var newcell	= row.insertCell(i);

				newcell.innerHTML = table.rows[rc].cells[i].innerHTML;
				//alert(newcell.childNodes);
				switch(newcell.childNodes[0].type) 
				{
				
					case "text":
							newcell.childNodes[0].value = " ";
							break;
					case "checkbox":
							newcell.childNodes[0].checked = false;
							break;
					case "select-one":
							newcell.childNodes[0].selectedIndex = 0;
							break;
				}
			}
			
		}


function popupCenter(pageURL, title, w, h) 
{
    var left = (screen.width / 2)  - (w / 2);
    var top  = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=1000, height=700, top='+top+', left='+left);
}

</script>
<style type="text/css">
table.myTable { border-collapse:collapse; }
table.myTable td, table.myTable th { border:1px solid green;padding:5px;font-size:12pt; }
<p style="font-size:10px;"></p>
input:focus, textarea:focus, select:focus{
        outline: none;}
</style>

<?php
require "dbconnect.php";
$usr=$_SESSION['usr'];
$dt=$_SESSION['dt'];

$dn=$_GET['data'];
$ergo=$pers=$xoros=$jobdone=$techn=$datedone=array();
$q=mysqli_query($con,"select * from diataktiko where dnum='$dn'");
$row=mysqli_fetch_array($q);
if (!empty($row))
{
	//$k=mysqli_num_rows($q);
	$rn=$row['dreal'];
	$din=$row['datein'];
	$new=0;
	$q1=mysqli_query($con,"select * from diadetail where dnum='$dn'");
	$i=0;
	while($row1=mysqli_fetch_array($q1))
	{
		$i++;
		$item[i]=$row1['item'];
		$ergo[$i]=$row1['jobreq'];
		$pers[$i]=$row1['person'];
		$xoros[$i]=$row1['xoros'];
		$jobdone[$i]=$row1['jobdone'];
		$techn[$i]=$row1['techn'];
		$datedone[$i]=$row1['datedone'];
		
	}
	?><h3> ΕΝΗΜΕΡΩΣΗ ΔΙΑΤΑΚΤΙΚΟΥ</h3><?php
	$k=$i;
}
else
{
	$k=6;
	$din=$dt;
	$new=1;
	?><h3> ΕΚΔΟΣΗ ΔΙΑΤΑΚΤΙΚΟΥ</h3><?php
}

?>

<p>
<form method="post" action="diataktiko2.php">
<fieldset  style="width:1005px;background: #fffae6;border:2px solid black;-moz-border-radius:3px;
    -webkit-border-radius:3px;border-radius:3px;padding: 1em;font:90%/1 Tahoma;" >
<legend><b> ΑΡΙΘΜΟΣ ΔΙΑΤΑΚΤΙΚΟΥ: </b><input type='text' name='dn' value='<?php echo $dn;?>'  size='10'/> </legend>
<p><b>Αντιστοιχει με το χειρόγραφο:</b><input type='text' name='rn' value='<?php echo $rn;?>' size='10'/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp <b>Ημερομηνία αποστολής:</b><input type='date' name='din' value='<?php echo $din;?>'/></p>
</fieldset><br>
<?php 
if($new==1)
{
	?><INPUT type="button" value="Προσθήκη Γραμμής" onclick="addRow('dataTable')" /><?php
}
?>
<TABLE id="dataTable" style='width:1000px' class='myTable'>
<thead style='border:1px solid black' bgcolor='#fffae6' >
<tr>
<th>Αρ. Εργ.</th>
<th>Εργασία για Διεκπεραίωση</th>
<th>Αναφορά από</th>
<th>Αίθουσα/Χώρος</th>
<th>Κατάσταση</th>
<th>Ημερομηνία</th>
</thead>
<tbody >
<?php
$i=0;
while($i<$k)
{
		 $i++;
		 if (empty($ergo[$i]))
		 {
			 $st=' ';
		 }
		 elseif ($datedone[$i] > 0) {$st='ΟΛΟΚΛΗΡΩΘΗΚΕ';} else {$st="ΕΚΚΡΕΜΕΙ";}   
		 echo "<tr>";
		 
		 echo "<td>" . "<a href=\"diataktiko3.php?data=".$dn."\">"."<b>".$i."</b>". "</a>". "</td>";
		 ?><td><textarea rows="3" cols="80" name="ergo[]" > <?php echo $ergo[$i];?></textarea></td>
		 <td><input type="text" name='pn[]' value='<?php echo $pers[$i]; ?>' ></td><?php
		 echo "<td>"."<input type='text' name='xoros[]' value=$xoros[$i] >"."</td>";
		 echo "<td>".$st."</td>";
		 echo "<td>".$datedone[$i]."</td>";
		 echo "</tr>";
}
echo "<input type='hidden' name='new' value=$new >";
echo "</tbody>";
echo "</table>";
?>
<br><br>
<input type="Submit" name="diataktiko" value="ΚΑΤΑΧΩΡΗΣΗ ΔΙΑΤΑΚΤΙΚΟΥ" >
</form>

<br><br>
<a  href=<?php echo $menu;?> style="color:blue "  > <button> Επιστροφή στο Μενού   </a> 
&nbsp;&nbsp;&nbsp;&nbsp<a  href="diataktiko1.php?data=<?php echo $dn;?>" style="color:blue "  > <button>Επιτροφή στa Διατακτικά </button></a>
</body>
</html>