Skip to content

Commit

Permalink
Added Settings page, added support for default weapon selection on Ad…
Browse files Browse the repository at this point in the history
…d Operative, display tweaks
  • Loading branch information
vjosset committed Nov 1, 2022
1 parent 0ebd709 commit 1a54f98
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 142 deletions.
12 changes: 9 additions & 3 deletions api/faction.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ function GETFaction() {
// Return the requested faction
$faction = Faction::GetFaction($factionid);

// Load the faction's killteams
$faction->loadKillTeams();
echo json_encode($faction);
if ($faction != null) {
// Load the faction's killteams
$faction->loadKillTeams();
echo json_encode($faction);
} else {
// Something went wrong
header("HTTP/1.0 404 Faction not found");
die();
}
}
}
?>
45 changes: 0 additions & 45 deletions api/imgdirtest.php

This file was deleted.

14 changes: 10 additions & 4 deletions api/operativeportrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ function GETRosterOperativePortrait() {
// File was found; read it and serve it
$filepath = $custopportraitpath;
} else {
// File not found, serve the generic portrait for this operative
// Custom file not found, serve the generic portrait for this operative
$filepath = "../img/portraits/{$ro->factionid}/{$ro->killteamid}/{$ro->fireteamid}/{$ro->opid}.jpg";

// Check if file exists
if (!file_exists($filepath)) {
header('HTTP/1.0 404 Portrait not found');
die();
}
}

// Read the found file and serve it
Expand Down Expand Up @@ -148,14 +154,14 @@ function POSTRosterOperativePortrait() {
die();
}
$filesize= $_FILES['file']['size'];
$fileext = strtolower(end(explode('.', $filename)));
$fileext = strtolower(pathinfo($filename)['extension']);

