uid == $node->uid)) {
return true;
}
}
if ($op == "collect contact information") {
if (user_access('collect contact information') && ($user->uid == $node->uid)) {
return true;
}
}
return null;
} // function citizenspeak_access
/**
* Implementation of hook_delete().
*/
function citizenspeak_delete($node) {
db_query("DELETE FROM {citizenspeak_campaigns} WHERE nid = %d", $node->nid);
} // function citizenspeak_delete
/**
* Implementation of hook_form().
*/
function citizenspeak_form(&$node, &$error) {
$output = '';
// In order to be able to attach taxonomy terms to this node, we need
// to display the appropriate form elements.
if (function_exists('taxonomy_node_form')) {
$output .= implode('', taxonomy_node_form('citizenspeak', $node));
}
// Now we define the form elements specific to our node type.
$email_group = '';
$email_group .= form_textarea(t('Email Message'), 'email_message', $node->email_message, 60, 20, t("Note: This text will be followed by the participant's contact information."), array(), true);
$email_group .= form_textarea(t('Send Message To'), 'email_recipients', $node->email_recipients, 60, 6, t("Use a comma or space to separate addresses. Make sure the above email addresses are valid to avoid campaign suspension."), array(), true);
$email_group .= form_checkbox(t('Put personal statements at top of letter'), 'campaign_format');
$output .= form_group(t('Campaign Information'), $email_group);
return $output;
} // function citizenspeak_form
/**
* Implementation of hook_insert().
*/
function citizenspeak_insert($node) {
db_query("INSERT INTO {citizenspeak_campaigns} (nid, email_message, email_recipients, campaign_format) VALUES (%d, '%s', '%s', %d)", $node->nid, $node->email_message, $node->email_recipients, $node->campaign_format);
drupal_set_message(t('
The campaign "%title" has been saved and the following web address has been activated: %url
Pass the web address along to people you wish to join your campaign.
To monitor your campaign, please go to %url/report
Good Luck!
%site_name
', array("%title" => $node->title, "%url" => url("node/". $node->nid, null, null, true), "%site_name" => variable_get("site_name", ""))));
} // function citizenspeak_insert
/**
* Implementation of hook_load().
*/
function citizenspeak_load($node) {
return db_fetch_array(db_query('SELECT * FROM {citizenspeak_campaigns} WHERE nid = %d', $node->nid));
} // function citizenspeak_load
/**
* Implementation of hook_node_name().
*
* @return name of the module
*/
function citizenspeak_node_name($node) {
return t('citizenspeak');
} // function citizenspeak_node_name
/**
* Implementation of hook_update().
*/
function citizenspeak_update($node) {
db_query("UPDATE {citizenspeak_campaigns} SET email_message = '%s', email_recipients = '%s', campaign_format = %d WHERE nid = %d", $node->email_message, $node->email_recipients, $node->campaign_format, $node->nid);
} // function citizenspeak_update
/**
* Implementation of hook_validate().
*
* @param &$node The node to be validated.
*/
function citizenspeak_validate(&$node) {
if (isset($node->email_message) && $node->email_message == '') {
form_set_error('email_message', 'You must provide an email message');
}
if (isset($node->email_recipients)) {
if ($node->email_recipients == '') {
form_set_error('email_recipients', 'You must provide at least one email address.');
}
$recipients = _citizenspeak_split_emails($node->email_recipients);
if (count($recipients) > 25) {
form_set_error('email_recipients', 'You may not have more than 25 email addresses.');
}
foreach ($recipients as $email) {
if (!valid_email_address($email)) {
form_set_error('email_recipients', 'You must provide valid email addresses.');
break;
}
}
} // if (isset($node->email_recipients))
} // function citizenspeak_validate
/**
* Implementation of hook_view().
*
* @param &$node The node to be displayed.
* @param $teaser Whether we are to generate a "teaser" or summary of the node,
* rather than display the whole thing.
* @param $page Whether the node is being displayed as a standalone page. If
* this is TRUE, the node title should not be displayed, as it will be printed
* automatically by the theme system. Also, the module may choose to alter the
* default breadcrumb trail in this case.
* @return None. The passed-by-reference $node parameter should be modified as
* necessary so it can be properly presented by theme('node', $node).
*/
function citizenspeak_view(&$node, $teaser = false, $page = false) {
if ($_POST['op'] == 'send') {
_citizenspeak_validate_participation($_POST['edit']);
}
$node->body .= theme('citizenspeak_participate_display', $node);
$node->teaser .= check_output($node->email_message);
} // function citizenspeak_view
?>