merge_users.php
5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
namespace Tz\WordPress\Tools\UserManager;
use Tz, Tz\Common;
use Tz\WordPress\CBV;
use Tz\WordPress\CBV\User;
use Tz\WordPress\UAM;
use Tz\WordPress\Tools;
use Tz\WordPress\Tools\Auth;
use Exception, StdClass;
use WP_User;
// Make sure some defaults are set because we use these values as is in the input boxes
if (! isset($_POST['search_user_from'])) {
$_POST['search_user_from'] = '';
}
if (! isset($_POST['search_user_to'])) {
$_POST['search_user_to'] = '';
}
?>
<style>
h4 {
float: left;
padding-right: 1em;
}
.merge-users {
float: left;
padding-right: 2em;
}
.merge-users label {
float: left;
font-weight: bold;
padding-right: 1em;
}
.merge-users input {
float: left;
}
.clear {
float: left;
clear: both;
}
.user-list, .user-list li {
float: left;
clear: both;
}
.changed {
margin-top: 5px;
clear: both;
display: none;
}
.changed h6 {
padding: 0px;
margin: 0px 0px 10px 0px;
font-size: 11px;
text-transform: uppercase;
}
.changed ul {
margin: 0;
padding: 0;
}
.changed ul li {
margin: 0px 0px 3px 0px;
padding: 0px;
font-size: 11px;
background: none;
}
.merge-table td { padding:10px;}
</style>
<div class="wrap">
<div id="icon-users" class="icon32"><br /></div>
<h2>Merge CBV Users...</h2>
<div class="validation-errors" style="display:none; margin: 10px 0px 10px;">
<div class="error-wrap">
<ul></ul>
</div>
</div>
<div id="post-body" style="padding:10px 0px 15px 0px;">
<form method="post" id="admin-search-merge-form">
<table cellspacing="0" class="widefat post fixed merge-table">
<thead>
<tr>
<th width="50%"><label for="search_user_from">Merge <strong><em>FROM</em></strong> User:</label></th>
<th width="50%"><label for="search_user_to">Merge <strong><em>TO</em></strong> User:</label></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="merge-users">
<input class="clear" type="text" name="search_user_from" value="<?php echo $_POST['search_user_from'] ?>" />
<input type="button" name="btn_user_from" value="Search" /> <img id="search_user_from_spinner" class="spinners" src="/wp-content/tz-tools/com/Branding/images/spinner.gif" style="display:none;" />
</div>
</td>
<td>
<div class="merge-users">
<input class="clear" type="text" name="search_user_to" value="<?php echo $_POST['search_user_to'] ?>" />
<input type="button" name="btn_user_to" value="Search" /> <img id="search_user_to_spinner" class="spinners" src="/wp-content/tz-tools/com/Branding/images/spinner.gif" style="display:none;" />
</div>
</td>
</tr>
<tr>
<td><div id="user-list-from"></div></td>
<td><div id="user-list-to"></div></td>
</tr>
</tbody>
</table>
<div id="field-list" class="changed">
<table cellspacing="0" class="widefat post fixed merge-table"></table>
</div>
<div style="clear:both;"></div>
<div style="margin-top:10px;">
<input type="hidden" value="from" name="which_user_search" />
<input type="hidden" value="no" name="do_search" />
<input type="hidden" value="no" name="do_merge" />
<input type="button" value="Merge Users" name="btn_merge" />
</div>
</form>
</div>
</div>
<script src="<?php echo Tools\url('../UserManager.js', __FILE__);?>" type="text/javascript"></script>
<script type="text/javascript">
var $ = jQuery;
var $which_user_search = $('[name=which_user_search]');
var $do_search = $('[name=do_search]');
var $do_merge = $('[name=do_merge]');
var $form = $('#admin-search-merge-form');
var $field_list = $('#field-list');
var $error_container = $('.validation-errors');
var $from_spinner = $('#search_user_from_spinner');
var $to_spinner = $('#search_user_to_spinner');
$('[name=btn_user_from]').click(function() {
$from_spinner.show();
$which_user_search.val("from");
$do_search.val("yes");
$form.submit();
});
$('[name=btn_user_to]').click(function() {
$to_spinner.show();
$which_user_search.val("to");
$do_search.val("yes");
$form.submit();
});
$('[name=btn_merge]').click(function() {
$do_search.val("no");
$do_merge.val("yes");
if (confirm('Are you sure you want to merge users? This action is NOT reversible!')) {
$form.submit();
}
});
$(function() {
var options = {
url: ajaxurl,
dataType: 'json',
type: 'post',
data: ({ajax:"yes", action: 'admin_search_merge_users'}),
success: function(data) {
$('.spinners').hide();
if (data.success == "false") {
$('h6', $error_container).html("OOPS...");
$('ul', $error_container).html(data.msg);
$field_list.hide();
$error_container.show();
} else {
$error_container.hide();
if (data.fields === undefined) {
$('#user-list-' + data.direction).html(data.html);
$field_list.hide();
} else {
$('#user-list-from').html("");
$('#user-list-to').html("");
$('table', $field_list).html(data.fields);
$field_list.show();
}
}
}
};
$form.ajaxForm(options);
});
</script>