'fieldset', '#title' => t('Show issues from'), '#collapsible' => FALSE, '#prefix' => '
', '#suffix' => '
', ); if (variable_get('simplenews_last_cron', '')) { $form['last_sent'] = array('#value' => '

'. format_plural(variable_get('simplenews_last_sent', 0), 'Last batch: 1 mail sent at !time.', 'Last batch: !count mails sent at !time.', array('!time' => format_date(variable_get('simplenews_last_cron', ''), 'small'), '!count' => variable_get('simplenews_last_sent', 0))) ."

\n"); } $header = array(t('Title'), t('Newsletter'), t('Date created'), t('Published'), t('Sent'), t('Operations')); list($names, $queries) = array_values(simplenews_get_filter('simplenews_newsletters_filter')); $filter = isset($_SESSION['simplenews_newsletters_filter']) ? $_SESSION['simplenews_newsletters_filter'] : ''; $form['simplenews_issue_filter']['filter'] = array( '#type' => 'select', '#options' => $names, '#default_value' => $filter, ); $where_condition = isset($queries[$filter]) && !empty($queries[$filter]) ? 'WHERE '. $queries[$filter] : ''; $query = " SELECT DISTINCT n.*, s.s_status, s.tid, s.sent_subscriber_count FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid " . $where_condition . " ORDER BY n.created DESC"; $count_query = " SELECT COUNT(n.nid) FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid " . $where_condition; $result = pager_query(db_rewrite_sql($query, 'n', 'nid'), 10, 0, db_rewrite_sql($count_query, 'n', 'nid'), 0); $rows = array(); module_load_include('inc', 'simplenews', 'includes/simplenews.mail'); while ($node = db_fetch_object($result)) { $row = array(); $operation = array(); $terms = array_keys(taxonomy_node_get_terms_by_vocabulary($node, $vid, 'name')); $status = $node->s_status; $sent_subscriber_count = $node->sent_subscriber_count; $pending_count = simplenews_count_spool($node->nid, $node->vid); $already_sent = $sent_subscriber_count - $pending_count; $source = 'sent'; $send_status = theme('simplenews_status', $status, 'sent', $already_sent, $sent_subscriber_count); $operation[] = l(t('edit'), 'node/'. $node->nid .'/edit', array('query' => drupal_get_destination())); $row[] = l($node->title, 'node/'. $node->nid); $row[] = isset($terms[0]) ? $terms[0] : t('n/a'); $row[] = format_date($node->created, 'small'); $row[] = theme('simplenews_status', $node->status, 'published'); $row[] = $send_status; $row[] = implode(' ', $operation); $rows[] = $row; } if ($pager = theme('pager', NULL, 10, 0)) { $rows[] = array(array('data' => $pager, 'colspan' => '8')); } if (!$rows) { $rows[] = array(array('data' => t('No newsletters available.'), 'colspan' => '8')); } $form['simplenews_issue_filter']['submit'] = array( '#type' => 'submit', '#value' => t('Filter'), ); $table = theme('table', $header, $rows); $form['table'] = array('#value' => $table); return $form; } function simplenews_admin_news_submit($form, &$form_state) { _simplenews_set_filter('simplenews_newsletters_filter', $form_state['values']); } /** * Store filter values in session var * * @param $type identification string * @param $form_values array of values to be stored */ function _simplenews_set_filter($type, $values) { if (empty($_SESSION[$type])) { $_SESSION[$type] = 'all'; } $op = $values['op']; if ($op == t('Filter') && isset($values['filter'])) { $_SESSION[$type] = $values['filter']; } } /** * Menu callback: newsletter admin form with list of available newsletter series. */ function simplenews_types_overview() { $rows = array(); $header = array(t('Newsletter name'), t('Subscribers'), t('Operations')); foreach (simplenews_get_newsletters(variable_get('simplenews_vid', ''), TRUE) as $newsletter) { $count = simplenews_count_subscriptions($newsletter->tid); $rows[] = array(check_plain($newsletter->name), $count, l(t('edit newsletter'), 'admin/content/simplenews/types/edit/'. $newsletter->tid)); } if (count($rows) == 0) { $rows[] = array(array('data' => t('There are currently no newsletter series.'), 'colspan' => count($header))); } return theme('table', $header, $rows); } /** * Menu callback: newsletter admin form for newsletter add/edit. * * @see simplenews_admin_types_form_validate() * @see simplenews_admin_types_form_submit() */ function simplenews_admin_types_form(&$form_state, $tid = NULL) { if (isset($tid)) { // We are editing an existing newsletter. $term = taxonomy_get_term($tid); // If the given term is not a newsletter, don't allow editing. if (variable_get('simplenews_vid', '') != $term->vid) { drupal_not_found(); return; } // Redirect on a delete operation for posterity's sake. if (isset($form_state['post']['op']) && $form_state['post']['op'] == t('Delete')) { drupal_goto('admin/content/simplenews/types/delete/'. $term->tid); } } else { // We will create a new newsletter. // Provide vocabulary id for the newsletter to be added to. $term = (object)array('vid' => variable_get('simplenews_vid', '')); $term->tid = ''; } $form['name'] = array( '#type' => 'textfield', '#title' => t('Newsletter name'), '#size' => 50, '#maxlength' => 128, '#description' => t('The name of this newsletter.'), '#required' => TRUE, '#default_value' => isset($term->name) ? $term->name : '', ); $form['description'] = array( '#type' => 'textarea', '#title' => t('Description'), '#cols' => 60, '#rows' => 5, '#description' => t('A description of the newsletter. To be displayed on taxonomy/term pages and RSS feeds.'), '#default_value' => isset($term->description) ? $term->description : '', ); $form['weight'] = array( '#type' => 'weight', '#title' => t('Weight'), '#delta' => 10, '#description' => t('Newsletters are displayed in ascending order by weight.'), '#required' => TRUE, '#default_value' => isset($term->weight) ? $term->weight : 0, ); $form['subscription'] = array( '#type' => 'fieldset', '#title' => t('Subscription settings'), '#collapsible' => FALSE, ); $options = array('none' => t('None'), 'on' => t('Default on'), 'off' => t('Default off'), 'silent' => t('Silent')); $form['subscription']['simplenews_new_account_'. $term->tid] = array( '#type' => 'select', '#title' => t('Subscribe new account'), '#options' => $options, '#default_value' => variable_get('simplenews_new_account_'. $term->tid, 'none'), '#description' => t('None: This newsletter is not listed on the user registration page.
Default on: This newsletter is listed on the user registration page and is selected by default.
Default off: This newsletter is listed on the user registration page and is not selected by default.
Silent: A new user is automatically subscribed to this newsletter. The newsletter is not listed on the user registration page.'), ); $options = array('hidden' => t('Hidden'), 'single' => t('Single'), 'double' => t('Double')); $form['subscription']['simplenews_opt_inout_'. $term->tid] = array( '#type' => 'select', '#title' => t('Opt-in/out method'), '#options' => $options, '#default_value' => variable_get('simplenews_opt_inout_'. $term->tid, 'double'), '#description' => t('Hidden: This newsletter does not appear on subscription forms. No unsubscribe footer in newsletter.
Single: Users are (un)subscribed immediately, no confirmation email is sent.
Double: When (un)subscribing at a subscription form, anonymous users receive an (un)subscription confirmation email. Authenticated users are (un)subscribed immediately.'), ); $form['simplenews_sender_information'] = array( '#type' => 'fieldset', '#title' => t('Sender information'), '#collapsible' => FALSE, ); $form['simplenews_sender_information']['simplenews_from_name_'. $term->tid] = array( '#type' => 'textfield', '#title' => t('From name'), '#size' => 60, '#maxlength' => 128, '#default_value' => variable_get('simplenews_from_name_'. $term->tid, variable_get('simplenews_from_name', variable_get('site_name', 'Drupal'))), ); $form['simplenews_subject'] = array( '#type' => 'fieldset', '#title' => t('Newsletter subject'), '#collapsible' => FALSE, ); $form['simplenews_subject']['token_help'] = array( '#title' => t('Replacement patterns'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['simplenews_subject']['token_help']['help'] = array( '#value' => theme('token_help', 'simplenews') . theme('token_help', 'node'), ); $form['simplenews_subject']['simplenews_email_subject_'. $term->tid] = array( '#type' => 'textfield', '#title' => t('Email subject'), '#size' => 60, '#maxlength' => 128, '#required' => TRUE, '#default_value' => variable_get('simplenews_email_subject_'. $term->tid, '[[simplenews-newsletters-name]] [title-raw]'), ); $form['simplenews_sender_information']['simplenews_from_address_'. $term->tid] = array( '#type' => 'textfield', '#title' => t('From email address'), '#size' => 60, '#maxlength' => 128, '#required' => TRUE, '#default_value' => variable_get('simplenews_from_address_'. $term->tid, variable_get('simplenews_from_address', variable_get('site_mail', ini_get('sendmail_from')))), ); $form['simplenews_hyperlinks'] = array('#type' => 'fieldset', '#title' => t('HTML to text conversion'), '#collapsible' => FALSE, '#description' => t('When your newsletter is sent as plain text, these options will determine how the conversion to text is performed.'), ); $form['simplenews_hyperlinks']['simplenews_hyperlinks_'. $term->tid] = array( '#type' => 'radios', '#title' => t('Hyperlink conversion'), '#options' => array( t('Append hyperlinks as a numbered reference list'), t('Display hyperlinks inline with the text') ), '#default_value' => variable_get('simplenews_hyperlinks_'. $term->tid, 1), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Save'), '#weight' => 25, ); $form['vid'] = array( '#type' => 'hidden', '#value' => isset($term->vid) ? $term->vid : variable_get('simplenews_vid', ''), ); // If we are editing a newsletter term, show delete option and store tid. // tid is used in validation and submission functions to differentiate // between form actions of creating a new or editing an existing term. if ($term->tid) { $form['delete'] = array( '#type' => 'submit', '#value' => t('Delete'), '#weight' => 30, ); $form['tid'] = array( '#type' => 'value', '#value' => $term->tid, ); } // Return to Newsletter list page after submit $form['#redirect'] = 'admin/content/simplenews/types'; return $form; } function simplenews_admin_types_form_validate($form, &$form_state) { $tid = $form_state['values']['tid']; $field_name = 'simplenews_from_address_'. $tid; if (!simplenews_valid_email_address($form_state['values'][$field_name])) { form_set_error($field_name, t("The sender's email address you supplied is not valid.")); } } function simplenews_admin_types_form_submit($form, &$form_state) { // Redirect on a delete operation for posterity's sake. if (isset($form_state['post']['op']) && $form_state['post']['op'] == t('Delete')) { drupal_goto('admin/content/simplenews/types/delete/'. $term->tid); } // Create or update taxonomy term for this newsletter. // When creating a term $form_state['values']['tid'] is NULL. if (isset($form_state['values']['tid'])) { $termdata = (array)taxonomy_get_term($form_state['values']['tid']); } $termdata['tid'] = $form_state['values']['tid']; $termdata['vid'] = $form_state['values']['vid']; $termdata['name'] = $form_state['values']['name']; $termdata['description'] = $form_state['values']['description']; $termdata['weight'] = $form_state['values']['weight']; switch (taxonomy_save_term($termdata)) { case SAVED_NEW: drupal_set_message(t('Created new term %name.', array('%name' => $form_state['values']['name']))); break; case SAVED_UPDATED: drupal_set_message(t('Updated term %name.', array('%name' => $form_state['values']['name']))); break; } // Store newsletter specific settings. // When editing a newsletter fieldnames have $tid suffix. // When creating a new newsletter field names have no suffix // and $form_state['values']['tid'] is NULL. if (isset($form_state['values']['tid'])) { $tid = $suffix = $form_state['values']['tid']; } else { // Get the tid from the database based on the form values used above to // create a new term. $tid = db_result(db_query(" SELECT t.tid FROM {term_data} t WHERE t.vid = %d AND t.name = '%s' ORDER BY t.tid DESC", $form_state['values']['vid'], $form_state['values']['name'])); $suffix = ''; } variable_set('simplenews_from_name_'. $tid, $form_state['values']['simplenews_from_name_'. $suffix]); variable_set('simplenews_from_address_'. $tid, $form_state['values']['simplenews_from_address_'. $suffix]); variable_set('simplenews_email_subject_'. $tid, $form_state['values']['simplenews_email_subject_'. $suffix]); variable_set('simplenews_hyperlinks_'. $tid, $form_state['values']['simplenews_hyperlinks_'. $suffix]); variable_set('simplenews_new_account_'. $tid, $form_state['values']['simplenews_new_account_'. $suffix]); variable_set('simplenews_opt_inout_'. $tid, $form_state['values']['simplenews_opt_inout_'. $suffix]); } /** * Menu callback: Delete newsletter series. * * @see simplenews_admin_types_delete_submit() */ function simplenews_admin_types_delete(&$form_state, $tid = NULL) { if (!isset($tid)) { drupal_not_found(); return; } $term = taxonomy_get_term($tid); $form = array(); $form['tid'] = array( '#type' => 'value', '#value' => $tid, ); $form['notice'] = array( '#value' => '

