From ccea2e8d0b09e738ab1892d0aa546f102d28ed7f Mon Sep 17 00:00:00 2001 From: Mark Unwin Date: Tue, 5 Nov 2024 12:13:56 +1000 Subject: [PATCH] Fix fields editing on devicesRead template. --- app/Models/DevicesModel.php | 10 ++++++---- app/Views/devicesRead.php | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Models/DevicesModel.php b/app/Models/DevicesModel.php index aa39d6cbd..d913b6917 100644 --- a/app/Models/DevicesModel.php +++ b/app/Models/DevicesModel.php @@ -917,7 +917,9 @@ public function update($id = null, $data = null): bool } $update = $this->updateFieldData('devices', $update_device); $this->builder->where('id', intval($id)); - $this->builder->update($update); + if (count((array)$update_device) > 0) { + $this->builder->update($update_device); + } if ($this->sqlError($this->db->error())) { return false; } @@ -988,11 +990,11 @@ public function update($id = null, $data = null): bool $updated = false; if (!empty($deviceFields)) { foreach ($deviceFields as $deviceField) { - if (intval($field->id) === intval($deviceField->fields_id)) { + if (intval($field->id) === intval($deviceField->field_id)) { $previous_value = (!empty($deviceField->value)) ? $deviceField->value : ''; - $update = true; + $updated = true; $sql = "UPDATE field SET value = ?, `timestamp` = NOW() WHERE id = ?"; - $this->db->query($sql, [$deviceField->id, $value]); + $this->db->query($sql, [$value, $deviceField->id]); $sql = "INSERT INTO edit_log VALUES (null, ?, ?, 'Field data was updated', ?, ?, 'field', ?, NOW(), ?, ?)"; $this->db->query($sql, [$user_id, $id, $source, 1000, $field->name, $value, $previous_value]); } diff --git a/app/Views/devicesRead.php b/app/Views/devicesRead.php index 3e7bc7270..9ae0d4a8a 100644 --- a/app/Views/devicesRead.php +++ b/app/Views/devicesRead.php @@ -611,7 +611,7 @@ } echo "
\n"; if ($field->{'type'} == 'varchar') { - echo read_field($field->{'name'}, '', '', $update); + echo read_field($field->{'name'}, $field->{'field.value'}, '', $update); } if ($field->{'type'} == 'list') { @@ -634,11 +634,11 @@ $item->attributes->name = $value; $values[] = $item; } - echo read_select($field->name, '', '', $update, '', $values); + echo read_select($field->name, $field->{'field.value'}, '', $update, '', $values); } if ($field->{'type'} == 'date') { - echo read_field($field->{'name'}, '', '', $update, '', '', '', 'date') ; + echo read_field($field->{'name'}, $field->{'field.value'}, '', $update, '', '', '', 'date') ; } echo "
\n"; }