Skip to content

Commit

Permalink
Add user/alert search page.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Oct 11, 2018
1 parent b3dcea9 commit c858a71
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
5 changes: 5 additions & 0 deletions www/docs/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@

?>
<h4>Recently registered users</h4>
<form action="./users.php" method="get">
<label for="user_search">Search:</label>
<input type="text" name="s" id="user_search">
<input type="submit" value="Go">
</form>
<?php

$q = $db->query("SELECT firstname,
Expand Down
110 changes: 110 additions & 0 deletions www/docs/admin/users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

include_once '../../includes/easyparliament/init.php';

$this_page = "admin_users";

$db = new ParlDB;

$user_data = array(
'header' => array(
'Name',
'Email',
'Confirmed?',
'Registration time'
),
'rows' => array(),
);

$alert_data = array(
'header' => array(
'Email',
'Created',
'State',
'Criteria',
),
'rows' => array(),
);

if ($search = get_http_var('s')) {
$q = $db->query("
SELECT firstname, lastname, email, user_id, confirmed, registrationtime
FROM users
WHERE email LIKE :search OR firstname LIKE :search OR lastname LIKE :search",
array(':search' => "%$search%"));

$USERURL = new \MySociety\TheyWorkForYou\Url('userview');
for ($row=0; $row<$q->rows(); $row++) {
$USERURL->insert(array('u' => $q->field($row, 'user_id')));
if ($q->field($row, 'confirmed') == 1) {
$confirmed = 'Yes';
$name = '<a href="' . $USERURL->generate() . '">' . _htmlspecialchars($q->field($row, 'firstname'))
. ' ' . _htmlspecialchars($q->field($row, 'lastname')) . '</a>';
} else {
$confirmed = 'No';
$name = _htmlspecialchars($q->field($row, 'firstname') . ' ' . $q->field($row, 'lastname'));
}

$user_data['rows'][] = array(
$name,
$q->field($row, 'email'),
$confirmed,
$q->field($row, 'registrationtime'),
);
}

$q = $db->query("
SELECT email, criteria, created, confirmed, deleted
FROM alerts WHERE email = :search",
array(':search' => $search));

for ($row=0; $row<$q->rows(); $row++) {
$confirmed = $q->field($row, 'confirmed');
$deleted = $q->field($row, 'deleted');
if ($deleted == 2) {
$state = 'Suspended';
} elseif ($deleted == 1) {
$state = 'Deleted';
} elseif ($confirmed) {
$state = 'Confirmed';
} else {
$state = 'Unconfirmed';
}

$alert_data['rows'][] = array(
$q->field($row, 'email'),
$q->field($row, 'created'),
$state,
$q->field($row, 'criteria'),
);
}
}

$PAGE->page_start();
$PAGE->stripe_start();

?>
<form action="./users.php" method="get">
<label for="user_search">Search:</label>
<input type="text" name="s" id="user_search" value="<?=_htmlspecialchars($search) ?>">
<input type="submit" value="Go">
</form>
<?php

$PAGE->block_start(array('title'=>'Users'));
$PAGE->display_table($user_data);
$PAGE->block_end();

$PAGE->block_start(array('title'=>'Alerts'));
$PAGE->display_table($alert_data);
$PAGE->block_end();

$menu = $PAGE->admin_menu();
$PAGE->stripe_end(array(
array(
'type' => 'html',
'content' => $menu,
)
));

$PAGE->page_end();

0 comments on commit c858a71

Please sign in to comment.