From 10fc019e1eda484cfc7b0b430650770023b041ca Mon Sep 17 00:00:00 2001 From: mauirixxx Date: Thu, 16 Aug 2018 23:25:54 -1000 Subject: [PATCH] individual stat tracking is completed --- header.php | 9 ++++---- includes/getaccountstats.php | 4 ++-- includes/getcharstats.php | 47 ++++++++++++++++++++++++++++++++++++++ includes/update-chartitleranks.php | 42 ++++++++++++++++++++++++++++++++++ updateaccountstats.php | 2 +- updatecharstats.php | 29 ++++++++++++++++++++++- 6 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 includes/getcharstats.php create mode 100644 includes/update-chartitleranks.php diff --git a/header.php b/header.php index 4854ae8..f7b0888 100644 --- a/header.php +++ b/header.php @@ -36,9 +36,6 @@ if (!$userid){ } echo '
'; echo '(Home) (Options) '; - if ($_SESSION['admin'] == 1){ - echo'(Administration) '; - } echo '() (Logout ' . $_SESSION['username'] . ')


'; + echo ') '; + if ($_SESSION['admin'] == 1){ + echo'(Administration) '; + } + echo '(Logout ' . $_SESSION['username'] . ')

'; } ?> \ No newline at end of file diff --git a/includes/getaccountstats.php b/includes/getaccountstats.php index a6359ae..9ab32cd 100644 --- a/includes/getaccountstats.php +++ b/includes/getaccountstats.php @@ -23,7 +23,7 @@ if (isset($_SESSION['userid'])) { $gt->fetch(); $gt->close(); $pr = number_format(($stpoints - $row['titlepoints'])); - if ($pr < 0) { + if ($pr <= 0) { $pr = "Highest rank achieved!"; $stname = "Highest rank achieved!"; } @@ -31,7 +31,7 @@ if (isset($_SESSION['userid'])) { $row['currentstrankname'] = "No title earned yet!"; $row['currentstrank'] = "0"; } - if ($row['percent'] > 100) { + if ($row['percent'] >= 100) { $ohp = 100; } else { $ohp = $row['percent']; diff --git a/includes/getcharstats.php b/includes/getcharstats.php new file mode 100644 index 0000000..faa792c --- /dev/null +++ b/includes/getcharstats.php @@ -0,0 +1,47 @@ +Character stats'; + echo 'TitleTitle RankTitle PointsCurrent RankPoints RemainingMax Title %Next Rank'; + // $gcs = Get Character Stats + $gcs = $con->prepare("SELECT * FROM gwcharstats WHERE charid = ? AND accid = ? AND userid = ? ORDER BY currentstrank DESC, percent ASC"); + $gcs->bind_param("iii", $_SESSION['prefcharid'], $_SESSION['prefaccid'], $_SESSION['userid']); + $gcs->execute(); + $result = $gcs->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"; + } + if ($row['percent'] >= 100) { + $ohp = 100; + } else { + $ohp = $row['percent']; + } + echo '' . $titlename . '' . $row['currentstrankname'] . '' . number_format($row['titlepoints']) . '' . $row['currentstrank'] . ''; + echo '' . $pr . '
'; + echo $ohp; + echo '% completed' . $stname . ''; + } + $gcs->close(); + echo '
'; +} +?> \ No newline at end of file diff --git a/includes/update-chartitleranks.php b/includes/update-chartitleranks.php new file mode 100644 index 0000000..91eca2d --- /dev/null +++ b/includes/update-chartitleranks.php @@ -0,0 +1,42 @@ +prepare("SELECT COUNT(*) FROM gwcharstats WHERE charid = ? AND titlenameid = ? AND accid = ? AND userid = ?"); + $cfr->bind_param("iiii", $_SESSION['prefcharid'], $_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(); + // $gpc = Get Percentage Completed + $gpc = $con->prepare("SELECT stpoints FROM gwsubtitles WHERE titlenameid = ? ORDER BY stnameid DESC LIMIT 1"); + $gpc->bind_param("i", $_POST['titlenameid']); + $gpc->execute(); + $gpc->bind_result($pmr); //$pmr = Percentage Max Rank + $gpc->fetch(); + $gpc->close(); + $progress = ceil(($_POST['titlepoints'] / $pmr) * 100); + if ($r1 > 0) { + // $urs = Update Rank Stats + $urs = $con->prepare("UPDATE gwcharstats SET stnameid = ?, titlepoints = ?, currentstrankname = ?, currentstrank = ?, percent = ? WHERE charid = ? AND titlenameid = ? AND accid = ? AND userid = ?"); + $urs->bind_param("iisiiiiii", $stnameid, $_POST['titlepoints'], $stname, $strank, $progress, $_SESSION['prefcharid'], $_POST['titlenameid'], $_SESSION['prefaccid'], $_SESSION['userid']); + $urs->execute(); + $urs->close(); + echo 'Title has been updated!

'; + } else { + // $irs = Insert Rank Stats + $irs = $con->prepare("INSERT INTO gwcharstats (titlenameid, stnameid, titlepoints, currentstrankname, currentstrank, percent, charid, accid, userid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $irs->bind_param("iiisiiiii", $_POST['titlenameid'], $stnameid, $_POST['titlepoints'], $stname, $strank, $progress, $_SESSION['prefcharid'], $_SESSION['prefaccid'], $_SESSION['userid']); + $irs->execute(); + $irs->close(); + echo 'Title entered!

'; + } +} +?> \ No newline at end of file diff --git a/updateaccountstats.php b/updateaccountstats.php index 9189ad8..218c42e 100644 --- a/updateaccountstats.php +++ b/updateaccountstats.php @@ -15,7 +15,7 @@ if (isset($_SESSION['userid'])) { echo '
'; echo 'Select account title to update: '; + // $cts = Character Title Select + $cts = $con->prepare("SELECT titlenameid, titlename FROM gwtitles WHERE titletype = 1 ORDER BY titlename"); + $cts->execute(); + $result = $cts->get_result(); + while ($row = $result->fetch_assoc()) { + echo ''; + } + echo '

'; + $cts->close(); + } else { + echo '
'; + echo '
'; + } + echo 'Current character stats for: ' . $_SESSION['prefcharname'] . '
'; + include_once ('includes/getcharstats.php'); + echo 'Return to your user page
'; } include_once ('footer.php'); ?> \ No newline at end of file