/**
* This is largely cadged from PageHistory::history
*/
function showCreditsPage($article)
{
global $wgOut, $wgUser;
$fname = 'showCreditsPage';
wfProfileIn($fname);
// Show a 404 page for anonymous users accessing the credits.
// We do this to hopefully improve SEO by removing links visible
// to Google.
if ($wgUser->isAnon()) {
$wgOut->setRobotpolicy('noindex,nofollow');
$wgOut->addHTML(wfMsg('logintoview'));
header('HTTP/1.0 404 Not Found');
return;
}
$wgOut->setPageTitle($article->mTitle->getPrefixedText());
$wgOut->setSubtitle(wfMsg('creditspage'));
$wgOut->setArticleFlag(false);
$wgOut->setArticleRelated(true);
$wgOut->setRobotpolicy('noindex,nofollow');
if ($article->mTitle->getArticleID() == 0) {
$s = wfMsg('nocredits');
} else {
$s = getCredits($article, -1);
}
$wgOut->addHTML($s);
wfProfileOut($fname);
}
function createTransaction()
{
// We need globals.
global $DB;
global $MySelf;
global $TIMEMARK;
// Are we allowed to poke in here?
if (!$MySelf->isAccountant()) {
makeNotice("Umm, you are not allowed to do this. Really. You are not.", "warning", "You are not supposed to be here");
}
// Check the ints.
numericCheck($_POST[wod], 0, 1);
numericCheck($_POST[amount], 0);
numericCheck($_POST[id], 0);
// Its easier on the eyes.
$type = $_POST[wod];
$amount = $_POST[amount];
$id = $_POST[id];
$username = idToUsername($id);
// invert the amount if we have a withdrawal.
if ($_POST[wod] == 1) {
$dir = "withdrawed";
$dir2 = "from";
$hisMoney = getCredits($id);
if ($hisMoney < $amount) {
$ayee = $hisMoney - $amount;
confirm("WARNING:<br>{$username} can NOT afford this withdrawal. If you choose to " . "authorize this transaction anyway his account will be at " . number_format($ayee, 2) . " ISK.");
}
} else {
$amount = $_POST[amount];
$dir = "deposited";
$dir2 = "into";
}
// We use custom reason, if set.
if ($_POST[reason2] != "") {
$reason = sanitize($_POST[reason2]);
} else {
$reason = sanitize($_POST[reason1]);
}
// Create transaction.
$transaction = new transaction($id, $type, $amount);
$transaction->setReason($reason);
// Success?
if (!$transaction->commit()) {
// Nope :(
makeNotice("Unable to create transaction. Danger, Will Robinson, DANGER!", "error", "Internal Error", "index.php?action=edituser&id={$id}", "[Back]");
} else {
// Success !
makeNotice("You successfully {$dir} {$amount} ISK {$dir2} " . $username . "'s account.", "notice", "Transaction complete", "index.php?action=edituser&id={$id}", "[Ok]");
}
}
function transferMoney()
{
// Globals
global $MySelf;
global $DB;
global $TIMEMARK;
$MyCredits = getCredits($MySelf->getID());
// Can we afford even the most basic transactions?
if (!numericCheckBool($MyCredits, 0)) {
makeNotice("You can not afford any transaction.", "warning", "Out of money", "index.php?action=manageWallet", "[cancel]");
}
// Did we supply an isk amount at all?
if ($_POST[amount] == "") {
makeNotice("You did not specify an ISK amount. Please go back, and try again.", "warning", "How much?", "index.php?action=manageWallet", "[cancel]");
}
if (!is_numeric($_POST[amount])) {
makeNotice("The frog looks at you and your cheque with the amount of \"" . $_POST[amount] . "\". The frog is unsure how much ISK that is and instead decides to lick your face in a friendly manner, then it closes the teller and goes for lunch.", "warning", "Huh?");
}
// Check for sanity.
if (!numericCheckBool($_POST[to], 0)) {
makeNotice("The supplied reciver is not valid.", "warning", "Invalid ID", "index.php?action=manageWallet", "[cancel]");
}
if (!numericCheckBool($_POST[amount], 0)) {
makeNotice("You need to specify a positive ISK value.", "error", "Invalid amount", "index.php?action=manageWallet", "[cancel]");
}
if (!numericCheckBool($_POST[amount], 0, $MyCredits)) {
makeNotice("You can not afford this transaction.", "warning", "Out of money", "index.php?action=manageWallet", "[cancel]");
}
// Ok so now we know: The reciver is valid, the sender has enough money.
$from = "<br><br>From: " . ucfirst($MySelf->getUsername());
$to = "<br>To: " . ucfirst(idToUsername($_POST[to]));
$amount = "<br>Amount: " . number_format($_POST[amount], 2) . " ISK";
$reason = "<br>Reason: " . $_POST[reason];
confirm("Please authorize this transaction:" . $from . $to . $amount . $reason);
// Lets do it.
$transaction = new transaction($_POST[to], 0, $_POST[amount]);
$transaction->setReason("Cash transfer from " . ucfirst($MySelf->getUsername()) . " to " . ucfirst(idToUsername($_POST[to])) . ": " . $_POST[reason]);
$transaction->isTransfer(true);
$transaction->commit();
// Send'em back.
makeNotice($amount . " has been transfered from your into " . ucfirst(idToUsername($_POST[to])) . " account.", "notice", "Cash transfered", "index.php?action=manageWallet", "[OK]");
}
function requestPayout()
{
// Globals
global $MySelf;
global $DB;
global $TIMEMARK;
// How much overdraft are we allowed?
$overdraft = 100 * 1000000;
// 100m
$overdraftlimit = false;
// How much isk we got?
$MyCredits = getCredits($MySelf->getID());
// Is this a number?
if (!is_numeric($_POST[amount])) {
makeNotice("The frog looks at you and your cheque with the amount of \"" . $_POST[amount] . "\". The frog is unsure how much ISK that is and instead decides to lick your face in a friendly manner, then it closes the teller and goes for lunch.", "warning", "Huh?");
}
// We are requesting a POSITIVE amount, right?
if (!numericCheckBool($_POST[amount], 0)) {
makeNotice("You can only request positive amounts of ISK. If you want money, go work for it.", "notice", "This aint no charity", "index.php?action=manageWallet", "But i got women and children to feed...");
}
// So, can we afford it?
if ($overdraft <= 0 && !numericCheckBool($_POST[amount], 1, $MyCredits)) {
makeNotice("You can only request a payment up to " . number_format($MyCredits) . " ISK. You requested " . number_format($_POST[amount]) . " ISK. Thats " . number_format($_POST[amount] - $MyCredits, 2) . " ISK more than you can afford.", "warning", "Too big of a payout.", "index.php?action=manageWallet", "[Cancel]");
}
// Allow an overdraft, but not too much
if ($overdraft > 0 && $overdraftlimit && !numericCheckBool($_POST[amount], 1, $MyCredits + $overdraft)) {
makeNotice("You can only request a payment up to " . number_format($MyCredits + $overdraft) . " ISK. You requested " . number_format($_POST[amount]) . " ISK. Thats " . number_format($_POST[amount] - ($MyCredits + $overdraft), 2) . " ISK more than you are allowed.", "warning", "Too big of a payout.", "index.php?action=manageWallet", "[Cancel]");
}
// We sure?
confirm("Please confirm your payout request of " . number_format($_POST[amount], 2) . " ISK.");
// Ok, do it.
$DB->query("INSERT INTO payoutRequests (time, applicant, amount) VALUES (?,?,?)", array($TIMEMARK, $MySelf->getID(), $_POST[amount]));
if ($DB->affectedRows() == 1) {
mailUser("We are notifying you that " . $MySelf->getUsername() . " has requested a payout of " . number_format($_POST[amount], 2) . " ISK", "WHB Payout Requested", "isAccountant");
makeNotice("You request has been logged. An accountant will soon honor your request.", "notice", "Request logged", "index.php?action=manageWallet", "[OK]");
} else {
makeNotice("Internal Error! Unable to record your request into the database! Inform the admin!", "error", "Internal Error!", "index.php?action=manageWallet", "[cancel]");
}
}
function changeCredits($uid, $pid, $credits)
{
if (!canViewPuzzle($uid, $pid)) {
utilsError("You do not have permission to modify this puzzle.");
}
$purifier = new HTMLPurifier();
mysql_query('START TRANSACTION');
$oldCredits = getCredits($pid);
$cleanCredits = $purifier->purify($credits);
//$cleanCredits = htmlspecialchars($cleanCredits);
updateCredits($uid, $pid, $oldCredits, $cleanCredits);
mysql_query('COMMIT');
}
function makeWelcome()
{
// Load the globals.
global $VERSION;
global $SITENAME;
global $IGB;
global $IGB_VISUAL;
global $MySelf;
global $DB;
global $ValidUntil;
/* HTML stuff */
$page = "<h2>Welcome to {$VERSION}!</h2>";
/* The welcome table */
$table = new table(2, true);
$table->addHeader(">> Welcome to {$VERSION}");
$table->addRow();
$table->addCol("Logged in as:", array("bold" => true, "align" => "right"));
$table->addCol(ucfirst($MySelf->getUsername()));
$table->addRow();
$table->addCol("Registered Rank:", array("bold" => true, "align" => "right"));
$table->addCol($MySelf->getRankName());
$table->addRow();
$table->addCol("Latest login:", array("bold" => true, "align" => "right"));
if ($MySelf->getLastlogin() < 1) {
$table->addCol("This is your very first login! Welcome!");
} else {
$table->addCol(date("r", $MySelf->getLastlogin()));
}
$table->addRow();
$table->addCol("Your account:", array("bold" => true, "align" => "right"));
$table->addCol(number_format(getCredits($MySelf->getID()), 2) . " ISK");
$table->addRow();
$table->addCol("Your profile:", array("bold" => true, "align" => "right"));
$table->addCol(makeProfileLink($MySelf->getID()));
global $BLESSED;
if ($BLESSED) {
$table->addRow("#330000");
$table->addCol("Installation Blessed!", array("bold" => true, "align" => "right"));
$table->addCol("It is not affected by expiration. It runs with the highest priority on the server and all limitations have been lifted.");
}
// Set the filename to the announce textfile.
$announceFile = "/path/to/your/announce/txt.file";
// Check its existance...
if (file_exists($announceFile)) {
// Then load it.
$globalAnnounce = file_get_contents($announceFile);
}
// Only display contents if more than X characters long.
if (strlen($globalAnnounce) > 10) {
// Create announcement table...
$announceTable = new table(1, true);
$announceTable->addHeader(">>> Important hosting information");
$announceTable->addRow();
$announceTable->addCol("{$globalAnnounce}");
// ... and add it to the page.
$page .= $announceTable->flush();
}
$page .= $table->flush();
/* Show failed Logins to admins. */
if ($MySelf->isAdmin()) {
$page .= showFailedLogins("15");
} else {
$page .= showFailedLogins("10", $MySelf->getUsername());
}
/* permissions table */
$permsTable = new table(1, true);
$permsTable->addHeader(">> Your permissions");
// Permissions matrix
$perms = array("canLogin" => "log in.", "canJoinRun" => "join mining operations.", "canCreateRun" => "create new mining operations.", "canCloseRun" => "close mining operations.", "canDeleteRun" => "delete mining operations.", "canAddHaul" => "haul to mining operations.", "canSeeEvents" => "view scheduled events.", "canEditEvents" => "add and delete scheduled events.", "canChangePwd" => "change your own password.", "canChangeEmail" => "change your own email.", "canChangeOre" => "manage ore prices and enable/disable them.", "canAddUser" => "add new accounts.", "canSeeUsers" => "see other accounts.", "canDeleteUser" => "delete other accounts.", "canEditRank" => "edit other peoples ranks.", "canManageUser" => "grant and take permissions.", "isAccountant" => "manage the corporation wallet and authorize payments.", "isOfficial" => "create official mining runs (with payout).");
$permDS = $DB->getAssoc("SELECT * FROM users WHERE id='" . $MySelf->getID() . "' AND deleted='0'");
$keys = array_keys($perms);
foreach ($keys as $key) {
if ($permDS[$MySelf->getID()][$key] == 1) {
$permsTable->addRow();
$permsTable->addCol("You are allowed to " . $perms[$key]);
}
}
$permsTable->addHeader("If you believe your permissions are faulty, consult your CEO immediatly.");
// Show the balance
$balance = getTransactions($MySelf->getID());
$logins = getLogins($MySelf->getID());
$page .= "<br>" . $balance . "<br>" . $permsTable->flush() . "<br>" . $logins;
// .. then return it.
return $page;
}
function payout()
{
// Some globals needed.
global $DB;
global $TIMEMARK;
global $MySelf;
global $IGB;
global $IGB_VISUAL;
// Are we allowed to do this?
if (!$MySelf->isAccountant()) {
makeNotice("You are not an accountant to your corporation. Access denied.", "error", "Access denied");
}
/*
* Amount of ISK owned.
*/
$iskOwned = new table(2, true);
$iskOwned->addHeader(">> Outstanding ISK");
// Load all unique members from the database.
$uniqeMembers = $DB->query("SELECT DISTINCT id FROM users WHERE deleted='0' ORDER BY username ASC");
// Create a row for each member.
while ($id = $uniqeMembers->fetchRow()) {
$playerCreds = getCredits($id['id']);
// We need this later on...
$allPeeps[$id['id']] = ucfirst(idToUsername($id['id']));
// if the member has more or less than zero isk, list him.
if ($playerCreds != 0) {
$iskOwned->addRow();
$iskOwned->addCol("<a href=\"index.php?action=showTransactions&id=" . $id['id'] . "\">" . $allPeeps[$id['id']] . "</a>");
$iskOwned->addCol(number_format($playerCreds, 2) . " ISK");
}
}
// Show the total isk owned.
$outstanding = totalIskOwned();
$iskOwned->addRow("#060622");
$iskOwned->addCol(">> Total Outstanding ISK:");
$iskOwned->addCol(totalIskOwned() . " ISK");
/*
* Show a drop down menu to create a menu to see everyones transaction log.
*/
$freeSelect = new table(2, true);
$freeSelect->addHeader(">> Lookup specific transaction log");
// Create a PDM for all the peoples.
foreach ($allPeeps as $peep) {
$pdm .= "<option value=\"" . array_search($peep, $allPeeps) . "\">{$peep}</option>";
}
$freeSelect->addRow();
$freeSelect->addCol("Show log of ", array("align" => "right"));
$freeSelect->addCol("<select name=\"id\">{$pdm}</select>");
$freeSelect->addHeaderCentered("<input type=\"submit\" name=\"submit\" value=\"Lookup log in Database\">");
unset($pdm);
/*
* Show current requests
*/
$requests = $DB->query("SELECT * FROM payoutRequests WHERE payoutTime IS NULL ORDER BY time DESC");
if ($IGB && $IGB_VISUAL) {
$table = new table(6, true);
} else {
$table = new table(5, true);
}
$table->addHeader(">> Pending payout requests");
$table->addRow("#060622");
$table->addCol("request");
$table->addCol("applicant");
if ($IGB && $IGB_VISUAL) {
$table->addCol("right click menu");
}
$table->addCol("time");
$table->addCol("amount");
$table->addCol("Payout");
while ($request = $requests->fetchRow()) {
if ($IGB && $IGB_VISUAL) {
$api = new api($request['applicant']);
// $profile = new profile($request['applicant']);
if ($api->valid() && ($IGB && $IGB_VISUAL)) {
$rcm = " [<a href=\"showinfo:1378//" . $api->getCharacterID() . "\">RCM</a>]";
}
}
$table->addRow();
$table->addCol("#" . str_pad($request['request'], "5", "0", STR_PAD_LEFT));
$table->addCol("<a href=\"index.php?action=showTransactions&id={$request['applicant']}\">" . ucfirst(idToUsername($request['applicant'])) . "</a>");
if ($IGB && $IGB_VISUAL) {
$table->addCol($rcm);
}
$table->addCol(date("d.m.y H:i:s", $request['time']));
if (getCredits($request['applicant']) < $request['amount']) {
$class .= "red";
}
if ($IGB && $IGB_VISUAL) {
$table->addCol("<input type=\"text\" class=\"{$class}\" name=\"dumb\" readonly value=\"" . number_format($request['amount'], 2) . "\"> ISK");
} else {
$table->addCol(number_format($request['amount'], 2) . " ISK", array("class" => $class));
}
// Can the user still cover his request with cash?
$table->addCol("<input type=\"checkbox\" name=\"" . $request['request'] . "\" value=\"true\">");
$haveRequest = true;
//} else {
// $table->addCol("<i>not enough ISK</i>");
//}
}
$table->addHeaderCentered("<input type=\"submit\" name=\"submit\" value=\"Mark as paid\">");
//.........这里部分代码省略.........
请发表评论