@@ -7,103 +7,103 @@ |
||
| 7 | 7 | class HandlerTable extends TrapDirectorTable |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - protected $status_display=array( |
|
| 11 | - -2 =>'ignore', |
|
| 12 | - -1 => '-', |
|
| 13 | - 0 => 'OK', |
|
| 14 | - 1 => 'warning', |
|
| 15 | - 2 => 'critical', |
|
| 16 | - 3 => 'unknown',); |
|
| 10 | + protected $status_display=array( |
|
| 11 | + -2 =>'ignore', |
|
| 12 | + -1 => '-', |
|
| 13 | + 0 => 'OK', |
|
| 14 | + 1 => 'warning', |
|
| 15 | + 2 => 'critical', |
|
| 16 | + 3 => 'unknown',); |
|
| 17 | 17 | |
| 18 | - // translate |
|
| 19 | - protected $doTranslate=false; |
|
| 20 | - protected $MIB; |
|
| 18 | + // translate |
|
| 19 | + protected $doTranslate=false; |
|
| 20 | + protected $MIB; |
|
| 21 | 21 | |
| 22 | - public function setMibloader($mibloader) |
|
| 23 | - { |
|
| 24 | - $this->MIB=$mibloader; |
|
| 25 | - $this->doTranslate=true; |
|
| 26 | - } |
|
| 22 | + public function setMibloader($mibloader) |
|
| 23 | + { |
|
| 24 | + $this->MIB=$mibloader; |
|
| 25 | + $this->doTranslate=true; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - public function getCurrentURL() |
|
| 30 | - { |
|
| 31 | - return Url::fromPath($this->urlPath . '/handler'); |
|
| 32 | - } |
|
| 29 | + public function getCurrentURL() |
|
| 30 | + { |
|
| 31 | + return Url::fromPath($this->urlPath . '/handler'); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - public function renderLine($row) |
|
| 35 | - { |
|
| 36 | - $html = ''; |
|
| 37 | - $firstCol = true; |
|
| 34 | + public function renderLine($row) |
|
| 35 | + { |
|
| 36 | + $html = ''; |
|
| 37 | + $firstCol = true; |
|
| 38 | 38 | |
| 39 | - $titleNames = array_keys($this->titles); |
|
| 40 | - foreach ($titleNames as $rowkey ) |
|
| 41 | - { |
|
| 42 | - // Check missing value |
|
| 43 | - if (property_exists($row, $rowkey)) |
|
| 44 | - { |
|
| 45 | - switch ($rowkey) |
|
| 46 | - { |
|
| 47 | - case 'action_match': // display text levels |
|
| 48 | - case 'action_nomatch': |
|
| 49 | - $val=$this->status_display[$row->$rowkey]; |
|
| 50 | - break; |
|
| 51 | - case 'trap_oid': // try to traslate oids. |
|
| 39 | + $titleNames = array_keys($this->titles); |
|
| 40 | + foreach ($titleNames as $rowkey ) |
|
| 41 | + { |
|
| 42 | + // Check missing value |
|
| 43 | + if (property_exists($row, $rowkey)) |
|
| 44 | + { |
|
| 45 | + switch ($rowkey) |
|
| 46 | + { |
|
| 47 | + case 'action_match': // display text levels |
|
| 48 | + case 'action_nomatch': |
|
| 49 | + $val=$this->status_display[$row->$rowkey]; |
|
| 50 | + break; |
|
| 51 | + case 'trap_oid': // try to traslate oids. |
|
| 52 | 52 | |
| 53 | - if ($this->doTranslate === true) |
|
| 54 | - { |
|
| 55 | - $oidName = $this->MIB->translateOID($row->$rowkey); |
|
| 56 | - if (isset($oidName['name'])) |
|
| 57 | - { |
|
| 58 | - $val=$oidName['name']; |
|
| 59 | - } |
|
| 60 | - else |
|
| 61 | - { |
|
| 62 | - $val = $row->$rowkey; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - else |
|
| 66 | - { |
|
| 67 | - $val = $row->$rowkey; |
|
| 68 | - } |
|
| 69 | - break; |
|
| 70 | - case 'host_name': // switch to hostgroup if name is null |
|
| 71 | - if ($row->$rowkey == null) |
|
| 72 | - { |
|
| 73 | - $val = $row->host_group_name; |
|
| 74 | - } |
|
| 75 | - else |
|
| 76 | - { |
|
| 77 | - $val = $row->$rowkey; |
|
| 78 | - } |
|
| 79 | - break; |
|
| 80 | - default: |
|
| 81 | - $val = $row->$rowkey; |
|
| 82 | - } |
|
| 83 | - if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
| 84 | - { |
|
| 53 | + if ($this->doTranslate === true) |
|
| 54 | + { |
|
| 55 | + $oidName = $this->MIB->translateOID($row->$rowkey); |
|
| 56 | + if (isset($oidName['name'])) |
|
| 57 | + { |
|
| 58 | + $val=$oidName['name']; |
|
| 59 | + } |
|
| 60 | + else |
|
| 61 | + { |
|
| 62 | + $val = $row->$rowkey; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + else |
|
| 66 | + { |
|
| 67 | + $val = $row->$rowkey; |
|
| 68 | + } |
|
| 69 | + break; |
|
| 70 | + case 'host_name': // switch to hostgroup if name is null |
|
| 71 | + if ($row->$rowkey == null) |
|
| 72 | + { |
|
| 73 | + $val = $row->host_group_name; |
|
| 74 | + } |
|
| 75 | + else |
|
| 76 | + { |
|
| 77 | + $val = $row->$rowkey; |
|
| 78 | + } |
|
| 79 | + break; |
|
| 80 | + default: |
|
| 81 | + $val = $row->$rowkey; |
|
| 82 | + } |
|
| 83 | + if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
| 84 | + { |
|
| 85 | 85 | |
| 86 | - } |
|
| 87 | - } else { |
|
| 88 | - $val = '-'; |
|
| 89 | - } |
|
| 90 | - if ($firstCol === true) { // Put link in first column for trap detail. |
|
| 91 | - $html .= '<td>' |
|
| 92 | - . $this->view->qlink( |
|
| 93 | - $this->view->escape($val), |
|
| 94 | - Url::fromPath( |
|
| 95 | - $this->urlPath . '/handler/add', |
|
| 96 | - array('ruleid' => $row->id) |
|
| 97 | - ) |
|
| 98 | - ) |
|
| 99 | - . '</td>'; |
|
| 100 | - } else { |
|
| 101 | - $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
| 102 | - } |
|
| 103 | - $firstCol=false; |
|
| 86 | + } |
|
| 87 | + } else { |
|
| 88 | + $val = '-'; |
|
| 89 | + } |
|
| 90 | + if ($firstCol === true) { // Put link in first column for trap detail. |
|
| 91 | + $html .= '<td>' |
|
| 92 | + . $this->view->qlink( |
|
| 93 | + $this->view->escape($val), |
|
| 94 | + Url::fromPath( |
|
| 95 | + $this->urlPath . '/handler/add', |
|
| 96 | + array('ruleid' => $row->id) |
|
| 97 | + ) |
|
| 98 | + ) |
|
| 99 | + . '</td>'; |
|
| 100 | + } else { |
|
| 101 | + $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
| 102 | + } |
|
| 103 | + $firstCol=false; |
|
| 104 | 104 | |
| 105 | - } |
|
| 106 | - return $html; |
|
| 107 | - } |
|
| 105 | + } |
|
| 106 | + return $html; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | } |
| 110 | 110 | \ No newline at end of file |
@@ -28,16 +28,16 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function getCurrentURL() |
| 30 | 30 | { |
| 31 | - return Url::fromPath($this->urlPath . '/handler'); |
|
| 31 | + return Url::fromPath($this->urlPath.'/handler'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function renderLine($row) |
| 35 | 35 | { |
| 36 | - $html = ''; |
|
| 37 | - $firstCol = true; |
|
| 36 | + $html=''; |
|
| 37 | + $firstCol=true; |
|
| 38 | 38 | |
| 39 | - $titleNames = array_keys($this->titles); |
|
| 40 | - foreach ($titleNames as $rowkey ) |
|
| 39 | + $titleNames=array_keys($this->titles); |
|
| 40 | + foreach ($titleNames as $rowkey) |
|
| 41 | 41 | { |
| 42 | 42 | // Check missing value |
| 43 | 43 | if (property_exists($row, $rowkey)) |
@@ -52,53 +52,53 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | if ($this->doTranslate === true) |
| 54 | 54 | { |
| 55 | - $oidName = $this->MIB->translateOID($row->$rowkey); |
|
| 55 | + $oidName=$this->MIB->translateOID($row->$rowkey); |
|
| 56 | 56 | if (isset($oidName['name'])) |
| 57 | 57 | { |
| 58 | 58 | $val=$oidName['name']; |
| 59 | 59 | } |
| 60 | 60 | else |
| 61 | 61 | { |
| 62 | - $val = $row->$rowkey; |
|
| 62 | + $val=$row->$rowkey; |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | else |
| 66 | 66 | { |
| 67 | - $val = $row->$rowkey; |
|
| 67 | + $val=$row->$rowkey; |
|
| 68 | 68 | } |
| 69 | 69 | break; |
| 70 | 70 | case 'host_name': // switch to hostgroup if name is null |
| 71 | 71 | if ($row->$rowkey == null) |
| 72 | 72 | { |
| 73 | - $val = $row->host_group_name; |
|
| 73 | + $val=$row->host_group_name; |
|
| 74 | 74 | } |
| 75 | 75 | else |
| 76 | 76 | { |
| 77 | - $val = $row->$rowkey; |
|
| 77 | + $val=$row->$rowkey; |
|
| 78 | 78 | } |
| 79 | 79 | break; |
| 80 | 80 | default: |
| 81 | - $val = $row->$rowkey; |
|
| 81 | + $val=$row->$rowkey; |
|
| 82 | 82 | } |
| 83 | - if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
|
| 83 | + if ($rowkey == 'trap_oid' && $this->doTranslate === true) |
|
| 84 | 84 | { |
| 85 | 85 | |
| 86 | 86 | } |
| 87 | 87 | } else { |
| 88 | - $val = '-'; |
|
| 88 | + $val='-'; |
|
| 89 | 89 | } |
| 90 | 90 | if ($firstCol === true) { // Put link in first column for trap detail. |
| 91 | - $html .= '<td>' |
|
| 91 | + $html.='<td>' |
|
| 92 | 92 | . $this->view->qlink( |
| 93 | 93 | $this->view->escape($val), |
| 94 | 94 | Url::fromPath( |
| 95 | - $this->urlPath . '/handler/add', |
|
| 95 | + $this->urlPath.'/handler/add', |
|
| 96 | 96 | array('ruleid' => $row->id) |
| 97 | 97 | ) |
| 98 | 98 | ) |
| 99 | 99 | . '</td>'; |
| 100 | 100 | } else { |
| 101 | - $html .= '<td>' . $this->view->escape($val) . '</td>'; |
|
| 101 | + $html.='<td>'.$this->view->escape($val).'</td>'; |
|
| 102 | 102 | } |
| 103 | 103 | $firstCol=false; |
| 104 | 104 | |
@@ -56,13 +56,11 @@ discard block |
||
| 56 | 56 | if (isset($oidName['name'])) |
| 57 | 57 | { |
| 58 | 58 | $val=$oidName['name']; |
| 59 | - } |
|
| 60 | - else |
|
| 59 | + } else |
|
| 61 | 60 | { |
| 62 | 61 | $val = $row->$rowkey; |
| 63 | 62 | } |
| 64 | - } |
|
| 65 | - else |
|
| 63 | + } else |
|
| 66 | 64 | { |
| 67 | 65 | $val = $row->$rowkey; |
| 68 | 66 | } |
@@ -71,8 +69,7 @@ discard block |
||
| 71 | 69 | if ($row->$rowkey == null) |
| 72 | 70 | { |
| 73 | 71 | $val = $row->host_group_name; |
| 74 | - } |
|
| 75 | - else |
|
| 72 | + } else |
|
| 76 | 73 | { |
| 77 | 74 | $val = $row->$rowkey; |
| 78 | 75 | } |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | // Filters |
| 20 | 20 | |
| 21 | - protected $filter; |
|
| 22 | - protected $enforcedFilters = array(); |
|
| 23 | - protected $searchColumns = array(); |
|
| 21 | + protected $filter; |
|
| 22 | + protected $enforcedFilters = array(); |
|
| 23 | + protected $searchColumns = array(); |
|
| 24 | 24 | |
| 25 | 25 | protected function getTitles() { |
| 26 | 26 | // TODO : check moduleconfig is set |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | // ****************** Render table in html |
| 31 | - public function __toString() |
|
| 32 | - { |
|
| 33 | - return $this->render(); |
|
| 34 | - } |
|
| 31 | + public function __toString() |
|
| 32 | + { |
|
| 33 | + return $this->render(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | public function render() |
| 37 | 37 | { |
@@ -95,26 +95,26 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public function count() |
|
| 99 | - { |
|
| 100 | - $db=$this->db(); |
|
| 98 | + public function count() |
|
| 99 | + { |
|
| 100 | + $db=$this->db(); |
|
| 101 | 101 | |
| 102 | 102 | $query = $db->select()->from( |
| 103 | - $this->moduleConfig->getTrapTableName(), |
|
| 104 | - array('COUNT(*)') |
|
| 105 | - ); |
|
| 103 | + $this->moduleConfig->getTrapTableName(), |
|
| 104 | + array('COUNT(*)') |
|
| 105 | + ); |
|
| 106 | 106 | $this->applyFiltersToQuery($query); |
| 107 | 107 | |
| 108 | - return $db->fetchOne($query); |
|
| 109 | - } |
|
| 108 | + return $db->fetchOne($query); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - public function getPaginator() |
|
| 112 | - { |
|
| 113 | - $paginator = new Paginator(); |
|
| 114 | - $paginator->setQuery($this); |
|
| 111 | + public function getPaginator() |
|
| 112 | + { |
|
| 113 | + $paginator = new Paginator(); |
|
| 114 | + $paginator->setQuery($this); |
|
| 115 | 115 | |
| 116 | - return $paginator; |
|
| 117 | - } |
|
| 116 | + return $paginator; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | // ****************** DB connection and query |
| 120 | 120 | |
@@ -124,24 +124,24 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | $query = $this->getBaseQuery(); |
| 126 | 126 | $this->applyFiltersToQuery($query); |
| 127 | - if ($this->hasLimit() || $this->hasOffset()) { |
|
| 128 | - $query->limit($this->getLimit(), $this->getOffset()); |
|
| 129 | - } |
|
| 127 | + if ($this->hasLimit() || $this->hasOffset()) { |
|
| 128 | + $query->limit($this->getLimit(), $this->getOffset()); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | return $db->fetchAll($query); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - public function getBaseQuery() |
|
| 135 | - { |
|
| 134 | + public function getBaseQuery() |
|
| 135 | + { |
|
| 136 | 136 | $db=$this->db(); |
| 137 | 137 | |
| 138 | 138 | $query = $db->select()->from( |
| 139 | - $this->moduleConfig->getTrapTableName(), |
|
| 140 | - $this->moduleConfig->getTrapListDisplayColumns() |
|
| 141 | - )->order('timestamp DESC'); |
|
| 139 | + $this->moduleConfig->getTrapTableName(), |
|
| 140 | + $this->moduleConfig->getTrapListDisplayColumns() |
|
| 141 | + )->order('timestamp DESC'); |
|
| 142 | 142 | |
| 143 | - return $query; |
|
| 144 | - } |
|
| 143 | + return $query; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | 146 | // ****************** Filters |
| 147 | 147 | |
@@ -171,39 +171,39 @@ discard block |
||
| 171 | 171 | $this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - protected function getSearchColumns() |
|
| 175 | - { |
|
| 176 | - return $this->getColumns(); |
|
| 177 | - } |
|
| 174 | + protected function getSearchColumns() |
|
| 175 | + { |
|
| 176 | + return $this->getColumns(); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | public function getColumns() |
| 180 | 180 | { |
| 181 | 181 | return $this->moduleConfig->getTrapListDisplayColumns(); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function setFilter($filter) |
|
| 185 | - { |
|
| 186 | - $this->filter = $filter; |
|
| 187 | - return $this; |
|
| 188 | - } |
|
| 184 | + public function setFilter($filter) |
|
| 185 | + { |
|
| 186 | + $this->filter = $filter; |
|
| 187 | + return $this; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | public function getFilterEditor(Request $request) |
| 191 | - { |
|
| 192 | - $filterEditor = Widget::create('filterEditor') |
|
| 193 | - ->setColumns(array_keys($this->getColumns())) |
|
| 194 | - ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
| 195 | - ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
| 196 | - ->ignoreParams('page') |
|
| 197 | - ->handleRequest($request); |
|
| 191 | + { |
|
| 192 | + $filterEditor = Widget::create('filterEditor') |
|
| 193 | + ->setColumns(array_keys($this->getColumns())) |
|
| 194 | + ->setSearchColumns(array_keys($this->getSearchColumns())) |
|
| 195 | + ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
|
| 196 | + ->ignoreParams('page') |
|
| 197 | + ->handleRequest($request); |
|
| 198 | 198 | |
| 199 | - $filter = $filterEditor->getFilter(); |
|
| 200 | - $this->setFilter($filter); |
|
| 199 | + $filter = $filterEditor->getFilter(); |
|
| 200 | + $this->setFilter($filter); |
|
| 201 | 201 | |
| 202 | - return $filterEditor; |
|
| 203 | - } |
|
| 202 | + return $filterEditor; |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - protected function applyFiltersToQuery($query) |
|
| 206 | - { |
|
| 205 | + protected function applyFiltersToQuery($query) |
|
| 206 | + { |
|
| 207 | 207 | |
| 208 | 208 | $sql=''; |
| 209 | 209 | if ($this->filter_query != '') |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $sql.="(status != 'done')"; |
| 225 | 225 | } |
| 226 | 226 | if ($sql != '') $query->where($sql); |
| 227 | - return $query; |
|
| 228 | - } |
|
| 227 | + return $query; |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | 230 | } |
| 231 | 231 | \ No newline at end of file |
@@ -212,7 +212,9 @@ discard block |
||
| 212 | 212 | $first=1; |
| 213 | 213 | foreach($this->moduleConfig->getTrapListSearchColumns() as $column) |
| 214 | 214 | { |
| 215 | - if ($first==0) $sql.=' OR '; |
|
| 215 | + if ($first==0) { |
|
| 216 | + $sql.=' OR '; |
|
| 217 | + } |
|
| 216 | 218 | $first=0; |
| 217 | 219 | $sql.=" CAST(".$column." AS char(100)) LIKE '%".$this->filter_query."%' "; |
| 218 | 220 | } |
@@ -220,10 +222,14 @@ discard block |
||
| 220 | 222 | } |
| 221 | 223 | if ($this->filter_done == 1) |
| 222 | 224 | { |
| 223 | - if ($sql != '') $sql.=' AND '; |
|
| 225 | + if ($sql != '') { |
|
| 226 | + $sql.=' AND '; |
|
| 227 | + } |
|
| 224 | 228 | $sql.="(status != 'done')"; |
| 225 | 229 | } |
| 226 | - if ($sql != '') $query->where($sql); |
|
| 230 | + if ($sql != '') { |
|
| 231 | + $query->where($sql); |
|
| 232 | + } |
|
| 227 | 233 | return $query; |
| 228 | 234 | } |
| 229 | 235 | |
@@ -9,275 +9,275 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | abstract class TrapDirectorTable |
| 11 | 11 | { |
| 12 | - /** @var array $titles table titles (name, display value) */ |
|
| 13 | - protected $titles = null; |
|
| 12 | + /** @var array $titles table titles (name, display value) */ |
|
| 13 | + protected $titles = null; |
|
| 14 | 14 | |
| 15 | - /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
|
| 16 | - protected $content = null; |
|
| 15 | + /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
|
| 16 | + protected $content = null; |
|
| 17 | 17 | |
| 18 | - /** @var array $columnNames names of columns for filtering */ |
|
| 19 | - protected $columnNames = array(); |
|
| 18 | + /** @var array $columnNames names of columns for filtering */ |
|
| 19 | + protected $columnNames = array(); |
|
| 20 | 20 | |
| 21 | - /** @var Selectable $dbConn connection to database */ |
|
| 22 | - protected $dbConn = null; |
|
| 21 | + /** @var Selectable $dbConn connection to database */ |
|
| 22 | + protected $dbConn = null; |
|
| 23 | 23 | |
| 24 | - /** Current view **/ |
|
| 25 | - protected $view; |
|
| 24 | + /** Current view **/ |
|
| 25 | + protected $view; |
|
| 26 | 26 | |
| 27 | - protected $urlPath; |
|
| 27 | + protected $urlPath; |
|
| 28 | 28 | |
| 29 | - // Database stuff |
|
| 29 | + // Database stuff |
|
| 30 | 30 | /** @var array $table (db ref, name) */ |
| 31 | - protected $table = array(); |
|
| 31 | + protected $table = array(); |
|
| 32 | 32 | |
| 33 | - /** @var Queryable $query Query in database; */ |
|
| 34 | - protected $query = null; |
|
| 33 | + /** @var Queryable $query Query in database; */ |
|
| 34 | + protected $query = null; |
|
| 35 | 35 | |
| 36 | - /** @var array $order : (db column, 'ASC' | 'DESC') */ |
|
| 37 | - protected $order = array(); |
|
| 38 | - protected $orderQuery = ''; |
|
| 36 | + /** @var array $order : (db column, 'ASC' | 'DESC') */ |
|
| 37 | + protected $order = array(); |
|
| 38 | + protected $orderQuery = ''; |
|
| 39 | 39 | |
| 40 | - /********* Filter ********/ |
|
| 41 | - /** @var string $filterString : string filter for db columns */ |
|
| 42 | - protected $filterString = ''; |
|
| 40 | + /********* Filter ********/ |
|
| 41 | + /** @var string $filterString : string filter for db columns */ |
|
| 42 | + protected $filterString = ''; |
|
| 43 | 43 | |
| 44 | - /** @var array $filterColumn : columns to apply filter to */ |
|
| 45 | - protected $filterColumn = array(); |
|
| 44 | + /** @var array $filterColumn : columns to apply filter to */ |
|
| 45 | + protected $filterColumn = array(); |
|
| 46 | 46 | |
| 47 | - protected $filterQuery=''; |
|
| 47 | + protected $filterQuery=''; |
|
| 48 | 48 | |
| 49 | - /*************** Paging *************/ |
|
| 50 | - protected $maxPerPage = 25; |
|
| 49 | + /*************** Paging *************/ |
|
| 50 | + protected $maxPerPage = 25; |
|
| 51 | 51 | |
| 52 | - protected $currentPage = 0; |
|
| 52 | + protected $currentPage = 0; |
|
| 53 | 53 | |
| 54 | - function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
| 55 | - { |
|
| 56 | - $this->table = $table; |
|
| 57 | - $this->titles = $titles; |
|
| 58 | - $this->content = $columns; |
|
| 59 | - $this->columnNames = $columnNames; |
|
| 60 | - $this->dbConn = $dbConn; |
|
| 54 | + function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
| 55 | + { |
|
| 56 | + $this->table = $table; |
|
| 57 | + $this->titles = $titles; |
|
| 58 | + $this->content = $columns; |
|
| 59 | + $this->columnNames = $columnNames; |
|
| 60 | + $this->dbConn = $dbConn; |
|
| 61 | 61 | |
| 62 | - $this->view = $view; |
|
| 63 | - $this->urlPath = $urlPath; |
|
| 62 | + $this->view = $view; |
|
| 63 | + $this->urlPath = $urlPath; |
|
| 64 | 64 | |
| 65 | - return $this; |
|
| 66 | - } |
|
| 65 | + return $this; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | - /************** GET variables and URLs *************/ |
|
| 70 | - public function getParams(array $getVars) |
|
| 71 | - { |
|
| 72 | - $this->getFilterQuery($getVars); |
|
| 73 | - $this->getPagingQuery($getVars); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function getCurrentURL() |
|
| 77 | - { |
|
| 78 | - return '?'; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - protected function getCurrentURLAndQS(string $caller) |
|
| 82 | - { |
|
| 83 | - $actionURL = $this->getCurrentURL() . '?' ; |
|
| 84 | - $QSList=array(); |
|
| 85 | - if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
| 86 | - array_push($QSList , $this->curFilterQuery()); |
|
| 69 | + /************** GET variables and URLs *************/ |
|
| 70 | + public function getParams(array $getVars) |
|
| 71 | + { |
|
| 72 | + $this->getFilterQuery($getVars); |
|
| 73 | + $this->getPagingQuery($getVars); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function getCurrentURL() |
|
| 77 | + { |
|
| 78 | + return '?'; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + protected function getCurrentURLAndQS(string $caller) |
|
| 82 | + { |
|
| 83 | + $actionURL = $this->getCurrentURL() . '?' ; |
|
| 84 | + $QSList=array(); |
|
| 85 | + if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
| 86 | + array_push($QSList , $this->curFilterQuery()); |
|
| 87 | 87 | |
| 88 | - if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
| 89 | - array_push($QSList , $this->curPagingQuery()); |
|
| 88 | + if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
| 89 | + array_push($QSList , $this->curPagingQuery()); |
|
| 90 | 90 | |
| 91 | - if ($caller != 'order' && $this->curOrderQuery() != '') |
|
| 92 | - array_push($QSList , $this->curOrderQuery()); |
|
| 91 | + if ($caller != 'order' && $this->curOrderQuery() != '') |
|
| 92 | + array_push($QSList , $this->curOrderQuery()); |
|
| 93 | 93 | |
| 94 | - if (count($QSList) != 0) |
|
| 95 | - $actionURL .= implode('&', $QSList); |
|
| 94 | + if (count($QSList) != 0) |
|
| 95 | + $actionURL .= implode('&', $QSList); |
|
| 96 | 96 | |
| 97 | - return $actionURL; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /************* DB queries ******************/ |
|
| 101 | - /** |
|
| 102 | - * Get base query in $this->query |
|
| 103 | - * @return TrapDirectorTable |
|
| 104 | - */ |
|
| 105 | - public function getBaseQuery() |
|
| 106 | - { |
|
| 107 | - $this->query = $this->dbConn->select(); |
|
| 108 | - $this->query = $this->query->from( |
|
| 109 | - $this->table, |
|
| 110 | - $this->content |
|
| 111 | - ); |
|
| 97 | + return $actionURL; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /************* DB queries ******************/ |
|
| 101 | + /** |
|
| 102 | + * Get base query in $this->query |
|
| 103 | + * @return TrapDirectorTable |
|
| 104 | + */ |
|
| 105 | + public function getBaseQuery() |
|
| 106 | + { |
|
| 107 | + $this->query = $this->dbConn->select(); |
|
| 108 | + $this->query = $this->query->from( |
|
| 109 | + $this->table, |
|
| 110 | + $this->content |
|
| 111 | + ); |
|
| 112 | 112 | |
| 113 | - return $this; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - public function fullQuery() |
|
| 117 | - { |
|
| 118 | - $this->getBaseQuery() |
|
| 119 | - ->applyFilter() |
|
| 120 | - ->applyPaging() |
|
| 121 | - ->applyOrder(); |
|
| 113 | + return $this; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + public function fullQuery() |
|
| 117 | + { |
|
| 118 | + $this->getBaseQuery() |
|
| 119 | + ->applyFilter() |
|
| 120 | + ->applyPaging() |
|
| 121 | + ->applyOrder(); |
|
| 122 | 122 | |
| 123 | - return $this->dbConn->fetchAll($this->query); |
|
| 124 | - //return $this->query->fetchAll(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /**************** Filtering ******************/ |
|
| 129 | - public function applyFilter() |
|
| 130 | - { |
|
| 131 | - if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
| 132 | - { |
|
| 133 | - return $this; |
|
| 134 | - } |
|
| 135 | - $filter=''; |
|
| 136 | - foreach ($this->filterColumn as $column) |
|
| 137 | - { |
|
| 138 | - if ($filter != "") $filter.=' OR '; |
|
| 139 | - //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
| 140 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
| 141 | - } |
|
| 142 | - //echo $filter; |
|
| 123 | + return $this->dbConn->fetchAll($this->query); |
|
| 124 | + //return $this->query->fetchAll(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /**************** Filtering ******************/ |
|
| 129 | + public function applyFilter() |
|
| 130 | + { |
|
| 131 | + if ($this->filterString == '' || count($this->filterColumn) == 0) |
|
| 132 | + { |
|
| 133 | + return $this; |
|
| 134 | + } |
|
| 135 | + $filter=''; |
|
| 136 | + foreach ($this->filterColumn as $column) |
|
| 137 | + { |
|
| 138 | + if ($filter != "") $filter.=' OR '; |
|
| 139 | + //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
|
| 140 | + $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
| 141 | + } |
|
| 142 | + //echo $filter; |
|
| 143 | 143 | |
| 144 | - $this->query=$this->query->where($filter); |
|
| 144 | + $this->query=$this->query->where($filter); |
|
| 145 | 145 | |
| 146 | - return $this; |
|
| 147 | - } |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - public function setFilter(string $filter, array $filterCol) |
|
| 150 | - { |
|
| 151 | - $this->filterString = $filter; |
|
| 152 | - $this->filterColumn = $filterCol; |
|
| 153 | - return $this; |
|
| 154 | - } |
|
| 149 | + public function setFilter(string $filter, array $filterCol) |
|
| 150 | + { |
|
| 151 | + $this->filterString = $filter; |
|
| 152 | + $this->filterColumn = $filterCol; |
|
| 153 | + return $this; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - public function renderFilter() |
|
| 158 | - { |
|
| 157 | + public function renderFilter() |
|
| 158 | + { |
|
| 159 | 159 | |
| 160 | - $html=' <form id="genfilter" name="mainFilterGen" |
|
| 160 | + $html=' <form id="genfilter" name="mainFilterGen" |
|
| 161 | 161 | enctype="application/x-www-form-urlencoded" |
| 162 | 162 | action="'.$this->getCurrentURLAndQS('filter').'" |
| 163 | 163 | method="get">'; |
| 164 | - $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
| 164 | + $html.='<input type="text" name="f" title="Search is simple! Try to combine multiple words" |
|
| 165 | 165 | placeholder="Search..." value="'.$this->filterQuery.'">'; |
| 166 | 166 | |
| 167 | - $html.='</form>'; |
|
| 168 | - return $html; |
|
| 169 | - } |
|
| 167 | + $html.='</form>'; |
|
| 168 | + return $html; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - public function getFilterQuery(array $getVars) |
|
| 172 | - { |
|
| 173 | - if (isset($getVars['f'])) |
|
| 174 | - { |
|
| 175 | - $this->filterQuery = $getVars['f']; |
|
| 176 | - $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - protected function curFilterQuery() |
|
| 181 | - { |
|
| 182 | - if ($this->filterQuery == '') return ''; |
|
| 183 | - return 'f='.$this->filterQuery; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /***************** Ordering ********************/ |
|
| 187 | - public function applyOrder() |
|
| 188 | - { |
|
| 189 | - if (count($this->order) == 0) |
|
| 190 | - { |
|
| 191 | - return $this; |
|
| 192 | - } |
|
| 193 | - $orderSQL=''; |
|
| 194 | - foreach ($this->order as $column => $direction) |
|
| 195 | - { |
|
| 196 | - if ($orderSQL != "") $orderSQL.=','; |
|
| 171 | + public function getFilterQuery(array $getVars) |
|
| 172 | + { |
|
| 173 | + if (isset($getVars['f'])) |
|
| 174 | + { |
|
| 175 | + $this->filterQuery = $getVars['f']; |
|
| 176 | + $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + protected function curFilterQuery() |
|
| 181 | + { |
|
| 182 | + if ($this->filterQuery == '') return ''; |
|
| 183 | + return 'f='.$this->filterQuery; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /***************** Ordering ********************/ |
|
| 187 | + public function applyOrder() |
|
| 188 | + { |
|
| 189 | + if (count($this->order) == 0) |
|
| 190 | + { |
|
| 191 | + return $this; |
|
| 192 | + } |
|
| 193 | + $orderSQL=''; |
|
| 194 | + foreach ($this->order as $column => $direction) |
|
| 195 | + { |
|
| 196 | + if ($orderSQL != "") $orderSQL.=','; |
|
| 197 | 197 | |
| 198 | - $orderSQL .= $column . ' ' . $direction; |
|
| 199 | - } |
|
| 200 | - $this->query = $this->query->order($orderSQL); |
|
| 198 | + $orderSQL .= $column . ' ' . $direction; |
|
| 199 | + } |
|
| 200 | + $this->query = $this->query->order($orderSQL); |
|
| 201 | 201 | |
| 202 | - return $this; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - public function setOrder(array $order) |
|
| 206 | - { |
|
| 207 | - $this->order = $order; |
|
| 208 | - return $this; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - public function getOrderQuery(array $getVars) |
|
| 212 | - { |
|
| 213 | - if (isset($getVars['o'])) |
|
| 214 | - { |
|
| 215 | - $this->orderQuery = $getVars['o']; |
|
| 216 | - // TODO |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - protected function curOrderQuery() |
|
| 221 | - { |
|
| 222 | - if ($this->orderQuery == '') return ''; |
|
| 223 | - return 'o='.$this->orderQuery; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /***************** Paging and counting *********/ |
|
| 227 | - public function countQuery() |
|
| 228 | - { |
|
| 229 | - $this->query = $this->dbConn->select(); |
|
| 230 | - $this->query = $this->query |
|
| 231 | - ->from( |
|
| 232 | - $this->table, |
|
| 233 | - array('COUNT(*)') |
|
| 234 | - ); |
|
| 235 | - $this->applyFilter(); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - public function count() |
|
| 239 | - { |
|
| 240 | - $this->countQuery(); |
|
| 241 | - return $this->dbConn->fetchOne($this->query); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - public function setMaxPerPage(int $max) |
|
| 245 | - { |
|
| 246 | - $this->maxPerPage = $max; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - protected function getPagingQuery(array $getVars) |
|
| 250 | - { |
|
| 251 | - if (isset($getVars['page'])) |
|
| 252 | - { |
|
| 253 | - $this->currentPage = $getVars['page']; |
|
| 254 | - } |
|
| 255 | - } |
|
| 202 | + return $this; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + public function setOrder(array $order) |
|
| 206 | + { |
|
| 207 | + $this->order = $order; |
|
| 208 | + return $this; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + public function getOrderQuery(array $getVars) |
|
| 212 | + { |
|
| 213 | + if (isset($getVars['o'])) |
|
| 214 | + { |
|
| 215 | + $this->orderQuery = $getVars['o']; |
|
| 216 | + // TODO |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + protected function curOrderQuery() |
|
| 221 | + { |
|
| 222 | + if ($this->orderQuery == '') return ''; |
|
| 223 | + return 'o='.$this->orderQuery; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /***************** Paging and counting *********/ |
|
| 227 | + public function countQuery() |
|
| 228 | + { |
|
| 229 | + $this->query = $this->dbConn->select(); |
|
| 230 | + $this->query = $this->query |
|
| 231 | + ->from( |
|
| 232 | + $this->table, |
|
| 233 | + array('COUNT(*)') |
|
| 234 | + ); |
|
| 235 | + $this->applyFilter(); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + public function count() |
|
| 239 | + { |
|
| 240 | + $this->countQuery(); |
|
| 241 | + return $this->dbConn->fetchOne($this->query); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + public function setMaxPerPage(int $max) |
|
| 245 | + { |
|
| 246 | + $this->maxPerPage = $max; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + protected function getPagingQuery(array $getVars) |
|
| 250 | + { |
|
| 251 | + if (isset($getVars['page'])) |
|
| 252 | + { |
|
| 253 | + $this->currentPage = $getVars['page']; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - protected function curPagingQuery() |
|
| 258 | - { |
|
| 259 | - if ($this->currentPage == '') return ''; |
|
| 260 | - return 'page='.$this->currentPage; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - public function renderPagingHeader() |
|
| 264 | - { |
|
| 265 | - $count = $this->count(); |
|
| 266 | - if ($count <= $this->maxPerPage ) |
|
| 267 | - { |
|
| 268 | - return 'count : ' . $this->count() . '<br>'; |
|
| 269 | - } |
|
| 257 | + protected function curPagingQuery() |
|
| 258 | + { |
|
| 259 | + if ($this->currentPage == '') return ''; |
|
| 260 | + return 'page='.$this->currentPage; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + public function renderPagingHeader() |
|
| 264 | + { |
|
| 265 | + $count = $this->count(); |
|
| 266 | + if ($count <= $this->maxPerPage ) |
|
| 267 | + { |
|
| 268 | + return 'count : ' . $this->count() . '<br>'; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
| 271 | + if ($this->currentPage == 0) $this->currentPage = 1; |
|
| 272 | 272 | |
| 273 | - $numPages = intdiv($count , $this->maxPerPage); |
|
| 274 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
| 273 | + $numPages = intdiv($count , $this->maxPerPage); |
|
| 274 | + if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
| 275 | 275 | |
| 276 | - $html = '<div class="pagination-control" role="navigation">'; |
|
| 277 | - $html .= '<ul class="nav tab-nav">'; |
|
| 278 | - if ($this->currentPage <=1) |
|
| 279 | - { |
|
| 280 | - $html .= ' |
|
| 276 | + $html = '<div class="pagination-control" role="navigation">'; |
|
| 277 | + $html .= '<ul class="nav tab-nav">'; |
|
| 278 | + if ($this->currentPage <=1) |
|
| 279 | + { |
|
| 280 | + $html .= ' |
|
| 281 | 281 | <li class="nav-item disabled" aria-hidden="true"> |
| 282 | 282 | <span class="previous-page"> |
| 283 | 283 | <span class="sr-only">Previous page</span> |
@@ -285,35 +285,35 @@ discard block |
||
| 285 | 285 | </span> |
| 286 | 286 | </li> |
| 287 | 287 | '; |
| 288 | - } |
|
| 289 | - else |
|
| 290 | - { |
|
| 291 | - $html .= ' |
|
| 288 | + } |
|
| 289 | + else |
|
| 290 | + { |
|
| 291 | + $html .= ' |
|
| 292 | 292 | <li class="nav-item"> |
| 293 | 293 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
| 294 | 294 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
| 295 | 295 | </a> |
| 296 | 296 | </li> |
| 297 | 297 | '; |
| 298 | - } |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - for ($i=1; $i <= $numPages ; $i++) |
|
| 301 | - { |
|
| 302 | - $active = ($this->currentPage == $i) ? 'active' : ''; |
|
| 303 | - $first = ($i-1)*$this->maxPerPage+1; |
|
| 304 | - $last = $i * $this->maxPerPage; |
|
| 305 | - if ($last > $count) $last = $count; |
|
| 306 | - $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
| 307 | - $html .= '<li class="' . $active . ' nav-item"> |
|
| 300 | + for ($i=1; $i <= $numPages ; $i++) |
|
| 301 | + { |
|
| 302 | + $active = ($this->currentPage == $i) ? 'active' : ''; |
|
| 303 | + $first = ($i-1)*$this->maxPerPage+1; |
|
| 304 | + $last = $i * $this->maxPerPage; |
|
| 305 | + if ($last > $count) $last = $count; |
|
| 306 | + $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
| 307 | + $html .= '<li class="' . $active . ' nav-item"> |
|
| 308 | 308 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
| 309 | 309 | '.$i.' |
| 310 | 310 | </a> |
| 311 | 311 | </li>'; |
| 312 | - } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - if ($this->currentPage == $numPages) |
|
| 315 | - { |
|
| 316 | - $html .= ' |
|
| 314 | + if ($this->currentPage == $numPages) |
|
| 315 | + { |
|
| 316 | + $html .= ' |
|
| 317 | 317 | <li class="nav-item disabled" aria-hidden="true"> |
| 318 | 318 | <span class="previous-page"> |
| 319 | 319 | <span class="sr-only">Previous page</span> |
@@ -321,21 +321,21 @@ discard block |
||
| 321 | 321 | </span> |
| 322 | 322 | </li> |
| 323 | 323 | '; |
| 324 | - } |
|
| 325 | - else |
|
| 326 | - { |
|
| 327 | - $html .= ' |
|
| 324 | + } |
|
| 325 | + else |
|
| 326 | + { |
|
| 327 | + $html .= ' |
|
| 328 | 328 | <li class="nav-item"> |
| 329 | 329 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
| 330 | 330 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
| 331 | 331 | </a> |
| 332 | 332 | </li> |
| 333 | 333 | '; |
| 334 | - } |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - $html .= '</ul> </div>'; |
|
| 336 | + $html .= '</ul> </div>'; |
|
| 337 | 337 | |
| 338 | - $htmlOLD = ' |
|
| 338 | + $htmlOLD = ' |
|
| 339 | 339 | <ul class="nav tab-nav"> |
| 340 | 340 | |
| 341 | 341 | <li class="active nav-item"> |
@@ -355,68 +355,68 @@ discard block |
||
| 355 | 355 | </li> |
| 356 | 356 | </ul> |
| 357 | 357 | '; |
| 358 | - return $html; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - public function applyPaging() |
|
| 362 | - { |
|
| 363 | - $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
| 364 | - return $this; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /*************** Rendering *************************/ |
|
| 368 | - public function renderTitles() |
|
| 369 | - { |
|
| 370 | - $html = "<thead>\n<tr>\n"; |
|
| 371 | - foreach ($this->titles as $values) |
|
| 372 | - { |
|
| 373 | - $html .= '<th>' . $values . '</th>'; |
|
| 374 | - } |
|
| 375 | - $html .= "</tr>\n</thead>\n"; |
|
| 376 | - return $html; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - public function renderLine( $value) |
|
| 380 | - { |
|
| 381 | - $html = ''; |
|
| 382 | - $titleNames = array_keys($this->titles); |
|
| 383 | - foreach ($titleNames as $name ) |
|
| 384 | - { |
|
| 385 | - $html .= '<td>'; |
|
| 386 | - $html .= $value->$name; |
|
| 387 | - $html .= "</td>\n"; |
|
| 388 | - } |
|
| 389 | - return $html; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - public function renderTable(array $values) |
|
| 393 | - { |
|
| 394 | - $html = '<tbody id="obj_table_body">'; |
|
| 395 | - foreach($values as $value) |
|
| 396 | - { |
|
| 397 | - $html .= "<tr>\n"; |
|
| 398 | - $html .= $this->renderLine($value); |
|
| 399 | - $html .= "</tr>\n"; |
|
| 400 | - } |
|
| 401 | - $html .= '</tbody>'; |
|
| 402 | - return $html; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - public function render() |
|
| 406 | - { |
|
| 407 | - $html = ''; |
|
| 358 | + return $html; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + public function applyPaging() |
|
| 362 | + { |
|
| 363 | + $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
| 364 | + return $this; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /*************** Rendering *************************/ |
|
| 368 | + public function renderTitles() |
|
| 369 | + { |
|
| 370 | + $html = "<thead>\n<tr>\n"; |
|
| 371 | + foreach ($this->titles as $values) |
|
| 372 | + { |
|
| 373 | + $html .= '<th>' . $values . '</th>'; |
|
| 374 | + } |
|
| 375 | + $html .= "</tr>\n</thead>\n"; |
|
| 376 | + return $html; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + public function renderLine( $value) |
|
| 380 | + { |
|
| 381 | + $html = ''; |
|
| 382 | + $titleNames = array_keys($this->titles); |
|
| 383 | + foreach ($titleNames as $name ) |
|
| 384 | + { |
|
| 385 | + $html .= '<td>'; |
|
| 386 | + $html .= $value->$name; |
|
| 387 | + $html .= "</td>\n"; |
|
| 388 | + } |
|
| 389 | + return $html; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + public function renderTable(array $values) |
|
| 393 | + { |
|
| 394 | + $html = '<tbody id="obj_table_body">'; |
|
| 395 | + foreach($values as $value) |
|
| 396 | + { |
|
| 397 | + $html .= "<tr>\n"; |
|
| 398 | + $html .= $this->renderLine($value); |
|
| 399 | + $html .= "</tr>\n"; |
|
| 400 | + } |
|
| 401 | + $html .= '</tbody>'; |
|
| 402 | + return $html; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + public function render() |
|
| 406 | + { |
|
| 407 | + $html = ''; |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | - $values = $this->fullQuery(); |
|
| 410 | + $values = $this->fullQuery(); |
|
| 411 | 411 | |
| 412 | - $html.="<table class='simple common-table table-row-selectable'>\n"; |
|
| 412 | + $html.="<table class='simple common-table table-row-selectable'>\n"; |
|
| 413 | 413 | |
| 414 | - $html .= $this->renderTitles(); |
|
| 415 | - $html .= $this->renderTable($values); |
|
| 416 | - $html .= '</table>'; |
|
| 414 | + $html .= $this->renderTitles(); |
|
| 415 | + $html .= $this->renderTable($values); |
|
| 416 | + $html .= '</table>'; |
|
| 417 | 417 | |
| 418 | 418 | |
| 419 | - return $html; |
|
| 420 | - } |
|
| 419 | + return $html; |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | 422 | } |
| 423 | 423 | \ No newline at end of file |
@@ -10,16 +10,16 @@ discard block |
||
| 10 | 10 | abstract class TrapDirectorTable |
| 11 | 11 | { |
| 12 | 12 | /** @var array $titles table titles (name, display value) */ |
| 13 | - protected $titles = null; |
|
| 13 | + protected $titles=null; |
|
| 14 | 14 | |
| 15 | 15 | /** @var array $content table content (name, sb column name). name index must be the same as $titles*/ |
| 16 | - protected $content = null; |
|
| 16 | + protected $content=null; |
|
| 17 | 17 | |
| 18 | 18 | /** @var array $columnNames names of columns for filtering */ |
| 19 | - protected $columnNames = array(); |
|
| 19 | + protected $columnNames=array(); |
|
| 20 | 20 | |
| 21 | 21 | /** @var Selectable $dbConn connection to database */ |
| 22 | - protected $dbConn = null; |
|
| 22 | + protected $dbConn=null; |
|
| 23 | 23 | |
| 24 | 24 | /** Current view **/ |
| 25 | 25 | protected $view; |
@@ -28,39 +28,39 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | // Database stuff |
| 30 | 30 | /** @var array $table (db ref, name) */ |
| 31 | - protected $table = array(); |
|
| 31 | + protected $table=array(); |
|
| 32 | 32 | |
| 33 | 33 | /** @var Queryable $query Query in database; */ |
| 34 | - protected $query = null; |
|
| 34 | + protected $query=null; |
|
| 35 | 35 | |
| 36 | 36 | /** @var array $order : (db column, 'ASC' | 'DESC') */ |
| 37 | - protected $order = array(); |
|
| 38 | - protected $orderQuery = ''; |
|
| 37 | + protected $order=array(); |
|
| 38 | + protected $orderQuery=''; |
|
| 39 | 39 | |
| 40 | 40 | /********* Filter ********/ |
| 41 | 41 | /** @var string $filterString : string filter for db columns */ |
| 42 | - protected $filterString = ''; |
|
| 42 | + protected $filterString=''; |
|
| 43 | 43 | |
| 44 | 44 | /** @var array $filterColumn : columns to apply filter to */ |
| 45 | - protected $filterColumn = array(); |
|
| 45 | + protected $filterColumn=array(); |
|
| 46 | 46 | |
| 47 | 47 | protected $filterQuery=''; |
| 48 | 48 | |
| 49 | 49 | /*************** Paging *************/ |
| 50 | - protected $maxPerPage = 25; |
|
| 50 | + protected $maxPerPage=25; |
|
| 51 | 51 | |
| 52 | - protected $currentPage = 0; |
|
| 52 | + protected $currentPage=0; |
|
| 53 | 53 | |
| 54 | - function __construct(array $table,array $titles, array $columns, array $columnNames, $dbConn , $view, $urlPath) |
|
| 54 | + function __construct(array $table, array $titles, array $columns, array $columnNames, $dbConn, $view, $urlPath) |
|
| 55 | 55 | { |
| 56 | - $this->table = $table; |
|
| 57 | - $this->titles = $titles; |
|
| 58 | - $this->content = $columns; |
|
| 59 | - $this->columnNames = $columnNames; |
|
| 60 | - $this->dbConn = $dbConn; |
|
| 56 | + $this->table=$table; |
|
| 57 | + $this->titles=$titles; |
|
| 58 | + $this->content=$columns; |
|
| 59 | + $this->columnNames=$columnNames; |
|
| 60 | + $this->dbConn=$dbConn; |
|
| 61 | 61 | |
| 62 | - $this->view = $view; |
|
| 63 | - $this->urlPath = $urlPath; |
|
| 62 | + $this->view=$view; |
|
| 63 | + $this->urlPath=$urlPath; |
|
| 64 | 64 | |
| 65 | 65 | return $this; |
| 66 | 66 | } |
@@ -80,19 +80,19 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | protected function getCurrentURLAndQS(string $caller) |
| 82 | 82 | { |
| 83 | - $actionURL = $this->getCurrentURL() . '?' ; |
|
| 83 | + $actionURL=$this->getCurrentURL().'?'; |
|
| 84 | 84 | $QSList=array(); |
| 85 | 85 | if ($caller != 'filter' && $this->curFilterQuery() != '') |
| 86 | - array_push($QSList , $this->curFilterQuery()); |
|
| 86 | + array_push($QSList, $this->curFilterQuery()); |
|
| 87 | 87 | |
| 88 | 88 | if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
| 89 | - array_push($QSList , $this->curPagingQuery()); |
|
| 89 | + array_push($QSList, $this->curPagingQuery()); |
|
| 90 | 90 | |
| 91 | 91 | if ($caller != 'order' && $this->curOrderQuery() != '') |
| 92 | - array_push($QSList , $this->curOrderQuery()); |
|
| 92 | + array_push($QSList, $this->curOrderQuery()); |
|
| 93 | 93 | |
| 94 | 94 | if (count($QSList) != 0) |
| 95 | - $actionURL .= implode('&', $QSList); |
|
| 95 | + $actionURL.=implode('&', $QSList); |
|
| 96 | 96 | |
| 97 | 97 | return $actionURL; |
| 98 | 98 | } |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function getBaseQuery() |
| 106 | 106 | { |
| 107 | - $this->query = $this->dbConn->select(); |
|
| 108 | - $this->query = $this->query->from( |
|
| 107 | + $this->query=$this->dbConn->select(); |
|
| 108 | + $this->query=$this->query->from( |
|
| 109 | 109 | $this->table, |
| 110 | 110 | $this->content |
| 111 | 111 | ); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | { |
| 138 | 138 | if ($filter != "") $filter.=' OR '; |
| 139 | 139 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
| 140 | - $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
|
| 140 | + $filter.=$column." LIKE '%".$this->filterString."%'"; |
|
| 141 | 141 | } |
| 142 | 142 | //echo $filter; |
| 143 | 143 | |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | public function setFilter(string $filter, array $filterCol) |
| 150 | 150 | { |
| 151 | - $this->filterString = $filter; |
|
| 152 | - $this->filterColumn = $filterCol; |
|
| 151 | + $this->filterString=$filter; |
|
| 152 | + $this->filterColumn=$filterCol; |
|
| 153 | 153 | return $this; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | { |
| 173 | 173 | if (isset($getVars['f'])) |
| 174 | 174 | { |
| 175 | - $this->filterQuery = $getVars['f']; |
|
| 175 | + $this->filterQuery=$getVars['f']; |
|
| 176 | 176 | $this->setFilter(html_entity_decode($getVars['f']), $this->columnNames); |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -195,16 +195,16 @@ discard block |
||
| 195 | 195 | { |
| 196 | 196 | if ($orderSQL != "") $orderSQL.=','; |
| 197 | 197 | |
| 198 | - $orderSQL .= $column . ' ' . $direction; |
|
| 198 | + $orderSQL.=$column.' '.$direction; |
|
| 199 | 199 | } |
| 200 | - $this->query = $this->query->order($orderSQL); |
|
| 200 | + $this->query=$this->query->order($orderSQL); |
|
| 201 | 201 | |
| 202 | 202 | return $this; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | public function setOrder(array $order) |
| 206 | 206 | { |
| 207 | - $this->order = $order; |
|
| 207 | + $this->order=$order; |
|
| 208 | 208 | return $this; |
| 209 | 209 | } |
| 210 | 210 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | if (isset($getVars['o'])) |
| 214 | 214 | { |
| 215 | - $this->orderQuery = $getVars['o']; |
|
| 215 | + $this->orderQuery=$getVars['o']; |
|
| 216 | 216 | // TODO |
| 217 | 217 | } |
| 218 | 218 | } |
@@ -226,8 +226,8 @@ discard block |
||
| 226 | 226 | /***************** Paging and counting *********/ |
| 227 | 227 | public function countQuery() |
| 228 | 228 | { |
| 229 | - $this->query = $this->dbConn->select(); |
|
| 230 | - $this->query = $this->query |
|
| 229 | + $this->query=$this->dbConn->select(); |
|
| 230 | + $this->query=$this->query |
|
| 231 | 231 | ->from( |
| 232 | 232 | $this->table, |
| 233 | 233 | array('COUNT(*)') |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | public function setMaxPerPage(int $max) |
| 245 | 245 | { |
| 246 | - $this->maxPerPage = $max; |
|
| 246 | + $this->maxPerPage=$max; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | protected function getPagingQuery(array $getVars) |
| 250 | 250 | { |
| 251 | 251 | if (isset($getVars['page'])) |
| 252 | 252 | { |
| 253 | - $this->currentPage = $getVars['page']; |
|
| 253 | + $this->currentPage=$getVars['page']; |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -262,22 +262,22 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | public function renderPagingHeader() |
| 264 | 264 | { |
| 265 | - $count = $this->count(); |
|
| 266 | - if ($count <= $this->maxPerPage ) |
|
| 265 | + $count=$this->count(); |
|
| 266 | + if ($count <= $this->maxPerPage) |
|
| 267 | 267 | { |
| 268 | - return 'count : ' . $this->count() . '<br>'; |
|
| 268 | + return 'count : '.$this->count().'<br>'; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
| 271 | + if ($this->currentPage == 0) $this->currentPage=1; |
|
| 272 | 272 | |
| 273 | - $numPages = intdiv($count , $this->maxPerPage); |
|
| 274 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
| 273 | + $numPages=intdiv($count, $this->maxPerPage); |
|
| 274 | + if ($count % $this->maxPerPage != 0) $numPages++; |
|
| 275 | 275 | |
| 276 | - $html = '<div class="pagination-control" role="navigation">'; |
|
| 277 | - $html .= '<ul class="nav tab-nav">'; |
|
| 278 | - if ($this->currentPage <=1) |
|
| 276 | + $html='<div class="pagination-control" role="navigation">'; |
|
| 277 | + $html.='<ul class="nav tab-nav">'; |
|
| 278 | + if ($this->currentPage <= 1) |
|
| 279 | 279 | { |
| 280 | - $html .= ' |
|
| 280 | + $html.=' |
|
| 281 | 281 | <li class="nav-item disabled" aria-hidden="true"> |
| 282 | 282 | <span class="previous-page"> |
| 283 | 283 | <span class="sr-only">Previous page</span> |
@@ -288,24 +288,24 @@ discard block |
||
| 288 | 288 | } |
| 289 | 289 | else |
| 290 | 290 | { |
| 291 | - $html .= ' |
|
| 291 | + $html.=' |
|
| 292 | 292 | <li class="nav-item"> |
| 293 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage - 1 ).'" class="previous-page" > |
|
| 293 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage - 1).'" class="previous-page" > |
|
| 294 | 294 | <i aria-hidden="true" class="icon-angle-double-left"></i> |
| 295 | 295 | </a> |
| 296 | 296 | </li> |
| 297 | 297 | '; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - for ($i=1; $i <= $numPages ; $i++) |
|
| 300 | + for ($i=1; $i <= $numPages; $i++) |
|
| 301 | 301 | { |
| 302 | - $active = ($this->currentPage == $i) ? 'active' : ''; |
|
| 303 | - $first = ($i-1)*$this->maxPerPage+1; |
|
| 304 | - $last = $i * $this->maxPerPage; |
|
| 305 | - if ($last > $count) $last = $count; |
|
| 306 | - $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
|
| 307 | - $html .= '<li class="' . $active . ' nav-item"> |
|
| 308 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
|
| 302 | + $active=($this->currentPage == $i) ? 'active' : ''; |
|
| 303 | + $first=($i - 1) * $this->maxPerPage + 1; |
|
| 304 | + $last=$i * $this->maxPerPage; |
|
| 305 | + if ($last > $count) $last=$count; |
|
| 306 | + $display='Show rows '.$first.' to '.$last.' of '.$count; |
|
| 307 | + $html.='<li class="'.$active.' nav-item"> |
|
| 308 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.$i.'" title="'.$display.'" aria-label="'.$display.'"> |
|
| 309 | 309 | '.$i.' |
| 310 | 310 | </a> |
| 311 | 311 | </li>'; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | if ($this->currentPage == $numPages) |
| 315 | 315 | { |
| 316 | - $html .= ' |
|
| 316 | + $html.=' |
|
| 317 | 317 | <li class="nav-item disabled" aria-hidden="true"> |
| 318 | 318 | <span class="previous-page"> |
| 319 | 319 | <span class="sr-only">Previous page</span> |
@@ -324,18 +324,18 @@ discard block |
||
| 324 | 324 | } |
| 325 | 325 | else |
| 326 | 326 | { |
| 327 | - $html .= ' |
|
| 327 | + $html.=' |
|
| 328 | 328 | <li class="nav-item"> |
| 329 | - <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. ($this->currentPage + 1 ).'" class="next-page"> |
|
| 329 | + <a href="'. $this->getCurrentURLAndQS('paging').'&page='.($this->currentPage + 1).'" class="next-page"> |
|
| 330 | 330 | <i aria-hidden="true" class="icon-angle-double-right"></i> |
| 331 | 331 | </a> |
| 332 | 332 | </li> |
| 333 | 333 | '; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - $html .= '</ul> </div>'; |
|
| 336 | + $html.='</ul> </div>'; |
|
| 337 | 337 | |
| 338 | - $htmlOLD = ' |
|
| 338 | + $htmlOLD=' |
|
| 339 | 339 | <ul class="nav tab-nav"> |
| 340 | 340 | |
| 341 | 341 | <li class="active nav-item"> |
@@ -360,60 +360,60 @@ discard block |
||
| 360 | 360 | |
| 361 | 361 | public function applyPaging() |
| 362 | 362 | { |
| 363 | - $this->query->limitPage($this->currentPage,$this->maxPerPage); |
|
| 363 | + $this->query->limitPage($this->currentPage, $this->maxPerPage); |
|
| 364 | 364 | return $this; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /*************** Rendering *************************/ |
| 368 | 368 | public function renderTitles() |
| 369 | 369 | { |
| 370 | - $html = "<thead>\n<tr>\n"; |
|
| 370 | + $html="<thead>\n<tr>\n"; |
|
| 371 | 371 | foreach ($this->titles as $values) |
| 372 | 372 | { |
| 373 | - $html .= '<th>' . $values . '</th>'; |
|
| 373 | + $html.='<th>'.$values.'</th>'; |
|
| 374 | 374 | } |
| 375 | - $html .= "</tr>\n</thead>\n"; |
|
| 375 | + $html.="</tr>\n</thead>\n"; |
|
| 376 | 376 | return $html; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - public function renderLine( $value) |
|
| 379 | + public function renderLine($value) |
|
| 380 | 380 | { |
| 381 | - $html = ''; |
|
| 382 | - $titleNames = array_keys($this->titles); |
|
| 383 | - foreach ($titleNames as $name ) |
|
| 381 | + $html=''; |
|
| 382 | + $titleNames=array_keys($this->titles); |
|
| 383 | + foreach ($titleNames as $name) |
|
| 384 | 384 | { |
| 385 | - $html .= '<td>'; |
|
| 386 | - $html .= $value->$name; |
|
| 387 | - $html .= "</td>\n"; |
|
| 385 | + $html.='<td>'; |
|
| 386 | + $html.=$value->$name; |
|
| 387 | + $html.="</td>\n"; |
|
| 388 | 388 | } |
| 389 | 389 | return $html; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | public function renderTable(array $values) |
| 393 | 393 | { |
| 394 | - $html = '<tbody id="obj_table_body">'; |
|
| 395 | - foreach($values as $value) |
|
| 394 | + $html='<tbody id="obj_table_body">'; |
|
| 395 | + foreach ($values as $value) |
|
| 396 | 396 | { |
| 397 | - $html .= "<tr>\n"; |
|
| 398 | - $html .= $this->renderLine($value); |
|
| 399 | - $html .= "</tr>\n"; |
|
| 397 | + $html.="<tr>\n"; |
|
| 398 | + $html.=$this->renderLine($value); |
|
| 399 | + $html.="</tr>\n"; |
|
| 400 | 400 | } |
| 401 | - $html .= '</tbody>'; |
|
| 401 | + $html.='</tbody>'; |
|
| 402 | 402 | return $html; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | public function render() |
| 406 | 406 | { |
| 407 | - $html = ''; |
|
| 407 | + $html=''; |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | - $values = $this->fullQuery(); |
|
| 410 | + $values=$this->fullQuery(); |
|
| 411 | 411 | |
| 412 | 412 | $html.="<table class='simple common-table table-row-selectable'>\n"; |
| 413 | 413 | |
| 414 | - $html .= $this->renderTitles(); |
|
| 415 | - $html .= $this->renderTable($values); |
|
| 416 | - $html .= '</table>'; |
|
| 414 | + $html.=$this->renderTitles(); |
|
| 415 | + $html.=$this->renderTable($values); |
|
| 416 | + $html.='</table>'; |
|
| 417 | 417 | |
| 418 | 418 | |
| 419 | 419 | return $html; |
@@ -82,17 +82,21 @@ discard block |
||
| 82 | 82 | { |
| 83 | 83 | $actionURL = $this->getCurrentURL() . '?' ; |
| 84 | 84 | $QSList=array(); |
| 85 | - if ($caller != 'filter' && $this->curFilterQuery() != '') |
|
| 86 | - array_push($QSList , $this->curFilterQuery()); |
|
| 85 | + if ($caller != 'filter' && $this->curFilterQuery() != '') { |
|
| 86 | + array_push($QSList , $this->curFilterQuery()); |
|
| 87 | + } |
|
| 87 | 88 | |
| 88 | - if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') |
|
| 89 | - array_push($QSList , $this->curPagingQuery()); |
|
| 89 | + if ($caller != 'paging' && $caller != 'filter' && $this->curPagingQuery() != '') { |
|
| 90 | + array_push($QSList , $this->curPagingQuery()); |
|
| 91 | + } |
|
| 90 | 92 | |
| 91 | - if ($caller != 'order' && $this->curOrderQuery() != '') |
|
| 92 | - array_push($QSList , $this->curOrderQuery()); |
|
| 93 | + if ($caller != 'order' && $this->curOrderQuery() != '') { |
|
| 94 | + array_push($QSList , $this->curOrderQuery()); |
|
| 95 | + } |
|
| 93 | 96 | |
| 94 | - if (count($QSList) != 0) |
|
| 95 | - $actionURL .= implode('&', $QSList); |
|
| 97 | + if (count($QSList) != 0) { |
|
| 98 | + $actionURL .= implode('&', $QSList); |
|
| 99 | + } |
|
| 96 | 100 | |
| 97 | 101 | return $actionURL; |
| 98 | 102 | } |
@@ -135,7 +139,9 @@ discard block |
||
| 135 | 139 | $filter=''; |
| 136 | 140 | foreach ($this->filterColumn as $column) |
| 137 | 141 | { |
| 138 | - if ($filter != "") $filter.=' OR '; |
|
| 142 | + if ($filter != "") { |
|
| 143 | + $filter.=' OR '; |
|
| 144 | + } |
|
| 139 | 145 | //$filter .= "'" . $column . "' LIKE '%" . $this->filterString. "%'"; |
| 140 | 146 | $filter .= $column . " LIKE '%" . $this->filterString. "%'"; |
| 141 | 147 | } |
@@ -179,7 +185,9 @@ discard block |
||
| 179 | 185 | |
| 180 | 186 | protected function curFilterQuery() |
| 181 | 187 | { |
| 182 | - if ($this->filterQuery == '') return ''; |
|
| 188 | + if ($this->filterQuery == '') { |
|
| 189 | + return ''; |
|
| 190 | + } |
|
| 183 | 191 | return 'f='.$this->filterQuery; |
| 184 | 192 | } |
| 185 | 193 | |
@@ -193,7 +201,9 @@ discard block |
||
| 193 | 201 | $orderSQL=''; |
| 194 | 202 | foreach ($this->order as $column => $direction) |
| 195 | 203 | { |
| 196 | - if ($orderSQL != "") $orderSQL.=','; |
|
| 204 | + if ($orderSQL != "") { |
|
| 205 | + $orderSQL.=','; |
|
| 206 | + } |
|
| 197 | 207 | |
| 198 | 208 | $orderSQL .= $column . ' ' . $direction; |
| 199 | 209 | } |
@@ -219,7 +229,9 @@ discard block |
||
| 219 | 229 | |
| 220 | 230 | protected function curOrderQuery() |
| 221 | 231 | { |
| 222 | - if ($this->orderQuery == '') return ''; |
|
| 232 | + if ($this->orderQuery == '') { |
|
| 233 | + return ''; |
|
| 234 | + } |
|
| 223 | 235 | return 'o='.$this->orderQuery; |
| 224 | 236 | } |
| 225 | 237 | |
@@ -256,7 +268,9 @@ discard block |
||
| 256 | 268 | |
| 257 | 269 | protected function curPagingQuery() |
| 258 | 270 | { |
| 259 | - if ($this->currentPage == '') return ''; |
|
| 271 | + if ($this->currentPage == '') { |
|
| 272 | + return ''; |
|
| 273 | + } |
|
| 260 | 274 | return 'page='.$this->currentPage; |
| 261 | 275 | } |
| 262 | 276 | |
@@ -268,10 +282,14 @@ discard block |
||
| 268 | 282 | return 'count : ' . $this->count() . '<br>'; |
| 269 | 283 | } |
| 270 | 284 | |
| 271 | - if ($this->currentPage == 0) $this->currentPage = 1; |
|
| 285 | + if ($this->currentPage == 0) { |
|
| 286 | + $this->currentPage = 1; |
|
| 287 | + } |
|
| 272 | 288 | |
| 273 | 289 | $numPages = intdiv($count , $this->maxPerPage); |
| 274 | - if ($count % $this->maxPerPage != 0 ) $numPages++; |
|
| 290 | + if ($count % $this->maxPerPage != 0 ) { |
|
| 291 | + $numPages++; |
|
| 292 | + } |
|
| 275 | 293 | |
| 276 | 294 | $html = '<div class="pagination-control" role="navigation">'; |
| 277 | 295 | $html .= '<ul class="nav tab-nav">'; |
@@ -285,8 +303,7 @@ discard block |
||
| 285 | 303 | </span> |
| 286 | 304 | </li> |
| 287 | 305 | '; |
| 288 | - } |
|
| 289 | - else |
|
| 306 | + } else |
|
| 290 | 307 | { |
| 291 | 308 | $html .= ' |
| 292 | 309 | <li class="nav-item"> |
@@ -302,7 +319,9 @@ discard block |
||
| 302 | 319 | $active = ($this->currentPage == $i) ? 'active' : ''; |
| 303 | 320 | $first = ($i-1)*$this->maxPerPage+1; |
| 304 | 321 | $last = $i * $this->maxPerPage; |
| 305 | - if ($last > $count) $last = $count; |
|
| 322 | + if ($last > $count) { |
|
| 323 | + $last = $count; |
|
| 324 | + } |
|
| 306 | 325 | $display = 'Show rows '. $first . ' to '. $last .' of '. $count; |
| 307 | 326 | $html .= '<li class="' . $active . ' nav-item"> |
| 308 | 327 | <a href="'. $this->getCurrentURLAndQS('paging') .'&page='. $i .'" title="' . $display . '" aria-label="' . $display . '"> |
@@ -321,8 +340,7 @@ discard block |
||
| 321 | 340 | </span> |
| 322 | 341 | </li> |
| 323 | 342 | '; |
| 324 | - } |
|
| 325 | - else |
|
| 343 | + } else |
|
| 326 | 344 | { |
| 327 | 345 | $html .= ' |
| 328 | 346 | <li class="nav-item"> |
@@ -4,16 +4,16 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class TrapModuleConfig |
| 6 | 6 | { |
| 7 | - /********** Database configuration ***********************/ |
|
| 7 | + /********** Database configuration ***********************/ |
|
| 8 | 8 | // Database prefix for tables |
| 9 | - protected $table_prefix; //< Database prefix for tables |
|
| 9 | + protected $table_prefix; //< Database prefix for tables |
|
| 10 | 10 | protected $DBConfigDefaults=array( |
| 11 | 11 | 'db_remove_days' => 60, // number of days before removing traps |
| 12 | 12 | 'log_destination' => 'syslog', // Log destination for trap handler |
| 13 | 13 | 'log_file' => '/tmp/trapdirector.log', // Log file |
| 14 | 14 | 'log_level' => 2, // log level |
| 15 | 15 | 'use_SnmpTrapAddess' => 1, // use SnmpTrapAddress by default |
| 16 | - 'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
|
| 16 | + 'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
|
| 17 | 17 | ); |
| 18 | 18 | // get default values for dbconfig |
| 19 | 19 | public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
@@ -120,27 +120,27 @@ discard block |
||
| 120 | 120 | // Note : must have 'source_ip' and 'last_sent' |
| 121 | 121 | public function getTrapHostListDisplayColumns() |
| 122 | 122 | { |
| 123 | - return array( |
|
| 124 | - 'source_name' => 't.source_name', |
|
| 125 | - 'source_ip' => 't.source_ip', |
|
| 126 | - 'trap_oid' => 't.trap_oid', |
|
| 127 | - 'count' => 'count(*)', |
|
| 128 | - 'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
|
| 129 | - ); |
|
| 123 | + return array( |
|
| 124 | + 'source_name' => 't.source_name', |
|
| 125 | + 'source_ip' => 't.source_ip', |
|
| 126 | + 'trap_oid' => 't.trap_oid', |
|
| 127 | + 'count' => 'count(*)', |
|
| 128 | + 'last_sent' => 'UNIX_TIMESTAMP(max(t.date_received))' |
|
| 129 | + ); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | public function getTrapHostListSearchColumns() |
| 133 | 133 | { |
| 134 | - return array(); // No search needed on this table |
|
| 134 | + return array(); // No search needed on this table |
|
| 135 | 135 | } |
| 136 | 136 | // Titles display in Trap List table |
| 137 | 137 | public function getTrapHostListTitles() |
| 138 | 138 | { |
| 139 | - return array( |
|
| 140 | - 'trap_oid' => 'Trap OID', |
|
| 141 | - 'count' => 'Number of traps received', |
|
| 142 | - 'last_sent' => 'Last trap received' |
|
| 143 | - ); |
|
| 139 | + return array( |
|
| 140 | + 'trap_oid' => 'Trap OID', |
|
| 141 | + 'count' => 'Number of traps received', |
|
| 142 | + 'last_sent' => 'Last trap received' |
|
| 143 | + ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
@@ -179,17 +179,17 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | public function getHandlerColumns() |
| 181 | 181 | { |
| 182 | - return array( |
|
| 183 | - 'r.host_name', 'r.host_group_name', |
|
| 184 | - 'r.ip4', 'r.ip6', |
|
| 185 | - 'r.trap_oid', |
|
| 186 | - 'r.rule', |
|
| 187 | - 'r.action_match', |
|
| 188 | - 'r.action_nomatch', |
|
| 189 | - 'r.service_name', |
|
| 190 | - 'r.num_match', |
|
| 191 | - 'r.id' |
|
| 192 | - ); |
|
| 182 | + return array( |
|
| 183 | + 'r.host_name', 'r.host_group_name', |
|
| 184 | + 'r.ip4', 'r.ip6', |
|
| 185 | + 'r.trap_oid', |
|
| 186 | + 'r.rule', |
|
| 187 | + 'r.action_match', |
|
| 188 | + 'r.action_nomatch', |
|
| 189 | + 'r.service_name', |
|
| 190 | + 'r.num_match', |
|
| 191 | + 'r.id' |
|
| 192 | + ); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // handler update (<key> => <sql select>) |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | 'revert_ok' => 'r.revert_ok', |
| 210 | 210 | 'display' => 'r.display', |
| 211 | 211 | 'modified' => 'UNIX_TIMESTAMP(r.modified)', |
| 212 | - 'modifier' => 'r.modifier' |
|
| 212 | + 'modifier' => 'r.modifier' |
|
| 213 | 213 | ); |
| 214 | 214 | } |
| 215 | 215 | |
@@ -12,13 +12,12 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | //use Icinga\Web\Form as Form; |
| 14 | 14 | /** Rules management |
| 15 | - |
|
| 16 | -*/ |
|
| 15 | + */ |
|
| 17 | 16 | class HandlerController extends TrapsController |
| 18 | 17 | { |
| 19 | 18 | |
| 20 | 19 | /** index : list existing rules |
| 21 | - */ |
|
| 20 | + */ |
|
| 22 | 21 | public function indexAction() |
| 23 | 22 | { |
| 24 | 23 | $this->checkReadPermission(); |
@@ -28,13 +27,13 @@ discard block |
||
| 28 | 27 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 29 | 28 | |
| 30 | 29 | $this->view->handlerTable = new HandlerTable( |
| 31 | - $this->moduleConfig->getTrapRuleName(), |
|
| 32 | - $this->moduleConfig->getHandlerListTitles(), |
|
| 33 | - $this->moduleConfig->getHandlerListDisplayColumns(), |
|
| 34 | - $this->moduleConfig->getHandlerColumns(), |
|
| 35 | - $dbConn->getConnection(), |
|
| 36 | - $this->view, |
|
| 37 | - $this->moduleConfig->urlPath()); |
|
| 30 | + $this->moduleConfig->getTrapRuleName(), |
|
| 31 | + $this->moduleConfig->getHandlerListTitles(), |
|
| 32 | + $this->moduleConfig->getHandlerListDisplayColumns(), |
|
| 33 | + $this->moduleConfig->getHandlerColumns(), |
|
| 34 | + $dbConn->getConnection(), |
|
| 35 | + $this->view, |
|
| 36 | + $this->moduleConfig->urlPath()); |
|
| 38 | 37 | |
| 39 | 38 | $getVars = $this->getRequest()->getParams(); |
| 40 | 39 | $this->view->handlerTable->getParams($getVars); |
@@ -60,22 +59,22 @@ discard block |
||
| 60 | 59 | */ |
| 61 | 60 | public function testruleAction() |
| 62 | 61 | { |
| 63 | - $this->checkReadPermission(); |
|
| 64 | - $this->getTabs()->add('get',array( |
|
| 65 | - 'active' => true, |
|
| 66 | - 'label' => $this->translate('Test Rule'), |
|
| 67 | - 'url' => Url::fromRequest() |
|
| 68 | - )); |
|
| 62 | + $this->checkReadPermission(); |
|
| 63 | + $this->getTabs()->add('get',array( |
|
| 64 | + 'active' => true, |
|
| 65 | + 'label' => $this->translate('Test Rule'), |
|
| 66 | + 'url' => Url::fromRequest() |
|
| 67 | + )); |
|
| 69 | 68 | |
| 70 | 69 | |
| 71 | - if ($this->params->get('rule') !== null) |
|
| 72 | - { |
|
| 73 | - $this->view->rule= $this->params->get('rule'); |
|
| 74 | - } |
|
| 75 | - else |
|
| 76 | - { |
|
| 77 | - $this->view->rule=''; |
|
| 78 | - } |
|
| 70 | + if ($this->params->get('rule') !== null) |
|
| 71 | + { |
|
| 72 | + $this->view->rule= $this->params->get('rule'); |
|
| 73 | + } |
|
| 74 | + else |
|
| 75 | + { |
|
| 76 | + $this->view->rule=''; |
|
| 77 | + } |
|
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | /** |
@@ -83,31 +82,31 @@ discard block |
||
| 83 | 82 | */ |
| 84 | 83 | private function add_setup_vars() |
| 85 | 84 | { |
| 86 | - // variables to send to view |
|
| 87 | - $this->view->hostlist=array(); // host list to input datalist |
|
| 88 | - $this->view->hostname=''; // Host name in input text |
|
| 89 | - $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
| 90 | - $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
| 91 | - $this->view->mainoid=''; // Trap OID |
|
| 92 | - $this->view->mib=''; // Trap mib |
|
| 93 | - $this->view->name=''; // Trap name |
|
| 94 | - $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
| 95 | - $this->view->objectList=array(); // objects sent with trap |
|
| 96 | - $this->view->display=''; // Initial display |
|
| 97 | - $this->view->rule=''; // rule display |
|
| 98 | - $this->view->revertOK=''; // revert OK in seconds |
|
| 99 | - $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
| 100 | - $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
| 101 | - $this->view->setToUpdate=false; // set form as update form |
|
| 102 | - $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
| 103 | - $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
| 85 | + // variables to send to view |
|
| 86 | + $this->view->hostlist=array(); // host list to input datalist |
|
| 87 | + $this->view->hostname=''; // Host name in input text |
|
| 88 | + $this->view->serviceGet=false; // Set to true to get list of service if only one host set |
|
| 89 | + $this->view->serviceSet=null; // Select service in services select (must have serviceGet=true). |
|
| 90 | + $this->view->mainoid=''; // Trap OID |
|
| 91 | + $this->view->mib=''; // Trap mib |
|
| 92 | + $this->view->name=''; // Trap name |
|
| 93 | + $this->view->trapListForMIB=array(); // Trap list if mib exists for trap |
|
| 94 | + $this->view->objectList=array(); // objects sent with trap |
|
| 95 | + $this->view->display=''; // Initial display |
|
| 96 | + $this->view->rule=''; // rule display |
|
| 97 | + $this->view->revertOK=''; // revert OK in seconds |
|
| 98 | + $this->view->hostid=-1; // normally set by javascript serviceGet() |
|
| 99 | + $this->view->ruleid=-1; // Rule id in DB for update & delete |
|
| 100 | + $this->view->setToUpdate=false; // set form as update form |
|
| 101 | + $this->view->setRuleMatch=-1; // set action on rule match (default nothing) |
|
| 102 | + $this->view->setRuleNoMatch=-1; // set action on rule no match (default nothing) |
|
| 104 | 103 | |
| 105 | - $this->view->selectGroup=false; // Select by group if true |
|
| 106 | - $this->view->hostgroupid=-1; // host group id |
|
| 107 | - $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
| 104 | + $this->view->selectGroup=false; // Select by group if true |
|
| 105 | + $this->view->hostgroupid=-1; // host group id |
|
| 106 | + $this->view->serviceGroupGet=false; // Get list of service for group (set serviceSet to select one) |
|
| 108 | 107 | |
| 109 | - $this->view->modifier=null; |
|
| 110 | - $this->view->modified=null; |
|
| 108 | + $this->view->modifier=null; |
|
| 109 | + $this->view->modified=null; |
|
| 111 | 110 | } |
| 112 | 111 | |
| 113 | 112 | /** |
@@ -116,102 +115,102 @@ discard block |
||
| 116 | 115 | */ |
| 117 | 116 | private function add_from_existing($trapid) |
| 118 | 117 | { |
| 119 | - /********** Setup from existing trap ***************/ |
|
| 120 | - // Get the full trap info |
|
| 121 | - $trapDetail=$this->getTrapDetail($trapid); |
|
| 118 | + /********** Setup from existing trap ***************/ |
|
| 119 | + // Get the full trap info |
|
| 120 | + $trapDetail=$this->getTrapDetail($trapid); |
|
| 122 | 121 | |
| 123 | - $hostfilter=$trapDetail->source_ip; |
|
| 122 | + $hostfilter=$trapDetail->source_ip; |
|
| 124 | 123 | |
| 125 | - // Get host |
|
| 126 | - try |
|
| 127 | - { |
|
| 128 | - $hosts=$this->getUIDatabase()->getHostByIP($hostfilter); |
|
| 129 | - } |
|
| 130 | - catch (Exception $e) |
|
| 131 | - { |
|
| 132 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 133 | - } |
|
| 124 | + // Get host |
|
| 125 | + try |
|
| 126 | + { |
|
| 127 | + $hosts=$this->getUIDatabase()->getHostByIP($hostfilter); |
|
| 128 | + } |
|
| 129 | + catch (Exception $e) |
|
| 130 | + { |
|
| 131 | + $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 132 | + } |
|
| 134 | 133 | |
| 135 | 134 | |
| 136 | - // if one unique host found -> put id text input |
|
| 137 | - if (count($hosts)==1) { |
|
| 138 | - $this->view->hostname=$hosts[0]->name; |
|
| 139 | - //$hostid=$hosts[0]->id; |
|
| 140 | - // Tell JS to get services when page is loaded |
|
| 141 | - $this->view->serviceGet=true; |
|
| 135 | + // if one unique host found -> put id text input |
|
| 136 | + if (count($hosts)==1) { |
|
| 137 | + $this->view->hostname=$hosts[0]->name; |
|
| 138 | + //$hostid=$hosts[0]->id; |
|
| 139 | + // Tell JS to get services when page is loaded |
|
| 140 | + $this->view->serviceGet=true; |
|
| 142 | 141 | |
| 143 | - } |
|
| 144 | - else |
|
| 145 | - { |
|
| 146 | - foreach($hosts as $key=>$val) |
|
| 147 | - { |
|
| 148 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 149 | - } |
|
| 150 | - } |
|
| 142 | + } |
|
| 143 | + else |
|
| 144 | + { |
|
| 145 | + foreach($hosts as $key=>$val) |
|
| 146 | + { |
|
| 147 | + array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 148 | + } |
|
| 149 | + } |
|
| 151 | 150 | |
| 152 | - // set up trap oid and objects received by the trap |
|
| 151 | + // set up trap oid and objects received by the trap |
|
| 153 | 152 | |
| 154 | - $this->view->mainoid=$trapDetail->trap_oid; |
|
| 155 | - if ($trapDetail->trap_name_mib != null) |
|
| 156 | - { |
|
| 157 | - $this->view->mib=$trapDetail->trap_name_mib; |
|
| 158 | - $this->view->name=$trapDetail->trap_name; |
|
| 159 | - $this->view->trapListForMIB=$this->getMIB() |
|
| 160 | - ->getTrapList($trapDetail->trap_name_mib); |
|
| 161 | - } |
|
| 153 | + $this->view->mainoid=$trapDetail->trap_oid; |
|
| 154 | + if ($trapDetail->trap_name_mib != null) |
|
| 155 | + { |
|
| 156 | + $this->view->mib=$trapDetail->trap_name_mib; |
|
| 157 | + $this->view->name=$trapDetail->trap_name; |
|
| 158 | + $this->view->trapListForMIB=$this->getMIB() |
|
| 159 | + ->getTrapList($trapDetail->trap_name_mib); |
|
| 160 | + } |
|
| 162 | 161 | |
| 163 | - // Get all objects that can be in trap from MIB |
|
| 164 | - $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
| 165 | - // Get all objects in current Trap |
|
| 166 | - $currentTrapObjects=$this->getTrapobjects($trapid); |
|
| 167 | - $oid_index=1; |
|
| 168 | - foreach ($currentTrapObjects as $key => $val) |
|
| 169 | - { |
|
| 170 | - $currentObjectType='Unknown'; |
|
| 171 | - $currentObjectTypeEnum='Unknown'; |
|
| 172 | - if (isset($allObjects[$val->oid]['type'])) |
|
| 173 | - { |
|
| 174 | - $currentObjectType=$allObjects[$val->oid]['type']; |
|
| 175 | - $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
| 176 | - } |
|
| 177 | - $currentObject=array( |
|
| 178 | - $oid_index, |
|
| 179 | - $val->oid, |
|
| 180 | - $val->oid_name_mib, |
|
| 181 | - $val->oid_name, |
|
| 182 | - $val->value, |
|
| 183 | - $currentObjectType, |
|
| 184 | - $currentObjectTypeEnum |
|
| 185 | - ); |
|
| 186 | - $oid_index++; |
|
| 187 | - array_push($this->view->objectList,$currentObject); |
|
| 188 | - // set currrent object to null in allObjects |
|
| 189 | - if (isset($allObjects[$val->oid])) |
|
| 190 | - { |
|
| 191 | - $allObjects[$val->oid]=null; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 195 | - { |
|
| 196 | - foreach ($allObjects as $key => $val) |
|
| 197 | - { |
|
| 198 | - if ($val==null) { continue; } |
|
| 199 | - array_push($this->view->objectList, array( |
|
| 200 | - $oid_index, |
|
| 201 | - $key, |
|
| 202 | - $allObjects[$key]['mib'], |
|
| 203 | - $allObjects[$key]['name'], |
|
| 204 | - '', |
|
| 205 | - $allObjects[$key]['type'], |
|
| 206 | - $allObjects[$key]['type_enum'] |
|
| 207 | - )); |
|
| 208 | - $oid_index++; |
|
| 209 | - } |
|
| 210 | - } |
|
| 162 | + // Get all objects that can be in trap from MIB |
|
| 163 | + $allObjects=$this->getMIB()->getObjectList($trapDetail->trap_oid); |
|
| 164 | + // Get all objects in current Trap |
|
| 165 | + $currentTrapObjects=$this->getTrapobjects($trapid); |
|
| 166 | + $oid_index=1; |
|
| 167 | + foreach ($currentTrapObjects as $key => $val) |
|
| 168 | + { |
|
| 169 | + $currentObjectType='Unknown'; |
|
| 170 | + $currentObjectTypeEnum='Unknown'; |
|
| 171 | + if (isset($allObjects[$val->oid]['type'])) |
|
| 172 | + { |
|
| 173 | + $currentObjectType=$allObjects[$val->oid]['type']; |
|
| 174 | + $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
|
| 175 | + } |
|
| 176 | + $currentObject=array( |
|
| 177 | + $oid_index, |
|
| 178 | + $val->oid, |
|
| 179 | + $val->oid_name_mib, |
|
| 180 | + $val->oid_name, |
|
| 181 | + $val->value, |
|
| 182 | + $currentObjectType, |
|
| 183 | + $currentObjectTypeEnum |
|
| 184 | + ); |
|
| 185 | + $oid_index++; |
|
| 186 | + array_push($this->view->objectList,$currentObject); |
|
| 187 | + // set currrent object to null in allObjects |
|
| 188 | + if (isset($allObjects[$val->oid])) |
|
| 189 | + { |
|
| 190 | + $allObjects[$val->oid]=null; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 194 | + { |
|
| 195 | + foreach ($allObjects as $key => $val) |
|
| 196 | + { |
|
| 197 | + if ($val==null) { continue; } |
|
| 198 | + array_push($this->view->objectList, array( |
|
| 199 | + $oid_index, |
|
| 200 | + $key, |
|
| 201 | + $allObjects[$key]['mib'], |
|
| 202 | + $allObjects[$key]['name'], |
|
| 203 | + '', |
|
| 204 | + $allObjects[$key]['type'], |
|
| 205 | + $allObjects[$key]['type_enum'] |
|
| 206 | + )); |
|
| 207 | + $oid_index++; |
|
| 208 | + } |
|
| 209 | + } |
|
| 211 | 210 | |
| 212 | - // Add a simple display |
|
| 213 | - $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
| 214 | - $this->view->create_basic_rule=true; |
|
| 211 | + // Add a simple display |
|
| 212 | + $this->view->display='Trap '.$trapDetail->trap_name.' received'; |
|
| 213 | + $this->view->create_basic_rule=true; |
|
| 215 | 214 | } |
| 216 | 215 | |
| 217 | 216 | /** |
@@ -220,29 +219,29 @@ discard block |
||
| 220 | 219 | */ |
| 221 | 220 | private function add_check_host_exists($ruleDetail) |
| 222 | 221 | { |
| 223 | - // Check if hostname still exists |
|
| 224 | - $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname); |
|
| 222 | + // Check if hostname still exists |
|
| 223 | + $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname); |
|
| 225 | 224 | |
| 226 | - if (count($host_get)==0) |
|
| 227 | - { |
|
| 228 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 229 | - $this->view->serviceGet=false; |
|
| 230 | - } |
|
| 231 | - else |
|
| 232 | - { |
|
| 233 | - // Tell JS to get services when page is loaded |
|
| 234 | - $this->view->serviceGet=true; |
|
| 235 | - // get service id for form to set : |
|
| 236 | - $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 237 | - if (count($serviceID) ==0) |
|
| 238 | - { |
|
| 239 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 240 | - } |
|
| 241 | - else |
|
| 242 | - { |
|
| 243 | - $this->view->serviceSet=$serviceID[0]->id; |
|
| 244 | - } |
|
| 245 | - } |
|
| 225 | + if (count($host_get)==0) |
|
| 226 | + { |
|
| 227 | + $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 228 | + $this->view->serviceGet=false; |
|
| 229 | + } |
|
| 230 | + else |
|
| 231 | + { |
|
| 232 | + // Tell JS to get services when page is loaded |
|
| 233 | + $this->view->serviceGet=true; |
|
| 234 | + // get service id for form to set : |
|
| 235 | + $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 236 | + if (count($serviceID) ==0) |
|
| 237 | + { |
|
| 238 | + $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 239 | + } |
|
| 240 | + else |
|
| 241 | + { |
|
| 242 | + $this->view->serviceSet=$serviceID[0]->id; |
|
| 243 | + } |
|
| 244 | + } |
|
| 246 | 245 | } |
| 247 | 246 | |
| 248 | 247 | /** |
@@ -251,33 +250,33 @@ discard block |
||
| 251 | 250 | */ |
| 252 | 251 | private function add_check_hostgroup_exists($ruleDetail) |
| 253 | 252 | { |
| 254 | - // Check if groupe exists |
|
| 255 | - $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname); |
|
| 256 | - if (count($group_get)==0) |
|
| 257 | - { |
|
| 258 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 259 | - $this->view->serviceGroupGet=false; |
|
| 260 | - } |
|
| 261 | - else |
|
| 262 | - { |
|
| 263 | - $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id); |
|
| 264 | - $foundGrpService=0; |
|
| 265 | - foreach ($grpServices as $grpService) |
|
| 266 | - { |
|
| 267 | - if ($grpService[0] == $ruleDetail->service_name) |
|
| 268 | - { |
|
| 269 | - $foundGrpService=1; |
|
| 270 | - $this->view->serviceSet=$ruleDetail->service_name; |
|
| 271 | - } |
|
| 272 | - } |
|
| 253 | + // Check if groupe exists |
|
| 254 | + $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname); |
|
| 255 | + if (count($group_get)==0) |
|
| 256 | + { |
|
| 257 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 258 | + $this->view->serviceGroupGet=false; |
|
| 259 | + } |
|
| 260 | + else |
|
| 261 | + { |
|
| 262 | + $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id); |
|
| 263 | + $foundGrpService=0; |
|
| 264 | + foreach ($grpServices as $grpService) |
|
| 265 | + { |
|
| 266 | + if ($grpService[0] == $ruleDetail->service_name) |
|
| 267 | + { |
|
| 268 | + $foundGrpService=1; |
|
| 269 | + $this->view->serviceSet=$ruleDetail->service_name; |
|
| 270 | + } |
|
| 271 | + } |
|
| 273 | 272 | |
| 274 | - // Tell JS to get services when page is loaded |
|
| 275 | - $this->view->serviceGroupGet=true; |
|
| 276 | - if ($foundGrpService==0) |
|
| 277 | - { |
|
| 278 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 279 | - } |
|
| 280 | - } |
|
| 273 | + // Tell JS to get services when page is loaded |
|
| 274 | + $this->view->serviceGroupGet=true; |
|
| 275 | + if ($foundGrpService==0) |
|
| 276 | + { |
|
| 277 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 278 | + } |
|
| 279 | + } |
|
| 281 | 280 | } |
| 282 | 281 | |
| 283 | 282 | /** |
@@ -289,52 +288,52 @@ discard block |
||
| 289 | 288 | */ |
| 290 | 289 | private function add_create_trap_object_list(&$display, &$rule) |
| 291 | 290 | { |
| 292 | - $curObjectList=array(); |
|
| 293 | - $index=1; |
|
| 294 | - // check in display & rule for : OID(<oid>) |
|
| 295 | - $matches=array(); |
|
| 296 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 297 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 298 | - { |
|
| 299 | - $curOid=$matches[1]; |
|
| 291 | + $curObjectList=array(); |
|
| 292 | + $index=1; |
|
| 293 | + // check in display & rule for : OID(<oid>) |
|
| 294 | + $matches=array(); |
|
| 295 | + while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 296 | + preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 297 | + { |
|
| 298 | + $curOid=$matches[1]; |
|
| 300 | 299 | |
| 301 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 302 | - && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
| 303 | - { |
|
| 304 | - array_push($curObjectList, array( |
|
| 305 | - $index, |
|
| 306 | - $curOid, |
|
| 307 | - $object['mib'], |
|
| 308 | - $object['name'], |
|
| 309 | - '', |
|
| 310 | - $object['type'], |
|
| 311 | - $object['type_enum'] |
|
| 312 | - )); |
|
| 313 | - } |
|
| 314 | - else |
|
| 315 | - { |
|
| 316 | - array_push($curObjectList, array( |
|
| 317 | - $index, |
|
| 318 | - $curOid, |
|
| 319 | - 'not found', |
|
| 320 | - 'not found', |
|
| 321 | - '', |
|
| 322 | - 'not found', |
|
| 323 | - 'not found' |
|
| 324 | - )); |
|
| 325 | - } |
|
| 326 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 327 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 328 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 329 | - $index++; |
|
| 330 | - } |
|
| 331 | - return $curObjectList; |
|
| 300 | + if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 301 | + && ($object=$this->getMIB()->translateOID($curOid)) != null) |
|
| 302 | + { |
|
| 303 | + array_push($curObjectList, array( |
|
| 304 | + $index, |
|
| 305 | + $curOid, |
|
| 306 | + $object['mib'], |
|
| 307 | + $object['name'], |
|
| 308 | + '', |
|
| 309 | + $object['type'], |
|
| 310 | + $object['type_enum'] |
|
| 311 | + )); |
|
| 312 | + } |
|
| 313 | + else |
|
| 314 | + { |
|
| 315 | + array_push($curObjectList, array( |
|
| 316 | + $index, |
|
| 317 | + $curOid, |
|
| 318 | + 'not found', |
|
| 319 | + 'not found', |
|
| 320 | + '', |
|
| 321 | + 'not found', |
|
| 322 | + 'not found' |
|
| 323 | + )); |
|
| 324 | + } |
|
| 325 | + $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 326 | + $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 327 | + $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 328 | + $index++; |
|
| 329 | + } |
|
| 330 | + return $curObjectList; |
|
| 332 | 331 | } |
| 333 | 332 | |
| 334 | 333 | /** Add a handler |
| 335 | - * Get params fromid : setup from existing trap (id of trap table) |
|
| 336 | - * Get param ruleid : edit from existing handler (id of rule table) |
|
| 337 | - */ |
|
| 334 | + * Get params fromid : setup from existing trap (id of trap table) |
|
| 335 | + * Get param ruleid : edit from existing handler (id of rule table) |
|
| 336 | + */ |
|
| 338 | 337 | public function addAction() |
| 339 | 338 | { |
| 340 | 339 | $this->checkConfigPermission(); |
@@ -354,8 +353,8 @@ discard block |
||
| 354 | 353 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
| 355 | 354 | |
| 356 | 355 | if (($trapid = $this->params->get('fromid')) !== null) { |
| 357 | - /********** Setup from existing trap ***************/ |
|
| 358 | - $this->add_from_existing($trapid); |
|
| 356 | + /********** Setup from existing trap ***************/ |
|
| 357 | + $this->add_from_existing($trapid); |
|
| 359 | 358 | return; |
| 360 | 359 | } |
| 361 | 360 | |
@@ -380,14 +379,14 @@ discard block |
||
| 380 | 379 | $this->view->warning_message=''; |
| 381 | 380 | if ($this->view->hostname != null) |
| 382 | 381 | { |
| 383 | - $this->view->selectGroup=false; |
|
| 384 | - // Check if hostname still exists |
|
| 385 | - $this->add_check_host_exists($ruleDetail); |
|
| 382 | + $this->view->selectGroup=false; |
|
| 383 | + // Check if hostname still exists |
|
| 384 | + $this->add_check_host_exists($ruleDetail); |
|
| 386 | 385 | } |
| 387 | 386 | else |
| 388 | 387 | { |
| 389 | - $this->view->selectGroup=true; |
|
| 390 | - $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
| 388 | + $this->view->selectGroup=true; |
|
| 389 | + $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
|
| 391 | 390 | } |
| 392 | 391 | |
| 393 | 392 | $this->view->mainoid=$ruleDetail->trap_oid; |
@@ -415,9 +414,9 @@ discard block |
||
| 415 | 414 | } |
| 416 | 415 | |
| 417 | 416 | /** Validate form and output message to user |
| 418 | - * @param in postdata |
|
| 419 | - * @return string status : OK / <Message> |
|
| 420 | - **/ |
|
| 417 | + * @param in postdata |
|
| 418 | + * @return string status : OK / <Message> |
|
| 419 | + **/ |
|
| 421 | 420 | protected function handlerformAction() |
| 422 | 421 | { |
| 423 | 422 | $postData=$this->getRequest()->getPost(); |
@@ -440,7 +439,7 @@ discard block |
||
| 440 | 439 | 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
| 441 | 440 | 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
| 442 | 441 | 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
| 443 | - 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 442 | + 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 444 | 443 | ); |
| 445 | 444 | |
| 446 | 445 | if (isset($postData[$params['action_form']['post']]) |
@@ -448,7 +447,7 @@ discard block |
||
| 448 | 447 | { |
| 449 | 448 | try |
| 450 | 449 | { |
| 451 | - $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
|
| 450 | + $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
|
| 452 | 451 | } |
| 453 | 452 | catch (Exception $e) |
| 454 | 453 | { |
@@ -458,7 +457,7 @@ discard block |
||
| 458 | 457 | //$this->Module()-> |
| 459 | 458 | $this->_helper->json(array( |
| 460 | 459 | 'status'=>'OK', |
| 461 | - 'redirect'=>'trapdirector/handler' |
|
| 460 | + 'redirect'=>'trapdirector/handler' |
|
| 462 | 461 | |
| 463 | 462 | )); |
| 464 | 463 | } |
@@ -485,7 +484,7 @@ discard block |
||
| 485 | 484 | $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
| 486 | 485 | if (! $isHostGroup ) |
| 487 | 486 | { // checks if selection by host |
| 488 | - $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']); |
|
| 487 | + $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']); |
|
| 489 | 488 | $params['ip4']['val']=$hostAddr->ip4; |
| 490 | 489 | $params['ip6']['val']=$hostAddr->ip6; |
| 491 | 490 | $checkHostName=$hostAddr->name; |
@@ -496,8 +495,8 @@ discard block |
||
| 496 | 495 | } |
| 497 | 496 | if (!is_numeric($params['serviceid']['val'])) |
| 498 | 497 | { |
| 499 | - $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 500 | - return; |
|
| 498 | + $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 499 | + return; |
|
| 501 | 500 | } |
| 502 | 501 | $serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']); |
| 503 | 502 | if ($params['service_name']['val'] != $serviceName->name2) |
@@ -508,7 +507,7 @@ discard block |
||
| 508 | 507 | } |
| 509 | 508 | else |
| 510 | 509 | { |
| 511 | - $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
|
| 510 | + $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
|
| 512 | 511 | if ($params['host_name']['val'] != $object->name1) |
| 513 | 512 | { |
| 514 | 513 | $this->_helper->json(array('status'=>"Invalid object group id : Please re enter service")); |
@@ -530,11 +529,11 @@ discard block |
||
| 530 | 529 | |
| 531 | 530 | if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') |
| 532 | 531 | { // If no rule number or action is clone, add the handler |
| 533 | - $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
|
| 532 | + $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
|
| 534 | 533 | } |
| 535 | 534 | else |
| 536 | 535 | { |
| 537 | - $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 536 | + $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 538 | 537 | $ruleID=$params['db_rule']['val']; |
| 539 | 538 | } |
| 540 | 539 | } |
@@ -548,9 +547,9 @@ discard block |
||
| 548 | 547 | } |
| 549 | 548 | |
| 550 | 549 | /** Get trap detail by trapid. |
| 551 | - * @param integer $trapid : id of trap in received table |
|
| 552 | - * @return array (objects) |
|
| 553 | - */ |
|
| 550 | + * @param integer $trapid : id of trap in received table |
|
| 551 | + * @return array (objects) |
|
| 552 | + */ |
|
| 554 | 553 | protected function getTrapDetail($trapid) |
| 555 | 554 | { |
| 556 | 555 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -566,14 +565,14 @@ discard block |
||
| 566 | 565 | } |
| 567 | 566 | try |
| 568 | 567 | { |
| 569 | - $query = $dbConn->select() |
|
| 568 | + $query = $dbConn->select() |
|
| 570 | 569 | ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
| 571 | 570 | ->where('id=?',$trapid); |
| 572 | 571 | $trapDetail=$dbConn->fetchRow($query); |
| 573 | 572 | if ( $trapDetail == null ) |
| 574 | 573 | { |
| 575 | - $trapDetail = 'NULL'; |
|
| 576 | - throw new Exception('No traps was found with id = '.$trapid); |
|
| 574 | + $trapDetail = 'NULL'; |
|
| 575 | + throw new Exception('No traps was found with id = '.$trapid); |
|
| 577 | 576 | } |
| 578 | 577 | } |
| 579 | 578 | catch (Exception $e) |
@@ -587,9 +586,9 @@ discard block |
||
| 587 | 586 | } |
| 588 | 587 | |
| 589 | 588 | /** Get trap objects |
| 590 | - * @param integer $trapid : trap id |
|
| 591 | - * @return array : full column in db of trap id |
|
| 592 | - */ |
|
| 589 | + * @param integer $trapid : trap id |
|
| 590 | + * @return array : full column in db of trap id |
|
| 591 | + */ |
|
| 593 | 592 | protected function getTrapobjects($trapid) |
| 594 | 593 | { |
| 595 | 594 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -605,7 +604,7 @@ discard block |
||
| 605 | 604 | } |
| 606 | 605 | try |
| 607 | 606 | { |
| 608 | - $query = $dbConn->select() |
|
| 607 | + $query = $dbConn->select() |
|
| 609 | 608 | ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
| 610 | 609 | ->where('trap_id=?',$trapid); |
| 611 | 610 | $trapDetail=$dbConn->fetchAll($query); |
@@ -621,10 +620,10 @@ discard block |
||
| 621 | 620 | } |
| 622 | 621 | |
| 623 | 622 | /** Get rule detail by ruleid. |
| 624 | - * @param integer $ruleid int id of rule in rule table |
|
| 625 | - * @return object|array : column objects in db |
|
| 626 | - * |
|
| 627 | - */ |
|
| 623 | + * @param integer $ruleid int id of rule in rule table |
|
| 624 | + * @return object|array : column objects in db |
|
| 625 | + * |
|
| 626 | + */ |
|
| 628 | 627 | protected function getRuleDetail($ruleid) |
| 629 | 628 | { |
| 630 | 629 | if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
@@ -635,7 +634,7 @@ discard block |
||
| 635 | 634 | // *************** Get main data |
| 636 | 635 | try |
| 637 | 636 | { |
| 638 | - $query = $dbConn->select() |
|
| 637 | + $query = $dbConn->select() |
|
| 639 | 638 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
| 640 | 639 | ->where('id=?',$ruleid); |
| 641 | 640 | $ruleDetail=$dbConn->fetchRow($query); |
@@ -652,7 +651,7 @@ discard block |
||
| 652 | 651 | } |
| 653 | 652 | |
| 654 | 653 | /** Setup tabs for rules |
| 655 | - */ |
|
| 654 | + */ |
|
| 656 | 655 | protected function prepareTabs() |
| 657 | 656 | { |
| 658 | 657 | return $this->getTabs()->add('status', array( |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | $this->checkReadPermission(); |
| 25 | 25 | $this->prepareTabs()->activate('status'); |
| 26 | 26 | |
| 27 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
| 27 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
| 28 | 28 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 29 | 29 | |
| 30 | - $this->view->handlerTable = new HandlerTable( |
|
| 30 | + $this->view->handlerTable=new HandlerTable( |
|
| 31 | 31 | $this->moduleConfig->getTrapRuleName(), |
| 32 | 32 | $this->moduleConfig->getHandlerListTitles(), |
| 33 | 33 | $this->moduleConfig->getHandlerListDisplayColumns(), |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $this->view, |
| 37 | 37 | $this->moduleConfig->urlPath()); |
| 38 | 38 | |
| 39 | - $getVars = $this->getRequest()->getParams(); |
|
| 39 | + $getVars=$this->getRequest()->getParams(); |
|
| 40 | 40 | $this->view->handlerTable->getParams($getVars); |
| 41 | 41 | |
| 42 | 42 | //$this->view->handlerTable->setFilter('127.0.0.1',array('ip4')); |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | $this->getHandlerListTable()->setConnection($dbConn); |
| 49 | 49 | $this->getHandlerListTable()->setMibloader($this->getMIB()); |
| 50 | 50 | // Apply pagination limits |
| 51 | - $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
| 51 | + $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
| 52 | 52 | |
| 53 | 53 | // Set Filter |
| 54 | - $this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
| 54 | + $this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
| 55 | 55 | |
| 56 | 56 | //$this->displayExitError('Handler/indexAction','Not implemented'); |
| 57 | 57 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | public function testruleAction() |
| 62 | 62 | { |
| 63 | 63 | $this->checkReadPermission(); |
| 64 | - $this->getTabs()->add('get',array( |
|
| 64 | + $this->getTabs()->add('get', array( |
|
| 65 | 65 | 'active' => true, |
| 66 | 66 | 'label' => $this->translate('Test Rule'), |
| 67 | 67 | 'url' => Url::fromRequest() |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | if ($this->params->get('rule') !== null) |
| 72 | 72 | { |
| 73 | - $this->view->rule= $this->params->get('rule'); |
|
| 73 | + $this->view->rule=$this->params->get('rule'); |
|
| 74 | 74 | } |
| 75 | 75 | else |
| 76 | 76 | { |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | } |
| 130 | 130 | catch (Exception $e) |
| 131 | 131 | { |
| 132 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
| 132 | + $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage()); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | |
| 136 | 136 | // if one unique host found -> put id text input |
| 137 | - if (count($hosts)==1) { |
|
| 137 | + if (count($hosts) == 1) { |
|
| 138 | 138 | $this->view->hostname=$hosts[0]->name; |
| 139 | 139 | //$hostid=$hosts[0]->id; |
| 140 | 140 | // Tell JS to get services when page is loaded |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | } |
| 144 | 144 | else |
| 145 | 145 | { |
| 146 | - foreach($hosts as $key=>$val) |
|
| 146 | + foreach ($hosts as $key=>$val) |
|
| 147 | 147 | { |
| 148 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
| 148 | + array_push($this->view->hostlist, $hosts[$key]->name); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
@@ -184,18 +184,18 @@ discard block |
||
| 184 | 184 | $currentObjectTypeEnum |
| 185 | 185 | ); |
| 186 | 186 | $oid_index++; |
| 187 | - array_push($this->view->objectList,$currentObject); |
|
| 187 | + array_push($this->view->objectList, $currentObject); |
|
| 188 | 188 | // set currrent object to null in allObjects |
| 189 | 189 | if (isset($allObjects[$val->oid])) |
| 190 | 190 | { |
| 191 | 191 | $allObjects[$val->oid]=null; |
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 194 | + if ($allObjects != null) // in case trap doesn't have objects or is not resolved |
|
| 195 | 195 | { |
| 196 | 196 | foreach ($allObjects as $key => $val) |
| 197 | 197 | { |
| 198 | - if ($val==null) { continue; } |
|
| 198 | + if ($val == null) { continue; } |
|
| 199 | 199 | array_push($this->view->objectList, array( |
| 200 | 200 | $oid_index, |
| 201 | 201 | $key, |
@@ -223,9 +223,9 @@ discard block |
||
| 223 | 223 | // Check if hostname still exists |
| 224 | 224 | $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname); |
| 225 | 225 | |
| 226 | - if (count($host_get)==0) |
|
| 226 | + if (count($host_get) == 0) |
|
| 227 | 227 | { |
| 228 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 228 | + $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore'; |
|
| 229 | 229 | $this->view->serviceGet=false; |
| 230 | 230 | } |
| 231 | 231 | else |
@@ -233,10 +233,10 @@ discard block |
||
| 233 | 233 | // Tell JS to get services when page is loaded |
| 234 | 234 | $this->view->serviceGet=true; |
| 235 | 235 | // get service id for form to set : |
| 236 | - $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 237 | - if (count($serviceID) ==0) |
|
| 236 | + $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname, $ruleDetail->service_name); |
|
| 237 | + if (count($serviceID) == 0) |
|
| 238 | 238 | { |
| 239 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 239 | + $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
| 240 | 240 | } |
| 241 | 241 | else |
| 242 | 242 | { |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | // Check if groupe exists |
| 255 | 255 | $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname); |
| 256 | - if (count($group_get)==0) |
|
| 256 | + if (count($group_get) == 0) |
|
| 257 | 257 | { |
| 258 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 258 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore'; |
|
| 259 | 259 | $this->view->serviceGroupGet=false; |
| 260 | 260 | } |
| 261 | 261 | else |
@@ -273,9 +273,9 @@ discard block |
||
| 273 | 273 | |
| 274 | 274 | // Tell JS to get services when page is loaded |
| 275 | 275 | $this->view->serviceGroupGet=true; |
| 276 | - if ($foundGrpService==0) |
|
| 276 | + if ($foundGrpService == 0) |
|
| 277 | 277 | { |
| 278 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 278 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -293,12 +293,12 @@ discard block |
||
| 293 | 293 | $index=1; |
| 294 | 294 | // check in display & rule for : OID(<oid>) |
| 295 | 295 | $matches=array(); |
| 296 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
| 297 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
| 296 | + while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) || |
|
| 297 | + preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches)) |
|
| 298 | 298 | { |
| 299 | 299 | $curOid=$matches[1]; |
| 300 | 300 | |
| 301 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
| 301 | + if ((preg_match('/\*/', $curOid) == 0) |
|
| 302 | 302 | && ($object=$this->getMIB()->translateOID($curOid)) != null) |
| 303 | 303 | { |
| 304 | 304 | array_push($curObjectList, array( |
@@ -323,9 +323,9 @@ discard block |
||
| 323 | 323 | 'not found' |
| 324 | 324 | )); |
| 325 | 325 | } |
| 326 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
| 327 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
| 328 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
| 326 | + $curOid=preg_replace('/\*/', '\*', $curOid); |
|
| 327 | + $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display); |
|
| 328 | + $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule); |
|
| 329 | 329 | $index++; |
| 330 | 330 | } |
| 331 | 331 | return $curObjectList; |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | $this->checkConfigPermission(); |
| 341 | 341 | // set up tab |
| 342 | 342 | $this->prepareTabs(); |
| 343 | - $this->getTabs()->add('get',array( |
|
| 343 | + $this->getTabs()->add('get', array( |
|
| 344 | 344 | 'active' => true, |
| 345 | 345 | 'label' => $this->translate('Add handler'), |
| 346 | 346 | 'url' => Url::fromRequest() |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
| 355 | 355 | |
| 356 | - if (($trapid = $this->params->get('fromid')) !== null) { |
|
| 356 | + if (($trapid=$this->params->get('fromid')) !== null) { |
|
| 357 | 357 | /********** Setup from existing trap ***************/ |
| 358 | 358 | $this->add_from_existing($trapid); |
| 359 | 359 | return; |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | $this->view->setRuleMatch=$ruleDetail->action_match; |
| 374 | 374 | $this->view->setRuleNoMatch=$ruleDetail->action_nomatch; |
| 375 | 375 | $this->view->hostgroupname=$ruleDetail->host_group_name; |
| 376 | - $this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified); |
|
| 376 | + $this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified); |
|
| 377 | 377 | $this->view->modifier=$ruleDetail->modifier; |
| 378 | 378 | |
| 379 | 379 | // Warning message if host/service don't exists anymore |
@@ -425,26 +425,26 @@ discard block |
||
| 425 | 425 | |
| 426 | 426 | $params=array( |
| 427 | 427 | // id (also db) => array('post' => post id, 'val' => default val, 'db' => send to table) |
| 428 | - 'hostgroup' => array('post' => 'hostgroup', 'db'=>false), |
|
| 429 | - 'db_rule' => array('post' => 'db_rule', 'db'=>false), |
|
| 430 | - 'hostid' => array('post' => 'hostid', 'db'=>false), |
|
| 431 | - 'host_name' => array('post' => 'hostname', 'val' => null, 'db'=>true), |
|
| 432 | - 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
|
| 433 | - 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
|
| 434 | - 'service_name' => array('post' => 'serviceName', 'db'=>true), |
|
| 435 | - 'trap_oid' => array('post' => 'oid', 'db'=>true), |
|
| 436 | - 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
|
| 437 | - 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
|
| 438 | - 'rule' => array('post' => 'rule', 'val' => '', 'db'=>true), |
|
| 439 | - 'action_match' => array('post' => 'ruleMatch', 'val' => -1, 'db'=>true), |
|
| 440 | - 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
|
| 441 | - 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 442 | - 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 443 | - 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 428 | + 'hostgroup' => array('post' => 'hostgroup', 'db'=>false), |
|
| 429 | + 'db_rule' => array('post' => 'db_rule', 'db'=>false), |
|
| 430 | + 'hostid' => array('post' => 'hostid', 'db'=>false), |
|
| 431 | + 'host_name' => array('post' => 'hostname', 'val' => null, 'db'=>true), |
|
| 432 | + 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
|
| 433 | + 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
|
| 434 | + 'service_name' => array('post' => 'serviceName', 'db'=>true), |
|
| 435 | + 'trap_oid' => array('post' => 'oid', 'db'=>true), |
|
| 436 | + 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
|
| 437 | + 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
|
| 438 | + 'rule' => array('post' => 'rule', 'val' => '', 'db'=>true), |
|
| 439 | + 'action_match' => array('post' => 'ruleMatch', 'val' => -1, 'db'=>true), |
|
| 440 | + 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
|
| 441 | + 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 442 | + 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
|
| 443 | + 'action_form' => array('post' => 'action_form', 'val' => null, 'db'=>false) |
|
| 444 | 444 | ); |
| 445 | 445 | |
| 446 | 446 | if (isset($postData[$params['action_form']['post']]) |
| 447 | - && $postData[$params['action_form']['post']] == 'delete' ) |
|
| 447 | + && $postData[$params['action_form']['post']] == 'delete') |
|
| 448 | 448 | { |
| 449 | 449 | try |
| 450 | 450 | { |
@@ -464,16 +464,16 @@ discard block |
||
| 464 | 464 | } |
| 465 | 465 | foreach (array_keys($params) as $key) |
| 466 | 466 | { |
| 467 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
| 468 | - if (! isset($postData[$params[$key]['post']])) |
|
| 467 | + if ($params[$key]['post'] == null) continue; // data not sent in post vars |
|
| 468 | + if (!isset($postData[$params[$key]['post']])) |
|
| 469 | 469 | { |
| 470 | 470 | // should not happen as the js checks data |
| 471 | - $this->_helper->json(array('status'=>'No ' . $key)); |
|
| 471 | + $this->_helper->json(array('status'=>'No '.$key)); |
|
| 472 | 472 | } |
| 473 | 473 | else |
| 474 | 474 | { |
| 475 | 475 | $data=$postData[$params[$key]['post']]; |
| 476 | - if ($data!=null && $data !="") |
|
| 476 | + if ($data != null && $data != "") |
|
| 477 | 477 | { |
| 478 | 478 | $params[$key]['val']=$postData[$params[$key]['post']]; |
| 479 | 479 | } |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | |
| 483 | 483 | try |
| 484 | 484 | { |
| 485 | - $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
|
| 486 | - if (! $isHostGroup ) |
|
| 485 | + $isHostGroup=($params['hostgroup']['val'] == 1) ?true:false; |
|
| 486 | + if (!$isHostGroup) |
|
| 487 | 487 | { // checks if selection by host |
| 488 | 488 | $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']); |
| 489 | 489 | $params['ip4']['val']=$hostAddr->ip4; |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | } |
| 497 | 497 | if (!is_numeric($params['serviceid']['val'])) |
| 498 | 498 | { |
| 499 | - $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
| 499 | + $this->_helper->json(array('status'=>"Invalid service id ".$params['serviceid']['val'])); |
|
| 500 | 500 | return; |
| 501 | 501 | } |
| 502 | 502 | $serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']); |
@@ -515,15 +515,15 @@ discard block |
||
| 515 | 515 | return; |
| 516 | 516 | } |
| 517 | 517 | // Put param in correct column (group_name) |
| 518 | - $params['host_group_name']['val'] = $params['host_name']['val']; |
|
| 518 | + $params['host_group_name']['val']=$params['host_name']['val']; |
|
| 519 | 519 | $params['host_name']['val']=null; |
| 520 | 520 | } |
| 521 | 521 | $dbparams=array(); |
| 522 | 522 | foreach ($params as $key=>$val) |
| 523 | 523 | { |
| 524 | - if ($val['db']==true ) |
|
| 524 | + if ($val['db'] == true) |
|
| 525 | 525 | { |
| 526 | - $dbparams[$key] = $val['val']; |
|
| 526 | + $dbparams[$key]=$val['val']; |
|
| 527 | 527 | } |
| 528 | 528 | } |
| 529 | 529 | // echo '<br>'; print_r($dbparams);echo '<br>'; |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | } |
| 535 | 535 | else |
| 536 | 536 | { |
| 537 | - $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
| 537 | + $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']); |
|
| 538 | 538 | $ruleID=$params['db_rule']['val']; |
| 539 | 539 | } |
| 540 | 540 | } |
@@ -553,10 +553,10 @@ discard block |
||
| 553 | 553 | */ |
| 554 | 554 | protected function getTrapDetail($trapid) |
| 555 | 555 | { |
| 556 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
| 556 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
| 557 | 557 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
| 558 | 558 | |
| 559 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 559 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 560 | 560 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 561 | 561 | // *************** Get main data |
| 562 | 562 | // extract columns and titles; |
@@ -566,19 +566,19 @@ discard block |
||
| 566 | 566 | } |
| 567 | 567 | try |
| 568 | 568 | { |
| 569 | - $query = $dbConn->select() |
|
| 570 | - ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
|
| 571 | - ->where('id=?',$trapid); |
|
| 569 | + $query=$dbConn->select() |
|
| 570 | + ->from($this->getModuleConfig()->getTrapTableName(), $elmts) |
|
| 571 | + ->where('id=?', $trapid); |
|
| 572 | 572 | $trapDetail=$dbConn->fetchRow($query); |
| 573 | - if ( $trapDetail == null ) |
|
| 573 | + if ($trapDetail == null) |
|
| 574 | 574 | { |
| 575 | - $trapDetail = 'NULL'; |
|
| 575 | + $trapDetail='NULL'; |
|
| 576 | 576 | throw new Exception('No traps was found with id = '.$trapid); |
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | 579 | catch (Exception $e) |
| 580 | 580 | { |
| 581 | - $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
|
| 581 | + $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage()); |
|
| 582 | 582 | return; |
| 583 | 583 | } |
| 584 | 584 | |
@@ -592,10 +592,10 @@ discard block |
||
| 592 | 592 | */ |
| 593 | 593 | protected function getTrapobjects($trapid) |
| 594 | 594 | { |
| 595 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
| 595 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
| 596 | 596 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
| 597 | 597 | |
| 598 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 598 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 599 | 599 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 600 | 600 | // *************** Get object data |
| 601 | 601 | // extract columns and titles; |
@@ -605,15 +605,15 @@ discard block |
||
| 605 | 605 | } |
| 606 | 606 | try |
| 607 | 607 | { |
| 608 | - $query = $dbConn->select() |
|
| 609 | - ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
|
| 610 | - ->where('trap_id=?',$trapid); |
|
| 608 | + $query=$dbConn->select() |
|
| 609 | + ->from($this->moduleConfig->getTrapDataTableName(), $data_elmts) |
|
| 610 | + ->where('trap_id=?', $trapid); |
|
| 611 | 611 | $trapDetail=$dbConn->fetchAll($query); |
| 612 | 612 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
| 613 | 613 | } |
| 614 | 614 | catch (Exception $e) |
| 615 | 615 | { |
| 616 | - $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
|
| 616 | + $this->displayExitError('Add handler : get trap data detail : ', $e->getMessage()); |
|
| 617 | 617 | return array(); |
| 618 | 618 | } |
| 619 | 619 | |
@@ -627,24 +627,24 @@ discard block |
||
| 627 | 627 | */ |
| 628 | 628 | protected function getRuleDetail($ruleid) |
| 629 | 629 | { |
| 630 | - if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
|
| 630 | + if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); } |
|
| 631 | 631 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
| 632 | 632 | |
| 633 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 633 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 634 | 634 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 635 | 635 | // *************** Get main data |
| 636 | 636 | try |
| 637 | 637 | { |
| 638 | - $query = $dbConn->select() |
|
| 639 | - ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
|
| 640 | - ->where('id=?',$ruleid); |
|
| 638 | + $query=$dbConn->select() |
|
| 639 | + ->from($this->getModuleConfig()->getTrapRuleName(), $queryArray) |
|
| 640 | + ->where('id=?', $ruleid); |
|
| 641 | 641 | $ruleDetail=$dbConn->fetchRow($query); |
| 642 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
| 642 | + if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid); |
|
| 643 | 643 | } |
| 644 | 644 | catch (Exception $e) |
| 645 | 645 | { |
| 646 | - $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
|
| 647 | - throw new Exception('Error : ' . $e->getMessage()); |
|
| 646 | + $this->displayExitError('Update handler : get rule detail', $e->getMessage()); |
|
| 647 | + throw new Exception('Error : '.$e->getMessage()); |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | return $ruleDetail; |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | { |
| 658 | 658 | return $this->getTabs()->add('status', array( |
| 659 | 659 | 'label' => $this->translate('Trap handlers'), |
| 660 | - 'url' => $this->getModuleConfig()->urlPath() . '/handler') |
|
| 660 | + 'url' => $this->getModuleConfig()->urlPath().'/handler') |
|
| 661 | 661 | ); |
| 662 | 662 | } |
| 663 | 663 | |
@@ -25,7 +25,9 @@ discard block |
||
| 25 | 25 | $this->prepareTabs()->activate('status'); |
| 26 | 26 | |
| 27 | 27 | $dbConn = $this->getUIDatabase()->getDb(); |
| 28 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 28 | + if ($dbConn === null) { |
|
| 29 | + throw new \ErrorException('uncatched db error'); |
|
| 30 | + } |
|
| 29 | 31 | |
| 30 | 32 | $this->view->handlerTable = new HandlerTable( |
| 31 | 33 | $this->moduleConfig->getTrapRuleName(), |
@@ -71,8 +73,7 @@ discard block |
||
| 71 | 73 | if ($this->params->get('rule') !== null) |
| 72 | 74 | { |
| 73 | 75 | $this->view->rule= $this->params->get('rule'); |
| 74 | - } |
|
| 75 | - else |
|
| 76 | + } else |
|
| 76 | 77 | { |
| 77 | 78 | $this->view->rule=''; |
| 78 | 79 | } |
@@ -126,8 +127,7 @@ discard block |
||
| 126 | 127 | try |
| 127 | 128 | { |
| 128 | 129 | $hosts=$this->getUIDatabase()->getHostByIP($hostfilter); |
| 129 | - } |
|
| 130 | - catch (Exception $e) |
|
| 130 | + } catch (Exception $e) |
|
| 131 | 131 | { |
| 132 | 132 | $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
| 133 | 133 | } |
@@ -140,8 +140,7 @@ discard block |
||
| 140 | 140 | // Tell JS to get services when page is loaded |
| 141 | 141 | $this->view->serviceGet=true; |
| 142 | 142 | |
| 143 | - } |
|
| 144 | - else |
|
| 143 | + } else |
|
| 145 | 144 | { |
| 146 | 145 | foreach($hosts as $key=>$val) |
| 147 | 146 | { |
@@ -191,11 +190,14 @@ discard block |
||
| 191 | 190 | $allObjects[$val->oid]=null; |
| 192 | 191 | } |
| 193 | 192 | } |
| 194 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
| 193 | + if ($allObjects!=null) { |
|
| 194 | + // in case trap doesn't have objects or is not resolved |
|
| 195 | 195 | { |
| 196 | 196 | foreach ($allObjects as $key => $val) |
| 197 | 197 | { |
| 198 | - if ($val==null) { continue; } |
|
| 198 | + if ($val==null) { continue; |
|
| 199 | + } |
|
| 200 | + } |
|
| 199 | 201 | array_push($this->view->objectList, array( |
| 200 | 202 | $oid_index, |
| 201 | 203 | $key, |
@@ -227,8 +229,7 @@ discard block |
||
| 227 | 229 | { |
| 228 | 230 | $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
| 229 | 231 | $this->view->serviceGet=false; |
| 230 | - } |
|
| 231 | - else |
|
| 232 | + } else |
|
| 232 | 233 | { |
| 233 | 234 | // Tell JS to get services when page is loaded |
| 234 | 235 | $this->view->serviceGet=true; |
@@ -237,8 +238,7 @@ discard block |
||
| 237 | 238 | if (count($serviceID) ==0) |
| 238 | 239 | { |
| 239 | 240 | $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
| 240 | - } |
|
| 241 | - else |
|
| 241 | + } else |
|
| 242 | 242 | { |
| 243 | 243 | $this->view->serviceSet=$serviceID[0]->id; |
| 244 | 244 | } |
@@ -257,8 +257,7 @@ discard block |
||
| 257 | 257 | { |
| 258 | 258 | $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
| 259 | 259 | $this->view->serviceGroupGet=false; |
| 260 | - } |
|
| 261 | - else |
|
| 260 | + } else |
|
| 262 | 261 | { |
| 263 | 262 | $grpServices=$this->getUIDatabase()->getServicesByHostGroupid($group_get[0]->id); |
| 264 | 263 | $foundGrpService=0; |
@@ -310,8 +309,7 @@ discard block |
||
| 310 | 309 | $object['type'], |
| 311 | 310 | $object['type_enum'] |
| 312 | 311 | )); |
| 313 | - } |
|
| 314 | - else |
|
| 312 | + } else |
|
| 315 | 313 | { |
| 316 | 314 | array_push($curObjectList, array( |
| 317 | 315 | $index, |
@@ -383,8 +381,7 @@ discard block |
||
| 383 | 381 | $this->view->selectGroup=false; |
| 384 | 382 | // Check if hostname still exists |
| 385 | 383 | $this->add_check_host_exists($ruleDetail); |
| 386 | - } |
|
| 387 | - else |
|
| 384 | + } else |
|
| 388 | 385 | { |
| 389 | 386 | $this->view->selectGroup=true; |
| 390 | 387 | $this->add_check_hostgroup_exists($ruleDetail); // Check if groupe exists |
@@ -392,9 +389,11 @@ discard block |
||
| 392 | 389 | |
| 393 | 390 | $this->view->mainoid=$ruleDetail->trap_oid; |
| 394 | 391 | $oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid); |
| 395 | - if ($oidName != null) // oid is found in mibs |
|
| 392 | + if ($oidName != null) { |
|
| 393 | + // oid is found in mibs |
|
| 396 | 394 | { |
| 397 | - $this->view->mib=$oidName['mib']; |
|
| 395 | + $this->view->mib=$oidName['mib']; |
|
| 396 | + } |
|
| 398 | 397 | $this->view->name=$oidName['name']; |
| 399 | 398 | $this->view->trapListForMIB=$this->getMIB() |
| 400 | 399 | ->getTrapList($oidName['mib']); |
@@ -449,8 +448,7 @@ discard block |
||
| 449 | 448 | try |
| 450 | 449 | { |
| 451 | 450 | $this->getUIDatabase()->deleteRule($postData[$params['db_rule']['post']]); |
| 452 | - } |
|
| 453 | - catch (Exception $e) |
|
| 451 | + } catch (Exception $e) |
|
| 454 | 452 | { |
| 455 | 453 | $this->_helper->json(array('status'=>$e->getMessage())); |
| 456 | 454 | return; |
@@ -464,13 +462,15 @@ discard block |
||
| 464 | 462 | } |
| 465 | 463 | foreach (array_keys($params) as $key) |
| 466 | 464 | { |
| 467 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
| 465 | + if ($params[$key]['post']==null) { |
|
| 466 | + continue; |
|
| 467 | + } |
|
| 468 | + // data not sent in post vars |
|
| 468 | 469 | if (! isset($postData[$params[$key]['post']])) |
| 469 | 470 | { |
| 470 | 471 | // should not happen as the js checks data |
| 471 | 472 | $this->_helper->json(array('status'=>'No ' . $key)); |
| 472 | - } |
|
| 473 | - else |
|
| 473 | + } else |
|
| 474 | 474 | { |
| 475 | 475 | $data=$postData[$params[$key]['post']]; |
| 476 | 476 | if ($data!=null && $data !="") |
@@ -505,8 +505,7 @@ discard block |
||
| 505 | 505 | $this->_helper->json(array('status'=>"Invalid service id : Please re enter service")); |
| 506 | 506 | return; |
| 507 | 507 | } |
| 508 | - } |
|
| 509 | - else |
|
| 508 | + } else |
|
| 510 | 509 | { |
| 511 | 510 | $object=$this->getUIDatabase()->getObjectNameByid($params['hostid']['val']); |
| 512 | 511 | if ($params['host_name']['val'] != $object->name1) |
@@ -531,14 +530,12 @@ discard block |
||
| 531 | 530 | if ($params['db_rule']['val'] == -1 || $params['action_form']['val'] == 'clone') |
| 532 | 531 | { // If no rule number or action is clone, add the handler |
| 533 | 532 | $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
| 534 | - } |
|
| 535 | - else |
|
| 533 | + } else |
|
| 536 | 534 | { |
| 537 | 535 | $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
| 538 | 536 | $ruleID=$params['db_rule']['val']; |
| 539 | 537 | } |
| 540 | - } |
|
| 541 | - catch (Exception $e) |
|
| 538 | + } catch (Exception $e) |
|
| 542 | 539 | { |
| 543 | 540 | $this->_helper->json(array('status'=>$e->getMessage())); |
| 544 | 541 | return; |
@@ -557,7 +554,9 @@ discard block |
||
| 557 | 554 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
| 558 | 555 | |
| 559 | 556 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 560 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 557 | + if ($dbConn === null) { |
|
| 558 | + throw new \ErrorException('uncatched db error'); |
|
| 559 | + } |
|
| 561 | 560 | // *************** Get main data |
| 562 | 561 | // extract columns and titles; |
| 563 | 562 | $elmts=NULL; |
@@ -575,8 +574,7 @@ discard block |
||
| 575 | 574 | $trapDetail = 'NULL'; |
| 576 | 575 | throw new Exception('No traps was found with id = '.$trapid); |
| 577 | 576 | } |
| 578 | - } |
|
| 579 | - catch (Exception $e) |
|
| 577 | + } catch (Exception $e) |
|
| 580 | 578 | { |
| 581 | 579 | $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
| 582 | 580 | return; |
@@ -596,7 +594,9 @@ discard block |
||
| 596 | 594 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
| 597 | 595 | |
| 598 | 596 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 599 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 597 | + if ($dbConn === null) { |
|
| 598 | + throw new \ErrorException('uncatched db error'); |
|
| 599 | + } |
|
| 600 | 600 | // *************** Get object data |
| 601 | 601 | // extract columns and titles; |
| 602 | 602 | $data_elmts=NULL; |
@@ -610,8 +610,7 @@ discard block |
||
| 610 | 610 | ->where('trap_id=?',$trapid); |
| 611 | 611 | $trapDetail=$dbConn->fetchAll($query); |
| 612 | 612 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
| 613 | - } |
|
| 614 | - catch (Exception $e) |
|
| 613 | + } catch (Exception $e) |
|
| 615 | 614 | { |
| 616 | 615 | $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
| 617 | 616 | return array(); |
@@ -631,7 +630,9 @@ discard block |
||
| 631 | 630 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
| 632 | 631 | |
| 633 | 632 | $dbConn = $this->getUIDatabase()->getDbConn(); |
| 634 | - if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
|
| 633 | + if ($dbConn === null) { |
|
| 634 | + throw new \ErrorException('uncatched db error'); |
|
| 635 | + } |
|
| 635 | 636 | // *************** Get main data |
| 636 | 637 | try |
| 637 | 638 | { |
@@ -639,9 +640,10 @@ discard block |
||
| 639 | 640 | ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
| 640 | 641 | ->where('id=?',$ruleid); |
| 641 | 642 | $ruleDetail=$dbConn->fetchRow($query); |
| 642 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
| 643 | - } |
|
| 644 | - catch (Exception $e) |
|
| 643 | + if ( $ruleDetail == null ) { |
|
| 644 | + throw new Exception('No rule was found with id = '.$ruleid); |
|
| 645 | + } |
|
| 646 | + } catch (Exception $e) |
|
| 645 | 647 | { |
| 646 | 648 | $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
| 647 | 649 | throw new Exception('Error : ' . $e->getMessage()); |