UP: Email users once they earn a certain number of %points', userpoints_translation()); break; } return $output; } function userpoints_email_userpoints($op, $new_points = 0, $uid = 0, $event = '') { switch($op) { case 'setting': $group = 'email'; $form[$group] = array( '#type' => 'fieldset', '#title' => t('Points for Roles'), '#description' => t('Points required to join each role. Enter 0 to ignore that role.'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form[$group][USERPOINTS_EMAIL_POINTS] = array( '#type' => 'textfield', '#title' => t('Points '), '#default_value' => variable_get(USERPOINTS_EMAIL_POINTS, 0), ); $form[$group][USERPOINTS_EMAIL_SUBJECT] = array( '#type' => 'textarea', '#title' => t('Subject of email to sent.'), '#default_value' => variable_get(USERPOINTS_EMAIL_SUBJECT, USERPOINTS_EMAIL_SUBJECT_DEFAULT), '#width' => 70, '#lines' => 5, ); $form[$group][USERPOINTS_EMAIL_TEXT] = array( '#type' => 'textarea', '#title' => t('Text of email to sent.'), '#default_value' => variable_get(USERPOINTS_EMAIL_TEXT, USERPOINTS_EMAIL_TEXT_DEFAULT), '#description' => t('Body of the email to send. %username and %points are replaced with values.'), '#width' => 70, '#lines' => 5, ); return $form; break; case 'points after': $current_points = userpoints_get_current_points($uid); if ($new_points > 0) { // Don't do anything if there are no points awarded _userpoints_email_process($uid, $current_points, $new_points); } break; } } function _userpoints_email_process($uid = 0, $current_points = 0, $new_points = 0) { $threshold = variable_get(USERPOINTS_EMAIL_POINTS, 0); $subject = variable_get(USERPOINTS_EMAIL_SUBJECT, USERPOINTS_EMAIL_SUBJECT_DEFAULT); $body = variable_get(USERPOINTS_EMAIL_TEXT, USERPOINTS_EMAIL_TEXT_DEFAULT); if ($threshold && $current_points >= $threshold) { $user = user_load(array('uid' => $uid)); $from = variable_get('site_mail', ini_get('sendmail_from')); $headers = "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from"; user_mail($user->mail, $subject, t($body, array('%username' => $user->name, '%points' => $current_points)), $headers); } }