| | 112 | |
|---|
| | 113 | |
|---|
| | 114 | function GetFilteredMaskList(LOGGROUP $grp = NULL, $maskid = false, $flags = 0) { |
|---|
| | 115 | $grp = $this->CheckGroup($grp, $flags); |
|---|
| | 116 | |
|---|
| | 117 | $info = $this->req->GetGroupOption("mask_table", $grp); |
|---|
| | 118 | // $info = $this->opts->Get("mask_table"); |
|---|
| | 119 | if (!$info) return parent::GetMaskList($grp, $flags); |
|---|
| | 120 | |
|---|
| | 121 | if (!is_array($info)) |
|---|
| | 122 | throw new ADEIException(translate("Invalid mask table specified in the reader configuration, the array with information should be provided")); |
|---|
| | 123 | |
|---|
| | 124 | if (!$info['table']) |
|---|
| | 125 | throw new ADEIException(translate("The mask table is not specified in the reader configuration")); |
|---|
| | 126 | |
|---|
| | 127 | if (!$info['id']) |
|---|
| | 128 | throw new ADEIException(translate("The id column for mask table is not specified in the reader configuration")); |
|---|
| | 129 | |
|---|
| | 130 | |
|---|
| | 131 | $query = ""; |
|---|
| | 132 | if (is_array($info['properties'])) { |
|---|
| | 133 | foreach ($info['properties'] as $prop => $col) { |
|---|
| | 134 | $query.= ", {$this->db->col_quote}$col{$this->db->col_quote} AS ${prop}"; |
|---|
| | 135 | } |
|---|
| | 136 | } |
|---|
| | 137 | |
|---|
| | 138 | if ($maskid) { |
|---|
| | 139 | $cond = " WHERE {$this->db->col_quote}{$info['id']}{$this->db->col_quote} = {$this->db->text_quote}{$maskid}{$this->db->text_quote}"; |
|---|
| | 140 | } elseif ($info['gid']) { |
|---|
| | 141 | $table = $this->db->FixTableName($grp->table); |
|---|
| | 142 | $cond = " WHERE {$this->db->col_quote}{$info['gid']}{$this->db->col_quote} = {$this->db->text_quote}{$table}{$this->db->text_quote}"; |
|---|
| | 143 | } else { |
|---|
| | 144 | $cond = ""; |
|---|
| | 145 | } |
|---|
| | 146 | $query = "SELECT {$this->db->col_quote}{$info['id']}{$this->db->col_quote} AS id{$query} FROM {$this->db->tbl_quote}{$info['table']}{$this->db->tbl_quote}" . $cond; |
|---|
| | 147 | |
|---|
| | 148 | $masks = $this->db->Query($query); |
|---|
| | 149 | |
|---|
| | 150 | if ($masks->rowCount()) { |
|---|
| | 151 | $items = $this->GetItemList($grp, NULL, $flags); |
|---|
| | 152 | $hash = array(); |
|---|
| | 153 | foreach ($items as $item) { |
|---|
| | 154 | $hash[$item['name']] = $item; |
|---|
| | 155 | } |
|---|
| | 156 | } else if ($maskid) { |
|---|
| | 157 | throw new ADEIException(translate("Mask \"%s\" is not found for group \"%s\"", $maskid, $grp->gid)); |
|---|
| | 158 | } |
|---|
| | 159 | |
|---|
| | 160 | $list = array(); |
|---|
| | 161 | foreach ($masks as $mask) { |
|---|
| | 162 | $items = explode(",", $mask['mask']); |
|---|
| | 163 | foreach ($items as &$item) { |
|---|
| | 164 | if (!is_numeric($item)) { |
|---|
| | 165 | if (isset($hash[$item])) { |
|---|
| | 166 | $item = $hash[$item]['id']; |
|---|
| | 167 | } else { |
|---|
| | 168 | throw new ADEIException(translate("Item \"%s\" specified in the mask \"%s\" is not available in the group \"%s\"", $item, $mask['id'], $grp->gid)); |
|---|
| | 169 | } |
|---|
| | 170 | } |
|---|
| | 171 | } |
|---|
| | 172 | |
|---|
| | 173 | $mask['mask'] = implode(",", $items); |
|---|
| | 174 | $mask['id'] = "maskid" . $mask['id']; |
|---|
| | 175 | |
|---|
| | 176 | $list[$mask['id']] = $mask; |
|---|
| | 177 | } |
|---|
| | 178 | |
|---|
| | 179 | return array_merge( |
|---|
| | 180 | parent::GetMaskList($grp, $flags), |
|---|
| | 181 | $list |
|---|
| | 182 | ); |
|---|
| | 183 | } |
|---|
| | 184 | |
|---|
| | 185 | function GetMaskList(LOGGROUP $grp = NULL, $flags = 0) { |
|---|
| | 186 | return $this->GetFilteredMaskList($grp, false, $flags); |
|---|
| | 187 | } |
|---|
| | 188 | |
|---|
| | 189 | function CreateMask(LOGGROUP $grp = NULL, array &$minfo = NULL, $flags = 0) { |
|---|
| | 190 | if ($minfo === NULL) { |
|---|
| | 191 | if ($this->req instanceof ITEMGroupRequest) |
|---|
| | 192 | $minfo = $this->req->GetMaskInfo($flags); |
|---|
| | 193 | } |
|---|
| | 194 | |
|---|
| | 195 | if (preg_match("/^maskid(\d+)$/", $minfo["db_mask"], $m)) { |
|---|
| | 196 | $res = new MASK(array(), $this, $grp, $flags); |
|---|
| | 197 | |
|---|
| | 198 | $masks = $this->GetFilteredMaskList($grp, $m[1], $flags); |
|---|
| | 199 | $mask = $masks->current(); |
|---|
| | 200 | |
|---|
| | 201 | if ($mask) { |
|---|
| | 202 | $res->SetIDs($mask['mask'], $mask['id']); |
|---|
| | 203 | } |
|---|
| | 204 | return $res; |
|---|
| | 205 | } else { |
|---|
| | 206 | return new MASK($minfo, $this, $grp, $flags); |
|---|
| | 207 | } |
|---|
| | 208 | } |
|---|
| | 209 | |
|---|