# See the files README and LICENSE for details
# --------------------------------------------------------
# $Id: admin_manage_notes.php,v 1.22 2003/08/20 11:26:16 vboctor Exp $
# --------------------------------------------------------
require_once 'core' . DIRECTORY_SEPARATOR . 'api.php';
login_cookie_check();
access_ensure_check_action(ACTION_NOTES_MODERATE);
print_html_top();
print_head_top();
print_title($g_window_title);
print_css($g_css_inc_file);
print_head_bottom();
print_body_top();
print_header($g_page_title);
print_top_page($g_top_page_inc);
print_admin_menu();
$query = "SELECT p.*, COUNT(n.id) as notes_count\r\n\t\t\tFROM " . config_get('phpWN_page_table') . " p,\r\n\t\t\t\t" . config_get('phpWN_note_table') . " n\r\n\t\t\tWHERE (p.id=n.page_id) AND (n.visible=" . NOTE_VISIBLE_PENDING . ")\r\n\t\t\tGROUP BY p.id \r\n\t\t\tORDER BY notes_count DESC";
$result = db_query($query);
echo <<<EOT
\t<p><strong>Following are the pages that have notes pending approval:</strong></p>
\t<table class="box" summary="">
\t\t<tr><th>Page</th><th>URL</th><th>Pending Notes</th></tr>

