prevent same person two day

This commit is contained in:
asandikci 2024-01-13 01:00:39 +03:00
parent 3099ab1244
commit 5d51ba82f5
No known key found for this signature in database
GPG key ID: 25C67A03B5666BC1
3 changed files with 75 additions and 10 deletions

View file

@ -41,7 +41,10 @@
<div id="tsparticles"></div>
<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>
<hr style="width: 100%; box-sizing: border-box;">
<div style="text-align:center;">Son veri güncelleme: <span id="latest-data"></span>
@ -129,12 +132,28 @@
flag = true;
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>
function isSameDay(a, b) {
return a.toDateString() == b.toDateString();
}
getPreviousData();
if (localStorage.getItem("win") == null) {
localStorage.setItem("win", "none");
}
@ -441,9 +460,10 @@
</script>
<script>
var t = setInterval(tick, 1000);
function tick(){
function tick() {
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");
localStorage.removeItem("guesses");
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;
include __DIR__ . '/todays.php';
include __DIR__ . '/previous.php';
include __DIR__ . '/../config.php';
require __DIR__ . '/../vendor/autoload.php';
@ -44,23 +45,38 @@ function updateRemoteData()
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)
function chooseTodayPerson()
{
global $APP_NAME;
global $TODAYS_PERSON;
$data = parseTOML()["data"];
backupPreviousPerson($TODAYS_PERSON);
$personArr = array();
foreach ($data as $key => $value) {
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\";";
$file = __DIR__ . "/todays.php";
@ -69,6 +85,25 @@ function chooseTodayPerson()
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
function getAllPersonNames()
{
@ -206,3 +241,12 @@ function parseTOML()
$array = $parser::ParseFile(__DIR__ . "/../data.toml");
return $array;
}
if ($_POST['updateData'] != null && $_POST['updateData'] == "yes") {
updateRemoteData();
}
if ($_POST['getPreviousPerson'] != null && $_POST['getPreviousPerson'] == "yes") {
echo getPreviousPersonName();
}