prevent same person two day

This commit is contained in:
Aliberk Sandıkçı 2024-01-13 01:00:39 +03:00
parent 3099ab1244
commit 911a66dc7b
Signed by: asandikci
GPG Key ID: 25C67A03B5666BC1
3 changed files with 75 additions and 10 deletions

View File

@ -41,7 +41,10 @@
<div id="tsparticles"></div> <div id="tsparticles"></div>
<hr style="width: 100%; box-sizing: border-box;"> <hr style="width: 100%; box-sizing: border-box;">
<div id="sorumli" style="margin-top:auto;text-align:center;">Veri Sorumlusu: <b>Ömer Arda Muratoğlu</b><br>Her türlü kaldırılmasını, eklenmesini ve/veya değiştirilmesi istediğiniz veriler için kendisi ile iletişime geçiniz !</div> <div style="margin-top:5px;text-align:center;"> <b>Dünün Şanslı Kişisi:</b> <span id="previous-person"><i>yükleniyor</i></span></div>
<hr style="width: 100%; box-sizing: border-box;">
<div id="sorumli" style="margin-top:5px;text-align:center;">Veri Sorumlusu: <b>Ömer Arda Muratoğlu</b><br>Her türlü kaldırılmasını, eklenmesini ve/veya değiştirilmesi istediğiniz veriler için kendisi ile iletişime geçiniz !</div>
<hr style="width: 100%; box-sizing: border-box;">
<div style="margin-top:5px;text-align:center;">Fikir için <b>Cem Deniz Akdeniz</b>'e Teşekkürler !</div> <div style="margin-top:5px;text-align:center;">Fikir için <b>Cem Deniz Akdeniz</b>'e Teşekkürler !</div>
<hr style="width: 100%; box-sizing: border-box;"> <hr style="width: 100%; box-sizing: border-box;">
<div style="text-align:center;">Son veri güncelleme: <span id="latest-data"></span> <div style="text-align:center;">Son veri güncelleme: <span id="latest-data"></span>
@ -129,12 +132,28 @@
flag = true; flag = true;
return; return;
} }
function getPreviousData() {
xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = xmlHttp.responseText;
document.getElementById("previous-person").innerHTML = "<b style='color:red';>" + response + "</b>";
console.debug("Dünün Şanslı Kişisi: " + response);
}
};
params = "getPreviousPerson=yes";
xmlHttp.open("POST", "src/server.php", true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.send(params);
flag = true;
}
</script> </script>
<script> <script>
function isSameDay(a, b) { function isSameDay(a, b) {
return a.toDateString() == b.toDateString(); return a.toDateString() == b.toDateString();
} }
getPreviousData();
if (localStorage.getItem("win") == null) { if (localStorage.getItem("win") == null) {
localStorage.setItem("win", "none"); localStorage.setItem("win", "none");
} }
@ -441,9 +460,10 @@
</script> </script>
<script> <script>
var t = setInterval(tick, 1000); var t = setInterval(tick, 1000);
function tick(){
function tick() {
var curTime = new Date(); var curTime = new Date();
if (curTime.getHours() == 0 && curTime.getMinutes() == 0 && curTime.getSeconds() > 1 && curTime.getSeconds() < 3){ if (curTime.getHours() == 0 && curTime.getMinutes() == 0 && curTime.getSeconds() > 1 && curTime.getSeconds() < 3) {
console.debug("Kullanıcının Ekranııkken Farklı Bir Güne Geçiş Yapıldı, Statlar Sıfırlanıyor ve Kullanıcı Bilgilendiriliyor"); console.debug("Kullanıcının Ekranııkken Farklı Bir Güne Geçiş Yapıldı, Statlar Sıfırlanıyor ve Kullanıcı Bilgilendiriliyor");
localStorage.removeItem("guesses"); localStorage.removeItem("guesses");
localStorage.removeItem("latest_guess"); localStorage.removeItem("latest_guess");

1
src/previous.php Normal file
View File

@ -0,0 +1 @@
<?php $PREVIOUS_PERSON = "aliberk_sandikci24";

View File

@ -3,6 +3,7 @@
use Yosymfony\Toml\Toml; use Yosymfony\Toml\Toml;
include __DIR__ . '/todays.php'; include __DIR__ . '/todays.php';
include __DIR__ . '/previous.php';
include __DIR__ . '/../config.php'; include __DIR__ . '/../config.php';
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
@ -16,7 +17,7 @@ function testData($toml)
try { try {
$array = $parser::Parse($toml); $array = $parser::Parse($toml);
} catch (Exception $e) { } catch (Exception $e) {
$ans = 'Caught exception: ' . $e->getMessage() . "\n"; $ans = 'Caught exception: ' . $e->getMessage() . "\n";
return $ans; return $ans;
} }
return 0; return 0;
@ -44,23 +45,38 @@ function updateRemoteData()
echo "success"; echo "success";
} }
# get random person
function randomizerr($array)
{
srand();
$random_number = random_int(0, count($array) - 1);
$choosen = $array[$random_number];
return $choosen;
}
# Choose the todays person (running each day with cronjob) # Choose the todays person (running each day with cronjob)
function chooseTodayPerson() function chooseTodayPerson()
{ {
global $APP_NAME; global $APP_NAME;
global $TODAYS_PERSON;
$data = parseTOML()["data"]; $data = parseTOML()["data"];
backupPreviousPerson($TODAYS_PERSON);
$personArr = array(); $personArr = array();
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
array_push($personArr, $key); array_push($personArr, $key);
} }
print_r($personArr);
srand();
$random_number = random_int(0, count($personArr) - 1);
$choosen = $personArr[$random_number];
// TODO control each person if already choosed recently? (make all persons avaliable AFTER all of them choosed )
$choosen = randomizerr($personArr);
echo $choosen . " - " . $TODAYS_PERSON;
while ($choosen == $TODAYS_PERSON) {
echo "!!!";
$choosen = randomizerr($personArr);
echo $choosen . " - " . $TODAYS_PERSON;
}
$string = "<?php \$TODAYS_PERSON = \"$choosen\";"; $string = "<?php \$TODAYS_PERSON = \"$choosen\";";
$file = __DIR__ . "/todays.php"; $file = __DIR__ . "/todays.php";
@ -69,6 +85,25 @@ function chooseTodayPerson()
chown("$file", $APP_NAME); chown("$file", $APP_NAME);
} }
# Backup previous person to previous.php file
function backupPreviousPerson($previous)
{
global $APP_NAME;
$string = "<?php \$PREVIOUS_PERSON = \"$previous\";";
$file = __DIR__ . "/previous.php";
file_put_contents($file, $string, LOCK_EX);
chmod("$file", 0700);
chown("$file", $APP_NAME);
}
# get Previous Person Name (isi_soyisim)
function getPreviousPersonName()
{
global $PREVIOUS_PERSON;
return parseTOML()["data"][$PREVIOUS_PERSON]["isim_soyisim"];
}
# Send all person names to frontend # Send all person names to frontend
function getAllPersonNames() function getAllPersonNames()
{ {
@ -206,3 +241,12 @@ function parseTOML()
$array = $parser::ParseFile(__DIR__ . "/../data.toml"); $array = $parser::ParseFile(__DIR__ . "/../data.toml");
return $array; return $array;
} }
if ($_POST['updateData'] != null && $_POST['updateData'] == "yes") {
updateRemoteData();
}
if ($_POST['getPreviousPerson'] != null && $_POST['getPreviousPerson'] == "yes") {
echo getPreviousPersonName();
}