<?php
error_reporting(0);
if ($_POST) {
$file_path = "//192.158.0.100/PRASHAN/Device control/device_log.txt";
$myfile = fopen($file_path, "w") or die("Unable to open file!");
$txt = $_POST['device']." ".$_POST['switch']."\n";
fwrite($myfile, $txt);
fclose($myfile);
}
?>
<html>
<head>
<script type="text/javascript">
function beforeSubmit(device_val, switch_val)
{
document.controll.device.value = device_val;
document.controll.switch.value = switch_val;
document.controll.submit();
}
<?php if($_POST) { ?>
var delay = 4000;
setTimeout(function() {
$device = null;
<?php if ($_POST['device'] == 'fan') {
$device = 'Fan';
} else if ($_POST['device'] == 'light1') {
$device = 'Motor';
} else if ($_POST['device'] == 'light2') {
$device = 'Light';
} else if ($_POST['device'] == 'light3') {
$device = 'Light';
}
if($_POST['switch'] == 'on') { ?>
document.getElementById("<?php echo $_POST['device']?>").innerHTML = '<span style="color:lime;"><b> <?php echo $device?> is On</b></span>';
<?php } else { ?>
document.getElementById("<?php echo $_POST['device']?>").innerHTML = '<span style="color:red;"><b> <?php echo $device?> is Off</b></span>';
<?php } ?>
}, delay);
<?php } ?>
</script>
</head>