<?php

$uid = TaskerMAN\Core\IO::GET('id');
$user = new TaskerMAN\Application\User($uid);
// User does not exist, throw 404
if (!$user->exists) {
    throw new TaskMAN\Core\FatalException('404 - Page Not Found', new \Exception('Requested user (' . $uid . ') was not found'));
}
TaskerMAN\WebInterface\WebInterface::setTitle($user->name);
$stats = TaskerMAN\Application\DashboardStats::getStats($user->id);
if (isset($_POST['delete'])) {
    try {
        TaskerMAN\Application\UserManagement::delete($uid);
        if ($uid == TaskerMAN\WebInterface\WebInterface::$user->getID()) {
            // User deleted themselves, log them out
            TaskerMAN\WebInterface\Session::destroy();
            header('Location: index.php?p=login');
            exit;
        }
        header('Location: index.php?p=list_users');
        exit;
    } catch (TaskerMAN\Application\UserManagementException $e) {
        $alert = '<div class="alert alert-danger" role="alert">' . $e->getMessage() . '</div>';
    }
} elseif (isset($_POST['submit'])) {
    // Form submitted
    if (isset($_POST['admin'])) {
        $is_admin = true;
    } else {
        $is_admin = false;
    }
<?php

// Return dashboard stats
echo TaskerMAN\Application\API::response(TaskerMAN\Application\DashboardStats::getStats(TaskerMAN\Application\API::$uid));
if ($stats['overdue'] > 0) {
    echo ' style="color: #F7464A"';
} else {
    echo ' style="color: #66CD00"';
}
echo '>' . $stats['overdue'] . '</span>';
?>
		</div>

		<div class="col-xs-6 col-sm-3 placeholder">
			<canvas id="chart-task-distribution" width="200" height="200"></canvas>

			<?php 
// Generate JavaScript
$js_task_distribution = array();
foreach (TaskerMAN\Application\DashboardStats::getTaskDistribution() as $item) {
    $color = TaskerMAN\WebInterface\PieChart::generatePastelColours($item['assignee_uid']);
    $js_task_distribution[] = '
					{
						value: ' . $item['count'] . ',
						color: "' . $color['color'] . '",
						highlight: "' . $color['highlight'] . '",
						label: "' . $item['name'] . '"
					}';
}
?>

			<script type="text/javascript">
				var ctx_task_distribution = document.getElementById("chart-task-distribution").getContext("2d");
				var data = [
					<?php