/** * add extra HTML after the form on the "Add entry" page */ function print_after_form() { global $DB, $PAGE, $USER; if ($this->setdefaultvalues) { // get string manager $strman = get_string_manager(); // set path to js library $module = $this->get_module_js(); // get user profile fields that are available $profilefields = $this->get_profile_fields(); $select = 'dataid = ?'; $params = array($this->data->id); $defaults = array(); if ($fields = $DB->get_records_select_menu('data_fields', $select, $params, 'id', 'id, name')) { foreach ($fields as $id => $field) { $field = $this->get_profile_field($field); if (in_array($field, $profilefields) && $USER->{$field}) { $value = $USER->{$field}; if ($field == 'country' && $strman->string_exists($value, 'countries')) { $value = $strman->get_string($value, 'countries', null, 'en'); } // add js call to set default value for this field (in browser) $options = array('id' => 'field_' . $id, 'value' => $value); $PAGE->requires->js_init_call('M.datafield_admin.set_default_value', $options, false, $module); } } } } if ($this->is_viewable) { if ($this->subfield) { $this->subfield->print_after_form(); } else { parent::print_after_form(); } } }