'. t('The uascoop_contact module enables the use of a site-wide contact form. Site-wide form allows community members to contact the site administration from a central location. Users can specify a subject and message in the contact form, sign up for the newsletter and also request that a copy of the e-mail be sent to their own address.') .'
'; $output .= ''. t('If the menu module is enabled, a menu item linking to the site-wide uascoop_contact page is added to the navigation block. It is disabled by default, but can be enabled via the menu management page. Links to the uascoop_contact page may also be added to the primary and secondary links using the same page.', array('%menu-module' => url('admin/menu'))) .'
'; $output .= t('uascoop_contact module links:') .''. t('The uascoop_contact module also adds a menu item (disabled by default) to the navigation block.', array('%menu-settings' => url('admin/menu'))) .' '. $menu_note .'
'; return($output); } } /** * Implementation of hook_menu(). */ function uascoop_contact_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'admin/uascoop_contact', 'title' => t('uascoop_contact form'), 'callback' => 'uascoop_contact_admin_categories', 'access' => user_access('administer site configuration'), ); $items[] = array('path' => 'admin/uascoop_contact/category', 'title' => t('categories'), 'callback' => 'uascoop_contact_admin_categories', 'access' => user_access('administer site configuration'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array('path' => 'admin/uascoop_contact/category/list', 'title' => t('list'), 'callback' => 'uascoop_contact_admin_categories', 'access' => user_access('administer site configuration'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); $items[] = array('path' => 'admin/uascoop_contact/category/add', 'title' => t('add category'), 'callback' => 'uascoop_contact_admin_edit', 'access' => user_access('administer site configuration'), 'type' => MENU_LOCAL_TASK, 'weight' => 1, ); $items[] = array('path' => 'admin/uascoop_contact/category/edit', 'title' => t('edit uascoop_contact category'), 'callback' => 'uascoop_contact_admin_edit', 'access' => user_access('administer site configuration'), 'type' => MENU_CALLBACK, ); $items[] = array('path' => 'admin/uascoop_contact/category/delete', 'title' => t('delete uascoop_contact'), 'callback' => 'uascoop_contact_admin_delete', 'access' => user_access('administer site configuration'), 'type' => MENU_CALLBACK, ); $items[] = array('path' => 'admin/uascoop_contact/settings', 'title' => t('settings'), 'callback' => 'uascoop_contact_admin_settings', 'access' => user_access('administer site configuration'), 'type' => MENU_LOCAL_TASK, 'weight' => 1, ); $items[] = array('path' => 'uascoop_contact', 'title' => variable_get('uascoop_contact_page_title', t('Contact Us')), 'callback' => 'uascoop_contact_mail_page', 'access' => user_access('access content'), 'type' => MENU_SUGGESTED_ITEM, ); } return $items; } /** * Categories/list tab. */ function uascoop_contact_admin_categories() { $result = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category'); $rows = array(); while ($category = db_fetch_object($result)) { $rows[] = array($category->category, $category->recipients, ($category->selected ? t('Yes') : t('No')), l(t('edit'), 'admin/uascoop_contact/category/edit/'. $category->cid), l(t('delete'), 'admin/uascoop_contact/category/delete/'. $category->cid)); } $header = array(t('Category'), t('Recipients'), t('Selected'), array('data' => t('Operations'), 'colspan' => 2)); return theme('table', $header, $rows); } /** * Category edit page. */ function uascoop_contact_admin_edit($cid = NULL) { if (arg(3) == "edit" && $cid > 0) { $edit = db_fetch_array(db_query("SELECT * FROM {contact} WHERE cid = %d", $cid)); } $form['category'] = array('#type' => 'textfield', '#title' => t('Category'), '#maxlength' => 255, '#default_value' => $edit['category'], '#description' => t("Example: 'website feedback' or 'product information'."), '#required' => TRUE, ); $form['recipients'] = array('#type' => 'textarea', '#title' => t('Recipients'), '#default_value' => $edit['recipients'], '#description' => t("Example: 'webmaster@yoursite.com' or 'sales@yoursite.com'. To specify multiple recipients, separate each e-mail address with a comma."), '#required' => TRUE, ); $form['reply'] = array('#type' => 'textarea', '#title' => t('Auto-reply'), '#default_value' => $edit['reply'], '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'), ); $form['weight'] = array('#type' => 'weight', '#title' => t('Weight'), '#default_value' => $edit['weight'], '#description' => t('When listing categories, those with lighter (smaller) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'), ); $form['selected'] = array('#type' => 'select', '#title' => t('Selected'), '#options' => array('0' => t('No'), '1' => t('Yes')), '#default_value' => $edit['selected'], '#description' => t('Set this to Yes if you would like this category to be selected by default.'), ); $form['cid'] = array('#type' => 'value', '#value' => $edit['cid'], ); $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), ); return drupal_get_form('uascoop_contact_admin_edit', $form); } /** * Validate the uascoop_contact category edit page form submission. */ function uascoop_contact_admin_edit_validate($form_id, $form_values) { if (empty($form_values['category'])) { form_set_error('category', t('You must enter a category.')); } if (empty($form_values['recipients'])) { form_set_error('recipients', t('You must enter one or more recipients.')); } else { $recipients = explode(',', $form_values['recipients']); foreach($recipients as $recipient) { if (!valid_email_address(trim($recipient))) { form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => theme('placeholder', $recipient)))); } } } } /** * Process the uascoop_contact category edit page form submission. */ function uascoop_contact_admin_edit_submit($form_id, $form_values) { if ($form_values['selected']) { // Unselect all other uascoop_contact categories. db_query('UPDATE {contact} SET selected = 0'); } $recipients = explode(',', $form_values['recipients']); foreach($recipients as $key=>$recipient) { // E-mail address validation has already been done in _validate. $recipients[$key] = trim($recipient); } $form_values['recipients'] = implode(',', $recipients); if (arg(3) == 'add') { db_query("INSERT INTO {contact} (category, recipients, reply, weight, selected) VALUES ('%s', '%s', '%s', %d, %d)", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected']); drupal_set_message(t('Category %category has been added.', array('%category' => theme('placeholder', $form_values['category'])))); watchdog('mail', t('uascoop_contact form: category %category added.', array('%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE, l(t('view'), 'admin/uascoop_contact')); } else { db_query("UPDATE {contact} SET category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d WHERE cid = %d", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected'], $form_values['cid']); drupal_set_message(t('Category %category has been updated.', array('%category' => theme('placeholder', $form_values['category'])))); watchdog('mail', t('uascoop_contact form: category %category updated.', array('%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE, l(t('view'), 'admin/uascoop_contact')); } return 'admin/uascoop_contact'; } /** * Category delete page. */ function uascoop_contact_admin_delete($cid = NULL) { if ($info = db_fetch_object(db_query("SELECT category FROM {contact} WHERE cid = %d", $cid))) { $form['category'] = array('#type' => 'value', '#value' => $info->category, ); return confirm_form('uascoop_contact_admin_delete', $form, t('Are you sure you want to delete %category?', array('%category' => theme('placeholder', $info->category))), 'admin/uascoop_contact', t('This action cannot be undone.'), t('Delete'), t('Cancel')); } else { drupal_set_message(t('Category not found.'), 'error'); drupal_goto('admin/uascoop_contact'); } } /** * Process category delete form submission. */ function uascoop_contact_admin_delete_submit($form_id, $form_values) { db_query("DELETE FROM {contact} WHERE cid = %d", arg(4)); drupal_set_message(t('Category %category has been deleted.', array('%category' => theme('placeholder', $form_values['category'])))); watchdog('mail', t('uascoop_contact form: category %category deleted.', array('%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE); return 'admin/uascoop_contact'; } /** * Settings tab. Using a form rather than hook_settings(). */ function uascoop_contact_admin_settings() { $form['uascoop_contact_page_title'] = array('#type' => 'textfield', '#title' => t('Title for the contact page'), '#default_value' => variable_get('uascoop_contact_page_title', t('Contact Us')), '#description' => t('Title for the uascoop_contact page. This text will appear in the page title and above the contact form.', array('%form' => url('uascoop_contact'))), ); $form['uascoop_contact_form_information'] = array('#type' => 'textarea', '#title' => t('Additional information'), '#default_value' => variable_get('uascoop_contact_form_information', t('You can leave a message using the uascoop_contact form below.')), '#description' => t('Information to show on the uascoop_contact page. Can be anything from submission guidelines to your postal address or telephone number.', array('%form' => url('uascoop_contact'))), ); $form['uascoop_contact_copy_message'] = array('#type' => 'textarea', '#title' => t('User Copy Email Message'), '#default_value' => variable_get('uascoop_contact_copy_message', t('If you did not send this form, please let us know as soon as possible.')), '#description' => t('This message will appear in the copy of the contact request that is sent to the user. This can be used for letting a user know how they can contact in case they did not submit the form or did not intend to contact.'), ); $form['uascoop_contact_newsletter_text'] = array('#type' => 'textfield', '#title' => t('Newsletter invitation text'), '#default_value' => variable_get('uascoop_contact_newsletter_text', t('Would you like to receive our monthly newsletter?')), '#description' => t('Newsletter invitation text on the uascoop_contact page. This text will appear next to the newsletter checkbox.', array('%form' => url('uascoop_contact'))), ); $form['uascoop_contact_hourly_threshold'] = array('#type' => 'select', '#title' => t('Hourly threshold'), '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)), '#default_value' => variable_get('uascoop_contact_hourly_threshold', 3), '#description' => t('The maximum number of contact form submissions a user can perform per hour.'), ); $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'), ); $form['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults'), ); // Use system_settings_form for the callback. return drupal_get_form('uascoop_contact_admin_settings', $form, 'system_settings_form'); } /** * Site-wide uascoop_contact page */ function uascoop_contact_mail_page() { global $user; require_once( 'recaptcha-php-1.8/recaptchalib.php' ); if (!flood_is_allowed('uascoop_contact', variable_get('uascoop_contact_hourly_threshold', 3))) { $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('uascoop_contact_hourly_threshold', 3))); } else { /* autofill the email if authenticated user */ if ($user->uid) { $edit['mail'] = $user->mail; } $result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category'); while ($category = db_fetch_object($result)) { $categories[$category->cid] = $category->category; if ($category->selected) { $default_category = $category->cid; } } if (count($categories) > 0) { $form['#token'] = $user->name . $user->mail; $form['uascoop_contact_information'] = array('#value' => filter_xss_admin(variable_get('uascoop_contact_form_information', t('You can leave us a message using the contact form below.')))); $form['first_name'] = array('#type' => 'textfield', '#title' => t('Your first name'), '#maxlength' => 255, '#required' => FALSE, ); $form['last_name'] = array('#type' => 'textfield', '#title' => t('Your last name'), '#maxlength' => 255, '#required' => FALSE, ); $form['mail'] = array('#type' => 'textfield', '#title' => t('Your e-mail address'), '#maxlength' => 255, '#default_value' => $edit['mail'], '#required' => TRUE, ); $form['newsletter'] = array('#type' => 'checkbox', '#title' => variable_get('uascoop_contact_newsletter_text', t('Would you like to receive our monthly newsletter?')), '#maxlength' => 255, '#required' => FALSE, ); $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 255, '#required' => TRUE, ); if (count($categories) > 1) { // If there is more than one category available and no default category has been selected, // prepend a default placeholder value. if (!isset($default_category)) { $categories = array(t('--')) + $categories; } $form['cid'] = array('#type' => 'select', '#title' => t('Category'), '#default_value' => $default_category, '#options' => $categories, '#required' => TRUE, ); } else { // If there is only one category, store its cid. $category_keys = array_keys($categories); $form['cid'] = array('#type' => 'value', '#value' => array_shift($category_keys), ); } $form['message'] = array('#type' => 'textarea', '#title' => t('Message'), '#required' => TRUE, ); $form['copy'] = array('#type' => 'checkbox', '#title' => t('Send me a copy.'), ); $form['recaptcha'] = array('#value' => ''.recaptcha_get_html(RECAPTCHA_PUBLIC).'