diff --git a/.gitignore b/.gitignore index f8ff8f89..d1d11368 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ gitignore/ .vscode/ src/themes/bluegrid *savemenu.sql -vendor/ \ No newline at end of file +vendor/ +/.idea/ diff --git a/src/_functions.php b/src/_functions.php index 4b8e3070..fd42aea0 100644 --- a/src/_functions.php +++ b/src/_functions.php @@ -1,285 +1,295 @@ , ", and ' symbols -function filterArray($arrValues) { - $newArray = array(); - foreach($arrValues as $key => $value) { - $temp = str_replace("<", "<", $value); + function filterArray($arrValues) + { + $newArray = array(); + foreach ($arrValues as $key => $value) { + $temp = str_replace("<", "<", $value); + $value = str_replace(">", ">", $temp); + $temp = str_replace("'", "'", $value); + $value = str_replace('"', '"', $temp); + $temp = str_replace("·", "&middot;", $value); + $temp = str_replace("»", "&raquo;", $temp); + $temp = str_replace("«", "&laquo;", $temp); + + $newArray[$key] = $temp; + } + return $newArray; + } + + function filterText($strText) + { + if ($strText === null) { + return ''; // Return an empty string or some default value if $strText is null + } + + $temp = str_replace("<", "<", $strText); $value = str_replace(">", ">", $temp); $temp = str_replace("'", "'", $value); $value = str_replace('"', '"', $temp); $temp = str_replace("·", "&middot;", $value); $temp = str_replace("»", "&raquo;", $temp); $temp = str_replace("«", "&laquo;", $temp); - - $newArray[$key] = $temp; + return $temp; } - return $newArray; -} - -function filterText($strText) { - $temp = str_replace("<", "<", $strText); - $value = str_replace(">", ">", $temp); - $temp = str_replace("'", "'", $value); - $value = str_replace('"', '"', $temp); - $temp = str_replace("·", "&middot;", $value); - $temp = str_replace("»", "&raquo;", $temp); - $temp = str_replace("«", "&laquo;", $temp); - return $temp; -} - -function getPreciseTime($intTime, $timeFormat="", $bypassTimeDiff=false) { - $timeDiff = (!$bypassTimeDiff) ? time() - $intTime : 99999; - - if($timeDiff < 3) { - $dispLastDate = "just now"; - } - elseif($timeDiff < 60) { - $dispLastDate = "$timeDiff seconds ago"; - } - elseif($timeDiff < 3600) { - $minDiff = round($timeDiff/60); - $dispMinute = "minutes"; - if($minDiff == 1) { - $dispMinute = "minute"; + + + function getPreciseTime($intTime, $timeFormat = "", $bypassTimeDiff = false) + { + $timeDiff = (!$bypassTimeDiff) ? time() - $intTime : 99999; + + if ($timeDiff < 3) { + $dispLastDate = "just now"; + } elseif ($timeDiff < 60) { + $dispLastDate = "$timeDiff seconds ago"; + } elseif ($timeDiff < 3600) { + $minDiff = round($timeDiff / 60); + $dispMinute = "minutes"; + if ($minDiff == 1) { + $dispMinute = "minute"; + } + + $dispLastDate = "$minDiff $dispMinute ago"; + } elseif ($timeDiff < 86400) { + $hourDiff = round($timeDiff / 3600); + $dispHour = "hours"; + if ($hourDiff == 1) { + $dispHour = "hour"; + } + + $dispLastDate = "$hourDiff $dispHour ago"; + } else { + + if ($timeFormat == "") { + $timeFormat = "D M j, Y g:i a"; + } + + + $dispLastDate = date($timeFormat, $intTime); + } - $dispLastDate = "$minDiff $dispMinute ago"; + return $dispLastDate; } - elseif($timeDiff < 86400) { - $hourDiff = round($timeDiff/3600); - $dispHour = "hours"; - if($hourDiff == 1) { - $dispHour = "hour"; - } - $dispLastDate = "$hourDiff $dispHour ago"; + function getDateUTC($time, $timeFormat = "D M j, Y g:i a") + { + $date = new DateTime(); + $date->setTimezone(new DateTimeZone("UTC")); + $date->setTimestamp($time); + + return $date->format($timeFormat); } - else { - if($timeFormat == "") { - $timeFormat = "D M j, Y g:i a"; + + function parseBBCode($strText) + { + global $MAIN_ROOT; + + // Basic Codes + + $arrBBCodes['Bold'] = array("bbOpenTag" => "[b]", "bbCloseTag" => "[/b]", "htmlOpenTag" => "", "htmlCloseTag" => ""); + $arrBBCodes['Italic'] = array("bbOpenTag" => "[i]", "bbCloseTag" => "[/i]", "htmlOpenTag" => "", "htmlCloseTag" => ""); + $arrBBCodes['Underline'] = array("bbOpenTag" => "[u]", "bbCloseTag" => "[/u]", "htmlOpenTag" => "", "htmlCloseTag" => ""); + $arrBBCodes['Image'] = array("bbOpenTag" => "[img]", "bbCloseTag" => "[/img]", "htmlOpenTag" => ""); + $arrBBCodes['CenterAlign'] = array("bbOpenTag" => "[center]", "bbCloseTag" => "[/center]", "htmlOpenTag" => "

", "htmlCloseTag" => "

"); + $arrBBCodes['LeftAlign'] = array("bbOpenTag" => "[left]", "bbCloseTag" => "[/left]", "htmlOpenTag" => "

", "htmlCloseTag" => "

"); + $arrBBCodes['RightAlign'] = array("bbOpenTag" => "[right]", "bbCloseTag" => "[/right]", "htmlOpenTag" => "

", "htmlCloseTag" => "

"); + $arrBBCodes['Quote'] = array("bbOpenTag" => "[quote]", "bbCloseTag" => "[/quote]", "htmlOpenTag" => "
", "htmlCloseTag" => "
"); + $arrBBCodes['Code'] = array("bbOpenTag" => "[code]", "bbCloseTag" => "[/code]", "htmlOpenTag" => "
", "htmlCloseTag" => "
"); + + $randPollDiv = "poll_" . md5(time() . uniqid()); + + $arrBBCodes['Poll'] = array("bbOpenTag" => "[poll]", "bbCloseTag" => "[/poll]", "htmlOpenTag" => "
"); + + + foreach ($arrBBCodes as $bbCode) { + + $strText = str_ireplace($bbCode['bbOpenTag'], $bbCode['htmlOpenTag'], $strText); + $strText = str_ireplace($bbCode['bbCloseTag'], $bbCode['htmlCloseTag'], $strText); + } + // Emoticons - $dispLastDate = date($timeFormat, $intTime); - - } + $arrEmoticonCodes = array(":)", ":(", ":D", ";)", ":p"); + $arrEmoticonImg = array("smile.png", "sad.png", "grin.png", "wink.png", "cheeky.png"); - return $dispLastDate; -} + foreach ($arrEmoticonCodes as $key => $value) { -function getDateUTC($time, $timeFormat = "D M j, Y g:i a") { - $date = new DateTime(); - $date->setTimezone(new DateTimeZone("UTC")); - $date->setTimestamp($time); - - return $date->format($timeFormat); -} + $imgURL = ""; + $strText = str_ireplace($value, $imgURL, $strText); + } -function parseBBCode($strText) { - global $MAIN_ROOT; - // Basic Codes + // Complex Codes, ex. Links, colors... - $arrBBCodes['Bold'] = array("bbOpenTag" => "[b]", "bbCloseTag" => "[/b]", "htmlOpenTag" => "", "htmlCloseTag" => ""); - $arrBBCodes['Italic'] = array("bbOpenTag" => "[i]", "bbCloseTag" => "[/i]", "htmlOpenTag" => "", "htmlCloseTag" => ""); - $arrBBCodes['Underline'] = array("bbOpenTag" => "[u]", "bbCloseTag" => "[/u]", "htmlOpenTag" => "", "htmlCloseTag" => ""); - $arrBBCodes['Image'] = array("bbOpenTag" => "[img]", "bbCloseTag" => "[/img]", "htmlOpenTag" => ""); - $arrBBCodes['CenterAlign'] = array("bbOpenTag" => "[center]", "bbCloseTag" => "[/center]", "htmlOpenTag" => "

", "htmlCloseTag" => "

"); - $arrBBCodes['LeftAlign'] = array("bbOpenTag" => "[left]", "bbCloseTag" => "[/left]", "htmlOpenTag" => "

", "htmlCloseTag" => "

"); - $arrBBCodes['RightAlign'] = array("bbOpenTag" => "[right]", "bbCloseTag" => "[/right]", "htmlOpenTag" => "

", "htmlCloseTag" => "

"); - $arrBBCodes['Quote'] = array("bbOpenTag" => "[quote]", "bbCloseTag" => "[/quote]", "htmlOpenTag" => "
", "htmlCloseTag" => "
"); - $arrBBCodes['Code'] = array("bbOpenTag" => "[code]", "bbCloseTag" => "[/code]", "htmlOpenTag" => "
", "htmlCloseTag" => "
"); - - $randPollDiv = "poll_".md5(time().uniqid()); - - $arrBBCodes['Poll'] = array("bbOpenTag" => "[poll]", "bbCloseTag" => "[/poll]", "htmlOpenTag" => "
"); - - + $strText = preg_replace("/\[url](.*?)\[\/url]/i", "$1", $strText); // Links no Titles + $strText = preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/i", "$2", $strText); // Links with Titles - foreach($arrBBCodes as $bbCode) { + $strText = preg_replace("/\[color=(.*)\](.*)\[\/color\]/i", "$2", $strText); // Text Color - $strText = str_ireplace($bbCode['bbOpenTag'],$bbCode['htmlOpenTag'],$strText); - $strText = str_ireplace($bbCode['bbCloseTag'],$bbCode['htmlCloseTag'],$strText); + $strText = str_replace("[/youtube]", "[/youtube]\n", $strText); + $strText = preg_replace("/\[youtube\](http|https)(\\:\\/\\/www\\.youtube\\.com\\/watch\\?v\\=)(.*)\[\/youtube\]/i", "", $strText); + $strText = preg_replace("/\\[youtube\\](http|https)(\\:\\/\\/youtu\\.be\\/)(.*)\\[\\/youtube\\]/i", "", $strText); + $strText = preg_replace("/\\[twitch\\](http|https)(\\:\\/\\/www\\.twitch\\.tv\\/)(.*)\\[\\/twitch\\]/i", "", $strText); + + $strText = preg_replace("/\[twitch\](http|https)(\:\/\/www\.twitch\.tv\/)(.*)\[\/twitch\]/i", "", $strText); + + $strText = autolink($strText); + + return $strText; } - - // Emoticons - - $arrEmoticonCodes = array(":)", ":(", ":D", ";)", ":p"); - $arrEmoticonImg = array("smile.png", "sad.png", "grin.png", "wink.png", "cheeky.png"); - - foreach($arrEmoticonCodes as $key => $value) { - - $imgURL = ""; - $strText = str_ireplace($value, $imgURL, $strText); - - } - - - // Complex Codes, ex. Links, colors... - - $strText = preg_replace("/\[url](.*?)\[\/url]/i", "$1", $strText); // Links no Titles - $strText = preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/i", "$2", $strText); // Links with Titles - - - - $strText = preg_replace("/\[color=(.*)\](.*)\[\/color\]/i", "$2", $strText); // Text Color - - $strText = str_replace("[/youtube]", "[/youtube]\n", $strText); - $strText = preg_replace("/\[youtube\](http|https)(\:\/\/www\.youtube\.com\/watch\?v\=)(.*)\[\/youtube\]/i", "", $strText); - $strText = preg_replace("/\[\youtube\](http|https)(\:\/\/youtu\.be\/)(.*)\[\/youtube\]/i", "", $strText); - - $strText = str_replace("[/twitch]", "[/twitch]\n", $strText); - $strText = preg_replace("/\[twitch\](http|https)(\:\/\/www\.twitch\.tv\/)(.*)\[\/twitch\]/i", "", $strText); - - $strText = autolink($strText); - - return $strText; -} - -function autoLinkImage($strText) { - $strText = preg_replace("//", "", $strText); - $strText = preg_replace("/(\"|\')(.*)(\"|\')/", "", $strText); - $strText = preg_replace("/(\"|\')(.*)(\"|\')/", "", $strText); - - return $strText; -} - -function deleteFile($filename) { - $returnVal = false; - if(file_exists($filename)) { - $returnVal = unlink($filename); + + function autoLinkImage($strText) + { + $strText = preg_replace("//", "", $strText); + $strText = preg_replace("/(\"|\')(.*)(\"|\')/", "", $strText); + $strText = preg_replace("/(\"|\')(.*)(\"|\')/", "", $strText); + + return $strText; } - - return $returnVal; -} -function getHTTP() { - if(!isset($_SERVER['HTTPS']) || (isset($_SERVER['HTTPS']) && (trim($_SERVER['HTTPS']) == "" || $_SERVER['HTTPS'] == "off"))) { - $dispHTTP = "http://"; + function deleteFile($filename) + { + $returnVal = false; + if (file_exists($filename)) { + $returnVal = unlink($filename); + } + + return $returnVal; } - else { - $dispHTTP = "https://"; + + function getHTTP() + { + if (!isset($_SERVER['HTTPS']) || (isset($_SERVER['HTTPS']) && (trim($_SERVER['HTTPS']) == "" || $_SERVER['HTTPS'] == "off"))) { + $dispHTTP = "http://"; + } else { + $dispHTTP = "https://"; + } + + return $dispHTTP; } - - return $dispHTTP; -} - -function addArraySpace($arr, $space, $atSpot) { - $newArr = array(); - $i=0; - foreach($arr as $key => $value) { - - if($atSpot == $key) { - - for($x=0; $x<$space; $x++) { - $newArr[$i] = ""; - $i++; + + function addArraySpace($arr, $space, $atSpot) + { + $newArr = array(); + $i = 0; + foreach ($arr as $key => $value) { + + if ($atSpot == $key) { + + for ($x = 0; $x < $space; $x++) { + $newArr[$i] = ""; + $i++; + } + + $newArr[$i] = $value; + } else { + $newArr[$i] = $value; } - - $newArr[$i] = $value; - } - else { - $newArr[$i] = $value; + + $i++; } - - $i++; + + return $newArr; } - - return $newArr; -} -function pluralize($word, $num) { - if($num == 1) { - $returnVal = $word; + function pluralize($word, $num) + { + if ($num == 1) { + $returnVal = $word; + } else { + $returnVal = $word . "s"; + } + + return $returnVal; } - else { - $returnVal = $word."s"; + + function encryptPassword($password) + { + $randomString = substr(md5(uniqid("", true)), 0, 22); + $randomNum = rand(4, 10); + if ($randomNum < 10) { + $randomNum = "0" . $randomNum; + } + + $strSalt = "$2a$" . $randomNum . "$" . $randomString; + $encryptPassword = crypt($password, $strSalt); + + $returnArr = array("password" => $encryptPassword, "salt" => $strSalt); + + return $returnArr; } - - return $returnVal; -} - -function encryptPassword($password) { - $randomString = substr(md5(uniqid("", true)),0,22); - $randomNum = rand(4,10); - if($randomNum < 10) { - $randomNum = "0".$randomNum; + + function getSelected($arrValues, $selectedValue) + { + $returnArr = array(); + foreach ($arrValues as $value) { + $returnArr[$value] = ($value == $selectedValue) ? " selected" : ""; + } + return $returnArr; } - - $strSalt = "$2a$".$randomNum."$".$randomString; - $encryptPassword = crypt($password, $strSalt); - - $returnArr = array("password" => $encryptPassword, "salt" => $strSalt); - - return $returnArr; -} - -function getSelected($arrValues, $selectedValue) { - $returnArr = array(); - foreach($arrValues as $value) { - $returnArr[$value] = ($value == $selectedValue) ? " selected" : ""; + + function debug_string_backtrace() + { + ob_start(); + debug_print_backtrace(); + $trace = ob_get_contents(); + ob_end_clean(); + + // Remove first item from backtrace as it's this function which + // is redundant. + $trace = preg_replace('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '', $trace, 1); + + // sanitize HTML + $trace = htmlspecialchars($trace); + + // Put each stack trace on its own line + $trace = preg_replace('/\n/', '
', $trace); + + // Delete all but 1st stack trace + // $trace = preg_replace('/\n.*/', '', $trace); + + return $trace; } - return $returnArr; -} - -function debug_string_backtrace() { - ob_start(); - debug_print_backtrace(); - $trace = ob_get_contents(); - ob_end_clean(); - - // Remove first item from backtrace as it's this function which - // is redundant. - $trace = preg_replace ('/^#0\s+' . __FUNCTION__ . "[^\n]*\n/", '', $trace, 1); - - // sanitize HTML - $trace = htmlspecialchars($trace); - - // Put each stack trace on its own line - $trace = preg_replace('/\n/', '
', $trace); - - // Delete all but 1st stack trace - // $trace = preg_replace('/\n.*/', '', $trace); - - return $trace; -} - -/** Dump your entire SQL table into an array. You can use this function to do a `WHERE $condition1Field = $condition1Value AND $condition2Field = $condition2Value` type query. */ -function sql_array_select_where($sqlTableAsArray, $condition1Field, $condition1Value, $condition2Field = false, $condition2Value = false) { - $result = []; - foreach ( $sqlTableAsArray as $row ) { - $condition2 = true; - if ( $condition2Field ) { - $condition2 = isset($row[$condition2Field]) && $row[$condition2Field] == $condition2Value; - } - - if ( - isset($row[$condition1Field]) && - $row[$condition1Field] == $condition1Value && - $condition2 - ) { - $result[] = $row; + + /** Dump your entire SQL table into an array. You can use this function to do a `WHERE $condition1Field = $condition1Value AND $condition2Field = $condition2Value` type query. */ + function sql_array_select_where($sqlTableAsArray, $condition1Field, $condition1Value, $condition2Field = false, $condition2Value = false) + { + $result = []; + foreach ($sqlTableAsArray as $row) { + $condition2 = true; + if ($condition2Field) { + $condition2 = isset($row[$condition2Field]) && $row[$condition2Field] == $condition2Value; + } + + if ( + isset($row[$condition1Field]) && + $row[$condition1Field] == $condition1Value && + $condition2 + ) { + $result[] = $row; + } } + return $result; } - return $result; -} \ No newline at end of file diff --git a/src/classes/access.php b/src/classes/access.php index d1e75244..6f5ede82 100644 --- a/src/classes/access.php +++ b/src/classes/access.php @@ -1,48 +1,50 @@ MySQL = $sqlConnection; $this->arrAccessTables = $accessTableArray; $this->arrAccessTypes = $accessTypesArray; - $this->cacheID = md5(time().uniqid()); - + $this->cacheID = md5(time() . uniqid()); + $this->objMember = new Member($sqlConnection); $this->objRankCat = new RankCategory($sqlConnection); $this->objRank = new Rank($sqlConnection); @@ -50,108 +52,111 @@ public function __construct($sqlConnection, $accessTableArray=array(), $accessTy $this->objMemberAccess = new Basic($sqlConnection, filterText($accessTableArray['member']['tableName']), filterText($accessTableArray['member']['tableID'])); $this->objRankAccess = new Basic($sqlConnection, filterText($accessTableArray['rank']['tableName']), filterText($accessTableArray['rank']['tableID'])); } - - - public function saveAccess() { - + + + public function saveAccess() + { + $arrBasicObj = array(); - - foreach($this->arrAccessTables as $key => $accessTableInfo) { + + foreach ($this->arrAccessTables as $key => $accessTableInfo) { $accessTableInfo['tableName'] = filterText($accessTableInfo['tableName']); - $this->MySQL->query("DELETE FROM ".$this->MySQL->get_tablePrefix().$accessTableInfo['tableName']." WHERE ".$this->arrAccessFor['keyName']." = '".$this->arrAccessFor['keyValue']."'"); - $this->MySQL->query("OPTIMIZE TABLE `".$this->MySQL->get_tablePrefix().$accessTableInfo['tableName']."`"); + $this->MySQL->query("DELETE FROM " . $this->MySQL->get_tablePrefix() . $accessTableInfo['tableName'] . " WHERE " . $this->arrAccessFor['keyName'] . " = '" . $this->arrAccessFor['keyValue'] . "'"); + $this->MySQL->query("OPTIMIZE TABLE `" . $this->MySQL->get_tablePrefix() . $accessTableInfo['tableName'] . "`"); } - - foreach($_SESSION['btMemberAccess'][$this->cacheID] as $memberID => $accessTypeValue) { - - if(is_numeric($memberID) && is_numeric($accessTypeValue)) { + + foreach ($_SESSION['btMemberAccess'][$this->cacheID] as $memberID => $accessTypeValue) { + + if (is_numeric($memberID) && is_numeric($accessTypeValue)) { $arrColumns = array($this->arrAccessFor['keyName'], "member_id", "accesstype"); $arrValues = array($this->arrAccessFor['keyValue'], $memberID, $accessTypeValue); $this->objMemberAccess->addNew($arrColumns, $arrValues); } } - - foreach($_SESSION['btAccessCache'][$this->cacheID] as $checkBoxName => $accessTypeValue) { + + foreach ($_SESSION['btAccessCache'][$this->cacheID] as $checkBoxName => $accessTypeValue) { $rankID = str_replace("rankaccess_", "", $checkBoxName); - if($this->objRank->select($rankID) && is_numeric($accessTypeValue)) { + if ($this->objRank->select($rankID) && is_numeric($accessTypeValue)) { $arrColumns = array($this->arrAccessFor['keyName'], "rank_id", "accesstype"); $arrValues = array($this->arrAccessFor['keyValue'], $rankID, $accessTypeValue); - $this->objRankAccess->addNew($arrColumns, $arrValues); + $this->objRankAccess->addNew($arrColumns, $arrValues); } - + } - + } - - public function dispSetRankAccess($blnShowFull=true) { + + public function dispSetRankAccess($blnShowFull = true) + { global $MAIN_ROOT, $THEME; $rankCounter = 0; $rankoptions = ""; - - $result = $this->MySQL->query("SELECT rankcategory_id FROM ".$this->MySQL->get_tablePrefix()."rankcategory ORDER BY ordernum DESC"); - while($row = $result->fetch_assoc()) { - + + $result = $this->MySQL->query("SELECT rankcategory_id FROM " . $this->MySQL->get_tablePrefix() . "rankcategory ORDER BY ordernum DESC"); + while ($row = $result->fetch_assoc()) { + $this->objRankCat->select($row['rankcategory_id']); $arrRanks = $this->objRankCat->getRanks(); $rankCatName = $this->objRankCat->get_info_filtered("name"); - - if(count($arrRanks) > 0) { - $rankoptions .= "".$rankCatName." - Check All - Uncheck All
"; - $rankoptions .= "
"; - foreach($arrRanks as $rankID) { - + + if (count($arrRanks) > 0) { + $rankoptions .= "" . $rankCatName . " - Check All - Uncheck All
"; + $rankoptions .= "
"; + foreach ($arrRanks as $rankID) { + $dispRankAccess = ""; - - foreach($this->arrAccessTypes as $accessTypeInfo) { - - if($_SESSION['btAccessCache'][$this->cacheID]["rankaccess_".$rankID] == $accessTypeInfo['value']) { - $dispRankAccess = " - ".$accessTypeInfo['displayValue'].""; + + foreach ($this->arrAccessTypes as $accessTypeInfo) { + + if (isset($_SESSION['btAccessCache'][$this->cacheID]["rankaccess_" . $rankID]) && $_SESSION['btAccessCache'][$this->cacheID]["rankaccess_" . $rankID] == $accessTypeInfo['value']) { + $dispRankAccess = " - " . $accessTypeInfo['displayValue'] . ""; } - + } - + $this->objRank->select($rankID); $rankName = $this->objRank->get_info_filtered("name"); - $rankoptions .= " ".$rankName.$dispRankAccess."
"; + $rankoptions .= " " . $rankName . $dispRankAccess . "
"; $rankCounter++; } - + $rankoptions .= "

"; - } - + } + } - - $rankOptionsHeight = $rankCounter*20; - - if($rankOptionsHeight > 300) { + + + $rankOptionsHeight = $rankCounter * 20; + + if ($rankOptionsHeight > 300) { $rankOptionsHeight = 300; } - - - if($blnShowFull) { + + + if ($blnShowFull) { echo "

-
Loading +
Loading

