Skip to content
Snippets Groups Projects
Commit 039ffb64 authored by Peter Rotich's avatar Peter Rotich
Browse files

Add ability to mass-remove users from org

parent 6d01a843
No related branches found
No related tags found
No related merge requests found
......@@ -207,6 +207,20 @@ class Organization extends OrganizationModel {
return $vars;
}
function removeUser($user) {
if (!$user instanceof User)
return false;
if (!$user->setOrganization(null))
return false;
// TODO: house cleaning - remove user from org contact..etc
return true;
}
function to_json() {
$info = array(
......
......@@ -110,10 +110,14 @@ class UserModel extends VerySimpleModel {
}
function setOrganization($org, $save=true) {
if (!$org instanceof Organization)
if (is_null($org))
$this->set('org_id', 0);
elseif ($org instanceof Organization)
$this->set('org', $org);
else // noop
return false;
$this->set('org', $org);
if ($save)
$this->save();
......
......@@ -64,13 +64,15 @@ else
<br/>
<?php
if ($num) { ?>
<form action="users.php" method="POST" name="staff" >
<form action="orgs.php?id=<?php echo $org->getId(); ?>" method="POST" name="users" >
<?php csrf_token(); ?>
<input type="hidden" name="do" value="mass_process" >
<input type="hidden" id="id" name="id" value="<?php echo $org->getId(); ?>" >
<input type="hidden" id="action" name="a" value="" >
<table class="list" border="0" cellspacing="1" cellpadding="0" width="940">
<thead>
<tr>
<th width="7px">&nbsp;</th>
<th width="350"> Name</th>
<th width="300"> Email</th>
<th width="100"> Status</th>
......@@ -90,6 +92,10 @@ if ($num) { ?>
$sel=true;
?>
<tr id="<?php echo $row['id']; ?>">
<td width=7px>
<input type="checkbox" class="ckb" name="ids[]"
value="<?php echo $row['id']; ?>" <?php echo $sel?'checked="checked"':''; ?> >
</td>
<td>&nbsp;
<a class="userPreview" href="users.php?id=<?php echo $row['id']; ?>"><?php echo $name; ?></a>
&nbsp;
......@@ -107,16 +113,61 @@ if ($num) { ?>
} //end of while.
endif; ?>
</tbody>
<tfoot>
<tr>
<td colspan="5">
<?php
if ($res && $num) {
?>
Select:&nbsp;
<a id="selectAll" href="#ckb">All</a>&nbsp;&nbsp;
<a id="selectNone" href="#ckb">None</a>&nbsp;&nbsp;
<a id="selectToggle" href="#ckb">Toggle</a>&nbsp;&nbsp;
<?php
} else {
echo 'No users found';
}
?>
</td>
</tr>
</tfoot>
</table>
<?php
if($res && $num): //Show options..
if ($res && $num) { //Show options..
echo '<div>&nbsp;Page:'.$pageNav->getPageLinks().'&nbsp;</div>';
endif;
?>
<p class="centered" id="actions">
<input class="button" type="submit" name="remove-users" value="Remove" >
</p>
<?php
}
?>
</form>
<?php
} ?>
<div style="display:none;" class="dialog" id="confirm-action">
<h3>Please Confirm</h3>
<a class="close" href=""><i class="icon-remove-circle"></i></a>
<hr/>
<p class="confirm-action" style="display:none;" id="remove-users-confirm">
Are you sure want to <b>REMOVE</b> selected user from <strong><?php
echo $org->getName(); ?></strong> organization?
</p>
<div>Please confirm to continue.</div>
<hr style="margin-top:1em"/>
<p class="full-width">
<span class="buttons" style="float:left">
<input type="button" value="No, Cancel" class="close">
</span>
<span class="buttons" style="float:right">
<input type="button" value="Yes, Do it!" class="confirm">
</span>
</p>
<div class="clear"></div>
</div>
<script type="text/javascript">
$(function() {
$(document).on('click', 'a.add-user', function(e) {
......
......@@ -33,6 +33,27 @@ if ($_POST) {
else
$errors['err'] = $status;
break;
case 'remove-users':
if (!$org)
$errors['err'] = ' Trying to remove users from unknown
organization';
elseif (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) {
$errors['err'] = 'You must select at least one user to remove';
} else {
$i = 0;
foreach ($_POST['ids'] as $k=>$v) {
if (($u=User::lookup($v)) && $org->removeUser($u))
$i++;
}
$num = count($_POST['ids']);
if ($i && $i == $num)
$msg = 'Selected users removed successfully';
elseif ($i > 0)
$warn = "$i of $num selected users removed";
elseif (!$errors['err'])
$errors['err'] = 'Unable to remove selected users';
}
break;
default:
$errors['err'] = 'Unknown action';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment