diff --git a/include/ajax.orgs.php b/include/ajax.orgs.php index 54ea1dc7fcb6ff8f83379da816c455297a731d2a..ea7dc6f1402d4d1b83ea6c5798b7ba065844d6e5 100644 --- a/include/ajax.orgs.php +++ b/include/ajax.orgs.php @@ -211,11 +211,11 @@ class OrgsAjaxAPI extends AjaxController { $info['title'] = __('Add New Organization'); $info['search'] = false; - return self::_lookupform($form, $info); + return $this->_lookupform($form, $info); } function lookup() { - return self::_lookupform(); + return $this->_lookupform(); } function selectOrg($id) { @@ -241,11 +241,15 @@ class OrgsAjaxAPI extends AjaxController { return $ajax->createNote('O'.$id); } - static function _lookupform($form=null, $info=array()) { + function _lookupform($form=null, $info=array()) { if (!$info or !$info['title']) $info += array('title' => __('Organization Lookup')); + if ($_POST && ($org = Organization::lookup($_POST['orgid']))) { + Http::response(201, $org->to_json()); + } + ob_start(); include(STAFFINC_DIR . 'templates/org-lookup.tmpl.php'); $resp = ob_get_contents(); diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 2fdb0088afed9bd537b1305aea7ea2a7918a8cb3..e84b4b6a6d816bbe7d0683a92a4db449053ace36 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -668,6 +668,9 @@ class DynamicFormEntry extends VerySimpleModel { 'null' => true, 'constraint' => array('form_id' => 'DynamicForm.id'), ), + 'answers' => array( + 'reverse' => 'DynamicFormEntryAnswer.entry' + ), ), ); diff --git a/include/class.user.php b/include/class.user.php index 87edb06ddf76f30c2dc4e11492e133cf80318324..886c18db9759700a816045236fc67d44366cfb2c 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -82,6 +82,13 @@ class UserModel extends VerySimpleModel { 'null' => true, '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 { $r = explode(' ', $name); $size = count($r); - + //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); $size = count($r); @@ -833,7 +840,12 @@ class UserAccountModel extends VerySimpleModel { function lock() { $this->setStatus(UserAccountStatus::LOCKED); - $this->save(); + return $this->save(); + } + + function unlock() { + $this->clearStatus(UserAccountStatus::LOCKED); + return $this->save(); } function isLocked() { diff --git a/include/staff/orgs.inc.php b/include/staff/orgs.inc.php index 7edaa7bc590aa57dcbfb0d7d2e8be4a13b1615fe..2f8dab1024c5e6c3342ef51fe4d7c853107b4986 100644 --- a/include/staff/orgs.inc.php +++ b/include/staff/orgs.inc.php @@ -86,9 +86,27 @@ $_SESSION['orgs_qs_'.$qhash] = $query; </table> </form> </div> - <div class="pull-right flush-right"> - <b><a href="#orgs/add" class="Icon newDepartment add-org"><?php - echo __('Add New Organization'); ?></a></b></div> + +<div class="pull-right"> + <a class="action-button add-org" + href="#"> + <i class="icon-plus-sign"></i> + <?php echo __('Add Organization'); ?> + </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="orgs-action" href="#delete"> + <i class="icon-trash icon-fixed-width"></i> + <?php echo __('Delete'); ?></a></li> + </ul> + </div> +</div> + <div class="clear"></div> <?php $showing = $search ? __('Search Results').': ' : ''; @@ -98,14 +116,16 @@ if($res && ($num=db_num_rows($res))) else $showing .= __('No organizations found!'); ?> -<form action="orgs.php" method="POST" name="staff" > +<form id="orgs-list" action="orgs.php" method="POST" name="staff" > <?php csrf_token(); ?> - <input type="hidden" name="do" value="mass_process" > - <input type="hidden" id="action" name="a" value="" > + <input type="hidden" name="a" value="mass_process" > + <input type="hidden" id="action" name="do" value="" > + <input type="hidden" id="selected-count" name="count" value="" > <table class="list" border="0" cellspacing="1" cellpadding="0" width="940"> <caption><?php echo $showing; ?></caption> <thead> <tr> + <th nowrap width="12"> </th> <th width="400"><a <?php echo $name_sort; ?> href="orgs.php?<?php echo $qstr; ?>&sort=name"><?php echo __('Name'); ?></a></th> <th width="100"><a <?php echo $users_sort; ?> href="orgs.php?<?php echo $qstr; ?>&sort=users"><?php echo __('Users'); ?></a></th> <th width="150"><a <?php echo $create_sort; ?> href="orgs.php?<?php echo $qstr; ?>&sort=create"><?php echo __('Created'); ?></a></th> @@ -123,6 +143,9 @@ else $sel=true; ?> <tr id="<?php echo $row['id']; ?>"> + <td nowrap> + <input type="checkbox" value="<?php echo $row['id']; ?>" class="mass nowarn"/> + </td> <td> <a href="orgs.php?id=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a> </td> <td> <?php echo $row['users']; ?></td> <td><?php echo Format::db_date($row['created']); ?></td> @@ -171,5 +194,28 @@ $(function() { return false; }); + + var goBaby = function(action) { + var ids = [], + $form = $('form#orgs-list'); + $(':checkbox.mass:checked', $form).each(function() { + ids.push($(this).val()); + }); + if (ids.length && confirm(__('You sure?'))) { + $form.find('#action').val(action); + $.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')); + } + }; + $(document).on('click', 'a.orgs-action', function(e) { + e.preventDefault(); + goBaby($(this).attr('href').substr(1)); + return false; + }); }); </script> diff --git a/include/staff/user-view.inc.php b/include/staff/user-view.inc.php index 7bb706c898b86fbde3c5310323ac72af82cd140b..1111cbf0e33fb7edfb8cce6a09583198b77145e8 100644 --- a/include/staff/user-view.inc.php +++ b/include/staff/user-view.inc.php @@ -28,7 +28,7 @@ $org = $user->getOrganization(); <?php } else { ?> <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 } ?> diff --git a/include/staff/users.inc.php b/include/staff/users.inc.php index deae27b5ea5ff1a10597ff78139d3b0490988de5..900651ea4e65dd7e97f9b1e7beb07b1622ad53c7 100644 --- a/include/staff/users.inc.php +++ b/include/staff/users.inc.php @@ -90,12 +90,52 @@ $_SESSION['users_qs_'.$qhash] = $query; </table> </form> </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> - | - <b><a href="#users/import" class="popup-dialog"><i class="icon-cloud-upload icon-large"></i> - <?php echo __('Import'); ?></a></b> + +<div class="pull-right"> + <a class="action-button popup-dialog" + href="#users/add"> + <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 href="#orgs/lookup/form" onclick="javascript: +$.dialog('ajax.php/orgs/lookup/form', 201); +return false;"> + <i class="icon-group icon-fixed-width"></i> + <?php echo __('Add to Organization'); ?></a></li> +<?php +if ('disabled' != $cfg->getClientRegistrationMode()) { ?> + <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> +<?php } # end of registration-enabled? ?> + </ul> + </div> </div> + <div class="clear"></div> <?php $showing = $search ? __('Search Results').': ' : ''; @@ -105,14 +145,17 @@ if($res && ($num=db_num_rows($res))) else $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(); ?> <input type="hidden" name="do" value="mass_process" > <input type="hidden" id="action" name="a" value="" > + <input type="hidden" id="selected-count" name="count" value="" > + <input type="hidden" id="org_id" name="org_id" value="" > <table class="list" border="0" cellspacing="1" cellpadding="0" width="940"> <caption><?php echo $showing; ?></caption> <thead> <tr> + <th nowrap width="12"> </th> <th width="350"><a <?php echo $name_sort; ?> href="users.php?<?php echo $qstr; ?>&sort=name"><?php echo __('Name'); ?></a></th> <th width="250"><a <?php echo $status_sort; ?> href="users.php?<?php @@ -145,6 +188,9 @@ else $sel=true; ?> <tr id="<?php echo $row['id']; ?>"> + <td nowrap> + <input type="checkbox" value="<?php echo $row['id']; ?>" class="mass nowarn"/> + </td> <td> <a class="userPreview" href="users.php?id=<?php echo $row['id']; ?>"><?php echo Format::htmlchars($name); ?></a> @@ -202,7 +248,38 @@ $(function() { }); return false; - }); + }); + var goBaby = function(action) { + 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(action); + $.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')); + } + }; + $(document).on('click', 'a.users-action', function(e) { + e.preventDefault(); + goBaby($(this).attr('href').substr(1)); + return false; + }); + $(document).on('dialog:close', function(e, json) { + $form = $('form#users-list'); + try { + var json = $.parseJSON(json); + $form.find('#org_id').val(json.id); + goBaby('setorg'); + } + catch (e) { console.log(e); } + }); }); </script> diff --git a/scp/ajax.php b/scp/ajax.php index 1168513601eb45882783c339934006856b36c550..6134731257943043d726590e305273d9daf46dc8 100644 --- a/scp/ajax.php +++ b/scp/ajax.php @@ -107,7 +107,7 @@ $dispatcher = patterns('', url_post('^/(?P<id>\d+)/profile$', 'updateOrg', array(true)), url_get('^/(?P<id>\d+)/edit$', 'editOrg'), url_get('^/lookup/form$', 'lookup'), - url_post('^/lookup/form$', 'addOrg'), + url_post('^/lookup$', 'lookup'), url_get('^/add$', 'addOrg'), url_post('^/add$', 'addOrg'), url_get('^/select$', 'selectOrg'), diff --git a/scp/js/scp.js b/scp/js/scp.js index f3d9ab3e1f84a7bf7e0bcd147bcb4b63fa213e50..02fe02c6b37f7b9fc3da9b3bc0cbaee41eb4b77e 100644 --- a/scp/js/scp.js +++ b/scp/js/scp.js @@ -570,12 +570,14 @@ $.dialog = function (url, codes, cb, options) { data: $form.serialize(), cache: false, success: function(resp, status, xhr) { + var done = $.Event('dialog:close'); if (xhr && xhr.status && codes && $.inArray(xhr.status, codes) != -1) { $.toggleOverlay(false); $popup.hide(); $('div.body', $popup).empty(); - if(cb) cb(xhr); + if(cb) cb(xhr, resp); + $popup.trigger(done, [resp, status, xhr]); } else { $('div.body', $popup).html(resp); $popup.effect('shake'); diff --git a/scp/orgs.php b/scp/orgs.php index 22cd2aeca213b7b6452b577d49390588fe87d822..e1b48de31e70cadc99dc4ce3f86b23e7de70385b 100644 --- a/scp/orgs.php +++ b/scp/orgs.php @@ -58,6 +58,39 @@ if ($_POST) { _N('selected end user', 'selected end users', $count)); } break; + + case 'mass_process': + if (!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) { + $errors['err'] = sprintf(__('You must select at least %s.'), + __('one organization')); + } + else { + $orgs = Organization::objects()->filter( + array('id__in' => $_POST['ids']) + ); + $count = 0; + switch (strtolower($_POST['do'])) { + case 'delete': + foreach ($orgs as $O) + if ($O->delete()) + $count++; + break; + + default: + $errors['err']=__('Unknown action - get technical help.'); + } + if (!$errors['err'] && !$count) { + $errors['err'] = __('Unable to manage any of the selected organizations'); + } + elseif ($_POST['count'] && $count != $_POST['count']) { + $warn = __('Not all selected items were updated'); + } + elseif ($count) { + $msg = __('Successfully managed selected organizations'); + } + } + break; + default: $errors['err'] = __('Unknown action'); } diff --git a/scp/users.php b/scp/users.php index ade2474137ff87dd793e9ebc01d9aad9dcd2a98c..bf5140215aa7012ad1d8eb72f42a0fc53c0cf6c1 100644 --- a/scp/users.php +++ b/scp/users.php @@ -70,7 +70,70 @@ if ($_POST) { $errors['err'] = sprintf(__('You must select at least %s.'), __('one end user')); } 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; + + case 'setorg': + if (!($org = Organization::lookup($_POST['org_id']))) + $errors['err'] = __('Unknown action - get technical help.'); + foreach ($users as $U) { + if ($U->setOrganization($org)) + $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; case 'import-users':