Browse Source

Merge pull request 'Replace deprecated chapters.json with Airtable API' (#33) from airtable into main

Reviewed-on: https://git.socialistra.org/socialist-rifle-association/website/pulls/33
main
parent
commit
fa0742c511
8 changed files with 206 additions and 905 deletions
  1. +13
    -63
      api/state/chapters/index.php
  2. +95
    -0
      chapters/chapterlist.php
  3. +0
    -787
      chapters/chapters.json
  4. +21
    -38
      chapters/index.php
  5. +3
    -1
      docker-compose.yml
  6. +3
    -5
      donate/capture.php
  7. +4
    -11
      donate/index.php
  8. +67
    -0
      res/php/stateresolution.php

+ 13
- 63
api/state/chapters/index.php View File

@ -16,79 +16,29 @@
// You should have received a copy of the GNU General Public License
// along with website. If not, see <http://www.gnu.org/licenses/>.
// Array of state abbreviations
$states = [
"Alabama" => "AL",
"Alaska" => "AK",
"Arizona" => "AZ",
"Arkansas" => "AR",
"California" => "CA",
"Colorado" => "CO",
"Connecticut" => "CT",
"Delaware" => "DE",
"Florida" => "FL",
"Georgia" => "GA",
"Hawaii" => "HI",
"Idaho" => "ID",
"Illinois" => "IL",
"Indiana" => "IN",
"Iowa" => "IA",
"Kansas" => "KS",
"Kentucky" => "KY",
"Louisiana" => "LA",
"Maine" => "ME",
"Maryland" => "MD",
"Massachusetts" => "MA",
"Michigan" => "MI",
"Minnesota" => "MN",
"Mississippi" => "MS",
"Missouri" => "MO",
"Montana" => "MT",
"Nebraska" => "NE",
"Nevada" => "NV",
"New Hampshire" => "NH",
"New Jersey" => "NJ",
"New Mexico" => "NM",
"New York" => "NY",
"North Carolina" => "NC",
"North Dakota" => "ND",
"Ohio" => "OH",
"Oklahoma" => "OK",
"Oregon" => "OR",
"Pennsylvania" => "PA",
"Rhode Island" => "RI",
"South Carolina" => "SC",
"South Dakota" => "SD",
"Tennessee" => "TN",
"Texas" => "TX",
"Utah" => "UT",
"Vermont" => "VT",
"Virginia" => "VA",
"Washington" => "WA",
"West Virginia" => "WV",
"Wisconsin" => "WI",
"Wyoming" => "WY",
"District of Columbia" => "DC",
"Guam" => "GU",
"Marhsall Islands" => "MH",
"Puerto Rico" => "PR",
"Virgin Islands" => "VI"
];
// Ensure required parameters are present
if (!isset($_GET["state"])) {
http_response_code(404);
die();
}
if (!array_key_exists($_GET["state"], $states)) {
set_include_path(get_include_path().":"."../../../");
include_once("res/php/stateresolution.php");
include_once("chapters/chapterlist.php");
$state = resolve_state($_GET["state"]);
if (!$state) {
http_response_code(404);
die();
}
if (!array_key_exists($state, $chapters)) {
http_response_code(404);
die();
}
$chapters = json_decode(file_get_contents("../../../chapters/chapters.json"), true);
$state = $states[$_GET["state"]];
header('Content-Type: application/json; charset=utf-8');
echo json_encode($chapters[$state]);

+ 95
- 0
chapters/chapterlist.php View File

@ -0,0 +1,95 @@
<?php
set_include_path(get_include_path().":"."../");
include_once("res/php/stateresolution.php");
// Load JSON info
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.airtable.com/v0/appKRJXHcCjQU3i6p/Chapters',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . getenv("AIRTABLE_KEY"),
),
));
$response = curl_exec($curl);
curl_close($curl);
// Rearrange data how we need it
class Chapter {
// Object oriented programming in PHP. I should be shot for this.
public string $name;
public string $state;
public string $logo;
// Contact info
public string $email;
public string $twitter;
public string $instagram;
public string $facebook;
public function __construct($value, $state) {
// Ensure the chapter is actually active
if (!isset($value->fields->Status) || $value->fields->Status != "Active") {
throw new ErrorException();
}
// Retrieve name
if (!isset($value->fields->Name)) {
throw new ErrorException();
}
$this->name = explode(", ", $value->fields->Name)[1];
// Retrieve state
$this->state = resolve_state($state);
// Retrieve logo
if (!isset($value->fields->Logo[0]->url)) {
$this->logo = "https://srastatic.nyc3.cdn.digitaloceanspaces.com/web/img/logo/default.png";
} else {
$this->logo = $value->fields->Logo[0]->url;
}
// Retrieve socials
foreach (["Email", "Twitter", "Instagram", "Facebook"] as $key) {
if (!isset($value->fields->$key)) { continue; } else {
$data = $value->fields->$key;
switch ($key) {
case "Email": $this->email = $data; break;
case "Twitter": $this->twitter = $data; break;
case "Instagram": $this->instagram = $data; break;
case "Facebook": $this->facebook = $data; break;
default: break;
}
}
}
}
}
if (getenv("PROFILE") == "debug") {
echo "<pre>" . var_export($response) . "</pre>";
}
$records = json_decode($response) -> records;
$chapters = [];
foreach ($records as $key => $value) {
if (!isset($value->fields->State)) {
continue;
}
foreach ($value->fields->State as $key=>$state) {
try {
$chapter = new Chapter($value, $state);
} catch (ErrorException $e) {
continue;
}
if (!in_array(resolve_state($state), $chapters)) {
$chapters += [resolve_state($state) => []];
}
array_push($chapters[resolve_state($state)], $chapter);
}
}
ksort($chapters);
?>

