public function send($giftId, $giftTo, $message, $giftAnonymous = 0) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); if ($giftId == 0) { return $result; } $giftInfo = $this->db_info($giftId); if ($giftInfo['error'] === true) { return $result; } $currentTime = time(); $stmt = $this->db->prepare("INSERT INTO gifts (giftId, giftTo, giftFrom, giftAnonymous, message, imgUrl, createAt) value (:giftId, :giftTo, :giftFrom, :giftAnonymous, :message, :imgUrl, :createAt)"); $stmt->bindParam(":giftId", $giftId, PDO::PARAM_INT); $stmt->bindParam(":giftTo", $giftTo, PDO::PARAM_INT); $stmt->bindParam(":giftFrom", $this->requestFrom, PDO::PARAM_INT); $stmt->bindParam(":giftAnonymous", $giftAnonymous, PDO::PARAM_INT); $stmt->bindParam(":message", $message, PDO::PARAM_STR); $stmt->bindParam(":imgUrl", $giftInfo['imgUrl'], PDO::PARAM_STR); $stmt->bindParam(":createAt", $currentTime, PDO::PARAM_INT); if ($stmt->execute()) { $giftId = $this->db->lastInsertId(); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "giftId" => $this->db->lastInsertId(), "gift" => $this->info($this->db->lastInsertId())); $account = new account($this->db, $giftTo); $account->updateCounters(); unset($account); if ($this->requestFrom != $giftTo) { $blacklist = new blacklist($this->db); $blacklist->setRequestFrom($giftTo); if (!$blacklist->isExists($this->requestFrom)) { $account = new account($this->db, $giftTo); if ($account->getAllowGiftsGCM() == ENABLE_GIFTS_GCM) { $gcm = new gcm($this->db, $giftTo); $gcm->setData(GCM_NOTIFY_GIFT, "You have new gift", 0); $gcm->send(); } unset($account); $notify = new notify($this->db); $notify->createNotify($giftTo, $this->requestFrom, NOTIFY_TYPE_GIFT, $giftId); unset($notify); } unset($blacklist); } } return $result; }
<?php /*! * ifsoft.co.uk engine v1.0 * * http://ifsoft.com.ua, http://ifsoft.co.uk * qascript@ifsoft.co.uk * * Copyright 2012-2016 Demyanchuk Dmitry (https://vk.com/dmitry.demyanchuk) */ include_once $_SERVER['DOCUMENT_ROOT'] . "/core/init.inc.php"; include_once $_SERVER['DOCUMENT_ROOT'] . "/config/api.inc.php"; if (!empty($_POST)) { $accountId = isset($_POST['accountId']) ? $_POST['accountId'] : 0; $accessToken = isset($_POST['accessToken']) ? $_POST['accessToken'] : ''; $allowGiftsGCM = isset($_POST['allowGiftsGCM']) ? $_POST['allowGiftsGCM'] : 0; $allowGiftsGCM = helper::clearInt($allowGiftsGCM); $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $auth = new auth($dbo); if (!$auth->authorize($accountId, $accessToken)) { api::printError(ERROR_ACCESS_TOKEN, "Error authorization."); } $result = array("error" => false, "error_code" => ERROR_SUCCESS); $account = new account($dbo, $accountId); $account->setAllowGiftsGCM($allowGiftsGCM); $result['allowGiftsGCM'] = $account->getAllowGiftsGCM(); echo json_encode($result); exit; }