From 53dcd7604c077f2a46383f89843e967f0ee9f567 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 28 Jul 2022 13:12:43 +0200 Subject: add single lo key for power and ping --- html/db.php | 12 ++++++++---- html/maintenance.php | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/html/db.php b/html/db.php index fee5ef6..960cbd3 100644 --- a/html/db.php +++ b/html/db.php @@ -128,14 +128,18 @@ class MyDB extends SQLite3 { $stm -> close(); return $result['value_id']; } - function add_key_for($machine, $state, $comment) { + function add_key_for($machine, $states, $comment) { $key_id = $this -> add_key($comment); - $value_id = $this -> get_value_id_of($machine, $state); + if (!is_array($states)) + $states = array($states); $stm = $this -> prepare( 'INSERT INTO permissions (key_id, value_id) VALUES (:key,:value)'); - $stm -> bindValue('value', $value_id); $stm -> bindValue('key', $key_id); - $stm -> execute(); + foreach ($states as $state) { + $value_id = $this -> get_value_id_of($machine, $state); + $stm -> bindValue('value', $value_id); + $stm -> execute(); + } $stm -> close(); } } diff --git a/html/maintenance.php b/html/maintenance.php index b45b731..9982751 100644 --- a/html/maintenance.php +++ b/html/maintenance.php @@ -83,8 +83,7 @@ if (array_key_exists('lights_out_machines', $_GET)) { break; } } - $db -> add_key_for($machine_id, $power_id, 'lights-out'); - $db -> add_key_for($machine_id, $ping_id, 'lights-out'); + $db -> add_key_for($machine_id, array($power_id, $ping_id), 'lights-out'); } echo 'done.' . "\n"; die(); -- cgit v1.2.3-54-g00ecf