function user_user_settings_form_submit

7.x user.module user_user_settings_form_submit($form, $form_state)
6.x user.module user_user_settings_form_submit($form, $form_state)

Save values from our settings form into the user_settings table (or other tables), as appropriate.

File

modules/user/user.module, line 1151

Code

function user_user_settings_form_submit($form, $form_state) {
  global $user;

  $timezone = $form_state ['values']['timezone'];
  $hide_charts = $form_state ['values']['hide_charts'];
  $image_url = $form_state ['values']['image_url'];
  $default_student_load_tab = $form_state ['values']['default_student_load_tab'];
  $default_notification_method = $form_state ['values']['default_notification_method'];

  $phone_number = user_get_attribute($user->id, 'mobile_phone', '');
  $phone_number = engagements_convert_to_valid_phone_number($phone_number);

  $sms_opt_out = $form_state ['values']['sms_opt_out__' . $phone_number];

  if ($sms_opt_out === 'yes' && $phone_number) {

    db_query("DELETE FROM sms_do_not_txt WHERE phone_number = ?", array($phone_number));
    db_query("INSERT INTO sms_do_not_txt (user_id, cwid, phone_number, prev_notification_method, updated)
                    VALUES (?, ?, ?, ?, ?)", array($user->id, $user->cwid, $phone_number, $default_notification_method, time()));

    $default_notification_method = 'email';

  }
  else if ($sms_opt_out === 'no' && $phone_number) {
    // Opt back in!
    $notification_method = db_result(db_query("SELECT prev_notification_method FROM sms_do_not_txt WHERE phone_number = ?", array($phone_number)));
    if ($notification_method) {
      $default_notification_method = $notification_method;
    }

    db_query("DELETE FROM sms_do_not_txt WHERE phone_number = ?", array($phone_number));
  }

  // are we updating password?  (If we made it here, we have already passed validation, and may continue.
  $new_password1 = $form_state ['values']['new_password1'];

  if ($new_password1 != "") {
    $new_pass = user_hash_password($new_password1);

    db_query("UPDATE users 
                SET password = ? 
                WHERE user_id = ? ", array($new_pass, $user->id));
    fp_add_message(t("Password has been updated successfully."));
    watchdog("user_self_edit", "User with user_id @uid changed password", array("@uid" => $user->id));
  }



  user_set_setting($user->id, "timezone", $timezone);
  user_set_setting($user->id, "hide_charts", $hide_charts);
  user_set_setting($user->id, "default_student_load_tab", $default_student_load_tab);
  user_set_setting($user->id, "default_notification_method", $default_notification_method);
  user_set_setting($user->id, "sms_opt_out__" . $phone_number, $sms_opt_out);
  user_set_setting($user->id, "image_url", $image_url);


  fp_add_message(t("User settings saved successfully."));
  $values = $form_state ['values'];
  unset($values ['new_password1']);
  unset($values ['new_password2']);
  unset($values ['current_password']);
  watchdog("user_self_edit", "User with user_id @uid updated other values: @other", array("@uid" => $user->id, "@other" => ppm($values, TRUE)));

}