Ok, I think I’ve been a total numpty. - I actually have 2 files, for 1 page - the main code page which is index.php and then a template file, index.tpl.php.
Here is the index.php code:
<?php
define('ADMIN_ROOT_PATH', './../../');
require ADMIN_ROOT_PATH . 'includes/common.inc.php';
$tpl = new template(ADMIN_ROOT_PATH . 'templates/');
$body = new template(ADMIN_ROOT_PATH . 'templates/database/posts/');
$tpl->set('title', $config['site_name'] . ' - Admin Panel - Database - Posts');
$tpl->set('navigation', '<a href="/">Home</a> » <a href="/admin/">Admin Panel</a> » <a href="/admin/database/">Database</a> » Posts');
// Posts
if (!isset($_POST['submit'])) {
/**
* get_num_posts() - get the number of posts
*
* @return integer, number of posts
*/
function get_num_posts() {
$search_string = isset($_POST['search_string']) ? check_input($_POST['search_string']) : '';
$result = $GLOBALS['db']->query("SELECT COUNT(p.post_id) FROM " . $GLOBALS['config']['db']['prefix'] . "database_posts p LEFT OUTER JOIN " . $GLOBALS['config']['db']['prefix'] . "categories c ON p.category_id = c.category_id WHERE p.title LIKE '%$search_string%' OR p.age LIKE '%$search_string%' OR p.agegroup LIKE '%$search_string%' OR p.gender LIKE '%$search_string%' OR p.ethnic_id LIKE '%$search_string%' OR p.religion LIKE '%$search_string%' OR p.lifestage LIKE '%$search_string%' OR p.address_line1 LIKE '%$search_string%' OR p.address_line2 LIKE '%$search_string%' OR p.city LIKE '%$search_string%' OR p.county LIKE '%$search_string%' OR p.postcode LIKE '%$search_string%' OR p.occupation LIKE '%$search_string%' OR p.ocother LIKE '%$search_string%' OR p.jobtitle LIKE '%$search_string%' OR p.hoccupation LIKE '%$search_string%' OR p.hjobtitle LIKE '%$search_string%' OR p.hseg LIKE '%$search_string%' OR p.email LIKE '%$search_string%' OR p.phone LIKE '%$search_string%' OR p.mobile LIKE '%$search_string%' OR p.cage LIKE '%$search_string%' OR p.cage2 LIKE '%$search_string%' OR p.cage3 LIKE '%$search_string%' OR p.cage4 LIKE '%$search_string%' OR p.cage5 LIKE '%$search_string%' OR p.clifestage LIKE '%$search_string%' OR p.clifeother LIKE '%$search_string%' OR p.pets LIKE '%$search_string%' OR p.pets2 LIKE '%$search_string%' OR p.pets3 LIKE '%$search_string%' OR p.pets4 LIKE '%$search_string%' OR p.cmake LIKE '%$search_string%' OR p.cmake2 LIKE '%$search_string%' OR p.cmodel LIKE '%$search_string%' OR p.regyear LIKE '%$search_string%' OR p.ctype LIKE '%$search_string%' OR p.ctype2 LIKE '%$search_string%' OR p.mobprov LIKE '%$search_string%' OR p.mobprov2 LIKE '%$search_string%' OR p.internet LIKE '%$search_string%' OR p.internet2 LIKE '%$search_string%' OR p.gas LIKE '%$search_string%' OR p.gas2 LIKE '%$search_string%' OR p.electric LIKE '%$search_string%' OR p.electric2 LIKE '%$search_string%' OR p.landline LIKE '%$search_string%' OR p.landline2 LIKE '%$search_string%' OR p.tvprov LIKE '%$search_string%' OR p.tvprov2 LIKE '%$search_string%' OR p.pastres LIKE '%$search_string%' OR p.socialgrad LIKE '%$search_string%' OR p.reshistory LIKE '%$search_string%' OR p.reshistory2 LIKE '%$search_string%' OR p.findme LIKE '%$search_string%' OR p.findme2 LIKE '%$search_string%' OR p.content LIKE '%$search_string%' OR c.category_name LIKE '%$search_string%'");
return $GLOBALS['db']->result($result, 0);
}
/**
* get_posts() - get the posts
*
* @param $page integer, current page
* @return array, posts
*/
function get_posts($page) {
$search_string = isset($_POST['search_string']) ? check_input($_POST['search_string']) : '';
$result = $GLOBALS['db']->query("SELECT p.*, c.category_name FROM " . $GLOBALS['config']['db']['prefix'] . "database_posts p LEFT OUTER JOIN " . $GLOBALS['config']['db']['prefix'] . "categories c ON p.category_id = c.category_id WHERE p.title LIKE '%$search_string%' OR p.age LIKE '%$search_string%' OR p.agegroup LIKE '%$search_string%' OR p.gender LIKE '%$search_string%' OR p.ethnic_id LIKE '%$search_string%' OR p.religion LIKE '%$search_string%' OR p.lifestage LIKE '%$search_string%' OR p.address_line1 LIKE '%$search_string%' OR p.address_line2 LIKE '%$search_string%' OR p.city LIKE '%$search_string%' OR p.county LIKE '%$search_string%' OR p.postcode LIKE '%$search_string%' OR p.occupation LIKE '%$search_string%' OR p.ocother LIKE '%$search_string%' OR p.jobtitle LIKE '%$search_string%' OR p.hoccupation LIKE '%$search_string%' OR p.hjobtitle LIKE '%$search_string%' OR p.hseg LIKE '%$search_string%' OR p.email LIKE '%$search_string%' OR p.phone LIKE '%$search_string%' OR p.mobile LIKE '%$search_string%' OR p.cage LIKE '%$search_string%' OR p.cage2 LIKE '%$search_string%' OR p.cage3 LIKE '%$search_string%' OR p.cage4 LIKE '%$search_string%' OR p.cage5 LIKE '%$search_string%' OR p.clifestage LIKE '%$search_string%' OR p.clifeother LIKE '%$search_string%' OR p.pets LIKE '%$search_string%' OR p.pets2 LIKE '%$search_string%' OR p.pets3 LIKE '%$search_string%' OR p.pets4 LIKE '%$search_string%' OR p.cmake LIKE '%$search_string%' OR p.cmake2 LIKE '%$search_string%' OR p.cmodel LIKE '%$search_string%' OR p.regyear LIKE '%$search_string%' OR p.ctype LIKE '%$search_string%' OR p.ctype2 LIKE '%$search_string%' OR p.mobprov LIKE '%$search_string%' OR p.mobprov2 LIKE '%$search_string%' OR p.internet LIKE '%$search_string%' OR p.internet2 LIKE '%$search_string%' OR p.gas LIKE '%$search_string%' OR p.gas2 LIKE '%$search_string%' OR p.electric LIKE '%$search_string%' OR p.electric2 LIKE '%$search_string%' OR p.landline LIKE '%$search_string%' OR p.landline2 LIKE '%$search_string%' OR p.tvprov LIKE '%$search_string%' OR p.tvprov2 LIKE '%$search_string%' OR p.pastres LIKE '%$search_string%' OR p.socialgrad LIKE '%$search_string%' OR p.reshistory LIKE '%$search_string%' OR p.reshistory2 LIKE '%$search_string%' OR p.findme LIKE '%$search_string%' OR p.findme2 LIKE '%$search_string%' OR p.content LIKE '%$search_string%' OR c.category_name LIKE '%$search_string%' ORDER BY title DESC LIMIT " . ($page - 1) * 15 . ", 15");
return fetch_array($result);
}
$body->set('page', isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1);
$tpl->set('body', $body->fetch('index.tpl.php'));
} else {
$result = $db->query("SELECT post_id FROM " . $config['db']['prefix'] . "database_posts");
while ($post = $db->fetch_array($result)) {
$status = isset($_POST['status' . $post['post_id']]) && $_POST['status' . $post['post_id']] == 0 ? 0 : 1;
$delete = isset($_POST['delete' . $post['post_id']]) && $_POST['delete' . $post['post_id']] == 'yes' ? 'yes' : 'no';
if (isset($_POST['status' . $post['post_id']])) {
$db->query("UPDATE " . $config['db']['prefix'] . "database_posts SET status = $status WHERE post_id = $post[post_id]");
}
if ($delete == 'yes') {
$db->query("DELETE FROM " . $config['db']['prefix'] . "database_posts WHERE post_id = $post[post_id]");
$db->query("DELETE FROM " . $config['db']['prefix'] . "database_comments WHERE post_id = $post[post_id]");
}
}
output('Posts successfully updated!');
redirect('/admin/database/posts/', 2);
}
echo $tpl->fetch('layout.tpl.php');
?>
and here is the HTML/ PHP (bits) page…
<div style="position: absolute; top: 5px; right: 5px;"><?php echo "<a href='mailto:".$emails."'>Mass Mail</a>"; ?> - <a href="/admin/database/posts/new.php"><img src="/admin/images/button_new.gif" border="0" alt="New" /></a></div>
<form method="post" action="/admin/database/posts/">
<p align="center" style="margin-top: 0;">Search <input type="text" name="search_string" value="<?php echo isset($_POST['search_string']) ? $_POST['search_string'] : ''; ?>" /> <input type="submit" name="search" value="Go" /></p>
</form>
<form method="post" action="/admin/database/posts/">
<div class="table_box">
<table border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<td colspan="7" class="header"><h1>Posts</h1></td>
</tr>
<tr>
<td width="10%" class="table_row"><strong>Delete:</strong></td>
<td width="30%" class="table_row"><strong>Name:</strong></td>
<td width="50%" class="table_row"><strong>Email:</strong></td>
<td width="20%" class="table_row"></td>
</tr>
<?php foreach (get_posts($page) as $post) { ?>
<tr>
<td align="center" width="10%" class="table_row"><input type="checkbox" name="delete<?php echo $post['post_id']; ?>" value="yes" /></td>
<td width="30%" class="table_row"><?php echo $post['title']; ?></td>
<td width="50%" class="table_row"><a href="mailto:<?php echo $post['email']; ?>"><?php echo $post['email']; ?></a></td>
<td width="20%" class="table_row"><a href="/admin/database/posts/edit.php?post_id=<?php echo $post['post_id']; ?>" onclick="return popup('/admin/database/posts/edit.php?post_id=<?php echo $post['post_id']; ?>')"><img src="/admin/images/button_edit.gif" border="0" alt="Edit" /></a></td>
</tr>
<?php } ?>
</table>
</div>
<?php echo multipage(get_num_posts(), 15, $page, '/admin/database/posts/index.php?page='); ?>
<p align="center"><input type="submit" name="submit" value="Submit Changes" /></p>
</form>
You can see in the HTML code I have used the code…
<?php echo "<a href='mailto:".$emails."'>Mass Mail</a>"; ?>
I am guessing I need to include the
<?php $emails[] = $post['email']; } $emails = implode(",",array_unique($emails)); ?>
somewhere within the index.php page? - but I am also assuming it would be different as $post would not work.