// Save the resized image
if (!in_array($fileext, array('jpg','jpeg','png','gif','JPG','JPEG','PNG','GIF'))) {
header('HTTP/1.0 400 Invalid File Extension');
die();
} else if($filesize > 2097152) {
header('HTTP/1.0 400 Max portrait size is 2 MB');
} else if($filesize > 10485760) {
header('HTTP/1.0 400 Max portrait size is 5 MB');
die();
} else {
// Get the uploaded image
Expand Down
5 changes: 5 additions & 0 deletions api/roster.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ function POSTRoster() {
$roster->rostername = "Copy of " . $roster->rostername;
}

$newrostername = getIfSet($_REQUEST["rostername"]);
if ($newrostername != "") {
$roster->rostername = $newrostername;
}

// Update its values for the current user and new roster id
$roster->rosterid = $newrosterid;
$roster->userid = $u->userid;
Expand Down
13 changes: 9 additions & 4 deletions api/rosterportrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ function GETRosterPortrait() {
// File not found, serve the generic portrait for this roster
$filepath = "../img/portraits/{$r->factionid}/{$r->killteamid}/{$r->killteamid}.png";

// Check if file exists
if (!file_exists($filepath)) {
header('HTTP/1.0 404 Portrait not found');
die();
}

// Read the found file and serve it
$thumb = imagecreatefromstring(file_get_contents($filepath));
header('Content-Type: image/png');
Expand Down Expand Up @@ -155,15 +161,14 @@ function POSTRosterPortrait() {
}

$filesize = $_FILES["file"]["size"];
$tmpext = explode('.', $filename);
$fileext = strtolower(end($tmpext));
$fileext = strtolower(pathinfo($filename)['extension']);

// Save the resized image
if (!in_array($fileext, array('jpg','jpeg','png','gif','JPG','JPEG','PNG','GIF'))) {
header('HTTP/1.0 400 Invalid File Extension');
die();
} else if($filesize > 2097152) {
header('HTTP/1.0 400 Max portrait size is 2 MB');
} else if($filesize > 10485760) {
header('HTTP/1.0 400 Max portrait size is 5 MB');
die();
} else {
// Get the uploaded image
Expand Down
4 changes: 3 additions & 1 deletion classes/operative.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function loadWeapons() {

global $dbcon;

$sql = "SELECT W.*, WP.profileid, W.weptype, WP.name, WP.A, WP.BS, WP.D, WP.A, WP.SR FROM Weapon W INNER JOIN WeaponProfile WP ON WP.killteamid = W.killteamid AND WP.fireteamid = W.fireteamid AND W.opid = WP.opid AND WP.wepid = W.wepid WHERE W.factionid = ? AND W.killteamid = ? AND W.fireteamid = ? AND W.opid = ? ORDER BY W.wepseq, W.weptype DESC, W.wepname, WP.profileid;";
$sql = "SELECT W.*, WP.profileid, W.weptype, WP.name, WP.A, WP.BS, WP.D, WP.A, WP.SR, W.isdefault FROM Weapon W INNER JOIN WeaponProfile WP ON WP.killteamid = W.killteamid AND WP.fireteamid = W.fireteamid AND W.opid = WP.opid AND WP.wepid = W.wepid WHERE W.factionid = ? AND W.killteamid = ? AND W.fireteamid = ? AND W.opid = ? ORDER BY W.wepseq, W.weptype DESC, W.wepname, WP.profileid;";

$cmd = $dbcon->prepare($sql);
if (!$cmd) {
Expand Down Expand Up @@ -80,6 +80,8 @@ public function loadWeapons() {
$currwep->wepid = $row->wepid;
$currwep->wepname = $row->wepname;
$currwep->weptype = $row->weptype;
$currwep->isdefault = $row->isdefault;
$currwep->isselected = $row->isdefault == 1;
}

// Load the profile
Expand Down
2 changes: 0 additions & 2 deletions classes/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
$root = $_SERVER['DOCUMENT_ROOT'];
require_once $root . '/include.php';

use OFW;

class Session extends \OFW\OFWObject {
public $sessionid = "";
public $userid = "";
Expand Down
2 changes: 0 additions & 2 deletions classes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
$root = $_SERVER['DOCUMENT_ROOT'];
require_once $root . '/include.php';

use OFW;

class User extends \OFW\OFWObject {
public $userid = "";
public $username = "";
Expand Down
1 change: 1 addition & 0 deletions classes/weapon.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Weapon extends \OFW\OFWObject {
public $wepseq = 0;
public $wepname = "";
public $weptype = "";
public $isdefault = 0;

public $profiles = [];

Expand Down
2 changes: 1 addition & 1 deletion faction.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<div ng-hide="loading">
<div class="card-group">
<div ng-repeat="killteam in faction.killteams" class="col-12 col-md-6 col-xl-4 p-1">
<div class="card border-light shadow darkcard">
<div class="card border-light shadow darkcard h-100">
<!-- Portrait -->
<img class="card-img-top" ng-src="/img/portraits/{{ faction.factionid }}/{{ killteam.killteamid }}/{{ killteam.killteamid }}.png" style="max-height: 270px; min-height: 270px; object-position: center top; object-fit: cover;" />

Expand Down
2 changes: 1 addition & 1 deletion header.shtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script type="text/javascript" src="/js/utils.js?cb=202210282122"></script>

<!-- App/Controller -->
<script type="text/javascript" src="js/app.js?cb=202210291908"></script>
<script type="text/javascript" src="js/app.js?cb=202211011129"></script>

<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
Expand Down
12 changes: 9 additions & 3 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ var app = angular.module("kt", ['ngSanitize'])
// Load a default roster for this user to get them started
$.ajax({
type: "POST",
url: APIURL + "roster.php?rid=PB-INTS&clone=1",
url: APIURL + "roster.php?rid=PB-INTS&clone=1&rostername=Sample Team: Intercessors",
timeout: 5000,
async: true,

Expand Down Expand Up @@ -1193,6 +1193,13 @@ var app = angular.module("kt", ['ngSanitize'])
}
}

// Validate the input
if (newop.wepids == "" && $scope.addop.operative.weapons.length > 0) {
// No weapons selected
toast("Please select weapons for this operative");
return;
}

// Parse the equipment
newop.eqids = "";
if ($scope.addop.operative.equipments) {
Expand Down Expand Up @@ -2172,10 +2179,9 @@ var app = angular.module("kt", ['ngSanitize'])
}

$scope.showPhoto = function(title, photourl) {
console.log("Showing photo " + title);
$scope.popup = {
"title": title,
"text": "<img src='" + photourl + "' class='w-100' />"
"text": "<img src='" + photourl + "#" + (new Date()).getTime() + "' class='w-100' />"
}

$("#popupmodal").modal("show");
Expand Down
5 changes: 4 additions & 1 deletion killteam.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@
</h3>

<div class="card-group collapse show" id="ft_{{ fireteam.fireteamid }}">
<div class="col-12 col-md-6 col-xl-4 align-items-stretch" ng-repeat="operative in fireteam.operatives">
<div ng-if="settings['display'] == 'card' || settings['display'] == null" class="col-12 col-md-6 col-xl-4 align-items-stretch" ng-repeat="operative in fireteam.operatives">
<?php include "templates/op_card.shtml" ?>
</div>
<div ng-if="settings['display'] == 'list'" class="col-12 col-md-6 col-xl-4 align-items-stretch" ng-repeat="operative in fireteam.operatives">
<?php include "templates/op_list.shtml" ?>
</div>
</div>
<br/>
</div>
Expand Down
7 changes: 3 additions & 4 deletions roster.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
$myRoster = Roster::GetRoster($rid);
if ($myRoster == null) {
// Roster not found
// Send them to login I guess?
header("Location: /login.htm");
// Send them to My Rosters I guess?
header("Location: /rosters.php");
exit;
}
$myRoster->loadOperatives();
Expand Down Expand Up @@ -78,10 +78,9 @@
?>
<li><a class="pointer dropdown-item p-1" ng-click="initAddOp(myRoster);"><i class="far fa-plus-square fa-fw" data-bs-toggle="tooltip" data-bs-placement="top" title="Add Operative"></i> Add Operative</a></li>
<li><a class="pointer dropdown-item p-1" ng-click="initEditRoster(myRoster);"><i class="fas fa-edit fa-fw" data-bs-toggle="tooltip" data-bs-placement="top" title="Rename Roster"></i> Rename Roster</a></li>
<li><a class="pointer dropdown-item p-1" ng-click="initUploadRosterPortrait(myRoster)" data-bs-toggle="tooltip" data-bs-placement="top" title="Change Portrait"><i class="fas fa-camera fa-fw"></i> Edit Roster Portrait</a></li>
<li><a class="pointer dropdown-item p-1" ng-click="initUploadRosterPortrait(myRoster)" data-bs-toggle="tooltip" data-bs-placement="top" title="Change Portrait"><i class="fas fa-camera fa-fw"></i> Edit Roster Portrait</a></li>
<li><a class="pointer dropdown-item p-1" ng-click="showpopup(myRoster.rostername, getRosterTextDescription(myRoster));"><i class="fas fa-file-alt fa-fw"></i> Get Text Description</a></li>
<!-- <li><a class="pointer dropdown-item p-1" ng-click="initPrintRoster(myRoster);"><i class="fas fa-print fa-fw" data-bs-toggle="tooltip" data-bs-placement="top" title="Print Roster"></i> Print</a></li> -->
<li ng-if="settings['display'] == 'list'"><a class="pointer dropdown-item p-1" ng-click="setSetting('display', 'card');"><i class="pointer far fa-id-card fa-fw"></i> Show Portraits</a></li>
<li ng-if="settings['display'] == 'card' || settings['display'] == null" ng-click="setSetting('display', 'list');"><a class="pointer dropdown-item p-1"><i class="pointer fas fa-list fa-fw"></i> Hide Portraits</a></li>
<!-- <li><a class="pointer dropdown-item p-1" onclick="$('#myrosterhelpmodal').modal('show');te('roster', 'help');"><i class="far fa-question-circle fa-fw" id="myrosterhelpbutton"></i> Help</a></li> -->
<li><a class="pointer dropdown-item p-1" ng-click="trackEvent('myRosters', 'getshareurl'); showShareRoster(myRoster);" data-bs-toggle="tooltip" data-bs-placement="top" title="Share Roster"><i class="fas fa-share-square fa-fw"></i> Share Roster</a></li>
Expand Down
1 change: 0 additions & 1 deletion rosters.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="rostersactions">
<li><a class="pointer dropdown-item p-1" ng-click="initNewRoster();"><i class="far fa-plus-square fa-fw" data-bs-toggle="tooltip" data-bs-placement="top" title="Add Operative"></i> Add New Roster</a></li>
<li><a class="pointer dropdown-item p-1 navloader" ng-href="/rosters.php?uid=prebuilt"><i class="fas fa-users fa-fw"></i> Pre-Built Rosters</a></li>
<li ng-if="settings['display'] == 'list'"><a class="pointer dropdown-item p-1" ng-click="setSetting('display', 'card');"><i class="pointer far fa-id-card fa-fw"></i> Show Portraits</a></li>
<li ng-if="settings['display'] == 'card' || settings['display'] == null" ng-click="setSetting('display', 'list');"><a class="pointer dropdown-item p-1"><i class="pointer fas fa-list fa-fw"></i> Hide Portraits</a></li>
</ul>
</div>
Expand Down
66 changes: 0 additions & 66 deletions settings.htm

This file was deleted.

Loading

0 comments on commit 1a54f98

Please sign in to comment.