testing

Modified: February 14, 2026 7:58 PM Category: Coding Notes List: Projects Created: October 15, 2025 4:17 PM Master Type: Notes Hide: No Starred: No Status: Unassigned

<?php
// CONFIG
$drupal_base = "https://hub.sea-meets-sky.com/main/";
$jsonapi_notes = "$drupal_base/jsonapi/node/n";
$username = "admin";
$password = "And1mJavert!";

// Handle quick capture form submission
if (!empty($_POST['note_body'])) {
    $body_text = trim($_POST['note_body']);
    $lines = explode("\n", $body_text);
    $title = trim($lines[0]) ?: 'Untitled Note';

    $new_note = [
        'data' => [
            'type' => 'node--n',
            'attributes' => [
                'title' => $title,
                'body' => ['value' => $body_text, 'format' => 'plain_text'],
                'field_inbox' => true, // quick capture default
            ],
        ],
    ];

    $ch = curl_init($jsonapi_notes);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/vnd.api+json']);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($new_note));
    $response = curl_exec($ch);
    curl_close($ch);

    echo "<p>Note created: " . htmlentities($title) . "</p>";
}

// Fetch notes helper
function fetch_notes($filter = '') {
    global $jsonapi_notes, $username, $password;
    $url = $jsonapi_notes . $filter;

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    $response = curl_exec($ch);
    curl_close($ch);

    $data = json_decode($response, true);
    return $data['data'] ?? [];
}

// Determine which view to show
$view = $_GET['view'] ?? 'inbox';

switch ($view) {
    case 'inbox':
        $notes = fetch_notes('?filter[field_inbox][value]=1');
        $title = 'Inbox Notes';
        break;
    case 'recent':
        $two_weeks_ago = date('c', strtotime('-2 weeks'));
        $notes = fetch_notes("?filter[created][value]=$two_weeks_ago&filter[created][operator]=>=");
        $title = 'Recent Notes (2 Weeks)';
        break;
    case 'all':
    default:
        $notes = fetch_notes('');
        $title = 'All Notes';
        break;
}
?>

<h2>Quick Capture Note</h2>
<form method="post">
    <textarea name="note_body" rows="4" cols="50" placeholder="Type your note here..."></textarea><br>
    <button type="submit">Save Note</button>
</form>

<h3>Dashboard</h3>
<p>
    <a href="?view=inbox">Inbox</a> | 
    <a href="?view=recent">Recent</a> | 
    <a href="?view=all">All</a>
</p>

<h4><?php echo $title; ?></h4>
<ul>
<?php foreach ($notes as $note) {
    $created = $note['attributes']['created'] ?? '';
    echo "<li>" . htmlentities($note['attributes']['title']) . " — $created</li>";
} ?>
</ul>