| @@ -1,23 +1,43 @@ | |||
| <?php | |||
| echo '<table border="1"><caption>Account wide stats</caption>'; | |||
| echo '<tr><th>Title Name</th><th>Title Points</th><th>Current Rank</th><th>Points Remaining</th><th>Next Rank</th></tr>'; | |||
| // $gas = GetAccountStats | |||
| $gas = $con->prepare("SELECT * FROM gwaccstats WHERE userid = ? AND accid = ?;"); | |||
| $gas->bind_param("ii", $_SESSION['prefaccid'], $_SESSION['userid']); | |||
| $gas->execute(); | |||
| $result = $gas->get_result(); | |||
| while ($row = $result->fetch_assoc()) { | |||
| echo '<tr><td>' . $row['currentstrankname'] . '</td><td>' . $row['titlepoints'] . '</td><td>' . $row['currentstrank'] . '</td>'; | |||
| echo '<td>'; | |||
| $pr = ($row['nextstrankpoints'] - $row['titlepoints']); | |||
| if ($pr < 0) { | |||
| echo 'Maximum rank achieved!'; | |||
| } else { | |||
| echo $pr; | |||
| //include_once ('includes/session-debug.php'); | |||
| //include_once ('includes/session-dump.php'); | |||
| // remove the above 2 lines | |||
| if (isset($_SESSION['userid'])) { | |||
| echo '<table border="1"><caption>Account wide stats</caption>'; | |||
| echo '<tr><th>Title</th><th>Title Rank</th><th>Title Points</th><th>Current Rank</th><th>Points Remaining</th><th>Next Rank</th></tr>'; | |||
| // $gas = GetAccountStats | |||
| $gas = $con->prepare("SELECT * FROM gwaccstats WHERE userid = ? AND accid = ?"); | |||
| $gas->bind_param("ii", $_SESSION['userid'], $_SESSION['prefaccid']); | |||
| $gas->execute(); | |||
| $result = $gas->get_result(); | |||
| while ($row = $result->fetch_assoc()) { | |||
| // $gnr = Get Next Rank | |||
| $gnr = $con->prepare("SELECT stpoints, stname FROM gwsubtitles WHERE titlenameid = ? AND stpoints >= ? ORDER BY stpoints ASC LIMIT 1"); | |||
| $gnr->bind_param("ii", $row['titlenameid'], $row['titlepoints']); | |||
| $gnr->execute(); | |||
| $gnr->bind_result($stpoints, $stname); | |||
| $gnr->fetch(); | |||
| $gnr->close(); | |||
| // $gt = Get Title | |||
| $gt = $con->prepare("SELECT titlename FROM gwtitles WHERE titlenameid = ?"); | |||
| $gt->bind_param("i", $row['titlenameid']); | |||
| $gt->execute(); | |||
| $gt->bind_result($titlename); | |||
| $gt->fetch(); | |||
| $gt->close(); | |||
| $pr = number_format(($stpoints - $row['titlepoints'])); | |||
| if ($pr < 0) { | |||
| $pr = "Highest rank achieved!"; | |||
| $stname = "Highest rank achieved!"; | |||
| } | |||
| if ($row['currentstrankname'] === NULL) { | |||
| $row['currentstrankname'] = "No title earned yet!"; | |||
| $row['currentstrank'] = "0"; | |||
| } | |||
| echo '<tr><td>' . $titlename . '</td><td>' . $row['currentstrankname'] . '</td><td>' . number_format($row['titlepoints']) . '</td><td>' . $row['currentstrank'] . '</td>'; | |||
| echo '<td>' . $pr . '</td><td>' . $stname . '</td></tr>'; | |||
| } | |||
| echo '</td>'; | |||
| echo '<td>' . $row['nextstrank'] . '</td></tr>'; | |||
| $gas->close(); | |||
| echo '</table><br />'; | |||
| } | |||
| $gas->close(); | |||
| echo '</table>'; | |||
| ?> | |||
| @@ -1,38 +1,33 @@ | |||
| <?php | |||
| # delete this block when shit finally works. | |||
| ini_set('display_errors', 'on'); | |||
| error_reporting(E_ALL); | |||
| mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); | |||
| # delete the above when shit finally works | |||
| if (isset($_POST['delsubtitle'])) { | |||
| if ($delst = $con->prepare("DELETE FROM gwsubtitles WHERE titlenameid = ? AND stnameid = ?")) { | |||
| $delst->bind_param("ii", $tnameid, $stnameid); | |||
| for ($i = 0; $i < count($_POST['delsubtitle']); $i++) { | |||
| $tnameid = $_POST['titlenameid'][$i]; | |||
| $stnameid = $_POST['delsubtitle'][$i]; | |||
| $delst->execute(); | |||
| } | |||
| $delst->close(); | |||
| } | |||
| echo 'Title rank(s) have been deleted, redirecting!'; | |||
| header ("Refresh:1; url=titlemanager.php"); | |||
| } else { | |||
| // this section updates the title name | |||
| if ($upd = $con->prepare("UPDATE gwsubtitles SET stname = ?, stpoints = ?, strank = ? WHERE titlenameid = ? AND stnameid = ?")) { | |||
| $upd->bind_param("siiii", $stname, $stpoints, $strank, $titlenameid, $stnameid); | |||
| for ($i = 0; $i < count($_POST['stname']); $i++) { | |||
| $stname = $_POST['stname'][$i]; | |||
| $stpoints = $_POST['stpoints'][$i]; | |||
| $strank = $_POST['strank'][$i]; | |||
| $titlenameid = $_POST['titlenameid'][$i]; | |||
| $stnameid = $_POST['stnameid'][$i]; | |||
| $upd->execute(); | |||
| } | |||
| $upd->close(); | |||
| } | |||
| echo 'Title rank(s) updated, redirecting!'; | |||
| header ("Refresh:1; url=titlemanager.php"); | |||
| if (isset($_SESSION['userid'])) { | |||
| if (isset($_POST['delsubtitle'])) { | |||
| if ($delst = $con->prepare("DELETE FROM gwsubtitles WHERE titlenameid = ? AND stnameid = ?")) { | |||
| $delst->bind_param("ii", $tnameid, $stnameid); | |||
| for ($i = 0; $i < count($_POST['delsubtitle']); $i++) { | |||
| $tnameid = $_POST['titlenameid'][$i]; | |||
| $stnameid = $_POST['delsubtitle'][$i]; | |||
| $delst->execute(); | |||
| } | |||
| $delst->close(); | |||
| } | |||
| echo 'Title rank(s) have been deleted, redirecting!'; | |||
| header ("Refresh:1; url=titlemanager.php"); | |||
| } else { | |||
| // this section updates the title name | |||
| if ($upd = $con->prepare("UPDATE gwsubtitles SET stname = ?, stpoints = ?, strank = ? WHERE titlenameid = ? AND stnameid = ?")) { | |||
| $upd->bind_param("siiii", $stname, $stpoints, $strank, $titlenameid, $stnameid); | |||
| for ($i = 0; $i < count($_POST['stname']); $i++) { | |||
| $stname = $_POST['stname'][$i]; | |||
| $stpoints = $_POST['stpoints'][$i]; | |||
| $strank = $_POST['strank'][$i]; | |||
| $titlenameid = $_POST['titlenameid'][$i]; | |||
| $stnameid = $_POST['stnameid'][$i]; | |||
| $upd->execute(); | |||
| } | |||
| $upd->close(); | |||
| } | |||
| echo 'Title rank(s) updated, redirecting!'; | |||
| header ("Refresh:1; url=titlemanager.php"); | |||
| } | |||
| } | |||
| ?> | |||
| @@ -0,0 +1,34 @@ | |||
| <?php | |||
| if (isset($_SESSION['userid'])) { | |||
| // check to see if we're going to INSERT or UPDATE a row | |||
| // $cfr = Check For Results | |||
| $cfr = $con->prepare("SELECT COUNT(*) FROM gwaccstats WHERE titlenameid = ? AND accid = ? AND userid = ?"); | |||
| $cfr->bind_param("iii", $_POST['titlenameid'], $_SESSION['prefaccid'], $_SESSION['userid']); | |||
| $cfr->execute(); | |||
| $cfr->bind_result($r1); | |||
| $cfr->fetch(); | |||
| $cfr->close(); | |||
| // $gcr = Get Current Rank | |||
| $gcr = $con->prepare("SELECT stnameid, stname, strank FROM gwsubtitles WHERE titlenameid = ? AND stpoints <= ? ORDER BY stpoints DESC LIMIT 1"); | |||
| $gcr->bind_param("ii", $_POST['titlenameid'], $_POST['titlepoints']); | |||
| $gcr->execute(); | |||
| $gcr->bind_result($stnameid, $stname, $strank); | |||
| $gcr->fetch(); | |||
| $gcr->close(); | |||
| if ($r1 > 0) { | |||
| // $urs = Update Rank Stats | |||
| $urs = $con->prepare("UPDATE gwaccstats SET stnameid = ?, titlepoints = ?, currentstrankname = ?, currentstrank = ? WHERE titlenameid = ? AND accid = ? AND userid = ?"); | |||
| $urs->bind_param("iisiiii", $stnameid, $_POST['titlepoints'], $stname, $strank, $_POST['titlenameid'], $_SESSION['prefaccid'], $_SESSION['userid']); | |||
| $urs->execute(); | |||
| $urs->close(); | |||
| echo 'Title has been updated!<br /><br />'; | |||
| } else { | |||
| // $irs = Insert Rank Stats | |||
| $irs = $con->prepare("INSERT INTO gwaccstats (titlenameid, stnameid, titlepoints, currentstrankname, currentstrank, accid, userid) VALUES (?, ?, ?, ?, ?, ?, ?)"); | |||
| $irs->bind_param("iiisiii", $_POST['titlenameid'], $stnameid, $_POST['titlepoints'], $stname, $strank, $_SESSION['prefaccid'], $_SESSION['userid']); | |||
| $irs->execute(); | |||
| $irs->close(); | |||
| echo 'Title entered!<br /></br />'; | |||
| } | |||
| } | |||
| ?> | |||
| @@ -2,11 +2,34 @@ | |||
| $pagetitle = "Update account wide stats"; | |||
| include_once ('header.php'); | |||
| if (isset($_SESSION['userid'])) { | |||
| include_once ('includes/session-debug.php'); | |||
| include_once ('includes/session-dump.php'); | |||
| if (!isset($_POST['acctitle'])) { | |||
| $_POST['acctitle'] = "notselected"; | |||
| } | |||
| if (isset($_POST['titlepoints'])) { | |||
| // include file just updates the database | |||
| include_once ('includes/update-titleranks.php'); | |||
| } | |||
| if ($_POST['acctitle'] == "notselected") { | |||
| echo '<form action="updateaccountstats.php" method="post">'; | |||
| echo 'Select account title to update: <select name="acctitle">'; | |||
| // $ats = Account Title Select | |||
| $ats = $con->prepare("SELECT titlenameid, titlename FROM gwtitles WHERE titletype = 0"); | |||
| $ats->execute(); | |||
| $result = $ats->get_result(); | |||
| while ($row = $result->fetch_assoc()) { | |||
| echo '<option value="' . $row['titlenameid'] . '">' . $row['titlename'] . '</option>'; | |||
| } | |||
| echo '</select><input type="submit" value="Select title"></form><br />'; | |||
| $ats->close(); | |||
| } else { | |||
| echo '<form action="updateaccountstats.php" method="post"><input type="hidden" name="titlenameid" value="' . $_POST['acctitle'] .'">'; | |||
| echo '<input type="number" name="titlepoints" required autofocus><input type="submit" value="Update points"></form>'; | |||
| } | |||
| echo 'Current account stats for: <b>' . $_SESSION['prefaccname'] . '</b><br />'; | |||
| include_once ('includes/getaccountstats.php'); | |||
| echo 'Return to your <a href="index.php" class="navlink">user</a> page'; | |||
| echo 'Return to your <a href="index.php" class="navlink">user</a> page<br />'; | |||
| } | |||
| include_once ('footer.php'); | |||
| ?> | |||