From 37f382ccc38463a8f2c78f2548fe4b087b64da0d Mon Sep 17 00:00:00 2001 From: yi12345 Date: Tue, 17 Sep 2013 23:16:13 +0300 Subject: [PATCH] fix forum surveys --- GameEngine/Alliance.php | 16 +++++++++ GameEngine/Database/db_MYSQL.php | 49 ++++++++++++++++++++++++++++ GameEngine/Database/db_MYSQLi.php | 49 ++++++++++++++++++++++++++++ Templates/Alliance/Forum/forum_5.tpl | 2 +- Templates/Alliance/Forum/forum_6.tpl | 41 +++++++++++++++++++++++ Templates/Alliance/forum.tpl | 28 ++++++++++++---- allianz.php | 3 ++ install/data/sql.sql | 34 +++++++++++++++++++ 8 files changed, 215 insertions(+), 7 deletions(-) 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 diff --git a/Templates/Alliance/Forum/forum_6.tpl b/Templates/Alliance/Forum/forum_6.tpl index 885b1c62..a226ee2c 100644 --- a/Templates/Alliance/Forum/forum_6.tpl +++ b/Templates/Alliance/Forum/forum_6.tpl @@ -62,6 +62,47 @@ if($database->CheckEditRes($aid)=="1"){ ?>
+ checkSurvey($arr['id'])){ + $survey = $database->getSurvey($arr['id']); + if(!$database->checkVote($arr['id'], $session->uid) && $survey['ends'] > time()){ + ?> +
Survey:
+
+
+ +
+ + + + +

+
+ + +
Survey:
+
+ getVoteSum($arr['id']); + for($i=1;$i<=8;$i++){ + if($survey['option'.$i] != ""){ + if($sum > 0){ + $width = 100 * ($survey['vote'.$i] / $sum); + }else{ + $width = 0; + } + ?> +
+ +
+ + uid; $alli = $_POST['pid']; - if(isset($_POST['umfrage_ende'])){ - $ends = ""; - }else{ - $ends = ''; - } if($text != ""){ if(!preg_match('/\[message\]/',$text) && !preg_match('/\[\/message\]/',$text)){ $text = "[message]".$text."[/message]"; @@ -108,7 +103,28 @@ if(isset($_POST['newtopic'])){ } } } - $database->CreatTopic($title,$text,$cat,$owner,$alli,$ends,$alliance,$player,$coor,$report); + $topic_id = $database->CreatTopic($title,$text,$cat,$owner,$alli,$ends,$alliance,$player,$coor,$report); + if($_POST['umfrage']) { + if(isset($_POST['umfrage_ende'])){ + $ends_date = $_POST['month']."/".$_POST['day']."/".$_POST['year']; + if($_POST['meridiem'] == 1){ + $_POST['hour'] += 12; + } + $ends_time = $_POST['hour'].":".$_POST['minute']; + $ends = strtotime($ends_date)-strtotime(date('m/d/Y'))+strtotime($ends_time); + }else{ + $ends = ''; + } + $survey = 0; + for($i=1;$i<=8;$i++){ + if($_POST['option'.$i] != ""){ + $survey = 1; + } + } + if($survey == 1){ + $database->createSurvey($topic_id, $_POST['umfrage_thema'], $_POST['option_1'], $_POST['option_2'], $_POST['option_3'], $_POST['option_4'], $_POST['option_5'], $_POST['option_6'], $_POST['option_7'], $_POST['option_8'], $ends); + } + } } } } diff --git a/allianz.php b/allianz.php index eebc596f..d5690177 100644 --- a/allianz.php +++ b/allianz.php @@ -167,6 +167,9 @@ $invite_permission = $database->getAlliancePermission($session->uid, "opt4", 0); if($_GET['s'] != 5 or $session->sit == 0){ switch($_GET['s']) { case 2: + if(isset($_POST['vote'])){ + $alliance->Vote($_POST); + } include ("Templates/Alliance/forum.tpl"); break; case 3: diff --git a/install/data/sql.sql b/install/data/sql.sql index 7e042a53..5c999227 100644 --- a/install/data/sql.sql +++ b/install/data/sql.sql @@ -745,6 +745,40 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%forum_post` ( -- +-- -------------------------------------------------------- + +-- +-- Table structure for table `%prefix%forum_survey` +-- + +CREATE TABLE IF NOT EXISTS `%PREFIX%forum_survey` ( + `topic` int(11) NOT NULL, + `title` varchar(255) NOT NULL, + `option1` varchar(255) NOT NULL, + `option2` varchar(255) NOT NULL, + `option3` varchar(255) NOT NULL, + `option4` varchar(255) NOT NULL, + `option5` varchar(255) NOT NULL, + `option6` varchar(255) NOT NULL, + `option7` varchar(255) NOT NULL, + `option8` varchar(255) NOT NULL, + `vote1` int(11) unsigned NOT NULL DEFAULT '0', + `vote2` int(11) unsigned NOT NULL DEFAULT '0', + `vote3` int(11) unsigned NOT NULL DEFAULT '0', + `vote4` int(11) unsigned NOT NULL DEFAULT '0', + `vote5` int(11) unsigned NOT NULL DEFAULT '0', + `vote6` int(11) unsigned NOT NULL DEFAULT '0', + `vote7` int(11) unsigned NOT NULL DEFAULT '0', + `vote8` int(11) unsigned NOT NULL DEFAULT '0', + `voted` text NOT NULL, + `ends` int(11) unsigned NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; + +-- +-- Dumping data for table `%prefix%forum_survey` +-- + + -- -------------------------------------------------------- --