<commit_before><?php

###
# Dashboard
#
# PURPOSE
# An administrative overview of the goings-on of Richmond Sunlight.
#
###

# INCLUDES
# Include any files or libraries that are necessary for this specific
# page to function.
include_once $_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/includes/settings.inc.php';

# DECLARATIVE FUNCTIONS
# Run those functions that are necessary prior to loading this specific
# page.
$database = new Database;
$database->connect_mysqli();

# PAGE METADATA
$page_title = 'Dashboard';
$site_section = 'admin';

# PAGE CONTENT

/*
 * If there's an operation to perform prior to loading the page
 */
if (isset($_GET['op']))
{

	$op = $_GET['op'];
	$user_id = $_GET['user_id'];

	/*
	 * Delete a user
	 */
	if ( $op == 'delete' && !empty($user_id) )
	{
		$user = new User;
		$user->id=$user_id;
		$user->delete();
	}
}

$page_body = '
		<div>
			<a href="/admin/comments/">Comments</a> |
			<a href="/admin/tag.php">Tag Bills</a> |
			<a href="/admin/video/">Video</a> |
			<a href="apc.php">APC</a>  |
			<a href="memcache.php">Memcached</a>
		</div>';

# Select the tags from the past 3 days that were not added by me.
$sql = 'SELECT tags.id, tags.tag, bills.number AS bill, sessions.year, users.name AS author
		FROM tags
		LEFT JOIN bills
			ON tags.bill_id=bills.id
		LEFT JOIN sessions
			ON bills.session_id=sessions.id
		LEFT JOIN users
			ON tags.user_id=users.id
		WHERE DATE_SUB(CURDATE(), INTERVAL 3 DAY) <= tags.date_created
		AND users.trusted = "n"
		ORDER BY tags.date_created DESC, bills.id DESC';
$result = mysqli_query($GLOBALS['db'], $sql);
if (mysqli_num_rows($result) > 0)
{
	$page_body .= '
		<h2>Recent Tags</h2>
		<p>The following tags have been applied to bills in the last three days by non-trusted
		users.</p>';
    while ($tag = mysqli_fetch_array($result))
    {
        $tag = array_map('stripslashes', $tag);
        $tag['bill'] = strtolower($tag['bill']);
        $page_body .= '<a href="/bill/'.$tag['year'].'/'.$tag['bill'].'/" title="'
            .$tag['author'].'">'.$tag['tag'].'</a>—[<a href="/process-tags.php?delete='
            .$tag['id'].'">x</a>] ';
    }
}

# Select the new users from the past month.
$sql = 'SELECT name, id, url
		FROM users
		WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date_created
		AND name IS NOT NULL
		ORDER BY date_created DESC';
$result = mysqli_query($GLOBALS['db'], $sql);
if (mysqli_num_rows($result) > 0)
{
    $page_body .= '
		<script>
		$(document).ready(function(){
			$(".user_delete").click(function(){
				return confirm("Are you sure you want to delete this user?");
			});
		});
		</script>
		<h2>Recent Registrants</h2>
		<p>The following people have signed up in the past 30 days.</p>';
    while ($user = mysqli_fetch_assoc($result))
    {
        $user = array_map('stripslashes', $user);
        if (!empty($user['url']))
        {
            $page_body .= '<a href="'.$user['url'].'">';
        }
        $page_body .= $user['name'];
        if (!empty($user['url']))
        {
            $page_body .= '</a> ';
		}
		$page_body .= '[<a href="?op=delete&amp;user_id=' . $user['id'] . '" class="user_delete">x</a>]';
        $page_body .= ', ';
    }
}

# Select the number of comments for the past seven days.
$sql = 'SELECT DATE_FORMAT(date_created, "%Y-%m-%d") AS date, COUNT(*) AS number
		FROM comments
		GROUP BY date
		ORDER BY date DESC
		LIMIT 7';
