You are here

function profile_form_profile in Drupal 4

Same name and namespace in other branches
  1. 5 modules/profile/profile.module \profile_form_profile()
  2. 6 modules/profile/profile.module \profile_form_profile()
1 call to profile_form_profile()
profile_user in modules/profile.module
Implementation of hook_user().

File

modules/profile.module, line 606
Support for configurable user profiles.

Code

function profile_form_profile($edit, $user, $category) {
  if (arg(0) == 'user' && arg(1) == 'register') {
    $result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d AND register = 1 ORDER BY category, weight', PROFILE_HIDDEN);
  }
  elseif (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'create') {
    $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
  }
  elseif (user_access('administer users')) {
    $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') ORDER BY weight", $category);
  }
  else {
    $result = db_query("SELECT * FROM {profile_fields} WHERE visibility != %d AND LOWER(category) = LOWER('%s') ORDER BY weight", PROFILE_HIDDEN, $category);

    // Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
  }
  $w = 1;
  while ($field = db_fetch_object($result)) {
    $category = $field->category;
    if (!isset($fields[$category])) {
      $fields[$category] = array(
        '#type' => 'fieldset',
        '#title' => check_plain($category),
        '#weight' => $w++,
      );
    }
    switch ($field->type) {
      case 'textfield':
      case 'url':
        $fields[$category][$field->name] = array(
          '#type' => 'textfield',
          '#title' => check_plain($field->title),
          '#default_value' => $edit[$field->name],
          '#maxlength' => 255,
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'textarea':
        $fields[$category][$field->name] = array(
          '#type' => 'textarea',
          '#title' => check_plain($field->title),
          '#default_value' => $edit[$field->name],
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'list':
        $fields[$category][$field->name] = array(
          '#type' => 'textarea',
          '#title' => check_plain($field->title),
          '#default_value' => $edit[$field->name],
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'checkbox':
        $fields[$category][$field->name] = array(
          '#type' => 'checkbox',
          '#title' => check_plain($field->title),
          '#default_value' => $edit[$field->name],
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'selection':
        $options = $field->required ? array() : array(
          '--',
        );
        $lines = split("[,\n\r]", $field->options);
        foreach ($lines as $line) {
          if ($line = trim($line)) {
            $options[$line] = $line;
          }
        }
        $fields[$category][$field->name] = array(
          '#type' => 'select',
          '#title' => check_plain($field->title),
          '#default_value' => $edit[$field->name],
          '#options' => $options,
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'date':
        $fields[$category][$field->name] = array(
          '#type' => 'date',
          '#title' => check_plain($field->title),
          '#default_value' => $edit[$field->name],
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
    }
  }
  return $fields;
}