Added vote to site

This commit is contained in:
Unick Soft
2017-07-28 00:17:42 +03:00
parent a64fff2dd9
commit ab0d155367
23 changed files with 199 additions and 9 deletions

15
src/admin/page_vote.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
include ("cgi-bin/saveGraphHelpers.php");
include ("./src/vote_func.php");
$g_lang["current_language"] = "ru";
$voteTopics = getVoteTopics();
$votes = getVotes($voteTopics);
for ($i = 0; $i < count($voteTopics); $i++)
{
$voteTopics[$i]["vote"] = $votes[$i];
}
?>

View File

@@ -1,6 +1,7 @@
<?php
include ("./src/donate.php");
include ("./src/vote_func.php");
$graphName = "";
if (isset($_GET["graph"]))
@@ -35,4 +36,13 @@
$g_lang["m_keyWords"] = $graphName . ", " . $g_lang["m_keyWords"];
$g_lang["m_description"] = $g_lang["title_notg"] . ": " . $graphName;
}
$wasVote = (isset($_COOKIE["vote0"]));
$voteTopics = getVoteTopics();
for ($i = 0; $i < count($voteTopics); $i++)
{
$voteTopics[$i]["index"] = $i;
}
shuffle($voteTopics);
?>

48
src/vote_func.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
function getVoteTopics()
{
global $g_config, $g_lang;
$voteTopics = array();
$voteTopicsFile = $g_config['voteTopics'] . $g_lang["current_language"];
$csvTopicFile = fopen($voteTopicsFile, "r");
if ($csvTopicFile)
{
while (($data = fgetcsv($csvTopicFile, 1000, "|")) !== FALSE)
{
$topic["title"] = $data[0];
$topic["desc"] = $data[1];
$voteTopics[] = $topic;
}
fclose($csvTopicFile);
}
return $voteTopics;
}
function getVotes($voteTopics)
{
global $g_config;
$votes = array();
for ($i = 0; $i < count($voteTopics); $i++)
{
$votes[] = 0;
}
$voteFile = fopen($g_config['vote'], "r");
if ($voteFile)
{
while (($line = fgets($voteFile)) !== false)
{
$votes[intval($line)] ++;
}
}
fclose($voteFile);
return $votes;
}
?>