From 500feb1671439e3e23af0575d2986e02b9c81fe4 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 27 Mar 2018 09:36:12 +0200 Subject: [usb-lock-off] Saving the edited rule is now working properly. --- modules-available/usblockoff/page.inc.php | 32 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'modules-available') diff --git a/modules-available/usblockoff/page.inc.php b/modules-available/usblockoff/page.inc.php index ee3358c3..e978eec2 100644 --- a/modules-available/usblockoff/page.inc.php +++ b/modules-available/usblockoff/page.inc.php @@ -76,23 +76,27 @@ class Page_usblockoff extends Page Database::exec("DELETE FROM `usb_rule_prop` WHERE ruleid=:ruleid", array('ruleid' => $ruleid)); } - // TODO: Prepare array for the insert. prop- has to be cut and vid:pid = id - $insert_att = array(); + // Prepare array for the insert. prop- has to be cut and vid:pid = id + $a = array(); foreach ($attributes as $att) { - $a = array(); - // TODO: SPECIAL CASE: PID AND VID needs to put together to VID:PID = ID - $a['prop'] = substr($att['prop'], 5); - $a['value'] = $att['value']; - $insert_att[] = $a; + // SPECIAL CASE: PID AND VID needs to put together to VID:PID = ID + if (substr($att['prop'], 5) === "vid") { + $a['id'] = $att['value'] . ':' . $a['id']; + } else if (substr($att['prop'], 5) === "pid") { + $a['id'] = $a['id'] . $att['value']; + } else { + $a[substr($att['prop'], 5)] = $att['value']; + } } - /* - Database::exec("INSERT INTO `usb_rule_prop` (ruleid, prop, value) VALUES (:ruleid, :prop, :val)", array( - 'ruleid' => $ruleid, - 'prop' => $a['prop'], - 'val' => $a['value'] - )); - */ + foreach ($a as $key => $value) { + // TODO: Better in one query? + Database::exec("INSERT INTO `usb_rule_prop` (ruleid, prop, value) VALUES (:ruleid, :prop, :val)", array( + 'ruleid' => $ruleid, + 'prop' => $key, + 'val' => $value + )); + } } private function addDevices() -- cgit v1.2.3-55-g7522