'spread/js',
'callback' => 'spread_js',
'type' => MENU_CALLBACK,
'access' => user_access('use spread form'),
);
$items[] = array(
'path' => 'admin/settings/spread',
'title' => t('Spread') ,
'description' => t('Manage Spread e-mail messages'),
'callback' => 'drupal_get_form',
'callback arguments' => array('spread_admin_settings'),
'access' => user_access('administer site configuration'),
);
}
return $items;
}
/**
* Implementation of hook_perm().
*/
function spread_perm() {
return array('use spread form');
}
function spread_admin_settings() {
$form = array();
$form['spread']['subject'] = array(
'#title' => t('Subject'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => variable_get('spread_subject', t('You need to discover this!')),
'#description' => t('The subject of the e-mail which will be sent.'),
);
$form['spread']['body'] = array(
'#title' => t('Body'),
'#type' => 'textarea',
'#required' => TRUE,
'#default_value' => variable_get('spread_body', t("Hi,\n!sender_email thinks that you should review this web page:\n!url")),
'#description' => t("This is the message which will be sent. You can use the following placeholders to adjust it:
!sender_email: user e-mail who spread the word
!url: web page from which the user spread the word"),
);
$form['spread']['how_many']= array(
'#title' => t("How many e-mail fields?"),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => variable_get('spread_how_many', 3),
'#description' => t('This is the number of e-mail fields which will be generated on the spread block form.'),
'#size' => 2,
'#maxlength' => '2',
);
return system_settings_form($form);
}
function spread_admin_settings_validate($form_id, $form_values) {
// Is entered value for field count is number?
if (!is_numeric($form_values['how_many'])) {
form_set_error('how_many', t('You must enter a numeric value'));
}
if ((int)$form_values['how_many'] == 0) {
form_set_error('how_many', t('0 seems to be not enough!'));
}
}
function spread_admin_settings_submit($form_id, $form_values) {
variable_set('spread_subject', $form_values['subject']);
variable_set('spread_body', $form_values['body']);
variable_set('spread_how_many', $form_values['how_many']);
drupal_set_message(t('Configuration saved.'));
}
function spread_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Spread form');
return $blocks;
case 'view':
switch ($delta) {
case 0:
// Checking user_access
if (user_access('use spread form')) {
$block['subject'] = t('Spread the word');
$block['content'] = drupal_get_form('spread_form');
drupal_add_js('Drupal.basePath = "'. base_path() .'"', 'inline');
drupal_add_js("Drupal.q = '". $_GET['q'] ."'", 'inline');
drupal_add_js(drupal_get_path('module', 'spread') .'/spread.js');
drupal_add_css(drupal_get_path('module', 'spread') .'/spread.css');
}
break;
}
return $block;
}
}
function spread_form() {
// We need this to get user's email
global $user;
$form['thank_you'] = array(
'#prefix' => "