Example #1
0
 public function definition()
 {
     global $USER, $CFG, $COURSE;
     if ($this->_customdata['obj']) {
         $this->set_data($this->_customdata['obj']);
         $disabled = true;
     } else {
         $disabled = false;
     }
     $mform =& $this->_form;
     $strgeneral = get_string('general');
     $strrequired = get_string('required');
     $bundle = NULL;
     /// Add some extra hidden fields
     $mform->addElement('hidden', 'id');
     $mform->addElement('hidden', 'search');
     $mform->addElement('text', 'idnumber', get_string('idnumber'));
     $mform->setType('idnumber', PARAM_TEXT);
     $mform->addRule('idnumber', null, 'maxlength', 255);
     $mform->setHelpButton('idnumber', array('userform/idnumber', get_string('idnumber'), 'block_curr_admin'));
     $username_group = array();
     if (empty($disabled)) {
         $mform->addRule('idnumber', null, 'required', null, 'client');
         $username_group[] =& $mform->createElement('text', 'username', get_string('username'));
         $username_group[] =& $mform->createElement('checkbox', 'id_same_user', null, get_string('id_same_as_user', 'block_curr_admin'));
         $mform->disabledIf('username_group', 'id_same_user', 'checked');
         $mform->addGroup($username_group, 'username_group', get_string('username'), ' ', false);
         $mform->addRule('username_group', $strrequired, 'required', null, 'client');
     } else {
         $mform->freeze('idnumber');
         $username_group[] =& $mform->createElement('static', 'username');
         $mform->addGroup($username_group, 'username_group', get_string('username'), ' ', false);
         $mform->freeze('username_group');
     }
     $mform->addGroupRule('username_group', array('username' => array(array(null, 'maxlength', 100))));
     $mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'));
     $mform->setType('newpassword', PARAM_TEXT);
     $mform->addRule('newpassword', null, 'maxlength', 25);
     $mform->addElement('text', 'firstname', get_string('userfirstname', 'block_curr_admin'));
     $mform->setType('firstname', PARAM_TEXT);
     $mform->addRule('firstname', $strrequired, 'required', null, 'client');
     $mform->addRule('firstname', null, 'maxlength', 100);
     $mform->addElement('text', 'lastname', get_string('userlastname', 'block_curr_admin'));
     $mform->setType('lastname', PARAM_TEXT);
     $mform->addRule('lastname', $strrequired, 'required', null, 'client');
     $mform->addRule('lastname', null, 'maxlength', 100);
     $mform->addElement('text', 'mi', get_string('usermi', 'block_curr_admin'));
     $mform->setType('mi', PARAM_TEXT);
     $mform->addRule('mi', null, 'maxlength', 100);
     $mform->addElement('text', 'email', get_string('email', 'block_curr_admin'));
     $mform->setType('email', PARAM_TEXT);
     $mform->addRule('email', null, 'email', null, 'client');
     $mform->addRule('email', null, 'required', null, 'client');
     $mform->addRule('email', null, 'maxlength', 100);
     $mform->addElement('text', 'email2', get_string('email2', 'block_curr_admin'));
     $mform->setType('email2', PARAM_TEXT);
     $mform->addRule('email2', null, 'email', null, 'client');
     $mform->addRule('email2', null, 'maxlength', 100);
     $mform->addElement('text', 'address', get_string('useraddress', 'block_curr_admin'));
     $mform->setType('address', PARAM_TEXT);
     $mform->addRule('address', null, 'maxlength', 100);
     $mform->addElement('text', 'address2', get_string('useraddress2', 'block_curr_admin'));
     $mform->setType('address2', PARAM_TEXT);
     $mform->addRule('address2', null, 'maxlength', 100);
     $mform->addElement('text', 'city', get_string('usercity', 'block_curr_admin'));
     $mform->setType('city', PARAM_TEXT);
     $mform->addRule('city', null, 'maxlength', 100);
     $mform->addElement('text', 'state', get_string('userstate', 'block_curr_admin'));
     $mform->setType('state', PARAM_TEXT);
     $mform->addRule('state', null, 'maxlength', 100);
     $mform->addElement('text', 'postalcode', get_string('userpostalcode', 'block_curr_admin'));
     $mform->setType('postalcode', PARAM_TEXT);
     $mform->addRule('postalcode', null, 'maxlength', 32);
     $country = cm_get_list_of_countries();
     $default_country[''] = get_string('selectacountry');
     $country = array_merge($default_country, $country);
     $mform->addElement('select', 'country', get_string('country'), $country);
     $mform->addRule('country', $strrequired, 'required', null, 'client');
     $mform->addElement('text', 'phone', get_string('phone'));
     $mform->setType('phone', PARAM_TEXT);
     $mform->addRule('phone', null, 'maxlength', 100);
     $mform->addElement('text', 'phone2', get_string('phone2', 'block_curr_admin'));
     $mform->setType('phone2', PARAM_TEXT);
     $mform->addRule('phone2', null, 'maxlength', 100);
     $mform->addElement('text', 'fax', get_string('fax', 'block_curr_admin'));
     $mform->setType('fax', PARAM_TEXT);
     $mform->addRule('fax', null, 'maxlength', 100);
     $bdaygroup = array();
     $days[''] = get_string('selectdays', 'block_curr_admin');
     for ($i = 1; $i <= 31; $i++) {
         $days[$i] = $i;
     }
     $months[''] = get_string('selectmonths', 'block_curr_admin');
     for ($i = 1; $i <= 12; $i++) {
         $months[$i] = userdate(gmmktime(12, 0, 0, $i, 15, 2000), "%B");
     }
     $years[''] = get_string('selectyears', 'block_curr_admin');
     for ($i = 1900; $i <= 2020; $i++) {
         $years[$i] = $i;
     }
     $bdaygroup[] =& $mform->createElement('select', 'birthday', get_string('day', 'block_curr_admin'), $days, '', true);
     $bdaygroup[] =& $mform->createElement('select', 'birthmonth', get_string('month', 'block_curr_admin'), $months, '', true);
     $bdaygroup[] =& $mform->createElement('select', 'birthyear', get_string('year', 'block_curr_admin'), $years, '', true);
     $mform->addGroup($bdaygroup, 'birthdate', get_string('userbirthdate', 'block_curr_admin'), ' ', false);
     //        $mform->addElement('date_selector', 'birthdate', get_string('userbirthdate', 'block_curr_admin')); //TODO: the bdaygroup stuff with this but need to update the pages as well
     $radioarray = array();
     $radioarray[] =& $mform->createElement('radio', 'gender', '', get_string('male', 'block_curr_admin'), 'M');
     $radioarray[] =& $mform->createElement('radio', 'gender', '', get_string('female', 'block_curr_admin'), 'F');
     $mform->addGroup($radioarray, 'gender', get_string('usergender', 'block_curr_admin'), ' ', false);
     $language = cm_get_list_of_languages();
     $mform->addElement('select', 'language', get_string('userlanguage', 'block_curr_admin'), $language);
     $mform->setDefault('language', 'English');
     $mform->setHelpButton('language', array('userform/language', get_string('userlanguage', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('text', 'transfercredits', get_string('transfercredits', 'block_curr_admin'));
     $mform->setType('transfercredits', PARAM_INT);
     $mform->setHelpButton('transfercredits', array('userform/transfercredits', get_string('transfercredits', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('textarea', 'comments', get_string('usercomments', 'block_curr_admin'));
     $mform->setType('comments', PARAM_CLEAN);
     $mform->setHelpButton('comments', array('userform/comments', get_string('usercomments', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('textarea', 'notes', get_string('notes', 'block_curr_admin'));
     $mform->setType('notes', PARAM_CLEAN);
     $mform->setHelpButton('notes', array('userform/notes', get_string('notes', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('advcheckbox', 'inactive', get_string('inactive', 'block_curr_admin'));
     $mform->setType('inactive', PARAM_TEXT);
     $mform->setHelpButton('inactive', array('userform/inactive', get_string('inactive', 'block_curr_admin'), 'block_curr_admin'));
     $fields = field::get_for_context_level('user');
     $fields = $fields ? $fields : array();
     $lastcat = null;
     $context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('user', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM);
     require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php';
     foreach ($fields as $rec) {
         $field = new field($rec);
         if (!isset($field->owners['manual'])) {
             continue;
         }
         if ($lastcat != $rec->categoryid) {
             $lastcat = $rec->categoryid;
             $mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname));
         }
         manual_field_add_form_element($this, $context, $field, !$field->multivalued);
         // ELIS-4000: Multi-valued fields require custom validation in form
     }
     if ($this->_customdata['obj']) {
         $this->set_data($this->_customdata['obj']);
     }
     $this->add_action_buttons();
 }
Example #2
0
 /**
  * Creates known user filter if present
  *
  * @uses $CURMAN
  * @uses $USER
  * @param string $fieldname
  * @param boolean $advanced
  * @return object filter
  */
 function get_field($fieldname, $advanced)
 {
     global $CURMAN, $USER;
     switch ($fieldname) {
         case 'username':
             return new user_filter_text('username', get_string('username'), $advanced, 'usr.username');
         case 'realname':
             return new cm_user_filter_text_OR('realname', get_string('fullname'), $advanced, 'fullname', array(sql_concat('usr.firstname', "' '", "COALESCE(usr.mi, '')", "' '", 'usr.lastname'), sql_concat('usr.firstname', "' '", 'usr.lastname')));
         case 'lastname':
             return new user_filter_text('lastname', get_string('lastname'), $advanced, 'usr.lastname');
         case 'firstname':
             return new user_filter_text('firstname', get_string('firstname'), $advanced, 'usr.firstname');
         case 'idnumber':
             return new user_filter_text('idnumber', get_string('idnumber'), $advanced, 'usr.idnumber');
         case 'email':
             return new user_filter_text('email', get_string('email'), $advanced, 'usr.email');
         case 'city':
             return new user_filter_text('city', get_string('city'), $advanced, 'usr.city');
         case 'country':
             return new user_filter_select('country', get_string('country'), $advanced, 'country', cm_get_list_of_countries(), $USER->country);
         case 'timecreated':
             return new user_filter_date('timecreated', get_string('createtime', 'block_curr_admin'), $advanced, 'usr.timecreated');
         case 'language':
             return new user_filter_select('language', get_string('preferredlanguage', 'block_curr_admin'), $advanced, 'usr.language', cm_get_list_of_languages());
         case 'clusterid':
             //obtain a mapping of cluster ids to names for all clusters
             $clusters = cm_get_list_of_clusters();
             //use a special filter class to filter users based on clusters
             return new cm_user_cluster_filter('clusterid', get_string('usercluster', 'block_curr_admin'), $advanced, 'usr.id', $clusters);
         case 'curriculumid':
             //obtain a mapping of curriculum ids to names for all curricula
             $choices = curriculum_get_menu();
             //use a special filter class to filter users based on curricula
             return new cm_user_curriculum_filter('curriculumid', get_string('usercurricula', 'block_curr_admin'), $advanced, 'usr.id', $choices);
         case 'inactive':
             $inactive_options = array(get_string('o_active', 'block_curr_admin'), get_string('all'), get_string('o_inactive', 'block_curr_admin'));
             return new cm_show_inactive_filter('inactive', get_string('showinactive', 'block_curr_admin'), $advanced, 'usr.inactive', $inactive_options);
         default:
             if (strncmp($fieldname, 'field_', 6) === 0) {
                 $f = substr($fieldname, 6);
                 $rec = new field($CURMAN->db->get_record(FIELDTABLE, 'shortname', $f));
                 return new cm_custom_field_filter($fieldname, $rec->shortname, $advanced, $rec);
             }
             return null;
     }
 }
 /**
  * Make Custom Filter Options
  *
  * This function handles filters that require custom values (languages, countries, etc).
  *
  * @param string $group  The index of the group to which the sub filter belongs to.
  * @param string $name   The name of the sub filter to process.
  * @param array  $help   An array representing the help icon for the filter
  * @return array The customized options for the selected sub-filter
  */
 function make_filter_options_custom($options, $group, $name)
 {
     switch ($name) {
         case 'fullname':
             //combine the firstname and lastname into a fullname field
             $firstname = $this->tables[$group]['crlm_user'] . '.firstname';
             $lastname = $this->tables[$group]['crlm_user'] . '.lastname';
             $options['dbfield'] = sql_fullname($firstname, $lastname);
             $options['talias'] = '';
             //todo: find a better way to do this
             $this->fieldtofiltermap[$group][$options['dbfield']] = generalized_filter_elisuserprofile::filtertypetext;
             break;
         case 'country':
             //populate dropdown entries for countries
             $countries = cm_get_list_of_countries();
             $options['choices'] = $countries;
             break;
         case 'language':
             //populate dropdown entries for languages
             $languages = cm_get_list_of_languages();
             $options['choices'] = $languages;
             break;
         case 'inactive':
             //populate dropdown entries for inactive flag filtering options
             $options['choices'] = array('0' => get_string('no'), 1 => get_string('yes'));
             $options['numeric'] = 1;
             break;
     }
     $pos = strpos($name, 'customfield-');
     if ($pos !== false) {
         $options['contextlevel'] = context_level_base::get_custom_context_level('user', 'block_curr_admin');
     }
     return $options;
 }