diff --git a/public/include/autoloader.inc.php b/public/include/autoloader.inc.php index 936ee1c9..37b3d09a 100644 --- a/public/include/autoloader.inc.php +++ b/public/include/autoloader.inc.php @@ -7,4 +7,5 @@ require_once(INCLUDE_DIR . '/smarty.inc.php'); // Load classes that need the above as dependencies require_once(CLASS_DIR . '/user.class.php'); require_once(CLASS_DIR . '/block.class.php'); +require_once(CLASS_DIR . '/share.class.php'); require_once(CLASS_DIR . '/settings.class.php'); diff --git a/public/include/classes/share.class.php b/public/include/classes/share.class.php new file mode 100644 index 00000000..62527821 --- /dev/null +++ b/public/include/classes/share.class.php @@ -0,0 +1,99 @@ +debug = $debug; + $this->mysqli = $mysqli; + $this->debug->append("Instantiated Share class", 2); + } + + // get and set methods + private function setErrorMessage($msg) { + $this->sError = $msg; + } + public function getError() { + return $this->sError; + } + + public function getSharesForAccountsByTimeframe($current='', $old='') { + $stmt = $this->mysqli->prepare("SELECT + a.id, + validT.account AS username, + sum(validT.valid) as valid, + IFNULL(sum(invalidT.invalid),0) as invalid + FROM + ( + SELECT DISTINCT + SUBSTRING_INDEX( `username` , '.', 1 ) as account, + COUNT(id) AS valid + FROM $this->table + WHERE + UNIX_TIMESTAMP(time) BETWEEN ? AND ? + AND + our_result = 'Y' + GROUP BY account + ) validT + LEFT JOIN + ( + SELECT DISTINCT + SUBSTRING_INDEX( `username` , '.', 1 ) as account, + COUNT(id) AS invalid + FROM $this->table + WHERE + UNIX_TIMESTAMP(time) BETWEEN ? AND ? + AND + our_result = 'N' + GROUP BY account + ) invalidT + ON validT.account = invalidT.account + INNER JOIN accounts a ON a.username = validT.account + GROUP BY a.username DESC"); + echo $this->mysqli->error; + if ($this->checkStmt($stmt)) { + $stmt->bind_param('iiii', $old, $current, $old, $current); + $stmt->execute(); + $result = $stmt->get_result(); + $stmt->close(); + return $result->fetch_all(MYSQLI_ASSOC); + } + return false; + } + + public function getFinderByTimeframe($current='', $old='') { + $stmt = $this->mysqli->prepare("SELECT + SUBSTRING_INDEX( `username` , '.', 1 ) AS account + FROM $this->table + WHERE upstream_result = 'Y' + AND UNIX_TIMESTAMP(time) BETWEEN ? AND ? + ORDER BY id DESC"); + echo $this->mysqli->error; + if ($this->checkStmt($stmt)) { + $stmt->bind_param('ii', $old, $current); + $stmt->execute(); + $result = $stmt->get_result(); + $stmt->close(); + return $result->fetch_object()->account; + } + return false; + } + + private function checkStmt($bState) { + if ($bState ===! true) { + $this->debug->append("Failed to prepare statement: " . $this->mysqli->error); + $this->setErrorMessage('Internal application Error'); + return false; + } + return true; + } +} + +$share = new Share($debug, $mysqli, SALT);