From 4f584dd220e7e44a91f5b45c4102aff150987b5b Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Fri, 29 May 2015 19:03:36 +0200 Subject: [PATCH] (mvc) check for uuid before using it. --- .../app/library/OPNsense/Base/UIModelGrid.php | 66 ++++++++++--------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/opnsense/mvc/app/library/OPNsense/Base/UIModelGrid.php b/src/opnsense/mvc/app/library/OPNsense/Base/UIModelGrid.php index 81a153bb0..7d47f2c11 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Base/UIModelGrid.php +++ b/src/opnsense/mvc/app/library/OPNsense/Base/UIModelGrid.php @@ -70,46 +70,48 @@ class UIModelGrid $recordIndex = 0; foreach ($this->DataField->sortedBy($sortBy, $sortDescending) as $record) { - // parse rows, because we may need to convert some (list) items we need to know the actual content - // before searching. - $row = array(); - $row['uuid'] = $record->getAttributes()['uuid']; - foreach ($fields as $fieldname) { - $row[$fieldname] = $record->$fieldname->getNodeData(); - if (is_array($row[$fieldname])) { - foreach ($row[$fieldname] as $fieldKey => $fieldValue) { - if ($fieldValue['selected'] == 1) { - $row[$fieldname] = $fieldValue['value']; + if (array_key_exists("uuid", $record->getAttributes())) { + // parse rows, because we may need to convert some (list) items we need to know the actual content + // before searching. + $row = array(); + $row['uuid'] = $record->getAttributes()['uuid']; + foreach ($fields as $fieldname) { + $row[$fieldname] = $record->$fieldname->getNodeData(); + if (is_array($row[$fieldname])) { + foreach ($row[$fieldname] as $fieldKey => $fieldValue) { + if ($fieldValue['selected'] == 1) { + $row[$fieldname] = $fieldValue['value']; + } + } + if (is_array($row[$fieldname])) { + $row[$fieldname] = "##Unlinked"; } } - if (is_array($row[$fieldname])) { - $row[$fieldname] = "##Unlinked"; - } } - } - // if a search phrase is provided, use it to search in all requested fields - if ($searchPhrase != '') { - $searchFound = false; - foreach ($fields as $fieldname) { - if (strpos(strtolower($row[$fieldname]), strtolower($searchPhrase)) !== false) { - $searchFound = true; - break; + // if a search phrase is provided, use it to search in all requested fields + if ($searchPhrase != '') { + $searchFound = false; + foreach ($fields as $fieldname) { + if (strpos(strtolower($row[$fieldname]), strtolower($searchPhrase)) !== false) { + $searchFound = true; + break; + } } + } else { + $searchFound = true; } - } else { - $searchFound = true; - } - // if result is relevant, count total and add (max number of) items to result. - // $itemsPerPage = -1 is used as wildcard for "all results" - if ($searchFound) { - if ((count($result['rows']) < $itemsPerPage && - $recordIndex >= ($itemsPerPage*($currentPage-1)) || $itemsPerPage == -1) - ) { - $result['rows'][] = $row; + // if result is relevant, count total and add (max number of) items to result. + // $itemsPerPage = -1 is used as wildcard for "all results" + if ($searchFound) { + if ((count($result['rows']) < $itemsPerPage && + $recordIndex >= ($itemsPerPage*($currentPage-1)) || $itemsPerPage == -1) + ) { + $result['rows'][] = $row; + } + $recordIndex++; } - $recordIndex++; } }