2012-02-29 08:00:23 +00:00
< ?
function link_users ( $UserID , $TargetID ) {
global $DB , $LoggedUser ;
authorize ();
if ( ! check_perms ( 'users_mod' )) {
error ( 403 );
}
if ( ! is_number ( $UserID ) || ! is_number ( $TargetID )) {
error ( 403 );
}
if ( $UserID == $TargetID ) {
return ;
}
2013-05-27 08:00:58 +00:00
$DB -> query ( "
SELECT 1
FROM users_main
WHERE ID IN ( $UserID , $TargetID ) " );
2013-07-10 00:08:53 +00:00
if ( $DB -> record_count () !== 2 ) {
2012-02-29 08:00:23 +00:00
error ( 403 );
}
2013-05-27 08:00:58 +00:00
$DB -> query ( "
SELECT GroupID
FROM users_dupes
WHERE UserID = $TargetID " );
2012-02-29 08:00:23 +00:00
list ( $TargetGroupID ) = $DB -> next_record ();
2013-05-27 08:00:58 +00:00
$DB -> query ( "
SELECT u . GroupID , d . Comments
FROM users_dupes AS u
JOIN dupe_groups AS d ON d . ID = u . GroupID
WHERE UserID = $UserID " );
2012-02-29 08:00:23 +00:00
list ( $UserGroupID , $Comments ) = $DB -> next_record ();
2012-10-11 08:00:15 +00:00
$UserInfo = Users :: user_info ( $UserID );
$TargetInfo = Users :: user_info ( $TargetID );
2012-02-29 08:00:23 +00:00
if ( ! $UserInfo || ! $TargetInfo ) {
return ;
}
if ( $TargetGroupID ) {
if ( $TargetGroupID == $UserGroupID ) {
return ;
}
if ( $UserGroupID ) {
2013-05-27 08:00:58 +00:00
$DB -> query ( "
UPDATE users_dupes
SET GroupID = $TargetGroupID
WHERE GroupID = $UserGroupID " );
$DB -> query ( "
UPDATE dupe_groups
SET Comments = CONCAT ( '".db_string($Comments)."\n\n' , Comments )
WHERE ID = $TargetGroupID " );
2012-02-29 08:00:23 +00:00
$DB -> query ( " DELETE FROM dupe_groups WHERE ID = $UserGroupID " );
$GroupID = $UserGroupID ;
} else {
$DB -> query ( " INSERT INTO users_dupes (UserID, GroupID) VALUES ( $UserID , $TargetGroupID ) " );
$GroupID = $TargetGroupID ;
}
} elseif ( $UserGroupID ) {
$DB -> query ( " INSERT INTO users_dupes (UserID, GroupID) VALUES ( $TargetID , $UserGroupID ) " );
$GroupID = $UserGroupID ;
} else {
$DB -> query ( " INSERT INTO dupe_groups () VALUES () " );
$GroupID = $DB -> inserted_id ();
$DB -> query ( " INSERT INTO users_dupes (UserID, GroupID) VALUES ( $TargetID , $GroupID ) " );
$DB -> query ( " INSERT INTO users_dupes (UserID, GroupID) VALUES ( $UserID , $GroupID ) " );
}
$AdminComment = sqltime () . " - Linked accounts updated: [user] " . $UserInfo [ 'Username' ] . " [/user] and [user] " . $TargetInfo [ 'Username' ] . " [/user] linked by " . $LoggedUser [ 'Username' ];
2013-05-27 08:00:58 +00:00
$DB -> query ( "
UPDATE users_info AS i
JOIN users_dupes AS d ON d . UserID = i . UserID
SET i . AdminComment = CONCAT ( '".db_string($AdminComment)."\n\n' , i . AdminComment )
WHERE d . GroupID = $GroupID " );
2012-02-29 08:00:23 +00:00
}
function unlink_user ( $UserID ) {
global $DB , $LoggedUser ;
authorize ();
if ( ! check_perms ( 'users_mod' )) {
error ( 403 );
}
if ( ! is_number ( $UserID )) {
error ( 403 );
}
2012-10-11 08:00:15 +00:00
$UserInfo = Users :: user_info ( $UserID );
2013-04-13 08:00:19 +00:00
if ( $UserInfo === false ) {
2012-02-29 08:00:23 +00:00
return ;
}
$AdminComment = sqltime () . " - Linked accounts updated: [user] " . $UserInfo [ 'Username' ] . " [/user] unlinked by " . $LoggedUser [ 'Username' ];
2013-05-27 08:00:58 +00:00
$DB -> query ( "
UPDATE users_info AS i
JOIN users_dupes AS d1 ON d1 . UserID = i . UserID
JOIN users_dupes AS d2 ON d2 . GroupID = d1 . GroupID
SET i . AdminComment = CONCAT ( '".db_string($AdminComment)."\n\n' , i . AdminComment )
WHERE d2 . UserID = $UserID " );
2013-12-30 08:01:05 +00:00
$DB -> query ( " DELETE FROM users_dupes WHERE UserID = ' $UserID ' " );
2013-05-27 08:00:58 +00:00
$DB -> query ( "
DELETE g .*
FROM dupe_groups AS g
LEFT JOIN users_dupes AS u ON u . GroupID = g . ID
WHERE u . GroupID IS NULL " );
2012-02-29 08:00:23 +00:00
}
function delete_dupegroup ( $GroupID ) {
global $DB ;
authorize ();
if ( ! check_perms ( 'users_mod' )) {
error ( 403 );
}
if ( ! is_number ( $GroupID )) {
error ( 403 );
}
$DB -> query ( " DELETE FROM dupe_groups WHERE ID = ' $GroupID ' " );
}
function dupe_comments ( $GroupID , $Comments ) {
2013-12-12 08:01:01 +00:00
global $DB , $LoggedUser ;
2012-02-29 08:00:23 +00:00
authorize ();
if ( ! check_perms ( 'users_mod' )) {
error ( 403 );
}
if ( ! is_number ( $GroupID )) {
error ( 403 );
}
2013-06-09 08:01:21 +00:00
$DB -> query ( "
SELECT SHA1 ( Comments ) AS CommentHash
FROM dupe_groups
WHERE ID = $GroupID " );
2012-02-29 08:00:23 +00:00
list ( $OldCommentHash ) = $DB -> next_record ();
if ( $OldCommentHash != sha1 ( $Comments )) {
$AdminComment = sqltime () . " - Linked accounts updated: Comments updated by " . $LoggedUser [ 'Username' ];
if ( $_POST [ 'form_comment_hash' ] == $OldCommentHash ) {
2013-05-27 08:00:58 +00:00
$DB -> query ( "
UPDATE dupe_groups
SET Comments = '".db_string($Comments)."'
WHERE ID = '$GroupID' " );
2012-02-29 08:00:23 +00:00
} else {
2013-05-27 08:00:58 +00:00
$DB -> query ( "
UPDATE dupe_groups
SET Comments = CONCAT ( '".db_string($Comments)."\n\n' , Comments )
WHERE ID = '$GroupID' " );
2012-02-29 08:00:23 +00:00
}
2013-05-27 08:00:58 +00:00
$DB -> query ( "
UPDATE users_info AS i
JOIN users_dupes AS d ON d . UserID = i . UserID
SET i . AdminComment = CONCAT ( '".db_string($AdminComment)."\n\n' , i . AdminComment )
WHERE d . GroupID = $GroupID " );
2012-02-29 08:00:23 +00:00
}
}
function user_dupes_table ( $UserID ) {
global $DB , $LoggedUser ;
if ( ! check_perms ( 'users_mod' )) {
error ( 403 );
}
if ( ! is_number ( $UserID )) {
error ( 403 );
}
2013-05-15 08:00:54 +00:00
$DB -> query ( "
SELECT d . ID , d . Comments , SHA1 ( d . Comments ) AS CommentHash
FROM dupe_groups AS d
JOIN users_dupes AS u ON u . GroupID = d . ID
WHERE u . UserID = $UserID " );
2012-02-29 08:00:23 +00:00
if ( list ( $GroupID , $Comments , $CommentHash ) = $DB -> next_record ()) {
2013-05-15 08:00:54 +00:00
$DB -> query ( "
SELECT m . ID
FROM users_main AS m
JOIN users_dupes AS d ON m . ID = d . UserID
WHERE d . GroupID = $GroupID
ORDER BY m . ID ASC " );
2012-02-29 08:00:23 +00:00
$DupeCount = $DB -> record_count ();
$Dupes = $DB -> to_array ();
} else {
$DupeCount = 0 ;
$Dupes = array ();
}
?>
2012-09-29 08:00:21 +00:00
< form class = " manage_form " name = " user " method = " post " id = " linkedform " action = " " >
2012-09-15 08:00:25 +00:00
< input type = " hidden " name = " action " value = " dupes " />
< input type = " hidden " name = " dupeaction " value = " update " />
< input type = " hidden " name = " userid " value = " <?= $UserID ?> " />
< input type = " hidden " id = " auth " name = " auth " value = " <?= $LoggedUser['AuthKey'] ?> " />
< input type = " hidden " id = " form_comment_hash " name = " form_comment_hash " value = " <?= $CommentHash ?> " />
2013-06-17 08:01:02 +00:00
< div class = " box box2 " id = " l_a_box " >
2013-04-30 18:18:07 +00:00
< div class = " head " >
2014-03-19 08:00:54 +00:00
Linked Accounts ( < ? = max ( $DupeCount - 1 , 0 ) ?> ) <a href="#" onclick="$('.linkedaccounts').gtoggle(); return false;" class="brackets">View</a>
2013-04-30 18:18:07 +00:00
</ div >
2012-09-01 08:00:24 +00:00
< table width = " 100% " class = " layout hidden linkedaccounts " >
2013-12-30 08:01:05 +00:00
< ? = ( $DupeCount ? " <tr> \n " : '' ) ?>
2012-02-29 08:00:23 +00:00
< ?
$i = 0 ;
foreach ( $Dupes as $Dupe ) {
$i ++ ;
list ( $DupeID ) = $Dupe ;
2012-10-11 08:00:15 +00:00
$DupeInfo = Users :: user_info ( $DupeID );
2012-02-29 08:00:23 +00:00
?>
2013-12-30 08:01:05 +00:00
< td align = " left " >< ? = Users :: format_username ( $DupeID , true , true , true , true ) ?>
< a href = " user.php?action=dupes&dupeaction=remove&auth=<?= $LoggedUser['AuthKey'] ?>&userid=<?= $UserID ?>&removeid=<?= $DupeID ?> " onclick = " return confirm('Are you sure you wish to remove <?= $DupeInfo['Username'] ?> from this group?'); " class = " brackets tooltip " title = " Remove linked account " > X </ a >
</ td >
2012-02-29 08:00:23 +00:00
< ?
2013-12-30 08:01:05 +00:00
if ( $i == 4 ) {
2012-02-29 08:00:23 +00:00
$i = 0 ;
2013-12-30 08:01:05 +00:00
echo " \t \t \t \t \t </tr> \n \t \t \t \t \t <tr> \n " ;
2012-02-29 08:00:23 +00:00
}
}
if ( $DupeCount ) {
2013-12-30 08:01:05 +00:00
if ( $i !== 0 ) {
for ( $j = $i ; $j < 4 ; $j ++ ) {
echo " \t \t \t \t \t \t <td> </td> \n " ;
}
2012-02-29 08:00:23 +00:00
}
?>
</ tr >
< ? } ?>
< tr >
2013-05-15 08:00:54 +00:00
< td colspan = " 5 " align = " left " style = " border-top: thin solid; " >< strong > Comments :</ strong ></ td >
2012-02-29 08:00:23 +00:00
</ tr >
< tr >
< td colspan = " 5 " align = " left " >
2013-12-12 08:01:01 +00:00
< div id = " dupecomments " class = " <?=( $DupeCount ? '' : 'hidden')?> " >< ? = Text :: full_format ( $Comments ); ?> </div>
2013-05-27 08:00:58 +00:00
< div id = " editdupecomments " class = " <?=( $DupeCount ? 'hidden' : '')?> " >
2013-05-15 08:00:54 +00:00
< textarea name = " dupecomments " onkeyup = " resize('dupecommentsbox'); " id = " dupecommentsbox " cols = " 65 " rows = " 5 " style = " width: 98%; " >< ? = display_str ( $Comments ) ?> </textarea>
2012-02-29 08:00:23 +00:00
</ div >
2013-06-24 08:00:28 +00:00
< span style = " float: right; " >< a href = " # " onclick = " $ ('#dupecomments').gtoggle(); $ ('#editdupecomments').gtoggle(); resize('dupecommentsbox'); return false; " class = " brackets " > Edit linked account comments </ a ></ span >
2012-02-29 08:00:23 +00:00
</ td >
</ tr >
</ table >
< div class = " pad hidden linkedaccounts " >
2013-06-24 08:00:28 +00:00
< label for = " target " > Link this user with : </ label >
< input type = " text " name = " target " id = " target " />
< input type = " submit " value = " Update " id = " submitlink " />
2012-02-29 08:00:23 +00:00
</ div >
</ div >
</ form >
< ?
}
?>