+ 0
- 787
chapters/chapters.json View File

@ -1,787 +0,0 @@
{
"AK": [
{
"name": "Anchorage",
"logo": "AK/anchorage.jpg",
"social": {
"email": "[email protected]",
"twitter": "AnchorageSRA",
"facebook": "Socialist-Rifle-Association-Alaska-250794808878108",
"phone": "9074441141"
}
}
],
"AL": [
{
"name": "Northeast Alabama",
"logo": "AL/nealabama.jpg",
"social": {
"email": "[email protected]",
"twitter": "AlabamaSRA",
"facebook": "NortheastAlabamaSRA",
"instagram": "northeast_alabama_sra"
}
}
],
"AR": [
{
"name": "Arkansas",
"logo": "AR/arkansas.png",
"social": {
"email": "[email protected]",
"twitter": "ArkansasSRA"
}
}
],
"AZ": [
{
"name": "Phoenix",
"logo": "AZ/phoenix.jpg",
"social": {
"email": "[email protected]",
"twitter": "Phoenix_SRA",
"facebook": "sraphoenix",
"instagram": "phoenix.sra"
}
},
{
"name": "Tucson",
"logo": "AZ/tucson.jpg",
"social": {
"email": "[email protected]",
"twitter": "TucsonSRA",
"facebook": "TucsonSRA"
}
}
],
"CA": [
{
"name": "East Los Angeles",
"logo": "default",
"social": {
"twitter": "EastLA_SRA",
"instagram": "losangelessra"
}
},
{
"name": "Inland Empire",
"logo": "default",
"social": {
"twitter": "IE_SRA"
}
},
{
"name": "Orange County",
"logo": "CA/orangecounty.png",
"social": {
"email": "[email protected]",
"twitter": "orangecountySRA"
}
},
{
"name": "Sacramento",
"logo": "CA/sacramento.jpg",
"social": {
"email": "[email protected]",
"twitter": "sactownSRA",
"instagram": "sactownsra"
}
},
{
"name": "San Diego",
"logo": "CA/sandiego.jpg",
"social": {
"email": "[email protected]",
"twitter": "SanDiegoSRA",
"instagram": "sandiegosra",
"facebook": "SanDiegoSocialistRA"
}
},
{
"name": "SF Bay Area",
"logo": "CA/bayarea.jpg",
"social": {
"email": "[email protected]",
"twitter": "BayAreaSRA",
"instagram": "bayareasra"
}
},
{
"name": "West Los Angeles",
"logo": "CA/westla.jpg",
"social": {
"email": "[email protected]",
"twitter": "westLA_sra",
"instagram": "losangelessra"
}
}
],
"CO": [
{
"name": "Front Range",
"logo": "CO/frontrange.png",
"social": {
"email": "[email protected]",
"twitter": "FrontRangeSRA"
}
},
{
"name": "Western Slope",
"logo": "default",
"social": {
"email": "[email protected]"
}
}
],
"CT": [
{
"name": "Southern New England",
"logo": "southnewengland.jpg",
"social": {
"email": "[email protected]",
"twitter": "sne_sra"
}
},
{
"name": "Connecticut",
"logo": "CT/ctsra.png",
"social": {
"email": "[email protected]",
"twitter": "ct_sra",
"facebook": "CTSocialistRA"
}
}
],
"MA": [
{
"name": "Southern New England",
"logo": "southnewengland.jpg",
"social": {
"email": "[email protected]",
"twitter": "sne_sra"
}
}
],
"RI": [
{
"name": "Southern New England",
"logo": "southnewengland.jpg",
"social": {
"email": "[email protected]",
"twitter": "sne_sra"
}
}
],
"FL": [
{
"name": "Northest Florida",
"logo": "FL/NEFLlogo.jpg",
"social": {
"email": "[email protected]",
"facebook": "NEFloridaSRA"
}
},
{
"name": "South Florida",
"logo": "FL/southflorida.jpg",
"social": {
"email": "[email protected]",
"twitter": "SFLSRA"
}
},
{
"name": "Space Coast",
"logo": "default",
"social": {
"email": "[email protected]"
}
},
{
"name": "Tallahassee",
"logo": "FL/tallahassee.jpg",
"social": {
"email": "[email protected]",
"twitter": "TLHSRA"
}
},
{
"name": "Tampa Bay",
"logo": "FL/tampabay.jpg",
"social": {
"email": "[email protected]"
}
}
],
"GA": [
{
"name": "Flint River",
"logo": "default",
"social": {
"email": "[email protected]"
}
},
{
"name": "North Georgia",
"logo": "GA/northga.jpg",
"social": {
"email": "[email protected]",
"twitter": "northgasra"
}
}
],
"IA": [
{
"name": "Iowa",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "IowaSRA"
}
}
],
"ID": [
{
"name": "Boise",
"logo": "default",
"social": {
"email": "[email protected]"
}
}
],
"IL": [
{
"name": "Chicago",
"logo": "IL/Chicago.svg",
"social": {
"email": "[email protected]",
"twitter": "ChicagoSRA",
"facebook": "ChicagoSRA"
}
},
{
"name": "Northern Illinois",
"logo": "IL/nil.png",
"social": {
"twitter": "N_IL_SRA",
"email": "[email protected]"
}
}
],
"IN": [
{
"name": "Central Indiana",
"logo": "IN/centralindiana.jpg",
"social": {
"email": "[email protected]",
"twitter": "IndianaSRA",
"facebook": "CINSRA"
}
}
],
"KS": [
{
"name": "Wichita KS",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "WichitaSRA"
}
},
{
"name": "Kansas City",
"logo": "MO/kcsra-color.png",
"social": {
"email": "[email protected]",
"twitter": "KansasCitySRA"
}
}
],
"KY": [
{
"name": "Kentucky",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "SRAKentucky"
}
}
],
"LA": [
{
"name": "NOLA",
"logo": "default",
"social": {
"email": "[email protected]"
}
}
],
"MD": [
{
"name": "Maryland",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "maryland_sra",
"instagram": "maryland_sra"
}
}
],
"ME": [
{
"name": "Eastern Maine",
"logo": "default",
"social": {
"email": "[email protected]"
}
},
{
"name": "Southern Maine",
"logo": "ME/smsra.png",
"social": {
"email": "[email protected]",
"twitter": "mainesra"
}
}
],
"MI": [
{
"name": "Michigan",
"logo": "MI/michigan.jpg",
"social": {
"email": "[email protected]",
"twitter": "rifle_mi",
"facebook": "MISOCIALISTRA"
}
}
],
"MN": [
{
"name": "Minnesota",
"logo": "MN/mnsra.png",
"social": {
"email": "[email protected]",
"twitter": "sra_minnesota",
"facebook": "SRAMinnesota"
}
}
],
"MO": [
{
"name": "Kansas City",
"logo": "MO/kcsra-color.png",
"social": {
"email": "[email protected]",
"twitter": "KansasCitySRA"
}
},
{
"name": "Springfield",
"logo": "default",
"social": {
"email": "[email protected]"
}
},
{
"name": "St Louis",
"logo": "MO/stlouis.jpg",
"social": {
"email": "[email protected]",
"twitter": "SRA_STL",
"facebook": "Socialist-Rifle-Association-Saint-Louis-2229107013996514"
}
}
],
"MT": [
{
"name": "Montana",
"logo": "MT/MontanaSRALogo.png",
"social": {
"email": "[email protected]",
"twitter": "montana_sra"
}
}
],
"NC": [
{
"name": "Asheville",
"logo": "NC/asheville.jpg",
"social": {
"email": "[email protected]",
"twitter": "SRA_Asheville"
}
},
{
"name": "Charlotte",
"logo": "NC/charlotte.png",
"social": {
"email": "[email protected]",
"twitter": "CharlotteMetSRA"
}
},
{
"name": "Triad NC",
"logo": "NC/triad.jpg",
"social": {
"email": "[email protected]",
"twitter": "TriadNCSRA",
"instagram": "triadncsra"
}
},
{
"name": "Triangle NC",
"logo": "NC/triangle.png",
"social": {
"email": "[email protected]",
"twitter": "TriangleSRA"
}
}
],
"NH": [
{
"name": "New Hampshire",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "newhampshireSRA",
"facebook": "newhampshireSRA"
}
}
],
"NM": [
{
"name": "Albuquerque",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "SRANewMexico",
"instagram": "sra_newmexico"
}
}
],
"NV": [
{
"name": "Las Vegas",
"logo": "NV/lvsra.png",
"social": {
"email": "[email protected]"
}
},
{
"name": "Reno",
"logo": "NV/reno.jpg",
"social": {
"email": "[email protected]",
"twitter": "reno_sra",
"facebook": "srareno",
"instagram": "reno_sra"
}
}
],
"NY": [
{
"name": "New York City",
"logo": "NY/nyc.jpg",
"social": {
"email": "[email protected]",
"twitter": "nyc_socialistRA"
}
},
{
"name": "Upstate New York",
"logo": "NY/upstateny.jpg",
"social": {
"email": "[email protected]",
"twitter": "SRA_UpstateNY",
"facebook": "UpstateNYSRA",
"instagram": "sra_upstateny",
"website": "https://sra-upstateny.org"
}
}
],
"OH": [
{
"name": "Central Ohio",
"logo": "OH/centraloh.jpg",
"social": {
"email": "[email protected]",
"twitter": "CentralOHSRA"
}
},
{
"name": "Greater Cincinnati",
"logo": "default",
"social": {
}
},
{
"name": "Northeast Ohio",
"logo": "OH/neoh.png",
"social": {
"email": "[email protected]",
"twitter": "NEO_SRA",
"facebook": "NortheastOhioSRA",
"instagram": "neo_sra"
}
},
{
"name": "Northwest Ohio",
"logo": "default",
"social": {
"email": "[email protected]"
}
}
],
"OK": [
{
"name": "Oklahoma City",
"logo": "default",
"social": {
"email": "[email protected]"
}
},
{
"name": "Tulsa",
"logo": "OK/tulsa.png",
"social": {
"email": "[email protected]",
"twitter": "RifleTulsa",
"facebook": "SocialistRATulsa"
}
}
],
"OR": [
{
"name": "Lane County",
"logo": "OR/lanecounty.png",
"social": {
"email": "[email protected]",
"twitter": "LaneCountySRA",
"instagram": "lanecountysra"
}
},
{
"name": "Heart of the Valley",
"logo": "OR/hotv.jpg",
"social": {
"email": "[email protected]",
"twitter": "srahotv"
}
},
{
"name": "PDX",
"logo": "OR/pdx.png",
"social": {
"email": "[email protected]",
"twitter": "PortlandSra",
"instagram": "pdxsra"
}
},
{
"name": "Southern OR",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "SouthernOR_SRA"
}
}
],
"PA": [
{
"logo": "PA/centralpa.png",
"name": "Central Pennsylvania",
"social": {
"email": "[email protected]",
"twitter": "CentralPaSra",
"facebook": "CentralPASra"
}
},
{
"name": "Philadelphia",
"logo": "PA/philly.jpg",
"social": {
"email": "[email protected]",
"twitter": "PhillySRA",
"facebook": "SRAPhilly"
}
},
{
"name": "Pittsburgh",
"logo": "PA/pittsburgh.png",
"social": {
"email": "[email protected]",
"twitter": "pittsburghSRA"
}
}
],
"SC": [
{
"name": "Low Country",
"logo": "default",
"social": {}
},
{
"name": "Upstate SC",
"logo": "SC/sc.png",
"social": {
"email": "[email protected]",
"twitter": "ScSRA",
"facebook": "UpstateSCRifleAssociation"
}
}
],
"TN": [
{
"name": "Tennessee",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "SRATennessee"
}
}
],
"TX": [
{
"name": "Austin",
"logo": "TX/atx.png",
"social": {
"email": "[email protected]",
"twitter": "atx_sra",
"instagram": "atx_sra"
}
},
{
"name": "Corpus Christi",
"logo": "TX/crp.png",
"social": {
"email": "[email protected]",
"twitter": "CorpusSra",
"facebook": "CCSocialistRA",
"instagram": "corpus_christi_sra"
}
},
{
"name": "Dallas/Fort Worth",
"logo": "TX/dfw.jpg",
"social": {
"email": "[email protected]",
"twitter": "SRA_DFW"
}
},
{
"name": "Houston",
"logo": "TX/Houston.jpg",
"social": {
"email": "[email protected]",
"twitter": "HoustonSRA"
}
},
{
"name": "San Antonio",
"logo": "TX/sanantonio.jpg",
"social": {
"email": "[email protected]",
"twitter": "SraAntonio"
}
}
],
"UT": [
{
"name": "SLC",
"logo": "UT/slc.jpg",
"social": {
"email": "[email protected]",
"twitter": "slcSRA"
}
}
],
"VA": [
{
"name": "Piedmont / Richmond",
"logo": "VA/rva.png",
"social": {
"email": "[email protected]",
"twitter": "rva_sra"
}
},
{
"name": "Southwest Virginia",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "SWVASRA"
}
}
],
"VT": [
{
"name": "Vermont",
"logo": "default",
"social": {
"email": "[email protected]"
}
}
],
"WA": [
{
"name": "Eastern Washington",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "SRA_Spokane"
}
},
{
"name": "Seattle / Puget Sound",
"logo": "WA/seattle.jpg",
"social": {
"email": "[email protected]",
"twitter": "SeattleSRA",
"instagram": "SeattleSRA"
}
}
],
"WI": [
{
"name": "Madison WI",
"logo": "WI/madison.jpg",
"social": {
"email": "[email protected]",
"twitter": "MadisonSra",
"facebook": "madisonSRA"
}
},
{
"name": "Milwaukee",
"logo": "WI/milwaukee.jpg",
"social": {
"email": "[email protected]",
"twitter": "milwaukeeSRA",
"facebook": "MilwaukeeSRA"
}
},
{
"name": "Northeastern Wisconsin",
"logo": "default",
"social": {
"email": "[email protected]"
}
},
{
"name": "Western Wisconsin",
"logo": "default",
"social": {
"email": "[email protected]",
"twitter": "WesternWISRA"
}
}
],
"WY": [
{
"name": "Southeast Wyoming",
"logo": "default",
"social": {
"email": "[email protected]"
}
}
]
}

