annotate php/get_filtered_count.php @ 3141:335bc77627e0 tip

fixing discrete interface to allow labels to display
author Dave Moffat <me@davemoffat.com>
date Mon, 26 Jul 2021 12:15:24 +0100
parents c7de85e03321
children
rev   line source
nicholas@2224 1 <?php
nicholas@3123 2 include_once("config.php");
nicholas@2457 3 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
nicholas@2457 4 header("Cache-Control: post-check=0, pre-check=0", false);
nicholas@2457 5 header("Pragma: no-cache");
nicholas@2224 6 //http://stackoverflow.com/questions/4444475/transfrom-relative-path-into-absolute-url-using-php
nicholas@2283 7 include "rel2abs.php";
nicholas@2224 8
nicholas@2224 9 /*
nicholas@2224 10 This looks for files that pass the filtering response
nicholas@2224 11 The filtering system uses key-value pairs
nicholas@2224 12 The key is double encoded using a '-'. The first part is the ID of the item to filter,
nicholas@2224 13 the second is the method:
nicholas@2224 14 min - Minimum Inclusive
nicholas@2224 15 max - Maximum Inclusive
nicholas@2224 16 exclude-# - exclude, followed by a number to uniquely add, (will create a triple [], ignore the third as random)
nicholas@2224 17 */
nicholas@2283 18 $keys = array();
nicholas@2224 19 $waet_url = null;
nicholas@2224 20 foreach ($_GET as $key => $value) {
nicholas@2224 21 $key = explode("-",$key);
nicholas@2224 22 if ($key[0] == "url") {
nicholas@2224 23 $waet_url = $value;
nicholas@2224 24 } else {
nicholas@2283 25 $v_pair = array($key[1],$value);
nicholas@2224 26 if(array_key_exists($key[0],$keys)) {
nicholas@2224 27 // We have some data
nicholas@2224 28 array_push($keys[$key[0]],$v_pair);
nicholas@2224 29 } else {
nicholas@2224 30 // Create new key data
nicholas@2283 31 $keys[$key[0]] = array($v_pair);
nicholas@2224 32 }
nicholas@2224 33 }
nicholas@2224 34 }
nicholas@2224 35
nicholas@2283 36 $files = array();
nicholas@3120 37 $saveLocation = getSaveLocation();
nicholas@3120 38 $saves = glob($saveLocation."*.xml");
nicholas@2224 39 if (is_array($saves))
nicholas@2224 40 {
nicholas@2224 41 foreach($saves as $filename) {
nicholas@2224 42 $xml_string = file_get_contents($filename, FILE_TEXT);
nicholas@2224 43 $xml_object = simplexml_load_string($xml_string);
nicholas@2224 44 if ($xml_object) {
nicholas@2224 45 // First we must check the URLs match
nicholas@2224 46 $waet = $xml_object->waet[0];
nicholas@2224 47 if (urldecode($waet["url"])==$waet_url) {
nicholas@2224 48 // It is part of the dataset, so now perform checks
nicholas@2224 49 $continue = true;
nicholas@2224 50 foreach($keys as $keyId => $keyArr) {
nicholas@2224 51 $elem = $xml_object->xpath("//*[@ref='".$keyId."']");
nicholas@2224 52 $elem = $elem[0]; // Can only be one.
nicholas@2224 53 switch ($elem["type"]) {
nicholas@2224 54 case "number":
nicholas@2224 55 // Number, we must check for min/max
nicholas@2224 56 $value = (real)$elem->response;
nicholas@2224 57 foreach ($keyArr as $keyCheck) {
nicholas@2224 58 if ($keyCheck[0] == 'min' && $value < $keyCheck[1]) {
nicholas@2224 59 $continue = false;
nicholas@2224 60 break;
nicholas@2224 61 } else if ($keyCheck[0] == 'max' && $value > $keyCheck[1]) {
nicholas@2224 62 $continue = false;
nicholas@2224 63 break;
nicholas@2224 64 }
nicholas@2224 65 }
nicholas@2224 66 break;
nicholas@2224 67 case "checkbox":
nicholas@2224 68 // Will have an array of <response>
nicholas@2224 69 foreach ($elem->response as $response) {
nicholas@2224 70 foreach ($keyArr as $keyCheck) {
nicholas@2224 71 if ($response["name"] == $keyCheck[1]) {
nicholas@2224 72 if($response["checked"] == "true" && $keyCheck[0] == "exclude") {
nicholas@2224 73 $continue = false;
nicholas@2224 74 break;
nicholas@2224 75 }
nicholas@2224 76 }
nicholas@2224 77 }
nicholas@2224 78 if($continue == false) {
nicholas@2224 79 break;
nicholas@2224 80 }
nicholas@2224 81 }
nicholas@2224 82 break;
nicholas@2224 83 case "radio":
nicholas@2224 84 foreach ($keyArr as $keyCheck) {
nicholas@2224 85 if ($keyCheck[0] == "exclude" && $elem->response["name"] == $keyCheck[1]) {
nicholas@2224 86
nicholas@2224 87 $continue = false;
nicholas@2224 88 break;
nicholas@2224 89 }
nicholas@2224 90 }
nicholas@2224 91 break;
nicholas@2224 92 default:
nicholas@2224 93 break;
nicholas@2224 94 }
nicholas@2224 95 if ($continue == false) {
nicholas@2224 96 break;
nicholas@2224 97 }
nicholas@2224 98 }
nicholas@2224 99 if ($continue) {
nicholas@2224 100 array_push($files,rel2abs($filename,"http://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
nicholas@2224 101 }
nicholas@2224 102 }
nicholas@2224 103 }
nicholas@2224 104 }
nicholas@2224 105 }
nicholas@2224 106 if (count($files) == 0) {
nicholas@2224 107 echo '{"urls": []}';
nicholas@2224 108 } else {
nicholas@2224 109 echo '{"urls": ["'.implode('","',$files).'"]}';
nicholas@2224 110 }
nicholas@2224 111
nicholas@2538 112 ?>