2015-02-11 23:52:11 -05:00
|
|
|
<?php
|
2015-02-12 15:23:08 -05:00
|
|
|
session_start();
|
|
|
|
require_once("config.inc.php");
|
2017-05-12 11:12:29 -04:00
|
|
|
require_once($yaptc_lang);
|
|
|
|
|
2015-02-20 05:16:28 -05:00
|
|
|
require_once($yaptc_inc . "functions.inc.php");
|
2015-02-25 16:01:50 -05:00
|
|
|
$yaptc_pagename = lang('USERS');
|
2016-02-04 14:18:34 -05:00
|
|
|
$yaptc_pageicon = '<i class="fa fa-users"></i> ';
|
2015-02-12 15:23:08 -05:00
|
|
|
require_once($yaptc_inc . "header.inc.php");
|
2015-02-20 05:16:28 -05:00
|
|
|
if (getSessionStatus() == false):
|
2015-02-19 10:53:29 -05:00
|
|
|
killSession();
|
2015-02-20 05:16:28 -05:00
|
|
|
else: ?>
|
2015-02-25 16:01:50 -05:00
|
|
|
<!-- ********** BEGIN CONTENT ********** -->
|
|
|
|
|
|
|
|
<?php if($session_user["0"]["usertype"] !== "Administrator"): header("Location: index.php"); ?>
|
|
|
|
<h2 class="content-subhead"><?php echo lang('NOT_AUTHORIZED'); ?></h2>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2017-05-11 16:57:56 -04:00
|
|
|
<!-- Begin page content -->
|
|
|
|
<div class="container">
|
|
|
|
<div class="page-header">
|
|
|
|
<h2><i class="fa fa-user-plus"></i> <?php echo lang('ADD_USER'); ?></h2>
|
|
|
|
</div>
|
|
|
|
<p class="lead"><?php echo lang('ADD_USER_DESC') . $yaptc_min_password; ?></p>
|
|
|
|
|
|
|
|
|
2015-02-18 05:37:38 -05:00
|
|
|
|
2015-02-20 01:57:34 -05:00
|
|
|
<?php
|
2015-02-12 15:23:08 -05:00
|
|
|
require_once($yaptc_lib . "phpass-0.3/PasswordHash.php");
|
2015-02-25 16:01:50 -05:00
|
|
|
if (!empty($_POST['newuser'])):
|
|
|
|
if (empty($_POST['username'])): $errors['username'] = lang('USERNAME_NOTEMPTY'); endif;
|
|
|
|
if (preg_match('/[^a-zA-Z0-9 .-_]/', $_POST['username'])): $errors['username'] = lang('ILLEGAL_CHARACTERS'); endif;
|
|
|
|
if (empty($_POST['password'])): $errors['password'] = lang('PASSWORD_NOTEMPTY'); endif;
|
|
|
|
if (strlen($_POST['password']) < $yaptc_min_password): $errors['password'] = lang('MIN_PASSWORD_LENGTH') . $yaptc_min_password; endif;
|
|
|
|
if (empty($_POST['password_confirm'])): $errors['password_confirm'] = lang('PASSWORD_NOTCONFIRMED'); endif;
|
|
|
|
if ($_POST['password'] != $_POST['password_confirm']): $errors['password_confirm'] = lang('PASSWORD_NOTMATCH'); endif;
|
2015-02-11 23:52:11 -05:00
|
|
|
$email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
|
2015-02-25 16:01:50 -05:00
|
|
|
if (!$email): $errors['email'] = lang('EMAIL_NOTVALID'); endif;
|
2015-02-11 23:52:11 -05:00
|
|
|
$query = "SELECT username, email
|
|
|
|
FROM users
|
|
|
|
WHERE username = :username OR email = :email";
|
2015-02-20 01:57:34 -05:00
|
|
|
$stmt = $yaptc_db->prepare($query);
|
2015-02-11 23:52:11 -05:00
|
|
|
$stmt->execute(array(
|
|
|
|
':username' => $_POST['username'],
|
|
|
|
':email' => $email
|
|
|
|
));
|
|
|
|
$existing = $stmt->fetchObject();
|
2015-02-25 16:01:50 -05:00
|
|
|
if ($existing):
|
|
|
|
if ($existing->username == $_POST['username']): $errors['username'] = lang('USERNAME_USED'); endif;
|
|
|
|
if ($existing->email == $email): $errors['email'] = lang('PASSWORD_USED'); endif;
|
|
|
|
endif;
|
|
|
|
endif;
|
2015-02-11 23:52:11 -05:00
|
|
|
|
2015-02-25 16:01:50 -05:00
|
|
|
if (!empty($_POST['newuser']) && empty($errors)):
|
2015-02-11 23:52:11 -05:00
|
|
|
$hasher = new PasswordHash(8, FALSE);
|
|
|
|
$password = $hasher->HashPassword($_POST['password']);
|
2015-02-25 16:01:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-19 10:53:29 -05:00
|
|
|
$query = "INSERT INTO users (firstname, lastname, username, password, email, created, usertype)
|
|
|
|
VALUES (:firstname, :lastname, :username, :password, :email, NOW(), :usertype)";
|
2015-02-20 01:57:34 -05:00
|
|
|
$stmt = $yaptc_db->prepare($query);
|
2015-02-11 23:52:11 -05:00
|
|
|
$success = $stmt->execute(array(
|
2015-02-19 10:53:29 -05:00
|
|
|
':firstname' => $_POST['firstname'],
|
|
|
|
':lastname' => $_POST['lastname'],
|
2015-02-11 23:52:11 -05:00
|
|
|
':username' => $_POST['username'],
|
|
|
|
':password' => $password,
|
|
|
|
':email' => $_POST['email'],
|
2015-02-12 15:23:08 -05:00
|
|
|
':usertype' => $_POST['usertype'],
|
2015-02-11 23:52:11 -05:00
|
|
|
));
|
2015-02-25 16:01:50 -05:00
|
|
|
if ($success): $message = "Account created."; else: echo "Account could not be created. Please try again later."; endif;
|
|
|
|
endif;
|
2015-02-11 23:52:11 -05:00
|
|
|
?>
|
|
|
|
|
|
|
|
<?php if (isset($message)): ?>
|
|
|
|
<p class="success"><?php echo $message; ?></p>
|
|
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($errors['registration'])): ?>
|
|
|
|
<p class="error"><?php echo $errors['registration']; ?></p>
|
|
|
|
<?php endif; ?>
|
|
|
|
|
2017-05-11 16:57:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
|
2016-02-04 14:18:34 -05:00
|
|
|
<fieldset id="registration">
|
2017-05-11 16:57:56 -04:00
|
|
|
<div class="form-group">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-sm-6">
|
|
|
|
<input type="text" class="form-control" id="firstname" name="firstname" placeholder="First Name" required />
|
2015-02-26 12:44:21 -05:00
|
|
|
<?php echo isset($errors['firstname']) ? $errors['firstname'] : ''; ?>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
<div class="col-sm-6">
|
|
|
|
<input type="text" class="form-control" id="lastname" name="lastname" placeholder="Last Name" required />
|
2015-02-26 12:44:21 -05:00
|
|
|
<?php echo isset($errors['lastname']) ? $errors['lastname'] : ''; ?>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-sm-6">
|
|
|
|
<input type="text" class="form-control" id="username" name="username" placeholder="Username" required />
|
2015-02-26 12:44:21 -05:00
|
|
|
<?php echo isset($errors['username']) ? $errors['username'] : ''; ?>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
<div class="col-sm-6">
|
|
|
|
<input type="text" class="form-control" id="email" name="email" placeholder="Email" />
|
2015-02-26 12:44:21 -05:00
|
|
|
<?php echo isset($errors['email']) ? $errors['email'] : ''; ?>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-sm-6">
|
|
|
|
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required />
|
2015-02-26 12:44:21 -05:00
|
|
|
<?php echo isset($errors['password']) ? $errors['password'] : ''; ?>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
<div class="col-sm-6">
|
|
|
|
<input type="password" class="form-control" id="password_confirm" name="password_confirm" placeholder="Confirm Password" required />
|
2015-02-26 12:44:21 -05:00
|
|
|
<?php echo isset($errors['password_confirm']) ? $errors['password_confirm'] : ''; ?>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-sm-6">
|
|
|
|
<select id="usertype" class="form-control" name="usertype" required>
|
2015-02-26 12:44:21 -05:00
|
|
|
<option value="00000000002" selected>User</option>
|
|
|
|
<option value="00000000001">Administrator</option>
|
|
|
|
</select>
|
|
|
|
<?php echo isset($errors['usertype']) ? $errors['usertype'] : ''; ?>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
<div class="col-sm-6">
|
2017-05-11 23:07:56 -04:00
|
|
|
<button type="submit" class="form-control btn btn-block btn-primary" value="Submit" name="newuser"><i class="fa fa-user-plus"></i> <?php echo lang('ADD_USER'); ?></button>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2015-02-26 12:44:21 -05:00
|
|
|
</div>
|
|
|
|
</fieldset>
|
|
|
|
</form>
|
2017-05-11 16:57:56 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-02-19 22:41:20 -05:00
|
|
|
|
2015-02-12 15:23:08 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
2015-02-19 22:41:20 -05:00
|
|
|
|
|
|
|
// delete user only if submitted by button
|
|
|
|
if (!empty($_POST['deluser']))
|
|
|
|
{
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'DELETE' || ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['_METHOD'] == 'DELETE')) {
|
|
|
|
$deleteid = (int) $_POST['deleteid'];
|
2015-02-20 01:57:34 -05:00
|
|
|
$deletequery = $yaptc_db->prepare("DELETE FROM users WHERE users.id=$deleteid");
|
2015-02-19 22:41:20 -05:00
|
|
|
$deletequery->execute();
|
|
|
|
echo "user deleted!";
|
2015-02-26 12:44:21 -05:00
|
|
|
header('Location: ' . $_SERVER['PHP_SELF']);
|
2015-02-19 22:41:20 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 12:44:21 -05:00
|
|
|
// Set up pagination
|
|
|
|
$page_num = 1;
|
|
|
|
if(!empty($_GET['pnum'])):
|
|
|
|
$page_num = filter_input(INPUT_GET, 'pnum', FILTER_VALIDATE_INT);
|
|
|
|
if(false === $page_num):
|
|
|
|
$page_num = 1;
|
|
|
|
endif;
|
|
|
|
endif;
|
2017-05-11 13:22:44 -04:00
|
|
|
$offset = ($page_num - 1) * $yaptc_rowsperpage;
|
|
|
|
$row_count = count(getUserInfo($yaptc_db, "%"));
|
2015-02-26 12:44:21 -05:00
|
|
|
$page_count = 0;
|
2017-05-11 13:22:44 -04:00
|
|
|
if (0 === $row_count): else: $page_count = (int)ceil($row_count / $yaptc_rowsperpage); if($page_num > $page_count): $page_num = 1; endif; endif;
|
2015-02-20 01:57:34 -05:00
|
|
|
?>
|
|
|
|
|
2017-05-11 16:57:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="container">
|
|
|
|
<div class="page-header">
|
|
|
|
<h2><i class="fa fa-list"></i> <?php echo lang('USERS'); ?></h2>
|
|
|
|
</div>
|
|
|
|
<p class="lead"><?php echo lang('USER_LIST_DESC'); ?></p>
|
|
|
|
|
|
|
|
|
2017-05-12 00:38:26 -04:00
|
|
|
<table class="table table-striped">
|
2015-02-25 16:01:50 -05:00
|
|
|
<thead>
|
2017-05-12 00:38:26 -04:00
|
|
|
<tr><th colspan="6"><?php echo '<ul class="pagination pagination-sm">'; for ($i = 1; $i <= $page_count; $i++): echo '<li class="'; if ($i === $page_num): echo 'active'; else: echo ' '; endif; echo '"><a href="' . $_SERVER['PHP_SELF'] . '?pnum=' . $i . '">' . $i . '</a></li>'; endfor; echo '</ul>'; ?></th></tr>
|
2015-02-25 16:01:50 -05:00
|
|
|
<tr><th><?php echo lang('NAME'); ?></th><th><?php echo lang('USERNAME'); ?></th><th><?php echo lang('EMAIL'); ?></th><th><?php echo lang('CREATED'); ?></th><th><?php echo lang('USERTYPE'); ?></th><th><?php echo lang('ACTIONS'); ?></th></tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2017-05-11 13:22:44 -04:00
|
|
|
<?php foreach (getUserInfo($yaptc_db, "%", $yaptc_rowsperpage, $offset) as $row): ?>
|
2015-02-25 16:01:50 -05:00
|
|
|
<tr>
|
2016-02-04 14:18:34 -05:00
|
|
|
<td><?php echo $row['lastname'] . ", " . $row['firstname']; ?></td><td><?php echo $row['username']; ?></td><td><?php echo $row['email']; ?></td><td><?php echo $row['created']; ?></td><td><?php echo $row['usertype']; ?></td><td><form method="post" onsubmit="return confirm('<?php echo lang('DELETE_WARNING'); ?>')"><input type="hidden" id="_METHOD" name="_METHOD" value="DELETE" /><input type="hidden" id="deleteid" name="deleteid" value="<?php echo $row['userid']; ?>" /><button class="button-error pure-button" id="deluser" name="deluser" value="deluser" type="submit" <?php if ($row['username'] == "admin"): echo "disabled"; endif; ?>><i class="fa fa-trash"></i> </button></form></td>
|
2015-02-25 16:01:50 -05:00
|
|
|
</tr>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2017-05-12 00:38:26 -04:00
|
|
|
</div>
|
2015-02-25 16:01:50 -05:00
|
|
|
|
|
|
|
<!-- ********** END CONTENT ********** -->
|
2015-02-20 05:16:28 -05:00
|
|
|
<?php endif; require_once($yaptc_inc . "footer.inc.php"); ?>
|