--- contact.module.bak 2006-06-15 11:34:16.000000000 -0700
+++ contact.module 2006-06-15 14:43:41.000000000 -0700
@@ -38,6 +38,15 @@
}
/**
+ * Valid permissions for this module
+ * @return An array of valid permissions for the contact module
+ */
+function contact_perm() {
+ return array('send user contact');
+} // function contact_perm()
+
+
+/**
* Implementation of hook_menu().
*/
function contact_menu($may_cache) {
@@ -307,10 +316,10 @@
else if (!$account->contact && !$admin_access) {
$output = t('%name is not accepting e-mails.', array('%name' => $account->name));
}
- else if (!$user->uid) {
+ else if (!$user->uid && ! user_access('send user contact')) {
$output = t('Please login or register to send %name a message.', array('%login' => url('user/login'), '%register' => url('user/register'), '%name' => $account->name));
}
- else if (!valid_email_address($user->mail)) {
+ else if ($user->uid && !valid_email_address($user->mail)) {
$output = t('You need to provide a valid e-mail address to contact other users. Please update your user information and try again.', array('%url' => url("user/$user->uid/edit")));
}
else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
@@ -320,10 +329,19 @@
drupal_set_title($account->name);
$form['#token'] = $user->name . $user->mail;
- $form['from'] = array('#type' => 'item',
- '#title' => t('From'),
- '#value' => $user->name .' <'. $user->mail .'>',
- );
+ if ($user->uid) { //user is logged in so we'll use the account email address
+ $form['from'] = array('#type' => 'item',
+ '#title' => t('From'),
+ '#value' => $user->name .' <'. $user->mail .'>',
+ );
+ } else { //user is not logged in so we must use a textfield and validate it
+ $form['from'] = array('#type' => 'textfield',
+ '#title' => t('From (email)'),
+ '#required' => TRUE,
+ '#defulat_value' => '',
+ '#validate' => array('_contact_mail_user_validate' => $form['from']),
+ );
+ }
$form['to'] = array('#type' => 'item',
'#title' => t('To'),
'#value' => $account->name,
@@ -354,6 +372,13 @@
}
}
+function _contact_mail_user_validate($formelement) {
+ $from = $formelement['#value'];
+ if (!valid_email_address($from)) {
+ form_set_error('from', t("Item $from must be no higher than 2."));
+ }
+}
+
/**
* Process the personal contact page form submission.
*/
@@ -375,7 +400,7 @@
// Prepare all fields:
$to = $account->mail;
- $from = $user->mail;
+ $from = $edit['from'];
// Format the subject:
$subject = '['. variable_get('site_name', 'drupal') .'] '. $edit['subject'];