function pb_request_list_flagged_page()
{
    global $wpdb;
    ?>

<div class="wrap">
<h2 class="logo-title">PrayBox Flagged Prayer Requests</h2>
<div id="pbx-wrap">

<?php 
    if (isset($_POST['action']) && $_POST['action'] == "remove_request") {
        $req_id = $_POST['pb_request_id'];
        $wpdb->query("DELETE FROM " . $wpdb->prefix . "pb_requests WHERE id='{$req_id}'");
        $wpdb->query("DELETE FROM " . $wpdb->prefix . "pb_flags WHERE request_id='{$req_id}'");
        ?>
<p><strong><?php 
        _e('Request Removed.', 'menu-test');
        ?>
</strong></p>
<?php 
    }
    ?>

<?php 
    if (isset($_POST['action']) && $_POST['action'] == "clear_flags") {
        $req_id = $_POST['pb_request_id'];
        $wpdb->query("DELETE FROM " . $wpdb->prefix . "pb_flags WHERE request_id='{$req_id}'");
        ?>
<p><strong><?php 
        _e('Flags Cleared.', 'menu-test');
        ?>
</strong></p>
<?php 
    }
    ?>

<?php 
    if (isset($_POST['action']) && $_POST['action'] == "remove_ban") {
        $req_id = $_POST['pb_request_id'];
        $ip = $_POST['pb_ip_address'];
        $time_now = time();
        $wpdb->query("DELETE FROM " . $wpdb->prefix . "pb_requests WHERE id='{$req_id}'");
        $wpdb->query("DELETE FROM " . $wpdb->prefix . "pb_flags WHERE request_id='{$req_id}'");
        $wpdb->insert($wpdb->prefix . 'pb_banned_ips', array('ip_address' => $ip, 'banned_date' => $time_now, 'reason' => 'request flagged as inappropriate'));
        ?>
<p><strong><?php 
        _e('Request Removed and IP Address Banned.', 'menu-test');
        ?>
</strong></p>
<?php 
    }
    ?>

<table class="pbx-data">
<tr><th>ID</th><th>First/Last/Email</th><th>Title</th><th width="300">Body</th><th>IP Address</th><th>Date Posted</th><th># Times Flagged</th><th>&nbsp;</th></tr>

<?php 
    $flags = $wpdb->get_results("SELECT request_id FROM " . $wpdb->prefix . "pb_flags GROUP BY request_id");
    if ($flags) {
        foreach ($flags as $flag) {
            $req_id = $flag->request_id;
            $num_flags = howManyFlags($req_id);
            $request = $wpdb->get_row("SELECT first_name,last_name,email,title,body,ip_address,submitted FROM " . $wpdb->prefix . "pb_requests WHERE id='{$req_id}'");
            $first_name = $request->first_name;
            $last_name = $request->last_name;
            $email = $request->email;
            $title = stripslashes($request->title);
            $body = prePgphOutput($request->body);
            $ip = $request->ip_address;
            $submitted = date("m-d-y", $request->submitted);
            echo "<tr><td>{$req_id}</td><td>{$first_name} {$last_name}<br />{$email}</td><td>{$title}</td><td>{$body}</td><td>{$ip}</td><td>{$submitted}</td><td>{$num_flags}</td><td align='center'>";
            echo "<form method='post'><input type='hidden' name='action' value='remove_request' /><input type='hidden' name='pb_request_id' value='{$req_id}' /><input type='submit' class='button-secondary' value='Remove' /></form>";
            echo "<form method='post'><input type='hidden' name='action' value='clear_flags' /><input type='hidden' name='pb_request_id' value='{$req_id}' /><input type='submit' class='button-secondary' value='Clear Flags' /></form>";
            echo "<form method='post'><input type='hidden' name='action' value='remove_ban' /><input type='hidden' name='pb_request_id' value='{$req_id}' /><input type='hidden' name='pb_ip_address' value='{$ip}' /><input type='submit' class='button-secondary' value='Remove/Ban' /></form>";
            echo "</td></tr>";
        }
    } else {
        echo "<tr><td colspan='8'>There are currently no flagged prayer requests.</td></tr>";
    }
    ?>
</table>
</div>
</div>
<?php 
}
示例#2
0
function displayRequests($page, $permalink)
{
    global $wpdb;
    $url_pos = strpos($permalink, "?");
    if ($url_pos === false) {
        $varprefix = "?";
    } else {
        $varprefix = "&";
    }
    $link = $permalink . $varprefix;
    $flag_thresh = get_option('pb_flag_threshhold');
    if (get_option('pb_timeframe_display') == 0) {
        $time_condition = "";
    } else {
        $timeframe = strtotime("-" . get_option('pb_timeframe_display') . " days");
        $time_condition = "AND submitted>{$timeframe}";
    }
    $listingsperpage = get_option('pb_page_display');
    $page_condition = $listingsperpage != 0 ? "LIMIT " . ($page - 1) * $listingsperpage . "," . $page * $listingsperpage : "";
    $this_display_qry_from = "FROM " . $wpdb->prefix . "pb_requests WHERE active='1' {$time_condition} ORDER BY submitted DESC {$page_condition}";
    $total_display_qry_from = "FROM " . $wpdb->prefix . "pb_requests WHERE active='1' {$time_condition}";
    $active_requests = $wpdb->get_results("SELECT id,title,body,submitted {$this_display_qry_from}");
    $num_requests = count($wpdb->get_results("SELECT id {$this_display_qry_from}"));
    $total_num_requests = count($wpdb->get_results("SELECT id {$total_display_qry_from}"));
    $req_list_output = "<div id='praybox_wrapper'>";
    $req_list_output .= "<p class='pbx-text'>" . get_option('pb_request_list_intro') . "</p>";
    if ($listingsperpage != 0) {
        $total_pages = ceil($total_num_requests / $listingsperpage);
        if ($total_pages != 1) {
            $i = 1;
            $req_list_output .= "<div class='pagination'>" . PB_ADMIN_PAGE . ": ";
            while ($i <= $total_pages) {
                if ($page == $i) {
                    $linkclass = " class='active'";
                } else {
                    $linkclass = "";
                }
                $req_list_output .= " <a href='{$link}" . "page={$i}' {$linkclass}>{$i}</a>";
                $i++;
            }
            $req_list_output .= "</div>";
        }
    }
    $req_list_output .= "<table class='pbx-req'>";
    $req_list_output .= "<tr><th>" . PB_REQ_TITLE . "</th><th>" . PB_REQ_NUM_PRAYERS . "</th><th>" . PB_REQ_SUBMITTED_ON . "</th><th>&nbsp;</th>";
    foreach ($active_requests as $a_req) {
        $req_id = $a_req->id;
        $title = stripslashes($a_req->title);
        if ($a_req->title != "") {
            $title = stripslashes($a_req->title);
        } else {
            $title = "<em>" . PB_REQ_UNTITLED . "</em>";
        }
        $body = stripslashes($a_req->body);
        $submitted = date("F j, Y", $a_req->submitted);
        $num_prayers = howManyPrayers($req_id);
        $num_flags = howManyFlags($req_id);
        if ($flag_thresh != 0) {
            $flag_ratio = $num_flags / $flag_thresh;
        } else {
            $flag_ratio = 0;
        }
        if ($flag_ratio < 1) {
            $req_list_output .= "<tr id='row_{$req_id}'><td>{$title}</td><td class='num-prayers'>{$num_prayers}</td><td>{$submitted}</td><td>";
            $req_list_output .= "<a href='#' req='{$req_id}'>" . PB_REQ_DETAILS . "</a>";
            $req_list_output .= "</td></tr>";
            $req_modals[] = "<div id='req_{$req_id}' class='pbx-modal' rel='{$req_id}'><h3 class='pbx-title'>{$title}</h3>" . "<div class='pbx-meta'><label>" . PB_REQ_SUBMITTED_BY . ":</label> {$display_name}</div>" . "<div class='pbx-body'><label>" . PB_REQ_REQUEST . ":</label> {$body}</div>" . "<div class='pbx-formfield pbx-formfield-footer'>" . "<button type='button' class='flag-btn flag-abuse'>" . PB_FLAG_ABUSE . "</button>" . "<button type='button' class='flag-btn flag-prayed'>" . PB_FLAG_PRAYED . "</button>" . "</div>" . "</div>";
        }
    }
    $req_list_output .= "</table>";
    if ($listingsperpage != 0) {
        $total_pages = ceil($total_num_requests / $listingsperpage);
        if ($total_pages != 1) {
            $i = 1;
            $req_list_output .= "<div class='pagination'>Page: ";
            while ($i <= $total_pages) {
                if ($page == $i) {
                    $linkclass = " class='active'";
                } else {
                    $linkclass = "";
                }
                $req_list_output .= " <a href='{$link}" . "page={$i}' {$linkclass}>{$i}</a>";
                $i++;
            }
            $req_list_output .= "</div>";
        }
    }
    $req_list_output .= "</div>";
    $req_list_modals = "<div class='pbx-modal-bg'>" . implode("\n", $req_modals) . "<div id='flag-response' class='pbx-modal'></div>" . "<div id='prayed-for' class='pbx-modal'>" . PB_THANK_YOU_PRAYER . "</div>" . "</div>";
    return $req_list_output . $req_list_modals;
}