';
echo '
';
echo '
';
echo '
';
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
if (!$rid){
echo $OUTPUT->heading(get_string('newentry','data'), 3);
}
/******************************************
* Regular expression replacement section *
******************************************/
if ($data->addtemplate){
$possiblefields = $DB->get_records('data_fields', array('dataid'=>$data->id), 'id');
$patterns = array();
$replacements = array();
///then we generate strings to replace
foreach ($possiblefields as $eachfield){
$field = data_get_field($eachfield, $data);
// To skip unnecessary calls to display_add_field().
if (strpos($data->addtemplate, "[[".$field->field->name."]]") !== false) {
// Replace the field tag.
$patterns[] = "[[".$field->field->name."]]";
$errors = '';
if (!empty($fieldnotifications[$field->field->name])) {
foreach ($fieldnotifications[$field->field->name] as $notification) {
$errors .= $OUTPUT->notification($notification);
}
}
$replacements[] = $errors . $field->display_add_field($rid, $datarecord);
}
// Replace the field id tag.
$patterns[] = "[[".$field->field->name."#id]]";
$replacements[] = 'field_'.$field->field->id;
}
if (core_tag_tag::is_enabled('mod_data', 'data_records')) {
$patterns[] = "##tags##";
$replacements[] = data_generate_tag_form($rid);
}
$newtext = str_ireplace($patterns, $replacements, $data->{$mode});
} else { //if the add template is not yet defined, print the default form!
echo data_generate_default_template($data, 'addtemplate', $rid, true, false);
$newtext = '';
}
foreach ($generalnotifications as $notification) {
echo $OUTPUT->notification($notification);
}
echo $newtext;
echo '
';
if ($rid) {
echo ' ';
} else {
if ((!$data->maxentries) ||
has_capability('mod/data:manageentries', $context) ||
(data_numentries($data) < ($data->maxentries - 1))) {
echo ' ';
}
}
echo '
';
echo $OUTPUT->box_end();
echo '