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

View File

@ -1,5 +1,5 @@
Options +ExecCGI
AddHandler AddType application/x-httpd-php .exe
#Options +ExecCGI
#AddHandler AddType application/x-httpd-php .exe
Options -Indexes
RewriteEngine on

View File

@ -1,4 +1,5 @@
<?
include ("../core/config/main.php");
include ("saveGraphHelpers.php");
$name = $_GET["name"];

View File

@ -1,4 +1,5 @@
<?
include ("../core/config/main.php");
include ("saveGraphHelpers.php");
$graph = file_get_contents("php://input");

View File

@ -3,8 +3,6 @@
Function to save/open graph
*/
include ("../core/config/main.php");
// Only latic.
function isValidName($name)
{

View File

@ -1,4 +1,6 @@
<?php
include ("../core/config/main.php");
include ("saveGraphHelpers.php");
$name = $_GET["name"];

15
cgi-bin/vote.php Normal file
View File

@ -0,0 +1,15 @@
<?
include ("../core/config/main.php");
if (!isset($_COOKIE["vote0"]))
{
$index = $_GET["index"];
setcookie("vote0", "true", time() + 3600 * 24 * 90, '/'); // 3 month
$file = fopen("../" . $g_config['vote'], "a");
fprintf($file, "%d\n", $index);
fclose($file);
echo ("OK");
}
?>

View File

@ -79,4 +79,6 @@
// Donate files
$g_config['donateTotal'] = "./tmp/donate/total.txt";
$g_config['donateTransactions'] = "./tmp/donate/transactions.txt";
$g_config['vote'] = "./tmp/vote/vote.txt";
$g_config['voteTopics'] = "./tmp/vote/voteTopics.txt_";
?>

View File

@ -44,7 +44,8 @@
array('link' => SiteRoot('admin/page_editor'), 'name' => 'Все страницы', 'label' => 'Смотреть все страницы'),
array('link' => SiteRoot('admin/page_editor_add'), 'name' => 'Добавить', 'label' => 'Добавить новую страницу'),
array('link' => SiteRoot('admin/page_saved_graph'), 'name' => 'Статистика', 'label' => 'Статистика сохранений'),
array('link' => SiteRoot('admin/page_example_graph'), 'name' => 'Примеры', 'label' => 'Примеры графов')
array('link' => SiteRoot('admin/page_example_graph'), 'name' => 'Примеры', 'label' => 'Примеры графов'),
array('link' => SiteRoot('admin/page_vote'), 'name' => 'Голосование', 'label' => 'Результаты голосования')
)
);

View File

@ -100,4 +100,6 @@
$g_lang["group_rename"] = "Group rename";
$g_lang["enter_vertices_text_in_each_line"] = "Enter text for each vertex in separate line";
$g_lang["or"] = "or";
$g_lang["vote"] = "Vote";
$g_lang["vote_question"] = "What functions should we add firstly?";
?>

View File

@ -104,5 +104,7 @@
$g_lang["group_rename"] = "Групповое переименование";
$g_lang["enter_vertices_text_in_each_line"] = "Введите текст для каждой вершины в отдельную строку";
$g_lang["or"] = "или";
$g_lang["vote"] = "Опрос";
$g_lang["vote_question"] = "Какие функции нам добавить в первую очередь?";
?>

View File

@ -398,7 +398,40 @@ function postLoadPage()
}
}
if (document.getElementById('VoteButton') !== null)
document.getElementById('VoteButton').onclick = function ()
{
var dialogButtons = {};
for (var i = 0; i < 6 && document.getElementById('vote' + i) !== null; i++)
{
document.getElementById('vote' + i)["voteIndex"] = i;
document.getElementById('vote' + i).onclick = function ()
{
console.log("Vote" + this["voteIndex"]);
$.ajax({
type: "GET",
url: "/cgi-bin/vote.php?index=" + this["voteIndex"],
dataType: "text"
});
$("#voteDialog").dialog('close');
$("#VoteButton").hide();
}
}
dialogButtons[g_close] = function() {
$( this ).dialog( "close" );
};
$( "#voteDialog" ).dialog({
resizable: false,
title: g_vote,
width: 400,
modal: true,
dialogClass: 'EdgeDialog',
buttons: dialogButtons,
});
}
// Get algorithms list and load it.
$.get( "/cgi-bin/getPluginsList.php",

View File

@ -66,6 +66,7 @@ var g_editWeight = "Edit weight";
var g_noWeight = "No weight";
var g_groupRename = "Group rename";
var g_vote = "Vote";
function loadTexts()
{
@ -133,4 +134,5 @@ function loadTexts()
g_noWeight = document.getElementById("noWeight").innerHTML;
g_groupRename = document.getElementById("groupeRenameText").innerHTML;
g_vote = document.getElementById("voteText").innerHTML;
}

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;
}
?>

6
tmp/auto_merge_css_js/css/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*.css
*.css.gz
*.txt
**/*.css
**/*.css.gz
**/*.txt

4
tmp/saved/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.png
*.xml
**/*.png
**/*.xml

0
tmp/vote/vote.txt Normal file
View File

View File

@ -0,0 +1,4 @@
User account|Possibility to store graphs in your user account and other settings.
Improved visualization|The ability to change colors for vertexes and edges, as well as the shape and size of the vertexes.
Improving the support of large graphs|Make easy work with large graphs with the number of vertixes is more than 300.
More algorithms|Add more algorithms: maximum flow, minimum cut, radius, diameter, coloring graph.

View File

@ -0,0 +1,4 @@
Личный кабинет|Возможность сохранения графов в своём личном кабинете и другие персоональные настройки.
Улучшение визуализации|Возможность изменения цветов для вешин и дуг, а также формы и размеров вершин.
Улучшение поддержки больших графов|Удобная работа с графами больших размеров с количеством вершин больше 300.
Больше алгоритмов|Добавление большего числа алгоритмов: максимальный поток, минимальный разрез, радиус, диаметр, раскраска графа.

View File

@ -4,7 +4,7 @@
</head>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" id="admin-menu">
<nav class="navbar navbar-inverse" role="navigation" id="admin-menu">
<div class="container">
<!-- Логотип и кнопка открытия меню сгруппированы для лучшего отображения на мобильных устройствах -->

10
tpl/admin/page_vote.php Normal file
View File

@ -0,0 +1,10 @@
<?php IncludeCom('dev/bootstrap3')?>
<h1>Голосование</h1>
<div>
<? for ($i = 0; $i < count($voteTopics); $i++): ?>
<p><?= $voteTopics[$i]["title"] ?> - <?= $voteTopics[$i]["vote"] ?></p>
<?php endfor; ?>
</div>

View File

@ -100,6 +100,10 @@
</div>
<button type="button" class="btn btn-default btn-sm" id="DeleteObject"><span class="glyphicon glyphicon-remove fa-fw"></span><span class="hidden-phone"> <?= L('delete')?></span></button>
<? if (!$wasVote && count($voteTopics) > 0): ?>
<button type="button" class="btn btn-success" id="VoteButton"><span class="glyphicon glyphicon-thumbs-up"></span> <?= L('vote') ?></button>
<? endif ?>
<!--
<button type="button" class="btn btn-default" id="Test"><span class="glyphicon glyphicon-remove"></span> Test repos</button>
-->
@ -274,6 +278,31 @@
<div><span class="glyphicon glyphicon-remove-sign text-danger"></span> <?= L('bad_inc_matrix_message')?></div>
</div>
<div id="incidenceMatrix">
<form>
<fieldset>
<p><?= L('incidence_matrix_description')?></p>
<textarea name="incidenceMatrixField" id="IncidenceMatrixField" wrap="off"></textarea>
<p id="BadIncidenceMatrixFormatMessage"><?= L('incidence_matrix_bad_format')?></p>
</fieldset>
</form>
</div>
<div id="voteDialog">
<form>
<fieldset>
<p><?= L('vote_question') ?></p>
<? foreach ($voteTopics as $topic): ?>
<div class="list-group">
<button type="button" class="list-group-item" id="vote<?=$topic["index"]?>">
<h4 class="list-group-item-heading"><?= $topic["title"] ?></h4>
<p class="list-group-item-text"><?= $topic["desc"] ?></p>
</button>
</div>
<? endforeach ?>
</fieldset>
</form>
</div>
<p id="SelectAndMoveObject" class="translation"><?= L('select_and_move_objects')?></p>
<p id="MoveCursorForMoving" class="translation"><?= L('move_cursor_for_moving')?></p>
@ -339,7 +368,8 @@
<p id="editWeight" class="translation"><?= L('edit_weight')?></p>
<p id="noWeight" class="translation"><?= L('default_weight')?></p>
<p id="groupeRenameText" class="translation"><?= L('group_rename')?></p>
<p id="voteText" class="translation"><?= L('vote')?></p>
</section>
<!--
<script>