function friendlist_unignore()
{
    global $session;
    $ac = httpget('ac');
    $ignored = rexplode(get_module_pref('ignored', 'friendlist', $ac));
    $iveignored = rexplode(get_module_pref('iveignored'));
    if (in_array($ac, $iveignored)) {
        $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            $row = db_fetch_assoc($result);
            $info = sprintf_translate("%s`Q has been removed from your list.", $row['name']);
            require_once "lib/systemmail.php";
            $t = array("`\$Ignore List Removal");
            $mailmessage = array("%s`0`@ has removed you from %s ignore list.", $session['user']['name'], $session['user']['sex'] ? translate_inline("her") : translate_inline("his"));
            systemmail($ac, $t, $mailmessage);
        } else {
            $info = translate_inline("That user no longer exists...");
        }
    }
    $ignored = array_diff($ignored, array($session['user']['acctid']));
    $ignored = rimplode($ignored);
    set_module_pref('ignored', $ignored, 'friendlist', $ac);
    if (in_array($ac, $iveignored)) {
        $iveignored = array_diff($iveignored, array($ac));
        $iveignored = rimplode($iveignored);
        set_module_pref('iveignored', $iveignored);
    }
    output_notl($info);
}
function friendlist_ignore()
{
    global $session;
    $iveignored = rexplode(get_module_pref('iveignored'));
    $friends = rexplode(get_module_pref('friends'));
    $request = rexplode(get_module_pref('request'));
    $ac = httpget('ac');
    $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
    $result = db_query($sql);
    if (db_num_rows($result) > 0 && in_array($ac, $friends)) {
        $row = db_fetch_assoc($result);
        require_once "lib/systemmail.php";
        $t = "`\$Friend List Ignore";
        $mailmessage = array("%s`0`@ has added you to %s ignore list.", $session['user']['name'], $session['user']['sex'] ? translate_inline("her") : translate_inline("his"));
        systemmail($ac, $t, $mailmessage);
        $friends = array_diff($friends, array($ac));
        invalidatedatacache("friendliststat-" . $session['user']['acctid']);
        invalidatedatacache("friendliststat-" . $ac);
    }
    $friends = rimplode($friends);
    set_module_pref('friends', $friends);
    $ignored = rexplode(get_module_pref('ignored', 'friendlist', $ac));
    $ignored[] = $session['user']['acctid'];
    $ignored = rimplode($ignored);
    set_module_pref('ignored', $ignored, 'friendlist', $ac);
    $act = $session['user']['acctid'];
    $friends = rexplode(get_module_pref('friends', 'friendlist', $ac));
    $friends = array_diff($friends, array($act));
    $friends = rimplode($friends);
    set_module_pref('friends', $friends, 'friendlist', $ac);
    if (in_array($ac, $request)) {
        $request = array_diff($request, array($ac));
        $request = rimplode($request);
        set_module_pref('request', $request);
    }
    $iveignored[] = $ac;
    $iveignored = rimplode($iveignored);
    set_module_pref('iveignored', $iveignored);
    output("You have ignored that user, they can no longer YoM you");
}
function friendlist_deny()
{
    global $session;
    $ignored = rexplode(get_module_pref('ignored'));
    $friends = rexplode(get_module_pref('friends'));
    $request = rexplode(get_module_pref('request'));
    $ac = httpget('ac');
    $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
    $result = db_query($sql);
    if (in_array($ac, $friends)) {
        $info = translate_inline("That user has been removed.");
        require_once "lib/systemmail.php";
        $t = "`\$Friend List Removal";
        $mailmessage = array("%s`0`@ has deleted you from %s Friend List.", $session['user']['name'], $session['user']['sex'] ? translate_inline("her") : translate_inline("his"));
        $friends = array_diff($friends, array($ac));
        $friends = rimplode($friends);
        set_module_pref('friends', $friends);
        $act = $session['user']['acctid'];
        $friends = rexplode(get_module_pref('friends', 'friendlist', $ac));
        $friends = array_diff($friends, array($act));
        $friends = rimplode($friends);
        set_module_pref('friends', $friends, 'friendlist', $ac);
        invalidatedatacache("friendliststat-" . $session['user']['acctid']);
        invalidatedatacache("friendliststat-" . $ac);
    } else {
        $info = translate_inline("That user has been denied.");
        require_once "lib/systemmail.php";
        $t = "`\$Friend Request Denied";
        $mailmessage = array("%s`0`@ has denied you your Friend Request.", $session['user']['name']);
        $request = array_diff($request, array($ac));
        $request = rimplode($request);
        set_module_pref('request', $request);
    }
    if (db_num_rows($result) > 0) {
        systemmail($ac, $t, $mailmessage);
        $row = db_fetch_assoc($result);
        $info = sprintf_translate("%s has been removed", $row['name']);
    }
    output_notl($info);
}
function friendlist_accept()
{
    global $session;
    $ignored = rexplode(get_module_pref('ignored'));
    $request = rexplode(get_module_pref('request'));
    $friends = rexplode(get_module_pref('friends'));
    $ac = httpget('ac');
    if (in_array($ac, $ignored)) {
        $info = translate_inline("This user has ignored you.");
    } elseif (in_array($ac, $friends)) {
        $info = translate_inline("This user is already in your list.");
    } elseif (in_array($ac, $request)) {
        $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            $row = db_fetch_assoc($result);
            invalidatedatacache("friendliststat-" . $session['user']['acctid']);
            invalidatedatacache("friendliststat-" . $ac);
            $friends[] = $ac;
            $info = sprintf_translate("%s`Q has been added to your list.", $row['name']);
            require_once "lib/systemmail.php";
            $t = "`\$Friend Request Accepted";
            $mailmessage = array("%s`0`@ has accepted your Friend Request.", $session['user']['name']);
            systemmail($ac, $t, $mailmessage);
            $friends = rimplode($friends);
            set_module_pref('friends', $friends);
            $friends = rexplode(get_module_pref('friends', 'friendlist', $ac));
            $friends[] = $session['user']['acctid'];
            $friends = rimplode($friends);
            set_module_pref('friends', $friends, 'friendlist', $ac);
            $request = array_diff($request, array($ac));
            $request = rimplode($request);
            set_module_pref('request', $request);
        } else {
            $info = translate_inline("That user no longer exists...");
        }
    }
    output_notl($info);
}
function friendlist_request()
{
    global $session;
    $ac = httpget('ac');
    $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$ac} AND locked=0";
    $result = db_query($sql);
    if (db_num_rows($result) > 0) {
        $row = db_fetch_assoc($result);
        $info = translate_inline("You have successfully sent your request to %s`Q.");
        $info = str_replace('%s', $row['name'], $info);
        require_once "lib/systemmail.php";
        $t = array("`\$Friend Request Sent");
        $mailmessage = array("%s`0`@ has sent you a Friend Request.`nIf this user has been spamming you with this, ignore them from your search function.", $session['user']['name']);
        systemmail($ac, $t, $mailmessage);
    } else {
        $info = translate_inline("That user no longer exists...");
    }
    $request = get_module_pref('request', 'friendlist', $ac);
    $request = rexplode($request);
    $request[] = $session['user']['acctid'];
    $request = rimplode($request);
    set_module_pref('request', $request, 'friendlist', $ac);
    output_notl($info);
}
function friendlist_list()
{
    global $session;
    $friends = rexplode(get_module_pref('friends'));
    $request = rexplode(get_module_pref('request'));
    $ignored = rexplode(get_module_pref('ignored'));
    $iveignored = rexplode(get_module_pref('iveignored'));
    output("`b`@Friends:`b`n");
    rawoutput("<table style='width:60%;text-align:center;' cellpadding='3' cellspacing='0' border='0'>");
    rawoutput("<tr class='trhead'><td>" . translate_inline("Name") . "</td><td>" . translate_inline("Logged In") . "</td><td>" . translate_inline("Location") . "</td><td>" . translate_inline("Alive") . "</td><td>" . translate_inline("Operations") . "</td></tr>");
    $last = date("Y-m-d H:i:s", strtotime("-" . getsetting("LOGINTIMEOUT", 900) . " sec"));
    $x = 0;
    if (implode(",", $friends) != '') {
        $sql = "SELECT name,acctid,login,laston,alive,loggedin,location FROM " . db_prefix("accounts") . " WHERE acctid IN (" . implode(',', $friends) . ") AND locked=0 ORDER BY login";
        $result = db_query($sql);
        while ($row = db_fetch_assoc($result)) {
            $ac = $row['acctid'];
            $x++;
            rawoutput("<tr class='" . ($x % 2 ? "trlight" : "trdark") . "'>");
            rawoutput("<td><a href='mail.php?op=write&to=" . rawurlencode($row['login']) . "'>" . appoencode("`&" . $row['name'], false) . "</a></td>");
            addnav("", "mail.php?op=write&to=" . rawurlencode($row['login']));
            $loggedin = $row['loggedin'];
            if ($row['laston'] < $last) {
                $loggedin = false;
            }
            $loggedin = translate_inline($loggedin ? "`^Yes`0" : "`%No`0");
            rawoutput("<td>" . appoencode($loggedin, false) . "</td>");
            rawoutput("<td><span class='colLtYellow'>" . htmlentities($row['location']) . "</span></td>");
            $alive = translate_inline($row['alive'] ? "`@Yes`0" : "`\$No`0");
            rawoutput("<td>" . appoencode($alive, false) . "</td>");
            $ops = "[<a href='runmodule.php?module=friendlist&op=deny&ac={$ac}' class='colDkGreen'>" . translate_inline("Remove") . "</a>] - [<a href='runmodule.php?module=friendlist&op=ignore&ac={$ac}' class='colDkGreen'>" . translate_inline("Ignore") . "</a>]";
            addnav("", "runmodule.php?module=friendlist&op=deny&ac={$ac}");
            addnav("", "runmodule.php?module=friendlist&op=ignore&ac={$ac}");
            rawoutput("<td>{$ops}</td></tr>");
        }
    }
    if ($x == 0) {
        rawoutput("<tr class='trlight'><td colspan='5'>");
        output("`^You have no friends");
        rawoutput("</td></tr>");
    }
    rawoutput("</table>");
    $friends = rimplode($friends);
    set_module_pref('friends', $friends);
    output("`n`b`@Friend Requests:`b`n");
    rawoutput("<table style='width:60%;text-align:center;' cellpadding='3' cellspacing='0' border='0'>");
    rawoutput("<tr class='trhead'><td>" . translate_inline("Name") . "</td><td>" . translate_inline("Operations") . "</td></tr>");
    $x = 0;
    $request = array_unique($request);
    if (implode(",", $request) != '') {
        $sql = "SELECT name,acctid,login,laston,alive,loggedin,location FROM " . db_prefix("accounts") . " WHERE acctid IN (" . implode(',', $request) . ") AND locked=0 ORDER BY login";
        $result = db_query($sql);
        while ($row = db_fetch_assoc($result)) {
            $ac = $row['acctid'];
            $x++;
            rawoutput("<tr class='" . ($x % 2 ? "trlight" : "trdark") . "'>");
            rawoutput("<td>" . appoencode($row['name'], false) . "</td>");
            $ops = "[<a href='runmodule.php?module=friendlist&op=accept&ac={$ac}' class='colDkGreen'>" . translate_inline("Accept") . "</a>] - [<a href='runmodule.php?module=friendlist&op=deny&ac={$ac}' class='colDkGreen'>" . translate_inline("Deny") . "</a>] - [<a href='runmodule.php?module=friendlist&op=ignore&ac={$ac}' class='colDkGreen'>" . translate_inline("Ignore") . "</a>]";
            addnav("", "runmodule.php?module=friendlist&op=accept&ac={$ac}");
            addnav("", "runmodule.php?module=friendlist&op=deny&ac={$ac}");
            addnav("", "runmodule.php?module=friendlist&op=ignore&ac={$ac}");
            rawoutput("<td>{$ops}</td></tr>");
        }
    }
    if ($x == 0) {
        rawoutput("<tr class='trlight'><td colspan='2'>");
        output("`^You have no requests");
        rawoutput("</td></tr>");
    }
    rawoutput("</table>");
    $request = rimplode($request);
    set_module_pref('request', $request);
    output("`n`b`@Ignored You:`b`n");
    rawoutput("<table style='width:60%;text-align:center;' cellpadding='3' cellspacing='0' border='0'>");
    rawoutput("<tr class='trhead'><td>" . translate_inline("Name") . "</td><td>" . translate_inline("Operations") . "</td></tr>");
    $x = 0;
    $ignored = array_unique($ignored);
    if (implode(",", $ignored) != '') {
        $sql = "SELECT name,acctid,login,laston,alive,loggedin,location FROM " . db_prefix("accounts") . " WHERE acctid IN (" . implode(',', $ignored) . ") AND locked=0 ORDER BY login";
        $result = db_query($sql);
        while ($row = db_fetch_assoc($result)) {
            $x++;
            $ac = $row['acctid'];
            rawoutput("<tr class='" . ($x % 2 ? "trlight" : "trdark") . "'>");
            rawoutput("<td>" . appoencode($row['name'], false) . "</td>");
            if (!in_array($ac, $iveignored)) {
                $ops = "[<a href='runmodule.php?module=friendlist&op=ignore&ac={$ac}' class='colDkGreen'>" . translate_inline("Ignore") . "</a>]";
                addnav("", "runmodule.php?module=friendlist&op=ignore&ac={$ac}");
            } else {
                $ops = appoencode("`i[" . translate_inline("Nothing") . "]`i", false);
            }
            rawoutput("<td>{$ops}</td></tr>");
        }
    }
    if ($x == 0) {
        rawoutput("<tr class='trlight'><td colspan='2'>");
        output("`^No one has ignored you");
        rawoutput("</td></tr>");
    }
    rawoutput("</table>");
    $ignored = rimplode($ignored);
    set_module_pref('ignored', $ignored);
    output("`n`b`@You've Ignored:`b`n");
    rawoutput("<table style='width:60%;text-align:center;' cellpadding='3' cellspacing='0' border='0'>");
    rawoutput("<tr class='trhead'><td>" . translate_inline("Name") . "</td><td>" . translate_inline("Operations") . "</td></tr>");
    $x = 0;
    $iveignored = array_unique($iveignored);
    if (implode(",", $iveignored) != '') {
        $sql = "SELECT name,acctid,login,laston,alive,loggedin,location FROM " . db_prefix("accounts") . " WHERE acctid IN (" . implode(',', $iveignored) . ") AND locked=0 ORDER BY login";
        $result = db_query($sql);
        while ($row = db_fetch_assoc($result)) {
            $x++;
            $ac = $row['acctid'];
            rawoutput("<tr class='" . ($x % 2 ? "trlight" : "trdark") . "'>");
            rawoutput("<td>" . appoencode($row['name'], false) . "</td>");
            $ops = "[<a href='runmodule.php?module=friendlist&op=unignore&ac={$ac}' class='colLtRed'>" . translate_inline("Unignore") . "</a>]";
            addnav("", "runmodule.php?module=friendlist&op=unignore&ac={$ac}");
            rawoutput("<td>{$ops}</td></tr>");
        }
    }
    if ($x == 0) {
        rawoutput("<tr class='trlight'><td colspan='2'>");
        output("`^You've haven't ignored anyone");
        rawoutput("</td></tr>");
    }
    rawoutput("</table>");
    $iveignored = rimplode($iveignored);
    set_module_pref('iveignored', $iveignored);
}