webmaster@1: variable_get('contact_hourly_threshold', 3))); webmaster@1: } webmaster@1: else { webmaster@1: $output = drupal_get_form('contact_mail_page'); webmaster@1: } webmaster@1: webmaster@1: return $output; webmaster@1: } webmaster@1: webmaster@1: function contact_mail_page() { webmaster@1: global $user; webmaster@1: webmaster@1: $form = $categories = array(); webmaster@1: webmaster@1: $result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category'); webmaster@1: while ($category = db_fetch_object($result)) { webmaster@1: $categories[$category->cid] = $category->category; webmaster@1: if ($category->selected) { webmaster@1: $default_category = $category->cid; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: if (count($categories) > 0) { webmaster@1: $form['#token'] = $user->uid ? $user->name . $user->mail : ''; webmaster@1: $form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.')))); webmaster@1: $form['name'] = array('#type' => 'textfield', webmaster@1: '#title' => t('Your name'), webmaster@1: '#maxlength' => 255, webmaster@1: '#default_value' => $user->uid ? $user->name : '', webmaster@1: '#required' => TRUE, webmaster@1: ); webmaster@1: $form['mail'] = array('#type' => 'textfield', webmaster@1: '#title' => t('Your e-mail address'), webmaster@1: '#maxlength' => 255, webmaster@1: '#default_value' => $user->uid ? $user->mail : '', webmaster@1: '#required' => TRUE, webmaster@1: ); webmaster@1: $form['subject'] = array('#type' => 'textfield', webmaster@1: '#title' => t('Subject'), webmaster@1: '#maxlength' => 255, webmaster@1: '#required' => TRUE, webmaster@1: ); webmaster@1: if (count($categories) > 1) { webmaster@1: // If there is more than one category available and no default category has been selected, webmaster@1: // prepend a default placeholder value. webmaster@1: if (!isset($default_category)) { webmaster@1: $default_category = t('- Please choose -'); webmaster@1: $categories = array($default_category) + $categories; webmaster@1: } webmaster@1: $form['cid'] = array('#type' => 'select', webmaster@1: '#title' => t('Category'), webmaster@1: '#default_value' => $default_category, webmaster@1: '#options' => $categories, webmaster@1: '#required' => TRUE, webmaster@1: ); webmaster@1: } webmaster@1: else { webmaster@1: // If there is only one category, store its cid. webmaster@1: $category_keys = array_keys($categories); webmaster@1: $form['cid'] = array('#type' => 'value', webmaster@1: '#value' => array_shift($category_keys), webmaster@1: ); webmaster@1: } webmaster@1: $form['message'] = array('#type' => 'textarea', webmaster@1: '#title' => t('Message'), webmaster@1: '#required' => TRUE, webmaster@1: ); webmaster@1: // We do not allow anonymous users to send themselves a copy webmaster@1: // because it can be abused to spam people. webmaster@1: if ($user->uid) { webmaster@1: $form['copy'] = array('#type' => 'checkbox', webmaster@1: '#title' => t('Send yourself a copy.'), webmaster@1: ); webmaster@1: } webmaster@1: else { webmaster@1: $form['copy'] = array('#type' => 'value', '#value' => FALSE); webmaster@1: } webmaster@1: $form['submit'] = array('#type' => 'submit', webmaster@1: '#value' => t('Send e-mail'), webmaster@1: ); webmaster@1: } webmaster@1: else { webmaster@1: drupal_set_message(t('The contact form has not been configured. Add one or more categories to the form.', array('@add' => url('admin/build/contact/add'))), 'error'); webmaster@1: } webmaster@1: return $form; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Validate the site-wide contact page form submission. webmaster@1: */ webmaster@1: function contact_mail_page_validate($form, &$form_state) { webmaster@1: if (!$form_state['values']['cid']) { webmaster@1: form_set_error('cid', t('You must select a valid category.')); webmaster@1: } webmaster@1: if (!valid_email_address($form_state['values']['mail'])) { webmaster@1: form_set_error('mail', t('You must enter a valid e-mail address.')); webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Process the site-wide contact page form submission. webmaster@1: */ webmaster@1: function contact_mail_page_submit($form, &$form_state) { webmaster@1: global $language; webmaster@1: webmaster@1: $values = $form_state['values']; webmaster@1: webmaster@1: // E-mail address of the sender: as the form field is a text field, webmaster@1: // all instances of \r and \n have been automatically stripped from it. webmaster@1: $from = $values['mail']; webmaster@1: webmaster@1: // Load category properties and save form values for email composition. webmaster@1: $contact = contact_load($values['cid']); webmaster@1: $values['contact'] = $contact; webmaster@1: webmaster@1: // Send the e-mail to the recipients using the site default language. webmaster@1: drupal_mail('contact', 'page_mail', $contact['recipients'], language_default(), $values, $from); webmaster@1: webmaster@1: // If the user requests it, send a copy using the current language. webmaster@1: if ($values['copy']) { webmaster@1: drupal_mail('contact', 'page_copy', $from, $language, $values, $from); webmaster@1: } webmaster@1: webmaster@1: // Send an auto-reply if necessary using the current language. webmaster@1: if ($contact['reply']) { webmaster@1: drupal_mail('contact', 'page_autoreply', $from, $language, $values, $contact['recipients']); webmaster@1: } webmaster@1: webmaster@1: flood_register_event('contact'); webmaster@1: watchdog('mail', '%name-from sent an e-mail regarding %category.', array('%name-from' => $values['name'] ." [$from]", '%category' => $contact['category'])); webmaster@1: drupal_set_message(t('Your message has been sent.')); webmaster@1: webmaster@1: // Jump to home page rather than back to contact page to avoid webmaster@1: // contradictory messages if flood control has been activated. webmaster@1: $form_state['redirect'] = ''; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Personal contact page. webmaster@1: */ webmaster@1: function contact_user_page($account) { webmaster@1: global $user; webmaster@1: webmaster@1: if (!valid_email_address($user->mail)) { webmaster@1: $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"))); webmaster@1: } webmaster@1: else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) { webmaster@1: $output = t('You cannot contact more than %number users per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3))); webmaster@1: } webmaster@1: else { webmaster@1: drupal_set_title(check_plain($account->name)); webmaster@1: $output = drupal_get_form('contact_mail_user', $account); webmaster@1: } webmaster@1: webmaster@1: return $output; webmaster@1: } webmaster@1: webmaster@1: function contact_mail_user(&$form_state, $recipient) { webmaster@1: global $user; webmaster@1: $form['#token'] = $user->name . $user->mail; webmaster@1: $form['recipient'] = array('#type' => 'value', '#value' => $recipient); webmaster@1: $form['from'] = array('#type' => 'item', webmaster@1: '#title' => t('From'), webmaster@1: '#value' => check_plain($user->name) .' <'. check_plain($user->mail) .'>', webmaster@1: ); webmaster@1: $form['to'] = array('#type' => 'item', webmaster@1: '#title' => t('To'), webmaster@1: '#value' => check_plain($recipient->name), webmaster@1: ); webmaster@1: $form['subject'] = array('#type' => 'textfield', webmaster@1: '#title' => t('Subject'), webmaster@1: '#maxlength' => 50, webmaster@1: '#required' => TRUE, webmaster@1: ); webmaster@1: $form['message'] = array('#type' => 'textarea', webmaster@1: '#title' => t('Message'), webmaster@1: '#rows' => 15, webmaster@1: '#required' => TRUE, webmaster@1: ); webmaster@1: $form['copy'] = array('#type' => 'checkbox', webmaster@1: '#title' => t('Send yourself a copy.'), webmaster@1: ); webmaster@1: $form['submit'] = array('#type' => 'submit', webmaster@1: '#value' => t('Send e-mail'), webmaster@1: ); webmaster@1: return $form; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Process the personal contact page form submission. webmaster@1: */ webmaster@1: function contact_mail_user_submit($form, &$form_state) { webmaster@1: global $user, $language; webmaster@1: webmaster@1: $account = $form_state['values']['recipient']; webmaster@1: webmaster@1: // Send from the current user to the requested user. webmaster@1: $to = $account->mail; webmaster@1: $from = $user->mail; webmaster@1: webmaster@1: // Save both users and all form values for email composition. webmaster@1: $values = $form_state['values']; webmaster@1: $values['account'] = $account; webmaster@1: $values['user'] = $user; webmaster@1: webmaster@1: // Send the e-mail in the requested user language. webmaster@1: drupal_mail('contact', 'user_mail', $to, user_preferred_language($account), $values, $from); webmaster@1: webmaster@1: // Send a copy if requested, using current page language. webmaster@1: if ($form_state['values']['copy']) { webmaster@1: drupal_mail('contact', 'user_copy', $from, $language, $values, $from); webmaster@1: } webmaster@1: webmaster@1: flood_register_event('contact'); webmaster@1: watchdog('mail', '%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name)); webmaster@1: drupal_set_message(t('The message has been sent.')); webmaster@1: webmaster@1: // Back to the requested users profile page. webmaster@1: $form_state['redirect'] = "user/$account->uid"; webmaster@1: }