function post_notification_admin_sub() { global $wpdb; $t_emails = $wpdb->prefix . 'post_notification_emails'; $t_cats = $wpdb->prefix . 'post_notification_cats'; if ($_GET['action'] == 'remove_email') { $remove = true; } else { $remove = false; } echo '<h3>' . __('List of addresses:', 'post_notification') . '</h3>'; if (isset($_POST['removeEmailChecked'])) { if ($_POST['removeEmail'] == "") { echo '<div class = "error">' . __('No address checked!', 'post_notification') . '</div>'; } else { echo __('The following addresses were deleted:', 'post_notification') . '<br /><br />'; foreach ($_POST['removeEmail'] as $removeAddress) { //Multiple table delete only works with mysql 4.0 or 4.1 $wpdb->query("DELETE {$t_cats}, {$t_emails} \r\n\t\t\t\t\tFROM {$t_emails} LEFT JOIN {$t_cats} USING (id) \r\n\t\t\t\t\tWHERE email_addr = '{$removeAddress}'"); echo "{$removeAddress}<br />"; } } } else { if (isset($_POST['email'])) { $email = $_POST['email']; } else { $email = '*'; } if (isset($_POST['cats'])) { $sel_cats = $_POST['cats']; } else { $sel_cats = ''; } if (!is_array($sel_cats)) { $sel_cats = array(); } if (isset($_POST['limit'])) { $limit = $_POST['limit']; } else { $limit = 50; } if (!is_numeric($limit)) { $limit = 50; } if ($limit < 1) { $limit = 1; } if (isset($_POST['start'])) { $start = $_POST['start']; } else { $start = ''; } if (!is_numeric($start)) { $start = 0; } if (isset($_POST['next'])) { $start += $limit; } if (isset($_POST['perv'])) { $start -= $limit; } if ($start < 0) { $start = 0; } if (isset($_POST['sortby'])) { $sortby = $_POST['sortby']; } else { $sortby = 'id'; } if (isset($_POST['sortorder'])) { $sortorder = $_POST['sortorder']; } else { $sortorder = 'ASC'; } $sortsrt = " {$sortby} {$sortorder} "; $show_id = isset($_POST['show_id']); $show_list = isset($_POST['show_list']); $show_unconf = isset($_POST['show_unconf']); echo '<form method="post" action="admin.php?page=post_notification/admin.php&action=' . $_GET['action'] . '"> '; echo __('Email:', 'post_notification') . ' <input name="email" type="text" size="30" value="' . $email . '"> '; echo __('Cats:', 'post_notification') . ' <select name="cats[]" multiple="multiple" style="height:auto"> '; $cats = get_categories(); $walker = new Walker_pn_CategoryDropdown(); echo call_user_func_array(array(&$walker, 'walk'), array($cats, 0, array('sel_cat' => $sel_cats))); echo '</select> '; echo __('Limit:', 'post_notification') . ' <input name="limit" type="text" size="4" value="' . $limit . '" /> '; echo __('Start at:', 'post_notification') . ' <input name="start" type="text" size="4" value="' . $start . '" /> '; echo __('Sort by:', 'post_notification') . ' <select name="sortby" size = "1" > ' . '<option value="id" ' . ($sortby == 'id' ? 'selected="selected"' : '') . '>' . __('ID', 'post_notification') . '</option>' . '<option value="email_addr" ' . ($sortby == 'email_addr' ? 'selected="selected"' : '') . '>' . __('Address', 'post_notification') . '</option>' . '<option value="date_subscribed" ' . ($sortby == 'date_subscribed' ? 'selected="selected"' : '') . '>' . __('Date accepted', 'post_notification') . '</option>' . '<option value="subscribe_ip" ' . ($sortby == 'subscribe_ip' ? 'selected="selected"' : '') . '>' . __('IP', 'post_notification') . '</option>' . '</select>'; echo ' <select name="sortorder" size = "1" > ' . '<option value="ASC" ' . ($sortorder == 'ASC' ? 'selected="selected"' : '') . '>' . __('Ascending', 'post_notification') . '</option>' . '<option value="DESC" ' . ($sortorder == 'DESC' ? 'selected="selected"' : '') . '>' . __('Descending', 'post_notification') . '</option>' . '</select>'; echo '<BR /> '; echo __('Show unconfirmed mails:', 'post_notification') . ' <input name="show_unconf" type="checkbox" '; if ($show_unconf) { echo ' checked = "checked" '; } echo '/><br /> '; echo __('Only show cat ids:', 'post_notification') . ' <input name="show_id" type="checkbox" '; if ($show_id) { echo ' checked = "checked" '; } echo '/><br/> '; echo __('Show as list:', 'post_notification') . ' <input name="show_list" type="checkbox" '; if ($show_list) { echo ' checked = "checked" '; } echo '/> '; ?> </select><br /> <input type="submit" name="submit" value="<?php _e('Update', 'post_notification'); ?> " /><input type="submit" name="perv" value="<<--" /><input type="submit" name="next" value="-->>" /> <form> <?php ///Ok, now let's do some work. if ($remove) { echo '<form method="post" action="admin.php?page=post_notification/admin.php&action=remove_email">'; } $email = str_replace('*', '%', $email); $sel_cats = implode(',', $sel_cats); $show_unconf ? $wadd = ' AND gets_mail IS NULL ' : ($wadd = ' AND gets_mail = 1 '); if ($sel_cats == '') { $emails = $wpdb->get_results("SELECT email_addr, gets_mail, last_modified, date_subscribed, id, act_code, subscribe_ip FROM {$t_emails} WHERE email_addr LIKE '{$email}' {$wadd} ORDER BY {$sortsrt} LIMIT {$start}, {$limit} "); $total = $wpdb->get_var("SELECT COUNT(*) FROM {$t_emails} WHERE email_addr LIKE '{$email}' {$wadd}"); } else { $emails = $wpdb->get_results("SELECT email_addr, gets_mail, last_modified, date_subscribed, e.id AS id, act_code, subscribe_ip FROM {$t_emails} e, {$t_cats} c WHERE email_addr LIKE '{$email}' {$wadd} AND e.id = c.id AND c.cat_id IN ({$sel_cats}) GROUP BY e.id ORDER BY {$sortsrt} LIMIT {$start}, {$limit} "); $total = $wpdb->get_var("SELECT COUNT(e.id) FROM {$t_emails} e, {$t_cats} c WHERE email_addr LIKE '{$email}' {$wadd} AND e.id = c.id AND c.cat_id IN ({$sel_cats})"); } if (!$emails) { echo '<p class="error">' . __('No entries found!', 'post_notification') . '</p>'; echo '</div>'; return; } echo '<p>'; echo str_replace(array('@@start', '@@end', '@@total'), array($start, $start + count($emails) - 1, $total), __('Showing entry @@start to @@end of @@total entries.', 'post_notification')); echo '</p>'; if (!$show_list) { echo '<table><tr>'; if ($remove) { echo '<td width="20"><b> </b></td>'; } echo '<td width="200"><b>' . __('Address', 'post_notification') . '</b></td> <td width="125"><b>' . __('Accepted', 'post_notification') . '</b></td> <td width="255"><b>' . __('Date accepted', 'post_notification') . '</b></td> <td><b>' . __('Subscribed categories', 'post_notification') . '</b></td> <td><b>' . __('IP', 'post_notification') . '</b></td> </tr>'; } else { echo '<br /><br />'; } foreach ($emails as $email) { $email_addr = $email->email_addr; $gets_mail = $email->gets_mail; $last_modified = $email->last_modified; $datestr = get_settings('date_format') . ' ' . get_settings('time_format'); $date_subscribed = post_notification_date_i18n_tz($datestr, post_notification_mysql2gmdate($email->date_subscribed)); $id = $email->id; $ip = long2ip($email->subscribe_ip); if ($gets_mail == "1") { $gets_mail = __('Yes', 'post_notification'); } else { $gets_mail = __('No', 'post_notification'); } $modlink = post_notification_get_mailurl($email->email_addr, $email->act_code); $subcats_db = $wpdb->get_results("SELECT cat_id FROM {$t_cats} WHERE id = " . $id . " ORDER BY cat_id ASC"); $catnames = ''; if (isset($subcats_db)) { foreach ($subcats_db as $subcat) { $cat = $subcat->cat_id; if ($cat == 0) { if ($show_id) { $catnames .= '<abbr title="' . __('All', 'post_notification') . '">0</abbr>, '; } else { $catnames .= __('All', 'post_notification') . ', '; } } else { $cat = get_category($cat); //ID -> Object if ($show_id) { $catnames .= '<abbr title="' . $cat->cat_name . '">' . $subcat->cat_id . '</abbr>, '; } else { $catnames .= $cat->cat_name . ', '; } } } $catnames = substr($catnames, 0, -2); } if (!$show_list) { echo "<tr>"; if ($remove) { echo "<td><input type=\"checkbox\" name=\"removeEmail[]\" value=\"{$email_addr}\" /></td>"; } echo "<td><a href=\"{$modlink}\" target=\"_blank\">{$email_addr}<a></td>"; echo "<td>{$gets_mail}</td>"; echo "<td>{$date_subscribed}</td>"; echo "<td>{$catnames}</td>"; echo "<td>{$ip}</td>"; echo "</tr>"; } else { echo $email_addr . '<br/>'; } } echo "</table>"; if ($remove) { ?> <script type="text/javascript"> function post_notification_checkall(value){ boxes = document.getElementsByName("removeEmail[]"); for(i = 0; i < boxes.length; i++){ boxes[i].checked = value; } } </script> <?php echo '<br />' . '<input type="button" onclick="post_notification_checkall(true)" value="' . __('Check all', 'post_notification') . '" />' . '<input type="button" onclick="post_notification_checkall(false)" value="' . __('Uncheck all', 'post_notification') . '" />' . '<br /> <input type="submit" name="removeEmailChecked" value="' . __('Delete', 'post_notification') . '"></form>'; } } }
function post_notification_admin_sub() { global $wpdb; $t_posts = $wpdb->prefix . 'post_notification_posts'; $t_cats = $wpdb->prefix . 'post_notification_cats'; $t_emails = $wpdb->prefix . 'post_notification_emails'; $datestr = get_settings('date_format') . ' ' . get_settings('time_format'); //Run the install require_once POST_NOTIFICATION_PATH . 'install.php'; post_notification_install(); //Check for problems $mutex = @fopen(POST_NOTIFICATION_PATH . '_temp/post_notification.lock', 'w'); if ($mutex == false) { echo '<div class="error">' . __('Couldn\'t create File:', 'post_notification') . ' ' . POST_NOTIFICATION_PATH . '_temp/post_notification.lock<br />' . __('Please assure the the path is writeable.', 'post_notification') . ' ' . __('This is an error!', 'post_notification') . '</div>'; } else { fclose($mutex); } if (!function_exists('iconv')) { echo '<div class="error">' . __('PHP was compiled without iconv-libs. This might cause severe trouble using UTF-8 with special chars or umlauts.', 'post_notification') . ' ' . __('Most hosters support this, as it is a sensible php-extension.', 'post_notification') . ' ' . '<a href="http://php.net/manual/ref.iconv.php">' . __('More information.', 'post_notification') . '</a></div>'; } if (!function_exists('mb_detect_encoding')) { echo '<div class="error">' . __('This version of PHP does not support the function mb_detect_encoding. You might experience some trouble with non-ASCII characters.', 'post_notification') . ' ' . __('Most hosters support this, as it is a sensible php-extension.', 'post_notification') . ' ' . '<a href="http://php.net/manual/ref.mbstring.php">' . __('More information.', 'post_notification') . '</a></div>'; } if (!function_exists('html_entity_decode')) { echo '<div class="error">' . __('This version of PHP does not support the function html_entity_decode. Sending out text mails will not be possible.', 'post_notification') . ' ' . __('Please contact your hoster.', 'post_notification') . '</a></div>'; } if ('' != ($dest = post_notification_installtheme())) { echo '<div class="error">' . __('Couldn\'t create File:', 'post_notification') . $dest . ' ' . __('Please assure the the path is writeable.', 'post_notification') . ' ' . __('You can also copy the file from the plugin directory manually.', 'post_notification') . '</div>'; } if (get_option('post_notification_debug') == 'yes') { echo '<div class="error">' . __('PN is in debugging mode. This should only be on, if something isn\'t working correctly.', 'post_notification') . '</div>'; } if (get_option('post_notification_uninstall') == 'yes') { require_once POST_NOTIFICATION_PATH . "install.php"; echo '<div class="error">' . __('It seems like you want to uninstall this Plugin. Please deactivate it or change the setting the options. ', 'post_notification') . '</div>'; } else { if ($wpdb->get_var("SHOW TABLES LIKE '{$t_cats}'") == NULL) { echo '<div class="error">' . __('It seems like there is some trouble creating the tables in the DB. If you\'re lucky there should be some errormessages on this page.', 'post_notification') . '</div>'; } } if (ini_get('max_execution_time') != 0 && ini_get('max_execution_time') < 15) { echo '<div class="error">' . __('The maximum executiontime is very low.', 'post_notification') . ' ' . '<a href="http://php.net/manual/ref.info.php#ini.max-execution-time">' . __('More information.', 'post_notification') . '</a></div>'; } if (get_option('db_version') > 4772 && get_option('db_version') < 6124 && substr(get_option('post_notification_template'), -5) == '.html') { echo '<div class="error">' . __('There is a bug in WP handling HTML-Mails. Please make sure a mail-plugin is installed.', 'post_notification') . ' <a href="http://wordpress.org/extend/plugins/wordpress-22-mailfix/">Wordpress 2.2 Mailfix</a> </div>'; } //clean up - just in case. //Probably there's something with better performance, but as long there are not // 10 000 emails in the db this shouldn't matter. /* Not well enaugh tested -> Next version $wpdb->query(" DELETE $t_cats, t_emails FROM $t_cats LEFT JOIN t_emails WHERE email_addr IS NULL "); */ //Try to send. if (get_option('post_notification_debug') == 'yes') { post_notification_send_check(true); } //------------ Some info..... $nummails = $wpdb->get_var("SELECT COUNT(*) FROM {$t_emails} WHERE gets_mail = 1"); echo '<p>' . __('Number of Subscribers:', 'post_notification') . "<b> {$nummails} </b></p>"; //------------ Some advertising ---- if ($nummails > 500) { echo '<p><b>' . __('Looks like you are realy using this plugin.', 'post_notification') . '</b> <a href="http://pn.xn--strbe-mva.de/forum.php?req=thread&postid=8">' . __('What about a donation?.', 'post_notification') . '</a></p>'; } echo '<p>' . __('The time is:', 'post_notification'); echo ' <b>' . post_notification_date_i18n_tz($datestr, time()) . '</b></p>'; //Can use i18n_time as it uses date echo '<p>' . __('Posts to be notified.', 'post_notification'); $posts = $wpdb->get_results("SELECT id, post_title, post_date_gmt, notification_sent, post_status, date_saved " . post_notification_sql_posts_to_send(true) . " ORDER BY post_date_gmt DESC"); echo '<table> <tr class="alternate"><th>' . __('Post-ID', 'post_notification') . '</th><th>' . __('Post title', 'post_notification') . '</th><th>' . __('Publish-date', 'post_notification') . '</th><th>' . __('Save-date', 'post_notification') . '</th><th>' . __('Last email-id', 'post_notification') . '</th></tr>'; if (empty($posts)) { echo '<tr><td colspan="5" class="alternate">' . __('None queued', 'post_notification') . '</td></tr>'; } else { foreach ($posts as $post) { echo '<tr class="alternate"><td>' . $post->id . '</td><td>' . $post->post_title . '</td><td>' . post_notification_date_i18n_tz($datestr, post_notification_mysql2gmdate($post->post_date_gmt)) . '</td><td>' . post_notification_date_i18n_tz($datestr, post_notification_mysql2gmdate($post->date_saved)) . '</td><td>' . $post->notification_sent . '</td></tr>'; } } echo '</table></p>'; echo '<p>' . __('The next mail will be sent:', 'post_notification') . ' '; if (get_option('post_notification_nextsend') == '-1') { _e('None queued', 'post_notification'); } else { echo post_notification_date_i18n_tz($datestr, get_option('post_notification_nextsend')); } echo '</p>'; echo '<p>' . __('The last mail was sent:', 'post_notification') . ' '; echo post_notification_date_i18n_tz($datestr, get_option('post_notification_lastsend')); echo '</p>'; echo '<p>' . __('The last post was saved:', 'post_notification') . ' '; echo post_notification_date_i18n_tz($datestr, get_option('post_notification_lastpost')); echo '</p>'; }