Add function on change room

This commit is contained in:
Haitem 2020-09-08 18:00:44 +02:00
parent 32521d0ed3
commit 2c6e7e2ecc
2 changed files with 18 additions and 10 deletions

View File

@ -15,12 +15,15 @@ if (!empty ($_POST)){
} }
if (isset ($_POST['deviceCommand']) && !empty ($_POST['deviceId'])) { if (isset ($_POST['deviceCommand']) && !empty ($_POST['deviceId'])) {
$deviceManager->edit ($_POST['deviceId'], array ('command' => $_POST['deviceCommand'])); $deviceManager->edit ($_POST['deviceId'], array ('command' => $_POST['deviceCommand']));
}else if (!empty ($_POST['deviceCommand'])) { } else if (!empty ($_POST['deviceCommand'])) {
$devices = $deviceManager->getAllDevices(); $devices = $deviceManager->getAllDevices();
foreach ($devices as $key => $device) { foreach ($devices as $key => $device) {
$deviceManager->edit ($device['device_id'], array ('command' => $_POST['deviceCommand'])); $deviceManager->edit ($device['device_id'], array ('command' => $_POST['deviceCommand']));
} }
} }
if (!empty ($_POST['deviceRoomId']) && !empty ($_POST['deviceId'])) {
$deviceManager->edit ($_POST['deviceId'], array ('room_id' => $_POST['deviceRoomId']));
}
header('Location: ./device'); header('Location: ./device');
die(); die();
} }

View File

@ -44,17 +44,22 @@
<td><i class="fa">&#x<?php echo (!empty($device['icon']) ? $device['icon'] : ""); ?></i></td> <td><i class="fa">&#x<?php echo (!empty($device['icon']) ? $device['icon'] : ""); ?></i></td>
<td><?php echo (!empty($device['name']) ? $device['name'] : ""); ?></td> <td><?php echo (!empty($device['name']) ? $device['name'] : ""); ?></td>
<td> <td>
<select class="input" id="device-<?php echo $device['device_id']?>-roomId"> <form method="post" action="" enctype="multipart/form-data">
<?php <input type="hidden" name="deviceId" value="<?php echo (!empty($device['device_id']) ? $device['device_id'] : ""); ?>">
foreach ($ROOMS as $key => $room) { <select class="input" name="deviceRoomId" onchange="this.form.submit();">
echo '<option value="'.$room['room_id'].'" '.($device['room_id'] == $room['room_id'] ? 'selected' : '').'>'.$room['name'].'</option>'; <?php
} if (!empty ($ROOMS)) {
?> foreach ($ROOMS as $key => $room) {
</select> echo '<option value="' . $room['room_id'] . '" ' . ($device['room_id'] == $room['room_id'] ? 'selected' : '') . '>' . $room['name'] . '</option>';
}
}
?>
</select>
</form>
</td> </td>
<td> <td>
<?php if (!empty($device['mac'])) : ?> <?php if (!empty($device['mac'])) : ?>
<?php <?php
$icon = "fa-circle"; $icon = "fa-circle";
$color = "yellow"; $color = "yellow";
if (!empty($device['firmware_hash'])) { if (!empty($device['firmware_hash'])) {
@ -69,7 +74,7 @@
} }
} }
?> ?>
<i class="fa <?php echo $icon; ?>" style="color: <?php echo $color; ?>"></i> <i class="fa <?php echo $icon; ?>" style="color: <?php echo $color; ?>"></i>
<?php echo $device['firmware_hash'] ?> <?php echo $device['firmware_hash'] ?>
<button class="fa custom-file-input" type="button" onclick="document.getElementById('deviceFirmware-<?php echo $device['device_id']?>').click();">&#xf0ee;</button> <button class="fa custom-file-input" type="button" onclick="document.getElementById('deviceFirmware-<?php echo $device['device_id']?>').click();">&#xf0ee;</button>