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));
 }
 public static function addNewEGOPWallet()
 {
     $email = Core::validate($_POST['EMAIL']);
     $api_id = Core::validate($_POST['API_ID']);
     $api_password = Core::validate($_POST['API_PASSWORD']);
     $store_id = Core::validate($_POST['STORE_ID']);
     $store_password = Core::validate($_POST['STORE_PASSWORD']);
     $checksum_key = Core::validate($_POST['CHECKSUM_KEY']);
     $currency_name = Core::validate($_POST['CURRENCY']);
     $share = Core::validate($_POST['SHARE']);
     // percent
     if ($email == null || $api_id == null || $api_password == null || $store_id == null || $store_password == null || $checksum_key == null || $currency_name == null || $share == null || !Core::isDouble($share)) {
         print 'Incorrect data';
         exit;
     }
     $currency = new Currency();
     if (!$currency->findBy(array('Name' => $currency_name))) {
         exit;
     }
     $result = WalletsEgop::findBy(array('currency_id' => $currency->getId(), 'email' => $email));
     if (!empty($result)) {
         print 'This wallet already exists';
         exit;
     }
     $oAuth = new EgoPayAuth($email, $api_id, $api_password);
     $oEgoPayJsonAgent = new EgoPayJsonApiAgent($oAuth);
     $oEgoPayJsonAgent->setVerifyPeer(false);
     try {
         $balance = $oEgoPayJsonAgent->getBalance($currency->getName());
     } catch (EgoPayApiException $e) {
         Core::write_log(EGOPAY_LOG_PATH, __FUNCTION__ . ' : getBalance Error: ' . $e->getCode() . " : " . $e->getMessage());
         print $e->getMessage();
         exit;
     }
     $wallet = new WalletsEgop();
     $wallet->setCurrencyId($currency->getId());
     $wallet->setEmail($email);
     $wallet->setApiId($api_id);
     $wallet->setApiPassword($api_password);
     $wallet->setStoreId($store_id);
     $wallet->setStorePassword($store_password);
     $wallet->setChecksumKey($checksum_key);
     $wallet->setValue($balance);
     $wallet->setShare($share / 100.0);
     $wallet->insert();
     header('Location: /admin/egop');
 }
<?php 
    foreach ($return['return']['funds'] as $key => $value) {
        ?>
    <?php 
        if ($key == $data[0]['rate']['firstCurrency'] || $key == $data[0]['rate']['secondCurrency']) {
            ?>
        <div class="wallet">
            <div class="wallet-icon left"><img src="/public/img/curr/<?php 
            print $key;
            ?>
.png" style=""></div>
            <div class="wallet-title left"><span id="<?php 
            print $key;
            ?>
" class="greenMark"><?php 
            $cur->findBy(array('Name' => $key));
            print $cur->getTradeName();
            ?>
</span></div>
            <br>
            <div class="wallet-list">
                <div class="wallet-list-item">
                    <b id="val<?php 
            print $key;
            ?>
"><?php 
            print $value;
            ?>
</b> (<?php 
            print $key;
            ?>
 public static function trade()
 {
     $user = usr::getCurrentUser(1);
     if ($user == null) {
         self::printErrorJson("You are not authorized");
         return;
     }
     $firstCurName = Core::validate(self::getVar('firstCurrency'));
     $secondCurName = Core::validate(self::getVar('secondCurrency'));
     $type = Core::validate(self::getVar('type'));
     $price = Core::validate(self::getVar('rate'));
     $volume = Core::validate(self::getVar('amount'));
     if ($firstCurName == null || $secondCurName == null || $type == null || $price == null || $volume == null) {
         self::printErrorJson("not all parameters are defined");
         return;
     }
     if (!Core::isDouble($price) || !Core::isDouble($volume)) {
         self::printErrorJson("parameters are defined incorrectly");
         return;
     }
     $rate = self::getRate($firstCurName, $secondCurName);
     if ($rate == null) {
         self::printErrorJson("rate {$firstCurName}" . "_" . " {$secondCurName} not exist");
         return;
     }
     $currency = new Currency();
     $currency->findBy(array('Name' => $firstCurName));
     if ($volume < $currency->getMinOrderAmount()) {
         self::printErrorJson("Please, check min order amount for this currency");
         return;
     }
     if ($type == 'buy') {
         $orderType = OrderType::BUY;
     } elseif ($type = 'sell') {
         $orderType = OrderType::SELL;
     } else {
         self::printErrorJson("undefined order type");
         return;
     }
     $orderId = OrderModel::createOrder($user->getId(), $rate, $orderType, $volume, $price);
     if ($orderId === false) {
         self::printErrorJson(OrderModel::getErrorMessage());
         return;
     }
     $return['order_id'] = $orderId;
     $return['funds'] = self::getFunds($user->getId());
     $result['success'] = 1;
     $result['return'] = $return;
     print json_encode($result);
 }