Closes #44
This commit is contained in:
parent
4d8143eb0d
commit
1f44769030
2 changed files with 86 additions and 7 deletions
|
@ -247,6 +247,10 @@ body {
|
|||
border: none;
|
||||
}
|
||||
|
||||
#content .table-compact {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
#content .table thead th {
|
||||
line-height: 38px;
|
||||
padding: 2px 15px 0;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
if(!isset($_GET['id'])){
|
||||
// Redirect id not set, redirect to overview
|
||||
Router::redirect("admin/listredirects");
|
||||
Router::redirect('admin/listredirects');
|
||||
}
|
||||
|
||||
$id = $_GET['id'];
|
||||
|
@ -12,37 +12,77 @@ $user = User::find($id);
|
|||
|
||||
if(is_null($user)){
|
||||
// User doesn't exist, redirect to overview
|
||||
Router::redirect("admin/listusers");
|
||||
Router::redirect('admin/listusers');
|
||||
}
|
||||
|
||||
if(!$user->isInLimitedDomains()){
|
||||
Router::redirect("admin/listusers/?missing-permission=1");
|
||||
Router::redirect('admin/listusers/?missing-permission=1');
|
||||
}
|
||||
|
||||
// Delete user
|
||||
if(isset($_POST['confirm'])){
|
||||
$confirm = $_POST['confirm'];
|
||||
|
||||
if($confirm === "yes"){
|
||||
if($confirm === 'yes'){
|
||||
// Check if admin is affected
|
||||
if(!in_array($user->getEmail(), Config::get('admins', array()))){
|
||||
|
||||
// Delete redirects of this user
|
||||
if(isset($_POST['delete_redirects']) && $_POST['delete_redirects'] === 'yes'
|
||||
&& isset($_POST['selected_redirects']) && is_array($_POST['selected_redirects'])
|
||||
){
|
||||
$redirectMultiIds = $_POST['selected_redirects'];
|
||||
|
||||
foreach($redirectMultiIds as $redirectMultiId){
|
||||
$redirectIds = explode(',', $redirectMultiId);
|
||||
|
||||
foreach($redirectIds as $redirectId){
|
||||
|
||||
// Note: No Multi* selected, so there is only Alias & Redirect
|
||||
$redirects = AbstractRedirect::findWhere(
|
||||
array(
|
||||
array(AbstractRedirect::attr('id'), $redirectId),
|
||||
array(AbstractRedirect::attr('destination'), 'LIKE', '%'.$user->getEmail().'%')
|
||||
)
|
||||
);
|
||||
|
||||
/** @var AbstractRedirect $redirect */
|
||||
foreach($redirects as $redirect){
|
||||
if($redirect instanceof Alias) {
|
||||
$redirect->delete();
|
||||
}
|
||||
elseif($redirect instanceof Redirect) {
|
||||
$redirect->setDestination(
|
||||
array_diff(
|
||||
$redirect->getDestination(),
|
||||
array($user->getEmail())
|
||||
)
|
||||
);
|
||||
$redirect->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$user->delete();
|
||||
|
||||
// Delete user successful, redirect to overview
|
||||
Router::redirect("admin/listusers/?deleted=1");
|
||||
Router::redirect('admin/listusers/?deleted=1');
|
||||
}
|
||||
else{
|
||||
// Admin tried to delete himself, redirect to overview
|
||||
Router::redirect("admin/listusers/?adm_del=1");
|
||||
Router::redirect('admin/listusers/?adm_del=1');
|
||||
}
|
||||
}
|
||||
else{
|
||||
// Choose to not delete user, redirect to overview
|
||||
Router::redirect("admin/listusers");
|
||||
Router::redirect('admin/listusers');
|
||||
}
|
||||
}
|
||||
|
||||
$redirects = $user->getAnonymizedRedirects();
|
||||
|
||||
?>
|
||||
|
||||
<h1>Delete user "<?php echo $user->getEmail() ?>"?</h1>
|
||||
|
@ -57,6 +97,41 @@ if(isset($_POST['confirm'])){
|
|||
<div class="input-info">The mailbox in the filesystem won't be affected.</div>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label>Redirects to this user:</label>
|
||||
<?php if($redirects->count() > 0): ?>
|
||||
<div class="input-info">Do you also want to delete the following redirects to this user?</div>
|
||||
<table class="table table-compact">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Source</th>
|
||||
<th>Destination</th>
|
||||
<tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($redirects as $redirect): /** @var AbstractRedirect $redirect */ ?>
|
||||
<tr>
|
||||
<td><input type="checkbox" name="selected_redirects[]" value="<?php echo $redirect->getId(); ?>" checked></td>
|
||||
<td><?php echo formatEmailsText($redirect->getSource()); ?></td>
|
||||
<td><?php echo formatEmailsText($redirect->getDestination()); ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="input">
|
||||
<label>
|
||||
<select name="delete_redirects" required>
|
||||
<option value="no">Don't delete the redirects.</option>
|
||||
<option value="yes">Yes, delete the selected redirects!</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="input-info">There are currently no redirects to this user.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<label for="confirm">Do you realy want to delete this user?</label>
|
||||
<div class="input">
|
||||
|
|
Loading…
Add table
Reference in a new issue