Skip to content

Instantly share code, notes, and snippets.

@Duckle29
Last active December 11, 2015 03:58
Show Gist options
  • Save Duckle29/4541279 to your computer and use it in GitHub Desktop.
Save Duckle29/4541279 to your computer and use it in GitHub Desktop.
<?php
function minutesSplitter($minutes)
{
$daySingular = 'day';
$dayPlural = 'days';
$hourSingular = 'hour'; //Allows you to change the word used for the singularium of hour.
$hourPlural = 'hours'; //Allows you to change the word used for the plural of hour.
$minutePlural = 'minutes'; //Allows you to change the word used for the singularium of minute.
$minuteSingular = 'minute'; //Allows you to change the word used for the plural of minute.
$andStr = 'and'; //Allows you to change the word used to combine the hours and minutes string.
$days = 0;
$hours = 0;
if($minutes > 59)
{
$hours = floor($minutes / 60);
$minutes = $minutes % 60;
}
if($hours > 23)
{
$days = floor($hours / 24);
$hours = $hours % 24;
}
if($days > 1)
{
$dayStr = $days.' '.$dayPlural;
}
else if($days = 1)
{
$dayStr = $days.' '.$daySingular;
}
else
{
$dayStr = '';
}
if($hours > 1)
{
$hourStr = $hours.' '.$hourPlural;
}
else if($hours = 1)
{
$hourStr = $hours.' '.$hourSingular;
}
else
{
$hourStr = '';
}
if($minutes > 1)
{
$minuteStr = $minutes. ' ' . $minutePlural;
}
else if($minutes = 1)
{
$minuteStr =$minutes. ' ' . $minuteSingular;
}
else if($minutes == 0 && !$hours)
{
$minuteStr =$minutes. ' ' . $minutePlural;
}
else
{
$minuteStr = '';
}
if($dayStr != '' && $hourStr != '')
{
$daysHoursComma = ', ';
}
else
{
$daysHoursComma = '';
}
if($hourStr != '' && $minutes != '')
{
$andStr =' '. $andStr .' ';
}
else
{
$andStr = '';
}
return $dayStr . $daysHoursComma . $hourStr . $andStr . $minuteStr;
}
function variableEcho($echoSel, $name = '', $humanity = '', $survival_attempts = '', $survival_time = '', $survivor_kills = '',$bandit_kills = '',$zombie_kills = '', $headshots = '', $errMsg = '')
{
switch($echoSel)
{
case 0:
echo('
<center>
<div class="box dayz">
<h3>Ingame name</h3>
<div class="errorMsg">'.$errMsg.'</div>
<form method="post">
<table>
<tr>
<td><label for="name">Username</label></td>
<td><input type="text" id="name" name="name" value="'.$name.'"/></td>
</tr>
<tr>
<td><input type="submit" /></td>
</tr>
</table>
</form>
</div>
</center>
');
break;
case 1:
echo('
<h3>Total sum</h3>
<table>
<tr>
<th>Name</th>
<td>'.$name.'</td>
</tr>
<tr>
<th>Deaths</th>
<td>'.$survival_attempts.'</td>
</tr>
<tr>
<th>Total playing time</th>
<td>'.$survival_time.'</td>
</tr>
<tr>
<th>Total survivor kills</th>
<td>'.$survivor_kills.'</td>
</tr>
<tr>
<th>Total bandit kills</th>
<td>'.$bandit_kills.'</td>
</tr>
<tr>
<th>Total zed kills</th>
<td>'.$zombie_kills.'</td>
</tr>
<tr>
<th>Total headshots</th>
<td>'.$headshots.'</td>
</tr>
</table>
<br />
<br />
');
break;
case 2:
echo('
<h3>Current life</h3>
<div class="errMsg">'.$errMsg.'</div>
<table>
<tr>
<th>Humanity</th>
<td>'.$humanity.'</td>
</tr>
<tr>
<th>Playing time</th>
<td>'.$survival_time.'</td>
</tr>
<tr>
<th>Survivor kills</th>
<td>'.$survivor_kills.'</td>
</tr>
<tr>
<th>Bandit kills</th>
<td>'.$bandit_kills.'</td>
</tr>
<tr>
<th>Zed kills</th>
<td>'.$zombie_kills.'</td>
</tr>
<tr>
<th>Headshots</th>
<td>'.$headshots.'</td>
</tr>
</table>
');
break;
default:
echo('
Duck goofed the PHP, please tell him if you can :P
');
break;
}
}
?>
<?php
/*
This is a script that displays the stats of people on your dayz server (private hive).
Made by Mikkel Jeppesen from http://snuletek.org
*/
/*------------------------------------------------------------------*/
/*Config*/
$host = 'HOSTNAME'; //Put the hostname or the ip of your database server here.
$user = 'USERNAME'; //Put your username here.
$pass = 'PASSWORD'; //Enter your password to the database here.
$dataBase = 'DATABASE'; //Enter the name of your database here.
$statsPage = 'HTTP://EXAMPLE.COM/STATS.PHP'; //The page that will contain this script.
//Remember to config the variables in functions.php too.
/*------------------------------------------------------------------*/
/*Code*/
/*IMPORTANT this codeblock HAS to go before any HTML gets outputted, includeing whitespace*/
session_start();
if(isset($_REQUEST['logout']) && $_REQUEST['logout'])
{
$_SESSION = array(); //destroy all of the session variables
session_destroy();
header('location: '.$statsPage);
}
/*IMPORTANT end*/
$con = mysql_connect($host,$user,$pass) or die('Could not connect: ' . mysql_error());
mysql_select_db($dataBase, $con) or die(mysql_error());
if(isset($_POST['name']) && $_POST['name'] != '' OR isset($_SESSION['name']) && $_SESSION['name'] != '')
{
if(isset($_POST['name']) && $_POST['name'] != '')
{
$_SESSION['name'] = $_POST['name'];
}
$name = $_SESSION['name'];
$name = mysql_real_escape_string($name);
$sql = 'SELECT unique_id, humanity ,survival_attempts, total_survival_time, total_survivor_kills, total_bandit_kills, total_zombie_kills, total_headshots, name FROM profile WHERE name = "'.$name.'"';
$resultRaw = mysql_query($sql);
if($userCount = mysql_num_rows($resultRaw))
{
echo('
<a href="'.$statsPage.'?logout=1">Pick another survivor</a>
<table>
');
while($result = mysql_fetch_row($resultRaw))
{
$unique_id = $result[0];
$humanity = $result[1];
if($result[2] > 0)
{
$survival_attempts = $result[2] - 1;
}
else
{
$survival_attempts = $result[2];
}
$total_survival_time = minutesSplitter($result[3]);
$total_survivor_kills = $result[4];
$total_bandit_kills = $result[5];
$total_zombie_kills = $result[6];
$total_headshots = $result[7];
$name = $result[8];
echo('
<tr>
<td>
');
variableEcho(1, $name, '', $survival_attempts, $total_survival_time, $total_survivor_kills, $total_bandit_kills, $total_zombie_kills, $total_headshots);
echo('</td>');
$sql = 'SELECT survival_time, survivor_kills, bandit_kills, zombie_kills, headshots FROM survivor WHERE unique_id = '.$unique_id.' AND is_dead = 0';
echo('');
$resultRaw2 = mysql_query($sql);
if(mysql_num_rows($resultRaw2))
{
$result2 = mysql_fetch_row($resultRaw2);
$survival_time = minutesSplitter($result2[0]);
$survivor_kills = $result2[1];
$bandit_kills = $result2[2];
$zombie_kills = $result2[3];
$headshots = $result2[4];
echo('<td>');
variableEcho(2, '', $humanity, '', $survival_time, $survivor_kills, $bandit_kills, $zombie_kills, $headshots);
echo('</td>');
}
else
{
variableEcho(2, '', '', '', '', '', '', '', '', 'You currently don\'t have any alive characters');
}
}
echo('</table>');
}
else
{
variableEcho(0, $name, '', '', '', '', '', '', '', 'No such user in the database.');
}
}
else
{
variableEcho(0);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment