diff --git a/GameEngine/Alliance.php b/GameEngine/Alliance.php index ae6f2bf8..30fb0d74 100644 --- a/GameEngine/Alliance.php +++ b/GameEngine/Alliance.php @@ -368,6 +368,22 @@ } } /***************************************** + Function to vote on forum survey + *****************************************/ + public function Vote($post) { + global $database, $session; + if($session->access != BANNED){ + if($database->checkSurvey($post['tid']) && !$database->checkVote($post['tid'], $session->uid)){ + $survey = $database->getSurvey($post['tid']); + $text = ''.$survey['voted'].','.$session->uid.','; + $database->Vote($post['tid'], $post['vote'], $text); + } + header("Location: allianz.php?s=2&fid2=".$post['fid2']."&pid=".$post['pid']."&tid=".$post['tid']); + }else{ + header("Location: banned.php"); + } + } + /***************************************** Function to quit from alliance *****************************************/ private function quitally($post) { diff --git a/GameEngine/Database/db_MYSQL.php b/GameEngine/Database/db_MYSQL.php index 9f808f38..2beccbd7 100644 --- a/GameEngine/Database/db_MYSQL.php +++ b/GameEngine/Database/db_MYSQL.php @@ -1059,6 +1059,55 @@ class MYSQL_DB { return mysql_insert_id($this->connection); } + function createSurvey($topic, $title, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8, $ends) { + $q = "INSERT into " . TB_PREFIX . "forum_survey (topic,title,option1,option2,option3,option4,option5,option6,option7,option8,ends) values ('$topic','$title','$option1','$option2','$option3','$option4','$option5','$option6','$option7','$option8','$ends')"; + return mysql_query($q, $this->connection); + } + + function getSurvey($topic) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + + function checkSurvey($topic) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function Vote($topic, $num, $text) { + $q = "UPDATE " . TB_PREFIX . "forum_survey set vote".$num." = vote".$num." + 1, voted = '$text' where topic = ".$topic.""; + return mysql_query($q, $this->connection); + } + + function checkVote($topic, $uid) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysql_query($q, $this->connection); + $array = mysql_fetch_array($result); + $text = $array['voted']; + if(preg_match('/,'.$uid.',/',$text)) { + return true; + } else { + return false; + } + } + + function getVoteSum($topic) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysql_query($q, $this->connection); + $array = mysql_fetch_array($result); + $sum = 0; + for($i=1;$i<=8;$i++){ + $sum += $array['vote'.$i]; + } + return $sum; + } + function CreatPost($post, $tids, $owner, $alliance, $player, $coor, $report) { $date = time(); $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date','$alliance','$player','$coor','$report')"; diff --git a/GameEngine/Database/db_MYSQLi.php b/GameEngine/Database/db_MYSQLi.php index a387d3ee..0b513c8b 100644 --- a/GameEngine/Database/db_MYSQLi.php +++ b/GameEngine/Database/db_MYSQLi.php @@ -1062,6 +1062,55 @@ class MYSQLi_DB { return mysqli_insert_id($this->connection); } + function createSurvey($topic, $title, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8, $ends) { + $q = "INSERT into " . TB_PREFIX . "forum_survey (topic,title,option1,option2,option3,option4,option5,option6,option7,option8,ends) values ('$topic','$title','$option1','$option2','$option3','$option4','$option5','$option6','$option7','$option8','$ends')"; + return mysqli_query($this->connection, $q); + } + + function getSurvey($topic) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysql_query($q, $this->connection); + return mysqli_fetch_array($result); + } + + function checkSurvey($topic) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysqli_query($this->connection, $q); + if(mysqli_num_rows($result)) { + return true; + } else { + return false; + } + } + + function Vote($topic, $num, $text) { + $q = "UPDATE " . TB_PREFIX . "forum_survey set vote".$num." = vote".$num." + 1, voted = '$text' where topic = ".$topic.""; + return mysqli_query($this->connection, $q); + } + + function checkVote($topic, $uid) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysqli_query($this->connection, $q); + $array = mysqli_fetch_array($result); + $text = $array['voted']; + if(preg_match('/,'.$uid.',/',$text)) { + return true; + } else { + return false; + } + } + + function getVoteSum($topic) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysqli_query($this->connection, $q); + $array = mysqli_fetch_array($result); + $sum = 0; + for($i=1;$i<=8;$i++){ + $sum += $array['vote'.$i]; + } + return $sum; + } + function CreatPost($post, $tids, $owner, $alliance, $player, $coor, $report) { $date = time(); $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date','$alliance','$player','$coor','$report')"; diff --git a/Templates/Alliance/Forum/forum_5.tpl b/Templates/Alliance/Forum/forum_5.tpl index e4848943..24c75954 100644 --- a/Templates/Alliance/Forum/forum_5.tpl +++ b/Templates/Alliance/Forum/forum_5.tpl @@ -113,7 +113,7 @@ if($session->access!=BANNED){ document.post.meridiem[1].disabled = true;} } //--> - + am pm
+
+