core/echo.php

32 lines
1.2 KiB
PHP
Raw Normal View History

2023-07-12 20:02:20 +05:00
<?php
header('Content-Type: application/json; charset=utf-8');
ini_set('display_errors', 0);
include '/home/cloud/core/api/php/genpass.php';
include '/home/cloud/core/api/php/json.php';
include 'api/php/dbsqlite.php';
DB::$dsn='sqlite:bd/tovar_api.db';
switch( @$_POST['action'] ) {
case 'addtovar':
$file = 'check.txt';
$massiv=json::from_j($_POST['json']);
for($i=0; $i<count($massiv);$i++){
$txt=DB::getValue("SELECT `txt` FROM `tovar` WHERE `txt`=? AND `barcode`=?", array(trim($massiv[$i]['txt']), trim($massiv[$i]['barcode'])));
if (!$txt)DB::add("INSERT INTO `tovar` (`txt`, `barcode`) VALUES (?, ?)", array(trim($massiv[$i]['txt']), trim($massiv[$i]['barcode'])));
}
file_put_contents($file, $_POST['json']);
$otvet['err'] = ($massiv)?0:2;
echo json::to_j($otvet);
break;
case 'getTovar':
$user_t=DB::getValue("SELECT `t` FROM `users` WHERE `key`=?", $_POST['key']);
if ($user_t<time()){
$msg['err']=1;
echo(json::to_j($msg));
}
print_r(json::to_j(DB::getAll("SELECT * FROM `tovar` WHERE `barcode`=?", $_POST['barcode'])));
break;
}
?>