You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB
PHP

<?php
/*
* Copyright 2020 Netsyms Technologies.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
$limit = 100;
if (!empty($VARS["limit"]) && preg_match("/^[0-9]+$/", $VARS["limit"])) {
$limit = $VARS["limit"];
}
if ($limit > 1000) {
$limit = 1000;
}
$query = (isset($VARS["q"]) ? strtolower($VARS["q"]) : "");
$results = $database->select(
"ballotitems",
[
"[>]ballotitemtypes" => ["itemtype" => "type"]
],
[
"itemid (id)",
"label",
"description",
"ballotitemtypes.text (type)"
], [
"OR" => [
"label[~]" => $query,
"description[~]" => $query
],
"LIMIT" => $limit
]
);
for ($i = 0; $i < count($results); $i++) {
$results[$i]["label"] = ucwords($results[$i]["label"]);
}
header("Content-Type: application/json");
sendJsonResp(null, "OK", ["count" => count($results), "results" => $results]);