| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
function contact_site_page() {
|
| 14 |
if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) {
|
| 15 |
$output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
|
| 16 |
}
|
| 17 |
elseif (!db_query("SELECT COUNT(cid) FROM {contact}")->fetchField()) {
|
| 18 |
if (user_access('administer site-wide contact form')) {
|
| 19 |
$output = t('The contact form has not been configured. <a href="@add">Add one or more categories</a> to the form.', array('@add' => url('admin/structure/contact/add')));
|
| 20 |
}
|
| 21 |
|
| 22 |
return drupal_not_found();
|
| 23 |
|
| 24 |
}
|
| 25 |
|
| 26 |
$output = drupal_get_form('contact_site_form');
|
| 27 |
|
| 28 |
|
| 29 |
return $output;
|
| 30 |
}
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
function contact_site_form() {
|
| 36 |
global $user;
|
| 37 |
|
| 38 |
$categories = db_query("SELECT cid, category FROM {contact} ORDER BY weight, category")->fetchAllKeyed();
|
| 39 |
$default_category = (int) db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField();
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
if (!$default_category) {
|
| 44 |
if (count($categories) > 1) {
|
| 45 |
$categories = array(0 => t('- Please choose -')) + $categories;
|
| 46 |
}
|
| 47 |
|
| 48 |
$default_category = key($categories);
|
| 49 |
|
| 50 |
}
|
| 51 |
|
| 52 |
$form['#token'] = $user->uid ? $user->name . $user->mail : '';
|
| 53 |
$form['name'] = array(
|
| 54 |
'#type' => 'textfield',
|
| 55 |
'#title' => t('Your name'),
|
| 56 |
'#maxlength' => 255,
|
| 57 |
'#default_value' => $user->uid ? $user->name : '',
|
| 58 |
'#required' => TRUE,
|
| 59 |
|
| 60 |
$form['mail'] = array(
|
| 61 |
'#type' => 'textfield',
|
| 62 |
'#title' => t('Your e-mail address'),
|
| 63 |
'#maxlength' => 255,
|
| 64 |
'#default_value' => $user->uid ? $user->mail : '',
|
| 65 |
'#required' => TRUE,
|
| 66 |
|
| 67 |
$form['subject'] = array(
|
| 68 |
'#type' => 'textfield',
|
| 69 |
'#title' => t('Subject'),
|
| 70 |
'#maxlength' => 255,
|
| 71 |
'#required' => TRUE,
|
| 72 |
|
| 73 |
$form['cid'] = array(
|
| 74 |
'#type' => 'select',
|
| 75 |
'#title' => t('Category'),
|
| 76 |
'#default_value' => $default_category,
|
| 77 |
'#options' => $categories,
|
| 78 |
'#required' => TRUE,
|
| 79 |
'#access' => count($categories) > 1,
|
| 80 |
|
| 81 |
$form['message'] = array(
|
| 82 |
'#type' => 'textarea',
|
| 83 |
'#title' => t('Message'),
|
| 84 |
'#required' => TRUE,
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
$form['copy'] = array(
|
| 89 |
'#type' => 'checkbox',
|
| 90 |
'#title' => t('Send yourself a copy.'),
|
| 91 |
'#access' => $user->uid,
|
| 92 |
|
| 93 |
$form['submit'] = array(
|
| 94 |
'#type' => 'submit',
|
| 95 |
'#value' => t('Send message'),
|
| 96 |
|
| 97 |
|
| 98 |
return $form;
|
| 99 |
}
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
function contact_site_form_validate($form, &$form_state) {
|
| 105 |
if (!$form_state['values']['cid']) {
|
| 106 |
form_set_error('cid', t('You must select a valid category.'));
|
| 107 |
}
|
| 108 |
if (!valid_email_address($form_state['values']['mail'])) {
|
| 109 |
form_set_error('mail', t('You must enter a valid e-mail address.'));
|
| 110 |
}
|
| 111 |
}
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
function contact_site_form_submit($form, &$form_state) {
|
| 117 |
global $language;
|
| 118 |
|
| 119 |
$values = $form_state['values'];
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
$from = $values['mail'];
|
| 124 |
|
| 125 |
|
| 126 |
$contact = contact_load($values['cid']);
|
| 127 |
$values['contact'] = $contact;
|
| 128 |
|
| 129 |
|
| 130 |
drupal_mail('contact', 'page_mail', $contact['recipients'], language_default(), $values, $from);
|
| 131 |
|
| 132 |
|
| 133 |
if ($values['copy']) {
|
| 134 |
drupal_mail('contact', 'page_copy', $from, $language, $values, $from);
|
| 135 |
}
|
| 136 |
|
| 137 |
|
| 138 |
if ($contact['reply']) {
|
| 139 |
drupal_mail('contact', 'page_autoreply', $from, $language, $values, $contact['recipients']);
|
| 140 |
}
|
| 141 |
|
| 142 |
flood_register_event('contact');
|
| 143 |
watchdog('mail', '%name-from sent an e-mail regarding %category.', array('%name-from' => $values['name'] . " [$from]", '%category' => $contact['category']));
|
| 144 |
drupal_set_message(t('Your message has been sent.'));
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
$form_state['redirect'] = '';
|
| 149 |
}
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
function contact_personal_page($account) {
|
| 155 |
global $user;
|
| 156 |
|
| 157 |
if (!valid_email_address($user->mail)) {
|
| 158 |
$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()))));
|
| 159 |
}
|
| 160 |
elseif (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3)) && !user_access('administer site-wide contact form')) {
|
| 161 |
$output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
|
| 162 |
}
|
| 163 |
|
| 164 |
drupal_set_title($account->name);
|
| 165 |
$output = drupal_get_form('contact_personal_form', $account);
|
| 166 |
|
| 167 |
|
| 168 |
return $output;
|
| 169 |
}
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
function contact_personal_form(&$form_state, $recipient) {
|
| 175 |
global $user;
|
| 176 |
$form['#token'] = $user->name . $user->mail;
|
| 177 |
$form['recipient'] = array('#type' => 'value', '#value' => $recipient);
|
| 178 |
$form['from'] = array('#type' => 'item',
|
| 179 |
'#title' => t('From'),
|
| 180 |
'#markup' => theme('username', $user) . ' <' . check_plain($user->mail) . '>',
|
| 181 |
|
| 182 |
$form['to'] = array('#type' => 'item',
|
| 183 |
'#title' => t('To'),
|
| 184 |
'#markup' => theme('username', $recipient),
|
| 185 |
|
| 186 |
$form['subject'] = array('#type' => 'textfield',
|
| 187 |
'#title' => t('Subject'),
|
| 188 |
'#maxlength' => 50,
|
| 189 |
'#required' => TRUE,
|
| 190 |
|
| 191 |
$form['message'] = array('#type' => 'textarea',
|
| 192 |
'#title' => t('Message'),
|
| 193 |
'#rows' => 15,
|
| 194 |
'#required' => TRUE,
|
| 195 |
|
| 196 |
$form['copy'] = array('#type' => 'checkbox',
|
| 197 |
'#title' => t('Send yourself a copy.'),
|
| 198 |
|
| 199 |
$form['submit'] = array('#type' => 'submit',
|
| 200 |
'#value' => t('Send message'),
|
| 201 |
|
| 202 |
return $form;
|
| 203 |
}
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
function contact_personal_form_submit($form, &$form_state) {
|
| 209 |
global $user, $language;
|
| 210 |
|
| 211 |
$account = $form_state['values']['recipient'];
|
| 212 |
|
| 213 |
|
| 214 |
$to = $account->mail;
|
| 215 |
$from = $user->mail;
|
| 216 |
|
| 217 |
|
| 218 |
$values = $form_state['values'];
|
| 219 |
$values['account'] = $account;
|
| 220 |
$values['user'] = $user;
|
| 221 |
|
| 222 |
|
| 223 |
drupal_mail('contact', 'user_mail', $to, user_preferred_language($account), $values, $from);
|
| 224 |
|
| 225 |
|
| 226 |
if ($form_state['values']['copy']) {
|
| 227 |
drupal_mail('contact', 'user_copy', $from, $language, $values, $from);
|
| 228 |
}
|
| 229 |
|
| 230 |
flood_register_event('contact');
|
| 231 |
watchdog('mail', '%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name));
|
| 232 |
drupal_set_message(t('Your message has been sent.'));
|
| 233 |
|
| 234 |
|
| 235 |
$form_state['redirect'] = "user/$account->uid";
|
| 236 |
}
|
| 237 |
|