From af878507421586e7d3191135238715d12412e225 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 20 Mar 2018 20:28:59 +0100 Subject: [usb-lock-off] Some bug fixes with wrong written targts in the db. --- modules-available/usblockoff/page.inc.php | 35 +++++++++++++++++----- .../usblockoff/templates/usb-edit-rule.html | 1 + 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'modules-available') diff --git a/modules-available/usblockoff/page.inc.php b/modules-available/usblockoff/page.inc.php index 40e0ff78..ee3358c3 100644 --- a/modules-available/usblockoff/page.inc.php +++ b/modules-available/usblockoff/page.inc.php @@ -69,13 +69,30 @@ class Page_usblockoff extends Page } private function editRule() { + $ruleid = Request::post('ruleid', 0, 'int'); + $attributes = json_decode(Request::post('attributes', '', 'string'), true); - $attributes = Request::post('attributes', '', 'string'); - $attributes = json_decode($attributes); + if ($ruleid != 0) { + Database::exec("DELETE FROM `usb_rule_prop` WHERE ruleid=:ruleid", array('ruleid' => $ruleid)); + } - foreach ($attributes as $a) { - // TODO: get attributes with $a['prop'] and $a['value'] and save or UPDATE it in the db. + // TODO: Prepare array for the insert. prop- has to be cut and vid:pid = id + $insert_att = 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; } + + /* + Database::exec("INSERT INTO `usb_rule_prop` (ruleid, prop, value) VALUES (:ruleid, :prop, :val)", array( + 'ruleid' => $ruleid, + 'prop' => $a['prop'], + 'val' => $a['value'] + )); + */ } private function addDevices() @@ -84,7 +101,6 @@ class Page_usblockoff extends Page $rules = json_decode(Request::post('rules', '', 'string'), true); - error_log(json_encode($rules)); foreach ($rules as $rule) { $rid = (int)$rule['id']; if($rid == 0) { @@ -143,14 +159,17 @@ class Page_usblockoff extends Page array( 'option' => 'allow', 'active' => true, + 'value' => 'allow', ), array( 'option' => 'block', 'active' => false, + 'value' => 'block', ), array( 'option' => 'reject', 'active' => false, + 'value' => 'reject', )); $setting['helptext'] = array('helptext' => Dictionary::translateFile('rule', 'abr_helptext')); $setting['property'] = 'action'; @@ -187,7 +206,6 @@ class Page_usblockoff extends Page 'ruleid' => $ruleid )); $idList = json_decode($this->getIDList(), true); - $pidList = array(); while ($attribute = $query->fetch(PDO::FETCH_ASSOC)) { $attributesHtml = ''; @@ -264,7 +282,7 @@ class Page_usblockoff extends Page Render::addTemplate('usb-edit-rule', array( 'configid' => $configid, 'attributes' => $attributes, - 'pidList' => array_values($pidList), + 'ruleid' => $ruleid, 'usbJson' => json_encode($idList), )); } @@ -340,14 +358,17 @@ class Page_usblockoff extends Page $setting['select_list'] = array(array( 'option' => 'allow', 'active' => ($target == 'allow' ? true : false), + 'value' => 'allow', ), array( 'option' => 'block', 'active' => ($target == 'block' ? true : false), + 'value' => 'block', ), array( 'option' => 'reject', 'active' => ($target == 'reject' ? true : false), + 'value' => 'reject', )); $setting['helptext'] = array('helptext' => Dictionary::translateFile('rule', 'abr_helptext')); $setting['property'] = 'action'; diff --git a/modules-available/usblockoff/templates/usb-edit-rule.html b/modules-available/usblockoff/templates/usb-edit-rule.html index ec14d5ab..296d3bf7 100644 --- a/modules-available/usblockoff/templates/usb-edit-rule.html +++ b/modules-available/usblockoff/templates/usb-edit-rule.html @@ -2,6 +2,7 @@ +
-- cgit v1.2.3-55-g7522