171 lines
3.6 KiB
PHP
171 lines
3.6 KiB
PHP
<?php
|
||
|
||
function api_client_kuri($hash){
|
||
|
||
$sql = "SELECT client_id FROM `clients` WHERE `clienthash` = '$hash' LIMIT 1 ";
|
||
$client = db_get($sql);
|
||
|
||
if (isset($client['client_id']))
|
||
return $client;
|
||
|
||
return false;
|
||
|
||
}
|
||
|
||
|
||
function clientbuys_kuri($client_id, $page = 1){
|
||
|
||
$sql_sub = "SELECT number_id FROM anbuy WHERE client_id = '$client_id' AND `number_id` = 486 LIMIT 1";
|
||
$findsub = db_get($sql_sub);
|
||
|
||
|
||
// if (isset($findsub['number_id'])) {// есть поп
|
||
// return clients_arch($page);
|
||
// }
|
||
|
||
$limit = 25;
|
||
$countsql = "SELECT DISTINCT COUNT(buy_id) as count FROM `anbuy` WHERE `client_id` = $client_id AND `buy_status` = '1' LIMIT 1";
|
||
|
||
$buycount = db_get($countsql);
|
||
|
||
|
||
$buysql = "
|
||
SELECT DISTINCT
|
||
price_id, pricehash, pricename, priceimg
|
||
FROM anbuy
|
||
LEFT JOIN price ON anbuy.number_id = price.price_id
|
||
WHERE client_id = '$client_id' AND `buy_status` = '1'
|
||
ORDER BY `buy_id` DESC
|
||
LIMIT $limit";
|
||
|
||
if ($page > 1){
|
||
$offset = $limit * ($page -1);
|
||
$pricesql .= " OFFSET $offset";
|
||
}
|
||
|
||
$books = db_get($buysql);
|
||
|
||
$result['books'] = clientbooks($books, $client_id);
|
||
$result['count'] = $buycount['count'];
|
||
|
||
return $result;
|
||
|
||
}
|
||
|
||
|
||
|
||
function client_find_email($email){
|
||
|
||
$pwd_query = "SELECT * FROM `clients` WHERE `clientmail` = '$mail' LIMIT 1";
|
||
$client = db_get($pwd_query);
|
||
|
||
if (isset($client['client_id']))
|
||
return $client;
|
||
else
|
||
return false;
|
||
|
||
}
|
||
|
||
function client_add_password($mail, $pwd, $pwd2){
|
||
|
||
$maxlen = 5;
|
||
|
||
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
|
||
return 'некорректный email';
|
||
|
||
$find = client_find_email($email);
|
||
if ($find)
|
||
return 'email не найден';
|
||
|
||
if ($pwd == ''){
|
||
return 'пароль не задан';
|
||
}
|
||
|
||
if (strlen($pwd) < $maxlen) {
|
||
return "пароль должен быть не менее $maxlen символов";
|
||
}
|
||
|
||
if ($pwd == $pwd2){
|
||
return "пароли не совпадают";
|
||
}
|
||
|
||
$clientpassword = password_hash($pwd);
|
||
$sqlupdate = "UPDATE `clients` SET `clientpassword` = '$clientpassword' WHERE `clientmail` = '$mail'";
|
||
|
||
dbl_get($sqlupdate);
|
||
|
||
return True;
|
||
|
||
}
|
||
|
||
|
||
|
||
function clientmail($mail, $hash){
|
||
|
||
$client = db_get("SELECT * FROM `clients` WHERE `clientmail` = $mail LIMIT 1");
|
||
|
||
if (!isset($client['client_id'])){
|
||
echo 'Не верный запрос';
|
||
return;
|
||
}
|
||
|
||
|
||
if ($client['clienthash'] !== $hash){
|
||
echo 'Не верный запрос';
|
||
return;
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
//весь активный архив
|
||
function clients_arch($page = 1){
|
||
|
||
$limit = 25;
|
||
|
||
$countsql = "SELECT COUNT(price_id) AS count
|
||
FROM price
|
||
WHERE category_id = 1
|
||
LIMIT 1";
|
||
|
||
$count = db_get($countsql);
|
||
|
||
|
||
$pricesql = "SELECT price_id, pricehash, pricename, priceimg FROM price WHERE category_id = 1 ORDER BY price_id DESC LIMIT $limit";
|
||
|
||
|
||
if ($page > 1){
|
||
$offset = $limit * ($page -1);
|
||
$pricesql .= " OFFSET $offset";
|
||
}
|
||
|
||
$books = db_get($pricesql);
|
||
|
||
$result['books'] = clientbooks($books, $clienthash);
|
||
$result['subscript'] = true;
|
||
$result['count'] = $count['count'];
|
||
|
||
return $result;
|
||
|
||
}
|
||
|
||
|
||
function clientbooks($books, $clienthash){
|
||
|
||
|
||
if (!is_array($books))
|
||
return null;
|
||
|
||
|
||
foreach($books as $book){
|
||
$book['pic'] = IMGSRV."price/180x280/{$book['price_id']}.{$book['priceimg']}";
|
||
$book['link'] = 'read/'.$clienthash;
|
||
$result[] = $book;
|
||
}
|
||
|
||
return $result;
|
||
|
||
} |