function init() {
/// Param 1 for menu type is the options
- if (($options = explode("\n", $this->field->param1)) === false) {
+ if (empty($this->field->param1)) {
+ $options = array();
+ } else if (($options = explode("\n", $this->field->param1)) === false) {
$options = array();
}
$this->options = $options;
require_once('index_category_form.php');
- $categoryform = new category_form(null, compact('category'));
+ $categoryform = new category_form(null);
+ $categoryform->set_data($category);
if ($categoryform->is_cancelled()) {
redirect($redirect);
exit;
} elseif ( $action == 'editfield' ) {
require_once('index_field_form.php');
- $fieldform = new field_form(null, compact('field'));
+ $fieldform = new field_form(null, $field->datatype);
+ $fieldform->set_data($field);
if ($fieldform->is_cancelled()) {
redirect($redirect);
exit;
function definition () {
global $USER, $CFG;
- $mform =& $this->_form;
- $renderer =& $mform->defaultRenderer();
- $category = $this->_customdata['category'];
+ $mform =& $this->_form;
$strrequired = get_string('required');
/// Add some extra hidden fields
- $mform->addElement('hidden', 'id', $category->id);
+ $mform->addElement('hidden', 'id');
$mform->addElement('hidden', 'action', 'editcategory');
- $mform->addElement('hidden', 'sesskey', $USER->sesskey);
$mform->addElement('text', 'name', get_string('profilecategoryname', 'admin'), 'maxlength="255" size="30"');
$mform->setType('name', PARAM_MULTILANG);
$mform->addRule('name', $strrequired, 'required', null, 'client');
- $mform->setDefault('name', $category->name);
$this->add_action_buttons(true);
} /// End of function
- function definition_after_data () {
- /// nothing yet
- }
-
-
/// perform some moodle validation
function validation ($data) {
global $CFG;
$data = (object)$data;
$err = array();
+
+ $category = get_record('user_info_category', 'id', $data->id);
/// Check the name is unique
- if (($category = get_record('user_info_category', 'name', $data->name)) and ($category->id <> $data->id)) {
+ if ($category and ($category->name !== $data->name) and (record_exists('user_info_category', 'name', $data->name))) {
$err['name'] = get_string('profilecategorynamenotunique', 'admin');
}
function definition () {
global $USER, $CFG;
- $mform =& $this->_form;
- $renderer =& $mform->defaultRenderer();
- $field = $this->_customdata['field'];
+ $mform =& $this->_form;
+ $fieldtype = $this->_customdata;
$strrequired = get_string('required');
/// Add some extra hidden fields
- $mform->addElement('hidden', 'id', $field->id);
+ $mform->addElement('hidden', 'id');
$mform->addElement('hidden', 'action', 'editfield');
- $mform->addElement('hidden', 'type', $field->datatype);
- $mform->addElement('hidden', 'oldcategory', $field->categoryid);
- $mform->addElement('hidden', 'datatype', $field->datatype);
- $mform->addElement('hidden', 'sesskey', $USER->sesskey);
+ $mform->addElement('hidden', 'type', $fieldtype);
+ $mform->addElement('hidden', 'oldcategory');
+ $mform->addElement('hidden', 'datatype');
+ $mform->addElement('hidden', 'sesskey');
/// Everything else is dependant on the data type
- require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
- $newfield = 'profile_field_'.$field->datatype;
- $formfield = new $newfield($field->id);
+ require_once($CFG->dirroot.'/user/profile/field/'.$fieldtype.'/field.class.php');
+ $newfield = 'profile_field_'.$fieldtype;
+ $formfield = new $newfield();
$formfield->edit_field($mform);
- /// override the defaults with the user settings
- $this->set_data($field);
$this->add_action_buttons(true);
global $CFG;
$data = (object)$data;
- $field = $this->_customdata['field'];
+ $fieldtype = $this->_customdata;
/// Everything else is dependant on the data type
- require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
- $newfield = 'profile_field_'.$field->datatype;
- $formfield = new $newfield($field->id);
+ require_once($CFG->dirroot.'/user/profile/field/'.$fieldtype.'/field.class.php');
+ $newfield = 'profile_field_'.$fieldtype;
+ $formfield = new $newfield();
$err = $formfield->edit_validate($data);
if (count($err) == 0){
$form->addElement('selectyesno', 'locked', get_string('profilelocked', 'admin'));
$form->setType('locked', PARAM_BOOL);
- unset($choices);
+ $choices = array();
$choices[0] = get_string('profilevisiblenone', 'admin');
$choices[1] = get_string('profilevisibleprivate', 'admin');
$choices[2] = get_string('profilevisibleall', 'admin');
$form->setDefault('visible', 2);
$form->setHelpButton('visible', array('profilevisible', get_string('profilevisible','admin')));
- unset($choices);
+ $choices = array();
$choices = profile_list_categories();
$form->addElement('select', 'categoryid', get_string('profilecategory', 'admin'), $choices);
$form->setType('categoryid', PARAM_INT);