You are here

function pcp_action_redirect_user_to_editform in Profile Complete Percent 6.2

Same name and namespace in other branches
  1. 5 pcp.module \pcp_action_redirect_user_to_editform()

Rules Action - Redirect the user to his profile edit page

Parameters

$user: The user for which the action is performed.

$settings: The configured settings of the rule action

Return value

Perform the redirection

See also

pcp_rules_action_info

File

./pcp.module, line 629
Allows users with valid permissions to tag profile fields created from the profile module as required fields for a users profile to be considered complete.

Code

function pcp_action_redirect_user_to_editform($user, $settings) {
  $settings = pcp_get_condition_settings('pcp_condition_check_profile_fields_completeness');
  $edit_categories = array();
  profile_load_profile($user);
  if ($settings['profile_fields']) {
    $result = db_query("SELECT fid, title, name, category FROM {profile_fields} WHERE fid IN (%d)", implode(', ', $settings['profile_fields']));
    while ($field = db_fetch_object($result)) {
      if (!$user->{$field->name}) {
        drupal_set_message(t('Please fill in "<i>' . $field->category . '</i>".'), 'warning');

        // Necessary to avoid redirect loop or malfunctioning
        unset($_REQUEST['destination']);
        unset($_REQUEST['edit']['destination']);
        drupal_goto('user/' . $user->uid . '/edit/' . $field->category);
      }
    }
  }
}