| 1 |
<?php
|
| 2 |
// $Id: contact_forms.module,v 1.14 2009/10/23 11:40:59 gpdinoz Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Creates a unique Site Wide Contact form with out drop down menu for each of the Contact Categories.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_form_alter()
|
| 11 |
*/
|
| 12 |
function contact_forms_form_alter(&$form, $form_state, $form_id) {
|
| 13 |
$path = $_GET['q'];
|
| 14 |
|
| 15 |
// redirect contact if another fall back page is defined
|
| 16 |
if ($path == 'contact' && variable_get('contactform_redirect', 'contact') != 'contact') {
|
| 17 |
drupal_goto(variable_get('contactform_redirect', 'contact'));
|
| 18 |
}
|
| 19 |
|
| 20 |
// Alter all contact forms except for /contact
|
| 21 |
if ($form_id == 'contact_mail_page' && $path != 'contact') {
|
| 22 |
|
| 23 |
$category = str_replace( array('-','_') , ' ' , arg(1));
|
| 24 |
$query = db_query("SELECT * FROM {contact} WHERE LOWER(category) = LOWER('%s')", $category);
|
| 25 |
$num = db_result(db_query("SELECT COUNT(*) FROM {contact} WHERE LOWER(category) = LOWER('%s')", $category));
|
| 26 |
//if category doesn't exist redirect to 'contact' or User Defined Page
|
| 27 |
if (!$num) {
|
| 28 |
drupal_goto(variable_get('contactform_redirect', 'contact'));
|
| 29 |
}
|
| 30 |
$categories_data = db_fetch_array($query);
|
| 31 |
|
| 32 |
$contact_form_var = variable_get('contactform_title', 'Contact !category');
|
| 33 |
drupal_set_title(t(variable_get('contactform_title', 'Contact !category'), array('!category' => $categories_data['category'])));
|
| 34 |
|
| 35 |
$form['contact_information'] = array(
|
| 36 |
'#type' => 'markup',
|
| 37 |
'#value' => t((!$categories_data['page_info'] ? variable_get('contactforms_information' , 'You can send !category a message using the contact form below.') : $categories_data['page_info']) , array('!category' => $categories_data['category'])),
|
| 38 |
);
|
| 39 |
|
| 40 |
$subject = str_replace( array('-','_') , ' ' , arg(2));
|
| 41 |
|
| 42 |
$form['subject'] = array('#type' => 'textfield',
|
| 43 |
'#title' => t('Subject'),
|
| 44 |
'#maxlength' => 255,
|
| 45 |
'#default_value' => $subject,
|
| 46 |
'#required' => TRUE,
|
| 47 |
);
|
| 48 |
|
| 49 |
$form['cid'] = array(
|
| 50 |
'#type' => 'hidden',
|
| 51 |
'#value' => $categories_data['cid'],
|
| 52 |
'#required' => TRUE,
|
| 53 |
);
|
| 54 |
}
|
| 55 |
|
| 56 |
//Alter the contact Category Forms
|
| 57 |
if($form_id == 'contact_admin_edit'){
|
| 58 |
$cid = $form['cid']['#value'];
|
| 59 |
if ($cid) {
|
| 60 |
$contact = db_fetch_object(db_query('SELECT * FROM {contact} WHERE cid = %d', $cid));
|
| 61 |
}
|
| 62 |
|
| 63 |
//Adds a text area that will hold category specific info for the contact page information
|
| 64 |
$form['page_info'] = array(
|
| 65 |
'#type' => 'textarea',
|
| 66 |
'#title' => t('Additional Information'),
|
| 67 |
'#weight' => 0,
|
| 68 |
'#default_value' => $contact->page_info,
|
| 69 |
'#description' => t('Information to show on the individual contact page. If this is left empty the "Default Additional Information" will be displayed'),
|
| 70 |
);
|
| 71 |
//Set the weight of the category name so It appears above our inserted info area
|
| 72 |
$form['category']['#weight']='-1';
|
| 73 |
|
| 74 |
|
| 75 |
}
|
| 76 |
|
| 77 |
// Alter contact settings form
|
| 78 |
if ($form_id == 'contact_admin_settings') {
|
| 79 |
|
| 80 |
// get example contact form path
|
| 81 |
$query = db_fetch_object(db_query("SELECT * FROM {contact} LIMIT 1"));
|
| 82 |
$name = str_replace(' ', '_' ,$query->category);
|
| 83 |
|
| 84 |
$form['contact_form_information'] = array(
|
| 85 |
'#type' => 'textarea',
|
| 86 |
'#title' => t('Standard Contact Form Additional Information'),
|
| 87 |
'#weight' => -1,
|
| 88 |
'#default_value' => variable_get('contact_form_information', t('You can leave a message using the contact form below.')),
|
| 89 |
'#description' => t('Information to show on the standard <a href="@form">contact page</a> which has the path of /contact. Can be anything from submission guidelines to your postal address or telephone number.', array('@form' => url('contact'))),
|
| 90 |
|
| 91 |
);
|
| 92 |
|
| 93 |
$form['contactforms_information'] = array(
|
| 94 |
'#type' => 'textarea',
|
| 95 |
'#title' => t('Default Additional Information for the individual contact pages'),
|
| 96 |
'#weight' => 0,
|
| 97 |
'#default_value' => variable_get('contactforms_information', t('You can send !category a message using the contact form below.')),
|
| 98 |
'#description' => t('If a category doesn\'t have additional information specified this will be shown. To place the category name in your message use the wildcard "!category" e.g. You can send !category a message using the contact form below.', array('@form' => url('contact/'.$name))),
|
| 99 |
);
|
| 100 |
|
| 101 |
$form['contactform_redirect'] = array(
|
| 102 |
'#type' => 'textfield',
|
| 103 |
'#title' => t('Contact Form redirect'),
|
| 104 |
'#default_value' => variable_get('contactform_redirect', 'contact'),
|
| 105 |
'#weight' => -2,
|
| 106 |
'#maxlength' => 60,
|
| 107 |
'#description' => t('The page you would like to redirect to if a contact/category path is entered that doesn\'t exist.'),
|
| 108 |
'#required' => false,
|
| 109 |
);
|
| 110 |
|
| 111 |
$form['contactform_title'] = array(
|
| 112 |
'#type' => 'textfield',
|
| 113 |
'#title' => t('Contact Form Title'),
|
| 114 |
'#default_value' => variable_get('contactform_title', 'Contact !category'),
|
| 115 |
'#weight' => -3,
|
| 116 |
'#maxlength' => 60,
|
| 117 |
'#description' => t('The title you would like displayed on the <a href="!form">contact page</a>. To place the category name in the title use the wildcard "!category".', array('!form' => url('contact/'.$name))),
|
| 118 |
'#required' => true,
|
| 119 |
);
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
}
|
| 124 |
}
|
| 125 |
/**
|
| 126 |
* Implementation of hook_menu_alter
|
| 127 |
*/
|
| 128 |
function contact_forms_menu_alter(&$items) {
|
| 129 |
$items['contact/%'] = $items['contact'];
|
| 130 |
}
|
| 131 |
/**
|
| 132 |
* Implementation of hook_schema_alter
|
| 133 |
*/
|
| 134 |
function contact_forms_schema_alter(&$schema) {
|
| 135 |
// Add field to existing schema.
|
| 136 |
$schema['contact']['fields']['page_info'] = array(
|
| 137 |
'type' => 'text',
|
| 138 |
'not null' => FALSE,
|
| 139 |
'size' => 'big',
|
| 140 |
'description' => 'Category Page Information Displayed on the individual category pages',
|
| 141 |
);
|
| 142 |
}
|