$result = mysqli_query($GLOBALS['db'], $sql);
if (mysqli_num_rows($result) > 0)
{
    $page_body .= '
		<h2>Comments by Day</h2>
		<p>This is the number of comments, by day. Only lists the last seven days for which<commit_msg>Style user listing more nicely<commit_after><?php

###
# Dashboard
#
# PURPOSE
# An administrative overview of the goings-on of Richmond Sunlight.
#
###

# INCLUDES
# Include any files or libraries that are necessary for this specific
# page to function.
include_once $_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/includes/settings.inc.php';

# DECLARATIVE FUNCTIONS
# Run those functions that are necessary prior to loading this specific
# page.
$database = new Database;
$database->connect_mysqli();

# PAGE METADATA
$page_title = 'Dashboard';
$site_section = 'admin';

# PAGE CONTENT

/*
 * If there's an operation to perform prior to loading the page
 */
if (isset($_GET['op']))
{

	$op = $_GET['op'];
	$user_id = $_GET['user_id'];

	/*
	 * Delete a user
	 */
	if ( $op == 'delete' && !empty($user_id) )
	{
		$user = new User;
		$user->id=$user_id;
		$user->delete();
	}
}

$page_body = '
		<div>
			<a href="/admin/comments/">Comments</a> |
			<a href="/admin/tag.php">Tag Bills</a> |
			<a href="/admin/video/">Video</a> |
			<a href="apc.php">APC</a>  |
			<a href="memcache.php">Memcached</a>
		</div>';

# Select the tags from the past 3 days that were not added by me.
$sql = 'SELECT tags.id, tags.tag, bills.number AS bill, sessions.year, users.name AS author
		FROM tags
		LEFT JOIN bills
			ON tags.bill_id=bills.id
		LEFT JOIN sessions
			ON bills.session_id=sessions.id
		LEFT JOIN users
			ON tags.user_id=users.id
		WHERE DATE_SUB(CURDATE(), INTERVAL 3 DAY) <= tags.date_created
		AND users.trusted = "n"
		ORDER BY tags.date_created DESC, bills.id DESC';
$result = mysqli_query($GLOBALS['db'], $sql);
if (mysqli_num_rows($result) > 0)
{
	$page_body .= '
		<h2>Recent Tags</h2>
		<p>The following tags have been applied to bills in the last three days by non-trusted
		users.</p>';
    while ($tag = mysqli_fetch_array($result))
    {
        $tag = array_map('stripslashes', $tag);
        $tag['bill'] = strtolower($tag['bill']);
        $page_body .= '<a href="/bill/'.$tag['year'].'/'.$tag['bill'].'/" title="'
            .$tag['author'].'">'.$tag['tag'].'</a>—[<a href="/process-tags.php?delete='
            .$tag['id'].'">x</a>] ';
    }
}

# Select the new users from the past month.
$sql = 'SELECT name, id, url
		FROM users
		WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date_created
		AND name IS NOT NULL
		ORDER BY date_created DESC';
$result = mysqli_query($GLOBALS['db'], $sql);
if (mysqli_num_rows($result) > 0)
{
    $page_body .= '
		<script>
		$(document).ready(function(){
			$(".user_delete").click(function(){
				return confirm("Are you sure you want to delete this user?");
			});
		});
		</script>
		<style>
			.user {
				display: inline-block;
				background-color: #f4eee5;
				padding: 2px 6px;
				margin: 3px;
				border-radius: 5px;
			}
				a.user_delete {
					font-family: arial;
					color: black;
					font-weight: 800;
					font-size: .75em;
					margin-left: .5em;
					text-decoration: none;
				}
		</style>
		
		<h2>Recent Registrants</h2>
		<p>The following people have signed up in the past 30 days.</p>';
    while ($user = mysqli_fetch_assoc($result))
    {
		$user = array_map('stripslashes', $user);
		$page_body .= '<div class="user">';
        if (!empty($user['url']))
        {
            $page_body .= '<a href="'.$user['url'].'">';
        }
        $page_body .= $user['name'];
        if (!empty($user['url']))
        {
            $page_body .= '</a> ';
		}
		$page_body .= '<a href="?op=delete&amp;user_id=' . $user['id'] . '" class="user_delete">✕</a>';
        $page_body .= '</div>';
    }
}

# Select the number of comments for the past seven days.
$sql = 'SELECT DATE_FORMAT(date_created, "%Y-%m-%d") AS date, COUNT(*) AS number
		FROM comments
		GROUP BY date
		ORDER BY date DESC
		LIMIT 7';
$result = mysqli_query($GLOBALS['db'], $sql);
if (mysqli_num_rows($result) > 0)
{
    $page_body .= '
		<h2>Comments by Day</h2>
		<p>This is the number of comments, by day. Only lists the last seven days for which
{'fraction_non_alphanumeric': 0.1785158277114686, 'fraction_numerical': 0.005708354955889984, 'mean_word_length': 3.3139339675433686, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '78886', 'n_tokens_mistral': 2987, 'n_tokens_neox': 2700, 'n_words': 714}