%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /www/varak.net/practiscore.varak.net_old/
Upload File :
Create Path :
Current File : //www/varak.net/practiscore.varak.net_old/receive.php

<?php
	$data = file_get_contents("php://input");
	file_put_contents(__DIR__ . "/data/" . uniqid("result_", true) . ".txt", $data);
	//echo $data;

	include "./lib/dibi.phar";
dibi::connect(array(
    'driver'   => 'mysql',
    'host'     => 'localhost',
    'username' => 'practiscore',
    'password' => 'Cepice321',
    'database' => 'practiscore',
    'charset'  => 'utf8',
    'profiler' => [
        'run' => TRUE,
        'file' => __DIR__ . '/log/log-' . date('Y-m-d') . '.txt',
],
));

	$result = json_decode($data);
	$insert = array(
		"match" => $result->matchId,
		"device" => $result->deviceId,
		"datetime" => $result->dateTime,
		"shooter" => $result->shooterName,
		"stage" => $result->stageNo,
		"time" => $result->time,
		"hitFactor" => $result->hitFactor,
		"alpha" => $result->alpha,
		"charlie" => $result->charlie,
		"delta" => $result->delta,
		"miss" => $result->miss,
		"noshoot" => $result->noshoot,
		"proc" => $result->proc,
		"hash" => $result->hash
	);
	$res = dibi::query("SELECT [id] FROM [received_score] WHERE [hash]=%s", $result->hash);
	if(count($res) > 0)
	{
		// UPDATE
		dibi::query("UPDATE [received_score] SET", $insert, "WHERE [id]=%i", $res->fetchSingle());
	}
	else
	{
		// INSERT
		dibi::query("INSERT INTO [received_score]", $insert);
	}

	// And new score table
    $shooter = 0;
	$stage = 0;
    $res = dibi::query("SELECT [id] FROM [shooters] WHERE [match]=%i AND [name]=%s", $result->matchId, $result->shooterName);
    if(count($res) > 0)
        $shooter = $res->fetchSingle();
    $res = dibi::query("SELECT [id] FROM [stages] WHERE [match]=%i AND [number]=%i", $result->matchId, $result->stageNo);
    if(count($res) > 0)
        $stage = $res->fetchSingle();
    $data = array(
        "match" => $result->matchId,
        "device" => $result->deviceId,
        "datetime" => $result->dateTime,
        "shooter" => $shooter,
        "stage" => $stage,
        "time" => $result->time,
        "hitFactor" => $result->hitFactor,
        "alpha" => $result->alpha,
        "charlie" => $result->charlie,
        "delta" => $result->delta,
        "miss" => $result->miss,
        "noshoot" => $result->noshoot,
        "proc" => $result->proc,
        "hash" => $result->hash
    );
    $res = dibi::query("SELECT [id] FROM [score] WHERE [hash]=%s", $result->hash);
    if(count($res) > 0)
    {
        // UPDATE
        dibi::query("UPDATE [score] SET", $data, "WHERE [id]=%i", $res->fetchSingle());
    }
    else
    {
        // INSERT
        dibi::query("INSERT INTO [score]", $data);
    }

	echo $result->hash . " OK";

Zerion Mini Shell 1.0