2020-08-31 19:23:23 +00:00
|
|
|
<?php
|
|
|
|
if (!empty ($_POST)){
|
2020-09-03 20:15:59 +00:00
|
|
|
$deviceManager = new DeviceManager ();
|
2021-01-05 11:19:30 +00:00
|
|
|
$subDeviceManager = new SubDeviceManager ();
|
2020-08-31 19:23:23 +00:00
|
|
|
if (!empty ($_FILES['deviceFirmware']) && !empty ($_FILES['deviceFirmware']['tmp_name']) && !empty ($_POST['deviceId'])) {
|
|
|
|
$file = $_FILES['deviceFirmware'];
|
|
|
|
$deviceMac = $deviceManager->getDeviceById ($_POST['deviceId'])['mac'];
|
|
|
|
$fileName = (!empty ($deviceMac) ? str_replace (":", "", $deviceMac) . ".bin" : "");
|
2020-09-02 17:44:40 +00:00
|
|
|
|
|
|
|
if ($fileName != "" && file_exists ("../updater/" . $fileName)) {
|
|
|
|
unlink("../updater/" . $fileName);
|
2020-08-31 19:23:23 +00:00
|
|
|
}
|
|
|
|
if ($fileName != "") {
|
2020-09-03 20:15:59 +00:00
|
|
|
copy ($file['tmp_name'], "../updater/" . $fileName);
|
2020-08-31 19:23:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset ($_POST['deviceCommand']) && !empty ($_POST['deviceId'])) {
|
|
|
|
$deviceManager->edit ($_POST['deviceId'], array ('command' => $_POST['deviceCommand']));
|
2020-09-08 16:00:44 +00:00
|
|
|
} else if (!empty ($_POST['deviceCommand'])) {
|
2020-09-03 20:15:59 +00:00
|
|
|
$devices = $deviceManager->getAllDevices();
|
|
|
|
foreach ($devices as $key => $device) {
|
|
|
|
$deviceManager->edit ($device['device_id'], array ('command' => $_POST['deviceCommand']));
|
|
|
|
}
|
2020-08-31 19:23:23 +00:00
|
|
|
}
|
2020-09-08 16:00:44 +00:00
|
|
|
if (!empty ($_POST['deviceRoomId']) && !empty ($_POST['deviceId'])) {
|
|
|
|
$deviceManager->edit ($_POST['deviceId'], array ('room_id' => $_POST['deviceRoomId']));
|
|
|
|
}
|
2020-09-08 16:47:58 +00:00
|
|
|
if (!empty ($_POST['deviceName']) && !empty ($_POST['deviceId'])) {
|
|
|
|
$deviceManager->edit ($_POST['deviceId'], array ('name' => $_POST['deviceName']));
|
|
|
|
}
|
2021-03-01 16:24:24 +00:00
|
|
|
if (!empty ($_POST['deviceApproved']) && !empty ($_POST['deviceId'])) {
|
|
|
|
$deviceManager->edit ($_POST['deviceId'], array ('approved' => $_POST['deviceApproved']));
|
|
|
|
}
|
2021-01-05 11:19:30 +00:00
|
|
|
if (isset ($_POST['deviceHistory']) && !empty ($_POST['deviceId'])) {
|
|
|
|
$subDeviceManager->editSubDevicesByDevice($_POST['deviceId'], array ('history' => $_POST['deviceHistory']));
|
|
|
|
}
|
|
|
|
header('Location: ' . BASEURL . str_replace(BASEDIR, "", $_SERVER['REQUEST_URI']));
|
2020-09-02 17:45:08 +00:00
|
|
|
die();
|
2020-08-31 19:23:23 +00:00
|
|
|
}
|