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.user.php b/include/class.user.php index a6f996002c6b8f60c5126040a2488ee225e92eea..886c18db9759700a816045236fc67d44366cfb2c 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -840,12 +840,12 @@ class UserAccountModel extends VerySimpleModel { function lock() { $this->setStatus(UserAccountStatus::LOCKED); - $this->save(); + return $this->save(); } function unlock() { $this->clearStatus(UserAccountStatus::LOCKED); - $this->save(); + return $this->save(); } function isLocked() { diff --git a/include/staff/users.inc.php b/include/staff/users.inc.php index be1739ec929d0ed40bb967bf752a3f878603a72d..900651ea4e65dd7e97f9b1e7beb07b1622ad53c7 100644 --- a/include/staff/users.inc.php +++ b/include/staff/users.inc.php @@ -112,6 +112,13 @@ $_SESSION['users_qs_'.$qhash] = $query; <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> @@ -124,6 +131,7 @@ $_SESSION['users_qs_'.$qhash] = $query; <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> @@ -142,6 +150,7 @@ else <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> @@ -240,15 +249,14 @@ $(function() { return false; }); - $(document).on('click', 'a.users-action', function(e) { - e.preventDefault(); + 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($(this).attr('href').substr(1)); + $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(); @@ -257,8 +265,21 @@ $(function() { $.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/users.php b/scp/users.php index f9915606d30f9265cf2ce607b761ca27c70de8dd..bf5140215aa7012ad1d8eb72f42a0fc53c0cf6c1 100644 --- a/scp/users.php +++ b/scp/users.php @@ -111,6 +111,15 @@ if ($_POST) { } 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.'); }