core/api/modules/quick-work/ajax.php

218 lines
5.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
ini_set('display_errors', 1);
switch (@$_POST['act']) {
case 'breakOtklic':
\DB::set("UPDATE `quick-work-otklic` SET `sel`=0 WHERE `id`=?", $_POST['id']);
break;
case 'getOtklic':
$sel = \DB::getValue("SELECT `id` FROM `quick-work-otklic` WHERE `sel`=1 AND `id`=?", $_POST['id']);
if (!$sel)\DB::set("UPDATE `quick-work-otklic` SET `sel`=1 WHERE `id`=?", $_POST['id']);
break;
case 'get-workers':
//узнаем нет ли уже выбранных...
$sel = \DB::getValue("SELECT `id` FROM `quick-work-otklic` WHERE `sel`=1 AND `work-id`=?", $_POST['id']);
if (!$sel) {
$users = \DB::getAll("SELECT `id`, `user_id`, `cena` FROM `quick-work-otklic` WHERE `work-id`=?", $_POST['id']);
//узнаем фио, фирму, аватар...
for ($i = 0; $i < count($users); $i++) {
$u = \DB::getAll("SELECT `fio`, `org`, `ava`, `repa` FROM `users` WHERE `id`=? LIMIT 1", $users[$i]['user_id']);
$users[$i]['fio'] = $u[0]['fio'];
$users[$i]['ava'] = $u[0]['ava'];
$users[$i]['org'] = $u[0]['org'];
$users[$i]['repa'] = $u[0]['repa'];
unset($u);
}
} else {
$users = \DB::getAll("SELECT `id`, `user_id`, `cena` FROM `quick-work-otklic` WHERE `work-id`=? AND `sel`=1 LIMIT 1", $_POST['id']);
//узнаем фио, фирму, аватар...
for ($i = 0; $i < count($users); $i++) {
$u = \DB::getAll("SELECT `fio`, `org`, `ava`, `repa` FROM `users` WHERE `id`=? LIMIT 1", $users[$i]['user_id']);
$users[$i]['fio'] = $u[0]['fio'];
$users[$i]['ava'] = $u[0]['ava'];
$users[$i]['org'] = $u[0]['org'];
$users[$i]['repa'] = $u[0]['repa'];
$users[$i]['isp'] = '1';
unset($u);
}
}
echo \json::to_j($users);
break;
case 'otklick':
//Смотрим, может он уже есть
$id = \DB::getValue("SELECT `id` FROM `quick-work-otklic` WHERE `work-id`=? AND `user_id`=? LIMIT 1", array($_POST['id'], $_SESSION['user_id']));
if (!$id)
\DB::add("INSERT INTO `quick-work-otklic` (`work-id`, `user_id`, `cena`, `t`) VALUES (?, ?, ?, ?)", array(
$_POST['id'],
$_SESSION['user_id'],
$_POST['cena'],
time()
)
);
break;
case 'new_work':
$_SESSION['work_id'] = \DB::add("INSERT INTO `quick-work`(`user_id`, `t`) VALUES (?, ?)", array($_SESSION['user_id'], time()));
break;
case 'upload';
@mkdir('img/quick-work', 0700);
@mkdir('img/quick-work/' . $_SERVER['SERVER_NAME'], 0700);
@mkdir('img/quick-work/' . $_SERVER['SERVER_NAME'] . '/' . $_SESSION['work_id'], 0700);
$dst = 'img/quick-work/' . $_SERVER['SERVER_NAME'] . '/' . $_SESSION['work_id'] . '/' . \core::genpassword() . '.jpg';
if (preg_match('/[.](jpg)|(jpeg)|(JPG)|(JPEG)$/', $_FILES['file']['name'])) {
$src = $_FILES['file']['tmp_name'];
copy($src, $dst);
}
break;
case 'save-work':
\DB::set("UPDATE `quick-work` SET `title`=?, `txt`=?, `cena`=?, `region`=?, `city`=?, `raion`=?, `t`=?, `status`=? WHERE `user_id`=? AND `id`=? AND `status`=0", array(
$_POST['title'], $_POST['txt'], $_POST['cena'], $_POST['region'], $_POST['city'], $_POST['raion'],
time(),
1, $_SESSION['user_id'], $_SESSION['work_id']
)
);
break;
case 'add_comment':
print_r($_POST);
if (!$_SESSION['user_id'] || !$_POST['txt'])
die();
$_POST['t'] = time();
$_POST['user_id'] = $_SESSION['user_id'];
unset($_POST['act']);
$db->add('pages_comments', $_POST);
break;
case 'like':
unset($a);
unset($b);
$a['id'] = $_POST['id'];
$b['likes'] = $db->get_val('pages', $a, 'likes') + 1;
setcookie("page_like", $a['id'], time() + 31536000, '/', $_SERVER['SERVER_NAME']);
$db->update('pages', $a['id'], $b);
echo 1;
break;
case 'get_like_galery':
unset($_POST['act']);
//$_POST['type']='foto';
echo $db->get_val("foto_img", $_POST, 'reyt');
break;
case 'foto_to_cart':
//определяем ИД пользователя
if ($_SESSION['user_id'])
$massiv['user_id'] = $_SESSION['user_id'];
else
$massiv['user_id'] = session_id();
$massiv['foto_id'] = $_POST['id'];
//cмотрим, нет ли в корзине
$id = $db->get_val('cart', $massiv, 'id');
$massiv['t'] = time();
if (!$id)
$db->add('cart', $massiv);
break;
case 'set_like_galery':
unset($_POST['act']);
$reyt = $db->get_val("foto_img", $_POST, 'reyt');
//ставить могут только авторизованные
if ($_SESSION['user_id']) {
$_POST['user_id'] = $_SESSION['user_id'];
$_POST['type'] = 'foto';
//смотрим, не лайкали ли уже эту фотку
$id = $db->get_val("anti_like", $_POST, 'id');
if (!$id) {
$reyt++;
//обновляем таблу с фоткой
unset($a);
$a['reyt'] = $reyt;
$db->update('foto_img', $_POST['id'], $a);
//пишем антилайк
$db->add('anti_like', $_POST);
}
}
echo $reyt;
break;
default:
}
?>