Skip to content
Snippets Groups Projects
Commit 0848e102 authored by Jared Hancock's avatar Jared Hancock
Browse files

users: Add basic mass actions for user directory

parent f1e31ba6
No related branches found
No related tags found
No related merge requests found
...@@ -668,6 +668,9 @@ class DynamicFormEntry extends VerySimpleModel { ...@@ -668,6 +668,9 @@ class DynamicFormEntry extends VerySimpleModel {
'null' => true, 'null' => true,
'constraint' => array('form_id' => 'DynamicForm.id'), 'constraint' => array('form_id' => 'DynamicForm.id'),
), ),
'answers' => array(
'reverse' => 'DynamicFormEntryAnswer.entry'
),
), ),
); );
......
...@@ -82,6 +82,13 @@ class UserModel extends VerySimpleModel { ...@@ -82,6 +82,13 @@ class UserModel extends VerySimpleModel {
'null' => true, 'null' => true,
'constraint' => array('default_email_id' => 'UserEmailModel.id') 'constraint' => array('default_email_id' => 'UserEmailModel.id')
), ),
'cdata_entry' => array(
'constraint' => array(
'id' => 'DynamicFormEntry.object_id',
"'U'" => 'DynamicFormEntry.object_type',
),
null => true,
),
) )
); );
...@@ -726,9 +733,9 @@ class PersonsName { ...@@ -726,9 +733,9 @@ class PersonsName {
$r = explode(' ', $name); $r = explode(' ', $name);
$size = count($r); $size = count($r);
//check if name is bad format (ex: J.Everybody), and fix them //check if name is bad format (ex: J.Everybody), and fix them
if($size==1 && mb_strpos($r[0], '.') !== false) if($size==1 && mb_strpos($r[0], '.') !== false)
{ {
$r = explode('.', $name); $r = explode('.', $name);
$size = count($r); $size = count($r);
...@@ -836,6 +843,11 @@ class UserAccountModel extends VerySimpleModel { ...@@ -836,6 +843,11 @@ class UserAccountModel extends VerySimpleModel {
$this->save(); $this->save();
} }
function unlock() {
$this->clearStatus(UserAccountStatus::LOCKED);
$this->save();
}
function isLocked() { function isLocked() {
return $this->_status->isLocked(); return $this->_status->isLocked();
} }
......
...@@ -28,7 +28,7 @@ $org = $user->getOrganization(); ...@@ -28,7 +28,7 @@ $org = $user->getOrganization();
<?php <?php
} else { ?> } else { ?>
<a id="user-register" class="action-button pull-right user-action" <a id="user-register" class="action-button pull-right user-action"
href="#users/<?php echo $user->getId(); ?>/register"><i class="icon-edit"></i> href="#users/<?php echo $user->getId(); ?>/register"><i class="icon-star"></i>
<?php echo __('Register'); ?></a> <?php echo __('Register'); ?></a>
<?php <?php
} ?> } ?>
......
...@@ -90,12 +90,44 @@ $_SESSION['users_qs_'.$qhash] = $query; ...@@ -90,12 +90,44 @@ $_SESSION['users_qs_'.$qhash] = $query;
</table> </table>
</form> </form>
</div> </div>
<div class="pull-right flush-right" style="padding-right:5px;">
<b><a href="#users/add" class="Icon newstaff popup-dialog"><?php echo __('Add User'); ?></a></b> <div class="pull-right">
| <a class="action-button popup-dialog"
<b><a href="#users/import" class="popup-dialog"><i class="icon-cloud-upload icon-large"></i> href="#users/add">
<?php echo __('Import'); ?></a></b> <i class="icon-plus-sign"></i>
<?php echo __('Add User'); ?>
</a>
<a class="action-button popup-dialog"
href="#users/import">
<i class="icon-upload"></i>
<?php echo __('Import'); ?>
</a>
<span class="action-button" data-dropdown="#action-dropdown-more"
style="/*DELME*/ vertical-align:top; margin-bottom:0">
<i class="icon-caret-down pull-right"></i>
<span ><i class="icon-cog"></i> <?php echo __('More');?></span>
</span>
<div id="action-dropdown-more" class="action-dropdown anchor-right">
<ul>
<li><a class="users-action" href="#delete">
<i class="icon-trash icon-fixed-width"></i>
<?php echo __('Delete'); ?></a></li>
<li><a class="users-action" href="#reset">
<i class="icon-envelope icon-fixed-width"></i>
<?php echo __('Send Password Reset Email'); ?></a></li>
<li><a class="users-action" href="#register">
<i class="icon-star icon-fixed-width"></i>
<?php echo __('Register'); ?></a></li>
<li><a class="users-action" href="#lock">
<i class="icon-lock icon-fixed-width"></i>
<?php echo __('Lock'); ?></a></li>
<li><a class="users-action" href="#unlock">
<i class="icon-unlock icon-fixed-width"></i>
<?php echo __('Unlock'); ?></a></li>
</ul>
</div>
</div> </div>
<div class="clear"></div> <div class="clear"></div>
<?php <?php
$showing = $search ? __('Search Results').': ' : ''; $showing = $search ? __('Search Results').': ' : '';
...@@ -105,14 +137,16 @@ if($res && ($num=db_num_rows($res))) ...@@ -105,14 +137,16 @@ if($res && ($num=db_num_rows($res)))
else else
$showing .= __('No users found!'); $showing .= __('No users found!');
?> ?>
<form action="users.php" method="POST" name="staff" > <form id="users-list" action="users.php" method="POST" name="staff" >
<?php csrf_token(); ?> <?php csrf_token(); ?>
<input type="hidden" name="do" value="mass_process" > <input type="hidden" name="do" value="mass_process" >
<input type="hidden" id="action" name="a" value="" > <input type="hidden" id="action" name="a" value="" >
<input type="hidden" id="selected-count" name="count" value="" >
<table class="list" border="0" cellspacing="1" cellpadding="0" width="940"> <table class="list" border="0" cellspacing="1" cellpadding="0" width="940">
<caption><?php echo $showing; ?></caption> <caption><?php echo $showing; ?></caption>
<thead> <thead>
<tr> <tr>
<th nowrap width="12"> </th>
<th width="350"><a <?php echo $name_sort; ?> href="users.php?<?php <th width="350"><a <?php echo $name_sort; ?> href="users.php?<?php
echo $qstr; ?>&sort=name"><?php echo __('Name'); ?></a></th> echo $qstr; ?>&sort=name"><?php echo __('Name'); ?></a></th>
<th width="250"><a <?php echo $status_sort; ?> href="users.php?<?php <th width="250"><a <?php echo $status_sort; ?> href="users.php?<?php
...@@ -145,6 +179,9 @@ else ...@@ -145,6 +179,9 @@ else
$sel=true; $sel=true;
?> ?>
<tr id="<?php echo $row['id']; ?>"> <tr id="<?php echo $row['id']; ?>">
<td nowrap>
<input type="checkbox" value="<?php echo $row['id']; ?>" class="mass nowarn"/>
</td>
<td>&nbsp; <td>&nbsp;
<a class="userPreview" href="users.php?id=<?php echo $row['id']; ?>"><?php <a class="userPreview" href="users.php?id=<?php echo $row['id']; ?>"><?php
echo Format::htmlchars($name); ?></a> echo Format::htmlchars($name); ?></a>
...@@ -202,7 +239,26 @@ $(function() { ...@@ -202,7 +239,26 @@ $(function() {
}); });
return false; return false;
}); });
$(document).on('click', 'a.users-action', function(e) {
e.preventDefault();
var ids = [],
$form = $('form#users-list');
$(':checkbox.mass:checked', $form).each(function() {
ids.push($(this).val());
});
if (ids.length && confirm(__('You sure?'))) {
$form.find('#action').val($(this).attr('href').substr(1));
$.each(ids, function() { $form.append($('<input type="hidden" name="ids[]">').val(this)); });
$form.find('#selected-count').val(ids.length);
$form.submit();
}
else if (!ids.length) {
$.sysAlert(__('Oops'),
__('You need to select at least one item'));
}
return false;
});
}); });
</script> </script>
...@@ -70,7 +70,61 @@ if ($_POST) { ...@@ -70,7 +70,61 @@ if ($_POST) {
$errors['err'] = sprintf(__('You must select at least %s.'), $errors['err'] = sprintf(__('You must select at least %s.'),
__('one end user')); __('one end user'));
} else { } else {
$errors['err'] = "Coming soon!"; $users = User::objects()->filter(
array('id__in' => $_POST['ids'])
);
$count = 0;
switch (strtolower($_POST['a'])) {
case 'lock':
foreach ($users as $U)
if (($acct = $U->getAccount()) && $acct->lock())
$count++;
break;
case 'unlock':
foreach ($users as $U)
if (($acct = $U->getAccount()) && $acct->unlock())
$count++;
break;
case 'delete':
foreach ($users as $U)
if ($U->delete())
$count++;
break;
case 'reset':
foreach ($users as $U)
if (($acct = $U->getAccount()) && $acct->sendResetEmail())
$count++;
break;
case 'register':
foreach ($users as $U) {
if (($acct = $U->getAccount()) && $acct->setConfirmationEmail())
$count++;
elseif ($acct = UserAccount::register($U,
array('sendemail' => true), $errors
)) {
$count++;
}
}
break;
default:
$errors['err']=__('Unknown action - get technical help.');
}
if (!$errors['err'] && !$count) {
$errors['err'] = __('Unable to manage any of the selected end users');
}
elseif ($_POST['count'] && $count != $_POST['count']) {
$warn = __('Not all selected items were updated');
}
elseif ($count) {
$msg = __('Successfully managed selected end users');
}
} }
break; break;
case 'import-users': case 'import-users':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment