Files
booking/booking.mailtemplate_admin.inc

233 lines
9.5 KiB
PHP

<?php
/**
* Function to allow admin user to define parameters for HTML emails that can be sent by Bookings module
*
* @param
* @return form render array
*/
function booking_mailtemplate_form($node, &$form_state) {
global $event;
$form = array();
$header_link_max_count = 3;
$social_media_link_max_count = 3;
$prefix = "<h2>Configure HTML email template</h2>";
// load any existing values from the drupal variable table
$colors = json_decode(variable_get('booking_mailtemplate_colors'), TRUE);
$header_links = json_decode(variable_get('booking_mailtemplate_header_links'), TRUE);
$social_links = json_decode(variable_get('booking_mailtemplate_social_links'), TRUE);
//watchdog('booking_debug', "<pre>Mail template navigation links loaded\n@info</pre>", array('@info' => print_r($header_links, true)));
//watchdog('booking_debug', "<pre>Mail template social links loaded\n@info</pre>", array('@info' => print_r($social_links, true)));
$form['booking_mailtemplate_header_image_url'] = array (
'#type' => 'textfield',
'#title' => t('URL of header image'),
'#description' => t('Specify full URL to image used in header'),
'#size' => 150,
'#maxlength' => 500,
'#default_value' => empty($colors['booking_mailtemplate_header_image_url']) ? $GLOBALS['base_url'] . '/sites/all/modules/booking/images/logo.png' : $colors['booking_mailtemplate_header_image_url'],
);
$form['booking_mailtemplate_header_link_url'] = array (
'#type' => 'textfield',
'#title' => t('Destination URL for header'),
'#description' => t('Specify full URL to direct user if they click on header image'),
'#size' => 150,
'#maxlength' => 500,
'#default_value' => empty($colors['booking_mailtemplate_header_link_url']) ? $GLOBALS['base_url'] : $colors['booking_mailtemplate_header_link_url'],
);
$form['colors'] = array(
'#type' => 'fieldset',
'#title' => 'Define Colours',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['colors']['booking_mailtemplate_background_color'] = array (
'#type' => 'textfield',
'#title' => t('Background Colour'),
'#description' => t('Specify CSS compatible value'),
'#size' => 10,
'#maxlength' => 50,
'#default_value' => empty($colors['booking_mailtemplate_background_color']) ? '#FFFFFF' : $colors['booking_mailtemplate_background_color'],
);
$form['colors']['booking_mailtemplate_content_background_color'] = array (
'#type' => 'textfield',
'#title' => t('Content area Background Colour'),
'#description' => t('Specify CSS compatible value'),
'#size' => 10,
'#maxlength' => 50,
'#default_value' => empty($colors['booking_mailtemplate_content_background_color']) ? '#FFFFFF' : $colors['booking_mailtemplate_content_background_color'],
);
$form['colors']['booking_mailtemplate_header_background_color'] = array (
'#type' => 'textfield',
'#title' => t('Header area Background Colour'),
'#description' => t('Specify CSS compatible value'),
'#size' => 10,
'#maxlength' => 50,
'#default_value' => empty($colors['booking_mailtemplate_header_background_color']) ? '#FFFFFF' : $colors['booking_mailtemplate_header_background_color'],
);
$form['colors']['booking_mailtemplate_navigation_background_color'] = array (
'#type' => 'textfield',
'#title' => t('Navigation links area Background Colour'),
'#description' => t('Specify CSS compatible value'),
'#size' => 10,
'#maxlength' => 50,
'#default_value' => empty($colors['booking_mailtemplate_navigation_background_color']) ? '#FFFFFF' : $colors['booking_mailtemplate_navigation_background_color'],
);
$form['colors']['booking_mailtemplate_text_color'] = array (
'#type' => 'textfield',
'#title' => t('Text Colour'),
'#description' => t('Specify CSS compatible value'),
'#size' => 10,
'#maxlength' => 50,
'#default_value' => empty($colors['booking_mailtemplate_text_color']) ? '#FFFFFF' : $colors['booking_mailtemplate_text_color'],
);
$form['colors']['booking_mailtemplate_subjectheading_text_color'] = array (
'#type' => 'textfield',
'#title' => t('Subject Heading Text Colour'),
'#description' => t('Specify CSS compatible value'),
'#size' => 10,
'#maxlength' => 50,
'#default_value' => empty($colors['booking_mailtemplate_subjectheading_text_color']) ? '#FFFFFF' : $colors['booking_mailtemplate_subjectheading_text_color'],
);
/*
$form['colors']['booking_mailtemplate_link_color'] = array (
'#type' => 'textfield',
'#title' => t('Link Colour'),
'#description' => t('Specify CSS compatible value'),
'#size' => 10,
'#maxlength' => 50,
'#default_value' => empty($colors['booking_mailtemplate_link_color']) ? '#FFFFFF' : $colors['booking_mailtemplate_link_color'],
);
*/
$form['header-links'] = array(
'#type' => 'fieldset',
'#title' => 'Navigation Header Links',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
//add form elements for header links
for ($i = 1; $i <= $header_link_max_count; $i++) {
$header_link_text = 'booking_mailtemplate_headerlink_text' . $i;
$header_link_url = 'booking_mailtemplate_headerlink_url' . $i;
$form['header-links'][$header_link_text] = array(
'#type' => 'textfield',
'#title' => t('Display text for navigation header link ' . $i),
'#size' => 150,
'#maxlength' => 300,
'#default_value' => empty($header_links[$i]['text']) ? 'Link Title' : $header_links[$i]['text'],
);
$form['header-links'][$header_link_url] = array(
'#type' => 'textfield',
'#title' => t('URL for navigation header link ' . $i),
'#size' => 150,
'#maxlength' => 500,
'#default_value' => empty($header_links[$i]['link']) ? $GLOBALS['base_url'] : $header_links[$i]['link'],
);
}
$form['social-links'] = array(
'#type' => 'fieldset',
'#title' => 'Social Media Links',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
//add form elements for social media links
for ($i = 1; $i <= $social_media_link_max_count; $i++) {
$social_link_text = 'booking_mailtemplate_sociallink_text' . $i;
$social_image_url = 'booking_mailtemplate_socialimage_url' . $i;
$social_link_url = 'booking_mailtemplate_sociallink_url' . $i;
$form['social-links'][$social_link_text] = array(
'#type' => 'textfield',
'#title' => t('Hover text for social link ' . $i),
'#size' => 150,
'#maxlength' => 300,
'#default_value' => empty($social_links[$i]['text']) ? '' : $social_links[$i]['text'],
);
$form['social-links'][$social_image_url] = array(
'#type' => 'textfield',
'#title' => t('URL to social image ' . $i),
'#size' => 150,
'#maxlength' => 500,
'#default_value' => empty($social_links[$i]['imageurl']) ? $GLOBALS['base_url'] : $social_links[$i]['imageurl'],
);
$form['social-links'][$social_link_url] = array(
'#type' => 'textfield',
'#title' => t('URL for social link ' . $i),
'#size' => 150,
'#maxlength' => 500,
'#default_value' => empty($social_links[$i]['linkurl']) ? $GLOBALS['base_url'] : $social_links[$i]['linkurl'],
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return array (
'first_para' => array (
'#type' => 'markup',
'#markup' => $prefix,
),
'form' => $form,
);
}
function booking_mailtemplate_form_submit($form, &$form_state)
{
global $event;
$color_data = array();
$header_data = array();
$social_data = array();
$values = $form_state['input'];
$colors_variable_list = array('booking_mailtemplate_background_color', 'booking_mailtemplate_content_background_color',
'booking_mailtemplate_navigation_background_color', 'booking_mailtemplate_subjectheading_text_color',
'booking_mailtemplate_header_background_color', 'booking_mailtemplate_text_color',
'booking_mailtemplate_header_image_url', 'booking_mailtemplate_header_link_url',
);
//'booking_mailtemplate_link_color',
//set all the values that are just using the builtin drupal variable definitions
foreach ($values as $key => $value) {
if (in_array($key, $colors_variable_list, FALSE)) {
//variable_set($key, $value);
$color_data[$key] = $value;
}
// update navigation header links
elseif (strpos($key, "booking_mailtemplate_headerlink") === 0) {
//get the ID for this header navigation link
preg_match("/.*(\d+)$/", $key, $matches);
$id = $matches[1];
$header_data[$id] = array(
'text' => $values['booking_mailtemplate_headerlink_text' . $id],
'link' => $values['booking_mailtemplate_headerlink_url' . $id],
);
}
// update social media links
elseif (strpos($key, "booking_mailtemplate_social") === 0) {
//get the ID for this header navigation link
preg_match("/.*(\d+)$/", $key, $matches);
$id = $matches[1];
$social_data[$id] = array(
'text' => $values['booking_mailtemplate_sociallink_text' . $id],
'imageurl' => $values['booking_mailtemplate_socialimage_url' . $id],
'linkurl' => $values['booking_mailtemplate_sociallink_url' . $id],
);
}
}
//watchdog('booking_debug', "<pre>Mail template navigation links\n@info</pre>", array('@info' => print_r($header_data, true)));
// store the data into the standard drupal variable table
variable_set('booking_mailtemplate_colors', json_encode($color_data));
variable_set('booking_mailtemplate_header_links', json_encode($header_data));
variable_set('booking_mailtemplate_social_links', json_encode($social_data));
}