Example #1
0
/**
 * Callback to enumerate possible user field types
 *
 */
function enumerate_types($selected = '')
{
    $options = '<option value="">All</option>';
    foreach (Userfield::get_types() as $type_code => $type_name) {
        $options .= '<option value="' . $type_code . '" ';
        if ($type_code == $selected) {
            $options .= '"selected" ';
        }
        $options .= '>' . $type_name . '</option>';
    }
    return $options;
}
Example #2
0
 case 'edit':
     // Check permission:
     $current_User->check_perm('users', 'edit', true);
     // Make sure we got an ufdf_ID:
     param('ufdf_ID', 'integer', true);
     break;
 case 'create':
     // Record new Userfield
 // Record new Userfield
 case 'create_new':
     // Record Userfield and create new
 // Record Userfield and create new
 case 'create_copy':
     // Record Userfield and create similar
     // Insert new user field...:
     $edited_Userfield = new Userfield();
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('userfield');
     // Check permission:
     $current_User->check_perm('users', 'edit', true);
     // load data from request
     if ($edited_Userfield->load_from_Request()) {
         // We could load data from form without errors:
         // While inserting into DB, ID property of Userfield object will be set to autogenerated ID
         // So far as we set ID manualy, we need to preserve this value
         // When assignment of wrong value will be fixed, we can skip this
         $entered_userfield_id = $edited_Userfield->ID;
         // Insert in DB:
         $DB->begin();
         // because of manual assigning ID,
         // member function Userfield::dbexists() is overloaded for proper functionality
Example #3
0
 /**
  * Get user field group ID by name AND Try to create new if it doesn't exist yet
  *
  * @param string Field code
  * @param string Field group name
  * @param string Field name
  * @param string Field type: 'text', 'word', 'email', 'number', 'phone', 'url'
  * @return integer Field ID
  */
 function userfield_get_by_code($field_code, $field_group_name, $field_name, $field_type)
 {
     if (is_null($this->userfields)) {
         // Load all user fields in cache on first time request:
         global $DB;
         $SQL = new SQL();
         $SQL->SELECT('ufdf_ID, ufdf_code');
         $SQL->FROM('T_users__fielddefs');
         $this->userfields = $DB->get_assoc($SQL->get(), 'Load all user fields in cache array of LDAP plugin');
         // Convert all user field codes to lowercase:
         $this->userfields = array_map('utf8_strtolower', $this->userfields);
     }
     // Code MUST be lowercase ASCII only:
     $field_code = utf8_strtolower($field_code);
     // Check if requested user field code already exists in DB:
     $field_ID = array_search($field_code, $this->userfields);
     if ($field_ID === false) {
         // No user field in DB, Try to create new:
         $field_group_ID = $this->userfield_get_group_by_name($field_group_name);
         if (!$field_group_ID) {
             // Some error on creating new user field group, We cannot create new user field without group:
             // Exit here:
             $this->debug_log(sprintf('Skip a creating of new user field "%s" because new group "%s" cannot be created.', $field_name, $field_group_name));
             return;
         }
         // Load Userfield class:
         load_class('users/model/_userfield.class.php', 'Userfield');
         $Userfield = new Userfield();
         $Userfield->set('code', $field_code);
         $Userfield->set('ufgp_ID', $field_group_ID);
         $Userfield->set('name', $field_name);
         $Userfield->set('type', $field_type);
         $Userfield->set('order', $Userfield->get_last_order($field_group_ID));
         $Userfield->set('duplicated', 'forbidden');
         if ($Userfield->dbinsert()) {
             // New user field has been created
             $field_ID = $Userfield->ID;
             // Add new user field code in cache array:
             $this->userfields[$field_ID] = $field_code;
             $this->debug_log(sprintf('New user field "%s" has been created in system', $field_name));
         }
     }
     return $field_ID;
 }