-
"; +
"; } - + echo $rankoptions; - - if($blnShowFull) { + + if ($blnShowFull) { echo "
With Selected:
@@ -173,13 +178,13 @@ public function dispSetRankAccess($blnShowFull=true) { var jsonRankAccess = JSON.stringify(objRankAccess); $('#loadingSpiralRankAccess').show(); - $('#".$this->rankAccessDiv."').hide(); + $('#" . $this->rankAccessDiv . "').hide(); - $.post('".$MAIN_ROOT."members/include/accesscache/setaccess.php', { accessType: 'rank', cacheID: '".$this->cacheID."', accessInfo: jsonRankAccess }, function(data) { + $.post('" . $MAIN_ROOT . "members/include/accesscache/setaccess.php', { accessType: 'rank', cacheID: '" . $this->cacheID . "', accessInfo: jsonRankAccess }, function(data) { $('#loadingSpiralRankAccess').hide(); - $('#".$this->rankAccessDiv."').html(data); - $('#".$this->rankAccessDiv."').fadeIn(250); + $('#" . $this->rankAccessDiv . "').html(data); + $('#" . $this->rankAccessDiv . "').fadeIn(250); }); @@ -188,45 +193,48 @@ public function dispSetRankAccess($blnShowFull=true) { "; } - + } - - - public function dispSetMemberAccess($blnShowFull=true) { + + + public function dispSetMemberAccess($blnShowFull = true) + { global $MAIN_ROOT, $THEME; - - if($blnShowFull) { - $membersTable = $this->MySQL->get_tablePrefix()."members"; - $ranksTable = $this->MySQL->get_tablePrefix()."ranks"; - $query = "SELECT ".$membersTable.".member_id FROM ".$membersTable.", ".$ranksTable." WHERE ".$membersTable.".rank_id = ".$ranksTable.".rank_id AND ".$membersTable.".disabled = '0' AND ".$membersTable.".rank_id != '1' ORDER BY ".$ranksTable.".ordernum DESC"; - + + $memberOptions = ""; // Initialize $memberOptions as an empty string + + if ($blnShowFull) { + $membersTable = $this->MySQL->get_tablePrefix() . "members"; + $ranksTable = $this->MySQL->get_tablePrefix() . "ranks"; + $query = "SELECT " . $membersTable . ".member_id FROM " . $membersTable . ", " . $ranksTable . " WHERE " . $membersTable . ".rank_id = " . $ranksTable . ".rank_id AND " . $membersTable . ".disabled = '0' AND " . $membersTable . ".rank_id != '1' ORDER BY " . $ranksTable . ".ordernum DESC"; + $result = $this->MySQL->query($query); - while($row = $result->fetch_assoc()) { - + while ($row = $result->fetch_assoc()) { + $this->objMember->select($row['member_id']); $this->objRank->select($this->objMember->get_info("rank_id")); - + $memberName = $this->objMember->get_info_filtered("username"); $rankName = $this->objRank->get_info_filtered("name"); - - $memberOptions .= ""; - + + $memberOptions .= ""; + } - + echo " - - - - - - - -
Member:
Access: - + + + + + + + @@ -236,13 +244,13 @@ public function dispSetMemberAccess($blnShowFull=true) {

-
Loading +
Loading

-
+
"; } - + echo "
Member:
Access: +
@@ -252,48 +260,58 @@ public function dispSetMemberAccess($blnShowFull=true) { "; - - foreach($_SESSION['btMemberAccess'][$this->cacheID] as $memberID => $accessTypeValue) { - - if($this->objMember->select($memberID)) { - + + if (is_array($_SESSION['btMemberAccess'][$this->cacheID])) { + foreach ($_SESSION['btMemberAccess'][$this->cacheID] as $memberID => $accessTypeValue) { + + if ($this->objMember->select($memberID)) { + $this->objRank->select($this->objMember->get_info("rank_id")); - + $memberName = $this->objMember->get_info_filtered("username"); $rankName = $this->objRank->get_info_filtered("name"); - - foreach($this->arrAccessTypes as $accessTypeInfo) { - if($_SESSION['btMemberAccess'][$this->cacheID][$memberID] == $accessTypeInfo['value']) { - $dispAccessValue = "".$accessTypeInfo['displayValue'].""; + $dispAccessValue = ""; + foreach ($this->arrAccessTypes as $accessTypeInfo) { + if ($_SESSION['btMemberAccess'][$this->cacheID][$memberID] == $accessTypeInfo['value']) { + $dispAccessValue = "" . $accessTypeInfo['displayValue'] . ""; } - } - + echo " - - - - - - "; + + + + + + "; } - + } - + } echo "
Actions:
".$rankName." ".$memberName."".$dispAccessValue."
" . $rankName . " " . $memberName . "" . $dispAccessValue . "
"; - - if(count($_SESSION['btMemberAccess'][$this->cacheID]) == 0) { + + if (is_array($_SESSION['btMemberAccess'][$this->cacheID]) && count($_SESSION['btMemberAccess'][$this->cacheID]) == 0) { echo " -

- No special member access rules set! -

- "; +

+ No special member access rules set! +

+ "; + } else { + echo " +

+ No special member access rules set! +

+ "; } - - if($blnShowFull) { + + echo " +
+ "; + + if ($blnShowFull) { echo "
@@ -308,13 +326,13 @@ public function dispSetMemberAccess($blnShowFull=true) { var jsonMemberAccess = JSON.stringify(objMemberAccess); $('#loadingSpiralMemberAccess').show(); - $('#".$this->memberAccessDiv."').hide(); + $('#" . $this->memberAccessDiv . "').hide(); - $.post('".$MAIN_ROOT."members/include/accesscache/setaccess.php', { accessType: 'member', cacheID: '".$this->cacheID."', accessInfo: jsonMemberAccess }, function(data) { + $.post('" . $MAIN_ROOT . "members/include/accesscache/setaccess.php', { accessType: 'member', cacheID: '" . $this->cacheID . "', accessInfo: jsonMemberAccess }, function(data) { $('#loadingSpiralMemberAccess').hide(); - $('#".$this->memberAccessDiv."').html(data); - $('#".$this->memberAccessDiv."').fadeIn(250); + $('#" . $this->memberAccessDiv . "').html(data); + $('#" . $this->memberAccessDiv . "').fadeIn(250); }); @@ -339,54 +357,57 @@ public function dispSetMemberAccess($blnShowFull=true) { "; } - + } - - - public function dispAccessOptions() { - - foreach($this->arrAccessTypes as $accessTypeInfo) { - echo ""; + + + public function dispAccessOptions() + { + + foreach ($this->arrAccessTypes as $accessTypeInfo) { + echo ""; } - + } - - public function getAccessInfo($memberObj) { + + public function getAccessInfo($memberObj) + { $memberInfo = $memberObj->get_info(); $returnArr = array("member" => "", "rank" => ""); - - $result = $this->MySQL->query("SELECT * FROM ".$this->arrAccessTables['member']['tableName']." WHERE ".filterText($this->arrAccessFor['keyName'])." = '".filterText($this->arrAccessFor['keyValue'])."' AND member_id = '".$memberInfo['member_id']."'"); - if($result->num_rows > 0) { + + $result = $this->MySQL->query("SELECT * FROM " . $this->arrAccessTables['member']['tableName'] . " WHERE " . filterText($this->arrAccessFor['keyName']) . " = '" . filterText($this->arrAccessFor['keyValue']) . "' AND member_id = '" . $memberInfo['member_id'] . "'"); + if ($result->num_rows > 0) { $row = $result->fetch_assoc(); - $returnArr['member'] = $row['accesstype']; + $returnArr['member'] = $row['accesstype']; } - - $result = $this->MySQL->query("SELECT * FROM ".$this->arrAccessTables['rank']['tableName']." WHERE ".filterText($this->arrAccessFor['keyName'])." = '".filterText($this->arrAccessFor['keyValue'])."' AND rank_id = '".$memberInfo['rank_id']."'"); - if($result->num_rows > 0) { + + $result = $this->MySQL->query("SELECT * FROM " . $this->arrAccessTables['rank']['tableName'] . " WHERE " . filterText($this->arrAccessFor['keyName']) . " = '" . filterText($this->arrAccessFor['keyValue']) . "' AND rank_id = '" . $memberInfo['rank_id'] . "'"); + if ($result->num_rows > 0) { $row = $result->fetch_assoc(); - $returnArr['rank'] = $row['accesstype']; + $returnArr['rank'] = $row['accesstype']; } - + return $returnArr; - + } - - public function loadCache() { - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix().$this->arrAccessTables['member']['tableName']." WHERE ".filterText($this->arrAccessFor['keyName'])." = '".filterText($this->arrAccessFor['keyValue'])."'"); - while($row = $result->fetch_assoc()) { + public function loadCache() + { + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . $this->arrAccessTables['member']['tableName'] . " WHERE " . filterText($this->arrAccessFor['keyName']) . " = '" . filterText($this->arrAccessFor['keyValue']) . "'"); + while ($row = $result->fetch_assoc()) { $_SESSION['btMemberAccess'][$this->cacheID][$row['member_id']] = $row['accesstype']; } - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix().$this->arrAccessTables['rank']['tableName']." WHERE ".filterText($this->arrAccessFor['keyName'])." = '".filterText($this->arrAccessFor['keyValue'])."'"); - while($row = $result->fetch_assoc()) { - $sessionName = "rankaccess_".$row['rank_id']; + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . $this->arrAccessTables['rank']['tableName'] . " WHERE " . filterText($this->arrAccessFor['keyName']) . " = '" . filterText($this->arrAccessFor['keyValue']) . "'"); + while ($row = $result->fetch_assoc()) { + $sessionName = "rankaccess_" . $row['rank_id']; $_SESSION['btAccessCache'][$this->cacheID][$sessionName] = $row['accesstype']; } - + } - - - } \ No newline at end of file + + + } diff --git a/src/classes/basic.php b/src/classes/basic.php index 5a12c177..deeb0898 100644 --- a/src/classes/basic.php +++ b/src/classes/basic.php @@ -1,450 +1,447 @@ MySQL = $sqlConnection; - $this->strTableName = $this->MySQL->get_tablePrefix().$tableName; - $this->strTableKey = $tableKey; - } - - - /** - - -Selector Method- - - intIDNum: The primary key used to identify the needed table row. Must be numeric unless $numericIDOnly is set to false. - - This will set $arrObjInfo to the table row array returned by the select statement, with the column titles set as the array keys. - Use the get_info method to get the values for the table row with the selected id number. - - Returns true when the table row is found - Returns false when no table row is found - - */ - public function select($intIDNum, $numericIDOnly = true) { - global $sqlCache; - - $returnVal = false; - if(!$numericIDOnly) { - $intIDNum = $this->MySQL->real_escape_string($intIDNum); - $checkID = true; + /* + * BlueThrust Clan Scripts + * Copyright 2014 + * + * Author: Bluethrust Web Development + * E-mail: support@bluethrust.com + * Website: http://www.bluethrust.com + * + * License: http://www.bluethrust.com/license.php + * + */ + + + class Basic + { + + + protected $MySQL; + protected $strTableName; + protected $strTableKey; + protected $intTableKeyValue; + protected $strTablePrefix; + protected $arrObjInfo; + + public function __construct($sqlConnection, $tableName, $tableKey) + { + $this->MySQL = $sqlConnection; + $this->strTableName = $this->MySQL->get_tablePrefix() . $tableName; + $this->strTableKey = $tableKey; } - else { - $checkID = is_numeric($intIDNum); + + + /** + * + * -Selector Method- + * + * intIDNum: The primary key used to identify the needed table row. Must be numeric unless $numericIDOnly is set to false. + * + * This will set $arrObjInfo to the table row array returned by the select statement, with the column titles set as the array keys. + * Use the get_info method to get the values for the table row with the selected id number. + * + * Returns true when the table row is found + * Returns false when no table row is found + */ + public function select($intIDNum, $numericIDOnly = true) + { + global $sqlCache; + + $returnVal = false; + if (!$numericIDOnly) { + $intIDNum = $this->MySQL->real_escape_string($intIDNum); + $checkID = true; + } else { + $checkID = is_numeric($intIDNum); + } + + + if ($checkID) { + if (isset($sqlCache[$this->strTableName])) { + $cache2 = $sqlCache[$this->strTableName]; + if (isset($cache2[$intIDNum])) { + $this->arrObjInfo = $cache2[$intIDNum]; + $returnVal = true; + $this->intTableKeyValue = $intIDNum; + } + } else { + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName . " WHERE " . $this->strTableKey . " = '$intIDNum'"); + if ($result->num_rows > 0) { + $this->arrObjInfo = $result->fetch_assoc(); + $returnVal = true; + $this->intTableKeyValue = $intIDNum; + } + } + } + + + return $returnVal; } - - if($checkID) { - if ( isset($sqlCache[$this->strTableName]) ) { - $cache2 = $sqlCache[$this->strTableName]; - if ( isset($cache2[$intIDNum]) ) { - $this->arrObjInfo = $cache2[$intIDNum]; - $returnVal = true; - $this->intTableKeyValue = $intIDNum; + + /** + * Select by multiple arguments. + * + * Format argument array as array[columnName] = value + * + */ + + public function selectByMulti($arrWhats) + { + + $returnVal = false; + if (is_array($arrWhats)) { + + $arrSQL = array(); + foreach ($arrWhats as $columnName => $value) { + $arrSQL[] = $columnName . " = ?"; } - } else { - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName." WHERE ".$this->strTableKey." = '$intIDNum'"); - if($result->num_rows > 0) { - $this->arrObjInfo = $result->fetch_assoc(); - $returnVal = true; - $this->intTableKeyValue = $intIDNum; + + $setSQL = implode(" AND ", $arrSQL); + + $query = "SELECT " . $this->strTableKey . " FROM " . $this->strTableName . " WHERE " . $setSQL; + + $stmt = $this->MySQL->prepare($query); + $returnID = ""; + + if ($stmt) { + + $this->MySQL->bindParams($stmt, $arrWhats); + $stmt->execute(); + $stmt->bind_result($result); + $stmt->fetch(); + $returnID = $result; + $stmt->close(); + + } + + + $returnVal = $this->select($returnID); + + } + + return $returnVal; } - - return $returnVal; - } - - - /** - * Select by multiple arguments. - * - * Format argument array as array[columnName] = value - * - */ - - public function selectByMulti($arrWhats) { - - $returnVal = false; - if(is_array($arrWhats)) { - - $arrSQL = array(); - foreach($arrWhats as $columnName => $value) { - $arrSQL[] = $columnName." = ?"; + + /** + * Get multi rows, returns an array of get_info_filtered, + * + * Format filterArgs array as array[columnName] = value + * + */ + + public function get_entries($filterArgs = array(), $orderBy = "", $blnNotFiltered = true, $filterComparators = array()) + { + + $returnVal = false; + $returnArr = array(); + $arrSelect = array(); + $selectBackID = ""; + + if ($this->intTableKeyValue != "") { + $selectBackID = $this->intTableKeyValue; } - - $setSQL = implode(" AND ", $arrSQL); - $query = "SELECT ".$this->strTableKey." FROM ".$this->strTableName." WHERE ".$setSQL; + $setSQL = ""; + if (count($filterArgs) > 0) { + + $arrSQL = array(); + foreach ($filterArgs as $columnName => $value) { + + $setComparator = isset($filterComparators[$columnName]) ? $filterComparators[$columnName] : "="; + + $arrSQL[] = $columnName . " " . $setComparator . " ?"; + + } + + $setSQL = implode(" AND ", $arrSQL); + if ($setSQL != "") { + $setSQL = " WHERE " . $setSQL; + } + } + + if ($orderBy != "") { + $orderBy = "ORDER BY " . $orderBy; + } + + $query = "SELECT " . $this->strTableKey . " FROM " . $this->strTableName . $setSQL . " " . $orderBy; $stmt = $this->MySQL->prepare($query); $returnID = ""; - if($stmt) { - - $this->MySQL->bindParams($stmt, $arrWhats); + if ($stmt) { + + if (count($filterArgs) > 0) { + $this->MySQL->bindParams($stmt, $filterArgs); + } + $stmt->execute(); $stmt->bind_result($result); - $stmt->fetch(); - $returnID = $result; + + while ($stmt->fetch()) { + + $arrSelect[] = $result; + + } + $stmt->close(); - } - - - - $returnVal = $this->select($returnID); - - - } - - return $returnVal; - } - - - /** - * Get multi rows, returns an array of get_info_filtered, - * - * Format filterArgs array as array[columnName] = value - * - */ - - public function get_entries($filterArgs=array(), $orderBy="", $blnNotFiltered=true, $filterComparators=array()) { - - $returnVal = false; - $returnArr = array(); - $arrSelect = array(); - $selectBackID = ""; - - if($this->intTableKeyValue != "") { - $selectBackID = $this->intTableKeyValue; - } - - $setSQL = ""; - if(count($filterArgs) > 0) { - - $arrSQL = array(); - foreach($filterArgs as $columnName => $value) { - - $setComparator = isset($filterComparators[$columnName]) ? $filterComparators[$columnName] : "="; - - $arrSQL[] = $columnName." ".$setComparator." ?"; - + foreach ($arrSelect as $selectKey) { + $this->select($selectKey); + $returnArr[] = $blnNotFiltered ? $this->get_info_filtered() : $this->get_info(); } - - $setSQL = implode(" AND ", $arrSQL); - - if($setSQL != "") { - $setSQL = " WHERE ".$setSQL; + + + if ($selectBackID != "") { + $this->select($selectBackID); } + + return $returnArr; + } - - if($orderBy != "") { - $orderBy = "ORDER BY ".$orderBy; - } - - $query = "SELECT ".$this->strTableKey." FROM ".$this->strTableName.$setSQL." ".$orderBy; - $stmt = $this->MySQL->prepare($query); - $returnID = ""; - if($stmt) { - if(count($filterArgs) > 0) { - $this->MySQL->bindParams($stmt, $filterArgs); + /** + * + * -Easy way to send an INSERT statement- + * + * arrColumns: Array of the column names that will be inserted into + * arrValues: Array of values that will be inserted into the column names in arrColumns + * + * Both arrays must contain the same amount of values and must line up with each other in order insert the desired values. + * + * After the query is sent, it will assign the strTableKeyValue with the last insert id and will "select" it, using the select method. + * + * Returns true if INSERT query is successful + * Returns false if there is an error + */ + public function addNew($arrColumns, $arrValues) + { + $returnVal = false; + + if (is_array($arrColumns)) { + $sqlColumns = implode(",", $arrColumns); + $sqlValues = rtrim(str_repeat("?, ", count($arrColumns)), ", "); } - - $stmt->execute(); - $stmt->bind_result($result); - - while($stmt->fetch()) { - - $arrSelect[] = $result; - + + $stmt = $this->MySQL->prepare("INSERT INTO " . $this->strTableName . " (" . $sqlColumns . ") VALUES (" . $sqlValues . ")"); + + if (is_array($arrValues)) { + foreach ($arrValues as $key => $value) { + if ($value !== null) { + $temp = str_replace(">", ">", $value); + $value = str_replace("<", "<", $temp); + $temp = str_replace('"', '"', $value); + $value = str_replace("'", "'", $temp); + $temp = str_replace("&middot;", "·", $value); + $temp = str_replace("&raquo;", "»", $temp); + $temp = str_replace("&laquo;", "«", $value); + } else { + $temp = null; + } + $arrValues[$key] = $temp; + } + + $stmt = $this->MySQL->bindParams($stmt, $arrValues); } - - $stmt->close(); - } + if ($stmt->execute()) { + $this->select($stmt->insert_id); + $returnVal = true; + $this->updateTableTime(); + } else { + echo $this->MySQL->displayError("basic.php - addNew"); + } - foreach($arrSelect as $selectKey) { - $this->select($selectKey); - $returnArr[] = $blnNotFiltered ? $this->get_info_filtered() : $this->get_info(); - } - - - if($selectBackID != "") { - $this->select($selectBackID); - } - - return $returnArr; - - } - - - /** - - -Easy way to send an INSERT statement- - - arrColumns: Array of the column names that will be inserted into - arrValues: Array of values that will be inserted into the column names in arrColumns - - Both arrays must contain the same amount of values and must line up with each other in order insert the desired values. - - After the query is sent, it will assign the strTableKeyValue with the last insert id and will "select" it, using the select method. - - Returns true if INSERT query is successful - Returns false if there is an error - - */ - public function addNew($arrColumns, $arrValues) { - $returnVal = false; - - - - if(is_array($arrColumns)) { - $sqlColumns = implode(",", $arrColumns); - $sqlValues = rtrim(str_repeat("?, ", count($arrColumns)),", "); - + return $returnVal; } + /** + * + * -Easy way to send an UPDATE query- + * + * arrTableColumns: Array of the table column names that will be updated + * arrColumnValues: Array of the values to update each given table column + * + * Both arrays need to contain the same amount of values and must line up with each other in order to update the correct column + * + * Must first use the select method before updating + * + * Returns true if successfully updates + */ + public function update($arrTableColumns, $arrColumnValues) + { + + $returnVal = false; + if (is_array($arrTableColumns) and is_array($arrColumnValues) and $this->intTableKeyValue != null) { + + if (count($arrTableColumns) == count($arrColumnValues)) { + + $combinedArray = array_combine($arrTableColumns, $arrColumnValues); + + foreach ($combinedArray as $key => $value) { + $temp = str_replace(">", ">", $value); + $value = str_replace("<", "<", $temp); + $temp = str_replace('"', '"', $value); + $value = str_replace("'", "'", $temp); + $temp = str_replace("&middot;", "·", $value); + $value = str_replace("&raquo;", "»", $temp); + $temp = str_replace("&laquo;", "«", $value); + + $arrQuery[] = $key . " = ?"; + $arrValues[] = $temp; + } + + + $updateQuery = implode(", ", $arrQuery); + + $stmt = $this->MySQL->prepare("UPDATE " . $this->strTableName . " SET " . $updateQuery . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + + $stmt = $this->MySQL->bindParams($stmt, $arrValues); + + + if ($stmt->execute()) { + $this->select($this->intTableKeyValue); + $returnVal = true; + + $this->updateTableTime(); + + + } else { + $this->MySQL->displayError("basic.php - update"); + } + + } - $stmt = $this->MySQL->prepare("INSERT INTO ".$this->strTableName." (".$sqlColumns.") VALUES (".$sqlValues.")"); - - if(is_array($arrValues)) { - foreach($arrValues as $key=>$value) { - $temp = str_replace(">", ">", $value); - $value = str_replace("<", "<", $temp); - $temp = str_replace('"', '"', $value); - $value = str_replace("'", "'", $temp); - $temp = str_replace("&middot;", "·", $value); - $temp = str_replace("&raquo;", "»", $temp); - $temp = str_replace("&laquo;", "«", $temp); - - $arrValues[$key] = $temp; } - - - $stmt = $this->MySQL->bindParams($stmt, $arrValues); - - } - - - if($stmt->execute()) { - $this->select($stmt->insert_id); - $returnVal = true; - $this->updateTableTime(); - } - else { - echo $this->MySQL->displayError("basic.php - addNew"); + + return $returnVal; } - return $returnVal; - - } - - - /** - - -Easy way to send an UPDATE query- - - arrTableColumns: Array of the table column names that will be updated - arrColumnValues: Array of the values to update each given table column - - Both arrays need to contain the same amount of values and must line up with each other in order to update the correct column - - Must first use the select method before updating - - Returns true if successfully updates - - */ - public function update($arrTableColumns, $arrColumnValues) { - - $returnVal = false; - if(is_array($arrTableColumns) AND is_array($arrColumnValues) AND $this->intTableKeyValue != null) { - - if(count($arrTableColumns) == count($arrColumnValues)) { - - $combinedArray = array_combine($arrTableColumns, $arrColumnValues); - - foreach($combinedArray as $key=>$value) { - $temp = str_replace(">", ">", $value); - $value = str_replace("<", "<", $temp); - $temp = str_replace('"', '"', $value); - $value = str_replace("'", "'", $temp); - $temp = str_replace("&middot;", "·", $value); - $value = str_replace("&raquo;", "»", $temp); - $temp = str_replace("&laquo;", "«", $value); - - $arrQuery[] = $key." = ?"; - $arrValues[] = $temp; - } - - - - $updateQuery = implode(", ", $arrQuery); - - $stmt = $this->MySQL->prepare("UPDATE ".$this->strTableName." SET ".$updateQuery." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - - $stmt = $this->MySQL->bindParams($stmt, $arrValues); - - - if($stmt->execute()) { - $this->select($this->intTableKeyValue); + /** + * + * -Delete Method- + * + * Will delete the selected row from the database. You must first "select" a table row using the select method in order to delete. + */ + public function delete() + { + $returnVal = false; + if ($this->intTableKeyValue != "") { + $result = $this->MySQL->query("DELETE FROM " . $this->strTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + + if (!$this->MySQL->error) { $returnVal = true; - - $this->updateTableTime(); - - - - } - else { - $this->MySQL->displayError("basic.php - update"); + } else { + $this->MySQL->displayError("basic.php"); } - + + $this->MySQL->query("OPTIMIZE TABLE `" . $this->strTableName . "`"); + $this->updateTableTime(); } - + + return $returnVal; + } - - return $returnVal; - } - - /** - - -Delete Method- - - Will delete the selected row from the database. You must first "select" a table row using the select method in order to delete. - - */ - public function delete() { - $returnVal = false; - if($this->intTableKeyValue != "") { - $result = $this->MySQL->query("DELETE FROM ".$this->strTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - - if(!$this->MySQL->error) { - $returnVal = true; + + + // Getter and Setter Methods + + /** Use the get_info method to get the values for the table row with the selected id number. */ + public function get_info($returnSingleValue = "") + { + $returnVal = ""; + if ($returnSingleValue == "") { + $returnVal = $this->arrObjInfo; + } else { + + $returnVal = $this->arrObjInfo[$returnSingleValue] ?? ''; + } + + return $returnVal; + } + + public function get_info_filtered($returnSingleValue = "") + { + if (!$this->arrObjInfo) { + return $this->arrObjInfo; } - else { - $this->MySQL->displayError("basic.php"); + + $arrFilteredInfo = array(); + foreach ($this->arrObjInfo as $key => $value) { + $temp = str_replace("<", "<", $value); + $value = str_replace(">", ">", $temp); + $temp = str_replace("'", "'", $value); + $value = str_replace('"', '"', $temp); + $temp = str_replace("·", "&middot;", $value); + $temp = str_replace("»", "&raquo;", $temp); + $temp = str_replace("«", "&laquo;", $temp); + + $arrFilteredInfo[$key] = $temp; } - - $this->MySQL->query("OPTIMIZE TABLE `".$this->strTableName."`"); - $this->updateTableTime(); + + $returnVal = ""; + if ($returnSingleValue == "") { + $returnVal = $arrFilteredInfo; + } else { + $returnVal = $arrFilteredInfo[$returnSingleValue]; + } + + return $returnVal; } - - return $returnVal; - - } - - - // Getter and Setter Methods - - /** Use the get_info method to get the values for the table row with the selected id number. */ - public function get_info($returnSingleValue = "") { - $returnVal = ""; - if($returnSingleValue == "") { - $returnVal = $this->arrObjInfo; + + + public function set_tableName($tableName) + { + $this->strTableName = $tableName; } - else { - - $returnVal = $this->arrObjInfo[$returnSingleValue] ?? ''; + + public function set_tableKey($tableKey) + { + $this->strTableKey = $tableKey; } - - return $returnVal; - } - - public function get_info_filtered($returnSingleValue = "") { - if ( ! $this->arrObjInfo ) { - return $this->arrObjInfo; + + public function get_tableKey() + { + return $this->strTableKey; } - - $arrFilteredInfo = array(); - foreach($this->arrObjInfo as $key => $value) { - $temp = str_replace("<", "<", $value); - $value = str_replace(">", ">", $temp); - $temp = str_replace("'", "'", $value); - $value = str_replace('"', '"', $temp); - $temp = str_replace("·", "&middot;", $value); - $temp = str_replace("»", "&raquo;", $temp); - $temp = str_replace("«", "&laquo;", $temp); - - $arrFilteredInfo[$key] = $temp; + + public function set_tablePrefix($tablePrefix) + { + $this->strTablePrefix = $tablePrefix; } - - $returnVal = ""; - if($returnSingleValue == "") { - $returnVal = $arrFilteredInfo; + + public function get_tablePrefix() + { + return $this->strTablePrefix; } - else { - $returnVal = $arrFilteredInfo[$returnSingleValue]; + + public function get_keyvalue() + { + return $this->intTableKeyValue; } - - return $returnVal; - } - - - public function set_tableName($tableName) { - $this->strTableName = $tableName; - } - - public function set_tableKey($tableKey) { - $this->strTableKey = $tableKey; - } - - public function get_tableKey() { - return $this->strTableKey; - } - - public function set_tablePrefix($tablePrefix) { - $this->strTablePrefix = $tablePrefix; - } - - public function get_tablePrefix() { - return $this->strTablePrefix; - } - - public function get_keyvalue() { - return $this->intTableKeyValue; - } - - public function get_MySQL() { - return $this->MySQL; - } - - public function updateTableTime() { - - $result = $this->MySQL->query("SELECT tablename FROM ".$this->MySQL->get_tablePrefix()."tableupdates WHERE tablename = '".$this->strTableName."'"); - if($result->num_rows > 0) { - $this->MySQL->query("UPDATE ".$this->MySQL->get_tablePrefix()."tableupdates SET updatetime = '".time()."' WHERE tablename = '".$this->strTableName."'"); + + public function get_MySQL() + { + return $this->MySQL; } - else { - $this->MySQL->query("INSERT INTO ".$this->MySQL->get_tablePrefix()."tableupdates (tablename, updatetime) VALUES ('".$this->strTableName."', '".time()."')"); + + public function updateTableTime() + { + + $result = $this->MySQL->query("SELECT tablename FROM " . $this->MySQL->get_tablePrefix() . "tableupdates WHERE tablename = '" . $this->strTableName . "'"); + if ($result->num_rows > 0) { + $this->MySQL->query("UPDATE " . $this->MySQL->get_tablePrefix() . "tableupdates SET updatetime = '" . time() . "' WHERE tablename = '" . $this->strTableName . "'"); + } else { + $this->MySQL->query("INSERT INTO " . $this->MySQL->get_tablePrefix() . "tableupdates (tablename, updatetime) VALUES ('" . $this->strTableName . "', '" . time() . "')"); + } + } - - } -} \ No newline at end of file + } diff --git a/src/classes/basicorder.php b/src/classes/basicorder.php index 7991851e..1f24fc2f 100644 --- a/src/classes/basicorder.php +++ b/src/classes/basicorder.php @@ -1,433 +1,405 @@ MySQL = $sqlConnection; - $this->strTableName = $this->MySQL->get_tablePrefix().$tableName; - $this->strTableKey = $tableKey; - } - - - /** - * - selectByOrder Method - - * - * Way to select a rank by ordernum. Essentially the same as the normal select method from basic except using the ordernum. + /* + * BlueThrust Clan Scripts + * Copyright 2014 * - * intOrderNum: The number order for the needed rank. + * Author: Bluethrust Web Development + * E-mail: support@bluethrust.com + * Website: http://www.bluethrust.com * - * Returns true when the table row is found. - * Returns false when the table row is not found. + * License: http://www.bluethrust.com/license.php * */ - function selectByOrder($intOrderNum) { - - $returnVal = false; - if(is_numeric($intOrderNum)) { - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName." WHERE ordernum = '".$intOrderNum."'"); - if($result->num_rows > 0) { - $this->arrObjInfo = $result->fetch_assoc(); - $returnVal = true; - $this->intTableKeyValue = $this->arrObjInfo[$this->strTableKey]; - $returnVal = true; + + require_once("basic.php"); + + class BasicOrder extends Basic + { + + protected $strAssociateTableName; // See the getAssociateIDs function for an explaination of "Associates" + protected $strAssociateKeyName; + + + public function __construct($sqlConnection, $tableName, $tableKey) + { + $this->MySQL = $sqlConnection; + $this->strTableName = $this->MySQL->get_tablePrefix() . $tableName; + $this->strTableKey = $tableKey; + } + + + /** + * - selectByOrder Method - + * + * Way to select a rank by ordernum. Essentially the same as the normal select method from basic except using the ordernum. + * + * intOrderNum: The number order for the needed rank. + * + * Returns true when the table row is found. + * Returns false when the table row is not found. + * + */ + function selectByOrder($intOrderNum) + { + + $returnVal = false; + if (is_numeric($intOrderNum)) { + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName . " WHERE ordernum = '" . $intOrderNum . "'"); + if ($result->num_rows > 0) { + $this->arrObjInfo = $result->fetch_assoc(); + $returnVal = true; + $this->intTableKeyValue = $this->arrObjInfo[$this->strTableKey]; + $returnVal = true; + } } - - + + return $returnVal; } - - return $returnVal; - - } - - - /** - * - getHighestOrder Function - - * - * Returns the highest ordernum in the rank table - * - */ - function getHighestOrderNum() { - $result = $this->MySQL->query("SELECT MAX(ordernum) FROM ".$this->strTableName); - $row = $result->fetch_assoc(); - - return $row['MAX(ordernum)']; - } - - - /** - * - makeRoom Method - - * - * Method to re-sort rank order numbers just before adding a new rank. You must first select a rank before using - * this method. - * - * Takes in either before and after and will set a spot for the new rank to be added before or after the rank that - * is currently selected. It will then return the new order number for the new rank. - * - * strBeforeAfter: String of either "before" or "after" - * - * Returns the ordernum for the new rank on success or "false" on error - * - */ - function makeRoom($strBeforeAfter) { - - $intRankID = $this->intTableKeyValue; - if($intRankID != null) { - - $intNewRankOrderNum = 0; - $arrRanks = array(); - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName." ORDER BY ordernum"); - $x = 1; - while($row = $result->fetch_assoc()) { - - if($row[$this->strTableKey] == $intRankID) { - - if($strBeforeAfter == "after") { - $intNewRankOrderNum = $x; - $x++; - $arrRanks[$x] = $row[$this->strTableKey]; - $x++; - } - elseif($strBeforeAfter == "before") { + + + /** + * - getHighestOrder Function - + * + * Returns the highest ordernum in the rank table + * + */ + function getHighestOrderNum() + { + $result = $this->MySQL->query("SELECT MAX(ordernum) FROM " . $this->strTableName); + $row = $result->fetch_assoc(); + + return $row['MAX(ordernum)']; + } + + + /** + * - makeRoom Method - + * + * Method to re-sort rank order numbers just before adding a new rank. You must first select a rank before using + * this method. + * + * Takes in either before and after and will set a spot for the new rank to be added before or after the rank that + * is currently selected. It will then return the new order number for the new rank. + * + * strBeforeAfter: String of either "before" or "after" + * + * Returns the ordernum for the new rank on success or "false" on error + * + */ + function makeRoom($strBeforeAfter) + { + + $intRankID = $this->intTableKeyValue; + if ($intRankID != null) { + + $intNewRankOrderNum = 0; + $arrRanks = array(); + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName . " ORDER BY ordernum"); + $x = 1; + while ($row = $result->fetch_assoc()) { + + if ($row[$this->strTableKey] == $intRankID) { + + if ($strBeforeAfter == "after") { + $intNewRankOrderNum = $x; + $x++; + $arrRanks[$x] = $row[$this->strTableKey]; + $x++; + } elseif ($strBeforeAfter == "before") { + $arrRanks[$x] = $row[$this->strTableKey]; + $x++; + $intNewRankOrderNum = $x; + $x++; + } + } else { $arrRanks[$x] = $row[$this->strTableKey]; $x++; - $intNewRankOrderNum = $x; - $x++; } - } - else { - $arrRanks[$x] = $row[$this->strTableKey]; - $x++; + + + if ($intNewRankOrderNum == 0) { + // intNewRank should not equal 0 after the above loop. + // The test will be if a numeric value is returned, so if it returns this string, something went wrong. + $intNewRankOrderNum = "false"; } - } - - - if($intNewRankOrderNum == 0) { - // intNewRank should not equal 0 after the above loop. - // The test will be if a numeric value is returned, so if it returns this string, something went wrong. - $intNewRankOrderNum = "false"; - } - - - if(is_numeric($intNewRankOrderNum)) { - - $intOriginalRank = $this->intTableKeyValue; - - foreach($arrRanks as $key => $value) { - - $arrColumns[0] = "ordernum"; - $arrValues[0] = $key; - - $this->select($value); - $this->update($arrColumns, $arrValues); - + + + if (is_numeric($intNewRankOrderNum)) { + + $intOriginalRank = $this->intTableKeyValue; + + foreach ($arrRanks as $key => $value) { + + $arrColumns[0] = "ordernum"; + $arrValues[0] = $key; + + $this->select($value); + $this->update($arrColumns, $arrValues); + } + + $this->select($intOriginalRank); } - - $this->select($intOriginalRank); - - } - - return $intNewRankOrderNum; - } - - - } - - /** - * - validateOrder Method - - * - * Helper method to check if a selected order is valid and "makesRoom" for new order. - * Used on pages that need to check if an ordernum that is being selected is valid. ex. Add New xxxxx Category - * - * ** Be Careful when using this Method --> It selects the rank with ID intOrderNumID - * ** Make sure to re-select the rank you have selected originally after using. - * - * Returns a number to be used for ordernum - * - */ - function validateOrder($intOrderNumID, $strBeforeAfter, $blnEdit = false, $intEditOrderNum = "") { - - $returnVal = false; - - if($intOrderNumID == "first") { - // "(no other categories)" selected, check to see if there are actually no other categories - - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName); - $num_rows = $result->num_rows; - - - if($num_rows == 0 || ($num_rows == 1 && $blnEdit)) { - - $returnVal = 1; + + return $intNewRankOrderNum; } - } - elseif($this->select($intOrderNumID) && ($strBeforeAfter == "before" || $strBeforeAfter == "after")) { - - - // Check first to see if we are editing or adding a new rank - - if($blnEdit) { - - // Editing... - // Check to see if the rank's order is being changed or if its staying the same - - - $addTo = 1; // Add 1 if we chose "before" - if($strBeforeAfter == "after") { - $addTo = -1; // Minus 1 if we chose "after" + + /** + * - validateOrder Method - + * + * Helper method to check if a selected order is valid and "makesRoom" for new order. + * Used on pages that need to check if an ordernum that is being selected is valid. ex. Add New xxxxx Category + * + * ** Be Careful when using this Method --> It selects the rank with ID intOrderNumID + * ** Make sure to re-select the rank you have selected originally after using. + * + * Returns a number to be used for ordernum + * + */ + function validateOrder($intOrderNumID, $strBeforeAfter, $blnEdit = false, $intEditOrderNum = "") + { + $returnVal = false; + + // Convert $intEditOrderNum to an integer if it's not empty + $intEditOrderNum = ($intEditOrderNum !== "") ? (int)$intEditOrderNum : 0; + + if ($intOrderNumID == "first") { + // "(no other categories)" selected, check to see if there are actually no other categories + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName); + $num_rows = $result->num_rows; + + if ($num_rows == 0 || ($num_rows == 1 && $blnEdit)) { + $returnVal = 1; } - - // Get the ordernum of the rank that we are using to determine the order of the rank being edited (*** It was selected in the IF statement above ***) - $thisCatOrderNum = $this->get_info("ordernum"); - - $checkOrderNum = $intEditOrderNum+$addTo; // This is the new ordernum of the rank we are editing - - // If checkOrderNum is the same as intEditOrderNum then the order hasn't changed - if($checkOrderNum != $intEditOrderNum) { + } elseif (is_numeric($intOrderNumID) && $this->select((int)$intOrderNumID) && ($strBeforeAfter == "before" || $strBeforeAfter == "after")) { + // Check first to see if we are editing or adding a new rank + if ($blnEdit) { + // Editing... + $addTo = ($strBeforeAfter == "after") ? -1 : 1; + $thisCatOrderNum = $this->get_info("ordernum"); + + // Ensure $thisCatOrderNum is an integer + $thisCatOrderNum = is_numeric($thisCatOrderNum) ? (int)$thisCatOrderNum : 0; + + $checkOrderNum = $intEditOrderNum + $addTo; + // If checkOrderNum is the same as intEditOrderNum then the order hasn't changed + if ($checkOrderNum != $intEditOrderNum) { + $returnVal = $this->makeRoom($strBeforeAfter); + } else { + $returnVal = $intEditOrderNum; + } + } else { + // Adding new... $returnVal = $this->makeRoom($strBeforeAfter); } - else { - $returnVal= $intEditOrderNum; - } - - } - else { - - $returnVal = $this->makeRoom($strBeforeAfter); - + + return $returnVal; + }1 + + + /** + * - resortOrder Method - + * + * Mainly used on the edit rank page and after makeRoom is used. + * This method re-sorts the rank table so that there are no spaces in between the ordernums. + * + * Ex. After makeRoom is called, the ordernums might be 1,2,4,5,6. + * This will re-sort the rank table so the ordernums go 1,2,3,4,5 + * + * + */ + function resortOrder() + { + + $counter = 1; // ordernum counter + $x = 0; // array counter + $arrUpdateID = array(); + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName . " ORDER BY ordernum"); + if ($result) { + while ($row = $result->fetch_assoc()) { + $arrUpdateID[] = $row[$this->strTableKey]; + $x++; + } + + $intOriginalRank = $this->intTableKeyValue; + foreach ($arrUpdateID as $intUpdateID) { + $arrUpdateCol[0] = "ordernum"; + $arrUpdateVal[0] = $counter; + $this->select($intUpdateID); + $this->update($arrUpdateCol, $arrUpdateVal); + $counter++; + } + + $this->select($intOriginalRank); } - + + return true; } - - return $returnVal; - } - - /** - * - resortOrder Method - - * - * Mainly used on the edit rank page and after makeRoom is used. - * This method re-sorts the rank table so that there are no spaces in between the ordernums. - * - * Ex. After makeRoom is called, the ordernums might be 1,2,4,5,6. - * This will re-sort the rank table so the ordernums go 1,2,3,4,5 - * - * - */ - function resortOrder() { - - $counter = 1; // ordernum counter - $x = 0; // array counter - $arrUpdateID = array(); - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName." ORDER BY ordernum"); - if($result) { - while($row = $result->fetch_assoc()) { - $arrUpdateID[] = $row[$this->strTableKey]; - $x++; - } - - $intOriginalRank = $this->intTableKeyValue; - foreach($arrUpdateID as $intUpdateID) { - $arrUpdateCol[0] = "ordernum"; - $arrUpdateVal[0] = $counter; - $this->select($intUpdateID); - $this->update($arrUpdateCol, $arrUpdateVal); - $counter++; + + + /** + * - Move Method - + * + * Easy way to move a rank either up or down 1 spot. Used mainly on the manage page. + * + * + * Returns true on successful move + * Returns false when no move is made + * + */ + function move($strDir) + { + + + $returnVal = false; + + if ($this->intTableKeyValue != "" and ($strDir == "up" or $strDir == "down")) { + $intOriginalRank = $this->intTableKeyValue; + $intOrderNum = $this->arrObjInfo['ordernum']; + + $moveUp = $intOrderNum + 1; + $moveDown = $intOrderNum - 1; + + $makeMove = ""; + + if ($strDir == "up" and $this->selectByOrder($moveUp)) { + $makeMove = "before"; + } elseif ($strDir == "down" and $this->selectByOrder($moveDown)) { + $makeMove = "after"; + } + + + if ($makeMove != "") { + $newSpot = $this->makeRoom($makeMove); + + if (is_numeric($newSpot)) { + $this->select($intOriginalRank); + $this->update(array("ordernum"), array($newSpot)); + $returnVal = true; + } + + $this->resortOrder(); + } } - - $this->select($intOriginalRank); + + + return $returnVal; } - - return true; - } - - - /** - * - Move Method - - * - * Easy way to move a rank either up or down 1 spot. Used mainly on the manage page. - * - * - * Returns true on successful move - * Returns false when no move is made - * - */ - function move($strDir) { - - - $returnVal = false; - - if($this->intTableKeyValue != "" AND ($strDir == "up" OR $strDir == "down")) { - $intOriginalRank = $this->intTableKeyValue; - $intOrderNum = $this->arrObjInfo['ordernum']; - - $moveUp = $intOrderNum+1; - $moveDown = $intOrderNum-1; - - $makeMove = ""; - - if($strDir == "up" AND $this->selectByOrder($moveUp)) { - $makeMove = "before"; - } - elseif($strDir == "down" AND $this->selectByOrder($moveDown)) { - $makeMove = "after"; - } - - - if($makeMove != "") { - $newSpot = $this->makeRoom($makeMove); - - if(is_numeric($newSpot)) { - $this->select($intOriginalRank); - $this->update(array("ordernum"), array($newSpot)); - $returnVal = true; + + + /** + * - findBeforeAfter Function - + * + * Easy way to find the ordernum of the rank either before or after. Finds the id of the rank before the selected rank, + * unless its the last rank, which it will return the rank which it is after. + * + * Returns an array with 2 items, [0] equals the rank id, [1] equals before, after or first (if no other ranks) + * + */ + function findBeforeAfter() + { + $returnArr = ""; + if ($this->intTableKeyValue != "") { + $intHighestOrderNum = $this->getHighestOrderNum(); + $intOriginalRank = $this->intTableKeyValue; + + $strBeforeAfter = "before"; + $intNextOrderID = 0; + $addTo = -1; + + + if ($this->arrObjInfo['ordernum'] == 1 && $intHighestOrderNum != 1) { + $strBeforeAfter = "after"; + $addTo = 1; + } elseif ($intHighestOrderNum == 1) { + $strBeforeAfter = "first"; } - - $this->resortOrder(); + + $checkNextOrder = $this->arrObjInfo['ordernum'] + $addTo; + + if ($this->selectByOrder($checkNextOrder)) { + $intNextOrderID = $this->arrObjInfo[$this->strTableKey]; + } + + $returnArr = array($intNextOrderID, $strBeforeAfter); } + return $returnArr; } - - - return $returnVal; - - } - - - - /** - * - findBeforeAfter Function - - * - * Easy way to find the ordernum of the rank either before or after. Finds the id of the rank before the selected rank, - * unless its the last rank, which it will return the rank which it is after. - * - * Returns an array with 2 items, [0] equals the rank id, [1] equals before, after or first (if no other ranks) - * - */ - function findBeforeAfter() { - $returnArr = ""; - if($this->intTableKeyValue != "") { - $intHighestOrderNum = $this->getHighestOrderNum(); - $intOriginalRank = $this->intTableKeyValue; - - $strBeforeAfter = "before"; - $intNextOrderID = 0; - $addTo = -1; - - - if($this->arrObjInfo['ordernum'] == 1 && $intHighestOrderNum != 1) { - $strBeforeAfter = "after"; - $addTo = 1; - } - elseif($intHighestOrderNum == 1) { - $strBeforeAfter = "first"; + + + /** + * - getAssociateIDs Function - + * + * I was unsure of the best way to name what I am calling "Associates" to the rank class and the ones that extend it. The only way I can + * think of explaining it is to give examples. + * + * EX1. Members is the associate to Ranks because 1 member can only have 1 rank, but many members can have the same 1 rank. + * EX2. Ranks is the associate to Rank Category because any one particular Rank can only have 1 Rank Cateogry, where as a Rank Category can contain many Ranks. + * + * If you can understand what my thought process is from the above examples, then hopefully you can figure out good ways to use this function + * if you want to modify the scripts. + * + * + * Returns an array of IDs for the associated table + * + */ + function getAssociateIDs($sqlOrderBY = "", $bypassFilter = false) + { + + $arrReturn = array(); + if (!$bypassFilter) { + $sqlOrderBY = $this->MySQL->real_escape_string($sqlOrderBY); } - - $checkNextOrder = $this->arrObjInfo['ordernum']+$addTo; - - if($this->selectByOrder($checkNextOrder)) { - $intNextOrderID = $this->arrObjInfo[$this->strTableKey]; + + if ($this->intTableKeyValue != "") { + $result = $this->MySQL->query("SELECT * FROM " . $this->strAssociateTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "' " . $sqlOrderBY); + while ($row = $result->fetch_assoc()) { + $arrReturn[] = $row[$this->strAssociateKeyName]; + } } - - $returnArr = array($intNextOrderID, $strBeforeAfter); - - + + return $arrReturn; } - return $returnArr; - } - - - /** - * - getAssociateIDs Function - - * - * I was unsure of the best way to name what I am calling "Associates" to the rank class and the ones that extend it. The only way I can - * think of explaining it is to give examples. - * - * EX1. Members is the associate to Ranks because 1 member can only have 1 rank, but many members can have the same 1 rank. - * EX2. Ranks is the associate to Rank Category because any one particular Rank can only have 1 Rank Cateogry, where as a Rank Category can contain many Ranks. - * - * If you can understand what my thought process is from the above examples, then hopefully you can figure out good ways to use this function - * if you want to modify the scripts. - * - * - * Returns an array of IDs for the associated table - * - */ - function getAssociateIDs($sqlOrderBY = "", $bypassFilter=false) { - - $arrReturn = array(); - if(!$bypassFilter) { - $sqlOrderBY = $this->MySQL->real_escape_string($sqlOrderBY); + + function set_assocTableName($tableName) + { + $this->strAssociateTableName = $this->MySQL->get_tablePrefix() . $tableName; } - - if($this->intTableKeyValue != "") { - $result = $this->MySQL->query("SELECT * FROM ".$this->strAssociateTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."' ".$sqlOrderBY); - while($row = $result->fetch_assoc()) { - $arrReturn[] = $row[$this->strAssociateKeyName]; - } + + function set_assocTableKey($tableKey) + { + $this->strAssociateKeyName = $tableKey; } - - return $arrReturn; - - } - - function set_assocTableName($tableName) { - $this->strAssociateTableName = $this->MySQL->get_tablePrefix().$tableName; - } - - function set_assocTableKey($tableKey) { - $this->strAssociateKeyName = $tableKey; - } - - - - function delete() { - - $returnVal = false; - if($this->intTableKeyValue != "") { - - $blnDelete1 = $this->MySQL->query("DELETE FROM ".$this->strTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - - if($this->strAssociateTableName != "") { - $blnDelete2 = $this->MySQL->query("DELETE FROM ".$this->strAssociateTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - $this->MySQL->query("OPTIMIZE TABLE `".$this->strAssociateTableName."`"); - } - else { - $blnDelete2 = true; - } - - if($blnDelete1 && $blnDelete2) { - $returnVal = true; + + function delete() + { + + $returnVal = false; + if ($this->intTableKeyValue != "") { + + $blnDelete1 = $this->MySQL->query("DELETE FROM " . $this->strTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + + if ($this->strAssociateTableName != "") { + $blnDelete2 = $this->MySQL->query("DELETE FROM " . $this->strAssociateTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + $this->MySQL->query("OPTIMIZE TABLE `" . $this->strAssociateTableName . "`"); + } else { + $blnDelete2 = true; + } + + if ($blnDelete1 && $blnDelete2) { + $returnVal = true; + } + + $this->resortOrder(); + + $this->MySQL->query("OPTIMIZE TABLE `" . $this->strTableName . "`"); } - - $this->resortOrder(); - - $this->MySQL->query("OPTIMIZE TABLE `".$this->strTableName."`"); - - } - - return $returnVal; - } - -} \ No newline at end of file + return $returnVal; + } + } diff --git a/src/classes/btbbcode.php b/src/classes/btbbcode.php index 383bd23e..b361253a 100644 --- a/src/classes/btbbcode.php +++ b/src/classes/btbbcode.php @@ -1,80 +1,83 @@ "[b]", "bbCloseTag" = > "[/b]", "htmlOpenTag" => "", "htmlCloseTag" => "", "type" => "simple") - * - * - Populate $arrBBCodes with multiple arrays like the one above with different bb codes. - * - Do btBBCodeParse->parse($string) to retrieve the output - * - 2 different types, simple and complex. If you set the type to complex, you should also set the arguments total - * - * - * ****I saw there was a BBCode parser on php.net both with PECL and PEAR, but I wanted a standalone one for - * in case users did not have the ability to use the packages. - * - * - */ -class btBBCode { - - - protected $arrBBCodes; - - public function __construct($bbCodeArray=array()) { - // Quick way to add bb codes - $this->arrBBCodes = $bbCodeArray; - } - - public function addBBCode($newBBCode) { - - $arrCheckKeys = array_keys($newBBCode); - - if(in_array("bbOpenTag", $arrCheckKeys) && in_array("bbCloseTag", $arrCheckKeys) && in_array("htmlOpenTag", $arrCheckKeys) && in_array("htmlCloseTag", $arrCheckKeys)) { - - $this->arrBBCodes[] = $newBBCode; - + + /* + * BBCodeParser + * + * Author: Leo Rojas + * E-mail: leorojas22@gmail.com + * / + + + /** + * Simple BB Code Parser + * + * + * Format BBCodes in this way: + * + * array("bbOpenTag" => "[b]", "bbCloseTag" = > "[/b]", "htmlOpenTag" => "", "htmlCloseTag" => "", "type" => "simple") + * + * - Populate $arrBBCodes with multiple arrays like the one above with different bb codes. + * - Do btBBCodeParse->parse($string) to retrieve the output + * - 2 different types, simple and complex. If you set the type to complex, you should also set the arguments total + * + * + * ****I saw there was a BBCode parser on php.net both with PECL and PEAR, but I wanted a standalone one for + * in case users did not have the ability to use the packages. + * + * + */ + + class btBBCode + { + + + protected $arrBBCodes; + + public function __construct($bbCodeArray = array()) + { + // Quick way to add bb codes + $this->arrBBCodes = $bbCodeArray; } - - } - - public function parse($strText) { - - foreach($this->arrBBCodes as $bbCodes) { - - if($bbCodes['type'] == "simple") { - - $strText = str_replace($bbCodes['bbOpenTag'],$bbCodes['htmlOpenTag'],$strText); - $strText = str_replace($bbCodes['bbCloseTag'],$bbCodes['htmlCloseTag'],$strText); + + public function addBBCode($newBBCode) + { + + $arrCheckKeys = array_keys($newBBCode); + + if (in_array("bbOpenTag", $arrCheckKeys) && in_array("bbCloseTag", $arrCheckKeys) && in_array("htmlOpenTag", $arrCheckKeys) && in_array("htmlCloseTag", $arrCheckKeys)) { + + $this->arrBBCodes[] = $newBBCode; + } - else { - $strText = preg_replace( + + } + + public function parse($strText) + { + + foreach ($this->arrBBCodes as $bbCodes) { + + if ($bbCodes['type'] == "simple") { + + $strText = str_replace($bbCodes['bbOpenTag'], $bbCodes['htmlOpenTag'], $strText); + $strText = str_replace($bbCodes['bbCloseTag'], $bbCodes['htmlCloseTag'], $strText); + } else { + //$strText = preg_replace( + + } } - + } - - } - - - -} + } + // Default BB Codes -$arrBold = array("bbOpenTag" => "[b]", "bbCloseTag" => "[/b]", "htmlOpenTag" => "", "htmlCloseTag" => ""); -$arrItalic = array("bbOpenTag" => "[i]", "bbCloseTag" => "[/i]", "htmlOpenTag" => "", "htmlCloseTag" => ""); -$arrUnderline = array("bbOpenTag" => "[u]", "bbCloseTag" => "[/u]", "htmlOpenTag" => "", "htmlCloseTag" => ""); + $arrBold = array("bbOpenTag" => "[b]", "bbCloseTag" => "[/b]", "htmlOpenTag" => "", "htmlCloseTag" => ""); + $arrItalic = array("bbOpenTag" => "[i]", "bbCloseTag" => "[/i]", "htmlOpenTag" => "", "htmlCloseTag" => ""); + $arrUnderline = array("bbOpenTag" => "[u]", "bbCloseTag" => "[/u]", "htmlOpenTag" => "", "htmlCloseTag" => ""); -$arrLink = array("bbOpenTag" => "[url]", "bbCloseTag" => "[/url]", "htmlOpenTag" => " ""); diff --git a/src/classes/btmysql.php b/src/classes/btmysql.php index 82f37287..cae3d019 100644 --- a/src/classes/btmysql.php +++ b/src/classes/btmysql.php @@ -1,135 +1,142 @@ $query, + 'stack_trace' => debug_string_backtrace(), + 'duration' => $diff, + ]; + } + return $result; } - $result = parent::query($query, $resultmode); - if ( $debug) { - $end = microtime(true); - $diff = round($end - $start, 3); - $SQL_PROFILER[] = [ - 'query' => $query, - 'stack_trace' => debug_string_backtrace(), - 'duration' => $diff, - ]; + + public function __construct($host, $username, $passwd, $dbname = "", $port = null, $socket = null) + { + + $host = !isset($host) ? ini_get("mysqli.default_host") : $host; + $username = !isset($username) ? ini_get("mysqli.default_user") : $username; + $passwd = !isset($passwd) ? ini_get("mysqli.default_pw") : $passwd; + $port = !isset($port) ? ini_get("mysqli.default_port") : $port; + $socket = !isset($socket) ? ini_get("mysqli.default_socket") : $socket; + + parent::__construct($host, $username, $passwd, $dbname, $port, $socket); + + $this->query("SET SESSION sql_mode = ''"); + + } - return $result; - } - - public function __construct($host, $username, $passwd, $dbname = "", $port=null, $socket=null) { - - $host = !isset($host) ? ini_get("mysqli.default_host") : $host; - $username = !isset($username) ? ini_get("mysqli.default_user") : $username; - $passwd = !isset($passwd) ? ini_get("mysqli.default_pw") : $passwd; - $port = !isset($port) ? ini_get("mysqli.default_port") : $port; - $socket = !isset($socket) ? ini_get("mysqli.default_socket") : $socket; - - parent::__construct($host, $username, $passwd, $dbname, $port, $socket); - - $this->query("SET SESSION sql_mode = ''"); - - - } - - - public function set_tablePrefix($tablePrefix) { - $this->bt_TablePrefix = $tablePrefix; - } - - public function get_tablePrefix() { - return $this->bt_TablePrefix; - } - - public function set_testingMode($testModeValue) { - $this->bt_TestingMode = $testModeValue; - } - - public function displayError($pageName="") { - if($this->bt_TestingMode) { - die($pageName." - ".$this->error); + + + public function set_tablePrefix($tablePrefix) + { + $this->bt_TablePrefix = $tablePrefix; } - } - - public function getParamTypes($arrValues) { - $strParamTypes = ""; - if(is_array($arrValues)) { - foreach($arrValues as $value) { - $valuetype = gettype($value); - switch($valuetype) { - case "integer": - $strParamTypes .= "i"; - break; - case "double": - $strParamTypes .= "d"; - break; - default: - $strParamTypes .= "s"; - } - - } + + public function get_tablePrefix() + { + return $this->bt_TablePrefix; } - return $strParamTypes; - } - - public function bindParams($objMySQLiStmt, $arrValues) { - $returnVal = false; - $strParamTypes = $this->getParamTypes($arrValues); - - $tmpParams = array_merge(array($strParamTypes), $arrValues); - $arrParams = array(); - foreach($tmpParams as $key=>$value) { - $arrParams[$key] = &$tmpParams[$key]; + + public function set_testingMode($testModeValue) + { + $this->bt_TestingMode = $testModeValue; } - - - if(!call_user_func_array(array($objMySQLiStmt, "bind_param"), $arrParams)) { - $returnVal = false; - echo $objMySQLiStmt->error; - echo "

"; - $this->displayError("btmysql.php - bindParams"); + + public function displayError($pageName = "") + { + if ($this->bt_TestingMode) { + die($pageName . " - " . $this->error); + } } - else { - $returnVal = $objMySQLiStmt; + + public function getParamTypes($arrValues) + { + $strParamTypes = ""; + if (is_array($arrValues)) { + foreach ($arrValues as $value) { + $valuetype = gettype($value); + switch ($valuetype) { + case "integer": + $strParamTypes .= "i"; + break; + case "double": + $strParamTypes .= "d"; + break; + default: + $strParamTypes .= "s"; + } + + } + } + return $strParamTypes; } - - - return $returnVal; - - } - - public function optimizeTables() { - $tables = array(); - $result = $this->query("SHOW TABLE STATUS WHERE Data_free > 0"); - while($row = $result->fetch_assoc()) { - $tables[] = "`".$row['Name']."`"; + + public function bindParams($objMySQLiStmt, $arrValues) + { + $returnVal = false; + $strParamTypes = $this->getParamTypes($arrValues); + + // Prepare the parameters for bind_param + $params = array($strParamTypes); + foreach ($arrValues as $key => $value) { + $params[] = &$arrValues[$key]; // Pass by reference + } + + if (!call_user_func_array(array($objMySQLiStmt, "bind_param"), $params)) { + $returnVal = false; + echo $objMySQLiStmt->error; + echo "

"; + $this->displayError("btmysql.php - bindParams"); + } else { + $returnVal = $objMySQLiStmt; + } + + return $returnVal; } - - $optimizeTables = implode(", ", $tables); - - if(count($tables) > 0) { - $this->query("OPTIMIZE TABLE ".$optimizeTables); + + + public function optimizeTables() + { + $tables = array(); + $result = $this->query("SHOW TABLE STATUS WHERE Data_free > 0"); + while ($row = $result->fetch_assoc()) { + $tables[] = "`" . $row['Name'] . "`"; + } + + $optimizeTables = implode(", ", $tables); + + if (count($tables) > 0) { + $this->query("OPTIMIZE TABLE " . $optimizeTables); + } + } - - } -} \ No newline at end of file + } diff --git a/src/classes/form.php b/src/classes/form.php index ab340f2b..c636910e 100644 --- a/src/classes/form.php +++ b/src/classes/form.php @@ -1,25 +1,26 @@ ", "
"); public $errors = array(); public $saveMessage; @@ -34,40 +35,42 @@ class Form { public $attachmentObj; private $arrDeleteFiles = array(); public $arrSkipPrefill = array(); - - + + private $richtextboxJSFile; private $colorpickerJSFile; - + /** * Components Array Example - * + * * $arr = array( - * 'display_name' => 'Username', - * 'type' => 'text', (text, textarea, select, checkbox, radio, button, submit, file, custom), - * 'tooltip' => 'tool tip text', - * 'value' => '' // you can also put value in the attributes array, but use here instead to pre-fill multi-select type inputs and textareas - * 'attributes' => array('name' => 'component_name', 'id' => 'component_id', 'style' => 'component_style', 'class=' => 'component_class'), - * 'sortorder' => 1, - * 'db_name' => 'column_name', - * 'html' => '' // Used only if the type is custom - * 'options' => array(value => display) // Used for checkboxes, radio buttons and select boxes, - * 'validate' => array("NOT_BLANK", "NUMBER_ONLY") - * + * 'display_name' => 'Username', + * 'type' => 'text', (text, textarea, select, checkbox, radio, button, submit, file, custom), + * 'tooltip' => 'tool tip text', + * 'value' => '' // you can also put value in the attributes array, but use here instead to pre-fill multi-select type inputs and textareas + * 'attributes' => array('name' => 'component_name', 'id' => 'component_id', 'style' => 'component_style', 'class=' => 'component_class'), + * 'sortorder' => 1, + * 'db_name' => 'column_name', + * 'html' => '' // Used only if the type is custom + * 'options' => array(value => display) // Used for checkboxes, radio buttons and select boxes, + * 'validate' => array("NOT_BLANK", "NUMBER_ONLY") + * * ); - * + * * $components = $arr; - * + * */ - public function __construct($args=array()) { - + public function __construct($args = array()) + { + $this->buildForm($args); - $this->richtextboxJSFile = ""; - $this->colorpickerJSFile = ""; + $this->richtextboxJSFile = ""; + $this->colorpickerJSFile = ""; } - - public function buildForm($args) { - + + public function buildForm($args) + { + $this->formName = $args['name'] ?? ''; $this->components = $args['components'] ?? ''; $this->objSave = $args['saveObject'] ?? ''; @@ -82,911 +85,900 @@ public function buildForm($args) { $this->embedJS = $args['embedJS'] ?? ''; $this->attachmentForm = false; $this->prefillValues = isset($args['prefillValues']) ? $args['prefillValues'] : false; - - if(isset($args['wrapper'])) { - $this->wrapper = $args['wrapper']; + + if (isset($args['wrapper'])) { + $this->wrapper = $args['wrapper']; } - - if(isset($args['beforeAfter'])) { - $this->beforeAfter = $args['beforeAfter']; + + if (isset($args['beforeAfter'])) { + $this->beforeAfter = $args['beforeAfter']; } - if(isset($args['mysql'])) { + if (isset($args['mysql'])) { $this->attachmentObj = new Download($args['mysql']); - $this->attachmentForm = true; + $this->attachmentForm = true; } - - - if($args['prefill'] ?? '') { + + + if ($args['prefill'] ?? '') { $this->arrSkipPrefill = $args['skipPrefill']; - $this->prefillDBValues(); + $this->prefillDBValues(); } - + } - + /** * - show Method - - * + * * Used to display the actual form - * + * */ - public function show() { + public function show() + { global $MAIN_ROOT, $hooksObj; - + $displayOptions = ''; - + $hooksObj->run($this->formName); - + uasort($this->components, array("Form", "sortForm")); - + $countRichTextbox = 0; - + $blnFileUploadForm = false; - + $displayForm = ""; $afterJS = $this->embedJS; - - foreach($this->components as $componentName => $componentInfo) { - + + foreach ($this->components as $componentName => $componentInfo) { + $dispAttributes = $this->convertAttributes($componentInfo['attributes'] ?? ''); - + $displayForm .= $componentInfo['before_html'] ?? ''; - + // Output Component Name - if(($componentInfo['display_name'] ?? '') != "") { + if (($componentInfo['display_name'] ?? '') != "") { $addValignComponents = array("file", "textarea", "beforeafter", "checkbox"); - $addVAlign = in_array($componentInfo['type'], $addValignComponents) ? " formVAlignTop" : ""; - $dispToolTip = (($componentInfo['tooltip'] ?? '') != "") ? " (?)" : ""; + $addVAlign = in_array($componentInfo['type'], $addValignComponents) ? " formVAlignTop" : ""; + $dispToolTip = (($componentInfo['tooltip'] ?? '') != "") ? " (?)" : ""; $displayForm .= " - + "; } - - // Output input - switch($componentInfo['type']) { + +// Output input + switch ($componentInfo['type']) { case "autocomplete": $afterJS .= $this->autocompleteJS($componentInfo['options']['list'], $componentInfo['options']['real_id'], $componentInfo['options']['fake_id']); - $fakeComponentName = "fake".$componentName; - $displayForm .= ""; + $fakeComponentName = "fake" . $componentName; + $fakeValue = isset($_POST[$fakeComponentName]) ? filterText($_POST[$fakeComponentName]) : ''; + $realValue = $componentInfo['value'] ?? ''; + $displayForm .= ""; break; case "textarea": - $displayForm .= ""; + $textareaValue = $componentInfo['value'] ?? ''; + $displayForm .= ""; break; case "richtextbox": $afterJS .= $this->richTextboxJS($componentInfo['attributes']['id'], $componentInfo['allowHTML'] ?? ''); + $richTextboxValue = $componentInfo['value'] ?? ''; $displayForm .= " -
- -
- "; +
+ +
+ "; $countRichTextbox++; unset($GLOBALS['richtextEditor']); break; case "codeeditor": $afterJS .= $this->codeEditorJS($componentInfo['attributes']['id']); $displayForm .= " -
".($componentInfo['value'] ?? '')."
- +
" . ($componentInfo['value'] ?? '') . "
+ "; break; case "datepicker": - + $datePick = new DateTime(); - $datePick->setTimestamp($componentInfo['value']/1000); + $datePick->setTimestamp($componentInfo['value'] / 1000); $datePick->setTimezone(new DateTimeZone("UTC")); - + $formatDatePick = $datePick->format("n-j-Y"); - + $afterJS .= $this->datepickerJS($componentInfo['attributes']['id'], $componentInfo['options']); - $displayForm .= ""; + $displayForm .= ""; break; case "timepicker": - + $arrTimezones = DateTimeZone::listIdentifiers(); - + $datePick = new DateTime(); - $datePick->setTimestamp($componentInfo['value']/1000); + $datePick->setTimestamp($componentInfo['value'] / 1000); $datePick->setTimezone(new DateTimeZone("UTC")); $selectedHour = $datePick->format("g"); $selectedMinute = $datePick->format("i"); $selectedAMPM = $datePick->format("A"); - - + + $selectPM = ($selectedAMPM == "PM") ? " selected" : ""; - + $displayForm .= "
- "; - - for($i=1; $i<12; $i++) { + + for ($i = 1; $i < 12; $i++) { $selected = ""; - if($selectedHour == $i) { + if ($selectedHour == $i) { $selected = " selected"; } - $displayForm .= ""; + $displayForm .= ""; } - + $displayForm .= " - "; - - for($i=0; $i<=59; $i++) { + + for ($i = 0; $i <= 59; $i++) { $selected = ""; - - $dispMinute = ($i<10) ? "0".$i : $i; - if($selectedMinute == $i) { + + $dispMinute = ($i < 10) ? "0" . $i : $i; + if ($selectedMinute == $i) { $selected = " selected"; } - $displayForm .= ""; + $displayForm .= ""; } - - + + $displayForm .= " - + - "; - - if($componentInfo['options']['show_timezone'] == 1) { + "; + + if ($componentInfo['options']['show_timezone'] == 1) { $displayForm .= " - "; - foreach($arrTimezones as $timeZone) { + foreach ($arrTimezones as $timeZone) { $tz = new DateTimeZone($timeZone); - $dispOffset = ((($tz->getOffset(new DateTime("now", $tz)))/60)/60); + $dispOffset = ((($tz->getOffset(new DateTime("now", $tz))) / 60) / 60); $dispSign = ($dispOffset < 0) ? "" : "+"; - + $selected = ""; - if($componentInfo['options']['selected_timezone'] == $timeZone) { + if ($componentInfo['options']['selected_timezone'] == $timeZone) { $selected = " selected"; } - - $displayForm .= ""; + + $displayForm .= ""; } - + $displayForm .= ""; } - + $displayForm .= "
"; - + break; case "select": - + $selectBoxObj = new SelectBox(); $selectBoxObj->setComponentName($componentName); - $selectBoxObj->setAttributes($componentInfo['attributes']); + $selectBoxObj->setAttributes($componentInfo['attributes']); $selectBoxObj->setOptions($componentInfo['options']); $selectBoxObj->setComponentValue($componentInfo['value'] ?? ''); $selectBoxObj->setNonSelectableItems($componentInfo['non_selectable_items'] ?? ''); $displayForm .= $selectBoxObj->getHTML(); - + break; case "checkbox": // Checkbox and radio are basically same thing, so checkbox falls through to radio section case "radio": - if(is_array($componentInfo['options'] ?? '')) { - $componentCounter = 1; - foreach($componentInfo['options'] as $optionValue => $displayValue) { + if (is_array($componentInfo['options'] ?? '')) { + $componentCounter = 1; + foreach ($componentInfo['options'] as $optionValue => $displayValue) { $dispSelected = ""; - + $newComponentName = $componentName; - if(count($componentInfo['options']) > 1) { - $newComponentName .= "_".$componentCounter; - - if($componentCounter > 1) { - $displayForm .= " "; + if (count($componentInfo['options']) > 1) { + $newComponentName .= "_" . $componentCounter; + + if ($componentCounter > 1) { + $displayForm .= " "; } - + $componentCounter++; } - - - if($optionValue == $componentInfo['value']) { + + + if ($optionValue == $componentInfo['value']) { $dispSelected = " checked"; } - - $dispLabel = ($displayValue != "") ? "
" : ""; - - $displayForm .= " ".$dispLabel; + + $dispLabel = ($displayValue != "") ? "
" : ""; + + $displayForm .= " " . $dispLabel; } - } - else { - + } else { + $dispChecked = ""; - if($componentInfo['checked'] ?? '') { - $dispChecked = " checked"; + if ($componentInfo['checked'] ?? '') { + $dispChecked = " checked"; } - - $displayForm .= ""; + + $displayForm .= ""; } break; case "file": $blnFileUploadForm = true; - + $displayForm .= "
File:
- +
    "; - if(is_array($componentInfo['options']['file_types'])) { - $displayForm .= "
  • File Types: ".implode(", ", $componentInfo['options']['file_types'])."
  • "; + if (is_array($componentInfo['options']['file_types'])) { + $displayForm .= "
  • File Types: " . implode(", ", $componentInfo['options']['file_types']) . "
  • "; } - - if(($componentInfo['options']['default_dimensions'] ?? '') != "") { - $displayForm .= "
  • Dimensions: ".$componentInfo['options']['default_dimensions']."
  • "; + + if (($componentInfo['options']['default_dimensions'] ?? '') != "") { + $displayForm .= "
  • Dimensions: " . $componentInfo['options']['default_dimensions'] . "
  • "; } - - $displayForm .= "
  • File Size: ".ini_get("upload_max_filesize")."B or less
"; - + + $displayForm .= "
  • File Size: " . ini_get("upload_max_filesize") . "B or less
  • "; + $displayForm .= "

    OR

    "; - - $displayForm .= "URL:
    "; - - if(($componentInfo['value'] ?? '') != "") { - - $displayForm .= "
    View Saved File"; - + + $displayForm .= "URL:
    "; + + if (($componentInfo['value'] ?? '') != "") { + + $displayForm .= "
    View Saved File"; + } - - + + $displayForm .= "
    "; break; case "section": - - $displayForm .= "
    "; - if($componentInfo['options']['section_title'] != "") { - $displayForm .= "

    ".$componentInfo['options']['section_title']."

    "; + + $displayForm .= "
    "; + if ($componentInfo['options']['section_title'] != "") { + $displayForm .= "

    " . $componentInfo['options']['section_title'] . "

    "; } - - if(($componentInfo['options']['section_description'] ?? '') != "") { - $displayForm .= "

    ".$componentInfo['options']['section_description']."

    "; + + if (($componentInfo['options']['section_description'] ?? '') != "") { + $displayForm .= "

    " . $componentInfo['options']['section_description'] . "

    "; } - - if(isset($componentInfo['components']) && $componentInfo['components'] != "" && is_array($componentInfo['components'])) { - + + if (isset($componentInfo['components']) && $componentInfo['components'] != "" && is_array($componentInfo['components'])) { + $sectionFormObj = new Form(); $sectionFormObj->isContainer = true; $sectionFormObj->components = $componentInfo['components']; $displayForm .= $sectionFormObj->show(); - + } $displayForm .= "
    "; - + break; case "beforeafter": $this->beforeAfter = true; - foreach($componentInfo['options'] as $optionValue => $displayValue) { - $dispSelected = ""; - if($optionValue == ($componentInfo['before_after_value'] ?? '')) { + foreach ($componentInfo['options'] as $optionValue => $displayValue) { + $dispSelected = ""; + if ($optionValue == ($componentInfo['before_after_value'] ?? '')) { $dispSelected = " selected"; } - - if($optionValue != ($componentInfo['value'] ?? '')) { - $displayOptions .= ""; + + if ($optionValue != ($componentInfo['value'] ?? '')) { + $displayOptions .= ""; } - + } - + $afterSelected = (($componentInfo['after_selected'] ?? '') == "after") ? " selected" : ""; - + $displayForm .= "
    - - +
    - + " . $displayOptions . "
    "; - + break; case "custom": break; case "colorpick": - + $afterJS .= $this->colorpickerJS($componentInfo['attributes']['id'], $componentInfo['allowHTML'] ?? ''); - $displayForm .= ""; - + $displayForm .= ""; + break; default: - $displayForm .= ""; + $displayForm .= ""; } - + $displayForm .= $componentInfo['html'] ?? ''; - - if($componentInfo['type'] != "section" && !isset($componentInfo['hidden'])) { + + if ($componentInfo['type'] != "section" && !isset($componentInfo['hidden'])) { $displayForm .= "
    "; } - + } - + $dispFormAttributes = $this->convertAttributes($this->attributes); - if($blnFileUploadForm) { $dispFormAttributes .= " enctype='multipart/form-data'"; } - + if ($blnFileUploadForm) { + $dispFormAttributes .= " enctype='multipart/form-data'"; + } + $dispErrors = ""; - if(count($this->errors) > 0) { + if (count($this->errors) > 0) { $dispErrors = "
    The following errors occurred:
      "; - foreach($this->errors as $dispError) { - $dispErrors .= "
    • ".$dispError."
    • "; + foreach ($this->errors as $dispError) { + $dispErrors .= "
    • " . $dispError . "
    • "; } $dispErrors .= "
    "; } - - if(!$this->isContainer) { - echo "
    ".($this->wrapper[0] ?? '').$dispErrors.$this->description."
    ".$displayForm."
    ".($this->wrapper[1] ?? '')."
    "; + + if (!$this->isContainer) { + echo "
    " . ($this->wrapper[0] ?? '') . $dispErrors . $this->description . "
    " . $displayForm . "
    " . ($this->wrapper[1] ?? '') . "
    "; } - - if($afterJS != "" && !$this->isContainer) { + + if ($afterJS != "" && !$this->isContainer) { echo " "; } - - - if($this->isContainer) { + + + if ($this->isContainer) { $js = ""; - if($afterJS != "") { + if ($afterJS != "") { $js = ""; } - - return $displayForm.$js; + + return $displayForm . $js; } - - + + } - - public function prefillPostedValues() { - + + public function prefillPostedValues() + { + $filterTypes = array("file", "beforeafter", "button"); - - foreach($this->components as $componentName => $componentInfo) { - if(!in_array($componentInfo['type'], $filterTypes)) { + + foreach ($this->components as $componentName => $componentInfo) { + if (!in_array($componentInfo['type'], $filterTypes)) { $this->components[$componentName]['value'] = $_POST[$componentName]; - } + } } - + } - - public function prefillDBValues() { - if($this->saveType == "update") { + public function prefillDBValues() + { + if ($this->saveType == "update") { $info = $this->objSave->get_info_filtered(); - foreach($this->components as $key => $value) { - if($this->components[$key]['db_name'] != "" && !in_array($this->components[$key]['db_name'], $this->arrSkipPrefill)) { + foreach ($this->components as $key => $value) { + // Check if 'db_name' key exists in the component + if (isset($this->components[$key]['db_name']) && $this->components[$key]['db_name'] != "" && !in_array($this->components[$key]['db_name'], $this->arrSkipPrefill)) { $this->components[$key]['value'] = $info[$this->components[$key]['db_name']]; } } - } - } - - + + /** - * - validate - - * + * - validate - + * * Used to validate the data entered into the form. - * + * * Presets: NOT_BLANK, NUMBER_ONLY, RESTRICT_TO_OPTIONS - * - * + * + * * RESTRICT_TO_OPTIONS: Used for components with options (i.e. selectboxes, multi-checkboxes and multi-radiobuttons) - * + * */ - public function validate() { + public function validate() + { $returnVal = false; - foreach($this->components as $componentName => $componentInfo) { - + foreach ($this->components as $componentName => $componentInfo) { + // Turn on RESTRICT_TO_OPTIONS by default for select, check boxes, radio buttons if ( $componentInfo['type'] == "checkbox" || $componentInfo['type'] == "radio" || $componentInfo['type'] == "select" ) { - if ( ! isset($this->components[$componentName]['validate']) ) { + if (!isset($this->components[$componentName]['validate'])) { $this->components[$componentName]['validate'] = []; } - - if ( ! in_array("RESTRICT_TO_OPTIONS", $this->components[$componentName]['validate']) ) { + + if (!in_array("RESTRICT_TO_OPTIONS", $this->components[$componentName]['validate'])) { $componentInfo['validate'][] = "RESTRICT_TO_OPTIONS"; } } - - foreach(($componentInfo['validate'] ?? []) as $validateMethod) { - + + foreach (($componentInfo['validate'] ?? []) as $validateMethod) { + $arrValidate = array(); - if(is_array($validateMethod)) { + if (is_array($validateMethod)) { $arrValidate = $validateMethod; $validateMethod = $arrValidate['name']; } - - - - switch($validateMethod) { + + + switch ($validateMethod) { case "NOT_BLANK": - if(($componentInfo['type'] == "checkbox" || $componentInfo['type'] == "radio") && count($componentInfo['options']) > 1) { + if (($componentInfo['type'] == "checkbox" || $componentInfo['type'] == "radio") && count($componentInfo['options']) > 1) { $componentCounter = 1; $countBlanks = 0; - foreach($componentInfo['options'] as $optionName => $optionValue) { - - $fullComponentName = $componentName."_".$componentCounter; - if(trim($_POST[$fullComponentName]) == "") { - $countBlanks++; + foreach ($componentInfo['options'] as $optionName => $optionValue) { + + $fullComponentName = $componentName . "_" . $componentCounter; + if (trim($_POST[$fullComponentName]) == "") { + $countBlanks++; } - + $componentCounter++; } - if($countBlanks == count($componentInfo['options'])) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You must select at least one value for ".$componentInfo['display_name']."."; + if ($countBlanks == count($componentInfo['options'])) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You must select at least one value for " . $componentInfo['display_name'] . "."; } - - } - elseif($componentInfo['type'] != "file" && trim($_POST[$componentName]) == "") { - $this->errors[] = (($arrValidate['customMessage'] ?? '') != "") ? $arrValidate['customMessage'] : $componentInfo['display_name']." may not be blank."; + + } elseif ($componentInfo['type'] != "file" && trim($_POST[$componentName]) == "") { + $this->errors[] = (($arrValidate['customMessage'] ?? '') != "") ? $arrValidate['customMessage'] : $componentInfo['display_name'] . " may not be blank."; } break; case "NUMBER_ONLY": - if(!is_numeric($_POST[$componentName]) && $componentInfo['type'] != "datepicker") { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name']." may only be a numeric value."; - } - elseif($componentInfo['type'] == "datepicker") { + if (!is_numeric($_POST[$componentName]) && $componentInfo['type'] != "datepicker") { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name'] . " may only be a numeric value."; + } elseif ($componentInfo['type'] == "datepicker") { $checkDate = explode("-", $_POST[$componentName]); - if(!is_numeric($checkDate[0]) || !is_numeric($checkDate[1]) || !is_numeric($checkDate[2])) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name']." may only be a date value."; + if (!is_numeric($checkDate[0]) || !is_numeric($checkDate[1]) || !is_numeric($checkDate[2])) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name'] . " may only be a date value."; } - + } break; case "POSITIVE_NUMBER": - if($_POST[$componentName] < 0) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name']." must be a positive number."; + if ($_POST[$componentName] < 0) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name'] . " must be a positive number."; } break; case "RESTRICT_TO_OPTIONS": - - if( isset($componentInfo['options']) && is_array($componentInfo['options'])) { + + if (isset($componentInfo['options']) && is_array($componentInfo['options'])) { $arrPostNames = array(); $arrPossibleValues = array(); $postCounter = 1; - foreach($componentInfo['options'] as $optionValue => $displayValue) { + foreach ($componentInfo['options'] as $optionValue => $displayValue) { $arrPossibleValues[] = $optionValue; - $arrPostNames[] = $componentName."_".$postCounter; + $arrPostNames[] = $componentName . "_" . $postCounter; $postCounter++; } - - if(($componentInfo['type'] == "checkbox" || $componentInfo['type'] == "radio") && count($componentInfo['options']) > 1) { + + if (($componentInfo['type'] == "checkbox" || $componentInfo['type'] == "radio") && count($componentInfo['options']) > 1) { $countErrors = 0; - foreach($arrPostNames as $postName) { + foreach ($arrPostNames as $postName) { - if(isset($_POST[$postName]) && !in_array($_POST[$postName], $arrPossibleValues)) { + if (isset($_POST[$postName]) && !in_array($_POST[$postName], $arrPossibleValues)) { $countErrors++; } - + } - - if($countErrors > 0) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You selected an invalid value for ".$componentInfo['display_name']."."; + + if ($countErrors > 0) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You selected an invalid value for " . $componentInfo['display_name'] . "."; } - - } - elseif( isset($_POST[$componentName]) && !in_array($_POST[$componentName], $arrPossibleValues)) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You selected an invalid value for ".$componentInfo['display_name']."."; + + } elseif (isset($_POST[$componentName]) && !in_array($_POST[$componentName], $arrPossibleValues)) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You selected an invalid value for " . $componentInfo['display_name'] . "."; } - + } - + break; case "IS_SELECTABLE": - + $selectBackID = isset($arrValidate['select_back']) ? $arrValidate['selectObj']->get_info($arrValidate['select_back']) : ""; - - if(!$arrValidate['selectObj']->select($_POST[$componentName])) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You selected an invalid value for ".$componentInfo['display_name']."."; + + if (!$arrValidate['selectObj']->select($_POST[$componentName])) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You selected an invalid value for " . $componentInfo['display_name'] . "."; } - + $arrValidate['selectObj']->select($selectBackID); - + break; case "IS_NOT_SELECTABLE": $selectBackID = isset($arrValidate['select_back']) ? $arrValidate['selectObj']->get_info($arrValidate['select_back']) : ""; - - if($arrValidate['selectObj']->select($_POST[$componentName])) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "The value selected for ".$componentInfo['display_name']." is already in use."; + + if ($arrValidate['selectObj']->select($_POST[$componentName])) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "The value selected for " . $componentInfo['display_name'] . " is already in use."; } - + $arrValidate['selectObj']->select($selectBackID); - + break; case "CHECK_LENGTH": - - if($arrValidate['min_length'] != "" && strlen(trim($_POST[$componentName])) < $arrValidate['min_length']) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "The value for ".$componentInfo['display_name']." must be at least ".$arrValidate['min_length']." characters long."; + + if ($arrValidate['min_length'] != "" && strlen(trim($_POST[$componentName])) < $arrValidate['min_length']) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "The value for " . $componentInfo['display_name'] . " must be at least " . $arrValidate['min_length'] . " characters long."; } - - if($arrValidate['max_length'] != "" && strlen(trim($_POST[$componentName])) > $arrValidate['max_length']) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "The value for ".$componentInfo['display_name']." can be a max of ".$arrValidate['min_length']." characters long."; + + if ($arrValidate['max_length'] != "" && strlen(trim($_POST[$componentName])) > $arrValidate['max_length']) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "The value for " . $componentInfo['display_name'] . " can be a max of " . $arrValidate['min_length'] . " characters long."; } - + break; case "EQUALS_VALUE": - - if($arrValidate['value'] != $_POST[$componentName]) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You entered an incorrect value for ".$componentInfo['display_name']."."; + + if ($arrValidate['value'] != $_POST[$componentName]) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You entered an incorrect value for " . $componentInfo['display_name'] . "."; } - + break; case "NOT_EQUALS_VALUE": - if($arrValidate['value'] == $_POST[$componentName]) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You entered an incorrect value for ".$componentInfo['display_name']."."; + if ($arrValidate['value'] == $_POST[$componentName]) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You entered an incorrect value for " . $componentInfo['display_name'] . "."; } break; case "GREATER_THAN": - if($arrValidate['value'] > strlen(trim($_POST[$componentName]))) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name']." must be a value greater than ".$arrValidate['value']."."; + if ($arrValidate['value'] > strlen(trim($_POST[$componentName]))) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name'] . " must be a value greater than " . $arrValidate['value'] . "."; } break; case "LESS_THAN": - if($arrValidate['value'] < strlen(trim($_POST[$componentName]))) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name']." must be a value less than ".$arrValidate['value']."."; + if ($arrValidate['value'] < strlen(trim($_POST[$componentName]))) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : $componentInfo['display_name'] . " must be a value less than " . $arrValidate['value'] . "."; } break; case "VALIDATE_ORDER": - - if($arrValidate['orderObject'] != "") { - - if(($arrValidate['set_category'] ?? '') != "") { + + if ($arrValidate['orderObject'] != "") { + + if (($arrValidate['set_category'] ?? '') != "") { $arrValidate['orderObject']->setCategoryKeyValue($arrValidate['set_category']); } - - $checkOrder = $arrValidate['orderObject']->validateOrder($_POST[$componentName], $_POST[$componentName."_beforeafter"], $arrValidate['edit'] ?? '', $arrValidate['edit_ordernum'] ?? ''); - if($checkOrder === false) { - $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You selected an invalid ".$componentInfo['display_name']."."; - } - else { + + $checkOrder = $arrValidate['orderObject']->validateOrder($_POST[$componentName], $_POST[$componentName . "_beforeafter"], $arrValidate['edit'] ?? '', $arrValidate['edit_ordernum'] ?? ''); + if ($checkOrder === false) { + $this->errors[] = ($arrValidate['customMessage'] != "") ? $arrValidate['customMessage'] : "You selected an invalid " . $componentInfo['display_name'] . "."; + } else { $_POST[$componentName] = $checkOrder; $this->components[$componentName]['resortOrderObject'] = $arrValidate['orderObject']; - + } - if(isset($arrValidate['select_back'])) { + if (isset($arrValidate['select_back'])) { $arrValidate['orderObject']->select($arrValidate['select_back']); } - + } - + break; default: - if(!is_array($validateMethod)) { + if (!is_array($validateMethod)) { call_user_func($validateMethod); - } - else { - call_user_func_array($validateMethod['function'], $validateMethod['args']); + } else { + call_user_func_array($validateMethod['function'], $validateMethod['args']); } } - + } - - - - if($componentInfo['type'] == "file" && $_POST[$componentName] == "") { + + + if ($componentInfo['type'] == "file" && $_POST[$componentName] == "") { // Check Upload $uploadFile = "noupload"; $outsideLink = false; - if($_FILES[$componentName."_file"]['name'] != "") { - $uploadFile = new BTUpload($_FILES[$componentName."_file"], $componentInfo['options']['file_prefix'], $componentInfo['options']['save_loc'], $componentInfo['options']['file_types']); - } - elseif($_POST[$componentName."_url"] != "") { - $uploadFile = new BTUpload($_POST[$componentName."_url"], $componentInfo['options']['file_prefix'], $componentInfo['options']['save_loc'], $componentInfo['options']['file_types'], $componentInfo['options']['ext_length'], true); + if ($_FILES[$componentName . "_file"]['name'] != "") { + $uploadFile = new BTUpload($_FILES[$componentName . "_file"], $componentInfo['options']['file_prefix'], $componentInfo['options']['save_loc'], $componentInfo['options']['file_types']); + } elseif ($_POST[$componentName . "_url"] != "") { + $uploadFile = new BTUpload($_POST[$componentName . "_url"], $componentInfo['options']['file_prefix'], $componentInfo['options']['save_loc'], $componentInfo['options']['file_types'], $componentInfo['options']['ext_length'], true); $outsideLink = true; } - - if($uploadFile != "noupload") { - - - - if($this->attachmentForm) { + + if ($uploadFile != "noupload") { + + + if ($this->attachmentForm) { $this->attachmentObj->setUploadObj($uploadFile); $this->attachmentObj->setCategory($componentInfo['options']['download_category']); - - if(!$this->attachmentObj->uploadFile()) { - $this->errors[] = "Unable to upload ".$componentInfo['display_name'].". Make sure that the file is not too big and correct extension."; - } - else { - $_POST[$componentName] = $componentInfo['options']['append_db_value'].$uploadFile->getUploadedFileName(); - } - - - - } - else { - if(!$uploadFile->uploadFile()) { - $this->errors[] = "Unable to upload ".$componentInfo['display_name'].". Make sure that the file is not too big and correct extension."; + + if (!$this->attachmentObj->uploadFile()) { + $this->errors[] = "Unable to upload " . $componentInfo['display_name'] . ". Make sure that the file is not too big and correct extension."; + } else { + $_POST[$componentName] = $componentInfo['options']['append_db_value'] . $uploadFile->getUploadedFileName(); } - else { - $_POST[$componentName] = $componentInfo['options']['append_db_value'].$uploadFile->getUploadedFileName(); + + + } else { + if (!$uploadFile->uploadFile()) { + $this->errors[] = "Unable to upload " . $componentInfo['display_name'] . ". Make sure that the file is not too big and correct extension."; + } else { + $_POST[$componentName] = $componentInfo['options']['append_db_value'] . $uploadFile->getUploadedFileName(); // Check if updating, and delete old file - - if($this->saveType != "add" && $componentInfo['db_name'] != "" && $this->objSave->get_info($componentInfo['db_name']) != "") { + + if ($this->saveType != "add" && $componentInfo['db_name'] != "" && $this->objSave->get_info($componentInfo['db_name']) != "") { $this->arrDeleteFiles[] = $this->objSave->get_info($componentInfo['db_name']); } - + } } - - - - } - elseif($componentInfo['value'] != "") { - $_POST[$componentName] = $componentInfo['value']; + + + } elseif (isset($componentInfo['value']) && $componentInfo['value'] != "") { + $_POST[$componentName] = $componentInfo['value']; } - - if(in_array("NOT_BLANK", $componentInfo['validate'])) { - if($_POST[$componentName] == "") { - $this->errors[] = $componentInfo['display_name']." may not be blank."; + + if (is_array($componentInfo['validate']) && in_array("NOT_BLANK", $componentInfo['validate'])) { + if ($_POST[$componentName] == "") { + $this->errors[] = $componentInfo['display_name'] . " may not be blank."; } } - - } - elseif($componentInfo['type'] == "datepicker") { - + + } elseif ($componentInfo['type'] == "datepicker") { + $formatDate = explode("-", $_POST[$componentName]); $datePick = new DateTime(); $datePick->setTimezone(new DateTimeZone("UTC")); $datePick->setDate($formatDate[2], $formatDate[0], $formatDate[1]); - - if(isset($componentInfo['usetime'])) { - $useTimeComponent = $componentInfo['usetime']; - $hour = $useTimeComponent."_hour"; - $minute = $useTimeComponent."_minute"; - $amPM = $useTimeComponent."_AMPM"; - - $setHour = ($_POST[$amPM] == "PM") ? $_POST[$hour]+12 : $_POST[$hour]; + + if (isset($componentInfo['usetime'])) { + $useTimeComponent = $componentInfo['usetime']; + $hour = $useTimeComponent . "_hour"; + $minute = $useTimeComponent . "_minute"; + $amPM = $useTimeComponent . "_AMPM"; + + $setHour = ($_POST[$amPM] == "PM") ? $_POST[$hour] + 12 : $_POST[$hour]; $setMinute = $_POST[$minute]; - + $datePick->setTime($setHour, $setMinute); } - + $dateTimestamp = $datePick->format("U"); - - $_POST[$componentName] = $dateTimestamp; - } - - + + $_POST[$componentName] = $dateTimestamp; + } + + } - - - if($_POST['checkCSRF'] != $_SESSION['csrfKey']) { + + + if ($_POST['checkCSRF'] != $_SESSION['csrfKey']) { $this->errors[] = "Invalid CSRF Token. Possible Hacking attempt?"; } - - - if(count($this->errors) == 0) { - $returnVal = true; + + + if (count($this->errors) == 0) { + $returnVal = true; } - + return $returnVal; } - - - + + /** * - save - - * + * * Saves the form data to the database - * + * */ - public function save() { + public function save() + { global $hooksObj; $hooksObj->run($this->formName); - + $this->blnSaveResult = false; - - - $arrResortOrder = array(); - if($this->validate()) { + $arrResortOrder = array(); + if ($this->validate()) { $arrColumns = array(); $arrValues = array(); - foreach($this->components as $componentName => $componentInfo) { - - if(isset($componentInfo['db_name']) && $componentInfo['db_name'] != "") { + foreach ($this->components as $componentName => $componentInfo) { + if (isset($componentInfo['db_name']) && $componentInfo['db_name'] != "") { $arrColumns[] = $componentInfo['db_name']; - $arrValues[] = $_POST[$componentName]; + // Check if $_POST[$componentName] is set and not null + $arrValues[] = isset($_POST[$componentName]) ? $_POST[$componentName] : ''; // Provide a default value if null } - if($componentInfo['type'] == "beforeafter") { - $this->beforeAfter = true; + // Check if 'hide' key exists in $componentInfo + if (isset($componentInfo['hide']) && $componentInfo['hide']) { + // Your logic for 'hide' key + } + + if ($componentInfo['type'] == "beforeafter") { + $this->beforeAfter = true; } - } - - if ( is_array($this->saveAdditional) ) { - foreach($this->saveAdditional as $dbName => $dbValue) { + + if (is_array($this->saveAdditional)) { + foreach ($this->saveAdditional as $dbName => $dbValue) { $arrColumns[] = $dbName; $arrValues[] = $dbValue; } } - - - if($this->objSave != "" && $this->saveType == "add") { + + if ($this->objSave != "" && $this->saveType == "add") { $this->blnSaveResult = $this->objSave->addNew($arrColumns, $arrValues); - } - elseif($this->objSave != "" && $this->saveType == "update") { + } elseif ($this->objSave != "" && $this->saveType == "update") { $this->blnSaveResult = $this->objSave->update($arrColumns, $arrValues); - - - if(count($this->arrDeleteFiles) > 0) { - foreach($this->arrDeleteFiles as $file) { - unlink(BASE_DIRECTORY.$file); + + + if (count($this->arrDeleteFiles) > 0) { + foreach ($this->arrDeleteFiles as $file) { + unlink(BASE_DIRECTORY . $file); } } - - } - elseif($this->objSave != "" && $this->saveType != "") { + + } elseif ($this->objSave != "" && $this->saveType != "") { //echo $this->saveType; $this->blnSaveResult = $this->objSave->{$this->saveType}($arrColumns, $arrValues); - - } - else { + + } else { $this->blnSaveResult = true; } - - - if(!$this->blnSaveResult) { + + + if (!$this->blnSaveResult) { $this->errors[] = "Unable to save information to the database. Please contact the website administrator."; - } - else { + } else { - if(is_array($this->afterSave)) { - foreach($this->afterSave as $saveFunction) { - if(!is_array($saveFunction)) { + if (is_array($this->afterSave)) { + foreach ($this->afterSave as $saveFunction) { + if (!is_array($saveFunction)) { call_user_func($saveFunction); + } else { + call_user_func_array($saveFunction['function'], $saveFunction['args']); } - else { - call_user_func_array($saveFunction['function'], $saveFunction['args']); - } - + } } - - - if($this->beforeAfter) { - foreach($this->components as $componentName => $componentInfo) { - + + + if ($this->beforeAfter) { + foreach ($this->components as $componentName => $componentInfo) { + // Check for Display Order input types, need to resort order - if($componentInfo['type'] == "beforeafter" && $componentInfo['resortOrderObject'] != "") { - $componentInfo['resortOrderObject']->resortOrder(); + if ($componentInfo['type'] == "beforeafter" && $componentInfo['resortOrderObject'] != "") { + $componentInfo['resortOrderObject']->resortOrder(); } - + } } - + } - + } - + return $this->blnSaveResult; - + } - - static function sortForm($a, $b) { + + static function sortForm($a, $b) + { $returnVal = 1; - if($a['sortorder'] == $b['sortorder']) { - $returnVal = 0; - } - elseif($a['sortorder'] < $b['sortorder']) { + if ($a['sortorder'] == $b['sortorder']) { + $returnVal = 0; + } elseif ($a['sortorder'] < $b['sortorder']) { $returnVal = -1; } - + return $returnVal; } - - public function addComponentSortSpace($spaceAmount=2, $components = array()) { - - if(count($components) > 0) { + + public function addComponentSortSpace($spaceAmount = 2, $components = array()) + { + + if (count($components) > 0) { $this->components = $components; } - + uasort($this->components, array("Form", "sortForm")); - + $nextSpot = 1; - - foreach($this->components as $componentName => $componentInfo) { + + foreach ($this->components as $componentName => $componentInfo) { $this->components[$componentName]['sortorder'] = $nextSpot; - $nextSpot += $nextSpot+$spaceAmount; + $nextSpot += $nextSpot + $spaceAmount; } - + } - + /** * - convertAttributes Function - - * + * * Converts attributes to string format if it's an array * example output: name = 'form_name' id='form_id' - * + * */ - public function convertAttributes($attr) { - - if(is_array($attr)) { + public function convertAttributes($attr) + { + + if (is_array($attr)) { $returnVal = ""; - foreach($attr as $attrName => $attrValue) { - $returnVal .= $attrName."='".$attrValue."' "; + foreach ($attr as $attrName => $attrValue) { + $returnVal .= $attrName . "='" . $attrValue . "' "; } - - } - else { + + } else { $returnVal = $attr; } - + return $returnVal; } - - - public function showSuccessDialog() { - - $popupLink = ($this->saveLink == "") ? MAIN_ROOT."members" : $this->saveLink; - + + + public function showSuccessDialog() + { + + $popupLink = ($this->saveLink == "") ? MAIN_ROOT . "members" : $this->saveLink; + $dispDialogTitle = ($this->saveMessageTitle == "") ? "Confirmation" : $this->saveMessageTitle; - - if($this->saveMessage != "") { + + if ($this->saveMessage != "") { echo " "; - } - else { + } else { echo " "; - + } - + } - - - private function autocompleteJS($searchList, $idTextbox, $wordTextbox) { + + + private function autocompleteJS($searchList, $idTextbox, $wordTextbox) + { $returnVal = " $(document).ready(function() { - var arr".$idTextbox." = ".$searchList."; + var arr" . $idTextbox . " = " . $searchList . "; - $('#".$wordTextbox."').autocomplete({ - source: arr".$idTextbox.", + $('#" . $wordTextbox . "').autocomplete({ + source: arr" . $idTextbox . ", minLength: 3, select: function(event, ui) { - $('#".$idTextbox."').val(ui.item.id); + $('#" . $idTextbox . "').val(ui.item.id); } @@ -997,39 +989,41 @@ private function autocompleteJS($searchList, $idTextbox, $wordTextbox) { }); "; - + return $returnVal; } - - private function codeEditorJS($componentID) { - + + private function codeEditorJS($componentID) + { + $returnVal = " - var ".$componentID." = ace.edit('".$componentID."'); - ".$componentID.".getSession().setMode('ace/mode/php'); - ".$componentID.".setTheme('ace/theme/eclipse'); - ".$componentID.".setHighlightActiveLine(false); - ".$componentID.".setShowPrintMargin(false); + var " . $componentID . " = ace.edit('" . $componentID . "'); + " . $componentID . ".getSession().setMode('ace/mode/php'); + " . $componentID . ".setTheme('ace/theme/eclipse'); + " . $componentID . ".setHighlightActiveLine(false); + " . $componentID . ".setShowPrintMargin(false); "; - + return $returnVal; } - - private function richTextboxJS($componentID, $allowHTML=false) { + + private function richTextboxJS($componentID, $allowHTML = false) + { global $MAIN_ROOT, $THEME, $hooksObj; - + $addHTML = ($allowHTML) ? ",code" : ""; - - + + $GLOBALS['richtextEditor'] = " $(document).ready(function() { - $('#".$componentID."').tinymce({ + $('#" . $componentID . "').tinymce({ - script_url: '".MAIN_ROOT."js/tiny_mce/tiny_mce.js', + script_url: '" . MAIN_ROOT . "js/tiny_mce/tiny_mce.js', theme: 'advanced', plugins: 'autolink,emotions,advimagescale', cleanup_on_startup: true, @@ -1038,10 +1032,10 @@ private function richTextboxJS($componentID, $allowHTML=false) { advimagescale_loading_callback: function(imgNode) { alert('resized to ' + imgNode.width + 'x' + imgNode.height); }, - theme_advanced_buttons1: 'bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,link,unlink,image,emotions,|,quotebbcode,codebbcode".$addHTML.",', + theme_advanced_buttons1: 'bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,link,unlink,image,emotions,|,quotebbcode,codebbcode" . $addHTML . ",', theme_advanced_buttons2: 'forecolorpicker,fontselect,fontsizeselect', theme_advanced_resizing: true, - content_css: '".MAIN_ROOT."themes/".THEME."/btcs4.css', + content_css: '" . MAIN_ROOT . "themes/" . THEME . "/btcs4.css', theme_advanced_statusbar_location: 'none', style_formats: [ {title: 'Quote', inline : 'div', classes: 'forumQuote'} @@ -1051,7 +1045,7 @@ private function richTextboxJS($componentID, $allowHTML=false) { ed.addButton('quotebbcode', { title: 'Insert Quote', - image: '".MAIN_ROOT."js/tiny_mce/quote.png', + image: '" . MAIN_ROOT . "js/tiny_mce/quote.png', onclick: function() { ed.focus(); innerText = ed.selection.getContent(); @@ -1063,7 +1057,7 @@ private function richTextboxJS($componentID, $allowHTML=false) { ed.addButton('codebbcode', { title: 'Insert Code', - image: '".MAIN_ROOT."js/tiny_mce/code.png', + image: '" . MAIN_ROOT . "js/tiny_mce/code.png', onclick: function() { ed.focus(); innerText = ed.selection.getContent(); @@ -1082,47 +1076,51 @@ private function richTextboxJS($componentID, $allowHTML=false) { "; $GLOBALS['rtCompID'] = $componentID; $hooksObj->run("form_richtexteditor"); - + unset($GLOBALS['rtCompID']); - + return $GLOBALS['richtextEditor']; } - - private function datepickerJS($componentID, $componentOptions) { - - + + private function datepickerJS($componentID, $componentOptions) + { + + $returnVal = " - $('#".$componentID."').datepicker({ - changeMonth: ".$componentOptions['changeMonth'].", - changeYear: ".$componentOptions['changeYear'].", - dateFormat: '".$componentOptions['dateFormat']."', - minDate: ".$componentOptions['minDate'].", - maxDate: ".$componentOptions['maxDate'].", - yearRange: '".$componentOptions['yearRange']."', - defaultDate: '".$componentOptions['defaultDate']."', - altField: '#".$componentOptions['altField']."', + $('#" . $componentID . "').datepicker({ + changeMonth: " . $componentOptions['changeMonth'] . ", + changeYear: " . $componentOptions['changeYear'] . ", + dateFormat: '" . $componentOptions['dateFormat'] . "', + minDate: " . $componentOptions['minDate'] . ", + maxDate: " . $componentOptions['maxDate'] . ", + yearRange: '" . $componentOptions['yearRange'] . "', + defaultDate: '" . $componentOptions['defaultDate'] . "', + altField: '#" . $componentOptions['altField'] . "', altFormat: 'm-d-yy' }); "; - + return $returnVal; } - - private function colorpickerJS($componentID) { + + private function colorpickerJS($componentID) + { $returnVal = " - $('#".$componentID."').miniColors({ + $('#" . $componentID . "').miniColors({ change: function(hex, rgb) { } }); "; - + return $returnVal; } - - public function getRichtextboxJSFile() { - return $this->richtextboxJSFile; + + public function getRichtextboxJSFile() + { + return $this->richtextboxJSFile; } - - public function getColorpickerJSFile() { - return $this->colorpickerJSFile; + + public function getColorpickerJSFile() + { + return $this->colorpickerJSFile; } - } \ No newline at end of file + } diff --git a/src/classes/member.php b/src/classes/member.php index e06d7397..0baa5905 100644 --- a/src/classes/member.php +++ b/src/classes/member.php @@ -1,1031 +1,1047 @@ MySQL = $sqlConnection; - $this->strTableName = $this->MySQL->get_tablePrefix()."members"; - $this->strTableKey = "member_id"; - - $this->objProfileOption = new ProfileOption($sqlConnection); - $this->objRank = new Rank($sqlConnection); - $this->objSocial = new Social($sqlConnection); - } - - - - function select($memberID, $numericIDOnly = true) { - $returnVal = false; - if(is_numeric($memberID)) { - - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName." WHERE member_id = '$memberID'"); - if($result->num_rows > 0) { - - $this->arrObjInfo = $result->fetch_assoc(); - $this->intTableKeyValue = $this->arrObjInfo['member_id']; - $returnVal = true; - } - + /* + * BlueThrust Clan Scripts + * Copyright 2014 + * + * Author: Bluethrust Web Development + * E-mail: support@bluethrust.com + * Website: http://www.bluethrust.com + * + * License: http://www.bluethrust.com/license.php + * + */ + + + require_once("consoleoption.php"); + require_once("profileoption.php"); + require_once("rank.php"); + require_once("medal.php"); + require_once("forumboard.php"); + require_once("social.php"); + + class Member extends Basic + { + + protected $objProfileOption; + public $objRank; + public $objSocial; + + function __construct($sqlConnection) + { + $this->MySQL = $sqlConnection; + $this->strTableName = $this->MySQL->get_tablePrefix() . "members"; + $this->strTableKey = "member_id"; + + $this->objProfileOption = new ProfileOption($sqlConnection); + $this->objRank = new Rank($sqlConnection); + $this->objSocial = new Social($sqlConnection); } - else { - $memberID = $this->MySQL->real_escape_string($memberID); - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName." WHERE username = '$memberID'"); - - if($result->num_rows > 0) { - $this->arrObjInfo = $result->fetch_assoc(); - $this->intTableKeyValue = $this->arrObjInfo['member_id']; - $returnVal = true; - - $this->objRank->select($this->arrObjInfo['rank_id']); + + + function select($memberID, $numericIDOnly = true) + { + $returnVal = false; + if (is_numeric($memberID)) { + + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName . " WHERE member_id = '$memberID'"); + if ($result->num_rows > 0) { + + $this->arrObjInfo = $result->fetch_assoc(); + $this->intTableKeyValue = $this->arrObjInfo['member_id']; + $returnVal = true; + } + + } else { + $memberID = $this->MySQL->real_escape_string($memberID); + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName . " WHERE username = '$memberID'"); + + if ($result->num_rows > 0) { + $this->arrObjInfo = $result->fetch_assoc(); + $this->intTableKeyValue = $this->arrObjInfo['member_id']; + $returnVal = true; + + $this->objRank->select($this->arrObjInfo['rank_id']); + } + } - } + $this->objSocial->memberID = $this->intTableKeyValue; + + return $returnVal; - $this->objSocial->memberID = $this->intTableKeyValue; - - return $returnVal; - - } - - function authorizeLogin($check_password, $encryptPW=0) { - - // get password hash from database - $checkRealPassword = $this->arrObjInfo['password'] ?? ''; - - // get just the salt from the database - $checkRealPassword2 = $this->arrObjInfo['password2'] ?? ''; - - if($encryptPW == 1) { - - // hash the plaintext password - $checkPass = crypt($check_password, $checkRealPassword2); - - } - else { - $checkPass = $check_password; - } - - $returnVal = false; - - // if passwords match - if( - $checkRealPassword == $checkPass && - ($this->arrObjInfo['disabled'] ?? '') == 0 - ) { - $returnVal = true; } - - return $returnVal; - - } - - function set_password($new_password) { - - $returnVal = false; - if($this->intTableKeyValue != "" ) { - - $passwordInfo = encryptPassword($new_password); - - if($this->update(array("password", "password2"), array($passwordInfo['password'], $passwordInfo['salt']))) { - $returnVal = true; + + function authorizeLogin($check_password, $encryptPW = 0) + { + + // get password hash from database + $checkRealPassword = $this->arrObjInfo['password'] ?? ''; + + // get just the salt from the database + $checkRealPassword2 = $this->arrObjInfo['password2'] ?? ''; + + if ($encryptPW == 1) { + + // hash the plaintext password + $checkPass = crypt($check_password, $checkRealPassword2); + + } else { + $checkPass = $check_password; } - - } - - return $returnVal; - - } - - - /** - * - playsGame Function - - * - * Checks to see if the selected member plays a particular game identified by the gamesplayed_id - * - * Returns true or false - * - */ - function playsGame($gamesplayed_id) { - - $returnVal = false; - if(is_numeric($gamesplayed_id)) { - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."gamesplayed_members WHERE gamesplayed_id = '".$gamesplayed_id."' AND member_id = '".$this->intTableKeyValue."'"); - - $num_rows = $result->num_rows; - - if($num_rows > 0) { + + $returnVal = false; + + // if passwords match + if ( + $checkRealPassword == $checkPass && + ($this->arrObjInfo['disabled'] ?? '') == 0 + ) { $returnVal = true; } - + + return $returnVal; + } - - return $returnVal; - } - - /** - * - gamesPlayed Function - - * - * Returns an array of games played ids - */ - function gamesPlayed() { - - $returnArr = array(); - if($this->intTableKeyValue != "") { - $result = $this->MySQL->query("SELECT gamesplayed_id FROM ".$this->MySQL->get_tablePrefix()."gamesplayed_members WHERE member_id = '".$this->intTableKeyValue."'"); - - while($row = $result->fetch_assoc()) { - $returnArr[] = $row['gamesplayed_id']; + + function set_password($new_password) + { + + $returnVal = false; + if ($this->intTableKeyValue != "") { + + $passwordInfo = encryptPassword($new_password); + + if ($this->update(array("password", "password2"), array($passwordInfo['password'], $passwordInfo['salt']))) { + $returnVal = true; + } + } - + + return $returnVal; + } - - return $returnArr; - - } - - - /** - * - getSquadList Function - - * - * Returns an array of squad_id's for the selected member. If the boolean value $founderOnly is set to true, then it only - * groups squads where the member is the founder. - */ - function getSquadList($founderOnly=false) { - $returnArr = array(); - - if($this->intTableKeyValue != "") { - - if($founderOnly) { - $query = "SELECT * FROM ".$this->MySQL->get_tablePrefix()."squads WHERE member_id = '".$this->intTableKeyValue."'"; - } - else { - $query = "SELECT * FROM ".$this->MySQL->get_tablePrefix()."squads_members WHERE member_id = '".$this->intTableKeyValue."'"; + + + /** + * - playsGame Function - + * + * Checks to see if the selected member plays a particular game identified by the gamesplayed_id + * + * Returns true or false + * + */ + function playsGame($gamesplayed_id) + { + + $returnVal = false; + if (is_numeric($gamesplayed_id)) { + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "gamesplayed_members WHERE gamesplayed_id = '" . $gamesplayed_id . "' AND member_id = '" . $this->intTableKeyValue . "'"); + + $num_rows = $result->num_rows; + + if ($num_rows > 0) { + $returnVal = true; + } + } - - $result = $this->MySQL->query($query); - while($row = $result->fetch_array()) { - $returnArr[] = $row['squad_id']; + + return $returnVal; + } + + /** + * - gamesPlayed Function - + * + * Returns an array of games played ids + */ + function gamesPlayed() + { + + $returnArr = array(); + if ($this->intTableKeyValue != "") { + $result = $this->MySQL->query("SELECT gamesplayed_id FROM " . $this->MySQL->get_tablePrefix() . "gamesplayed_members WHERE member_id = '" . $this->intTableKeyValue . "'"); + + while ($row = $result->fetch_assoc()) { + $returnArr[] = $row['gamesplayed_id']; + } + } - + + return $returnArr; + } - - return $returnArr; - - } - - - - /** - * - * - getTournamentList Function - - * - * Returns an array of tournament_id's for the selected member. If the boolean value $creatorOnly is set to true, then it only - * groups tournaments where the member is the creator or manager. If left as false will only return the tournaments that the member is playing in - * - * - */ - function getTournamentList($creatorOnly=false) { - $returnArr = array(); - - if($this->intTableKeyValue != "") { - if($creatorOnly) { - $query = "SELECT * FROM ".$this->MySQL->get_tablePrefix()."tournaments WHERE member_id = '".$this->intTableKeyValue."'"; - $result = $this->MySQL->query($query); - while($row = $result->fetch_array()) { - $returnArr[] = $row['tournament_id']; + + + /** + * - getSquadList Function - + * + * Returns an array of squad_id's for the selected member. If the boolean value $founderOnly is set to true, then it only + * groups squads where the member is the founder. + */ + function getSquadList($founderOnly = false) + { + $returnArr = array(); + + if ($this->intTableKeyValue != "") { + + if ($founderOnly) { + $query = "SELECT * FROM " . $this->MySQL->get_tablePrefix() . "squads WHERE member_id = '" . $this->intTableKeyValue . "'"; + } else { + $query = "SELECT * FROM " . $this->MySQL->get_tablePrefix() . "squads_members WHERE member_id = '" . $this->intTableKeyValue . "'"; } - - $query = "SELECT tournament_id FROM ".$this->MySQL->get_tablePrefix()."tournament_managers WHERE member_id = '".$this->intTableKeyValue."'"; + $result = $this->MySQL->query($query); - while($row = $result->fetch_assoc()) { - $returnArr[] = $row['tournament_id']; + while ($row = $result->fetch_array()) { + $returnArr[] = $row['squad_id']; } - + } - else { - $query = "SELECT * FROM ".$this->MySQL->get_tablePrefix()."tournamentplayers WHERE member_id = '".$this->intTableKeyValue."'"; - $result = $this->MySQL->query($query); - while($row = $result->fetch_array()) { - $teamArr[] = $row['team_id']; - } + return $returnArr; + + } + + + /** + * + * - getTournamentList Function - + * + * Returns an array of tournament_id's for the selected member. If the boolean value $creatorOnly is set to true, then it only + * groups tournaments where the member is the creator or manager. If left as false will only return the tournaments that the member is playing in + * + * + */ + function getTournamentList($creatorOnly = false) + { + $returnArr = array(); + + if ($this->intTableKeyValue != "") { + if ($creatorOnly) { + $query = "SELECT * FROM " . $this->MySQL->get_tablePrefix() . "tournaments WHERE member_id = '" . $this->intTableKeyValue . "'"; + $result = $this->MySQL->query($query); + while ($row = $result->fetch_array()) { + $returnArr[] = $row['tournament_id']; + } + + $query = "SELECT tournament_id FROM " . $this->MySQL->get_tablePrefix() . "tournament_managers WHERE member_id = '" . $this->intTableKeyValue . "'"; + $result = $this->MySQL->query($query); + while ($row = $result->fetch_assoc()) { + $returnArr[] = $row['tournament_id']; + } + + } else { + + $query = "SELECT * FROM " . $this->MySQL->get_tablePrefix() . "tournamentplayers WHERE member_id = '" . $this->intTableKeyValue . "'"; + $result = $this->MySQL->query($query); + while ($row = $result->fetch_array()) { + $teamArr[] = $row['team_id']; + } + + + $teamSQL = "('" . implode("','", $teamArr) . "')"; + + $query = "SELECT * FROM " . $this->MySQL->get_tablePrefix() . "tournamentteams WHERE tournamentteam_id IN " . $teamSQL; + $result = $this->MySQL->query($query); + //echo $this->MySQL->error; + while ($row = $result->fetch_array()) { + $returnArr[] = $row['tournament_id']; + //echo $row['tournament_id']."
    "; + } - $teamSQL = "('".implode("','", $teamArr)."')"; - - $query = "SELECT * FROM ".$this->MySQL->get_tablePrefix()."tournamentteams WHERE tournamentteam_id IN ".$teamSQL; - $result = $this->MySQL->query($query); - //echo $this->MySQL->error; - while($row = $result->fetch_array()) { - $returnArr[] = $row['tournament_id']; - //echo $row['tournament_id']."
    "; } - - - + + //print_r($returnArr); + + } - - //print_r($returnArr); - - + + return $returnArr; + } - - return $returnArr; - - } - - - function hasAccess($consoleOption) { - global $sqlCache; - - $returnVal = false; - $consoleInfo = $consoleOption->get_info_filtered(); - - if($this->intTableKeyValue != "") { - - if ( isset($sqlCache['console_members']) ) { - $result = sql_array_select_where( - $sqlCache['console_members'], - 'member_id', - $this->intTableKeyValue, - 'console_id', - $consoleInfo['console_id'] - ); - $num_rows = count($result); - } else { - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."console_members WHERE member_id = '".$this->intTableKeyValue."' AND console_id = '".$consoleInfo['console_id']."'"); - $num_rows = $result->num_rows; - } - - if($num_rows == 1) { - $accessInfo = $result; - - if($accessInfo['allowdeny'] == 1) { + + + function hasAccess($consoleOption) + { + global $sqlCache; + + $returnVal = false; + $consoleInfo = $consoleOption->get_info_filtered(); + + if ($this->intTableKeyValue != "") { + + if (isset($sqlCache['console_members'])) { + $result = sql_array_select_where( + $sqlCache['console_members'], + 'member_id', + $this->intTableKeyValue, + 'console_id', + $consoleInfo['console_id'] + ); + $num_rows = count($result); + } else { + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "console_members WHERE member_id = '" . $this->intTableKeyValue . "' AND console_id = '" . $consoleInfo['console_id'] . "'"); + $num_rows = $result->num_rows; + } + + if ($num_rows == 1) { + $accessInfo = $result; + + if ($accessInfo['allowdeny'] == 1) { + $returnVal = true; + } + } elseif ($num_rows == 0 && $consoleOption->hasAccess($this->arrObjInfo['rank_id'])) { $returnVal = true; } - } elseif($num_rows == 0 && $consoleOption->hasAccess($this->arrObjInfo['rank_id'])) { - $returnVal = true; } + + return $returnVal; + } - - return $returnVal; - - } - - - function getProfileValue($profileOptionID, $skipSelectOption=false) { - - $returnVal = ""; - if($this->intTableKeyValue != "" && is_numeric($this->intTableKeyValue)) { - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."profileoptions_values WHERE member_id = '".$this->intTableKeyValue."' AND profileoption_id = '".$profileOptionID."'"); - - if($result->num_rows == 1) { - - $row = $result->fetch_assoc(); - $returnVal = filterText($row['inputvalue']); - - $this->objProfileOption->select($profileOptionID); - - if($this->objProfileOption->isSelectOption() && !$skipSelectOption) { - // returnVal is currently just a selectopt_id - // Look up what the value is for the selectopt_id - - - $this->objProfileOption->objProfileOptionSelect->select($returnVal); - - $returnVal = $this->objProfileOption->objProfileOptionSelect->get_info_filtered("selectvalue"); - + + + function getProfileValue($profileOptionID, $skipSelectOption = false) + { + + $returnVal = ""; + if ($this->intTableKeyValue != "" && is_numeric($this->intTableKeyValue)) { + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "profileoptions_values WHERE member_id = '" . $this->intTableKeyValue . "' AND profileoption_id = '" . $profileOptionID . "'"); + + if ($result->num_rows == 1) { + + $row = $result->fetch_assoc(); + $returnVal = filterText($row['inputvalue']); + + $this->objProfileOption->select($profileOptionID); + + if ($this->objProfileOption->isSelectOption() && !$skipSelectOption) { + // returnVal is currently just a selectopt_id + // Look up what the value is for the selectopt_id + + + $this->objProfileOption->objProfileOptionSelect->select($returnVal); + + $returnVal = $this->objProfileOption->objProfileOptionSelect->get_info_filtered("selectvalue"); + + } + + + } else { + $returnVal = "Not Set"; } - - - - } - else { - $returnVal = "Not Set"; - } - } - - return $returnVal; - - } - - function setProfileValue($profileOptionID, $profileOptionValue) { - $returnVal = false; - if($this->intTableKeyValue != "" && is_numeric($this->intTableKeyValue)) { - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."profileoptions_values WHERE member_id = '".$this->intTableKeyValue."' AND profileoption_id = '".$profileOptionID."'"); - - if($result->num_rows == 1) { - $row = $result->fetch_assoc(); - $this->objProfileOption->objProfileOptionValue->select($row['values_id']); - $this->objProfileOption->objProfileOptionValue->delete(); - } - - - if($this->objProfileOption->objProfileOptionValue->addNew(array("profileoption_id", "member_id", "inputvalue"), array($profileOptionID, $this->intTableKeyValue, $profileOptionValue))) { - $returnVal = true; } - + return $returnVal; + } - - return $returnVal; - } - - - function getGameStatValue($gameStatID) { - - $returnVal = ""; - $gameStatObj = new Basic($this->MySQL, "gamestats", "gamestats_id"); - - if($this->intTableKeyValue != "" && $gameStatObj->select($gameStatID)) { - - $gameStatInfo = $gameStatObj->get_info_filtered(); - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."gamestats_members WHERE member_id = '".$this->intTableKeyValue."' AND gamestats_id = '".$gameStatID."'"); - - if($result->num_rows == 1) { - $row = $result->fetch_assoc(); - - if($gameStatInfo['textinput'] != 1) { - $returnVal = round($row['statvalue'], $gameStatInfo['decimalspots']); + function setProfileValue($profileOptionID, $profileOptionValue) + { + $returnVal = false; + if ($this->intTableKeyValue != "" && is_numeric($this->intTableKeyValue)) { + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "profileoptions_values WHERE member_id = '" . $this->intTableKeyValue . "' AND profileoption_id = '" . $profileOptionID . "'"); + + if ($result->num_rows == 1) { + $row = $result->fetch_assoc(); + $this->objProfileOption->objProfileOptionValue->select($row['values_id']); + $this->objProfileOption->objProfileOptionValue->delete(); } - else { - $returnVal = $row['stattext']; + + + if ($this->objProfileOption->objProfileOptionValue->addNew(array("profileoption_id", "member_id", "inputvalue"), array($profileOptionID, $this->intTableKeyValue, $profileOptionValue))) { + $returnVal = true; } - + + } - - + + return $returnVal; + } - - return $returnVal; - } - - - function getMemberLink($args=array("color" => true)) { - global $MAIN_ROOT; - $returnVal = ""; - if($this->intTableKeyValue != "" && is_numeric($this->intTableKeyValue)) { - - $memberRank = new Rank($this->MySQL); - $memberRankCat = new Basic($this->MySQL, "rankcategory", "rankcategory_id"); - $memberInfo = $this->get_info_filtered(); - - - $memberRank->select($memberInfo['rank_id']); - $rankInfo = $memberRank->get_info_filtered(); - - $memberRankCat->select($rankInfo['rankcategory_id']); - $memberColor = $memberRankCat->get_info_filtered("color"); - - if($args['color'] ?? '') { - $returnVal = "".$memberInfo['username'].""; - } - else { - $returnVal = "".$memberInfo['username'].""; + + + function getGameStatValue($gameStatID) + { + + $returnVal = ""; + $gameStatObj = new Basic($this->MySQL, "gamestats", "gamestats_id"); + + if ($this->intTableKeyValue != "" && $gameStatObj->select($gameStatID)) { + + $gameStatInfo = $gameStatObj->get_info_filtered(); + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "gamestats_members WHERE member_id = '" . $this->intTableKeyValue . "' AND gamestats_id = '" . $gameStatID . "'"); + + if ($result->num_rows == 1) { + $row = $result->fetch_assoc(); + + if ($gameStatInfo['textinput'] != 1) { + $returnVal = round($row['statvalue'], $gameStatInfo['decimalspots']); + } else { + $returnVal = $row['stattext']; + } + + } + + } - - - if( isset($args['wrapper']) && $args['wrapper'] === false ) { - $returnVal = MAIN_ROOT."profile.php?mID=".$this->intTableKeyValue; + + return $returnVal; + } + + + function getMemberLink($args = array("color" => true)) + { + global $MAIN_ROOT; + $returnVal = ""; + if ($this->intTableKeyValue != "" && is_numeric($this->intTableKeyValue)) { + + $memberRank = new Rank($this->MySQL); + $memberRankCat = new Basic($this->MySQL, "rankcategory", "rankcategory_id"); + $memberInfo = $this->get_info_filtered(); + + + $memberRank->select($memberInfo['rank_id']); + $rankInfo = $memberRank->get_info_filtered(); + + $memberRankCat->select($rankInfo['rankcategory_id']); + $memberColor = $memberRankCat->get_info_filtered("color"); + + if ($args['color'] ?? '') { + $returnVal = "" . $memberInfo['username'] . ""; + } else { + $returnVal = "" . $memberInfo['username'] . ""; + } + + + if (isset($args['wrapper']) && $args['wrapper'] === false) { + $returnVal = MAIN_ROOT . "profile.php?mID=" . $this->intTableKeyValue; + } + } - + + return $returnVal; + } - - return $returnVal; - - } - - - function postNotification($strMessage, $strIconType="general") { - - $returnVal = false; - - if($this->intTableKeyValue != "") { - $objNotification = new Basic($this->MySQL, "notifications", "notification_id"); - $time = time(); - $arrColumns = array("member_id", "datesent", "message", "icontype"); - $arrValues = array($this->intTableKeyValue, $time, $strMessage, $strIconType); - - if($objNotification->addNew($arrColumns, $arrValues)) { - $returnVal = true; + + + function postNotification($strMessage, $strIconType = "general") + { + + $returnVal = false; + + if ($this->intTableKeyValue != "") { + $objNotification = new Basic($this->MySQL, "notifications", "notification_id"); + $time = time(); + $arrColumns = array("member_id", "datesent", "message", "icontype"); + $arrValues = array($this->intTableKeyValue, $time, $strMessage, $strIconType); + + if ($objNotification->addNew($arrColumns, $arrValues)) { + $returnVal = true; + } + } - + + return $returnVal; + } - - return $returnVal; - - } - - function sendPM($to, $subject, $message, $replypmID=0, $arrGroups=array(), $email=false) { - - $returnVal = false; - - if($this->intTableKeyValue != "") { - $pmObj = new Basic($this->MySQL, "privatemessages", "pm_id"); - $toMemberObj = new Member($this->MySQL); - if(is_array($to)) { - // Multi Member PM - - $multiMemPMObj = new Basic($this->MySQL, "privatemessage_members", "pmmember_id"); - - $arrColumns = array("sender_id", "datesent", "subject", "message", "originalpm_id"); - $arrValues = array($this->intTableKeyValue, time(), $subject, $message, $replypmID); - - if($pmObj->addNew($arrColumns, $arrValues)) { - - $pmInfo = $pmObj->get_info(); - $arrBCC = array(); - $arrColumns = array("pm_id", "member_id", "grouptype", "group_id"); - foreach($to as $memberID) { - - $groupType = (is_array($arrGroups[$memberID])) ? $arrGroups[$memberID][0] : ""; - $groupID = (is_array($arrGroups[$memberID])) ? $arrGroups[$memberID][1] : ""; - - $arrValues = array($pmInfo['pm_id'], $memberID, $groupType, $groupID); - - $multiMemPMObj->addNew($arrColumns, $arrValues); - $toMemberObj->select($memberID); - $emailNotificationPM = $toMemberObj->getEmailNotificationSetting("privatemessage") == 1; - $blockedEmailPM = $toMemberObj->getEmailNotificationSetting("email_privatemessage") == 1; - if($toMemberObj->get_info("email") != "" && ($emailNotificationPM || ($email && !$blockedEmailPM))) { - $arrBCC[] = $toMemberObj->get_info("email"); + + function sendPM($to, $subject, $message, $replypmID = 0, $arrGroups = array(), $email = false) + { + + $returnVal = false; + + if ($this->intTableKeyValue != "") { + $pmObj = new Basic($this->MySQL, "privatemessages", "pm_id"); + $toMemberObj = new Member($this->MySQL); + if (is_array($to)) { + // Multi Member PM + + $multiMemPMObj = new Basic($this->MySQL, "privatemessage_members", "pmmember_id"); + + $arrColumns = array("sender_id", "datesent", "subject", "message", "originalpm_id"); + $arrValues = array($this->intTableKeyValue, time(), $subject, $message, $replypmID); + + if ($pmObj->addNew($arrColumns, $arrValues)) { + + $pmInfo = $pmObj->get_info(); + $arrBCC = array(); + $arrColumns = array("pm_id", "member_id", "grouptype", "group_id"); + foreach ($to as $memberID) { + + $groupType = (is_array($arrGroups[$memberID])) ? $arrGroups[$memberID][0] : ""; + $groupID = (is_array($arrGroups[$memberID])) ? $arrGroups[$memberID][1] : ""; + + $arrValues = array($pmInfo['pm_id'], $memberID, $groupType, $groupID); + + $multiMemPMObj->addNew($arrColumns, $arrValues); + $toMemberObj->select($memberID); + $emailNotificationPM = $toMemberObj->getEmailNotificationSetting("privatemessage") == 1; + $blockedEmailPM = $toMemberObj->getEmailNotificationSetting("email_privatemessage") == 1; + if ($toMemberObj->get_info("email") != "" && ($emailNotificationPM || ($email && !$blockedEmailPM))) { + $arrBCC[] = $toMemberObj->get_info("email"); + } + } - + + if (count(arrBCC) > 0) { + + $objMail = new btMail(); + $objMail->sendMail("", $subject, $message, array("from" => $this->arrObjInfo['email'], "bcc" => $arrBCC)); + + } + + $returnVal = true; } - - if(count(arrBCC) > 0) { - - $objMail = new btMail(); - $objMail->sendMail("", $subject, $message, array("from" => $this->arrObjInfo['email'], "bcc" => $arrBCC)); - + + } else { + + $arrColumns = array("sender_id", "receiver_id", "datesent", "subject", "message", "originalpm_id"); + $arrValues = array($this->intTableKeyValue, $to, time(), $subject, $message, $replypmID); + + if ($pmObj->addNew($arrColumns, $arrValues)) { + $toMemberObj->select($to); + if ($toMemberObj->getEmailNotificationSetting("privatemessage") == 1 || ($email && $toMemberObj->getEmailNotificationSetting("email_privatemessage") == 0)) { + $toMemberObj->email($subject, $message, $this->arrObjInfo['email']); + } + + $returnVal = true; + } - - $returnVal = true; + } - + } - else { - - $arrColumns = array("sender_id", "receiver_id", "datesent", "subject", "message", "originalpm_id"); - $arrValues = array($this->intTableKeyValue, $to, time(), $subject, $message, $replypmID); - - if($pmObj->addNew($arrColumns, $arrValues)) { - $toMemberObj->select($to); - if($toMemberObj->getEmailNotificationSetting("privatemessage") == 1 || ($email && $toMemberObj->getEmailNotificationSetting("email_privatemessage") == 0)) { - $toMemberObj->email($subject, $message, $this->arrObjInfo['email']); - } - - $returnVal = true; - + + return $returnVal; + + + } + + + function countPMs($showOnlyNew = false) + { + + $totalPMInbox = 0; + if ($this->intTableKeyValue != "") { + if ($showOnlyNew) { + $result1 = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "privatemessages WHERE receiver_id = '" . $this->intTableKeyValue . "' AND status = '0' AND deletereceiver = '0' AND receiverfolder_id = '0'"); + $result2 = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "privatemessage_members WHERE member_id = '" . $this->intTableKeyValue . "' AND seenstatus = '0' AND deletestatus = '0' AND pmfolder_id = '0'"); + } else { + $result1 = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "privatemessages WHERE receiver_id = '" . $this->intTableKeyValue . "' AND deletereceiver = '0' AND receiverfolder_id = '0'"); + $result2 = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "privatemessage_members WHERE member_id = '" . $this->intTableKeyValue . "' AND deletestatus = '0' AND pmfolder_id = '0'"); } - + + $totalSinglePM = $result1->num_rows; + $totalMultiPM = $result2->num_rows; + + + $totalPMInbox = $totalSinglePM + $totalMultiPM; } - + + return $totalPMInbox; + } - - return $returnVal; - - - } - - - function countPMs($showOnlyNew=false) { - - $totalPMInbox = 0; - if($this->intTableKeyValue != "") { - if($showOnlyNew) { - $result1 = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."privatemessages WHERE receiver_id = '".$this->intTableKeyValue."' AND status = '0' AND deletereceiver = '0' AND receiverfolder_id = '0'"); - $result2 = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."privatemessage_members WHERE member_id = '".$this->intTableKeyValue."' AND seenstatus = '0' AND deletestatus = '0' AND pmfolder_id = '0'"); - } - else { - $result1 = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."privatemessages WHERE receiver_id = '".$this->intTableKeyValue."' AND deletereceiver = '0' AND receiverfolder_id = '0'"); - $result2 = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."privatemessage_members WHERE member_id = '".$this->intTableKeyValue."' AND deletestatus = '0' AND pmfolder_id = '0'"); + + + function addProfileView() + { + + $returnVal = false; + if ($this->intTableKeyValue != "") { + + $profileViews = $this->arrObjInfo['profileviews']; + + $newProfileViews = $profileViews + 1; + + $this->update(array("profileviews"), array($newProfileViews)); + + $this->arrObjInfo['profileviews'] = $newProfileViews; + + $returnVal = true; } - - $totalSinglePM = $result1->num_rows; - $totalMultiPM = $result2->num_rows; - - - $totalPMInbox = $totalSinglePM+$totalMultiPM; - } - - return $totalPMInbox; - - } - - - function addProfileView() { - - $returnVal = false; - if($this->intTableKeyValue != "") { - - $profileViews = $this->arrObjInfo['profileviews']; - - $newProfileViews = $profileViews+1; - - $this->update(array("profileviews"), array($newProfileViews)); - - $this->arrObjInfo['profileviews'] = $newProfileViews; - - $returnVal = true; + + return $returnVal; + } - - return $returnVal; - - } - - function countRecruits($returnList=false) { - - $returnVal = 0; - if($this->intTableKeyValue != "") { - - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName." WHERE recruiter = '".$this->intTableKeyValue."' AND disabled = '0'"); - - if($returnList) { - - $returnArr = array(); - - while($row = $result->fetch_assoc()) { - - $returnArr[] = $row['member_id']; - + + function countRecruits($returnList = false) + { + + $returnVal = 0; + if ($this->intTableKeyValue != "") { + + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName . " WHERE recruiter = '" . $this->intTableKeyValue . "' AND disabled = '0'"); + + if ($returnList) { + + $returnArr = array(); + + while ($row = $result->fetch_assoc()) { + + $returnArr[] = $row['member_id']; + + } + + $returnVal = $returnArr; + + } else { + $returnVal = $result->num_rows; } - - $returnVal = $returnArr; - - } - else { - $returnVal = $result->num_rows; + } - + + + return $returnVal; + + } - - - return $returnVal; - - - } - - - /** - * - getMedalList Function - - * - * Returns an array of the selected member's medals. - * If $blnIDKeys is set to true, the medalmember_id will be used for the keys in the returned array. - * - */ - function getMedalList($blnIDKeys=false, $orderNumID=0) { - - $returnArr = array(); - if($this->intTableKeyValue != "") { - - switch($orderNumID) { - case 1: - $sqlDisplayOrder = "m.ordernum DESC"; - break; - case 2: - $sqlDisplayOrder = "m.name"; - break; - default: - $sqlDisplayOrder = "mm.dateawarded DESC"; - break; - } - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."medals_members mm, ".$this->MySQL->get_tablePrefix()."medals m WHERE member_id = '".$this->intTableKeyValue."' AND m.medal_id = mm.medal_id ORDER BY ".$sqlDisplayOrder); - while($row = $result->fetch_assoc()) { - - - if($blnIDKeys) { - $key = $row['medalmember_id']; - $returnArr[$key] = $row['medal_id']; + + + /** + * - getMedalList Function - + * + * Returns an array of the selected member's medals. + * If $blnIDKeys is set to true, the medalmember_id will be used for the keys in the returned array. + * + */ + function getMedalList($blnIDKeys = false, $orderNumID = 0) + { + + $returnArr = array(); + if ($this->intTableKeyValue != "") { + + switch ($orderNumID) { + case 1: + $sqlDisplayOrder = "m.ordernum DESC"; + break; + case 2: + $sqlDisplayOrder = "m.name"; + break; + default: + $sqlDisplayOrder = "mm.dateawarded DESC"; + break; } - else { - $returnArr[] = $row['medal_id']; + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "medals_members mm, " . $this->MySQL->get_tablePrefix() . "medals m WHERE member_id = '" . $this->intTableKeyValue . "' AND m.medal_id = mm.medal_id ORDER BY " . $sqlDisplayOrder); + while ($row = $result->fetch_assoc()) { + + + if ($blnIDKeys) { + $key = $row['medalmember_id']; + $returnArr[$key] = $row['medal_id']; + } else { + $returnArr[] = $row['medal_id']; + } + + } - - + + } - - + + return $returnArr; } - - return $returnArr; - } - - /** - * - autoAwardMedals Method - - * - * Awards the selected member a medal based on number of days in clan. - * - */ - function autoAwardMedals() { - - if($this->intTableKeyValue != "") { - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."medals WHERE autodays != '0' OR autorecruits != '0' ORDER BY ordernum DESC"); - while($row = $result->fetch_assoc()) { - $arrMedals[] = $row['medal_id']; - } - - $medalObj = new Medal($this->MySQL); - $awardMedalObj = new Basic($this->MySQL, "medals_members", "medalmember_id"); - foreach($arrMedals as $medalID) { - - $medalObj->select($medalID); - $arrMembers = $medalObj->getAssociateIDs(); - - $arrFrozenMembers = $medalObj->getFrozenMembersList(); - $frozenDate = 0; - if(in_array($this->intTableKeyValue, $arrFrozenMembers)) { - $frozenMedalID = array_search($this->intTableKeyValue, $arrFrozenMembers); - $medalObj->objFrozenMedal->select($frozenMedalID); - - $frozenDate = $medalObj->objFrozenMedal->get_info("freezetime"); - - } - - $daysInClan = (time() - $this->arrObjInfo['datejoined'])/86400; - - if($medalObj->get_info("autodays") != 0 && ($daysInClan >= $medalObj->get_info("autodays") && !in_array($this->intTableKeyValue, $arrMembers)) && time() > $frozenDate) { - $awardMedalObj->addNew(array("medal_id", "member_id", "dateawarded"), array($medalID, $this->intTableKeyValue, time())); - - $this->postNotification("You have been awarded the ".$medalObj->get_info_filtered("name")." for being the clan for ".$medalObj->get_info("autodays")." days."); - $this->logAction("Auto awarded medal for being in the clan for ".$medalObj->get_info("autodays")." days."); - + + /** + * - autoAwardMedals Method - + * + * Awards the selected member a medal based on number of days in clan. + * + */ + function autoAwardMedals() + { + + if ($this->intTableKeyValue != "") { + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "medals WHERE autodays != '0' OR autorecruits != '0' ORDER BY ordernum DESC"); + while ($row = $result->fetch_assoc()) { + $arrMedals[] = $row['medal_id']; } - - if($medalObj->get_info("autorecruits") != 0 && ($this->countRecruits() >= $medalObj->get_info("autorecruits") && !in_array($this->intTableKeyValue, $arrMembers)) && time() > $frozenDate) { - $awardMedalObj->addNew(array("medal_id", "member_id", "dateawarded"), array($medalID, $this->intTableKeyValue, time())); - - $this->postNotification("You have been awarded the ".$medalObj->get_info_filtered("name")." for recruiting ".$medalObj->get_info("autorecruits")." members."); - $this->logAction("Auto awarded medal for recruiting ".$medalObj->get_info("autorecruits")." members."); - + + $medalObj = new Medal($this->MySQL); + $awardMedalObj = new Basic($this->MySQL, "medals_members", "medalmember_id"); + foreach ($arrMedals as $medalID) { + + $medalObj->select($medalID); + $arrMembers = $medalObj->getAssociateIDs(); + + $arrFrozenMembers = $medalObj->getFrozenMembersList(); + $frozenDate = 0; + if (in_array($this->intTableKeyValue, $arrFrozenMembers)) { + $frozenMedalID = array_search($this->intTableKeyValue, $arrFrozenMembers); + $medalObj->objFrozenMedal->select($frozenMedalID); + + $frozenDate = $medalObj->objFrozenMedal->get_info("freezetime"); + + } + + $daysInClan = (time() - $this->arrObjInfo['datejoined']) / 86400; + + if ($medalObj->get_info("autodays") != 0 && ($daysInClan >= $medalObj->get_info("autodays") && !in_array($this->intTableKeyValue, $arrMembers)) && time() > $frozenDate) { + $awardMedalObj->addNew(array("medal_id", "member_id", "dateawarded"), array($medalID, $this->intTableKeyValue, time())); + + $this->postNotification("You have been awarded the " . $medalObj->get_info_filtered("name") . " for being the clan for " . $medalObj->get_info("autodays") . " days."); + $this->logAction("Auto awarded medal for being in the clan for " . $medalObj->get_info("autodays") . " days."); + + } + + if ($medalObj->get_info("autorecruits") != 0 && ($this->countRecruits() >= $medalObj->get_info("autorecruits") && !in_array($this->intTableKeyValue, $arrMembers)) && time() > $frozenDate) { + $awardMedalObj->addNew(array("medal_id", "member_id", "dateawarded"), array($medalID, $this->intTableKeyValue, time())); + + $this->postNotification("You have been awarded the " . $medalObj->get_info_filtered("name") . " for recruiting " . $medalObj->get_info("autorecruits") . " members."); + $this->logAction("Auto awarded medal for recruiting " . $medalObj->get_info("autorecruits") . " members."); + + } + + } - - - - + + } - - - + } - - } - - - /** - * - autoPromote Method - - * - * Awards the selected member a medal based on number of days in clan. - * - */ - function autoPromote() { - - if($this->intTableKeyValue != "") { - - $result = $this->MySQL->query("SELECT rank_id FROM ".$this->MySQL->get_tablePrefix()."ranks WHERE autodays != '0' ORDER BY ordernum DESC"); - while($row = $result->fetch_assoc()) { - $arrRanks[] = $row['rank_id']; - } - - $rankObj = new Rank($this->MySQL); - $rankObj->select($this->arrObjInfo['rank_id']); - $memberRankInfo = $rankObj->get_info(); - $daysInClan = (time() - $this->arrObjInfo['datejoined'])/86400; - foreach($arrRanks as $rankID) { - $rankObj->select($rankID); - if($rankObj->get_info("ordernum") > $memberRankInfo['ordernum'] && $memberRankInfo['rank_id'] != 1 && $daysInClan >= $rankObj->get_info("autodays") && time() > $this->arrObjInfo['freezerank']) { + /** + * - autoPromote Method - + * + * Awards the selected member a medal based on number of days in clan. + * + */ + function autoPromote() + { + + if ($this->intTableKeyValue != "") { + + $result = $this->MySQL->query("SELECT rank_id FROM " . $this->MySQL->get_tablePrefix() . "ranks WHERE autodays != '0' ORDER BY ordernum DESC"); + while ($row = $result->fetch_assoc()) { + $arrRanks[] = $row['rank_id']; + } + + $rankObj = new Rank($this->MySQL); + $rankObj->select($this->arrObjInfo['rank_id']); + $memberRankInfo = $rankObj->get_info(); + $daysInClan = (time() - $this->arrObjInfo['datejoined']) / 86400; + foreach ($arrRanks as $rankID) { + + $rankObj->select($rankID); + + if ($rankObj->get_info("ordernum") > $memberRankInfo['ordernum'] && $memberRankInfo['rank_id'] != 1 && $daysInClan >= $rankObj->get_info("autodays") && time() > $this->arrObjInfo['freezerank']) { + + if ($this->update(array("rank_id", "lastpromotion"), array($rankID, time()))) { + $this->logAction("Auto promoted for being in the clan for " . $rankObj->get_info("autodays") . " days."); + $memberRankInfo['ordernum'] = $rankObj->get_info("ordernum"); + } - if($this->update(array("rank_id", "lastpromotion"), array($rankID, time()))) { - $this->logAction("Auto promoted for being in the clan for ".$rankObj->get_info("autodays")." days."); - $memberRankInfo['ordernum'] = $rankObj->get_info("ordernum"); } - + } - + + } - - - + } - - } - - - public function awardMedal($medalID, $reason="") { - $returnVal = false; - if($this->intTableKeyValue != "") { - $medal = new Medal($this->MySQL); - $medalList = $this->getMedalList(); - if($medal->select($medalID) && !in_array($medalID, $medalList)) { - $medalMemberObj = new Basic($this->MySQL, "medals_members", "medalmember_id"); - $arrColumns = array("member_id", "medal_id", "dateawarded", "reason"); - $arrValues = array($this->intTableKeyValue, $medalID, time(), $reason); - if($medalMemberObj->addNew($arrColumns, $arrValues)) { - - $this->postNotification("You were awarded the medal: ".$medal->get_info_filtered("name").""); - + + + public function awardMedal($medalID, $reason = "") + { + $returnVal = false; + if ($this->intTableKeyValue != "") { + $medal = new Medal($this->MySQL); + $medalList = $this->getMedalList(); + if ($medal->select($medalID) && !in_array($medalID, $medalList)) { + $medalMemberObj = new Basic($this->MySQL, "medals_members", "medalmember_id"); + $arrColumns = array("member_id", "medal_id", "dateawarded", "reason"); + $arrValues = array($this->intTableKeyValue, $medalID, time(), $reason); + if ($medalMemberObj->addNew($arrColumns, $arrValues)) { + + $this->postNotification("You were awarded the medal: " . $medal->get_info_filtered("name") . ""); + + } + } - + } - + + return $returnVal; } - - return $returnVal; - } - - - /** - * - Log Action Method - - * - * Adds a new log entry into the logs involving this member's id - * - */ - - function logAction($message="") { - - $returnVal = false; - if($this->intTableKeyValue != "") { - $logObj = new Basic($this->MySQL, "logs", "log_id"); - - $arrColumns = array("member_id", "logdate", "message", "ipaddress"); - $arrValues = array($this->intTableKeyValue, time(), $message, $_SERVER['REMOTE_ADDR']); - - if($logObj->addNew($arrColumns, $arrValues)) { - $returnVal = true; + + + /** + * - Log Action Method - + * + * Adds a new log entry into the logs involving this member's id + * + */ + + function logAction($message = "") + { + + $returnVal = false; + if ($this->intTableKeyValue != "") { + $logObj = new Basic($this->MySQL, "logs", "log_id"); + + $arrColumns = array("member_id", "logdate", "message", "ipaddress"); + $arrValues = array($this->intTableKeyValue, time(), $message, $_SERVER['REMOTE_ADDR']); + + if ($logObj->addNew($arrColumns, $arrValues)) { + $returnVal = true; + } + + } - - + + return $returnVal; + } - - return $returnVal; - - } - - - /** - * - Select Admin Function - - * - * Selects the admin account - * - */ - function selectAdmin() { - - $returnVal= false; - $result = $this->MySQL->query("SELECT member_id FROM ".$this->strTableName." WHERE rank_id = '1'"); - $row = $result->fetch_assoc(); - - if($this->select($row['member_id'])) { - $returnVal = true; + + + /** + * - Select Admin Function - + * + * Selects the admin account + * + */ + function selectAdmin() + { + + $returnVal = false; + $result = $this->MySQL->query("SELECT member_id FROM " . $this->strTableName . " WHERE rank_id = '1'"); + $row = $result->fetch_assoc(); + + if ($this->select($row['member_id'])) { + $returnVal = true; + } + + + return $returnVal; + } - - return $returnVal; - - } - - - function get_privileges() { - - $returnArr= array(); - $filterArray = array(); - - $rankObj = new Rank($this->MySQL); - - if($this->intTableKeyValue != "") { - - $rankObj->select($this->arrObjInfo['rank_id']); - $arrPrivileges = $rankObj->get_privileges(); - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."console_members WHERE member_id = '".$this->intTableKeyValue."'"); - while($row = $result->fetch_assoc()) { - if($row['allowdeny'] == 1 && !in_array($row['console_id'], $arrPrivileges)) { - $arrPrivileges[] = $row['console_id']; + + function get_privileges() + { + + $returnArr = array(); + $filterArray = array(); + + $rankObj = new Rank($this->MySQL); + + if ($this->intTableKeyValue != "") { + + $rankObj->select($this->arrObjInfo['rank_id']); + $arrPrivileges = $rankObj->get_privileges(); + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "console_members WHERE member_id = '" . $this->intTableKeyValue . "'"); + while ($row = $result->fetch_assoc()) { + if ($row['allowdeny'] == 1 && !in_array($row['console_id'], $arrPrivileges)) { + $arrPrivileges[] = $row['console_id']; + } elseif ($row['allowdeny'] == 0 && in_array($row['console_id'], $arrPrivileges)) { + $key = array_search($row['console_id'], $arrPrivileges); + $arrPrivileges[$key] = 0; + } } - elseif($row['allowdeny'] == 0 && in_array($row['console_id'], $arrPrivileges)) { - $key = array_search($row['console_id'], $arrPrivileges); - $arrPrivileges[$key] = 0; + + + } + + return $arrPrivileges; + + } + + /** + * - hasSeenTopic Function - + * + * Returns true if the selected member has seen the forum topic. + */ + + public function hasSeenTopic($topicID) + { + + $returnVal = false; + + if ($this->intTableKeyValue != "" && $topicID != "" && is_numeric($topicID)) { + + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "forum_topicseen WHERE forumtopic_id = '" . $topicID . "' AND member_id = '" . $this->intTableKeyValue . "'"); + + if ($result->num_rows > 0) { + $returnVal = true; } + } - - - - + + + return $returnVal; + } - - return $arrPrivileges; - - } - - /** - * - hasSeenTopic Function - - * - * Returns true if the selected member has seen the forum topic. - */ - - public function hasSeenTopic($topicID) { - $returnVal = false; - if($this->intTableKeyValue != "" && $topicID != "" && is_numeric($topicID)) { - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."forum_topicseen WHERE forumtopic_id = '".$topicID."' AND member_id = '".$this->intTableKeyValue."'"); - - if($result->num_rows > 0) { - $returnVal = true; + public function countForumPosts() + { + $returnVal = 0; + if ($this->intTableKeyValue != "") { + + $result = $this->MySQL->query("SELECT member_id FROM " . $this->MySQL->get_tablePrefix() . "forum_post WHERE member_id = '" . $this->intTableKeyValue . "'"); + $returnVal = $result->num_rows; + } + return $returnVal; } - - - return $returnVal; - - } - - - public function countForumPosts() { - $returnVal = 0; - if($this->intTableKeyValue != "") { - - $result = $this->MySQL->query("SELECT member_id FROM ".$this->MySQL->get_tablePrefix()."forum_post WHERE member_id = '".$this->intTableKeyValue."'"); - $returnVal = $result->num_rows; - + + public function updateTableTime() + { + + $arrCallingInfo = debug_backtrace(); + if ($arrCallingInfo[1]['function'] == "addNew") { + parent::updateTableTime(); + } } - - return $returnVal; - } - - public function updateTableTime() { - - $arrCallingInfo = debug_backtrace(); - if($arrCallingInfo[1]['function'] == "addNew") { - parent::updateTableTime(); + + + public function requestedIA($returnID = false) + { + + $returnVal = false; + if ($this->intTableKeyValue != "") { + + $result = $this->MySQL->query("SELECT iarequest_id FROM " . $this->MySQL->get_tablePrefix() . "iarequest WHERE member_id = '" . $this->intTableKeyValue . "'"); + + if (!$returnID) { + $returnVal = ($result->num_rows > 0) ? true : false; + } else { + $row = $result->fetch_assoc(); + $returnVal = $row['iarequest_id']; + } + + } + + return $returnVal; } - } - - - public function requestedIA($returnID=false) { - - $returnVal = false; - if($this->intTableKeyValue != "") { - - $result = $this->MySQL->query("SELECT iarequest_id FROM ".$this->MySQL->get_tablePrefix()."iarequest WHERE member_id = '".$this->intTableKeyValue."'"); - - if(!$returnID) { - $returnVal = ($result->num_rows > 0) ? true : false; + + + protected function getMemberPicture($db_name, $defaultpic, $cssClass = array(), $setWidth = "", $setHeight = "") + { + global $MAIN_ROOT, $THEME; + + $avatarURL = ""; + + if (isset($this->arrObjInfo[$db_name])) { + $avatarURL = $this->arrObjInfo[$db_name]; + $checkURL = parse_url($avatarURL); + + if (!isset($checkURL['scheme']) || $checkURL['scheme'] == "") { + $avatarURL = $MAIN_ROOT . $this->arrObjInfo[$db_name]; + } + } else { + $avatarURL = $MAIN_ROOT . "themes/" . $THEME . "/images/" . $defaultpic; } - else { - $row = $result->fetch_assoc(); - $returnVal = $row['iarequest_id']; + + $arrStyle = array(); + if ($setWidth != "") { + $arrStyle['width'] = $setWidth; } - - } - - return $returnVal; - } - - - - - protected function getMemberPicture($setWidth="", $setHeight="", $db_name, $defaultpic, $cssClass=array()) { - global $MAIN_ROOT, $THEME; - - $checkURL = parse_url($this->arrObjInfo[$db_name]); - - $avatarURL = $this->arrObjInfo[$db_name]; - if($this->arrObjInfo[$db_name] == "") { - $avatarURL = $MAIN_ROOT."themes/".$THEME."/images/".$defaultpic; + + if ($setHeight != "") { + $arrStyle['height'] = $setHeight; + } + + $dispStyle = ""; + if (is_array($arrStyle) && count($arrStyle) > 0) { + $styleParts = array(); + foreach ($arrStyle as $attr => $value) { + // Ensure that $value is a string + $styleParts[] = $attr . ": " . (is_array($value) ? implode(" ", $value) : $value); + } + $dispStyle = " style='" . implode("; ", $styleParts) . "'"; + } + + // Ensure cssClass is an array + if (!is_array($cssClass)) { + $cssClass = array($cssClass); + } + + $dispClass = ""; + if (count($cssClass) > 0) { + $dispClass = " class='" . implode(" ", $cssClass) . "'"; + } + + return ""; } - elseif(!isset($checkURL['scheme']) || $checkURL['scheme'] = "") { - $avatarURL = $MAIN_ROOT.$this->arrObjInfo[$db_name]; + + public function getAvatar($setWidth = "", $setHeight = "") + { + return $this->getMemberPicture($setWidth, $setHeight, "avatar", "defaultavatar.png", array("avatarImg")); } - - $arrStyle = array(); - if($setWidth != "") { - $arrStyle['width'] = $setWidth; + + + public function getProfilePic($setWidth = "", $setHeight = "") + { + return $this->getMemberPicture($setWidth, $setHeight, "profilepic", "defaultprofile.png"); } - - if($setHeight != "") { - $arrStyle['height'] = $setHeight; + + public function getEmailNotificationSetting($notificationName) + { + + $emailNotificationSetting = new Basic($this->MySQL, "emailnotifications_settings", "emailnotificationsetting_id"); + + $emailNotificationSetting->selectByMulti(array("member_id" => $this->intTableKeyValue)); + + return $emailNotificationSetting->get_info($notificationName); + } - - $dispStyle = ""; - if(count($arrStyle) > 0) { - $dispStyle = " style='"; - foreach($arrStyle as $attr => $value) { - $dispStyle .= $attr.": ".$value.";"; + + public function delete() + { + $returnVal = false; + if ($this->intTableKeyValue != "") { + $info = $this->arrObjInfo; + + $returnVal = parent::delete(); + if ($returnVal) { + if ($info['profilepic'] != "") { + deleteFile(BASE_DIRECTORY . $info['profilepic']); + } + + if ($info['avatar'] != "") { + deleteFile(BASE_DIRECTORY . $info['avatar']); + } + } + } - $dispStyle .= "'"; + return $returnVal; } - - $dispClass = ""; - if(count($cssClass) > 0) { - $dispClass = " class='"; - foreach($cssClass as $class) { - $dispClass .= $class." "; + + + public function setEmailReminder($sendDate, $subject, $message, $updateID = 0) + { + + $emailReminder = new Basic($this->MySQL, "emailnotifications_queue", "emailnotificationsqueue_id"); + + if ($updateID == 0) { + $emailReminder->addNew(array("member_id", "senddate", "subject", "message"), array($this->intTableKeyValue, $sendDate, $subject, $message)); + } else { + $emailReminder->select($updateID); + $emailReminder->update(array("member_id", "senddate", "subject", "message"), array($this->intTableKeyValue, $sendDate, $subject, $message)); } - $dispClass .= "'"; + + return $emailReminder->get_info("emailnotificationsqueue_id"); } - - return ""; - - } - - public function getAvatar($setWidth="", $setHeight="") { - return $this->getMemberPicture($setWidth, $setHeight, "avatar", "defaultavatar.png", array("avatarImg")); - } - - - public function getProfilePic($setWidth="", $setHeight="") { - return $this->getMemberPicture($setWidth, $setHeight, "profilepic", "defaultprofile.png"); - } - - public function getEmailNotificationSetting($notificationName) { - - $emailNotificationSetting = new Basic($this->MySQL, "emailnotifications_settings", "emailnotificationsetting_id"); - - $emailNotificationSetting->selectByMulti(array("member_id" => $this->intTableKeyValue)); - - return $emailNotificationSetting->get_info($notificationName); - - } - - public function delete() { - $returnVal = false; - if($this->intTableKeyValue != "") { - $info = $this->arrObjInfo; - - $returnVal = parent::delete(); - if($returnVal) { - if($info['profilepic'] != "") { - deleteFile(BASE_DIRECTORY.$info['profilepic']); - } - - if($info['avatar'] != "") { - deleteFile(BASE_DIRECTORY.$info['avatar']); - } + + public function email($subject, $message, $from = "") + { + + if ($this->arrObjInfo['email'] != "") { + $objMail = new btMail(); + $objMail->sendMail($this->arrObjInfo['email'], $subject, $message, array("from" => $from)); + } - - } - return $returnVal; - } - - - public function setEmailReminder($sendDate, $subject, $message, $updateID=0) { - - $emailReminder = new Basic($this->MySQL, "emailnotifications_queue", "emailnotificationsqueue_id"); - - if($updateID == 0) { - $emailReminder->addNew(array("member_id", "senddate", "subject", "message"), array($this->intTableKeyValue, $sendDate, $subject, $message)); - } - else { - $emailReminder->select($updateID); - $emailReminder->update(array("member_id", "senddate", "subject", "message"), array($this->intTableKeyValue, $sendDate, $subject, $message)); - } - - return $emailReminder->get_info("emailnotificationsqueue_id"); - } - - public function email($subject, $message, $from="") { - if($this->arrObjInfo['email'] != "") { - $objMail = new btMail(); - $objMail->sendMail($this->arrObjInfo['email'], $subject, $message, array("from" => $from)); - } - + + } - - -} \ No newline at end of file diff --git a/src/classes/news.php b/src/classes/news.php index ab58f3de..077ce8a3 100644 --- a/src/classes/news.php +++ b/src/classes/news.php @@ -1,299 +1,308 @@ MySQL = $sqlConnection; - $this->strTableName = $this->MySQL->get_tablePrefix().$newsTableName; - $this->strTableKey = $newsTableKey; - - $this->strCommentTableName = $this->MySQL->get_tablePrefix().$commentTableName; - $this->strCommentTableKey = $commentTableKey; - - $this->objComment = new Basic($sqlConnection, $commentTableName, $this->strCommentTableKey); - - $this->consoleObj = new ConsoleOption($sqlConnection); - - $htmlInNewsCID = $this->consoleObj->findConsoleIDByName("HTML in News Posts"); - $this->consoleObj->select($htmlInNewsCID); - - $this->determinePrivateNewsStatus(); - } - - - - public function getComments($orderBY="") { - - $returnArr = array(); - - if($orderBY == "") { - $orderBY = " ORDER BY dateposted DESC"; + class News extends Basic + { + + + protected $strCommentTableName; + protected $strCommentTableKey; + public $objComment; + private $consoleObj; + private $blnViewPrivateNews; + + public function __construct($sqlConnection, $newsTableName = "news", $newsTableKey = "news_id", $commentTableName = "comments", $commentTableKey = "comment_id") + { + + $this->MySQL = $sqlConnection; + $this->strTableName = $this->MySQL->get_tablePrefix() . $newsTableName; + $this->strTableKey = $newsTableKey; + + $this->strCommentTableName = $this->MySQL->get_tablePrefix() . $commentTableName; + $this->strCommentTableKey = $commentTableKey; + + $this->objComment = new Basic($sqlConnection, $commentTableName, $this->strCommentTableKey); + + $this->consoleObj = new ConsoleOption($sqlConnection); + + $htmlInNewsCID = $this->consoleObj->findConsoleIDByName("HTML in News Posts"); + $this->consoleObj->select($htmlInNewsCID); + + $this->determinePrivateNewsStatus(); } - - if($this->intTableKeyValue != "") { - - - $result = $this->MySQL->query("SELECT * FROM ".$this->strCommentTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'".$orderBY); - while($row = $result->fetch_assoc()) { - $returnArr[] = $row[$this->strCommentTableKey]; + + + public function getComments($orderBY = "") + { + + $returnArr = array(); + + if ($orderBY == "") { + $orderBY = " ORDER BY dateposted DESC"; } - - } - - return $returnArr; - - } - - - public function countComments() { - - $returnVal = 0; - - if($this->intTableKeyValue != "") { - - $result = $this->MySQL->query("SELECT * FROM ".$this->strCommentTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - - $returnVal = $result->num_rows; - - - } - - return $returnVal; - - } - - - - public function postComment($intMemberID, $strMessage) { - - $returnVal = false; - - if(is_numeric($intMemberID) && $this->intTableKeyValue != "" && trim($strMessage) != "") { - - if($this->objComment->addNew(array($this->strTableKey, "member_id", "message", "dateposted"), array($this->intTableKeyValue, $intMemberID, $strMessage, time()))) { - $returnVal = true; + + if ($this->intTableKeyValue != "") { + + + $result = $this->MySQL->query("SELECT * FROM " . $this->strCommentTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'" . $orderBY); + while ($row = $result->fetch_assoc()) { + $returnArr[] = $row[$this->strCommentTableKey]; + } + } - + + return $returnArr; + } - - return $returnVal; - - } - - public function delete() { - - $returnVal = false; - if($this->intTableKeyValue != "") { - - - $result1 = $this->MySQL->query("DELETE FROM ".$this->strTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - $result2 = $this->MySQL->query("DELETE FROM ".$this->strCommentTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - - - if($result1 && $result2) { - $returnVal = true; + + public function countComments() + { + + $returnVal = 0; + + if ($this->intTableKeyValue != "") { + + $result = $this->MySQL->query("SELECT * FROM " . $this->strCommentTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + + $returnVal = $result->num_rows; + + } - + + return $returnVal; + } - - - return $returnVal; - - } - - - public function show() { - global $hooksObj; - if($this->intTableKeyValue != "") { - $member = new Member($this->MySQL); - $postInfo = $this->arrObjInfo; - - $checkHTMLAccess = ""; - if($member->select($postInfo['lasteditmember_id'])) { - $checkHTMLAccess = $member->hasAccess($this->consoleObj); - $dispLastEditTime = getPreciseTime($postInfo['lasteditdate']); - $dispLastEdit = "last edited by ".$member->getMemberLink()." - ".$dispLastEditTime.""; - } - - $dispNewsType = ""; - if($postInfo['newstype'] == 1) { - $dispNewsType = " - public"; + + + public function postComment($intMemberID, $strMessage) + { + + $returnVal = false; + + if (is_numeric($intMemberID) && $this->intTableKeyValue != "" && trim($strMessage) != "") { + + if ($this->objComment->addNew(array($this->strTableKey, "member_id", "message", "dateposted"), array($this->intTableKeyValue, $intMemberID, $strMessage, time()))) { + $returnVal = true; + } + } - elseif($postInfo['newstype'] == 2) { - $dispNewsType = " - private"; + + return $returnVal; + + } + + + public function delete() + { + + $returnVal = false; + if ($this->intTableKeyValue != "") { + + + $result1 = $this->MySQL->query("DELETE FROM " . $this->strTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + $result2 = $this->MySQL->query("DELETE FROM " . $this->strCommentTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + + + if ($result1 && $result2) { + $returnVal = true; + } + } - - - $member->select($postInfo['member_id']); - - $checkHTMLAccess = ($checkHTMLAccess == "") ? $member->hasAccess($this->consoleObj) : $checkHTMLAccess; - $dispNews = $checkHTMLAccess ? parseBBCode($postInfo['newspost']) : nl2br(parseBBCode(filterText($postInfo['newspost']))); - - $GLOBALS['news_post']['id'] = $this->intTableKeyValue; - $GLOBALS['news_post']['post'] = " + + + return $returnVal; + + } + + + public function show() + { + global $hooksObj; + if ($this->intTableKeyValue != "") { + $member = new Member($this->MySQL); + $postInfo = $this->arrObjInfo; + + $checkHTMLAccess = ""; + $dispLastEdit = ""; // Initialize $dispLastEdit + + if ($member->select($postInfo['lasteditmember_id'])) { + $checkHTMLAccess = $member->hasAccess($this->consoleObj); + $dispLastEditTime = getPreciseTime($postInfo['lasteditdate']); + $dispLastEdit = "last edited by " . $member->getMemberLink() . " - " . $dispLastEditTime . ""; + } + $dispNewsType = ""; + if ($postInfo['newstype'] == 1) { + $dispNewsType = " - public"; + } elseif ($postInfo['newstype'] == 2) { + $dispNewsType = " - private"; + } + + + $member->select($postInfo['member_id']); + + $checkHTMLAccess = ($checkHTMLAccess == "") ? $member->hasAccess($this->consoleObj) : $checkHTMLAccess; + $dispNews = $checkHTMLAccess ? parseBBCode($postInfo['newspost']) : nl2br(parseBBCode(filterText($postInfo['newspost']))); + + $GLOBALS['news_post']['id'] = $this->intTableKeyValue; + $GLOBALS['news_post']['post'] = " -
    +

    - ".$dispNews." + " . $dispNews . "
    -
    ".$dispLastEdit."
    -

    Comments (".$this->countComments().")

    +
    " . $dispLastEdit . "
    +

    Comments (" . $this->countComments() . ")

    "; - - $hooksObj->run("newspost_show"); - echo $GLOBALS['news_post']['post']; - - unset($GLOBALS['news_POST']); - - } - - } - - - public function calcPages($postType="") { - global $websiteInfo; - - if($postType != "") { - $newsPostSQL = "newstype = '".$postType."'"; - } - else { - $showPrivateSQL = $this->blnViewPrivateNews ? " OR newstype = '2'" : ""; - $newsPostSQL = "newstype = '1'".$showPrivateSQL; + + $hooksObj->run("newspost_show"); + echo $GLOBALS['news_post']['post']; + + unset($GLOBALS['news_POST']); + + } + } - - - $result = $this->MySQL->query("SELECT * FROM ".$this->strTableName." WHERE ".$newsPostSQL." ORDER BY dateposted DESC"); - $totalPosts = $result->num_rows; - - $websiteInfo['news_postsperpage'] = ($websiteInfo['news_postsperpage'] <= 0) ? 1 : $websiteInfo['news_postsperpage']; - - $totalPages = ceil($totalPosts/$websiteInfo['news_postsperpage']); - - return $totalPages; - - } - - - public function displayPageSelector($postType="", $pageURL="") { - - if(!isset($_GET['page'])) { $_GET['page'] = 1; } - $totalPages = $this->calcPages($postType); - - $dispLink = ($pageURL == "") ? MAIN_ROOT."news/?page=" : $pageURL; - - $pageSelector = new PageSelector(); - - $pageSelector->setPages($totalPages); - $pageSelector->setLink($dispLink); - - $pageSelector->setCurrentPage($_GET['page']); - - $pageSelector->show(); - - /* - if($_GET['page'] <= $totalPages) { - - $nextPage = $_GET['page']+1; - $prevPage = $_GET['page']-1; - - $dispLink = ($pageURL == "") ? MAIN_ROOT."news/?page=" : $pageURL; - - $dispPrevPage = ($prevPage > 0) ? "NEWER ENTRIES" : ""; - $dispNextPage = ($nextPage <= $totalPages) ? "OLDER ENTRIES" : ""; - - $pageSpacer = ($dispPrevPage != "" && $dispNextPage != "") ? "   |   " : ""; - - echo " -

    - ".$dispPrevPage.$pageSpacer.$dispNextPage." -

    - "; - }*/ - - } - - public function getPosts($postType="") { - global $websiteInfo; - - $totalPages = $this->calcPages($postType); - - if($postType != "") { - $newsPostSQL = "newstype = '".$postType."'"; + + + public function calcPages($postType = "") + { + global $websiteInfo; + + if ($postType != "") { + $newsPostSQL = "newstype = '" . $postType . "'"; + } else { + $showPrivateSQL = $this->blnViewPrivateNews ? " OR newstype = '2'" : ""; + $newsPostSQL = "newstype = '1'" . $showPrivateSQL; + } + + + $result = $this->MySQL->query("SELECT * FROM " . $this->strTableName . " WHERE " . $newsPostSQL . " ORDER BY dateposted DESC"); + $totalPosts = $result->num_rows; + + $websiteInfo['news_postsperpage'] = ($websiteInfo['news_postsperpage'] <= 0) ? 1 : $websiteInfo['news_postsperpage']; + + $totalPages = ceil($totalPosts / $websiteInfo['news_postsperpage']); + + return $totalPages; + } - else { - $showPrivateSQL = $this->blnViewPrivateNews ? " OR newstype = '2'" : ""; - $newsPostSQL = "newstype = '1'".$showPrivateSQL; + + + public function displayPageSelector($postType = "", $pageURL = "") + { + + if (!isset($_GET['page'])) { + $_GET['page'] = 1; + } + $totalPages = $this->calcPages($postType); + + $dispLink = ($pageURL == "") ? MAIN_ROOT . "news/?page=" : $pageURL; + + $pageSelector = new PageSelector(); + + $pageSelector->setPages($totalPages); + $pageSelector->setLink($dispLink); + + $pageSelector->setCurrentPage($_GET['page']); + + $pageSelector->show(); + + /* + if($_GET['page'] <= $totalPages) { + + $nextPage = $_GET['page']+1; + $prevPage = $_GET['page']-1; + + $dispLink = ($pageURL == "") ? MAIN_ROOT."news/?page=" : $pageURL; + + $dispPrevPage = ($prevPage > 0) ? "NEWER ENTRIES" : ""; + $dispNextPage = ($nextPage <= $totalPages) ? "OLDER ENTRIES" : ""; + + $pageSpacer = ($dispPrevPage != "" && $dispNextPage != "") ? "   |   " : ""; + + echo " +

    + ".$dispPrevPage.$pageSpacer.$dispNextPage." +

    + "; + }*/ + } - - - if(!isset($_GET['page']) || $_GET['page'] > $totalPages) { - $sqlLimit = " LIMIT 0, ".$websiteInfo['news_postsperpage']; - $_GET['page'] = 1; + + public function getPosts($postType = "") + { + global $websiteInfo; + + $totalPages = $this->calcPages($postType); + + if ($postType != "") { + $newsPostSQL = "newstype = '" . $postType . "'"; + } else { + $showPrivateSQL = $this->blnViewPrivateNews ? " OR newstype = '2'" : ""; + $newsPostSQL = "newstype = '1'" . $showPrivateSQL; + } + + + if (!isset($_GET['page']) || $_GET['page'] > $totalPages) { + $sqlLimit = " LIMIT 0, " . $websiteInfo['news_postsperpage']; + $_GET['page'] = 1; + } else { + $sqlLimit = " LIMIT " . ($_GET['page'] - 1) * $websiteInfo['news_postsperpage'] . ", " . $websiteInfo['news_postsperpage']; + } + + $returnArr = array(); + $result = $this->MySQL->query("SELECT news_id FROM " . $this->strTableName . " WHERE " . $newsPostSQL . " ORDER BY dateposted DESC " . $sqlLimit); + while ($row = $result->fetch_assoc()) { + $returnArr[] = $row; + } + + return $returnArr; + } - else { - $sqlLimit = " LIMIT ".($_GET['page']-1)*$websiteInfo['news_postsperpage'].", ".$websiteInfo['news_postsperpage']; + + private function determinePrivateNewsStatus() + { + $member = new Member($this->MySQL); + $member->select($_SESSION['btUsername']); + $consoleObj = new ConsoleOption($this->MySQL); + + $privateNewsCID = $consoleObj->findConsoleIDByName("View Private News"); + $consoleObj->select($privateNewsCID); + + $this->blnViewPrivateNews = ($member->authorizeLogin($_SESSION['btPassword']) && $member->hasAccess($consoleObj)); } - - $returnArr = array(); - $result = $this->MySQL->query("SELECT news_id FROM ".$this->strTableName." WHERE ".$newsPostSQL." ORDER BY dateposted DESC ".$sqlLimit); - while($row = $result->fetch_assoc()) { - $returnArr[] = $row; + + public function getHTMLNewsConsole() + { + return $this->consoleObj; } - return $returnArr; - } - - private function determinePrivateNewsStatus() { - $member = new Member($this->MySQL); - $member->select($_SESSION['btUsername']); - $consoleObj = new ConsoleOption($this->MySQL); - - $privateNewsCID = $consoleObj->findConsoleIDByName("View Private News"); - $consoleObj->select($privateNewsCID); - - $this->blnViewPrivateNews = ($member->authorizeLogin($_SESSION['btPassword']) && $member->hasAccess($consoleObj)); - } - - public function getHTMLNewsConsole() { - return $this->consoleObj; - } - -} \ No newline at end of file diff --git a/src/classes/pmfolder.php b/src/classes/pmfolder.php index 193caba8..23a4571f 100644 --- a/src/classes/pmfolder.php +++ b/src/classes/pmfolder.php @@ -1,122 +1,129 @@ MySQL = $sqlConnection; $this->strTableKey = "pmfolder_id"; - $this->strTableName = $this->MySQL->get_tablePrefix()."privatemessage_folders"; + $this->strTableName = $this->MySQL->get_tablePrefix() . "privatemessage_folders"; $this->intMemberID = 0; - + //$this->strAssociateKeyName = "pm_id"; //$this->strAssociateTableName = $this->MySQL->get_tablePrefix()."privatemessages"; - + $this->strCategoryKey = "member_id"; - + } - - public function select($intIDNum, $numericIDOnly = true) { + + public function select($intIDNum, $numericIDOnly = true) + { + $returnVal = false; // Initialize $returnVal $arrSpecialFolders = array("Inbox" => self::INBOX_ID, "Sent Messages" => self::SENTBOX_ID, "Trash" => self::TRASH_ID); - if(in_array($intIDNum, $arrSpecialFolders)) { + + if (in_array($intIDNum, $arrSpecialFolders)) { $this->arrObjInfo['name'] = array_search($intIDNum, $arrSpecialFolders); $this->intTableKeyValue = $intIDNum; - - } - else { - $returnVal = parent::select($intIDNum, numericIDOnly); + } else { + $returnVal = parent::select($intIDNum, $numericIDOnly); // Corrected typo here } - + return $returnVal; } - - function isMemberFolder() { + + + function isMemberFolder() + { $returnVal = false; - if(($this->intTableKeyValue != "" && $this->arrObjInfo['member_id'] == $this->intMemberID) || ($this->intTableKeyValue == 0 || $this->intTableKeyValue == -1 || $this->intTableKeyValue == -2)) { - $returnVal = true; + if (($this->intTableKeyValue != "" && $this->arrObjInfo['member_id'] == $this->intMemberID) || ($this->intTableKeyValue == 0 || $this->intTableKeyValue == -1 || $this->intTableKeyValue == -2)) { + $returnVal = true; } - + return $returnVal; } - - - function listFolders($memberID=0) { - if($memberID != 0) { + + function listFolders($memberID = 0) + { + + if ($memberID != 0) { $this->intMemberID = $memberID; } - + $returnArr = array(); - if(isset($this->intMemberID) && is_numeric($this->intMemberID)) { + if (isset($this->intMemberID) && is_numeric($this->intMemberID)) { - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."privatemessage_folders WHERE member_id = '".$this->intMemberID."' ORDER BY sortnum"); - while($row = $result->fetch_assoc()) { - $returnArr[$row['pmfolder_id']] = $row['name']; + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "privatemessage_folders WHERE member_id = '" . $this->intMemberID . "' ORDER BY sortnum"); + while ($row = $result->fetch_assoc()) { + $returnArr[$row['pmfolder_id']] = $row['name']; } - + } - + return $returnArr; - + } - - function getFolderContents() { - + + function getFolderContents() + { + $arrPM = array(); - $arrMultiPM = array(); - - if($this->intTableKeyValue !== "" && $this->intMemberID != 0) { - $pmTable = $this->MySQL->get_tablePrefix()."privatemessages"; - $pmMultiTable = $this->MySQL->get_tablePrefix()."privatemessage_members"; - - if($this->intTableKeyValue == -1) { - $filterSQL = "senderfolder_id = '".$this->intTableKeyValue."' AND sender_id = '".$this->intMemberID."' AND deletesender = '0'"; - } - else { - $filterSQL = "receiver_id = '".$this->intMemberID."' AND receiverfolder_id = '".$this->intTableKeyValue."' AND deletereceiver = '0'"; + $arrMultiPM = array(); + + if ($this->intTableKeyValue !== "" && $this->intMemberID != 0) { + $pmTable = $this->MySQL->get_tablePrefix() . "privatemessages"; + $pmMultiTable = $this->MySQL->get_tablePrefix() . "privatemessage_members"; + + if ($this->intTableKeyValue == -1) { + $filterSQL = "senderfolder_id = '" . $this->intTableKeyValue . "' AND sender_id = '" . $this->intMemberID . "' AND deletesender = '0'"; + } else { + $filterSQL = "receiver_id = '" . $this->intMemberID . "' AND receiverfolder_id = '" . $this->intTableKeyValue . "' AND deletereceiver = '0'"; } - - + + //echo "SELECT pm_id, datesent FROM ".$pmTable." WHERE (senderfolder_id = '".$this->intTableKeyValue."' AND sender_id = '".$this->intMemberID."' AND deletesender = '0') OR (receiver_id = '".$this->intMemberID."' AND receiverfolder_id = '".$this->intTableKeyValue."' AND deletereceiver = '0')"; - $result = $this->MySQL->query("SELECT pm_id, datesent FROM ".$pmTable." WHERE ".$filterSQL); - while($row = $result->fetch_assoc()) { + $result = $this->MySQL->query("SELECT pm_id, datesent FROM " . $pmTable . " WHERE " . $filterSQL); + while ($row = $result->fetch_assoc()) { $arrPM[$row['pm_id']] = $row['datesent']; } - - $result = $this->MySQL->query("SELECT ".$pmMultiTable.".pmmember_id, ".$pmMultiTable.".pm_id, ".$pmTable.".datesent FROM ".$pmTable.", ".$pmMultiTable." WHERE ".$pmMultiTable.".pm_id = ".$pmTable.".pm_id AND ".$pmMultiTable.".pmfolder_id = '".$this->intTableKeyValue."' AND ".$pmMultiTable.".deletestatus = '0' AND ".$pmMultiTable.".member_id = '".$this->intMemberID."'"); - while($row = $result->fetch_assoc()) { + + $result = $this->MySQL->query("SELECT " . $pmMultiTable . ".pmmember_id, " . $pmMultiTable . ".pm_id, " . $pmTable . ".datesent FROM " . $pmTable . ", " . $pmMultiTable . " WHERE " . $pmMultiTable . ".pm_id = " . $pmTable . ".pm_id AND " . $pmMultiTable . ".pmfolder_id = '" . $this->intTableKeyValue . "' AND " . $pmMultiTable . ".deletestatus = '0' AND " . $pmMultiTable . ".member_id = '" . $this->intMemberID . "'"); + while ($row = $result->fetch_assoc()) { $arrPM[$row['pm_id']] = $row['datesent']; $arrMultiPM[$row['pm_id']] = $row['pmmember_id']; - + } - + arsort($arrPM); - + } - + $returnArr = array($arrPM, $arrMultiPM); - + return $returnArr; } - - + + /** Used to select special folders (Inbox, Sent, Trash) */ - function setFolder($folderID) { - if(is_numeric($folderID)) { + function setFolder($folderID) + { + if (is_numeric($folderID)) { $this->intTableKeyValue = $folderID; } } - - - } \ No newline at end of file + + + } diff --git a/src/classes/privatemessage.php b/src/classes/privatemessage.php index 7118c68e..1ee703f2 100644 --- a/src/classes/privatemessage.php +++ b/src/classes/privatemessage.php @@ -1,124 +1,122 @@ MySQL = $sqlConnection; - $this->strTableKey = "pm_id"; - $this->strTableName = $this->MySQL->get_tablePrefix()."privatemessages"; - - $this->strAssociateTableName = $this->MySQL->get_tablePrefix()."privatemessage_members"; - $this->strAssociateKeyName = "pmmember_id"; - - - $this->multiMemPMObj = new Basic($sqlConnection, "privatemessage_members", "pmmember_id"); - - $this->memberObj = new Member($sqlConnection); - $this->rankCatObj = new RankCategory($sqlConnection); - $this->squadObj = new Squad($sqlConnection); - $this->tournamentObj = new Tournament($sqlConnection); - } - - - public function getRecipients($blnNameOnly=false) { - global $MAIN_ROOT; - $arrGroups = array(); - - if($this->intTableKeyValue != "" && $this->arrObjInfo['receiver_id'] == 0) { - $arrGroups['list'] = array(); + require_once("basicorder.php"); + require_once("member.php"); + require_once("rankcategory.php"); + require_once("squad.php"); + require_once("tournament.php"); + + class PrivateMessage extends BasicOrder + { + + public $multiMemPMObj; + public $memberObj; + public $rankCatObj; + public $squadObj; + public $tournamentObj; + + public function __construct($sqlConnection) + { + + $this->MySQL = $sqlConnection; + $this->strTableKey = "pm_id"; + $this->strTableName = $this->MySQL->get_tablePrefix() . "privatemessages"; + + $this->strAssociateTableName = $this->MySQL->get_tablePrefix() . "privatemessage_members"; + $this->strAssociateKeyName = "pmmember_id"; + + + $this->multiMemPMObj = new Basic($sqlConnection, "privatemessage_members", "pmmember_id"); + + $this->memberObj = new Member($sqlConnection); + $this->rankCatObj = new RankCategory($sqlConnection); + $this->squadObj = new Squad($sqlConnection); + $this->tournamentObj = new Tournament($sqlConnection); + } + + + public function getRecipients($blnNameOnly = false) + { + global $MAIN_ROOT; + $arrGroups = array(); + $arrGroups['list'] = array(); // Initialize 'list' to ensure it's always set $arrGroups['rank'] = array(); $arrGroups['squad'] = array(); $arrGroups['tournament'] = array(); $arrGroups['rankcategory'] = array(); - - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."privatemessage_members WHERE pm_id = '".$this->intTableKeyValue."'"); - while($row = $result->fetch_assoc()) { - if($row['grouptype'] != "" && !in_array($row['group_id'], $arrGroups[$row['grouptype']])) { - $arrGroups[$row['grouptype']][] = $row['group_id']; - $dispName = ""; - - switch($row['grouptype']) { - case "rankcategory": - $dispName = ($this->rankCatObj->select($row['group_id'])) ? $this->rankCatObj->get_info_filtered("name")." - Category" : ""; - break; - case "rank": - $dispName = ($this->memberObj->objRank->select($row['group_id'])) ? $this->memberObj->objRank->get_info_filtered("name")." - Rank" : ""; - break; - case "squad": - $dispName = ($this->squadObj->select($row['group_id'])) ? "".$this->squadObj->get_info_filtered("name")." Members" : ""; - break; - case "tournament": - $dispName = ($this->tournamentObj->select($row['group_id'])) ? "".$this->tournamentObj->get_info_filtered("name")." Players" : ""; - break; - } - if($dispName != "" && !$blnNameOnly) { - $arrGroups['list'][$row['pmmember_id']] = $row['member_id']; - } - elseif($dispName != "") { - $arrGroups['list'][] = $dispName; + if ($this->intTableKeyValue != "" && $this->arrObjInfo['receiver_id'] == 0) { + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "privatemessage_members WHERE pm_id = '" . $this->intTableKeyValue . "'"); + while ($row = $result->fetch_assoc()) { + if ($row['grouptype'] != "" && !in_array($row['group_id'], $arrGroups[$row['grouptype']])) { + $arrGroups[$row['grouptype']][] = $row['group_id']; + $dispName = ""; + + switch ($row['grouptype']) { + case "rankcategory": + $dispName = ($this->rankCatObj->select($row['group_id'])) ? $this->rankCatObj->get_info_filtered("name") . " - Category" : ""; + break; + case "rank": + $dispName = ($this->memberObj->objRank->select($row['group_id'])) ? $this->memberObj->objRank->get_info_filtered("name") . " - Rank" : ""; + break; + case "squad": + $dispName = ($this->squadObj->select($row['group_id'])) ? "" . $this->squadObj->get_info_filtered("name") . " Members" : ""; + break; + case "tournament": + $dispName = ($this->tournamentObj->select($row['group_id'])) ? "" . $this->tournamentObj->get_info_filtered("name") . " Players" : ""; + break; + } + + if ($dispName != "" && !$blnNameOnly) { + $arrGroups['list'][$row['pmmember_id']] = $row['member_id']; + } elseif ($dispName != "") { + $arrGroups['list'][] = $dispName; + } + + } elseif ($row['grouptype'] == "") { + $this->memberObj->select($row['member_id']); + if ($blnNameOnly) { + $arrGroups['list'][] = $this->memberObj->getMemberLink(); + } else { + $arrGroups['list'][] = $row['member_id']; + } } - } - elseif($row['grouptype'] == "") { - $this->memberObj->select($row['member_id']); - if($blnNameOnly) { - $arrGroups['list'][] = $this->memberObj->getMemberLink(); - } - else { - $arrGroups['list'][] = $row['member_id']; - } + + // Check if 'list' is set and not empty before trying to implode + if ($blnNameOnly && !empty($arrGroups['list'])) { + $arrGroups['list'] = implode(", ", $arrGroups['list']); } + + return $arrGroups['list']; } - - if($blnNameOnly) { - $arrGroups['list'] = implode(", ", $arrGroups['list']); - } - + } - - return $arrGroups['list']; - - } - - /** Gets folder based on Member ID */ - function getFolder($memberID, $multiPM=false) { - - $returnVal = ""; - - if($this->intTableKeyValue != "") { - - $arrRecipients = $this->getRecipients(); - - if($this->arrObjInfo['sender_id'] == $memberID && !$multiPM) { - $returnVal = $this->arrObjInfo['senderfolder_id']; - } - elseif($this->arrObjInfo['receiver_id'] == $memberID && !$multiPM) { - $returnVal = $this->arrObjInfo['receiverfolder_id']; - } - elseif($this->arrObjInfo['receiver_id'] == 0 && in_array($memberID, $arrRecipients)) { - $tempKey = array_search($memberID, $arrRecipients); - $this->multiMemPMObj->select($tempKey); - - $returnVal = $this->multiMemPMObj->get_info("pmfolder_id"); + + /** Gets folder based on Member ID */ + function getFolder($memberID, $multiPM = false) + { + + $returnVal = ""; + + if ($this->intTableKeyValue != "") { + + $arrRecipients = $this->getRecipients(); + + if ($this->arrObjInfo['sender_id'] == $memberID && !$multiPM) { + $returnVal = $this->arrObjInfo['senderfolder_id']; + } elseif ($this->arrObjInfo['receiver_id'] == $memberID && !$multiPM) { + $returnVal = $this->arrObjInfo['receiverfolder_id']; + } elseif ($this->arrObjInfo['receiver_id'] == 0 && in_array($memberID, $arrRecipients)) { + $tempKey = array_search($memberID, $arrRecipients); + $this->multiMemPMObj->select($tempKey); + + $returnVal = $this->multiMemPMObj->get_info("pmfolder_id"); + } + } - + + return $returnVal; } - - return $returnVal; + } - -} \ No newline at end of file diff --git a/src/classes/rank.php b/src/classes/rank.php index 24fa51dc..6ba7cde4 100644 --- a/src/classes/rank.php +++ b/src/classes/rank.php @@ -1,196 +1,204 @@ MySQL = $sqlConnection; - $this->strTableName = $this->MySQL->get_tablePrefix()."ranks"; - $this->strTableKey = "rank_id"; - $this->strAssociateTableName = $this->MySQL->get_tablePrefix()."members"; - $this->strAssociateKeyName = "member_id"; - } + /* + * BlueThrust Clan Scripts + * Copyright 2014 + * + * Author: Bluethrust Web Development + * E-mail: support@bluethrust.com + * Website: http://www.bluethrust.com + * + * License: http://www.bluethrust.com/license.php + * + */ + + + require_once("basicorder.php"); + + class Rank extends BasicOrder + { - - function get_privileges() { - - $arrPrivileges = array(); - - if($this->intTableKeyValue == 1) { - $result = $this->MySQL->query("SELECT console_id FROM ".$this->MySQL->get_tablePrefix()."console ORDER BY sortnum"); + + function __construct($sqlConnection) + { + $this->MySQL = $sqlConnection; + $this->strTableName = $this->MySQL->get_tablePrefix() . "ranks"; + $this->strTableKey = "rank_id"; + $this->strAssociateTableName = $this->MySQL->get_tablePrefix() . "members"; + $this->strAssociateKeyName = "member_id"; } - else { - $result = $this->MySQL->query("SELECT rp.console_id FROM ".$this->MySQL->get_tablePrefix()."rank_privileges rp, ".$this->MySQL->get_tablePrefix()."console c WHERE rank_id = '".$this->intTableKeyValue."' AND c.console_id = rp.console_id ORDER BY c.sortnum"); + + + function get_privileges() + { + + $arrPrivileges = array(); + + if ($this->intTableKeyValue == 1) { + $result = $this->MySQL->query("SELECT console_id FROM " . $this->MySQL->get_tablePrefix() . "console ORDER BY sortnum"); + } else { + $result = $this->MySQL->query("SELECT rp.console_id FROM " . $this->MySQL->get_tablePrefix() . "rank_privileges rp, " . $this->MySQL->get_tablePrefix() . "console c WHERE rank_id = '" . $this->intTableKeyValue . "' AND c.console_id = rp.console_id ORDER BY c.sortnum"); + } + + + while ($row = $result->fetch_assoc()) { + $arrPrivileges[] = $row['console_id']; + } + + + return $arrPrivileges; } - - - while($row = $result->fetch_assoc()) { - $arrPrivileges[] = $row['console_id']; + + /** + * - countMembers Function - + * + * + * Returns the number of members with the current selected rank + */ + function countMembers() + { + $result = $this->MySQL->query("SELECT * FROM " . $this->MySQL->get_tablePrefix() . "members WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + $num_rows = $result->num_rows; + + + return $num_rows; } - - - return $arrPrivileges; - } - - - /** - * - countMembers Function - - * - * - * Returns the number of members with the current selected rank - */ - function countMembers() { - $result = $this->MySQL->query("SELECT * FROM ".$this->MySQL->get_tablePrefix()."members WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - $num_rows = $result->num_rows; - - - return $num_rows; - } - - /** - * - getLocalImageURL Function - - * - * Used to determine if the image attached to the selected rank is a local image or external image. - * - * Returns FALSE when the image is an external url. - * Returns the local image address when the image is on the server. - * - */ - function getLocalImageURL() { - global $MAIN_ROOT; - $returnVal = false; - if($this->intTableKeyValue != "") { - - if(strpos($this->arrObjInfo['imageurl'], "http://") === false) { - - $returnVal = $this->arrObjInfo['imageurl']; - + + /** + * - getLocalImageURL Function - + * + * Used to determine if the image attached to the selected rank is a local image or external image. + * + * Returns FALSE when the image is an external url. + * Returns the local image address when the image is on the server. + * + */ + function getLocalImageURL() + { + global $MAIN_ROOT; + $returnVal = false; + if ($this->intTableKeyValue != "") { + + if (strpos($this->arrObjInfo['imageurl'], "http://") === false) { + + $returnVal = $this->arrObjInfo['imageurl']; + + } + } + return $returnVal; } - - return $returnVal; - } - - /** - * - Refresh Image Size Method - - * - * If imageheight and imagewidth are not set, this will find the actual size of the image and - * set it to the arrObjInfo['imagewidth'] and arrObjInfo['imageheight'] - * - */ - function refreshImageSize() { - if($this->intTableKeyValue != "") { - if ( $this->arrObjInfo['imageurl'] ) { - if($this->arrObjInfo['imagewidth'] == 0) { - $imageURL = $this->getLocalImageURL(); - - $imageSize = getimagesize($imageURL); - $this->arrObjInfo['imagewidth'] = $imageSize[0]; - } - - if($this->arrObjInfo['imageheight'] == 0) { - $imageURL = $this->getLocalImageURL(); - - $imageSize = getimagesize($imageURL); - $this->arrObjInfo['imageheight'] = $imageSize[1]; + + /** + * - Refresh Image Size Method - + * + * If imageheight and imagewidth are not set, this will find the actual size of the image and + * set it to the arrObjInfo['imagewidth'] and arrObjInfo['imageheight'] + * + */ + function refreshImageSize() + { + if ($this->intTableKeyValue != "") { + if ($this->arrObjInfo['imageurl']) { + if ($this->arrObjInfo['imagewidth'] == 0) { + $imageURL = $this->getLocalImageURL(); + + $imageSize = getimagesize($imageURL); + if ($imageSize !== false) { + $this->arrObjInfo['imagewidth'] = $imageSize[0]; + } + } + + if ($this->arrObjInfo['imageheight'] == 0) { + $imageURL = $this->getLocalImageURL(); + + $imageSize = getimagesize($imageURL); + if ($imageSize !== false) { + $this->arrObjInfo['imageheight'] = $imageSize[1]; + } + } } } } - } - - /** - * - delete Method - - * - * Special delete method for rank to also delete privilege permissions associated with this rank from the rank_privileges table. - */ - public function delete() { - - $returnVal = false; - if($this->intTableKeyValue != "") { - - - $imageURL = $this->getLocalImageURL(); - if($imageURL !== false) { - - deleteFile(BASE_DIRECTORY.$imageURL); - - } - - $result = $this->MySQL->query("DELETE FROM ".$this->MySQL->get_tablePrefix()."rank_privileges WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - $result = $this->MySQL->query("DELETE FROM ".$this->strTableName." WHERE ".$this->strTableKey." = '".$this->intTableKeyValue."'"); - $this->resortOrder(); - - if(!$this->MySQL->error) { - $returnVal = true; - } - else { - $this->MySQL->displayError("basic.php"); + + + /** + * - delete Method - + * + * Special delete method for rank to also delete privilege permissions associated with this rank from the rank_privileges table. + */ + public function delete() + { + + $returnVal = false; + if ($this->intTableKeyValue != "") { + + + $imageURL = $this->getLocalImageURL(); + if ($imageURL !== false) { + + deleteFile(BASE_DIRECTORY . $imageURL); + + } + + $result = $this->MySQL->query("DELETE FROM " . $this->MySQL->get_tablePrefix() . "rank_privileges WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + $result = $this->MySQL->query("DELETE FROM " . $this->strTableName . " WHERE " . $this->strTableKey . " = '" . $this->intTableKeyValue . "'"); + $this->resortOrder(); + + if (!$this->MySQL->error) { + $returnVal = true; + } else { + $this->MySQL->displayError("basic.php"); + } + } - + + return $returnVal; + } - - return $returnVal; - - } - - - public function get_info($returnSingleValue = "") { - global $MAIN_ROOT; - $result = parent::get_info($returnSingleValue); - - if( isset($result['imageurl']) && substr($result['imageurl'],0,4) != "http") { - if($returnSingleValue == "") { - - $fullImageURL = $MAIN_ROOT.$result['imageurl']; - $result['imageurl'] = $fullImageURL; - } - elseif($returnSingleValue == "imageurl") { - $fullImageURL = $MAIN_ROOT.$result; - $result = $fullImageURL; + + + public function get_info($returnSingleValue = "") + { + global $MAIN_ROOT; + $result = parent::get_info($returnSingleValue); + + if (isset($result['imageurl']) && substr($result['imageurl'], 0, 4) != "http") { + if ($returnSingleValue == "") { + + $fullImageURL = $MAIN_ROOT . $result['imageurl']; + $result['imageurl'] = $fullImageURL; + } elseif ($returnSingleValue == "imageurl") { + $fullImageURL = $MAIN_ROOT . $result; + $result = $fullImageURL; + } } + return $result; + } - return $result; - - } - - - public function get_info_filtered($returnSingleValue = "") { - global $MAIN_ROOT; - $result = parent::get_info_filtered($returnSingleValue); - - if( isset($result['imageurl']) && substr($result['imageurl'],0,4) != "http") { - if($returnSingleValue == "") { - - $fullImageURL = $MAIN_ROOT.$result['imageurl']; - $result['imageurl'] = $fullImageURL; - } - elseif($returnSingleValue == "imageurl") { - $fullImageURL = $MAIN_ROOT.$result; - $result = $fullImageURL; + + + public function get_info_filtered($returnSingleValue = "") + { + global $MAIN_ROOT; + $result = parent::get_info_filtered($returnSingleValue); + + if (isset($result['imageurl']) && substr($result['imageurl'], 0, 4) != "http") { + if ($returnSingleValue == "") { + + $fullImageURL = $MAIN_ROOT . $result['imageurl']; + $result['imageurl'] = $fullImageURL; + } elseif ($returnSingleValue == "imageurl") { + $fullImageURL = $MAIN_ROOT . $result; + $result = $fullImageURL; + } } + + return $result; + } - - return $result; - + + } - - -} \ No newline at end of file diff --git a/src/forum/recent.php b/src/forum/recent.php index 32b473b9..a64717db 100644 --- a/src/forum/recent.php +++ b/src/forum/recent.php @@ -1,112 +1,112 @@ setTitle("Recent Posts"); -$breadcrumbObj->addCrumb("Home", MAIN_ROOT); -$breadcrumbObj->addCrumb("Forum", MAIN_ROOT."forum"); -$breadcrumbObj->addCrumb("Recent Posts"); + $breadcrumbObj->setTitle("Recent Posts"); + $breadcrumbObj->addCrumb("Home", MAIN_ROOT); + $breadcrumbObj->addCrumb("Forum", MAIN_ROOT . "forum"); + $breadcrumbObj->addCrumb("Recent Posts"); -$PAGE_NAME = "Recent Forum Posts - "; + $PAGE_NAME = "Recent Forum Posts - "; -require_once(BASE_DIRECTORY."forum/templates/_header.php"); + require_once(BASE_DIRECTORY . "forum/templates/_header.php"); -$NUM_PER_PAGE = $websiteInfo['forum_postsperpage']; -if($member->select($_SESSION['btUsername']) && $member->authorizeLogin($_SESSION['btPassword'])) { - $memberInfo = $member->get_info_filtered(); - $LOGGED_IN = true; - $NUM_PER_PAGE = $memberInfo['postsperpage']; -} - -if($NUM_PER_PAGE == 0) { - $NUM_PER_PAGE = 25; -} - + $NUM_PER_PAGE = $websiteInfo['forum_postsperpage']; + if ($member->select($_SESSION['btUsername']) && $member->authorizeLogin($_SESSION['btPassword'])) { + $memberInfo = $member->get_info_filtered(); + $LOGGED_IN = true; + $NUM_PER_PAGE = $memberInfo['postsperpage']; + } -$accessableTopicsSQL = "SELECT forumtopic_id, forumboard_id FROM ".$dbprefix."forum_topic"; -$result = $mysqli->query($accessableTopicsSQL); -while($row = $result->fetch_assoc()) { - $boardObj->select($row['forumboard_id']); - if($boardObj->memberHasAccess($memberInfo)) { - $arrTopics[] = $row['forumtopic_id']; + if ($NUM_PER_PAGE == 0) { + $NUM_PER_PAGE = 25; } -} -$topicsFilterSQL = "('".implode("','", $arrTopics)."')"; + $arrTopics = []; -$totalPostsSQL = $mysqli->query("SELECT COUNT(*) as totalPosts FROM ".$dbprefix."forum_post WHERE forumtopic_id IN ".$topicsFilterSQL." ORDER BY dateposted"); -$totalPosts = $totalPostsSQL->fetch_assoc(); -$totalPosts = $totalPosts['totalPosts']; + $accessableTopicsSQL = "SELECT forumtopic_id, forumboard_id FROM " . $dbprefix . "forum_topic"; + $result = $mysqli->query($accessableTopicsSQL); + while ($row = $result->fetch_assoc()) { + $boardObj->select($row['forumboard_id']); + if ($boardObj->memberHasAccess($memberInfo)) { + $arrTopics[] = $row['forumtopic_id']; + } + } -if(!isset($_GET['pID']) || !is_numeric($_GET['pID'])) { - $intOffset = 0; - $_GET['pID'] = 1; -} -else { - $intOffset = $NUM_PER_PAGE*($_GET['pID']-1); -} + $topicsFilterSQL = "('" . implode("','", $arrTopics) . "')"; + $totalPostsSQL = $mysqli->query("SELECT COUNT(*) as totalPosts FROM " . $dbprefix . "forum_post WHERE forumtopic_id IN " . $topicsFilterSQL . " ORDER BY dateposted"); + $totalPosts = $totalPostsSQL->fetch_assoc(); + $totalPosts = $totalPosts['totalPosts']; + if (!isset($_GET['pID']) || !is_numeric($_GET['pID'])) { + $intOffset = 0; + $_GET['pID'] = 1; + } else { + $intOffset = $NUM_PER_PAGE * ($_GET['pID'] - 1); + } // Count Pages -$NUM_OF_PAGES = ceil($totalPosts/$NUM_PER_PAGE); + $NUM_OF_PAGES = ceil($totalPosts / $NUM_PER_PAGE); + + if ($NUM_OF_PAGES == 0) { + $NUM_OF_PAGES = 1; + } -if($NUM_OF_PAGES == 0) { - $NUM_OF_PAGES = 1; -} + $pageSelector = new PageSelector(); + $pageSelector->setPages($NUM_OF_PAGES); + $pageSelector->setCurrentPage($_GET['pID']); + $pageSelector->setLink(MAIN_ROOT . "forum/recent.php?pID="); -$pageSelector = new PageSelector(); -$pageSelector->setPages($NUM_OF_PAGES); -$pageSelector->setCurrentPage($_GET['pID']); -$pageSelector->setLink(MAIN_ROOT."forum/recent.php?pID="); + echo "
    "; + $pageSelector->show(); + echo "
    "; -echo "
    "; -$pageSelector->show(); -echo "
    "; + if ($NUM_OF_PAGES == 1) { + echo "

    "; + } -if($NUM_OF_PAGES == 1) { echo "

    "; } + $query = "SELECT * FROM " . $dbprefix . "forum_post WHERE forumtopic_id IN " . $topicsFilterSQL . " ORDER BY dateposted DESC LIMIT " . $intOffset . ", " . $NUM_PER_PAGE; + $result = $mysqli->query($query); -$query = "SELECT * FROM ".$dbprefix."forum_post WHERE forumtopic_id IN ".$topicsFilterSQL." ORDER BY dateposted DESC LIMIT ".$intOffset.", ".$NUM_PER_PAGE; -$result = $mysqli->query($query); + $count = 0; + while ($row = $result->fetch_assoc()) { + $count++; + $boardObj->objPost->select($row['forumpost_id']); + $topicInfo = $boardObj->objPost->getTopicInfo(true); + $boardObj->select($topicInfo['forumboard_id']); -$count = 0; -while($row = $result->fetch_assoc()) { - $count++; - $boardObj->objPost->select($row['forumpost_id']); - $topicInfo = $boardObj->objPost->getTopicInfo(true); - $boardObj->select($topicInfo['forumboard_id']); + echo "
    " . $boardObj->getLink(true) . " - " . $boardObj->objPost->getLink(true) . "
    "; + $boardObj->objPost->show(true); - echo "
    ".$boardObj->getLink(true)." - ".$boardObj->objPost->getLink(true)."
    "; - $boardObj->objPost->show(true); - - if($count != $result->num_rows) { - echo "

    "; + if ($count != $result->num_rows) { + echo "

    "; + } } -} -echo "
    "; -$pageSelector->show(); -echo "
    "; + echo "
    "; + $pageSelector->show(); + echo "
    "; -if($result->num_rows == 0) { + if ($result->num_rows == 0) { - echo " + echo "

    @@ -115,7 +115,7 @@

    "; - -} -require_once(BASE_DIRECTORY."forum/templates/_footer.php"); \ No newline at end of file + } + + require_once(BASE_DIRECTORY . "forum/templates/_footer.php"); diff --git a/src/forum/unread.php b/src/forum/unread.php index 32116401..15a218e7 100644 --- a/src/forum/unread.php +++ b/src/forum/unread.php @@ -1,117 +1,120 @@ -setTitle("Unread Posts"); -$breadcrumbObj->addCrumb("Home", MAIN_ROOT); -$breadcrumbObj->addCrumb("Forum", MAIN_ROOT."forum"); -$breadcrumbObj->addCrumb("Unread Posts"); + $breadcrumbObj->setTitle("Unread Posts"); + $breadcrumbObj->addCrumb("Home", MAIN_ROOT); + $breadcrumbObj->addCrumb("Forum", MAIN_ROOT . "forum"); + $breadcrumbObj->addCrumb("Unread Posts"); -$PAGE_NAME = "Recent Forum Posts - "; + $PAGE_NAME = "Recent Forum Posts - "; -require_once(BASE_DIRECTORY."forum/templates/_header.php"); + require_once(BASE_DIRECTORY . "forum/templates/_header.php"); + + $memberInfo = array("member_id" => 0); + $NUM_PER_PAGE = $websiteInfo['forum_postsperpage']; + if ($member->select($_SESSION['btUsername']) && $member->authorizeLogin($_SESSION['btPassword'])) { + $memberInfo = $member->get_info_filtered(); + $LOGGED_IN = true; + $NUM_PER_PAGE = $memberInfo['postsperpage']; + } -$memberInfo = array("member_id" => 0); -$NUM_PER_PAGE = $websiteInfo['forum_postsperpage']; -if($member->select($_SESSION['btUsername']) && $member->authorizeLogin($_SESSION['btPassword'])) { - $memberInfo = $member->get_info_filtered(); - $LOGGED_IN = true; - $NUM_PER_PAGE = $memberInfo['postsperpage']; -} + if ($NUM_PER_PAGE == 0) { + $NUM_PER_PAGE = 25; + } -if($NUM_PER_PAGE == 0) { - $NUM_PER_PAGE = 25; -} + $seenTopicsSQL = "SELECT forumtopic_id FROM " . $dbprefix . "forum_topicseen WHERE member_id = '" . $memberInfo['member_id'] . "'"; -$seenTopicsSQL = "SELECT forumtopic_id FROM ".$dbprefix."forum_topicseen WHERE member_id = '".$memberInfo['member_id']."'"; + $arrTopics = []; -$accessableTopicsSQL = "SELECT forumtopic_id, forumboard_id FROM ".$dbprefix."forum_topic WHERE forumtopic_id NOT IN (".$seenTopicsSQL.")"; -$result = $mysqli->query($accessableTopicsSQL); -while($row = $result->fetch_assoc()) { - $boardObj->select($row['forumboard_id']); - if($boardObj->memberHasAccess($memberInfo)) { - $arrTopics[] = $row['forumtopic_id']; + $accessableTopicsSQL = "SELECT forumtopic_id, forumboard_id FROM " . $dbprefix . "forum_topic WHERE forumtopic_id NOT IN (" . $seenTopicsSQL . ")"; + $result = $mysqli->query($accessableTopicsSQL); + while ($row = $result->fetch_assoc()) { + $boardObj->select($row['forumboard_id']); + if ($boardObj->memberHasAccess($memberInfo)) { + $arrTopics[] = $row['forumtopic_id']; + } } -} -$topicsFilterSQL = "('".implode("','", $arrTopics)."')"; + $topicsFilterSQL = "('" . implode("','", $arrTopics) . "')"; -$totalPostsSQL = $mysqli->query("SELECT COUNT(*) as totalPosts FROM ".$dbprefix."forum_post WHERE forumtopic_id IN ".$topicsFilterSQL." ORDER BY dateposted"); -$totalPosts = $totalPostsSQL->fetch_assoc(); -$totalPosts = $totalPosts['totalPosts']; + $totalPostsSQL = $mysqli->query("SELECT COUNT(*) as totalPosts FROM " . $dbprefix . "forum_post WHERE forumtopic_id IN " . $topicsFilterSQL . " ORDER BY dateposted"); + $totalPosts = $totalPostsSQL->fetch_assoc(); + $totalPosts = $totalPosts['totalPosts']; -if(!isset($_GET['pID']) || !is_numeric($_GET['pID'])) { - $intOffset = 0; - $_GET['pID'] = 1; -} -else { - $intOffset = $NUM_PER_PAGE*($_GET['pID']-1); -} + if (!isset($_GET['pID']) || !is_numeric($_GET['pID'])) { + $intOffset = 0; + $_GET['pID'] = 1; + } else { + $intOffset = $NUM_PER_PAGE * ($_GET['pID'] - 1); + } // Count Pages -$NUM_OF_PAGES = ceil($totalPosts/$NUM_PER_PAGE); + $NUM_OF_PAGES = ceil($totalPosts / $NUM_PER_PAGE); -if($NUM_OF_PAGES == 0) { - $NUM_OF_PAGES = 1; -} + if ($NUM_OF_PAGES == 0) { + $NUM_OF_PAGES = 1; + } -$pageSelector = new PageSelector(); -$pageSelector->setPages($NUM_OF_PAGES); -$pageSelector->setCurrentPage($_GET['pID']); -$pageSelector->setLink(MAIN_ROOT."forum/recent.php?pID="); + $pageSelector = new PageSelector(); + $pageSelector->setPages($NUM_OF_PAGES); + $pageSelector->setCurrentPage($_GET['pID']); + $pageSelector->setLink(MAIN_ROOT . "forum/recent.php?pID="); -echo "
    "; -$pageSelector->show(); -echo "
    "; + echo "
    "; + $pageSelector->show(); + echo "
    "; -if($NUM_OF_PAGES == 1) { echo "

    "; } + if ($NUM_OF_PAGES == 1) { + echo "

    "; + } -$query = "SELECT * FROM ".$dbprefix."forum_post WHERE forumtopic_id IN ".$topicsFilterSQL." ORDER BY dateposted DESC LIMIT ".$intOffset.", ".$NUM_PER_PAGE; -$result = $mysqli->query($query); + $query = "SELECT * FROM " . $dbprefix . "forum_post WHERE forumtopic_id IN " . $topicsFilterSQL . " ORDER BY dateposted DESC LIMIT " . $intOffset . ", " . $NUM_PER_PAGE; + $result = $mysqli->query($query); -$count = 0; -while($row = $result->fetch_assoc()) { - $count++; - $boardObj->objPost->select($row['forumpost_id']); - $topicInfo = $boardObj->objPost->getTopicInfo(true); - $boardObj->select($topicInfo['forumboard_id']); + $count = 0; + while ($row = $result->fetch_assoc()) { + $count++; + $boardObj->objPost->select($row['forumpost_id']); + $topicInfo = $boardObj->objPost->getTopicInfo(true); + $boardObj->select($topicInfo['forumboard_id']); - echo "
    ".$boardObj->getLink(true)." - ".$boardObj->objPost->getLink(true)."
    "; - $boardObj->objPost->show(true); - - if($count != $result->num_rows) { - echo "

    "; + echo "
    " . $boardObj->getLink(true) . " - " . $boardObj->objPost->getLink(true) . "
    "; + $boardObj->objPost->show(true); + + if ($count != $result->num_rows) { + echo "

    "; + } } -} -echo "
    "; -$pageSelector->show(); -echo "
    "; + echo "
    "; + $pageSelector->show(); + echo "
    "; -if($result->num_rows == 0) { + if ($result->num_rows == 0) { - echo " + echo "

    @@ -120,8 +123,8 @@

    "; - -} + + } -require_once(BASE_DIRECTORY."forum/templates/_footer.php"); \ No newline at end of file + require_once(BASE_DIRECTORY . "forum/templates/_footer.php"); diff --git a/src/members/console.managelist.list.php b/src/members/console.managelist.list.php index 4b4c3557..a81aadd9 100644 --- a/src/members/console.managelist.list.php +++ b/src/members/console.managelist.list.php @@ -12,118 +12,123 @@ * */ - if(!defined("LOGGED_IN") || !LOGGED_IN) { - + if (!defined("LOGGED_IN") || !LOGGED_IN) { + $setupManageListArgs = json_decode($_POST['listArgs'], true); require_once("../_setup.php"); - + + require_once("../_setup.php"); + $member = new Member($mysqli); $member->select($_SESSION['btUsername']); - + $consoleObj = new ConsoleOption($mysqli); - if(!$consoleObj->select($setupManageListArgs['console_id'])) { + $setupManageListArgs = json_decode($_POST['listArgs'], true); + + if (!$consoleObj->select($setupManageListArgs['console_id'])) { exit(); } - - if(!$member->authorizeLogin($_SESSION['btPassword']) || !$member->hasAccess($consoleObj)) { - exit(); + + if (!$member->authorizeLogin($_SESSION['btPassword']) || !$member->hasAccess($consoleObj)) { + exit(); + } + +// Ensure that 'actions' key exists and is an array + $actionsWidth = 0; + $titleWidth = 100; + if (isset($setupManageListArgs['actions']) && is_array($setupManageListArgs['actions'])) { + $actionsWidth = count($setupManageListArgs['actions']) * 6; + $titleWidth = 100 - $actionsWidth; } - - $actionsWidth = count($setupManageListArgs['actions'])*6; - $titleWidth = 100-($actionsWidth); } - echo " "; - $counter = 0; - foreach($setupManageListArgs['items'] as $itemInfo) { + $counter = 0; + foreach ($setupManageListArgs['items'] as $itemInfo) { - if($itemInfo['type'] == "listitem") { - - if($counter == 1) { - $addCSS = " alternateBGColor"; - $counter = 0; - } - else { - $addCSS = ""; - $counter = 1; - } - - echo " + if ($itemInfo['type'] == "listitem") { + + if ($counter == 1) { + $addCSS = " alternateBGColor"; + $counter = 0; + } else { + $addCSS = ""; + $counter = 1; + } + + echo " - + "; - - foreach($setupManageListArgs['actions'] as $actionTypes) { - $dispAction = ""; - switch($actionTypes) { - case "moveup": - $dispAction = !in_array("moveup", $itemInfo['actions']) ? "" : ""; - break; - case "movedown": - $dispAction = !in_array("movedown", $itemInfo['actions']) ? "" : ""; - break; - case "edit": - $dispAction = ""; - break; - case "delete": - $dispAction = ""; - break; - default: - $dispAction = call_user_func_array($actionTypes, array($itemInfo['item_id'])); - } - - echo " - - "; + + foreach ($setupManageListArgs['actions'] as $actionTypes) { + $dispAction = ""; + switch ($actionTypes) { + case "moveup": + $dispAction = !in_array("moveup", $itemInfo['actions']) ? "" : ""; + break; + case "movedown": + $dispAction = !in_array("movedown", $itemInfo['actions']) ? "" : ""; + break; + case "edit": + $dispAction = ""; + break; + case "delete": + $dispAction = ""; + break; + default: + $dispAction = call_user_func_array($actionTypes, array($itemInfo['item_id'])); } - - - echo ""; - - } - else { // Category Title - - $dispAddItemToCategory = ($itemInfo['add_to_cat_link'] == "") ? "" : ""; - + echo " + + "; + } + + + echo ""; + + } else { // Category Title + + $dispAddItemToCategory = ($itemInfo['add_to_cat_link'] == "") ? "" : ""; + + echo " - - + + "; - - } + } - + } + echo "
    ".$itemInfo['display_name']."" . $itemInfo['display_name'] . "".$dispAction."
    " . $dispAction . "
    ".$dispAddItemToCategory."" . $dispAddItemToCategory . "
    "; - - if(count($setupManageListArgs['items']) == 0) { - if(substr($setupManageListArgs['item_title'],-1) == ":") { - $noItemName = substr($setupManageListArgs['item_title'], 0, strlen($setupManageListArgs['item_title'])-1); - } - elseif($setupManageListArgs['item_title'] == "") { - $noItemName = "item"; + if (count($setupManageListArgs['items']) == 0) { + + if (substr($setupManageListArgs['item_title'], -1) == ":") { + $noItemName = substr($setupManageListArgs['item_title'], 0, strlen($setupManageListArgs['item_title']) - 1); + } elseif ($setupManageListArgs['item_title'] == "") { + $noItemName = "item"; } - + echo "

    - No ".strtolower($noItemName)."s added yet! + No " . strtolower($noItemName) . "s added yet!

    "; - - } \ No newline at end of file + + } diff --git a/src/members/console.managelist.php b/src/members/console.managelist.php index 08b3fd02..bed255e3 100644 --- a/src/members/console.managelist.php +++ b/src/members/console.managelist.php @@ -12,101 +12,92 @@ * */ - if(!defined("LOGGED_IN") || !LOGGED_IN) { die(""); } - - - $actionsWidth = count($setupManageListArgs['actions'])*6; - $titleWidth = 100-($actionsWidth); - - + if (!defined("LOGGED_IN") || !LOGGED_IN) { + die(""); + } + + + $actionsWidth = count($setupManageListArgs['actions']) * 6; + $titleWidth = 100 - ($actionsWidth); + + // Setup default values if not given - $actionsTitleName = ($setupManageListArgs['action_title'] == "") ? "Actions:" : $setupManageListArgs['action_title']; - $itemTitleName = ($setupManageListArgs['item_title'] == "") ? "Item:" : $setupManageListArgs['item_title']; - - $dispAddNewLink = (!isset($setupManageListArgs['add_new_link']['url']) || $setupManageListArgs['add_new_link']['url'] == "") ? "" : "» ".$setupManageListArgs['add_new_link']['name']." «"; - - $setupManageListArgs['list_div_name'] = ($setupManageListArgs['list_div_name'] == "") ? "manageListDiv" : $setupManageListArgs['list_div_name']; - - $setupManageListArgs['loading_spiral'] = ($setupManageListArgs['loading_spiral'] == "") ? "manageListLoadingSpiral" : $setupManageListArgs['loading_spiral']; - - - - + $actionsTitleName = $setupManageListArgs['action_title'] ?? "Actions:"; + $itemTitleName = $setupManageListArgs['item_title'] ?? "Item:"; + + $dispAddNewLink = (!isset($setupManageListArgs['add_new_link']['url']) || $setupManageListArgs['add_new_link']['url'] == "") ? "" : "» " . $setupManageListArgs['add_new_link']['name'] . " «"; + + $setupManageListArgs['list_div_name'] = $setupManageListArgs['list_div_name'] ?? "manageListDiv"; + $setupManageListArgs['loading_spiral'] = $setupManageListArgs['loading_spiral'] ?? "manageListLoadingSpiral"; + + // Display Manage List - + echo " - + - - + +
    ".$dispAddNewLink."

    " . $dispAddNewLink . "

    ".$itemTitleName."".$actionsTitleName."" . $itemTitleName . "" . $actionsTitleName . "
    -


    Loading...

    +


    Loading...

    -
    +
    "; - - require_once("console.managelist.list.php"); - + + require_once("console.managelist.list.php"); + $moveLink = $setupManageListArgs['move_link'] ?? "defaultMoveLink.php"; // Replace 'defaultMoveLink.php' with your default link echo "
    - "; \ No newline at end of file + "; diff --git a/src/members/include/admin/sitesettings_submit.php b/src/members/include/admin/sitesettings_submit.php index 9014dbb5..17680fd5 100644 --- a/src/members/include/admin/sitesettings_submit.php +++ b/src/members/include/admin/sitesettings_submit.php @@ -1,160 +1,156 @@ select($_SESSION['btUsername']); - -$submitSuccess = false; -$scrollTop = true; - -$cID = $consoleObj->findConsoleIDByName("Website Settings"); -$consoleObj->select($cID); - -if($member->authorizeLogin($_SESSION['btPassword'])) { - - - $memberInfo = $member->get_info(); - - if($member->hasAccess($consoleObj)) { - $countErrors = 0; - - - // Check Clan Name - - if(trim($_POST['clanName']) == "") { - $countErrors++; - $dispError .= "   · You must enter a name for your clan.
    "; - } - - // Check Theme - - - $arrThemes = scandir("../../../themes"); - $arrCheckTheme = array(); - foreach($arrThemes as $strTheme) { - - $themeURL = "../../../themes/".$strTheme; - - if(is_dir($themeURL) && $strTheme != "." && $strTheme != "..") { - $arrCheckTheme[] = $strTheme; + /* + * BlueThrust Clan Scripts + * Copyright 2014 + * + * Author: Bluethrust Web Development + * E-mail: support@bluethrust.com + * Website: http://www.bluethrust.com + * + * License: http://www.bluethrust.com/license.php + * + */ + + require_once("../_setup.php"); + require_once("../classes/member.php"); + require_once("../classes/rank.php"); + require_once("../classes/consoleoption.php"); + + $consoleObj = new ConsoleOption($mysqli); + $member = new Member($mysqli); + $member->select($_SESSION['btUsername']); + + $submitSuccess = false; + $scrollTop = true; + + $cID = $consoleObj->findConsoleIDByName("Website Settings"); + $consoleObj->select($cID); + + if ($member->authorizeLogin($_SESSION['btPassword'])) { + + + $memberInfo = $member->get_info(); + + if ($member->hasAccess($consoleObj)) { + $countErrors = 0; + + + // Check Clan Name + + if (trim($_POST['clanName']) == "") { + $countErrors++; + $dispError .= "   · You must enter a name for your clan.
    "; } - } - if(!in_array($_POST['themeName'], $arrCheckTheme)) { - $countErrors++; - $dispError .= "   · You selected an invalid theme.
    "; - } - - - // Check Max Diplomacy - - if(!is_numeric($_POST['maxDiplomacy']) || (is_numeric($_POST['maxDiplomacy']) && $_POST['maxDiplomacy'] < 0)) { - $countErrors++; - $dispError .= "   · You must enter postive number or zero for max diplomacy requests.
    "; - } - - // Check Failed Logins - - if(!is_numeric($_POST['failedLogins']) || (is_numeric($_POST['failedLogins']) && $_POST['failedLogins'] < 0)) { - $countErrors++; - $dispError .= "   · You must enter postive number or zero for failed login attempts.
    "; - } - - // Check Max Days - - if($_POST['maxDSL'] != "" && (!is_numeric($_POST['maxDSL']) || (is_numeric($_POST['maxDSL']) && $_POST['maxDSL'] < 0))) { - $countErrors++; - $dispError .= "   · You must enter postive number or zero for max days.
    "; - } - - // Check Medal Order - - $arrCheckMedalOrder = array(0, 1, 2); - if(!in_array($_POST['medalOrder'], $arrCheckMedalOrder)) { - $countErrors++; - $dispError .= "   · You selected an invalid medal display order.
    "; - } - - if($_POST['debugMode'] != 1) { - $_POST['debugMode'] = 0; - } - - - if($_POST['hideInactive'] != 1) { - $_POST['hideInactive'] = 0; - } - - $numOfNewsPosts = 0; - if($_POST['showHPNews'] == "yes" && $_POST['numOfNewsPosts'] == "custom" && is_numeric($_POST['customNewsAmount']) && $_POST['customNewsAmount'] > 0) { - $numOfNewsPosts = $_POST['customNewsAmount']; - } - elseif($_POST['showHPNews'] == "yes" && $_POST['numOfNewsPosts'] == "all") { - $numOfNewsPosts = -1; - } - elseif($_POST['showHPNews'] == "yes" && is_numeric($_POST['numOfNewsPosts']) && $_POST['numOfNewsPosts'] > 0) { - $numOfNewsPosts = $_POST['numOfNewsPosts']; - } - - if(!is_numeric($_POST['newsPostsPerPage']) || $_POST['newsPostsPerPage'] < 0) { - $countErrors++; - $dispError .= "   · News Posts Per Page must be a positive numeric value."; - } - - if(!is_numeric($_POST['emailqueue_delay']) || $_POST['emailqueue_delay'] < 5) { - $countErrors++; - $dispError .= "   · E-mail queue delay must be a at least 5 minutes."; - } - - - if($countErrors == 0) { - - $updateSettings = array("clanname", "clantag", "logourl", "theme", "maxdiplomacy", "failedlogins", "maxdsl", "lowdsl", "meddsl", "highdsl", "medalorder", "debugmode", "hideinactive", "hpnews", "news_postsperpage", "emailqueue_delay"); - $updateSettingVals = array($_POST['clanName'], $_POST['clanTag'], $_POST['logoURL'], $_POST['themeName'], $_POST['maxDiplomacy'], $_POST['failedLogins'], $_POST['maxDSL'], $_POST['lowDSL'], $_POST['medDSL'], $_POST['highDSL'], $_POST['medalOrder'], $_POST['debugMode'], $_POST['hideInactive'], $numOfNewsPosts, $_POST['newsPostsPerPage'], $_POST['emailqueue_delay']); - - - if(!$webInfoObj->multiUpdate($updateSettings, $updateSettingVals)) { + // Check Theme + + + $arrThemes = scandir("../../../themes"); + $arrCheckTheme = array(); + foreach ($arrThemes as $strTheme) { + + $themeURL = "../../../themes/" . $strTheme; + + if (is_dir($themeURL) && $strTheme != "." && $strTheme != "..") { + $arrCheckTheme[] = $strTheme; + } + } + + if (!in_array($_POST['themeName'], $arrCheckTheme)) { $countErrors++; - $dispError .= "   · Unable to save the information to the database.
    "; + $dispError .= "   · You selected an invalid theme.
    "; } - - } - - - - if($countErrors == 0) { - $dispTime = date("l F j, Y g:i:s A"); - echo " + + + // Check Max Diplomacy + + if (!is_numeric($_POST['maxDiplomacy']) || (is_numeric($_POST['maxDiplomacy']) && $_POST['maxDiplomacy'] < 0)) { + $countErrors++; + $dispError .= "   · You must enter postive number or zero for max diplomacy requests.
    "; + } + + // Check Failed Logins + + if (!is_numeric($_POST['failedLogins']) || (is_numeric($_POST['failedLogins']) && $_POST['failedLogins'] < 0)) { + $countErrors++; + $dispError .= "   · You must enter postive number or zero for failed login attempts.
    "; + } + + // Check Max Days + + if ($_POST['maxDSL'] != "" && (!is_numeric($_POST['maxDSL']) || (is_numeric($_POST['maxDSL']) && $_POST['maxDSL'] < 0))) { + $countErrors++; + $dispError .= "   · You must enter postive number or zero for max days.
    "; + } + + // Check Medal Order + + $arrCheckMedalOrder = array(0, 1, 2); + if (!in_array($_POST['medalOrder'], $arrCheckMedalOrder)) { + $countErrors++; + $dispError .= "   · You selected an invalid medal display order.
    "; + } + + if ($_POST['debugMode'] != 1) { + $_POST['debugMode'] = 0; + } + + + if ($_POST['hideInactive'] != 1) { + $_POST['hideInactive'] = 0; + } + + $numOfNewsPosts = 0; + if ($_POST['showHPNews'] == "yes" && $_POST['numOfNewsPosts'] == "custom" && is_numeric($_POST['customNewsAmount']) && $_POST['customNewsAmount'] > 0) { + $numOfNewsPosts = $_POST['customNewsAmount']; + } elseif ($_POST['showHPNews'] == "yes" && $_POST['numOfNewsPosts'] == "all") { + $numOfNewsPosts = -1; + } elseif ($_POST['showHPNews'] == "yes" && is_numeric($_POST['numOfNewsPosts']) && $_POST['numOfNewsPosts'] > 0) { + $numOfNewsPosts = $_POST['numOfNewsPosts']; + } + + if (!is_numeric($_POST['newsPostsPerPage']) || $_POST['newsPostsPerPage'] < 0) { + $countErrors++; + $dispError .= "   · News Posts Per Page must be a positive numeric value."; + } + + if (!is_numeric($_POST['emailqueue_delay']) || $_POST['emailqueue_delay'] < 5) { + $countErrors++; + $dispError .= "   · E-mail queue delay must be a at least 5 minutes."; + } + + + if ($countErrors == 0) { + + $updateSettings = array("clanname", "clantag", "logourl", "theme", "maxdiplomacy", "failedlogins", "maxdsl", "lowdsl", "meddsl", "highdsl", "medalorder", "debugmode", "hideinactive", "hpnews", "news_postsperpage", "emailqueue_delay"); + $updateSettingVals = array($_POST['clanName'], $_POST['clanTag'], $_POST['logoURL'], $_POST['themeName'], $_POST['maxDiplomacy'], $_POST['failedLogins'], $_POST['maxDSL'], $_POST['lowDSL'], $_POST['medDSL'], $_POST['highDSL'], $_POST['medalOrder'], $_POST['debugMode'], $_POST['hideInactive'], $numOfNewsPosts, $_POST['newsPostsPerPage'], $_POST['emailqueue_delay']); + + + if (!$webInfoObj->multiUpdate($updateSettings, $updateSettingVals)) { + $countErrors++; + $dispError .= "   · Unable to save the information to the database.
    "; + } + + } + + + if ($countErrors == 0) { + $dispTime = date("l F j, Y g:i:s A"); + echo " "; - - } - else { - echo " + + } else { + echo " "; + } + } - } -} \ No newline at end of file diff --git a/src/members/include/polls/createpoll.php b/src/members/include/polls/createpoll.php index 219338fe..59be5edc 100644 --- a/src/members/include/polls/createpoll.php +++ b/src/members/include/polls/createpoll.php @@ -1,128 +1,124 @@ get_info(); - $consoleObj->select($_GET['cID']); - if(!$member->hasAccess($consoleObj)) { + /* + * BlueThrust Clan Scripts + * Copyright 2014 + * + * Author: Bluethrust Web Development + * E-mail: support@bluethrust.com + * Website: http://www.bluethrust.com + * + * License: http://www.bluethrust.com/license.php + * + */ + + if (!isset($member) || substr($_SERVER['PHP_SELF'], -11) != "console.php") { exit(); + } else { + $memberInfo = $member->get_info(); + $consoleObj->select($_GET['cID']); + if (!$member->hasAccess($consoleObj)) { + exit(); + } } -} -require_once("../classes/access.php"); -require_once("../classes/poll.php"); + require_once("../classes/access.php"); + require_once("../classes/poll.php"); -$cID = $_GET['cID']; + $cID = $_GET['cID']; -$dispError = ""; -$countErrors = 0; + $dispError = ""; + $countErrors = 0; + $pollObj = new Poll($mysqli); + $accessObj = $pollObj->objAccess; -$pollObj = new Poll($mysqli); -$accessObj = $pollObj->objAccess; + if (isset($_POST['accessCacheID'])) { + $accessObj->cacheID = $_POST['accessCacheID']; + } -if(isset($_POST['accessCacheID'])) { - $accessObj->cacheID = $_POST['accessCacheID']; -} + $_SESSION['btAccessCacheTables'][$accessObj->cacheID] = json_encode($accessObj->arrAccessTables); + $_SESSION['btAccessCacheTypes'][$accessObj->cacheID] = json_encode($accessObj->arrAccessTypes); -$_SESSION['btAccessCacheTables'][$accessObj->cacheID] = json_encode($accessObj->arrAccessTables); -$_SESSION['btAccessCacheTypes'][$accessObj->cacheID] = json_encode($accessObj->arrAccessTypes); + $arrPostSelected = array(); -$arrPostSelected = array(); + if (!empty($_POST['submit'])) { -if ( ! empty($_POST['submit']) ) { - - // Check Question - if(trim($_POST['pollquestion']) == "") { - $countErrors++; - $dispError .= "   · Your poll question may not be blank.
    "; - } - - // Check Access Types - $arrCheckAccessTypes = array("members", "memberslimited", "public"); - if(!in_array($_POST['accesstype'], $arrCheckAccessTypes)) { - $countErrors++; - $dispError .= "   · You selected an invalid access type.
    "; - } - + // Check Question + if (trim($_POST['pollquestion']) == "") { + $countErrors++; + $dispError .= "   · Your poll question may not be blank.
    "; + } - // Check Result Visibility - $arrCheckVisTypes = array("open", "votedonly", "pollend", "never"); - if(!in_array($_POST['resultvisibility'], $arrCheckVisTypes)) { - $countErrors++; - $dispError .= "   · You selected an invalid result visibility type.
    "; - } - - // Check Max Votes - - if($_POST['maxvotes'] != "" && (!is_numeric($_POST['maxvotes']) || $_POST['maxvotes'] < 0)) { - $countErrors++; - $dispError .= "   · Max votes per user must be a value greater than zero.
    "; - } - - // Check Poll End - - if($_POST['enddate'] != "forever" && $_POST['enddate'] != "choose") { - $countErrors++; - $dispError .= "   · You selected an invalid poll end date.
    "; - } - elseif($_POST['enddate'] == "choose" && (!is_numeric($_POST['realenddate']) || $_POST['realenddate'] <= 0)) { - $countErrors++; - $dispError .= "   · You selected an invalid poll end date.
    "; - } - - - - if($countErrors == 0) { - - $setEndDate = 0; - if($_POST['enddate'] == "choose") { - $setEndDate = $_POST['realenddate']/1000; - $tempYear = date("Y", $setEndDate); - $tempMonth = date("n", $setEndDate); - $tempDay = date("j", $setEndDate); - $tempHour = $_POST['endhour']; - if($_POST['endAMPM'] == "PM") { - $tempHour += 12; - } - - $setEndDate = mktime($tempHour, $_POST['endminute'], 0, $tempMonth, $tempDay, $tempYear); + // Check Access Types + $arrCheckAccessTypes = array("members", "memberslimited", "public"); + if (!in_array($_POST['accesstype'], $arrCheckAccessTypes)) { + $countErrors++; + $dispError .= "   · You selected an invalid access type.
    "; } - - - $_POST['multivote'] = ($_POST['multivote'] != 1) ? 0 : 1; - $_POST['displayvoters'] = ($_POST['displayvoters'] != 1) ? 0 : 1; - - $arrColumns = array("member_id", "question", "accesstype", "multivote", "displayvoters", "resultvisibility", "maxvotes", "pollend", "dateposted"); - $arrValues = array($memberInfo['member_id'], $_POST['pollquestion'], $_POST['accesstype'], $_POST['multivote'], $_POST['displayvoters'], $_POST['resultvisibility'], $_POST['maxvotes'], $setEndDate, time()); - - if($pollObj->addNew($arrColumns, $arrValues)) { - $pollObj->cacheID = $_POST['pollCacheID']; - $pollObj->savePollOptions(); - - if($_POST['accesstype'] == "memberslimited") { - $accessObj->cacheID = $_POST['accessCacheID']; - $accessObj->arrAccessFor = array("keyName" => "poll_id", "keyValue" => $pollObj->get_info("poll_id")); - $accessObj->saveAccess(); + + + // Check Result Visibility + $arrCheckVisTypes = array("open", "votedonly", "pollend", "never"); + if (!in_array($_POST['resultvisibility'], $arrCheckVisTypes)) { + $countErrors++; + $dispError .= "   · You selected an invalid result visibility type.
    "; + } + + // Check Max Votes + + if ($_POST['maxvotes'] != "" && (!is_numeric($_POST['maxvotes']) || $_POST['maxvotes'] < 0)) { + $countErrors++; + $dispError .= "   · Max votes per user must be a value greater than zero.
    "; + } + + // Check Poll End + + if ($_POST['enddate'] != "forever" && $_POST['enddate'] != "choose") { + $countErrors++; + $dispError .= "   · You selected an invalid poll end date.
    "; + } elseif ($_POST['enddate'] == "choose" && (!is_numeric($_POST['realenddate']) || $_POST['realenddate'] <= 0)) { + $countErrors++; + $dispError .= "   · You selected an invalid poll end date.
    "; + } + + + if ($countErrors == 0) { + + $setEndDate = 0; + if ($_POST['enddate'] == "choose") { + $setEndDate = $_POST['realenddate'] / 1000; + $tempYear = date("Y", $setEndDate); + $tempMonth = date("n", $setEndDate); + $tempDay = date("j", $setEndDate); + $tempHour = $_POST['endhour']; + if ($_POST['endAMPM'] == "PM") { + $tempHour += 12; + } + + $setEndDate = mktime($tempHour, $_POST['endminute'], 0, $tempMonth, $tempDay, $tempYear); } - - echo " + + + $_POST['multivote'] = ($_POST['multivote'] != 1) ? 0 : 1; + $_POST['displayvoters'] = ($_POST['displayvoters'] != 1) ? 0 : 1; + + $arrColumns = array("member_id", "question", "accesstype", "multivote", "displayvoters", "resultvisibility", "maxvotes", "pollend", "dateposted"); + $arrValues = array($memberInfo['member_id'], $_POST['pollquestion'], $_POST['accesstype'], $_POST['multivote'], $_POST['displayvoters'], $_POST['resultvisibility'], $_POST['maxvotes'], $setEndDate, time()); + + if ($pollObj->addNew($arrColumns, $arrValues)) { + $pollObj->cacheID = $_POST['pollCacheID']; + $pollObj->savePollOptions(); + + if ($_POST['accesstype'] == "memberslimited") { + $accessObj->cacheID = $_POST['accessCacheID']; + $accessObj->arrAccessFor = array("keyName" => "poll_id", "keyValue" => $pollObj->get_info("poll_id")); + $accessObj->saveAccess(); + } + + echo " "; - + + } else { + $countErrors++; + $dispError .= "   · Unable to save information to the database. Please contact the website administrator.
    "; + } } - else { - $countErrors++; - $dispError .= "   · Unable to save information to the database. Please contact the website administrator.
    "; + + + if ($countErrors > 0) { + + $_POST = filterArray($_POST); + $_POST['submit'] = false; + + $arrPostSelected['accesstype']['limited'] = ($_POST['accesstype'] == "memberslimited") ? " selected" : ""; + $arrPostSelected['accesstype']['public'] = ($_POST['accesstype'] == "public") ? " selected" : ""; + + $arrPostSelected['multivote'] = (isset($_POST['multivote']) && $_POST['multivote'] == 1) ? " checked" : ""; + $arrPostSelected['displayvoters'] = (isset($_POST['displayvoters']) && $_POST['displayvoters'] == 1) ? " checked" : ""; + + $arrPostSelected['resultvisibility']['votedonly'] = ($_POST['resultvisibility'] == "votedonly") ? " selected" : ""; + $arrPostSelected['resultvisibility']['pollend'] = ($_POST['resultvisibility'] == "pollend") ? " selected" : ""; + $arrPostSelected['resultvisibility']['never'] = ($_POST['resultvisibility'] == "never") ? " selected" : ""; + + $arrPostSelected['pollend']['choose'] = ($_POST['enddate'] == "choose") ? " selected" : ""; + $arrPostSelected['pollend']['forever'] = ($_POST['enddate'] == "forever") ? " selected" : ""; + + $arrPostSelected['endAMPM'] = ($_POST['endAMPM'] == "PM") ? " selected" : ""; + } + + } - - - if($countErrors > 0) { - - $_POST = filterArray($_POST); - $_POST['submit'] = false; - - $arrPostSelected['accesstype']['limited'] = ($_POST['accesstype'] == "memberslimited") ? " selected" : ""; - $arrPostSelected['accesstype']['public'] = ($_POST['accesstype'] == "public") ? " selected" : ""; - - $arrPostSelected['multivote'] = ($_POST['multivote'] == 1) ? " checked" : ""; - $arrPostSelected['displayvoters'] = ($_POST['displayvoters'] == 1) ? " checked" : ""; - - - $arrPostSelected['resultvisibility']['votedonly'] = ($_POST['resultvisibility'] == "votedonly") ? " selected" : ""; - $arrPostSelected['resultvisibility']['pollend'] = ($_POST['resultvisibility'] == "pollend") ? " selected" : ""; - $arrPostSelected['resultvisibility']['never'] = ($_POST['resultvisibility'] == "never") ? " selected" : ""; - - $arrPostSelected['pollend']['choose'] = ($_POST['enddate'] == "choose") ? " selected" : ""; - $arrPostSelected['pollend']['forever'] = ($_POST['enddate'] == "forever") ? " selected" : ""; - - $arrPostSelected['endAMPM'] = ($_POST['endAMPM'] == "PM") ? " selected" : ""; - - } - - -} -$addMenuItemCID = $consoleObj->findConsoleIDByName("Add Menu Item"); -if ( empty($_POST['submit']) ) { - - echo " + $addMenuItemCID = $consoleObj->findConsoleIDByName("Add Menu Item"); + if (empty($_POST['submit'])) { + + echo "
    "; - - - if($dispError != "") { + + } + if ($dispError != "") { echo "
    Unable to create poll because the following errors occurred:

    @@ -187,106 +181,102 @@
    "; $pollOptionCacheID = $_POST['pollCacheID']; + } else { + $pollOptionCacheID = md5(time() . uniqid()); + $_SESSION['btPollOptionCache'][$pollOptionCacheID] = array(); } - else { - $pollOptionCacheID = md5(time().uniqid()); - $_SESSION['btPollOptionCache'][$pollOptionCacheID] = array(); - } - - - + + $hourOptions = ""; - for($i=12; $i>=1; $i--) { + for ($i = 12; $i >= 1; $i--) { $tempNum = str_pad($i, 2, "0", STR_PAD_LEFT); $dispSelected = ""; - if(isset($_POST['endhour']) && $_POST['endhour'] == $i) { + if (isset($_POST['endhour']) && $_POST['endhour'] == $i) { $dispSelected = " selected"; } - - $hourOptions .= ""; + + $hourOptions .= ""; } - + $minuteOptions = ""; - for($i=0; $i<=59; $i++) { + for ($i = 0; $i <= 59; $i++) { $tempNum = str_pad($i, 2, "0", STR_PAD_LEFT); - + $dispSelected = ""; - if(isset($_POST['endminute']) && $_POST['endminute'] == $i) { - $dispSelected = " selected"; + if (isset($_POST['endminute']) && $_POST['endminute'] == $i) { + $dispSelected = " selected"; } - - $minuteOptions .= ""; + + $minuteOptions .= ""; } - - + echo " - -
    - Use the form below to add a poll. You can display polls in menus by going to the Add Menu Item page. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Question:
    Access: - -
    Multi-Vote: (?) - -
    Display Voters: (?)
    Result Visibility: - -
    Max votes per user: (?) - -
    Run poll until: - - -
    + + Use the form below to add a poll. You can display polls in menus by going to the Add Menu Item page. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Question:
    Access: + +
    Multi-Vote: (?) + +
    Display Voters: (?)
    Result Visibility: + +
    Max votes per user: (?) + +
    Run poll until: + + +
    @@ -295,22 +285,22 @@
    "; - - $accessObj->rankAccessDiv = "rankAccessList"; - $accessObj->dispSetRankAccess(); - - echo " + + $accessObj->rankAccessDiv = "rankAccessList"; + $accessObj->dispSetRankAccess(); + + echo "
    Member Access:

    Use this section to set whether a specific member is allowed to access this poll.

    "; - - $accessObj->memberAccessDiv = "memberAccessList"; - $accessObj->dispSetMemberAccess(); - - echo " + + $accessObj->memberAccessDiv = "memberAccessList"; + $accessObj->dispSetMemberAccess(); + + echo "
    @@ -331,7 +321,7 @@

    -
    Loading +
    Loading

    @@ -348,8 +338,8 @@

    - - + +
    "; -} \ No newline at end of file diff --git a/src/members/include/polls/include/addoption.php b/src/members/include/polls/include/addoption.php index efcb38ed..4bf1361f 100644 --- a/src/members/include/polls/include/addoption.php +++ b/src/members/include/polls/include/addoption.php @@ -1,105 +1,104 @@ select($_SESSION['btUsername']); + $consoleObj = new ConsoleOption($mysqli); + $member = new Member($mysqli); + $member->select($_SESSION['btUsername']); + $createPollCID = $consoleObj->findConsoleIDByName("Create a Poll"); + $consoleObj->select($createPollCID); + $blnConsoleCheck1 = $member->hasAccess($consoleObj); -$createPollCID = $consoleObj->findConsoleIDByName("Create a Poll"); -$consoleObj->select($createPollCID); -$blnConsoleCheck1 = $member->hasAccess($consoleObj); + $managePollsCID = $consoleObj->findConsoleIDByName("Manage Polls"); + $consoleObj->select($managePollsCID); + $blnConsoleCheck2 = $member->hasAccess($consoleObj); -$managePollsCID = $consoleObj->findConsoleIDByName("Manage Polls"); -$consoleObj->select($managePollsCID); -$blnConsoleCheck2 = $member->hasAccess($consoleObj); + $blnConsoleCheck = $blnConsoleCheck1 || $blnConsoleCheck2; -$blnConsoleCheck = $blnConsoleCheck1 || $blnConsoleCheck2; - -$pollObj = new Poll($mysqli); + $pollObj = new Poll($mysqli); // Check Login -$LOGIN_FAIL = true; -if($member->authorizeLogin($_SESSION['btPassword']) && $blnConsoleCheck) { - - $pollObj->cacheID = $_POST['cacheID']; - - if ( ! empty($_POST['submit']) ) { - - $arrNewOption = array(); - $arrErrors = array(); - $arrReturn = array(); - - - // Check Value - if(trim($_POST['optionValue']) == "") { - $arrErrors[] = "Option value may not be blank."; - } - - - // Check Color - if(trim($_POST['optionColor']) == "") { - $_POST['optionColor'] = "#FFFFFF"; - } - - // Check Display Order - - if(count($_SESSION['btPollOptionCache'][$pollObj->cacheID]) > 0 && (!is_numeric($_POST['optionOrder']) || !isset($_POST['optionOrder']) || ($_POST['optionOrderBeforeAfter'] != "before" && $_POST['optionOrderBeforeAfter'] != "after"))) { - $arrErrors[] = "You selected an invalid display order."; - } - - if(count($arrErrors) == 0) { + $LOGIN_FAIL = true; + if ($member->authorizeLogin($_SESSION['btPassword']) && $blnConsoleCheck) { - $newSortNum = $pollObj->makeCacheRoom($_POST['optionOrderBeforeAfter'], $_POST['optionOrder']); - - $arrReturn['result'] = "success"; - $arrReturn['info'] = $newSortNum; - - $arrNewOption['value'] = $_POST['optionValue']; - $arrNewOption['color'] = $_POST['optionColor']; - - - $_SESSION['btPollOptionCache'][$pollObj->cacheID][$newSortNum] = $arrNewOption; + $pollObj->cacheID = $_POST['cacheID']; - $pollObj->resortCacheOrder(); - - } - - if(count($arrErrors) > 0) { - - $arrReturn['result'] = "fail"; - $arrReturn['errors'] = $arrErrors; - + if (!empty($_POST['submit'])) { + + $arrNewOption = array(); + $arrErrors = array(); + $arrReturn = array(); + + + // Check Value + if (trim($_POST['optionValue']) == "") { + $arrErrors[] = "Option value may not be blank."; + } + + + // Check Color + if (trim($_POST['optionColor']) == "") { + $_POST['optionColor'] = "#FFFFFF"; + } + + // Check Display Order + + if (count($_SESSION['btPollOptionCache'][$pollObj->cacheID]) > 0 && (!is_numeric($_POST['optionOrder']) || !isset($_POST['optionOrder']) || ($_POST['optionOrderBeforeAfter'] != "before" && $_POST['optionOrderBeforeAfter'] != "after"))) { + $arrErrors[] = "You selected an invalid display order."; + } + + if (count($arrErrors) == 0) { + + $newSortNum = $pollObj->makeCacheRoom($_POST['optionOrderBeforeAfter'], $_POST['optionOrder']); + + $arrReturn['result'] = "success"; + $arrReturn['info'] = $newSortNum; + + $arrNewOption['value'] = $_POST['optionValue']; + $arrNewOption['color'] = $_POST['optionColor']; + + + $_SESSION['btPollOptionCache'][$pollObj->cacheID][$newSortNum] = $arrNewOption; + + $pollObj->resortCacheOrder(); + + } + + if (count($arrErrors) > 0) { + + $arrReturn['result'] = "fail"; + $arrReturn['errors'] = $arrErrors; + + } + + header('Content-Type: application/json'); + echo json_encode($arrReturn); } - - - echo json_encode($arrReturn); - } - - - if ( empty($_POST['submit']) ) { - echo " + + + if (empty($_POST['submit'])) { + echo " "; - - $pmFolderObj->resortOrder(); + + $pmFolderObj->resortOrder(); + } else { + $countErrors++; + $dispError .= "   · Unable to save folder to the database. Please contact the website administrator.
    "; + } + } - else { - $countErrors++; - $dispError .= "   · Unable to save folder to the database. Please contact the website administrator.
    "; + + + if ($countErrors > 0) { + $_POST = filterArray($_POST); + $_POST['submit'] = false; } - - } - - - - if($countErrors > 0) { - $_POST = filterArray($_POST); - $_POST['submit'] = false; - } - - -} -if ( empty($_POST['submit']) ) { - $arrFolders = $pmFolderObj->listFolders($memberInfo['member_id']); - $folderOptions = ""; - foreach($arrFolders as $folderID => $folderName) { - $folderOptions .= ""; - } - - if($folderOptions == "") { - $folderOptions = ""; } - - - echo " -
    -
    - "; - if($dispError != "") { + if (empty($_POST['submit'])) { + + $arrFolders = $pmFolderObj->listFolders($memberInfo['member_id']); + $folderOptions = ""; + foreach ($arrFolders as $folderID => $folderName) { + $folderOptions .= ""; + } + + if ($folderOptions == "") { + $folderOptions = ""; + } + + echo " + +
    + "; + + if ($dispError != "") { + echo "
    Unable to add folder because the following errors occurred:

    $dispError
    "; - } + } - echo " - Use the form below to add new folder for your private messages. - - - - - - - - - - - - -
    Folder Name:
    Display Order: -
    - -

    - -
    -
    -
    - - "; -} \ No newline at end of file + echo " + Use the form below to add new folder for your private messages. + + + + + + + + + + + + +
    Folder Name:
    Display Order: +
    + +

    + +
    +
    +
    + +"; + } diff --git a/src/members/include/social/manage.php b/src/members/include/social/manage.php index 1b9899b8..392a3392 100644 --- a/src/members/include/social/manage.php +++ b/src/members/include/social/manage.php @@ -1,46 +1,40 @@ get_info_filtered(); - $consoleObj->select($_GET['cID']); - if(!$member->hasAccess($consoleObj)) { + if (!isset($member) || substr($_SERVER['PHP_SELF'], -11) != "console.php") { exit(); + } else { + $memberInfo = $member->get_info_filtered(); + $consoleObj->select($_GET['cID'] ?? ''); + if (!$member->hasAccess($consoleObj)) { + exit(); + } } - -} -$cID = $_GET['cID']; + $cID = $_GET['cID'] ?? ''; -$socialObj = new Social($mysqli); -$objManageList = new btOrderManageList($socialObj); -$objManageList->strMainListLink = BASE_DIRECTORY."members/include/social/include/main.php"; + $socialObj = new Social($mysqli); + $objManageList = new btOrderManageList($socialObj); + $objManageList->strMainListLink = BASE_DIRECTORY . "members/include/social/include/main.php"; -if($_GET['sID'] != "" && $socialObj->select($_GET['sID']) && $_GET['action'] == "edit") { - require_once("include/edit.php"); -} -elseif($_GET['action'] == "delete" && $socialObj->select($_POST['itemID'])) { - $socialInfo = $socialObj->get_info_filtered(); - $objManageList->strDeleteName = $socialInfo['name']; - $objManageList->strDeletePostVarID = "sID"; - - -} -elseif($_GET['action'] != "move") { - require_once($objManageList->strMainListLink); -} \ No newline at end of file +// Check if 'sID' and 'action' are set in the $_GET array + if (isset($_GET['sID'], $_GET['action']) && $_GET['sID'] != "" && $socialObj->select($_GET['sID']) && $_GET['action'] == "edit") { + require_once("include/edit.php"); + } elseif (isset($_GET['action'], $_POST['itemID']) && $_GET['action'] == "delete" && $socialObj->select($_POST['itemID'])) { + $socialInfo = $socialObj->get_info_filtered(); + $objManageList->strDeleteName = $socialInfo['name']; + $objManageList->strDeletePostVarID = "sID"; + } elseif (!isset($_GET['action']) || $_GET['action'] != "move") { + require_once($objManageList->strMainListLink); + } diff --git a/src/members/include/worldclocks/manageclocks.php b/src/members/include/worldclocks/manageclocks.php index 74292375..a9c91398 100644 --- a/src/members/include/worldclocks/manageclocks.php +++ b/src/members/include/worldclocks/manageclocks.php @@ -13,33 +13,29 @@ */ - - if(!isset($member) || substr($_SERVER['PHP_SELF'], -11) != "console.php") { + if (!isset($member) || substr($_SERVER['PHP_SELF'], -11) != "console.php") { exit(); - } - else { + } else { $memberInfo = $member->get_info_filtered(); $consoleObj->select($_GET['cID']); - if(!$member->hasAccess($consoleObj)) { + if (!$member->hasAccess($consoleObj)) { exit(); } - + } - - + + $objManageList = new btOrderManageList($clockObj); - $objManageList->strMainListLink = BASE_DIRECTORY."members/include/worldclocks/main.php"; + $objManageList->strMainListLink = BASE_DIRECTORY . "members/include/worldclocks/main.php"; + - - if($_GET['clockID'] != "" && $clockObj->select($_GET['clockID']) && $_GET['action'] == "edit") { + if (isset($_GET['clockID']) && $_GET['clockID'] != "" && $clockObj->select($_GET['clockID']) && isset($_GET['action']) && $_GET['action'] == "edit") { $clockInfo = $clockObj->get_info_filtered(); - require_once(BASE_DIRECTORY."members/include/worldclocks/edit.php"); - } - elseif($_GET['action'] == "delete" && $clockObj->select($_POST['itemID'])) { + require_once(BASE_DIRECTORY . "members/include/worldclocks/edit.php"); + } elseif (isset($_GET['action']) && $_GET['action'] == "delete" && isset($_POST['itemID']) && $clockObj->select($_POST['itemID'])) { $info = $clockObj->get_info_filtered(); $objManageList->strDeleteName = $info['name']; - $objManageList->strDeletePostVarID = "clockID"; + $objManageList->strDeletePostVarID = "clockID"; + } elseif (!isset($_GET['action']) || $_GET['action'] != "move") { + require_once($objManageList->strMainListLink); } - elseif($_GET['action'] != "move") { - require_once($objManageList->strMainListLink); - } \ No newline at end of file diff --git a/src/members/privatemessages/compose.php b/src/members/privatemessages/compose.php index e8c229f6..4af43c52 100644 --- a/src/members/privatemessages/compose.php +++ b/src/members/privatemessages/compose.php @@ -1,47 +1,46 @@ $arr) { - if(time() > $arr['exptime']) { - unset($_SESSION['btComposeList'][$key]); + foreach ($_SESSION['btComposeList'] as $key => $arr) { + if (time() > $arr['exptime']) { + unset($_SESSION['btComposeList'][$key]); + } } -} // Start Page -$consoleObj = new ConsoleOption($mysqli); - -$cID = $consoleObj->findConsoleIDByName("Private Messages"); -$consoleObj->select($cID); -$consoleInfo = $consoleObj->get_info_filtered(); -$consoleTitle = $consoleInfo['pagetitle']; + $consoleObj = new ConsoleOption($mysqli); + $cID = $consoleObj->findConsoleIDByName("Private Messages"); + $consoleObj->select($cID); + $consoleInfo = $consoleObj->get_info_filtered(); + $consoleTitle = $consoleInfo['pagetitle']; -$member = new Member($mysqli); -$member->select($_SESSION['btUsername']); + $member = new Member($mysqli); + $member->select($_SESSION['btUsername']); -$PAGE_NAME = "Compose Message - ".$consoleTitle." - "; -$dispBreadCrumb = "Home > My Account > ".$consoleTitle." > Compose Message"; -$EXTERNAL_JAVASCRIPT .= " - - + $PAGE_NAME = "Compose Message - " . $consoleTitle . " - "; + $dispBreadCrumb = "Home > My Account > " . $consoleTitle . " > Compose Message"; + $EXTERNAL_JAVASCRIPT .= " + + "; -$prevFolder = "../../"; -require_once(BASE_DIRECTORY."themes/".$THEME."/_header.php"); + $prevFolder = "../../"; + require_once(BASE_DIRECTORY . "themes/" . $THEME . "/_header.php"); -$breadcrumbObj->setTitle("Compose Message"); -$breadcrumbObj->addCrumb("Home", MAIN_ROOT); -$breadcrumbObj->addCrumb("My Account", MAIN_ROOT."members"); -$breadcrumbObj->addCrumb($consoleTitle, MAIN_ROOT."members/console.php?cID=".$cID); -$breadcrumbObj->addCrumb("Compose Message"); -require_once(BASE_DIRECTORY."include/breadcrumb.php"); + $breadcrumbObj->setTitle("Compose Message"); + $breadcrumbObj->addCrumb("Home", MAIN_ROOT); + $breadcrumbObj->addCrumb("My Account", MAIN_ROOT . "members"); + $breadcrumbObj->addCrumb($consoleTitle, MAIN_ROOT . "members/console.php?cID=" . $cID); + $breadcrumbObj->addCrumb("Compose Message"); + require_once(BASE_DIRECTORY . "include/breadcrumb.php"); -$pmObj = new BasicOrder($mysqli, "privatemessages", "pm_id"); -$rankCatObj = new RankCategory($mysqli); -$squadObj = new Squad($mysqli); -$tournamentObj = new Tournament($mysqli); -$multiMemPMObj = new Basic($mysqli, "privatemessage_members", "pmmember_id"); + $pmObj = new BasicOrder($mysqli, "privatemessages", "pm_id"); + $rankCatObj = new RankCategory($mysqli); + $squadObj = new Squad($mysqli); + $tournamentObj = new Tournament($mysqli); + $multiMemPMObj = new Basic($mysqli, "privatemessage_members", "pmmember_id"); -$pmObj->set_assocTableName("privatemessage_members"); -$pmObj->set_assocTableKey("member_id"); + $pmObj->set_assocTableName("privatemessage_members"); + $pmObj->set_assocTableKey("member_id"); // Check Login -$LOGIN_FAIL = true; -if($member->authorizeLogin($_SESSION['btPassword']) && $member->hasAccess($consoleObj)) { - - $memberInfo = $member->get_info_filtered(); - $formObj = new Form(); - - - require_once(BASE_DIRECTORY."members/privatemessages/include/compose_submit.php"); - require_once(BASE_DIRECTORY."members/privatemessages/include/compose_setup.php"); - - $i = 1; - $arrComponents = array( - "tomember" => array( - "type" => "custom", - "display_name" => "To", - "html" => "
    + $LOGIN_FAIL = true; + if ($member->authorizeLogin($_SESSION['btPassword']) && $member->hasAccess($consoleObj)) { + + $memberInfo = $member->get_info_filtered(); + $formObj = new Form(); + + + require_once(BASE_DIRECTORY . "members/privatemessages/include/compose_submit.php"); + require_once(BASE_DIRECTORY . "members/privatemessages/include/compose_setup.php"); + + $i = 1; + $arrComponents = array( + "tomember" => array( + "type" => "custom", + "display_name" => "To", + "html" => "
    ", - "sortorder" => $i++, - - ), - "subject" => array( - "type" => "text", - "display_name" => "Subject", - "attributes" => array("class" => "formInput textBox bigTextBox"), - "sortorder" => $i++, - "value" => $_POST['subject'] - ), - "message" => array( - "type" => "textarea", - "display_name" => "Message", - "sortorder" => $i++, - "attributes" => array("class" => "formInput textBox", "rows" => "8", "cols" => "50"), - "validate" => array("NOT_BLANK") - ), - "submit" => array( - "type" => "submit", - "value" => "Send Message", - "attributes" => array("class" => "submitButton formSubmitButton"), - "sortorder" => $i++ - ), - "pmsessionid" => array( + "sortorder" => $i++, + + ), + "subject" => array( + "type" => "text", + "display_name" => "Subject", + "attributes" => array("class" => "formInput textBox bigTextBox"), + "sortorder" => $i++, + "value" => isset($_POST['subject']) ? $_POST['subject'] : '' + ), + + "message" => array( + "type" => "textarea", + "display_name" => "Message", + "sortorder" => $i++, + "attributes" => array("class" => "formInput textBox", "rows" => "8", "cols" => "50"), + "validate" => array("NOT_BLANK") + ), + "submit" => array( + "type" => "submit", + "value" => "Send Message", + "attributes" => array("class" => "submitButton formSubmitButton"), + "sortorder" => $i++ + ), + "pmsessionid" => array( + "type" => "hidden", + "value" => $pmSessionID, + "hidden" => true, + "sortorder" => $i++ + ) + + ); + + + if (isset($_GET['threadID']) && is_numeric($_GET['threadID'])) { + $replyPMID = $_GET['threadID']; + } else { + $replyPMID = 0; + } + + + $arrComponents['replypmid'] = array( "type" => "hidden", - "value" => $pmSessionID, + "value" => $replyPMID, "hidden" => true, "sortorder" => $i++ - ) - - ); - - - if(isset($_GET['threadID']) && is_numeric($_GET['threadID'])) { - $replyPMID = $_GET['threadID']; - } - else { - $replyPMID = 0; - } - - - $arrComponents['replypmid'] = array( - "type" => "hidden", - "value" => $replyPMID, - "hidden" => true, - "sortorder" => $i++ - ); - - - // Send as Email - $emailPMCID = $consoleObj->findConsoleIDByName("Email Private Messages"); - $consoleObj->select($emailPMCID); - if($member->hasAccess($consoleObj)) { - - $formObj->addComponentSortSpace(2, $arrComponents); - $arrComponents = $formObj->components; - - $arrComponents['emailpm'] = array( - "type" => "checkbox", - "value" => 1, - "sortorder" => 2, - "display_name" => "Send as E-mail", - "tooltip" => "Checking this box will force an e-mail to be sent to the member(s) as well.", - "attributes" => array("class" => "formInput") ); - + + + // Send as Email + $emailPMCID = $consoleObj->findConsoleIDByName("Email Private Messages"); + $consoleObj->select($emailPMCID); + if ($member->hasAccess($consoleObj)) { + + $formObj->addComponentSortSpace(2, $arrComponents); + $arrComponents = $formObj->components; + + $arrComponents['emailpm'] = array( + "type" => "checkbox", + "value" => 1, + "sortorder" => 2, + "display_name" => "Send as E-mail", + "tooltip" => "Checking this box will force an e-mail to be sent to the member(s) as well.", + "attributes" => array("class" => "formInput") + ); + + } + $consoleObj->select($cID); + + $setupFormArgs = array( + "name" => "console-" . $cID . "-compose", + "components" => $arrComponents, + "saveMessage" => "Successfully Sent Private Message!", + "attributes" => array("action" => MAIN_ROOT . "members/privatemessages/compose.php", "method" => "post"), + "description" => "Use the form below to send a private message.

    Extra Information:
    You may send private messages in batches to squads, tournaments, or ranks by typing in their associated name. Typing in a squad name, tournament title or rank name will send to that group.

    ", + "embedJS" => $composePageJS + ); + + + require_once(BASE_DIRECTORY . "members/console.form.php"); + + + } else { + + die(""); + } - $consoleObj->select($cID); - - $setupFormArgs = array( - "name" => "console-".$cID."-compose", - "components" => $arrComponents, - "saveMessage" => "Successfully Sent Private Message!", - "attributes" => array("action" => MAIN_ROOT."members/privatemessages/compose.php", "method" => "post"), - "description" => "Use the form below to send a private message.

    Extra Information:
    You may send private messages in batches to squads, tournaments, or ranks by typing in their associated name. Typing in a squad name, tournament title or rank name will send to that group.

    ", - "embedJS" => $composePageJS - ); - - - - require_once(BASE_DIRECTORY."members/console.form.php"); - - -} -else { - - die(""); - -} - - - -require_once(BASE_DIRECTORY."themes/".$THEME."/_footer.php"); \ No newline at end of file + + + require_once(BASE_DIRECTORY . "themes/" . $THEME . "/_footer.php"); diff --git a/src/themes/include_header.php b/src/themes/include_header.php index e90b6d80..96fda086 100644 --- a/src/themes/include_header.php +++ b/src/themes/include_header.php @@ -1,120 +1,118 @@ select($_SESSION['btUsername'])) { + $memberObj = new Member($mysqli); + if ($memberObj->select($_SESSION['btUsername'])) { - if($memberObj->authorizeLogin($_SESSION['btPassword'])) { - define("LOGGED_IN", true); + if ($memberObj->authorizeLogin($_SESSION['btPassword'])) { + define("LOGGED_IN", true); - $memberInfo = $memberObj->get_info(); - $memberUsername = $memberInfo['username']; - $memberID = $memberInfo['member_id']; + $memberInfo = $memberObj->get_info(); + $memberUsername = $memberInfo['username']; + $memberID = $memberInfo['member_id']; - if($memberInfo['loggedin'] == 0) { - $memberObj->update(array("loggedin"), array(1)); - } + if ($memberInfo['loggedin'] == 0) { + $memberObj->update(array("loggedin"), array(1)); + } - $actualPageNameLoc = strrpos($PAGE_NAME," - "); - $actualPageName = substr($PAGE_NAME, 0, $actualPageNameLoc); + $actualPageNameLoc = strrpos($PAGE_NAME, " - "); + $actualPageName = substr($PAGE_NAME, 0, $actualPageNameLoc); - if($PAGE_NAME == "") { - $actualPageName = "Home Page"; - } + if ($PAGE_NAME == "") { + $actualPageName = "Home Page"; + } - $lastSeenLink = "".$actualPageName.""; - $arrUpdateColLastSeen = array("lastseen", "lastseenlink"); - $arrUpdateValLastSeen = array(time(), $lastSeenLink); + $lastSeenLink = "" . $actualPageName . ""; + $arrUpdateColLastSeen = array("lastseen", "lastseenlink"); + $arrUpdateValLastSeen = array(time(), $lastSeenLink); - if((time()-$memberInfo['lastlogin']) > 3600) { - $arrUpdateColLastSeen[] = "lastlogin"; - $arrUpdateValLastSeen[] = time(); - } + if ((time() - $memberInfo['lastlogin']) > 3600) { + $arrUpdateColLastSeen[] = "lastlogin"; + $arrUpdateValLastSeen[] = time(); + } - $memberObj->update($arrUpdateColLastSeen, $arrUpdateValLastSeen); + $memberObj->update($arrUpdateColLastSeen, $arrUpdateValLastSeen); - $rankObj = new Rank($mysqli); - $rankObj->select($memberInfo['rank_id']); - $rankInfo = $rankObj->get_info(); - $memberRank = $rankInfo['name']; + $rankObj = new Rank($mysqli); + $rankObj->select($memberInfo['rank_id']); + $rankInfo = $rankObj->get_info(); + $memberRank = $rankInfo['name']; - $consoleOptionObj = new ConsoleOption($mysqli); + $consoleOptionObj = new ConsoleOption($mysqli); - - // Members Only Tagger - - $dispMembersOnlyTagger = ""; - if(isset($_SESSION['btMembersOnlyTagger']) && $_SESSION['btMembersOnlyTagger'] == 1 && substr($_SERVER['PHP_SELF'], -11) != "console.php") { - - $pageTaggerURL = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; - - $taggerCID = $consoleOptionObj->findConsoleIDByName("Member's Only Pages"); - - if($taggerObj->select($pageTaggerURL, false)) { - $pageTagStatus = "Member's Only"; - $dispTagOrUntag = "Untag"; - } - else { - $pageTagStatus = "Public"; - $dispTagOrUntag = "Tag"; - } - - $dispMembersOnlyTagger = " + + // Members Only Tagger + + $dispMembersOnlyTagger = ""; + if (isset($_SESSION['btMembersOnlyTagger']) && $_SESSION['btMembersOnlyTagger'] == 1 && substr($_SERVER['PHP_SELF'], -11) != "console.php") { + + $pageTaggerURL = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; + + $taggerCID = $consoleOptionObj->findConsoleIDByName("Member's Only Pages"); + + if ($taggerObj->select($pageTaggerURL, false)) { + $pageTagStatus = "Member's Only"; + $dispTagOrUntag = "Untag"; + } else { + $pageTagStatus = "Public"; + $dispTagOrUntag = "Tag"; + } + + $dispMembersOnlyTagger = "
    -

    Members Only Tagger: ".$actualPageName."

    +

    Members Only Tagger: " . $actualPageName . "

    -

    Current Status: ".$pageTagStatus."
    Return to Member's Only Pages

    +

    Current Status: " . $pageTagStatus . "
    Return to Member's Only Pages

    - +
    @@ -123,7 +121,7 @@ function setMembersOnlyTaggerStatus() { $(document).ready(function() { - $.post('".$MAIN_ROOT."members/include/admin/membersonlypagetagger.php', { setTaggerStatus: '1' }, function(data) { + $.post('" . $MAIN_ROOT . "members/include/admin/membersonlypagetagger.php', { setTaggerStatus: '1' }, function(data) { $('#membersOnlyTagger').fadeOut(250); }); }); @@ -134,7 +132,7 @@ function setMembersOnlyPageStatus() { $(document).ready(function() { $('#membersOnlyTaggerHTML').hide(); $('#membersOnlyLoadingSpiral').show(); - $.post('".$MAIN_ROOT."members/include/admin/membersonlypagetagger.php', { setPageStatus: '1', pageName: '".filterText($actualPageName)."', tagURL: '".$pageTaggerURL."' }, function(data) { + $.post('" . $MAIN_ROOT . "members/include/admin/membersonlypagetagger.php', { setPageStatus: '1', pageName: '" . filterText($actualPageName) . "', tagURL: '" . $pageTaggerURL . "' }, function(data) { $('#membersOnlyTaggerHTML').html(data); $('#membersOnlyLoadingSpiral').hide(); @@ -149,62 +147,61 @@ function setMembersOnlyPageStatus() { "; - } - - } + } - } + } + } -} -if(!defined("LOGGED_IN")) { - define("LOGGED_IN", false); -} + } + + if (!defined("LOGGED_IN")) { + define("LOGGED_IN", false); + } -if($taggerObj->select($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'], false) && constant('LOGGED_IN') == false) { + if ($taggerObj->select($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], false) && constant('LOGGED_IN') == false) { - echo " + echo " "; - - exit(); - -} + exit(); -$hitCountObj = new Basic($mysqli, "hitcounter", "hit_id"); -$result = $mysqli->query("SELECT * FROM ".$dbprefix."hitcounter WHERE ipaddress = '".$IP_ADDRESS."'"); -if($result->num_rows > 0) { - $hitCountRow = $result->fetch_assoc(); - $hitCountObj->select($hitCountRow['hit_id']); - $updateHits = $hitCountObj->get_info("totalhits")+1; - - - $updateColumns = array("totalhits", "pagename"); - $updateValues = array($updateHits, $PAGE_NAME); - - if(time() > ($hitCountObj->get_info("dateposted")+1800)) { - $updateColumns[] = "dateposted"; - $updateValues[] = time(); } - - $hitCountObj->update($updateColumns, $updateValues); -} -else { - $hitCountObj->addNew(array("ipaddress", "dateposted", "pagename", "totalhits"), array($IP_ADDRESS, time(), $PAGE_NAME, 1)); -} + + $hitCountObj = new Basic($mysqli, "hitcounter", "hit_id"); + $result = $mysqli->query("SELECT * FROM " . $dbprefix . "hitcounter WHERE ipaddress = '" . $IP_ADDRESS . "'"); + if ($result->num_rows > 0) { + $hitCountRow = $result->fetch_assoc(); + $hitCountObj->select($hitCountRow['hit_id']); + $updateHits = $hitCountObj->get_info("totalhits") + 1; + + + $updateColumns = array("totalhits", "pagename"); + $updateValues = array($updateHits, $PAGE_NAME); + + if (time() > ($hitCountObj->get_info("dateposted") + 1800)) { + $updateColumns[] = "dateposted"; + $updateValues[] = time(); + } + + $hitCountObj->update($updateColumns, $updateValues); + + } else { + $hitCountObj->addNew(array("ipaddress", "dateposted", "pagename", "totalhits"), array($IP_ADDRESS, time(), $PAGE_NAME, 1)); + } -$blnDisplayNewsTicker = false; + $blnDisplayNewsTicker = false; -$hooksObj->addHook("worldclock-display", "displayDefaultWorldClock"); \ No newline at end of file + $hooksObj->addHook("worldclock-display", "displayDefaultWorldClock");