public function edit($record, $fieldprefix, $mode) { if ($this->hasFlag(self::AF_IP_SINGLEFIELD)) { return parent::edit($record, $fieldprefix, $mode); } $inputs = []; $values = empty($record[$this->fieldName()]) ? null : explode('.', $record[$this->fieldName()]); for ($i = 0; $i < 4; ++$i) { $name = $this->getHtmlName($fieldprefix) . '[' . $i . ']'; $value = isset($values[$i]) ? $values[$i] : ''; $inputs[] = '<input type="text" name="' . $name . '" value="' . $value . '" maxlength="3" size="3" />'; } return implode('.', $inputs); }
public function edit($record, $fieldprefix, $mode) { // There are 2 possibilities. Either we are going to search, // in which case we show a searchbox. // Or, a search has already been performed but multiple // matches have been found and an atkerror was set. // In this case, we show the selects. $select = false; if (isset($record['atkerror'])) { foreach ($record['atkerror'] as $error) { if ($error['attrib_name'] === $this->fieldName()) { $select = true; } } } if ($select && $this->createSearchNodeInstance()) { $res = ''; $notempty = false; // First lets get the results, which were lost during the redirect $this->m_matches = $this->getMatches($record[$this->fieldName()]); // Second check if we actually found anything if ($this->m_matches) { foreach ($this->m_matches as $match) { if (!empty($match)) { $notempty = true; continue; } } if (!$notempty) { return Tools::atktext('no_results_found'); } } if ($this->m_mode == 'multiselect' && count($this->m_matches) > 1) { $optionArray = $valueArray = []; foreach ($this->m_matches as $keyword => $matches) { for ($i = 0, $_i = count($matches); $i < $_i; ++$i) { $optionArray[] = $this->m_searchnodeInstance->descriptor($matches[$i]); $valueArray[] = $this->m_searchnodeInstance->primaryKey($matches[$i]); } } $attrib = new MultiSelectAttribute($this->m_name, $optionArray, $valueArray, 1, self::AF_NO_LABEL | MultiSelectAttribute::AF_CHECK_ALL | MultiSelectAttribute::AF_LINKS_BOTTOM); $res .= $attrib->edit($record, $fieldprefix, $mode); } else { if ($this->m_mode == 'select' || $this->m_mode == 'multiselect' && count($this->m_matches) == 1) { // Select one record from all matches. $res .= '<SELECT NAME="' . $this->getHtmlName($fieldprefix) . '[]" class="form-control select-standard">'; $res .= '<OPTION VALUE="">' . Tools::atktext('select_none'); $selects = []; foreach ($this->m_matches as $keyword => $matches) { for ($i = 0, $_i = count($matches); $i < $_i; ++$i) { $item = '<OPTION VALUE="' . $this->m_searchnodeInstance->primaryKey($matches[$i]) . '">' . $this->m_searchnodeInstance->descriptor($matches[$i]); if (!in_array($item, $selects)) { $selects[] = $item; } } $res .= implode("\n", $selects); } $res .= '</SELECT>'; } else { if ($this->m_mode == 'selectperkeyword') { // Select one record per keyword. $res = '<table border="0">'; foreach ($this->m_matches as $keyword => $matches) { if (count($matches) > 0) { $res .= '<tr><td>\'' . $keyword . '\': </td><td><SELECT NAME="' . $this->getHtmlName($fieldprefix) . '[]" class="form-control select-standard">'; $res .= '<OPTION VALUE="">' . Tools::atktext('select_none'); for ($i = 0, $_i = count($matches); $i < $_i; ++$i) { $res .= '<OPTION VALUE="' . $this->m_searchnodeInstance->primaryKey($matches[$i]) . '">' . $this->m_searchnodeInstance->descriptor($matches[$i]); } $res .= '</SELECT></td></tr>'; } } $res .= '</table>'; } } } return $res; } else { $record = ''; // clear the record so we always start with an empty // searchbox. return parent::edit($record, $fieldprefix, $mode); } }