| 45 |
* A local task for citizenspeak_report() at node/###/report |
* A local task for citizenspeak_report() at node/###/report |
| 46 |
* A menu callback for citizenspeak_thank_you() at node/###/thank_you |
* A menu callback for citizenspeak_thank_you() at node/###/thank_you |
| 47 |
*/ |
*/ |
| 48 |
function citizenspeak_menu($may_cache) { |
function citizenspeak_menu() { |
| 49 |
$items = array(); |
$items = array(); |
| 50 |
|
|
| 51 |
if ($may_cache) { |
// CitizenSpeak campaigns page. |
| 52 |
// Adding a CitizenSpeak node to the system. |
$items['citizenspeak'] = array( |
| 53 |
$items[] = array( |
'title' => 'All CitizenSpeak Campaigns', |
| 54 |
'path' => 'node/add/citizenspeak', |
'access callback' => 'user_access', |
| 55 |
'title' => t('CitizenSpeak Campaign'), |
'access arguments' => array('access content'), |
| 56 |
'access' => user_access('create campaigns') |
'page callback' => 'citizenspeak_page', |
| 57 |
); |
'type' => MENU_SUGGESTED_ITEM |
| 58 |
|
); |
|
// CitizenSpeak campaigns page. |
|
|
$items[] = array( |
|
|
'path' => 'citizenspeak', |
|
|
'title' => t('All CitizenSpeak Campaigns'), |
|
|
'access' => user_access('access content'), |
|
|
'callback' => 'citizenspeak_page', |
|
|
'type' => MENU_SUGGESTED_ITEM |
|
|
); |
|
|
|
|
|
// CitizenSpeak administration page. |
|
|
$items[] = array( |
|
|
'path' => 'admin/settings/citizenspeak', |
|
|
'title' => t('CitizenSpeak'), |
|
|
'description' => t('Allows the creation of email petition campaign nodes.'), |
|
|
'callback' => 'drupal_get_form', |
|
|
'callback arguments' => array('citizenspeak_admin_settings'), |
|
|
'access' => user_access('administer site configuration'), |
|
|
'type' => MENU_NORMAL_ITEM, // optional |
|
|
); |
|
| 59 |
|
|
| 60 |
} |
// CitizenSpeak administration page. |
| 61 |
else { // Menu items that are not cached. These change on a "regular basis". |
$items['admin/settings/citizenspeak'] = array( |
| 62 |
if (arg(0) == 'node' && is_numeric(arg(1))) { // Make sure a node is being pulled up. |
'title' => 'CitizenSpeak', |
| 63 |
$node = node_load(arg(1)); |
'description' => 'Allows the creation of email petition campaign nodes.', |
| 64 |
if ($node->type == 'citizenspeak') { |
'page callback' => 'drupal_get_form', |
| 65 |
global $user; |
'page arguments' => array('citizenspeak_admin_settings'), |
| 66 |
|
'access callback' => 'user_access', |
| 67 |
$items[] = array( |
'access arguments' => array('administer site configuration'), |
| 68 |
'path' => 'node/'.arg(1).'/report', |
'type' => MENU_NORMAL_ITEM, // optional |
| 69 |
'title' => t('view campaign reports'), |
); |
| 70 |
'callback' => 'citizenspeak_report', |
|
| 71 |
'callback arguments' => arg(1), |
$items['node/%node/report'] = array( |
| 72 |
'access' => ($node->uid == $user->uid) && user_access('collect contact information'), |
'title' => 'view campaign reports', |
| 73 |
'weight' => 3, |
'page callback' => 'citizenspeak_report', |
| 74 |
'type' => MENU_LOCAL_TASK |
'page arguments' => array(1), |
| 75 |
); |
'access callback' => 'citizenspeak_check_report_access', |
| 76 |
|
'access arguments' => array(1), |
| 77 |
|
'weight' => 3, |
| 78 |
|
'type' => MENU_LOCAL_TASK |
| 79 |
|
); |
| 80 |
|
|
| 81 |
$items[] = array( |
$items['node/%node/thank_you'] = array( |
| 82 |
'path' => 'node/'.arg(1).'/thank_you', |
'title' => 'Thank You!', |
| 83 |
'title' => t('Thank You!'), |
'page callback' => 'citizenspeak_thank_you', |
| 84 |
'callback' => 'citizenspeak_thank_you', |
'page arguments' => array(1), |
| 85 |
'callback arguments' => arg(1), |
'access callback' => 'user_access', |
| 86 |
'access' => user_access('participate in campaigns'), |
'access arguments' => array('participate in campaigns'), |
| 87 |
'type' => MENU_CALLBACK |
'type' => MENU_CALLBACK |
| 88 |
); |
); |
|
} |
|
|
} |
|
|
} |
|
| 89 |
|
|
| 90 |
return $items; |
return $items; |
| 91 |
} // function citizenspeak_menu |
} // function citizenspeak_menu |
| 92 |
|
|
| 93 |
|
function citizenspeak_check_report_access($node) { |
| 94 |
|
if ($node->type != 'citizenspeak') { |
| 95 |
|
return; |
| 96 |
|
} |
| 97 |
|
global $user; |
| 98 |
|
if(($node->uid == $user->uid) && user_access('collect contact information')) { |
| 99 |
|
return TRUE; |
| 100 |
|
} |
| 101 |
|
return FALSE; |
| 102 |
|
} |
| 103 |
|
|
| 104 |
/** |
/** |
| 105 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 106 |
* |
* |
| 229 |
if ($op == "list") { |
if ($op == "list") { |
| 230 |
$block[0]["info"] = t('popular citizenspeak campaigns'); |
$block[0]["info"] = t('popular citizenspeak campaigns'); |
| 231 |
return $block; |
return $block; |
| 232 |
} |
} else { |
| 233 |
else { |
$most_popular = db_query(db_rewrite_sql('SELECT n.nid, n.title, COUNT(*) AS participants FROM {node} n LEFT JOIN citizenspeak_participants AS cp ON n.nid = cp.nid WHERE n.type = \'citizenspeak\' AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) < cp.sent_at AND n.promote = 1 AND n.status = 1 GROUP BY n.nid ORDER BY participants DESC LIMIT 5')); |
| 234 |
$most_popular = db_query(db_rewrite_sql('SELECT n.nid, n.title, COUNT(*) AS participants FROM {node} n LEFT JOIN {citizenspeak_participants} AS cp ON n.nid = cp.nid WHERE n.type = \'citizenspeak\' AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) < cp.sent_at AND n.promote = 1 AND n.status = 1 GROUP BY n.nid ORDER BY participants DESC LIMIT 5')); |
|
| 235 |
if (db_num_rows($most_popular)) { |
$num_rows = FALSE; |
| 236 |
|
|
| 237 |
|
while($campaign = db_fetch_object($most_popular)) { |
| 238 |
|
$campaigns[] = l($campaign->title, "node/$campaign->nid"); |
| 239 |
|
$num_rows = TRUE; |
| 240 |
|
} |
| 241 |
|
|
| 242 |
|
if($num_rows) { |
| 243 |
$block['subject'] = t('popular campaigns'); |
$block['subject'] = t('popular campaigns'); |
|
|
|
|
while($campaign = db_fetch_object($most_popular)) { |
|
|
$campaigns[] = l($campaign->title, "node/$campaign->nid"); |
|
|
} |
|
|
|
|
| 244 |
$block['content'] = theme('item_list', $campaigns) . l(t("all campaigns"), "citizenspeak"); |
$block['content'] = theme('item_list', $campaigns) . l(t("all campaigns"), "citizenspeak"); |
| 245 |
return $block; |
return $block; |
| 246 |
} |
} |
| 253 |
* @param $nid |
* @param $nid |
| 254 |
* Node ID of the campaign |
* Node ID of the campaign |
| 255 |
*/ |
*/ |
| 256 |
/*function citizenspeak_send_petition_submit($form_id, $edit) {*/ |
function citizenspeak_send_petition_form_submit($form_id, &$form_state) { |
|
function citizenspeak_send_petition_form_submit($form_id, $edit) { |
|
| 257 |
// Log response |
// Log response |
| 258 |
$id = db_next_id('citizenspeak_participants'); |
db_query("INSERT INTO {citizenspeak_participants} (nid, name, organization, email, address, city, state, zip, phone, fax, personal_statement, sent_at) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', NOW())", $form_state['nid'], $form_state['values']['name'], $form_state['values']['organization'], $form_state['values']['email'], $form_state['values']['address'], $form_state['values']['city'], $form_state['values']['state'], $form_state['values']['zip'], $form_state['values']['phone'], $form_state['values']['fax'], $form_state['values']['personal_statement']); |
| 259 |
db_query("INSERT INTO {citizenspeak_participants} (nid, id, name, organization, email, address, city, state, zip, phone, fax, personal_statement, sent_at) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', NOW())", $edit['nid'], $id, $edit['name'], $edit['organization'], $edit['email'], $edit['address'], $edit['city'], $edit['state'], $edit['zip'], $edit['phone'], $edit['fax'], $edit['personal_statement']); |
|
| 260 |
|
$id = db_last_insert_id('citizenspeak_participants', 'id'); |
| 261 |
|
|
| 262 |
// Make email content |
// Make email content |
| 263 |
$node = node_load($edit['nid']); |
$node = node_load($form_state['nid']); |
| 264 |
$participant = db_fetch_object(db_query("SELECT * FROM {citizenspeak_participants} WHERE id = %d", $id)); |
$participant = db_fetch_object(db_query("SELECT * FROM {citizenspeak_participants} WHERE id = %d", $id)); |
| 265 |
$message = theme("citizenspeak_message", $node, $participant); |
$message = theme("citizenspeak_message", $node, $participant); |
| 266 |
$headers = theme("citizenspeak_message_headers", $node, $participant); |
$headers = theme("citizenspeak_message_headers", $node, $participant); |
| 273 |
|
|
| 274 |
// Send email (or display debugging page) |
// Send email (or display debugging page) |
| 275 |
if (!variable_get('citizenspeak_debug', 0)) { |
if (!variable_get('citizenspeak_debug', 0)) { |
| 276 |
mail($node->email_recipients, $node->title, $message, $headers); |
if(!mail($node->email_recipients, $node->title, $message, $headers)) { |
| 277 |
|
// drupal_set_message("ERROR: Mail was not sent. Please contact the site administrator", 'error'); |
| 278 |
|
print $note->title . $message . $headers; |
| 279 |
|
} |
| 280 |
// Redirect to thank you page |
// Redirect to thank you page |
| 281 |
drupal_goto("node/". $edit['nid'] ."/thank_you"); |
drupal_goto("node/". $form_state['nid'] ."/thank_you"); |
| 282 |
} |
} |
| 283 |
else { |
else { |
| 284 |
return theme('citizenspeak_debug_page', $node, $message, $headers); |
return theme('citizenspeak_debug_page', $node, $message, $headers); |
| 291 |
* @param $nid |
* @param $nid |
| 292 |
* Node ID of the campaign |
* Node ID of the campaign |
| 293 |
*/ |
*/ |
| 294 |
function citizenspeak_thank_you($nid) { |
function citizenspeak_thank_you($node) { |
| 295 |
$node = node_load($nid); |
// $node = node_load($nid); |
| 296 |
$owner = user_load(array('uid' => $node->uid)); |
$owner = user_load(array('uid' => $node->uid)); |
| 297 |
if ($owner->use_redirect) { |
if ($owner->use_redirect) { |
| 298 |
header("Location: ". $node->redirect_url); |
header("Location: ". $node->redirect_url); |
| 310 |
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 AND n.type = 'citizenspeak' ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10)); |
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 AND n.type = 'citizenspeak' ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10)); |
| 311 |
|
|
| 312 |
$output = ''; |
$output = ''; |
| 313 |
if (db_num_rows($result)) { |
$num_rows = FALSE; |
| 314 |
while ($node = db_fetch_object($result)) { |
while ($node = db_fetch_object($result)) { |
| 315 |
$output .= node_view(node_load($node->nid), 1); |
$output .= node_view(node_load($node->nid), 1); |
| 316 |
} |
$num_rows = TRUE; |
| 317 |
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); |
} |
| 318 |
|
|
| 319 |
|
if ($num_rows) { |
| 320 |
|
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0); |
| 321 |
} |
} |
| 322 |
|
|
| 323 |
print theme('page', $output); |
print theme('page', $output); |
| 324 |
} |
} |