Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
Tz Tools
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
fa978a0c
authored
2011-02-10 14:12:06 +0000
by
Marty Penner
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Refactored merge users functionality to search in more places; changed output HTML to tables
1 parent
df223fbc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
104 deletions
com/UserManager/UserManager.php
com/UserManager/views/merge_users.php
com/UserManager/UserManager.php
View file @
fa978a0
...
...
@@ -967,10 +967,10 @@ class Actions {
}
if
(
$do_search
==
'yes'
)
{
$username
=
$
_POST
[
'search_user_'
.
$direction
]
;
$username
=
$
wpdb
->
escape
(
$_POST
[
'search_user_'
.
$direction
])
;
// Don't search for an empty string as it will return all results
if
(
empty
(
$
_POST
[
'search_user_'
.
$direction
]
))
{
if
(
empty
(
$
username
))
{
die
(
json_encode
(
array
(
'success'
=>
'false'
,
'msg'
=>
'You must enter a value to search for.'
...
...
@@ -978,34 +978,43 @@ class Actions {
}
// Initialize
$html
=
'<
div><ul class="user-list"><h4>Username</h4><h4>Member ID</h4><h4>Email</h4
>'
;
$html
=
'<
table><thead><tr><th>First Name</th><th>Last Name</th><th>Member ID</th><th>Email</th></tr></thead><tbody
>'
;
$i
=
0
;
$query
=
"SELECT ID, user_login, user_email FROM
$wpdb->users
WHERE user_login LIKE '"
.
$wpdb
->
escape
(
$username
)
.
"%'"
;
// Check for search term in first_name, last_name, user_login, and user_email, but only if user status is not 'terminated'
$query
=
"
SELECT ID, user_email
FROM
$wpdb->users
WHERE
(user_login LIKE '%
$username
%')
OR (user_email LIKE '%
$username
%')
OR (ID IN (
SELECT user_id
FROM
$wpdb->usermeta
WHERE (meta_key = 'first_name' OR meta_key = 'last_name')
AND meta_value LIKE '%
$username
%'
))
AND (ID NOT IN (
SELECT user_id FROM
$wpdb->usermeta
WHERE meta_key = 'status' AND meta_value = 'terminated'
))
ORDER BY user_email"
;
$result
=
$wpdb
->
get_results
(
$query
,
ARRAY_A
);
if
(
!
empty
(
$result
))
{
foreach
(
$result
as
$user
)
{
// Check if user has status of 'terminated'
$user_status
=
$wpdb
->
get_var
(
$wpdb
->
prepare
(
"SELECT meta_value FROM
$wpdb->usermeta
WHERE user_id = %d AND meta_key LIKE 'status'"
,
$user
[
'ID'
]));
if
(
$user_status
==
'terminated'
)
{
continue
;
}
// Get the member ID as well, but don't display it if it's the same as 'user_login'
$member_id
=
get_user_meta
(
$user
[
'ID'
],
'member_id'
,
TRUE
);
if
(
$member_id
==
$user
[
'user_login'
])
{
$member_id
=
'""'
;
}
// Get the member ID as well
$member_id
=
get_user_meta
(
$user
[
'ID'
],
'member_id'
,
TRUE
);
$first_name
=
get_user_meta
(
$user
[
'ID'
],
'first_name'
,
TRUE
);
$last_name
=
get_user_meta
(
$user
[
'ID'
],
'last_name'
,
TRUE
);
$html
.=
<<<HTML
<
li
>
<
input type="radio" name="merge_user_{$direction}" value="{$user['user_login']}" /
>
<
label for="merge_user_{$direction}">{$user['user_login']}</label
>
<
label for="merge_user_{$direction}">{$member_id}</label
>
<
label for="merge_user_{$direction}">{$user['user_email']}</label
>
</
li
>
<
tr
>
<
td><input type="radio" name="merge_user_{$direction}" value="{$user['ID']}" />$first_name</td
>
<
td>$last_name</td
>
<
td>$member_id</td
>
<
td>{$user['user_email']}</td
>
</
tr
>
HTML;
$i
++
;
...
...
@@ -1013,10 +1022,10 @@ HTML;
}
else
{
die
(
json_encode
(
array
(
'success'
=>
'false'
,
'msg'
=>
'No users found matching that
criteria
.'
'msg'
=>
'No users found matching that
term
.'
)));
}
$html
.=
'</
ul></div
>'
;
$html
.=
'</
tbody></table
>'
;
$return
=
array
(
'success'
=>
'true'
,
...
...
@@ -1040,12 +1049,45 @@ HTML;
$html
=
''
;
$from_user
=
new
User\Account
(
$_POST
[
'merge_user_from'
]);
$to_user
=
new
User\Account
(
$_POST
[
'merge_user_to'
]);
// These fields are skipped ONLY IN DISPLAY
$skipped_fields
=
array
(
'ID'
,
'id'
,
'user_login'
,
'user_email'
,
'member_id'
'member_id'
,
'caps'
,
'cap_key'
,
'roles'
,
'allcaps'
,
'filter'
,
'user_pass'
,
'user_activation_key'
,
'status'
,
'four_security_expiration'
,
'course_4q_approvals'
,
'user_level'
,
'validated'
,
'posts_per_page'
,
'overload_ppp'
,
'rich_editing'
,
'comment_shortcuts'
,
'admin_color'
,
'use_ssl'
,
'wp_capabilities'
,
'wp_user_level'
,
'x_cicbv.person'
,
'tz_profile_pub'
,
'events'
,
'four_security_questions'
,
'special_statuses'
,
'mainmenu'
,
'cehours'
,
'subscription'
,
'notices'
,
'invoices'
,
'courses_registered'
,
);
// Get rid of the unnecessary data object in the current user object
unset
(
$from_user
->
data
);
...
...
@@ -1063,26 +1105,8 @@ HTML;
// Make sure we're updating the right user ID and perform update
update_user_meta
(
$to_user
->
ID
,
$key
,
$val
);
// Build a set of nested html lists that display the fields (goes 3 levels deep; bloody ugly, but works)
$html_l2
=
''
;
if
(
is_array
(
$val
))
{
// Rinse and repeat
foreach
(
$val
as
$subk
=>
$subv
)
{
$html_l3
=
''
;
if
(
is_array
(
$subv
))
{
// And yet again...
foreach
(
$subv
as
$k3
=>
$v3
)
{
$html_l3
.=
"<li>
$k3
=
$v3
</li>"
;
}
$html_l2
.=
"<li><ul>
$subk
: [
$html_l3
]</ul></li>"
;
}
else
{
$html_l2
.=
"<li>
$subk
=
$subv
</li>"
;
}
}
$html
.=
"<li><ul>
$key
: [
$html_l2
]</ul></li>"
;
}
else
{
$html
.=
"<li>
$key
:
$val
</li>"
;
}
// Build a table of data
$html
.=
"
\n\t
<tr><td>
$key
:
$val
</td></tr>"
;
}
// Set a few meta values for the old user
...
...
@@ -1090,9 +1114,9 @@ HTML;
update_user_meta
(
$from_user
->
ID
,
'merged_to'
,
$to_user
->
ID
);
update_user_meta
(
$from_user
->
ID
,
'datetime_merged'
,
time
());
$html
=
'<
h6>Changed:</h6><ul
>'
.
$html
=
'<
thead><tr><th>Changed:</th></tr></thead><tbody
>'
.
$html
.
'</
ul
>'
;
'</
tbody
>'
;
$return
=
array
(
'success'
=>
'true'
,
...
...
com/UserManager/views/merge_users.php
View file @
fa978a0
...
...
@@ -30,64 +30,10 @@ if (! isset($_POST['search_user_to'])) {
padding
:
10px
;
}
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
{
float
:
left
;
width
:
250px
;
margin-top
:
5px
;
border
:
1px
solid
green
;
clear
:
both
;
#field-list
{
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
;
}
</style>
<div
class=
"wrap"
>
...
...
@@ -119,9 +65,9 @@ h4 {
<div
id=
"user-list-to"
></div>
</div>
<div
id=
"field-list"
class=
"changed"
>
<div
id=
"field-list"
>
<h6>
Success!
</h6>
<
ul></ul
>
<
table></table
>
</div>
<div
style=
"clear:both;"
></div>
...
...
@@ -190,7 +136,7 @@ $(function() {
}
else
{
$
(
'#user-list-from'
).
html
(
""
);
$
(
'#user-list-to'
).
html
(
""
);
$
(
'
ul
'
,
$field_list
).
html
(
data
.
fields
);
$
(
'
table
'
,
$field_list
).
html
(
data
.
fields
);
$field_list
.
show
();
}
}
...
...
Please
register
or
sign in
to post a comment