00001 <?php
00002
00003
00013 function contact_site_page() {
00014 global $user;
00015
00016 if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) {
00017 $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
00018 }
00019 else {
00020 $output = drupal_get_form('contact_mail_page');
00021 }
00022
00023 return $output;
00024 }
00025
00026 function contact_mail_page() {
00027 global $user;
00028
00029 $form = $categories = array();
00030
00031 $result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category');
00032 while ($category = db_fetch_object($result)) {
00033 $categories[$category->cid] = $category->category;
00034 if ($category->selected) {
00035 $default_category = $category->cid;
00036 }
00037 }
00038
00039 if (count($categories) > 0) {
00040 $form['#token'] = $user->uid ? $user->name . $user->mail : '';
00041 $form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.'))));
00042 $form['name'] = array('#type' => 'textfield',
00043 '#title' => t('Your name'),
00044 '#maxlength' => 255,
00045 '#default_value' => $user->uid ? $user->name : '',
00046 '#required' => TRUE,
00047 );
00048 $form['mail'] = array('#type' => 'textfield',
00049 '#title' => t('Your e-mail address'),
00050 '#maxlength' => 255,
00051 '#default_value' => $user->uid ? $user->mail : '',
00052 '#required' => TRUE,
00053 );
00054 $form['subject'] = array('#type' => 'textfield',
00055 '#title' => t('Subject'),
00056 '#maxlength' => 255,
00057 '#required' => TRUE,
00058 );
00059 if (count($categories) > 1) {
00060
00061
00062 if (!isset($default_category)) {
00063 $default_category = t('- Please choose -');
00064 $categories = array($default_category) + $categories;
00065 }
00066 $form['cid'] = array('#type' => 'select',
00067 '#title' => t('Category'),
00068 '#default_value' => $default_category,
00069 '#options' => $categories,
00070 '#required' => TRUE,
00071 );
00072 }
00073 else {
00074
00075 $category_keys = array_keys($categories);
00076 $form['cid'] = array('#type' => 'value',
00077 '#value' => array_shift($category_keys),
00078 );
00079 }
00080 $form['message'] = array('#type' => 'textarea',
00081 '#title' => t('Message'),
00082 '#required' => TRUE,
00083 );
00084
00085
00086 if ($user->uid) {
00087 $form['copy'] = array('#type' => 'checkbox',
00088 '#title' => t('Send yourself a copy.'),
00089 );
00090 }
00091 else {
00092 $form['copy'] = array('#type' => 'value', '#value' => FALSE);
00093 }
00094 $form['submit'] = array('#type' => 'submit',
00095 '#value' => t('Send e-mail'),
00096 );
00097 }
00098 else {
00099 drupal_set_message(t('The contact form has not been configured. <a href="@add">Add one or more categories</a> to the form.', array('@add' => url('admin/build/contact/add'))), 'error');
00100 }
00101 return $form;
00102 }
00103
00107 function contact_mail_page_validate($form, &$form_state) {
00108 if (!$form_state['values']['cid']) {
00109 form_set_error('cid', t('You must select a valid category.'));
00110 }
00111 if (!valid_email_address($form_state['values']['mail'])) {
00112 form_set_error('mail', t('You must enter a valid e-mail address.'));
00113 }
00114 }
00115
00119 function contact_mail_page_submit($form, &$form_state) {
00120 global $language;
00121
00122 $values = $form_state['values'];
00123
00124
00125
00126 $from = $values['mail'];
00127
00128
00129 $contact = contact_load($values['cid']);
00130 $values['contact'] = $contact;
00131
00132
00133 drupal_mail('contact', 'page_mail', $contact['recipients'], language_default(), $values, $from);
00134
00135
00136 if ($values['copy']) {
00137 drupal_mail('contact', 'page_copy', $from, $language, $values, $from);
00138 }
00139
00140
00141 if ($contact['reply']) {
00142 drupal_mail('contact', 'page_autoreply', $from, $language, $values, $contact['recipients']);
00143 }
00144
00145 flood_register_event('contact');
00146 watchdog('mail', '%name-from sent an e-mail regarding %category.', array('%name-from' => $values['name'] . " [$from]", '%category' => $contact['category']));
00147 drupal_set_message(t('Your message has been sent.'));
00148
00149
00150
00151 $form_state['redirect'] = '';
00152 }
00153
00157 function contact_user_page($account) {
00158 global $user;
00159
00160 if (!valid_email_address($user->mail)) {
00161 $output = t('You need to provide a valid e-mail address to contact other users. Please update your <a href="@url">user information</a> and try again.', array('@url' => url("user/$user->uid/edit", array('query' => 'destination=' . drupal_get_destination()))));
00162 }
00163 else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) {
00164 $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
00165 }
00166 else {
00167 drupal_set_title(check_plain($account->name));
00168 $output = drupal_get_form('contact_mail_user', $account);
00169 }
00170
00171 return $output;
00172 }
00173
00174 function contact_mail_user(&$form_state, $recipient) {
00175 global $user;
00176 $form['#token'] = $user->name . $user->mail;
00177 $form['recipient'] = array('#type' => 'value', '#value' => $recipient);
00178 $form['from'] = array('#type' => 'item',
00179 '#title' => t('From'),
00180 '#value' => check_plain($user->name) . ' <' . check_plain($user->mail) . '>',
00181 );
00182 $form['to'] = array('#type' => 'item',
00183 '#title' => t('To'),
00184 '#value' => check_plain($recipient->name),
00185 );
00186 $form['subject'] = array('#type' => 'textfield',
00187 '#title' => t('Subject'),
00188 '#maxlength' => 50,
00189 '#required' => TRUE,
00190 );
00191 $form['message'] = array('#type' => 'textarea',
00192 '#title' => t('Message'),
00193 '#rows' => 15,
00194 '#required' => TRUE,
00195 );
00196 $form['copy'] = array('#type' => 'checkbox',
00197 '#title' => t('Send yourself a copy.'),
00198 );
00199 $form['submit'] = array('#type' => 'submit',
00200 '#value' => t('Send e-mail'),
00201 );
00202 return $form;
00203 }
00204
00208 function contact_mail_user_submit($form, &$form_state) {
00209 global $user, $language;
00210
00211 $account = $form_state['values']['recipient'];
00212
00213
00214 $to = $account->mail;
00215 $from = $user->mail;
00216
00217
00218 $values = $form_state['values'];
00219 $values['account'] = $account;
00220 $values['user'] = $user;
00221
00222
00223 drupal_mail('contact', 'user_mail', $to, user_preferred_language($account), $values, $from);
00224
00225
00226 if ($form_state['values']['copy']) {
00227 drupal_mail('contact', 'user_copy', $from, $language, $values, $from);
00228 }
00229
00230 flood_register_event('contact');
00231 watchdog('mail', '%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name));
00232 drupal_set_message(t('The message has been sent.'));
00233
00234
00235 $form_state['redirect'] = "user/$account->uid";
00236 }