Skip to content

Instantly share code, notes, and snippets.

@bmcbride
bmcbride / fulcrum-device-delete-webhook.php
Created February 12, 2014 16:51
Fulcrum webhook endpoint used for deleting a record from the device when the Status field is changed. In this case the Status field data name was left at the default 'status' (line 15). I set the default status to 'Active' (green) and added an additional status of 'Deleted' (red). When a user changes the status to 'Deleted' and syncs their devic…
<?php
# Fulcrum Info
$form_id = 'my_form_id'; // Get from App URL: https://web.fulcrumapp.com/data/{my_form_id}#
$fulcrum_api_key = 'my_fulcrum_api_key'; // Get from Fulcrum settings page
//$input = file_get_contents('payload.json'); # local file for testing
$input = file_get_contents('php://input'); # POST data from webhook
$data = json_decode($input, TRUE);
# Make sure it's the form we want
@bmcbride
bmcbride / index.html
Created May 2, 2014 19:31
Fulcrum GeoJSON Data Shares
<!DOCTYPE html>
<html>
<head>
<title>Fulcrum Data Shares</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"></script>
@bmcbride
bmcbride / fulcrum-photo-viewer.php
Last active August 29, 2015 14:01
A simple script for viewing a contact page of photos, based on a column of comma delimited photo ID's as fetched from Fulcrum. Simply prepend 'http://someurl.com/fulcrum-photo-viewer.php?photos=' to your list of photo ID's.
<?php
$fulcrum_api_key = 'your-fulcrum-api-key-goes-here';
if (!isset($_GET['photos']) && !isset($_GET['photo'])){
print 'photo or photos parameter required!';
}
if (isset($_GET['photos'])) {
$photos = explode(',', $_GET['photos']);
@bmcbride
bmcbride / README.md
Last active August 29, 2015 14:04
Post-processing scripts for generating OpenTrails compliant Trailheads CSV & GeoJOSN files from the Fulcrum OpenTrails Trailhead App- http://fulcrumapp.com/apps/opentrails-trailheads

Data exported out of the Fulcrum OpenTrails Trailhead App requires some post processing in order to generate the proper files, per the OpenTrails trailheads.geojson specification. Simply export as Shapefile and execute the following GDAL/OGR commands:

ogr2ogr -f "SQLite" opentrails-trailheads.sqlite -nln "trailheads" -a_srs "EPSG:4326" opentrails_trailheads.shp
ogr2ogr -update -f "SQLite" opentrails-trailheads.sqlite -nln "osm_tags" opentrails_trailheads_osm_tags.dbf
@bmcbride
bmcbride / index.html
Created October 15, 2014 14:59
Leaflet.fullscreen plugin iframe demo
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1,user-scalable=no,maximum-scale=1,width=device-width">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>Leaflet Fullscreen Iframe</title>
</head>
<body>
@bmcbride
bmcbride / fulcrum-basic-webhook.php
Created November 10, 2014 22:11
Basic Fulcrum webhook endpoint written in PHP. Enter your form id & email, upload to a web server, and configure your webhook settings in Fulcrum to point to this endpoint. Default action emails webhook JSON payload, but realistically, you would want to do something with the recordArray and formArray variables.
<?php
$form_id = 'your-fulcrum-form-id-goes-here';
$email = 'me@gmail.com';
$input = file_get_contents('php://input'); # POST data from webhook
//$input = file_get_contents('payload.json'); # local file for testing
$webhook = json_decode($input, true);
# Webhook data
$webhookID = $webhook['id'];
import os
import urllib
import urllib2
import base64
import json
import sys
import argparse
try:
import requests
except ImportError:
@bmcbride
bmcbride / fulcrum_classification_set_example.json
Created March 26, 2015 17:37
Example classification_set JSON for an API request
{
"classification_set": {
"name": "Agricultural Products",
"description": "A list of common agricultural products",
"items": [
{
"label": "cereals",
"value": "cereals",
"child_classifications": [
{
@bmcbride
bmcbride / sqlite_geojson.php
Created February 27, 2012 02:08
PHP SQLite to GeoJSON
<?php
/**
* SQLite to GeoJSON (Requires https://github.com/phayes/geoPHP)
* Query a SQLite table or view (with a WKB GEOMETRY field) and return the results in GeoJSON format, suitable for use in OpenLayers, Leaflet, etc.
*
* @param string $geotable The SQLite table name *REQUIRED*
* @param string $geomfield The WKB GEOMETRY field *REQUIRED*
* @param string $fields Fields to be returned *OPTIONAL (If omitted, all fields will be returned)*
* @param string $parameters SQL WHERE clause parameters *OPTIONAL*
* @param string $orderby SQL ORDER BY constraint *OPTIONAL*
@bmcbride
bmcbride / move.bat
Created October 26, 2015 13:53
Batch organize Fulcrum photos into different folders.
move /Y ad0c334e-b57f-471f-89f1-2ca17988b74c.jpg photos-a
move /Y 88e60f5c-15e9-4d68-8e79-4b659f66157b.jpg photos-a
move /Y 4da2cd00-d3a7-4468-997e-042303dc7137.jpg photos-a
move /Y bc0edbe2-45b0-4ad5-9b35-a8c3e623634d.jpg photos-a
move /Y 9fa41b28-24c8-4f8f-abf5-08604a043d13.jpg photos-a
move /Y e28c7d9c-06af-43bc-8f8c-1862f0bc6642.jpg photos-a
move /Y 95360e82-f6a5-46ce-b33d-58a8f571fe11.jpg photos-b
move /Y cb39737a-a3ed-4240-91ff-d967c8151ab9.jpg photos-b
move /Y 2be31a26-a482-4802-81e9-478e5cc676e9.jpg photos-b
move /Y 4b4aeba8-7d78-4a41-9c61-b5bd60a484b2.jpg photos-b