EOT;
$count = 0;
while ($row = db_fetch_array($result)) {
    $color = util_alternate_colors($count++);
    extract($row, EXTR_PREFIX_ALL, 'v');
    echo "<tr bgcolor=\"{$color}\"><td><a href=\"{$v_url}\">{$v_page}</a></td><td>{$v_url}</td><td>{$v_notes_count}</td></tr>\n";
}
$t_now = date(config_get('date_format'));
function theme_body($p_page_data)
{
    if (false === $p_page_data) {
        # @@@ Handle not indexed (and auto index off)
        return;
    }
    global $g_note_add_page, $s_add_note_link, $s_manage, $s_admin, $g_web_directory, $g_theme;
    $t_notes = $p_page_data['notes'];
    $t_page = $p_page_data['page'];
    $t_page_id = $p_page_data['id'];
    $t_images_base = $g_web_directory . 'themes/' . $g_theme . '/images/';
    $add_picture = $t_images_base . 'notes_add.gif';
    $help_picture = $t_images_base . 'notes_about.gif';
    $prev_picture = $t_images_base . 'caret_left.gif';
    $next_picture = $t_images_base . 'caret_right.gif';
    if (false === $p_page_data['preview']) {
        $t_link_start = "<a href=\"{$g_note_add_page}?f_page_id={$t_page_id}\">";
        $t_link_end = '</a>';
    } else {
        $t_link_start = $t_link_end = '';
    }
    #
    # HEADER
    #
    echo <<<EOT
\t\t<div class="phpnet">
\t\t<table summary="" cellpadding="4" cellspacing="0">
\t\t\t<tr class="dark">
\t\t\t\t<td><small>User Contributed Notes</small><br /><strong>{$t_page}</strong></td>
\t\t\t\t<td align="right">
\t\t\t\t\t{$t_link_start}<img src="{$add_picture}" width="13" height="13" alt="Add Notes" />{$t_link_end}
\t\t\t\t\t<img src="{$help_picture}" width="13" height="13" alt="About Notes" />
\t\t\t\t</td>
\t\t\t</tr>
EOT;
    #
    # NOTES
    #
    if (0 === count($t_notes)) {
        echo <<<EOT
\t\t\t<tr class="light">
\t\t\t\t<td colspan="2">There are no user contributed notes for this page.</td>
\t\t\t</tr>
EOT;
    } else {
        for ($i = 0; $i < count($t_notes); $i++) {
            $t_moderation = '';
            $t_note_info = $t_notes[$i];
            if (false === $p_page_data['preview']) {
                if (access_check_action(ACTION_NOTES_MODERATE)) {
                    $t_url = $p_page_data['url'];
                    $t_moderation = '';
                    if ($t_note_info['visible'] != NOTE_VISIBLE_ACCEPTED) {
                        $t_moderation .= link_note_action($t_note_info['id'], 'accept', $t_url, access_check_action(ACTION_NOTES_MODERATE_ACCEPT)) . ' ';
                    }
                    if ($t_note_info['visible'] != NOTE_VISIBLE_PENDING) {
                        $t_moderation .= link_note_action($t_note_info['id'], 'queue', $t_url, access_check_action(ACTION_NOTES_MODERATE_QUEUE)) . ' ';
                    }
                    if ($t_note_info['visible'] != NOTE_VISIBLE_DECLINED) {
                        $t_moderation .= link_note_action($t_note_info['id'], 'decline', $t_url, access_check_action(ACTION_NOTES_MODERATE_DECLINE)) . ' ';
                    }
                    if ($t_note_info['visible'] != NOTE_VISIBLE_ARCHIVED) {
                        $t_moderation .= link_note_action($t_note_info['id'], 'archive', $t_url, access_check_action(ACTION_NOTES_MODERATE_ARCHIVE)) . ' ';
                    }
                    $t_moderation .= link_note_action($t_note_info['id'], 'edit', $t_url, access_check_action(ACTION_NOTES_EDIT));
                    if ($t_note_info['visible'] != NOTE_VISIBLE_DELETED) {
                        $t_moderation .= link_note_action($t_note_info['id'], 'delete', $t_url, access_check_action(ACTION_NOTES_MODERATE_DELETE));
                    }
                }
            }
            if (isset($t_note_info['id']) && $t_note_info['id'] != 0) {
                $t_id = (int) $t_note_info['id'];
                $t_visibility = '';
                if (NOTE_VISIBLE_ACCEPTED != $t_note_info['visible']) {
                    $t_visibility = '(' . note_get_visibility_str($t_note_info['visible']) . ') - ';
                }
                $t_id_view = "<tt>{$t_visibility}#{$t_id}<br />{$t_moderation}</tt>";
                $t_id_bookmark = "<a name=\"{$t_id}\"></a>";
            } else {
                $t_id_view = '&nbsp;';
                $t_id_bookmark = '';
            }
            if (isset($t_note_info['email'])) {
                $t_email = $t_note_info['email'];
            } else {
                $t_email = '';
            }
            if (isset($t_note_info['date'])) {
                # 06-Feb-2002 02:28
                $t_date = date('d-M-Y G:i', $t_note_info['date']);
            } else {
                $t_date = '';
            }
            if (isset($t_note_info['note'])) {
                $t_note = nl2br('<tt>' . $t_note_info['note'] . '</tt>');
            } else {
                $t_note = '&nbsp;';
            }
            echo <<<EOT
\t\t\t\t<tr class="light">
\t\t\t\t\t<td colspan="2">
\t\t\t\t\t\t{$t_id_bookmark}

\t\t\t\t\t\t<table summary="" cellpadding="2" cellspacing="0">
\t\t\t\t\t\t\t<tr class="light">
\t\t\t\t\t\t\t\t<td><strong>{$t_email}</strong><br />{$t_date}</td>
\t\t\t\t\t\t\t\t<td align="right">{$t_id_view}</td>
\t\t\t\t\t\t\t</tr>
\t\t\t\t\t\t\t<tr class="lighter">
\t\t\t\t\t\t\t\t<td colspan="2">{$t_note}</td>
\t\t\t\t\t\t\t</tr>
\t\t\t\t\t\t</table>
\t\t\t\t\t</td>
\t\t\t\t</tr>
EOT;
        }
    }
    #
    # FOOTER
    #
    if (empty($p_page_data['prev_page'])) {
        $t_prev_text = '';
    } else {
        $t_prev_text = "<img src=\"{$prev_picture}\" width=\"11\" height=\"7\" alt=\"" . $p_page_data['prev_page'] . "\" />" . link_create($p_page_data['prev_url'], $p_page_data['prev_page'], true, '', '');
    }
    if (empty($p_page_data['next_page'])) {
        $t_next_text = '';
    } else {
        $t_next_text = link_create($p_page_data['next_url'], $p_page_data['next_page'], true, '', '') . "<img src=\"{$next_picture}\" width=\"11\" height=\"7\" alt=\"" . $p_page_data['next_page'] . "\" />";
    }
    if (empty($t_prev_text) && empty($t_next_text)) {
        $t_navigation_row = '';
    } else {
        $t_navigation_row = "<tr><td>{$t_prev_text}</td><td align=\"right\">{$t_next_text}</td></tr>";
    }
    if (false === $p_page_data['preview']) {
        $t_link_start = "<a href=\"{$g_note_add_page}?f_page_id={$t_page_id}\">";
        $t_link_end = '</a>';
    } else {
        $t_link_start = $t_link_end = '';
    }
    if (0 !== count($t_notes)) {
        echo <<<EOT
\t\t\t<tr class="dark">
\t\t\t\t<td colspan="2" align="right">
\t\t\t\t{$t_link_start}<img src="{$add_picture}" width="13" height="13" alt="Add Notes" />{$t_link_end}
\t\t\t\t<img src="{$help_picture}" width="13" height="13" alt="About Notes" />
\t\t\t\t</td>
\t\t\t</tr>
EOT;
    }
    if (false === $p_page_data['preview']) {
        # Tue, 17 Sep 2002
        $t_last_updated = date('D, d M Y - G:i:s', $p_page_data['last_updated']);
        echo <<<EOT
\t\t\t<tr class="dark"><td colspan="2">
\t\t\t\t<table class="light" cellpadding="0" cellspacing="4">
\t\t\t\t\t{$t_navigation_row}
\t\t\t\t\t<tr><td align="right" colspan="2"><small>Last updated: {$t_last_updated}</small></td></tr>
\t\t\t\t</table>
\t\t\t</td></tr>
EOT;
    }
    echo '</table></div>';
    if (false === $p_page_data['preview'] && access_is_logged_in()) {
        echo '<div class="pwn">';
        print_admin_menu();
        echo '</div>';
    }
}