diff --git a/user/profile/field/menu/field.class.php b/user/profile/field/menu/field.class.php index 584e083e6d3..72612ec7263 100644 --- a/user/profile/field/menu/field.class.php +++ b/user/profile/field/menu/field.class.php @@ -4,7 +4,9 @@ class profile_field_menu extends profile_field_base { 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; diff --git a/user/profile/index.php b/user/profile/index.php index ec55cb86729..76b4eefe336 100644 --- a/user/profile/index.php +++ b/user/profile/index.php @@ -110,7 +110,8 @@ if ( ($action == 'editcategory' )) { 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; @@ -153,7 +154,8 @@ if ( ($action == 'editcategory' )) { } 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; diff --git a/user/profile/index_category_form.php b/user/profile/index_category_form.php index 596db12a933..d636365efb8 100644 --- a/user/profile/index_category_form.php +++ b/user/profile/index_category_form.php @@ -8,41 +8,34 @@ class category_form extends moodleform { 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'); } diff --git a/user/profile/index_field_form.php b/user/profile/index_field_form.php index 979348bb94a..4189a0366fa 100644 --- a/user/profile/index_field_form.php +++ b/user/profile/index_field_form.php @@ -8,29 +8,26 @@ class field_form extends moodleform { 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); @@ -47,12 +44,12 @@ class field_form extends moodleform { 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){ diff --git a/user/profile/lib.php b/user/profile/lib.php index 552ffea9fc5..ae7895efa3c 100644 --- a/user/profile/lib.php +++ b/user/profile/lib.php @@ -212,7 +212,7 @@ class profile_field_base { $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'); @@ -221,7 +221,7 @@ class profile_field_base { $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);