summaryrefslogtreecommitdiffstats
path: root/public/day.php
diff options
context:
space:
mode:
Diffstat (limited to 'public/day.php')
-rw-r--r--public/day.php121
1 files changed, 89 insertions, 32 deletions
diff --git a/public/day.php b/public/day.php
index 1c21f1b..9dd5377 100644
--- a/public/day.php
+++ b/public/day.php
@@ -5,14 +5,21 @@
require_once '../system/init.php';
- $sql = 'SELECT * FROM atwork WHERE user = ? AND start <= ? AND finish >= ?';
+ $tmp = explode('.', $_POST['d']);
+ $date = sprintf('%d-%02d-%02d', $tmp[2], $tmp[1], $tmp[0]);
+
+ // Find this day
+ $sql = "SELECT * FROM atwork WHERE user = ?
+ AND date(?) BETWEEN date(start) AND date(finish);";
$stmt = $db->prepare($sql);
- $stmt->execute(array($_SESSION['user'], $_POST['d'], $_POST['d']));
-// print_r($stmt->fetchAll());
+ $stmt->execute(array($_SESSION['user'], $date));
+ $day = $stmt->fetchAll();
+ $day = array_pad($day, 5, array());
?>
+
<form action="#" method="post" id="timeform">
- <input type="hidden" id="date" name="date" value="<?= $_POST['d']; ?>"/>
+ <input id="date" name="date" type="hidden" value="<?= $_POST['d']; ?>"/>
<table>
<thead>
<tr>
@@ -22,50 +29,83 @@
</thead>
<tbody>
-<?php foreach(range(0, 4) as $r): ?>
+<?php
+
+ foreach(range(0, 4) as $r):
+
+ $start = @date_parse($day[$r]['start']);
+ $finish = @date_parse($day[$r]['finish']);
+
+?>
-<tr>
- <td>
- <select name="start-h[<?= $r; ?>]" class="start_h">
- <option>--</option>
+ <tr>
+ <td>
+ <select name="start-h[<?= $r; ?>]" class="start_h">
+ <option>--</option>
-<?php foreach(range(8, 23) as $h): ?>
+<?php
+
+ foreach(range(8, 23) as $h):
+
+ $selected = ($h == $start['hour']) ? 'selected="selected"' : '';
+
+?>
- <option><?= sprintf('%02d', $h); ?></option>
+ <option <?= $selected; ?>><?= sprintf('%02d', $h); ?></option>
<?php endforeach ?>
- </select>
- :
- <select name="start-m[<?= $r; ?>]" class="start_m">
- <option>--</option>
+ </select>
+ :
+ <select name="start-m[<?= $r; ?>]" class="start_m">
+ <option>--</option>
-<?php foreach(range(0, 3) as $m): ?>
+<?php
+
+ foreach(range(0, 3) as $m):
+
+ $min = sprintf('%02d', $m*15);
+ $selected = ($min == $start['minute']) ? 'selected="selected"' : '';
+
+?>
- <option><?= sprintf('%02d', $m*15); ?></option>
+ <option <?= $selected; ?>><?= $min; ?></option>
<?php endforeach ?>
- </select>
- </td>
- <td>
- <select name="finish-h[<?= $r; ?>]" class="finish_h">
- <option>--</option>
+ </select>
+ </td>
+ <td>
+ <select name="finish-h[<?= $r; ?>]" class="finish_h">
+ <option>--</option>
-<?php foreach(range(8, 23) as $h): ?>
-
- <option><?= sprintf('%02d', $h); ?></option>
+<?php
+
+ foreach(range(8, 23) as $h):
+
+ $selected = ($h == $finish['hour']) ? 'selected="selected"' : '';
+
+?>
+ <option <?= $selected; ?>><?= sprintf('%02d', $h); ?></option>
+
<?php endforeach ?>
-
+
</select>
:
<select name="finish-m[<?= $r; ?>]" class="finish_m">
<option>--</option>
-<?php foreach(range(0, 3) as $m): ?>
+<?php
- <option><?= sprintf('%02d', $m*15); ?></option>
+ foreach(range(0, 3) as $m):
+
+ $min = sprintf('%02d', $m*15);
+ $selected = ($min == $finish['minute']) ? 'selected="selected"' : '';
+
+?>
+
+ <option <?= $selected; ?>><?= $min; ?></option>
<?php endforeach ?>
@@ -75,11 +115,28 @@
<?php endforeach ?>
<tr>
- <td colspan="2"><strong>Merkinnät</strong>
- <br/>
- <textarea name="notes" rows="8" cols="40"></textarea></td>
+ <td colspan="2">
+ <select style="width:368px" name="type" id="type">
+ <option>--</option>
+ <option value="1">Töissä</option>
+ <option value="2">Etätöissä</option>
+ <option value="3">Sairaana</option>
+ <option value="4">Ylityövapaalla</option>
+ <option value="5">Koulutuksessa</option>
+ <option value="6">Vuosilomalla</option>
+ <option value="7">Isyys/äitiyslomalla</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2">Merkinnät<br/>
+ <textarea name="notes" rows="2" cols="40"></textarea></td>
+ </tr>
+ <tr>
+ <td colspan="2">
+ <input type="checkbox" id="lunch" name="lunch" value="1"/> Lounastauko
+ </td>
</tr>
-
</tbody>
</table>
</form> \ No newline at end of file