/** * Replace parts into the form template. * @param array $matches The matches found which preg_replace_callback is calling us for. * @return string What we want to replace this match with. */ function ReplaceEditorPart($matches) { global $session; // $matches[0] is the complete match switch ($matches[0]) { case "##form##": /** @todo It might be nice to construct a form ID */ return sprintf('<form method="POST" enctype="multipart/form-data" class="editor" id="%s">', $this->Id); case "##submit##": $action = $this->RecordAvailable ? 'update' : 'insert'; $submittype = $this->RecordAvailable ? translate('Apply Changes') : translate('Create'); return sprintf('<input type="hidden" name="_editor_action[%s]" value="%s"><input type="submit" class="submit" name="%s" value="%s">', $this->Id, $action, $this->SubmitName, $submittype); } // $matches[1] the match for the first subpattern // enclosed in '(...)' and so on $field_name = $matches[1]; $what_part = $matches[3]; $part3 = isset($matches[5]) ? $matches[5] : null; $value_field_name = $field_name; if (substr($field_name, 0, 4) == 'xxxx') { // Sometimes we will prepend 'xxxx' to the field name so that the field // name differs from the column name in the database. We also remove it // when it's submitted. $value_field_name = substr($field_name, 4); } $attributes = ""; if (isset($this->Fields[$field_name]) && is_object($this->Fields[$field_name])) { $field = $this->Fields[$field_name]; $attributes = $field->RenderAttributes(); } $field_value = isset($this->Record->{$value_field_name}) ? $this->Record->{$value_field_name} : null; switch ($what_part) { case "options": $currval = $part3; if (!isset($currval) && isset($field_value)) { $currval = $field_value; } if (isset($field->OptionList) && $field->OptionList != "") { $option_list = $field->OptionList; } else { @dbg_error_log('editor', "DBG: Current=%s, OptionQuery: %s", $currval, $field->LookupSql); $opt_qry = new AwlQuery($field->LookupSql); $option_list = EntryField::BuildOptionList($opt_qry, $currval, "FieldOptions: {$field_name}"); $field->OptionList = $option_list; } return $option_list; case "select": $currval = $part3; if (!isset($currval) && isset($field_value)) { $currval = $field_value; } if (isset($field->OptionList) && $field->OptionList != "") { $option_list = $field->OptionList; } else { @dbg_error_log('editor', 'DBG: Current=%s, OptionQuery: %s', $currval, $field->LookupSql); $opt_qry = new AwlQuery($field->LookupSql); $option_list = EntryField::BuildOptionList($opt_qry, $currval, 'FieldOptions: ' . $field_name); $field->OptionList = $option_list; } return '<select class="entry" name="' . $field_name . '"' . $attributes . '>' . $option_list . '</select>'; case "checkbox": if ($field_value === true) { $checked = ' CHECKED'; } else { switch ($field_value) { case 'f': case 'off': case 'false': case '': case '0': $checked = ""; break; default: $checked = ' CHECKED'; } } return '<input type="hidden" value="off" name="' . $field_name . '"><input class="entry" type="checkbox" value="on" name="' . $field_name . '"' . $checked . $attributes . '>'; case "input": $size = isset($part3) ? $part3 : 6; return "<input class=\"entry\" value=\"" . htmlspecialchars($field_value) . "\" name=\"{$field_name}\" size=\"{$size}\"{$attributes}>"; case "file": $size = isset($part3) ? $part3 : 30; return "<input type=\"file\" class=\"entry\" value=\"" . htmlspecialchars($field_value) . "\" name=\"{$field_name}\" size=\"{$size}\"{$attributes}>"; case "money": $size = isset($part3) ? $part3 : 8; return "<input class=\"money\" value=\"" . htmlspecialchars(sprintf("%0.2lf", $field_value)) . "\" name=\"{$field_name}\" size=\"{$size}\"{$attributes}>"; case "date": $size = isset($part3) ? $part3 : 10; return "<input class=\"date\" value=\"" . htmlspecialchars($field_value) . "\" name=\"{$field_name}\" size=\"{$size}\"{$attributes}>"; case "textarea": list($cols, $rows) = explode('x', $part3); return "<textarea class=\"entry\" name=\"{$field_name}\" rows=\"{$rows}\" cols=\"{$cols}\"{$attributes}>" . htmlspecialchars($field_value) . "</textarea>"; case "hidden": return sprintf("<input type=\"hidden\" value=\"%s\" name=\"{$field_name}\">", htmlspecialchars($field_value)); case "password": return sprintf("<input type=\"password\" value=\"%s\" name=\"{$field_name}\" size=\"10\">", htmlspecialchars($part3)); case "encval": case "enc": return htmlspecialchars($field_value); case "submit": $action = $this->RecordAvailable ? 'update' : 'insert'; return sprintf('<input type="hidden" name="_editor_action[%s]" value="%s"><input type="submit" class="submit" name="%s" value="%s">', $this->Id, $action, $this->SubmitName, $value_field_name); default: return str_replace("\n", "<br />", $field_value); } }
/** * A utility function for a submit button within a data entry table * @return string The HTML fragment to display a submit button for the form. */ function SubmitButton($fname, $fvalue, $attributes = '') { $field = new EntryField('submit', $fname, $this->_ParseAttributes('submit', $attributes), $fvalue); return $field->Render(); }