Gazelle/sections/user/linkedfunctions.php
2012-02-04 08:00:25 +00:00

1 line
5.6 KiB
PHP

<?
include_once(SERVER_ROOT.'/classes/class_text.php'); // Text formatting class
function link_users($UserID, $TargetID) {
global $DB;
authorize();
if (!check_perms('users_mod')) {
error(403);
}
if (!is_number($UserID) || !is_number($TargetID)) {
error(403);
}
if ($UserID == $TargetID) {
return;
}
$DB->query("SELECT 1 FROM users_main WHERE ID IN ($UserID, $TargetID)");
if ($DB->record_count() != 2) {
error(403);
}
$DB->query("SELECT GroupID FROM users_dupes WHERE UserID = $TargetID");
list($TargetGroupID) = $DB->next_record();
$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");
list($UserGroupID, $Comments) = $DB->next_record();
if ($TargetGroupID) {
if ($TargetGroupID == $UserGroupID) {
return;
}
if ($UserGroupID) {
$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");
$DB->query("DELETE FROM dupe_groups WHERE ID = $UserGroupID");
} else {
$DB->query("INSERT INTO users_dupes (UserID, GroupID) VALUES ($UserID, $TargetGroupID)");
}
} elseif ($UserGroupID) {
$DB->query("INSERT INTO users_dupes (UserID, GroupID) VALUES ($TargetID, $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)");
}
}
function unlink_user($UserID) {
global $DB;
authorize();
if (!check_perms('users_mod')) {
error(403);
}
if (!is_number($UserID)) {
error(403);
}
$DB->query("DELETE FROM users_dupes WHERE UserID='$UserID'");
$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");
}
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) {
global $DB, $Text;
authorize();
if (!check_perms('users_mod')) {
error(403);
}
if (!is_number($GroupID)) {
error(403);
}
$DB->query("UPDATE dupe_groups SET Comments = '".db_string($Comments)."' WHERE ID = '$GroupID'");
}
function user_dupes_table($UserID) {
global $DB, $LoggedUser;
$Text = new TEXT;
if (!check_perms('users_mod')) {
error(403);
}
if (!is_number($UserID)) {
error(403);
}
$DB->query("SELECT d.ID, d.Comments
FROM dupe_groups AS d
JOIN users_dupes AS u ON u.GroupID = d.ID
WHERE u.UserID = $UserID");
if (list($GroupID, $Comments) = $DB->next_record()) {
$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 = $UserID DESC");
$DupeCount = $DB->record_count();
$Dupes = $DB->to_array();
} else {
$DupeCount = 0;
$Dupes = array();
}
?>
<div class="box">
<div class="head"><?=max($DupeCount - 1, 0)?> Linked Account<?=(($DupeCount == 2)?'':'s')?> <a href="#" onclick="$('.linkedaccounts').toggle(); return false;">(View)</a></div>
<?
if ($DupeCount > 0) {
?>
<table width="100%" class="hidden linkedaccounts">
<tr>
<?
$i = 0;
foreach ($Dupes as $Dupe) {
$i++;
list($DupeID) = $Dupe;
$DupeInfo = user_info($DupeID);
?>
<td align="left"><?=format_username($DupeID, $DupeInfo['Username'], $DupeInfo['Donor'], $DupeInfo['Warned'], $DupeInfo['Enabled'])?>
(<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?');">x</a>)</td>
<?
if ($i == 5) {
$i = 0;
echo "</tr><tr>";
}
}
for ($j = $i; $j < 5; $j++) {
echo '<td>&nbsp;</td>';
}
?>
</tr>
<tr>
<td colspan="5" align="left" style="border-top: thin solid"><strong>Comments:</strong></td>
</tr>
<tr>
<td colspan="5" align="left">
<div id="dupecomments"><?=$Text->full_format($Comments);?></div>
<div id="editdupecomments" class="hidden">
<form>
<input type="hidden" name="action" value="dupes">
<input type="hidden" name="dupeaction" value="comments">
<input type="hidden" name="groupid" value="<?=$GroupID?>">
<input type="hidden" name="userid" value="<?=$UserID?>">
<input type="hidden" id="auth" name="auth" value="<?=$LoggedUser['AuthKey']?>">
<textarea name="dupecomments" onkeyup="resize('dupecommentsbox');" id="dupecommentsbox" cols="65" rows="5" style="width:98%;"><?=display_str($Comments)?></textarea>
<input type="submit" value="Set Comments">
</form>
</div>
<span style="float:right; font-style: italic;"><a href="#" onClick="$('#dupecomments').toggle(); $('#editdupecomments').toggle(); resize('dupecommentsbox'); return false;">(Edit linked account comments)</a>
</td>
</tr>
</table>
<?
}
?>
<div class="pad hidden linkedaccounts">
<form method="GET">
<input type="hidden" name="action" value="dupes">
<input type="hidden" name="authkey" value="dupes">
<input type="hidden" name="dupeaction" value="add">
<input type="hidden" name="userid" value="<?=$UserID?>">
<input type="hidden" id="auth" name="auth" value="<?=$LoggedUser['AuthKey']?>">
<label for="target">Link this user with: </label><input type="text" name="target" id="target"><input type="submit" value="Link">
</form>
</div>
</div>
<?
}
?>