science-ation/scripts/update_signatures.php
2025-03-13 23:01:51 +00:00

106 lines
2.8 KiB
PHP

<?
/*
* This file is part of the Science-ation project
* Science-ation Website: https://science-ation.ca
*
* This file was part of the 'Science Fair In A Box' project
*
*
* Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
* Copyright (C) 2005 James Grant <james@lightbox.org>
* Copyright (C) 2024 AlgoLibre Inc. <science-ation@algolibre.io>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
require_once ('./data/config.inc.php');
$API_URL="https://signatures.algolibre.io/api";
$TEMPLATE_ID=7;
$dsn = "mysql:host=db;dbname=$DBNAME;charset=utf8mb4";
$pdo = new PDO($dsn, $DBUSER, $DBPASS);
$pagination = -1;
$curl = curl_init();
$completed = [];
do {
$SIGNATURES_MAX = 100;
$url = "$API_URL/submissions?template_id=$TEMPLATE_ID&status=completed&limit=$SIGNATURES_MAX";
if ($pagination != -1) {
$url = "$API_URL/submissions?template_id=$TEMPLATE_ID&status=completed&limit=$SIGNATURES_MAX&after=" . $pagination;
}
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [
'X-Auth-Token: baEUbT1iLsNdBDSWpNqvxoTCDshJ6a6D8YDCsjMxAKF'
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo 'cURL Error #:' . $err;
} else {
$converted = mb_convert_encoding($response, 'UTF-8');
$data = json_decode($converted);
foreach ($data->data as $submissions) {
foreach ($submissions->submitters as $submitter) {
if ($submitter->role == "Student 1" && $submissions->archived_at == null) {
$completed[] = $submitter->email;
}
}
}
$pagination = $data->pagination->next;
}
} while ($pagination > 0);
foreach ($completed as $student) {
try {
$stmt = $pdo->prepare("UPDATE registrations set status='paymentpending' where email=? and status != 'complete'");
$stmt->execute([$student]);
if ($stmt->rowCount() == 0) {
error_log("No update for: " . $student);
}
} catch (PDOException $exception) {
error_log("Err: " . $student . ": " . $exception);
}
}
curl_close($curl);
?>