source: trunk/add.php

Last change on this file was 95, checked in by chronos, 2 years ago
  • Modified: Updated Common package.
  • Added: Explicit types for better type checking.
  • Fixed: Support for php 8.0.
File size: 1.4 KB
Line 
1<?php
2
3include_once('Application/Core.php');
4
5$Core = new Core();
6$Core->UseSession = false;
7$Core->ShowPage = false;
8$Core->Run();
9
10$AddedValues = 0;
11
12// Try to load single value
13$Time = time();
14if (array_key_exists('MeasureId', $_GET) and array_key_exists('Value', $_GET))
15{
16 if (array_key_exists('Time', $_GET)) $Time = $_GET['Time'] * 1;
17 AddValue(addslashes($_GET['MeasureId']), addslashes($_GET['Value']), $Time);
18 $AddedValues = $AddedValues + 1;
19}
20
21// Try to load multiple values
22$Time = time();
23$I = 1;
24while (array_key_exists('MeasureId'.$I, $_GET) and array_key_exists('Value'.$I, $_GET))
25{
26 if (array_key_exists('Time'.$I, $_GET)) $Time = $_GET['Time'.$I] * 1;
27 AddValue(addslashes($_GET['MeasureId'.$I]), addslashes($_GET['Value'.$I]), $Time);
28 $AddedValues = $AddedValues + 1;
29 $I++;
30}
31
32if ($AddedValues == 0) echo('Nebyly zadány potřebné parametry MeasureId a Value.'."\n");
33
34function AddValue(int $MeasureId, float $Value, int $Time): void
35{
36 global $Core;
37
38 $Measure = new Measure($Core->Database);
39 $Measure->Load($MeasureId);
40 $HostName = gethostbyaddr($_SERVER['REMOTE_ADDR']);
41 if (($HostName == $Measure->Data['PermissionAdd']) or ($_SERVER['REMOTE_ADDR'] == gethostbyname($Measure->Data['PermissionAdd'])))
42 {
43 $Measure->AddValue($Value, $Time);
44 echo('Hodnota '.$Value.' uložena'."\n");
45 } else echo('Nemáte oprávnění k aktualizaci zadané veličiny!<br>Vaše adresa: '.$HostName.'('.$_SERVER['REMOTE_ADDR'].')'."\n");
46}
Note: See TracBrowser for help on using the repository browser.