'. t('Note: All subscriptions associated with this newsletter will be lost.') .'

', ); $form['#redirect'] = 'admin/content/simplenews/types'; return confirm_form($form, t('Are you sure you want to delete %title?', array('%title' => $term->name)), 'admin/content/simplenews/types', t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } function simplenews_admin_types_delete_submit($form, &$form_state) { if ($form_state['values']['confirm']) { $tid = $form_state['values']['tid']; $term = taxonomy_get_term($tid); taxonomy_del_term($tid); variable_del('simplenews_from_name_'. $tid); variable_del('simplenews_email_subject_'. $tid); variable_del('simplenews_from_address_'. $tid); variable_del('simplenews_hyperlinks_'. $tid); variable_del('simplenews_new_account_'. $tid); variable_del('simplenews_opt_inout_'. $tid); drupal_set_message(t('Newsletter %title has been deleted.', array('%title' => $term->name))); } } /** * Menu callback: Delete multiple subscriptions. * * @see simplenews_subscription_multiple_delete_confirm_submit() */ function simplenews_subscription_multiple_delete_confirm() { // Subscriptions to be deleted are passed via session var. $snids = $_SESSION['simplenews_subscriptions_delete']; $form['snids'] = array('#prefix' => '', '#tree' => TRUE); // array_filter returns only elements with TRUE values foreach (array_filter($snids) as $snid => $value) { $mail = db_result(db_query(' SELECT mail FROM {simplenews_subscriptions} WHERE snid = %d', $snid)); $form['snids'][$snid] = array( '#type' => 'hidden', '#value' => $snid, '#prefix' => '
  • ', '#suffix' => check_plain($mail) ."
  • \n" ); } $form['operation'] = array( '#type' => 'hidden', '#value' => 'delete', ); $form['#submit'][] = 'simplenews_subscription_multiple_delete_confirm_submit'; return confirm_form($form, t('Are you sure you want to delete these subscriptions?'), 'admin/content/simplenews/users', t('This action cannot be undone.'), t('Delete all'), t('Cancel') ); } function simplenews_subscription_multiple_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { foreach ($form_state['values']['snids'] as $snid => $value) { simplenews_delete_subscription($snid); } drupal_set_message(t('The subscriptions have been deleted.')); } return ''; } /** * Menu callback: Mass subscribe to newsletters. * * @see simplenews_subscription_list_add_submit() * @todo Add 32char description field as subscription source */ function simplenews_subscription_list_add() { global $language; $form['emails'] = array( '#type' => 'textarea', '#title' => t('Email addresses'), '#cols' => 60, '#rows' => 5, '#description' => t('Email addresses must be separated by comma, space or newline.'), ); $newsletters = array(); foreach (simplenews_get_newsletters(variable_get('simplenews_vid', ''), TRUE) as $newsletter) { $newsletters[$newsletter->tid] = check_plain($newsletter->name); } $form['newsletters'] = array( '#type' => 'checkboxes', '#title' => t('Subscribe to'), '#options' => $newsletters, '#required' => TRUE, ); // Include language selection when the site is multilingual. // Default value is the empty string which will result in receiving emails // in the site's default language. if (variable_get('language_count', 1) > 1) { $options[''] = t('Site default language'); $languages = language_list('enabled'); foreach ($languages[1] as $langcode => $item) { $name = t($item->name); $options[$langcode] = $name . ($item->native != $name ? ' ('. $item->native .')' : ''); } $form['language'] = array( '#type' => 'radios', '#title' => t('Anonymous user preferred language'), '#default_value' => '', '#options' => $options, '#description' => t('New anonymous mail addresses will be subscribed with the selected preferred language. Registered users will be subscribed with their preferred language as set on their account page. The language of existing subscribers is unchanged.'), ); } else { $form['language'] = array('#type' => 'value', '#value' => ''); } $form['submit'] = array( '#type' => 'submit', '#value' => t('Subscribe'), ); return $form; } function simplenews_subscription_list_add_submit($form, &$form_state) { $added = array(); $invalid = array(); $checked_newsletters = array_filter($form_state['values']['newsletters']); $langcode = $form_state['values']['language']; $emails = preg_split("/[\s,]+/", $form_state['values']['emails']); foreach ($emails as $email) { $email = trim($email); if ($email == '') { continue; } if (simplenews_valid_email_address($email)) { foreach ($checked_newsletters as $tid) { $newsletter = taxonomy_get_term($tid); simplenews_subscribe_user($email, $newsletter->tid, FALSE, 'mass subscribe', $langcode); $added[] = $email; } } else { $invalid[] = $email; } } if ($added) { $added = implode(", ", $added); drupal_set_message(t('The following addresses were added or updated: %added.', array('%added' => $added))); $newsletter_names = array(); foreach ($checked_newsletters as $tid) { $newsletter = taxonomy_get_term($tid); $newsletter_names[] = $newsletter->name; } drupal_set_message(t('The addresses were subscribed to the following newsletters: %newsletters.', array('%newsletters' => implode(', ', $newsletter_names)))); } else { drupal_set_message(t('No addresses were added.')); } if ($invalid) { $invalid = implode(", ", $invalid); drupal_set_message(t('The following addresses were invalid: %invalid.', array('%invalid' => $invalid)), 'error'); } } /** * Menu callback: Export email address of subscriptions. * * @see simplenews_admin_export_after_build() * @todo Add checkboxes for subscribed and unsubscribed selection. */ function simplenews_subscription_list_export() { $form['states'] = array( '#type' => 'checkboxes', '#title' => t('Status'), '#options' => array('active' => t('Active users'), 'inactive' => t('Inactive users')), '#description' => t('Subscriptions matching the selected states will be exported.'), '#required' => TRUE, ); $newsletters = array(); foreach (simplenews_get_newsletters(variable_get('simplenews_vid', ''), TRUE) as $newsletter) { $newsletters[$newsletter->tid] = check_plain($newsletter->name); } $form['newsletters'] = array( '#type' => 'checkboxes', '#title' => t('Subscribed to'), '#options' => $newsletters, '#description' => t('Subscriptions matching the selected newsletters will be exported.'), '#required' => TRUE, ); // Emails item is initially empty. It serves as place holder. Data is added by // simplenews_admin_export_after_build(). $form['emails'] = array(); $form['submit'] = array( '#type' => 'submit', '#value' => t('Export'), ); $form['#after_build'] = array('simplenews_admin_export_after_build'); $form['#redirect'] = FALSE; return $form; } function simplenews_admin_export_after_build($form, $form_element) { //TODO: Add (un)subscribed as filter to form. if (isset($form_element['values']['op']) && $form_element['values']['op'] == t('Export')) { $states = array_filter($form_element['values']['states']); $newsletters = array_filter($form_element['values']['newsletters']); // Build where clause for active/inactive state and newsletter selection. if (isset($states['active'])) { $where[] = 's.activated = 1'; } if (isset($states['inactive'])) { $where[] = 's.activated = 0'; } $where = isset($where) ? implode(' OR ', $where) : NULL; foreach (simplenews_get_newsletters(variable_get('simplenews_vid', ''), TRUE) as $newsletter) { if (isset($newsletters[$newsletter->tid])) { $where_tid[] = 't.tid = '. $newsletter->tid; } } $where_tid = isset($where_tid) ? implode(' OR ', $where_tid) : NULL; // Get subscription data if (isset($where) && isset($where_tid)) { $query = ' SELECT DISTINCT s.mail FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid AND t.status = 1 WHERE (' . $where . ') AND (' . $where_tid . ')'; $result = db_query($query); while ($mail = db_fetch_object($result)) { $mails[] = $mail->mail; } } // Build form field containing exported emails. // The field will be included in the form where at the ['emails'] place holder. if (isset($mails)) { $exported_mails = implode(", ", $mails); } else { $exported_mails = t('No addresses were found.'); } $form['emails'] = array( '#type' => 'textarea', '#title' => t('Export results'), '#cols' => 60, '#rows' => 5, '#value' => $exported_mails, ); } return $form; } /** * Menu callback: Mass subscribe to newsletters. * * @see simplenews_subscription_list_remove_submit() * @todo Add 32char description field as unsubscription source */ function simplenews_subscription_list_remove() { $form['emails'] = array( '#type' => 'textarea', '#title' => t('Email addresses'), '#cols' => 60, '#rows' => 5, '#description' => t('Email addresses must be separated by comma, space or newline.'), ); $newsletters = array(); foreach (simplenews_get_newsletters(variable_get('simplenews_vid', ''), TRUE) as $newsletter) { $newsletters[$newsletter->tid] = check_plain($newsletter->name); } $form['newsletters'] = array( '#type' => 'checkboxes', '#title' => t('Unsubscribe from'), '#options' => $newsletters, '#required' => TRUE, ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Unsubscribe'), ); return $form; } function simplenews_subscription_list_remove_submit($form, &$form_state) { $removed = array(); $invalid = array(); $checked_newsletters = array_filter($form_state['values']['newsletters']); $emails = preg_split("/[\s,]+/", $form_state['values']['emails']); foreach ($emails as $email) { $email = trim($email); if (simplenews_valid_email_address($email)) { foreach ($checked_newsletters as $tid) { $newsletter = taxonomy_get_term($tid); simplenews_unsubscribe_user($email, $newsletter->tid, FALSE, 'mass unsubscribe'); $removed[] = $email; } } else { $invalid[] = $email; } } if ($removed) { $removed = implode(", ", $removed); drupal_set_message(t('The following addresses were unsubscribed: %removed.', array('%removed' => $removed))); $newsletter_names = array(); foreach ($checked_newsletters as $tid) { $newsletter = taxonomy_get_term($tid); $newsletter_names[] = $newsletter->name; } drupal_set_message(t('The addresses were unsubscribed from the following newsletters: %newsletters.', array('%newsletters' => implode(', ', $newsletter_names)))); } else { drupal_set_message(t('No addresses were removed.')); } if ($invalid) { $invalid = implode(", ", $invalid); drupal_set_message(t('The following addresses were invalid: %invalid.', array('%invalid' => $invalid)), 'error'); } } /** * Menu callback: subscription administration. */ function simplenews_subscription_admin($form_state) { // Delete subscriptions requires delete confirmation. This is handled with a different form if (isset($form_state['post']['operation']) && $form_state['post']['operation'] == 'delete' && isset($form_state['post']['snids'])) { $destination = drupal_get_destination(); $_SESSION['simplenews_subscriptions_delete'] = $form_state['post']['snids']; // Note: we redirect from admin/content/simplenews/users to admin/content/simplenews/subscriptions/delete to make the tabs disappear. drupal_goto("admin/content/simplenews/subscriptions/delete", $destination); } $form = simplenews_subscription_filter_form(); $form['admin'] = simplenews_subscription_list_form(); return $form; } /** * Build the form for admin subscription. * * Form consists of a filter fieldset, an operation fieldset and a list of * subscriptions matching the filter criteria. * * @see simplenews_subscription_list_form_validate() * @see simplenews_subscription_list_form_submit() */ function simplenews_subscription_list_form() { //TODO: Subscriber maintenance needs overhaul now we have more data available. // Table header. Used as tablesort default $header = array( array('data' => t('Email'), 'field' => 'ss.mail', 'sort' => 'asc'), array('data' => t('Username'), 'field' => 'u.name'), array('data' => t('Status'), 'field' => 'ss.activated'), ); if (variable_get('language_count', 1) > 1) { $header[] = array('data' => t('Language'), 'field' => 'ss.language'); } $header[] = t('Operations'); // Data collection with filter and sorting applied $filter = simplenews_build_subscription_filter_query(); $query = ' SELECT DISTINCT ss.snid, ss.*, u.name FROM {simplenews_subscriptions} ss LEFT JOIN {users} u ON ss.uid = u.uid INNER JOIN {simplenews_snid_tid} s ON ss.snid = s.snid ' . $filter['where']; // $count_query used to count distinct records only, match per line $count_query = preg_replace('/SELECT.*/', 'SELECT COUNT(DISTINCT ss.snid)', $query); $query .= tablesort_sql($header); $result = pager_query($query, 30, 0, $count_query); // Update options $form['options'] = array( '#type' => 'fieldset', '#title' => t('Update options'), '#prefix' => '
    ', '#suffix' => '
    ', ); $form['options']['operation'] = array( '#type' => 'select', '#options' => array( 'activate' => t('Activate'), 'inactivate' => t('Inactivate'), 'delete' => t('Delete'), ), '#default_value' => 'activate'); $form['options']['submit'] = array( '#type' => 'submit', '#value' => t('Update'), '#submit' => array('simplenews_subscription_list_form_submit'), '#validate' => array('simplenews_subscription_list_form_validate'), ); $snids = array(); // Subscription table and table pager $languages = language_list(); while ($subscription = db_fetch_object($result)) { $snids[$subscription->snid] = ''; $form['mail'][$subscription->snid] = array('#value' => $subscription->mail); $form['name'][$subscription->snid] = array('#value' => isset($subscription->uid) ? l($subscription->name, 'user/'. $subscription->uid) : $subscription->name); $form['status'][$subscription->snid] = array('#value' => theme('simplenews_status', $subscription->activated, 'activated')); if (variable_get('language_count', 1) > 1) { $form['language'][$subscription->snid] = array('#value' => $languages[$subscription->language]->name); } $form['operations'][$subscription->snid] = array('#value' => l(t('edit'), 'admin/content/simplenews/users/edit/'. $subscription->snid, array(), drupal_get_destination())); } $form['snids'] = array('#type' => 'checkboxes', '#options' => $snids); $form['pager'] = array('#value' => theme('pager', NULL, 30, 0)); $form['#theme'] = 'simplenews_subscription_list'; return $form; } function simplenews_subscription_list_form_validate($form, &$form_state) { if (isset($form_state['values']['operation'])) { $snids = array_filter($form_state['values']['snids']); if (empty($snids)) { form_set_error('', t('No items selected.')); } } } function simplenews_subscription_list_form_submit($form, &$form_state) { if (isset($form_state['values']['operation'])) { $snids = array_filter($form_state['values']['snids']); $args = array($snids); switch ($form_state['values']['operation']) { case 'activate': call_user_func_array('simplenews_activate_subscription', $args); drupal_set_message(t('The update has been performed.')); break; case 'inactivate': call_user_func_array('simplenews_inactivate_subscription', $args); drupal_set_message(t('The update has been performed.')); break; } } } /** * Menu callback: Simplenews admin settings - General. */ function simplenews_admin_settings(&$form_state) { $vid = variable_get('simplenews_vid', ''); $address_default = variable_get('site_mail', ini_get('sendmail_from')); $form = array(); $form['simplenews_general_settings']['simplenews_content_types'] = array( '#type' => 'checkboxes', '#title' => t('Content types'), '#required' => TRUE, '#options' => array_map('check_plain', node_get_types('names')), '#default_value' => variable_get('simplenews_content_types', array('simplenews' => 'simplenews')), '#description' => t('Content types to be used as newsletter.'), ); $vocabulary_options = array('' => t('