+ 21
- 38
chapters/index.php View File

@ -16,6 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with website. If not, see <http://www.gnu.org/licenses/>.
?>
<?php
include_once("./chapterlist.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -149,49 +152,29 @@ h5 {
<div style="text-align: center;"><h2 id="instructions">Click on a state above to view local chapters</h2></div>
<hr>
<div>
<?php
// Load JSON info
$chapters = json_decode(file_get_contents("chapters.json"), true);
// Build state list
<?php
function build_social(string $icon, string $url) {
echo("<h3><a href=\"$url\"><i class=\"$icon\"></i></a></h3>");
}
foreach ($chapters as $state => $list) {
echo("<div id=\"list-$state\" class=\"chapter-details\" style=\"display: none\">");
// Build chapters
foreach ($list as $chapter) {
$logo = $chapter["logo"];
$name = $chapter["name"];
echo("<div id=\"biotext\">");
if ($logo == "default") {
echo("<img src=\"https://srastatic.nyc3.cdn.digitaloceanspaces.com/web/img/logo/default.png\" class=\"bio\">"); }
else {
echo("<img src=\"https://srastatic.nyc3.cdn.digitaloceanspaces.com/web/img/logo/$logo\" class=\"bio\">"); }
$logo = $chapter->logo;
$name = $chapter->name;
echo("
<div id=\"biodesk\">
<div id=\"chaplist\">
<h1>$name</h1>
");
foreach ($chapter["social"] as $platform => $username) {
// Build social media links
switch ($platform) {
case "twitter":
echo("<h3><a href=\"https://twitter.com/$username\"><i class=\"fab fa-twitter\"></i></a></h3>");
break;
case "facebook":
echo("<h3><a href=\"https://www.facebook.com/$username/\"><i class=\"fab fa-facebook-f\"></i></a></h3>");
break;
case "instagram":
echo("<h3><a href=\"https://instagram.com/$username\"><i class=\"fab fa-instagram\"></i></a></h3>");
break;
case "email":
echo("<h3><a href=\"mailto:$username\"><i class=\"fas fa-envelope\"></i></a></h3>");
break;
case "website":
echo("<h3><a href=\"$username\"><i class=\"fas fa-link\"></i></a></h3>");
break;
case "phone":
echo('<h3><a href="tel:' . $username . '"><i class="fas fa-phone"></i></a></h3>');
break;
}
}
<div id=\"biotext\">
<img src=\"$logo\" class=\"bio\">
<div id=\"biodesk\">
<div id=\"chaplist\">
<h1>$name</h1>
");
if (isset($chapter->email)) { build_social("fas fa-envelope", "mailto:" . $chapter->email); }
if (isset($chapter->twitter)) { build_social("fab fa-twitter", $chapter->twitter); }
if (isset($chapter->instagram)) { build_social("fab fa-instagram", $chapter->instagram); }
if (isset($chapter->facebook)) { build_social("fab fa-facebook", $chapter->facebook); }
echo("</div></div></div><hr>");
}
echo("</div>");


+ 3
- 1
docker-compose.yml View File

@ -6,4 +6,6 @@ services:
- 80:80
environment:
- STRIPE_PUBLIC_KEY=${STRIPE_PUBLIC_KEY}
- STRIPE_PRIVATE_KEY=${STRIPE_PRIVATE_KEY}
- STRIPE_PRIVATE_KEY=${STRIPE_PRIVATE_KEY}
- AIRTABLE_KEY=${AIRTABLE_KEY}
- PROFILE=${PROFILE}

+ 3
- 5
donate/capture.php View File

@ -57,14 +57,12 @@ array starts with the "National SRA" value because it's a special case.
$recipient = strip_tags($_POST["recipient"]);
$recipientsList = array("National SRA");
// Load chapters.json from /chapters
$chapters = json_decode(
file_get_contents("../chapters/chapters.json"),
true // Make an associative array
);
include_once("../chapters/chapterlist.php");
// Create the list
foreach ($chapters as $state => $list) {
foreach ($list as $chapter) {
$chapterString = $state . ': ' . $chapter["name"];
$chapterString = $state . ': ' . $chapter->name;
array_push($recipientsList, $chapterString);
}
}


+ 4
- 11
donate/index.php View File

@ -16,6 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with website. If not, see <http://www.gnu.org/licenses/>.
include_once("../chapters/chapterlist.php");
?>
@ -148,9 +149,6 @@
#card-errors {
color: #000;
font-weight: 400;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
@ -334,27 +332,22 @@ if (isset($error)) {
<select name="recipient" id="recipient" required>
<option value="National SRA">National SRA</option>
<?php
// Populate selection with list of chapters
$chapters = json_decode(
file_get_contents("../chapters/chapters.json"),
true
);
$chapterIndex = 1;
foreach ($chapters as $state => $list) {
foreach($list as $chapter) {
echo '<option value="'
. $state . ': ' . $chapter["name"] .
. $state . ': ' . $chapter->name .
'"';
/*
* allows url auto selection of chapter and state for donations like so
* https://socialistra.org/donate/?state=ct&chapter=southern%20new%20england
*
*/
if (isset($_GET["chapter"]) && isset($_GET["state"]) && strtolower($chapter["name"]) == strtolower($_GET["chapter"]) && strtolower($state) == strtolower($_GET["state"])) {
if (isset($_GET["chapter"]) && isset($_GET["state"]) && strtolower($chapter->name) == strtolower($_GET["chapter"]) && strtolower($state) == strtolower($_GET["state"])) {
echo ' selected';
}
echo '>';
echo $state . ': ' . $chapter["name"] . '</option>';
echo $state . ': ' . $chapter->name . '</option>';
$chapterIndex += 1;
}
}


+ 67
- 0
res/php/stateresolution.php View File

@ -0,0 +1,67 @@
<?php
// The jquery plugin for the map requires two letter abbreviations instead of full state names
function resolve_state(string $state) {
// Array of state abbreviations
$states = [
"Alabama" => "AL",
"Alaska" => "AK",
"Arizona" => "AZ",
"Arkansas" => "AR",
"California" => "CA",
"Colorado" => "CO",
"Connecticut" => "CT",
"Delaware" => "DE",
"Florida" => "FL",
"Georgia" => "GA",
"Hawaii" => "HI",
"Idaho" => "ID",
"Illinois" => "IL",
"Indiana" => "IN",
"Iowa" => "IA",
"Kansas" => "KS",
"Kentucky" => "KY",
"Louisiana" => "LA",
"Maine" => "ME",
"Maryland" => "MD",
"Massachusetts" => "MA",
"Michigan" => "MI",
"Minnesota" => "MN",
"Mississippi" => "MS",
"Missouri" => "MO",
"Montana" => "MT",
"Nebraska" => "NE",
"Nevada" => "NV",
"New Hampshire" => "NH",
"New Jersey" => "NJ",
"New Mexico" => "NM",
"New York" => "NY",
"North Carolina" => "NC",
"North Dakota" => "ND",
"Ohio" => "OH",
"Oklahoma" => "OK",
"Oregon" => "OR",
"Pennsylvania" => "PA",
"Rhode Island" => "RI",
"South Carolina" => "SC",
"South Dakota" => "SD",
"Tennessee" => "TN",
"Texas" => "TX",
"Utah" => "UT",
"Vermont" => "VT",
"Virginia" => "VA",
"Washington" => "WA",
"West Virginia" => "WV",
"Wisconsin" => "WI",
"Wyoming" => "WY",
"District of Columbia" => "DC",
"Guam" => "GU",
"Marhsall Islands" => "MH",
"Puerto Rico" => "PR",
"Virgin Islands" => "VI"
];
if (!array_key_exists($state, $states)) {
return false;
}
return $states[$state];
}
?>

Loading…
Cancel
Save