<html>
<head>
<title>Profile Utilities</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<?php include $_SERVER['DOCUMENT_ROOT']."/style.php"; ?>
<script src="jquery.json-view.min.js"></script>
<link href="jquery.json-view.min.css" rel="stylesheet">
</head>
<body>
<?php include $_SERVER['DOCUMENT_ROOT']."/navbar.php"; ?>
<br>
<div class="container">
<div class="jumbotron">
<h1>Profile Utilities</h1>
<p><small>Utilities to inspect and modify user's profiles (For in-studio testing only).</small></p>
</div>
<div class="panel panel-primary"><div class="panel-heading"><h3 class="panel-title">Credential</h3></div>
<?php
$debug = false;
$Credential = $_POST['credential'];
if ( "$Credential" == "" ) $Credential = $_GET['credential'];
$Command = $_POST['command'];
if ( "$Credential" == "" )
{
echo "<div class=\"panel-body\">Required parameter missing: credential</div></div>";
}
else
{
echo "<div class=\"panel-body\">$Credential</div></div>";
echo "<br>";
if ( "$Command" == "" )
{
?>
<div class="panel panel-primary"><div class="panel-heading"><h3 class="panel-title">Actions</h3></div>
<div class="panel-body">
<div class="container" align=center>
<form method="POST" enctype="multipart/form-data">
<?php
echo "<input type=\"hidden\" name=\"credential\" value=\"$Credential\" \>";
?>
<div class="container">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="radio" name="suffix" value="" autocomplete="off" checked>None
</label>
<label class="btn btn-primary ">
<input type="radio" name="suffix" value="HQ" autocomplete="off" >HQ Suffix
</label>
<label class="btn btn-primary ">
<input type="radio" name="suffix" value="HN" autocomplete="off" >HN Suffix
</label>
</div>
</div>
<br>
<div class="row">
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="Get">Get Whole Profile</button>
<div class="col-md-1"></div>
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="Reset">Soft Reset Profile</button>
<div class="col-md-1"></div>
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="Wipe">Wipe Profile</button>
</div>
<br>
<div class="row">
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="GetSaveGame">Get SaveGame</button>
<div class="col-md-1"></div>
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="SetSaveGame">Set SaveGame</button>
<div class="col-md-1"></div>
<button class="btn btn-primary btn-file col-md-3">Browse Save Game<input type="file" name="savegame_file" > </button>
</div>
<br>
<div class="row">
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="GetName">Get Player Name</button>
<div class="col-md-1"></div>
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="SetName">Set Player Name</button>
<div class="col-md-1"></div>
<div class="container col-md-3">
<div class="input-group">
<span class="input-group-addon">Name</span>
<input type="text" class="form-control" name="playerName" value="Player_1234">
</div>
</div>
</div>
<br>
<div class="row">
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="GetLevel">Get Player Level</button>
<div class="col-md-1"></div>
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="SetLevel">Set Player Level</button>
<div class="col-md-1"></div>
<div class="container col-md-3">
<div class="input-group">
<span class="input-group-addon">Level</span>
<input type="number" class="form-control" name="playerLevel" min="0" value="1">
</div>
</div>
</div>
<br>
<div class="row">
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="GetResources">Get Resource Levels</button>
<div class="col-md-1"></div>
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="SetResources">Set Resource Levels</button>
<div class="col-md-1"></div>
<div class="container col-md-3">
<div class="input-group"><span class="input-group-addon">Coin</span><input type="number" class="form-control" name="hc" min="0" value="0"></div>
</div>
<div class="col-md-8"></div>
<div class="container col-md-3">
<div class="input-group"><span class="input-group-addon">Food</span><input type="number" class="form-control" name="food" min="0" value="0"></div>
</div>
<div class="col-md-8"></div>
<div class="container col-md-3">
<div class="input-group"><span class="input-group-addon">Fuel</span><input type="number" class="form-control" name="fuel" min="0" value="0"></div>
</div>
<div class="col-md-8"></div>
<div class="container col-md-3">
<div class="input-group"><span class="input-group-addon">Scrap</span><input type="number" class="form-control" name="scrap" min="0" value="0"></div>
</div>
</div>
<br>
<div class="row">
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="GetLayout">Get Tycoon Layout</button>
<div class="col-md-1"></div>
<button class="btn btn-primary col-md-3" type="submit" formaction="tools.php" name="command" value="SetLayout">Set Tycoon Layout</button>
<div class="col-md-1"></div>
<button class="btn btn-primary btn-file col-md-3">Browse Layout Json <input type="file" name="layout_file" > </button>
</div>
</form>
</div>
</div>
</div>
<?php
}
else
{
$res_hc = $_POST['hc'];
$res_food = $_POST['food'];
$res_fuel = $_POST['fuel'];
$res_scrap = $_POST['scrap'];
$PlayerName = $_POST['playerName'];
$PlayerLevel = $_POST['playerLevel'];
$LayoutData = $_POST['layout_file'];
$Suffix = $_POST['suffix'];
$EncodedCredential = urlencode($Credential);
if ( "$Command" == "Get" ) { $Label = "Getting Whole Profile"; $IsJson = true; $CmdArgs = "get all"; }
if ( "$Command" == "GetSaveGame" ) { $Label = "Getting Save Game"; $IsJson = true; $CmdArgs = "get savegame"; }
if ( "$Command" == "SetSaveGame" ) { $Label = "Setting Save Game "; $IsJson = false; $CmdArgs = "set ._savegame$Suffix "; }
if ( "$Command" == "SetName" ) { $Label = "Setting Player Name"; $IsJson = false; $CmdArgs = "modify name $PlayerName"; }
if ( "$Command" == "SetLevel" ) { $Label = "Setting Player Level"; $IsJson = false; $CmdArgs = "modify level $PlayerLevel"; }
if ( "$Command" == "SetResources" ) { $Label = "Setting Player Resources"; $IsJson = false; $CmdArgs = "modify resources $res_hc,$res_food,$res_fuel,$res_scrap"; }
if ( "$Command" == "SetLayout" ) { $Label = "Setting Player Layout"; $IsJson = false; $CmdArgs = "set layout "; }
if ( "$Command" == "GetName" ) { $Label = "Getting Player Name"; $IsJson = false; $CmdArgs = "get name"; }
if ( "$Command" == "GetLevel" ) { $Label = "Getting Player Level"; $IsJson = false; $CmdArgs = "get level"; }
if ( "$Command" == "GetResources" ) { $Label = "Getting Player Resources"; $IsJson = false; $CmdArgs = "get resources"; }
if ( "$Command" == "GetLayout" ) { $Label = "Getting Player Layout"; $IsJson = true; $CmdArgs = "get layout"; }
if ( "$Command" == "Reset" ) { $Label = "Resetting Profile "; $IsJson = false; $CmdArgs = "reset"; }
if ( "$Command" == "Wipe" ) { $Label = "Wiping Profile"; $IsJson = false; $CmdArgs = "clear"; }
echo "<div class=\"panel panel-success\"><div class=\"panel-heading\"><h3 class=\"panel-title\">$Label</h3></div>";
if ( "$Command" == "SetSaveGame" )
{
$UploadFile = $_FILES['savegame_file']['tmp_name'];
$CmdArgs = "$CmdArgs" . "$UploadFile";
}
if ( "$Command" == "SetLayout" )
{
$UploadFile = $_FILES['layout_file']['tmp_name'];
$CmdArgs = "$CmdArgs" . "$UploadFile";
}
if ( $IsJson == true ) {
$Result = shell_exec("./profile_utils.sh --suffix \"$Suffix\" $EncodedCredential $CmdArgs | python -m json.tool");
} else {
$Result = shell_exec("./profile_utils.sh --suffix \"$Suffix\" $EncodedCredential $CmdArgs");
}
echo "<div class=\"panel-body\">";
if ( $IsJson == true ) {
/* echo " <pre><code>$Result</code></pre>"; */
?>
<div>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#tree" aria-controls="tree" role="tab" data-toggle="tab">Tree View</a></li>
<li role="presentation"><a href="#raw" aria-controls="raw" role="tab" data-toggle="tab">Raw</a></li>
<div class="col-md-1"></div>
<li role="presentation"><button class="btn btn-primary" id="save_json_button"></button></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="tree"><div id="jsonTreeView"></div></div>
<?php
echo "<div role=\"tabpanel\" class=\"tab-pane\" id=\"raw\"><pre><code> $Result </code></pre></div>";
?>
</div>
</div>
<script>
<?php
echo "var data = $Result ;";
?>
var json = JSON.stringify(data);
var blob = new Blob([json], {type: "application/json"});
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.download = "profile_data.json";
a.href = url;
a.textContent = "Save";
document.getElementById('save_json_button').appendChild(a);
$('#jsonTreeView').jsonView(json);
</script>
<?php
} else {
echo " <pre><code>$Result</code></pre>";
}
echo "</div><div class=\"panel-footer\">Command used: ./profile_utils.sh --suffix \"$Suffix\" $EncodedCredential $CmdArgs</div></div>";
}
}
?>
</div>
</body>
</html>