Kaynağa Gözat

Add table properties

Foppe Hemminga 5 yıl önce
ebeveyn
işleme
c4af66570d
4 değiştirilmiş dosya ile 220 ekleme ve 30 silme
  1. 16 12
      index.php
  2. 166 0
      properties.php
  3. 33 17
      snippets.php
  4. 5 1
      sqlite.php

+ 16 - 12
index.php

@@ -30,24 +30,28 @@ require "functions.php";
 // global
 $screen = 0;
 $maintainer = array(0, '?');
-if ( isset( $_REQUEST['i'] ) && $_REQUEST['i'] != '' ) {
+$action = '';
+if ( isset( $_REQUEST['action'] ) ) {
+    $action = $_REQUEST['action'];
+}
+if ( $action == 'i' ) {
 	// Try adding new maintainer ...
-    $maintainer = add_maintainer( $_REQUEST['i'] );
+    $maintainer = add_maintainer( $_REQUEST['api'] );
     // ... then return to start screen
 	$screen = 0;
 }
-if ( isset( $_REQUEST['m'] ) && $_REQUEST['m'] != '' ) {
+if ( $action == 'm' ) {
 	// There is a maintainer
-    $maintainer = get_maintainer( $_REQUEST['m'] );
+    $maintainer = get_maintainer( $_REQUEST['maintainer'] );
 	$screen = 2;
-	if (isset($_REQUEST['e'])) {
-		// Request for edit screen
-		$screen = 3;
-	}
-	if (isset($_REQUEST['x'])) {
-		// Request to remove player
-		$screen = 4;
-	}
+}
+if ( $action == 'e' ) {
+    // Request for edit screen
+    $screen = 3;
+}
+if ( $action == 'x' ) {
+    // Request to remove player
+    $screen = 4;
 }
 assert( '$screen >= 0', "By now \$screen should be set to a value >= 0." );
 ?>

+ 166 - 0
properties.php

@@ -0,0 +1,166 @@
+<?php
+$properties = [
+	"useractivity" => 26812157,
+	"logins" => 4361,
+	"weaponsbought" => 11148,
+	"attackmisses" => 23099,
+	"attackdamage" => 59339207,
+	"attackhits" => 52822,
+	"axehits" => 1067,
+	"attackswon" => 14058,
+	"highestbeaten" => 100,
+	"bestkillstreak" => 504,
+	"jailed" => 306,
+	"mailssent" => 1724,
+	"attackcriticalhits" => 10813,
+	"slahits" => 425,
+	"moneymugged" => 19552798251,
+	"largestmug" => 1000026663,
+	"friendmailssent" => 375,
+	"roundsfired" => 271152,
+	"pishits" => 346,
+	"defendswon" => 2765,
+	"hospital" => 8372,
+	"defendslost" => 3694,
+	"rifhits" => 6620,
+	"attackslost" => 797,
+	"attacksassisted" => 336,
+	"attacksstealthed" => 8335,
+	"onehitkills" => 6547,
+	"dumpsearches" => 1026,
+	"dumpfinds" => 1026,
+	"itemsdumped" => 5050,
+	"itemssent" => 3567,
+	"drugsused" => 5351,
+	"cantaken" => 77,
+	"auctionswon" => 16,
+	"daysbeendonator" => 1880,
+	"spousemailssent" => 104,
+	"medicalitemsused" => 21704,
+	"companymailssent" => 185,
+	"trainsreceived" => 1071,
+	"cityfinds" => 522,
+	"theyrunaway" => 1022,
+	"failedbusts" => 249,
+	"peoplebusted" => 3000,
+	"pointsbought" => 44095,
+	"itemsbought" => 3426,
+	"xantaken" => 4811,
+	"traveltimes" => 3474,
+	"mextravel" => 481,
+	"itemsboughtabroad" => 92725,
+	"cantravel" => 462,
+	"lontravel" => 387,
+	"caytravel" => 410,
+	"argtravel" => 350,
+	"hawtravel" => 165,
+	"japtravel" => 132,
+	"switravel" => 586,
+	"soutravel" => 133,
+	"dubtravel" => 172,
+	"chitravel" => 196,
+	"shrtaken" => 50,
+	"shohits" => 157,
+	"piehits" => 4646,
+	"bountiescollected" => 798,
+	"totalbountyreward" => 210769630,
+	"medstolen" => 8,
+	"attacksdraw" => 218,
+	"virusescoded" => 125,
+	"yourunaway" => 157,
+	"victaken" => 84,
+	"overdosed" => 108,
+	"revivesreceived" => 805,
+	"auctionsells" => 15,
+	"exttaken" => 246,
+	"kettaken" => 50,
+	"respectforfaction" => 76338,
+	"smghits" => 1663,
+	"bountiesreceived" => 206,
+	"factionmailssent" => 173,
+	"peoplebought" => 502,
+	"peopleboughtspent" => 54974080,
+	"chahits" => 234,
+	"machits" => 119,
+	"heahits" => 697,
+	"networth" => 30913343466,
+	"grehits" => 276,
+	"missioncreditsearned" => 40942,
+	"contractscompleted" => 1022,
+	"dukecontractscompleted" => 1022,
+	"revives" => 663,
+	"missionscompleted" => 1,
+	"bountiesplaced" => 486,
+	"totalbountyspent" => 194793585,
+	"bloodwithdrawn" => 5140,
+	"lsdtaken" => 11,
+	"defendsstalemated" => 28,
+	"meritsbought" => 45,
+	"opitaken" => 14,
+	"nerverefills" => 1409,
+	"consumablesused" => 24693,
+	"candyused" => 1838,
+	"alcoholused" => 13823,
+	"energydrinkused" => 9032,
+	"tokenrefills" => 200,
+	"organisedcrimes" => 158,
+	"booksread" => 10,
+	"h2hhits" => 147,
+	"classifiedadsplaced" => 6,
+	"traveltime" => 37995600,
+	"unarmoredwon" => 259,
+	"stockpayouts" => 486,
+	"boostersused" => 1188,
+	"territorytime" => 2624733,
+	"rehabs" => 6667,
+	"rehabcost" => 1404830000,
+	"awards" => 462,
+	"statenhancersused" => 5,
+	"bestdamage" => 11472,
+	"racingpointsearned" => 2118,
+	"raceswon" => 698,
+	"racesentered" => 2390,
+	"receivedbountyvalue" => 88109384,
+	"pcptaken" => 1,
+	"cityitemsbought" => 85276,
+	"specialammoused" => 10977,
+	"spetaken" => 1,
+	"hollowammoused" => 4000,
+	"tracerammoused" => 2498,
+	"incendiaryammoused" => 2493,
+	"piercingammoused" => 1986,
+	"refills" => 1611
+];
+$list = [];
+foreach ( $properties as $key => $val ) {
+	$list[] = strval($key);
+}
+print("<pre>");
+print_r( $list );
+print("</pre>");
+
+$pdo = null;
+try {
+	$pdo = new PDO("sqlite:" . './slork.sqlite');
+} catch (PDOException $e) {
+	// handle the exception here
+}
+if ( !$pdo ) {
+	exit( "Cannot connect to database" );
+}
+$query = "DROP TABLE IF EXISTS properties;";
+$pdo->exec( $query );
+$query = "CREATE TABLE IF NOT EXISTS properties (id INTEGER PRIMARY KEY, property TEXT, UNIQUE(property));";
+$pdo->exec( $query );
+$query = "INSERT INTO properties (property) VALUES (?) ON CONFLICT (property) DO NOTHING;";
+$stmt = $pdo->prepare( $query );
+foreach ( $list as $item ) {
+	$stmt->execute( [$item] );
+}
+/**
+$query = "SELECT property FROM properties;";
+$stmt = $pdo->query( $query );
+foreach( $stmt as $row ) {
+	print( $row['property'] . ', ');
+}
+*/

+ 33 - 17
snippets.php

@@ -26,19 +26,25 @@ $snippets[0] = <<<HTML
 			<!-- This form adds a new maintainer -->
 		<div class="form-group">
     		<label for="newAPIKey">New maintainer</label>
-    		<input type="password" class="form-control" name="i" id="newAPIKey" aria-describedby="newAPIKey" placeholder="Enter API key">
+    		<input type="hidden" name="action" value="i">
+    		<input type="password" class="form-control" name="api" id="newAPIKey" aria-describedby="newAPIKey" placeholder="Enter API key">
     		<small id="newAPIKey" class="form-text text-muted">Assuming you are new here, add your Torn API key</small>
   		</div>
-  		<h4>OR</h4>
-  		<!-- This part selects an existing maintainer -->
+  		<button type="submit" class="btn btn-primary">Submit</button>
+  	</form>
+  	<div><p>&nbsp;</p></div>
+  	<h4>OR</h4>
+  	<!-- This part selects an existing maintainer -->
+  	<form>
   		<div class="form-group">
 			<label for="existingMaintainer">Existing maintainer</label>
-    		<select class="form-control" name="m" id="existingMaintainer">
-				<option></option>
+			<input type="hidden" name="action" value="m">
+    		<select class="form-control" name="maintainer" id="existingMaintainer">
+				<option></option><!-- Empty option -->
 HTML;
 
 foreach ( $all_maintainers as $maintainer_key => $maintainer_value ) {
-	$snippets[0] .= "\t\t\t\t<option value=\"$maintainer_key\">$maintainer_value [$maintainer_key]</option>";
+	$snippets[0] .= "\t\t\t\t<option value=\"$maintainer_key\">$maintainer_value [$maintainer_key]</option>\n";
 }
 
 $snippets[0] .= <<<HTML
@@ -62,23 +68,33 @@ print_r( $rows );
 print( "</pre>" );
 $players_id = array();
 foreach ( $rows as $row ) {
-	$players_id[] = $row['value'] . " [" . $row['player'] . "]";
+	$players_id[] = array($row['player'], $row['value'] . " [" . $row['player'] . "]");
 }
 
 $snippets[2] = <<<HTML
-	<table class="table">
-		<thead>
-			<tr>
-				<th>Player</th><th>Edit</th><th>Remove</th>
-			</tr>
-		</thead>
-		<tbody>
+	<form id="player">
+		<div class="form-group">
+			<table class="table">
+				<thead>
+					<tr>
+						<th>Player</th><th>Edit</th><th>Remove</th>
+					</tr>
+				</thead>
+				<tbody>
 HTML;
+
 		foreach ( $players_id as $player ) {
-			$snippets[2] .= "<tr><td>$player</td><td><button class=\"btn btn-primary\">Edit</button></td><td><button class=\"btn btn-danger\">Remove</button></td>";
+			$snippets[2] .= "\n\t\t\t\t\t<tr>";
+			$snippets[2] .= "\n\t\t\t\t\t\t<td>$player[1]";
+			$snippets[2] .= "<input type=\"hidden\" name=\"player\" value=\"$player[0]\" form=\"player\"></td><td>";
+			$snippets[2] .= "<input type=\"hidden\" name=\"maintainer\" value=\"$maintainer[0]\" form=\"player\">";
+			$snippets[2] .= "<button class=\"btn btn-primary\" name=\"action\" value=\"e\" form=\"player\">Edit</button></td>";
+			$snippets[2] .= "<td><button class=\"btn btn-danger\" name=\"action\" value=\"x\" form=\"player\">Remove</button></td>\n\t\t\t\t\t</tr>";
 		}
 
 $snippets[2] .= <<<HTML
-		</tbody>
-	</table>
+\n				</tbody>
+			</table>
+		</div>
+	</form>
 HTML;

+ 5 - 1
sqlite.php

@@ -30,4 +30,8 @@ CREATE TABLE IF NOT EXISTS player (
 		FOREIGN KEY (maintainer) REFERENCES maintainer(maintainer));
 QUERY;
 $stmt = $pdo->exec( $query );
-//$stmt->execute();
+//$stmt->execute();
+
+// properties.php contains queries for a subsequent
+// table properties containing default property names.
+require_once "properties.php";