diff --git a/include/class.organization.php b/include/class.organization.php index 78332b1e60067de88efac03bd3306e7da0a69dcf..afa46b017799429019cb03815751070ddb430b6a 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -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( diff --git a/include/class.user.php b/include/class.user.php index 21e7d99c0e0955346de6fa043f38b4785ae25a4d..f736501fc807c82b75fecf79e4389add1eac9ef2 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -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(); diff --git a/include/staff/templates/users.tmpl.php b/include/staff/templates/users.tmpl.php index d5beaf2c77fdcd50d8dde8bd189a84e7acf4e0e9..42ad7e6f1d1317df697f492cb7a9bb5a0949cfee 100644 --- a/include/staff/templates/users.tmpl.php +++ b/include/staff/templates/users.tmpl.php @@ -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"> </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> <a class="userPreview" href="users.php?id=<?php echo $row['id']; ?>"><?php echo $name; ?></a> @@ -107,16 +113,61 @@ if ($num) { ?> } //end of while. endif; ?> </tbody> + <tfoot> + <tr> + <td colspan="5"> + <?php + if ($res && $num) { + ?> + Select: + <a id="selectAll" href="#ckb">All</a> + <a id="selectNone" href="#ckb">None</a> + <a id="selectToggle" href="#ckb">Toggle</a> + <?php + } else { + echo 'No users found'; + } + ?> + </td> + </tr> + </tfoot> </table> <?php -if($res && $num): //Show options.. +if ($res && $num) { //Show options.. echo '<div> Page:'.$pageNav->getPageLinks().' </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) { diff --git a/scp/orgs.php b/scp/orgs.php index 83a13fb0ba712365295341d5510ad37d2c51822c..373864afd09b30f321af48d20890ea197d32538b 100644 --- a/scp/orgs.php +++ b/scp/orgs.php @@ -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'; }