public static function beforeAction() { $usr = usr::getCurrentUser(1); if (!isset($usr) || !Core::isAdministrator($usr)) { header('Location: / '); exit; } self::$user = $usr; }
public static function EGOP_transaction_o() { $usr = usr::getCurrentUser(1); if ($usr == null) { header('Location: /'); exit; } $client_account = Core::validate($_POST['email']); $amount = Core::validate($_POST['amount']); $currency_name = Core::validate($_POST['currency']); if ($amount == 0 || !Core::isDouble($amount, 2)) { print json_encode(array('location' => URL_WRONG_MONEY_VALUE)); exit; } if (!Core::isEmailAddress($client_account)) { print json_encode(array('location' => URL_WRONG_DATA_INPUT)); exit; } $currency = new Currency(); if (!$currency->findBy(array('Name' => $currency_name))) { print json_encode(array('location' => URL_SERVER_ERROR)); exit; } $purseList = Purse::findBy(array('UID' => $usr->getId(), 'CurId' => $currency->getId())); if (empty($purseList)) { exit; } $limits = self::transactionLimits($currency->getId(), 'EGOP', 1); $feeVolume = $amount * $limits['fee']; $feeVolume = Core::round_up($feeVolume, 2); $purse = new Purse(); $purse->findById($purseList[0]['id']); if ($purse->getValue() < $amount + $feeVolume) { print json_encode(array('location' => URL_WRONG_MONEY_VALUE)); exit; } if ($amount < $limits['min']) { print json_encode(array('location' => URL_ERROR . self::LIMITS)); return; } if ($limits['max'] != null) { $transaction_history = new AtEgop(); $transactions = $transaction_history->findAllByForLastPeriod(array('UID' => $usr->getid(), 'type' => 1, 'status' => 1)); $totalAmount = 0.0; if (isset($transactions)) { foreach ($transactions as $transaction) { $totalAmount += $transaction['amount']; } } if ($totalAmount + $amount > $limits['max']) { print json_encode(array('location' => URL_ERROR . self::LIMITS)); return; } } $at = new AtEgop(); $at->setUID($usr->getId()); $at->setClientAccount($client_account); $at->setAmount($amount); $at->setCurrencyId($currency->getId()); $at->setType(1); $at->setStatus(0); $at->setTimestamp(Core::timestamp_gmp()); $at->insert(); $success = self::send_output_link('EGOP', $at->getId(), $usr); if (!$success) { print json_encode(array('location' => URL_SERVER_ERROR)); return; } print json_encode(array('location' => URL_NOTIFICATION_SEND)); }
<?php if (isset($data['firstCurrency'])) { $currentRate = $data; } else { if (isset($_GET['Data'])) { $currentRate = $_GET['Data']; } } if (isset($currentRate['firstCurrency'])) { $rateInfo = api::rateInfo($currentRate['firstCurrency'], $currentRate['secondCurrency']); $maxPrice = $rateInfo['bid']; $minPrice = $rateInfo['ask']; $totalPrice = $rateInfo['total_price']; $totalVolume = $rateInfo['total_volume']; $user = usr::getCurrentUser(1); if ($user != null) { $userFunds = usr::getCurrentUsersPurses(); $userFirstCurrFundsIndex = Core::array_search($userFunds, 'CurName', $currentRate['firstCurrency']); $userFirstCurrFunds = $userFirstCurrFundsIndex == -1 ? 0 : $userFunds[$userFirstCurrFundsIndex]['Value']; $userSecondCurrFundsIndex = Core::array_search($userFunds, 'CurName', $currentRate['secondCurrency']); $userSecondCurrFunds = $userSecondCurrFundsIndex == -1 ? 0 : $userFunds[$userSecondCurrFundsIndex]['Value']; } else { $userFirstCurrFunds = 0; $userSecondCurrFunds = 0; } if (isset($currentRate['limit'])) { $depth = api::depth($currentRate['firstCurrency'], $currentRate['secondCurrency'], $currentRate['limit']); } else { $depth = api::depth($currentRate['firstCurrency'], $currentRate['secondCurrency']); }
public static function tradeHistory($firstCurrencyName = null, $secondCurrencyName = null, $count = null) { $user = usr::getCurrentUser(1); $isAjax = 0; if ($count == null) { $count = Core::validate(self::getVar('count')); } $from_id = Core::validate(self::getVar('from_id')); $end_id = Core::validate(self::getVar('end_id')); $order = Core::validate(self::getVar('order')); $since = Core::validate(self::getVar('since')); $end = Core::validate(self::getVar('end')); if ($firstCurrencyName == null) { $firstCurrencyName = Core::validate(self::getVar('firstCurrency')); $isAjax = 1; } if ($secondCurrencyName == null) { $secondCurrencyName = Core::validate(self::getVar('secondCurrency')); $isAjax = 1; } $rate = self::getRate($firstCurrencyName, $secondCurrencyName); if ($rate != null) { $params['RateId'] = $rate->getId(); } $params['count'] = $count; $params['from_id'] = $from_id; $params['end_id'] = $end_id; $params['order'] = $order; $params['since'] = $since != null ? date("Y-m-d H:i:s", $since) : null; $params['end'] = $end != null ? date("Y-m-d H:i:s", $end) : null; $deals = Deal::getHistory($params); $return = array(); $rate = new Rate(); $currency = new Currency(); foreach ($deals as $value) { $rate->findById($value['RateId']); $currency->findById($rate->getFirstCurrencyId()); $deal['pair'] = $currency->getName(); $currency->findById($rate->getSecondCurrencyId()); $deal['pair'] .= " - " . $currency->getName(); $deal['type'] = $value['Type'] == 0 ? "buy" : "sell"; $deal['amount'] = $value['Volume']; $deal['rate'] = $value['Price']; $deal['order_id'] = $value['OrderId']; $deal['is_your_order'] = $user != null && $user->getId() == $value['UID'] ? 1 : 0; $deal['timestamp'] = strtotime($value['Date']); array_push($return, $deal); } $result['success'] = 1; $result['return'] = $return; if ($isAjax == 0) { return $result; } print json_encode($result); }
public static function removeWidget() { $usr = usr::getCurrentUser(1); if (!isset($usr)) { return; } $widgetId = Core::validate(self::getVar('id')); $widget = new Widget(); $result = $widget->findBy(array('UID' => $usr->getId(), 'id' => $widgetId)); if (count($result) <= 0) { return; } $widget->setId($widgetId); $widget->delete(); header('Location: / '); }