mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 17:28:55 +00:00
131 lines
3.7 KiB
PHP
131 lines
3.7 KiB
PHP
<?php
|
|
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'smarty.php';
|
|
|
|
|
|
use nntmux\Users;
|
|
|
|
$page = new AdminPage();
|
|
$users = new Users();
|
|
|
|
$user = [
|
|
'id' => '',
|
|
'username' => '',
|
|
'email' => '',
|
|
'password' => ''
|
|
];
|
|
|
|
// set the current action
|
|
$action = $_REQUEST['action'] ?? 'view';
|
|
|
|
//get the user roles
|
|
$userRoles = $users->getRoles();
|
|
$roles = [];
|
|
$defaultRole = Users::ROLE_USER;
|
|
$defaultInvites = Users::DEFAULT_INVITES;
|
|
foreach ($userRoles as $r) {
|
|
$roles[$r['id']] = $r['name'];
|
|
if ($r['isdefault'] === 1) {
|
|
$defaultrole = $r['id'];
|
|
$defaultinvites = $r['defaultinvites'];
|
|
}
|
|
}
|
|
|
|
switch ($action) {
|
|
case 'add':
|
|
$user += [
|
|
'role' => $defaultRole,
|
|
'notes' => '',
|
|
'invites' => $defaultInvites,
|
|
'movieview' => 1,
|
|
'xxxview' => 1,
|
|
'musicview' => 1,
|
|
'consoleview' => 1,
|
|
'gameview' => 1,
|
|
'bookview' => 1
|
|
];
|
|
$page->smarty->assign('user', $user);
|
|
break;
|
|
case 'submit':
|
|
if (empty($_POST['id'])) {
|
|
$invites = $defaultInvites;
|
|
foreach ($userRoles as $role) {
|
|
if ($role['id'] === $_POST['role']) {
|
|
$invites = $role['defaultinvites'];
|
|
}
|
|
}
|
|
$ret = $users->signup($_POST['username'], $_POST['password'], $_POST['email'], '', $_POST['role'], $_POST['notes'], $invites, '', true);
|
|
} else {
|
|
$ret = $users->update($_POST['id'], $_POST['username'], $_POST['email'], $_POST['grabs'], $_POST['role'], $_POST['notes'], $_POST['invites'], (isset($_POST['movieview']) ? 1 : 0), (isset($_POST['musicview']) ? 1 : 0), (isset($_POST['gameview']) ? 1 : 0), (isset($_POST['xxxview']) ? 1 : 0), (isset($_POST['consoleview']) ? 1 : 0), (isset($_POST['bookview']) ? 1 : 0));
|
|
if ($_POST['password'] !== '') {
|
|
$users->updatePassword($_POST['id'], $_POST['password']);
|
|
}
|
|
if ($_POST['rolechangedate'] !== '') {
|
|
$users->updateUserRoleChangeDate($_POST['id'], $_POST['rolechangedate']);
|
|
}
|
|
if ($_POST['role'] !== '') {
|
|
$email = $_POST['email'] ?? $_GET['email'];
|
|
\nntmux\utility\Utility::sendEmail($email, 'Account changed', 'Your account role has been changed to ' . $_POST['role'], \App\Models\Settings::value('site.main.email'));
|
|
}
|
|
}
|
|
|
|
if ($ret >= 0) {
|
|
header('Location:' . WWW_TOP . '/user-list.php');
|
|
} else {
|
|
switch ($ret) {
|
|
case Users::ERR_SIGNUP_BADUNAME:
|
|
$page->smarty->assign('error', 'Bad username. Try a better one.');
|
|
break;
|
|
case Users::ERR_SIGNUP_BADPASS:
|
|
$page->smarty->assign('error', 'Bad password. Try a longer one.');
|
|
break;
|
|
case Users::ERR_SIGNUP_BADEMAIL:
|
|
$page->smarty->assign('error', 'Bad email.');
|
|
break;
|
|
case Users::ERR_SIGNUP_UNAMEINUSE:
|
|
$page->smarty->assign('error', 'Username in use.');
|
|
break;
|
|
case Users::ERR_SIGNUP_EMAILINUSE:
|
|
$page->smarty->assign('error', 'Email in use.');
|
|
break;
|
|
default:
|
|
$page->smarty->assign('error', 'Unknown save error.');
|
|
break;
|
|
}
|
|
$user = [
|
|
'id' => $_POST['id'],
|
|
'username' => $_POST['username'],
|
|
'email' => $_POST['email'],
|
|
'notes' => $_POST['notes'],
|
|
'grabs' => $_POST['grabs'] ?? 0,
|
|
'role' => $_POST['role'],
|
|
'invites' => $_POST['invites'] ?? 0,
|
|
'movieview' => $_POST['movieview'],
|
|
'bookview' => $_POST['bookview']
|
|
];
|
|
$page->smarty->assign('user', $user);
|
|
}
|
|
break;
|
|
case 'view':
|
|
default:
|
|
|
|
if (isset($_GET['id'])) {
|
|
$page->title = 'User Edit';
|
|
$id = $_GET['id'];
|
|
$user = $users->getById($id);
|
|
|
|
$page->smarty->assign('user', $user);
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
$page->smarty->assign('yesno_ids', array(1, 0));
|
|
$page->smarty->assign('yesno_names', array('Yes', 'No'));
|
|
|
|
$page->smarty->assign('role_ids', array_keys($roles));
|
|
$page->smarty->assign('role_names', $roles);
|
|
|
|
$page->content = $page->smarty->fetch('user-edit.tpl');
|
|
$page->render();
|
|
|