summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--computer-time-limit.php42
1 files changed, 22 insertions, 20 deletions
diff --git a/computer-time-limit.php b/computer-time-limit.php
index 0e20559..c97db5e 100644
--- a/computer-time-limit.php
+++ b/computer-time-limit.php
@@ -39,16 +39,16 @@ if (array_key_exists('msg', $_POST) && array_key_exists('sig', $_POST)) {
print($key . ' is not known.');
die();
}
- $aktiv = $row['aktiv'];
+ $host = $row['host'];
$bis = strtotime($row['bis']);
$von = strtotime($row['von']);
- log_to_file('from_db ' . $key . ' ' . $_POST['msg'] . ' ' . $aktiv . ' ' . $von . ' ' . $bis);
+ log_to_file('from_db ' . $key . ' ' . $_POST['msg'] . ' ' . $host . ' ' . $von . ' ' . $bis);
if ($bis < $von) {
- $aktiv = 0;
+ $host = NULL;
$bis = $von;
}
$bis = $bis + 30*60*(floor($now/60/60/24) - floor($von/60/60/24));
- if ($aktiv) {
+ if (!is_null($host)) {
$von = $now;
}
$noch = $bis - $von;
@@ -59,14 +59,18 @@ if (array_key_exists('msg', $_POST) && array_key_exists('sig', $_POST)) {
$noch = 4*60*60;
}
+ $msg_parts = explode(' ', $_POST['msg'], 2);
+
print($noch . "\n");
- switch ($_POST['msg']) {
+ switch ($msg_parts[1]) {
case 'start':
- $aktiv = 1;
+ $host = $msg_parts[0];
break;
;;
case 'stop':
- $aktiv = 0;
+ if ($host == $msg_parts[0]) {
+ $host = NULL;
+ }
break;
;;
default:
@@ -75,14 +79,20 @@ if (array_key_exists('msg', $_POST) && array_key_exists('sig', $_POST)) {
;;
}
if ($noch == 0) {
- $aktiv = 0;
+ $host = NULL;
}
$von = date('Y-m-d H:i:s', $now);
$bis = date('Y-m-d H:i:s', $now + $noch);
- log_to_file('to_db ' . $key . ' ' . $aktiv . ' ' . $von . ' ' . $bis);
+ if (is_null($host)) {
+ $host = 'NULL';
+ } else {
+ $host = '"' . $host . '"';
+ }
+
+ log_to_file('to_db ' . $key . ' ' . $host . ' ' . $von . ' ' . $bis);
$db -> exec(
'UPDATE `computer_time`' .
- ' SET `aktiv`=' . $aktiv . ',' .
+ ' SET `host`=' . $host . ',' .
'`von`="' . $von . '",' .
'`bis`="' . $bis . '"' .
' WHERE `name`="' . $key . '"');
@@ -98,7 +108,7 @@ while ($row = $result->fetchArray()) {
$bis = strtotime($row['bis']);
$von = strtotime($row['von']);
- if ($row['aktiv']) {
+ if (!is_null($row['host'])) {
$von = $now;
}
$noch = $bis - $von;
@@ -110,15 +120,7 @@ while ($row = $result->fetchArray()) {
print($noch);
print(')');
- ?></td><td><?php
-
- if ($row['aktiv']) {
- print('eingeloggt');
- } else {
- print('&nbsp;');
- }
-
- ?></td></tr>
+ ?></td><td><?php print($row['host']); ?></td></tr>
<?php
}