/**
  * Delete existing currency
  *
  * @param void
  * @return null
  */
 function delete()
 {
     if ($this->active_currency->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if ($this->request->isSubmitted()) {
         $delete = $this->active_currency->delete();
         if ($delete && !is_error($delete)) {
             flash_success('Currency ":name" has been deleted', array('name' => $this->active_currency->getName()));
         } else {
             flash_error('Failed to delete ":name" currency', array('name' => $this->active_currency->getName()));
         }
         // if
         $this->redirectTo('admin_currencies');
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
 }
    public function giveProduct()
    {
        if (session_status() === PHP_SESSION_NONE) {
            session_start();
        }
        $userkey = intval($_SESSION["userkey"]);
        $db = UniversalConnect::doConnect();
        $this->return .= <<<HTML
<script>
\$(document).ready(function(){
    \$('.collapsible').collapsible({
      accordion : false // A setting that changes the collapsible behavior to expandable instead of the default accordion style
    });
  });
</script>
<ul class="collapsible card" data-collapsible="accordion">
    <li class="blue">
        <div class="row flow-text" style="padding: 5px 10px;">
            <div class="col s3 center">
                <p>Currency</p>
            </div>
            <div class="col s3 center">
                <p>Bid Rate</p>
            </div>
            <div class="col s3 center">
                <p>Offer Rate</p>
            </div>
            <div class="col s3 center">
                <p>Amount</p>
            </div>
        </div>
    </li>
HTML;
        $this->return .= "<li><div class=\"row\">";
        $this->return .= "<div class=\"col s3 center card-content\"><p>" . $this->basecurr->getName() . " (" . $this->basecurr->getShortName() . ")</p></div>";
        $this->return .= "<div class=\"col s3 center card-content\"><p>N.A.</p></div>";
        $this->return .= "<div class=\"col s3 center card-content\"><p>N.A.</p></div>";
        $this->return .= "<div class=\"col s3 center card-content\"><p>" . number_format($this->basecurr->getAmount(), 2) . "</p></div>";
        $this->return .= "</div></li>";
        $query = "SELECT currencyid FROM currency WHERE currencyid != 1 ORDER BY currencyid ASC";
        $result = $db->query($query) or die($db->error);
        while ($row = $result->fetch_assoc()) {
            $base_shortname = $this->basecurr->getShortName();
            $secCurr = new Currency($row["currencyid"]);
            $name = $secCurr->getName();
            $shortname = $secCurr->getShortName();
            $bidRate = number_format($secCurr->getBuyValue(), 2);
            $offerRate = number_format($secCurr->getSellValue(), 2);
            $currencyID = $row["currencyid"];
            $this->return .= <<<JAVASCRIPT
<script>
    function sellchange{$currencyID}()
    {
        var tmp = document.getElementById("sellamt{$currencyID}").value;
        tmp = tmp.replace(/[^\\d\\.\\-\\ ]/g, '');
        var amt = parseFloat(tmp);
        amt *= {$bidRate};
        Number.prototype.formatMoney = function (rate)
        {
            var n = this,
                    c = isNaN(c = Math.abs(c)) ? 2 : c,
                    d = d == undefined ? "." : d,
                    t = t == undefined ? "," : t,
                    s = n < 0 ? "-" : "",
                    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
                    j = (j = i.length) > 3 ? j % 3 : 0;
            return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\\d{3})(?=\\d)/g, "\$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
        };
        document.getElementById("disp_sellamt{$currencyID}").innerHTML = (amt).formatMoney(2, '.', ',');
    }
    function buychange{$currencyID}()
    {
        var tmp = document.getElementById("buyamt{$currencyID}").value;
        tmp = tmp.replace(/[^\\d\\.\\-\\ ]/g, '');
        var amt = parseFloat(tmp);
        amt *= {$offerRate};
        Number.prototype.formatMoney = function (rate)
        {
            var n = this,
                    c = isNaN(c = Math.abs(c)) ? 2 : c,
                    d = d == undefined ? "." : d,
                    t = t == undefined ? "," : t,
                    s = n < 0 ? "-" : "",
                    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
                    j = (j = i.length) > 3 ? j % 3 : 0;
            return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\\d{3})(?=\\d)/g, "\$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
        };
        document.getElementById("disp_buyamt{$currencyID}").innerHTML = (amt).formatMoney(2, '.', ',');
    }
    function cleanify(elementID)
    {
        var tmp = document.getElementById(elementID).value;
        tmp = tmp.replace(/[^\\d\\.\\-\\ ]/g, '');
        document.getElementById(elementID).value = parseFloat(tmp);
        return true;
    }
</script>
JAVASCRIPT;
            $this->return .= <<<HTML
<li>
    <div class="collapsible-header" style="padding:0px">
        <div class="row">
            <div class="col s3 center card-content">
                <p>{$name} ({$shortname})</p>
            </div>
            <div class="col s3 center card-content">
                <p>{$bidRate}</p>
            </div>
            <div class="col s3 center card-content">
                <p>{$offerRate}</p>
            </div>
            <div class="col s3 center card-content">
                <p>
HTML;
            $this->return .= number_format($secCurr->getAmount(), 2);
            $this->return .= <<<HTML
                </p>
            </div>
        </div>
    </div>
    <div class="collapsible-body">
        <!--<div class="row">
            <div class="col s6 center">
                <p>Sell {$base_shortname}, Buy {$shortname}</p>
            </div>
            <div class="col s6 center">
                <p>Buy {$base_shortname}, Sell {$shortname}</p>
            </div>
        </div>-->
        <form name="transact{$currencyID}" action="./" method="post">
            <div class="row">  
                <input type="hidden" name="currid" value="{$currencyID}" />
                <div class="col s6 center">
                    <p style="text-align:center;">
                        Sell {$base_shortname} <input type="number" name="sellamt{$currencyID}" id="sellamt{$currencyID}" onchange="sellchange{$currencyID}()" onkeyup="sellchange{$currencyID}()" style="width: 40px;"/> million for {$shortname} <span id="disp_sellamt{$currencyID}">0.00</span> million
                    </p>
                </div>
                <div class="col s6 center">
                    <p style="text-align:center;">
                        Buy {$base_shortname} <input type="number" name="buyamt{$currencyID}" id="buyamt{$currencyID}" onchange="buychange{$currencyID}()" onkeyup="buychange{$currencyID}()" style="width: 40px;"/> million for {$shortname} <span id="disp_buyamt{$currencyID}">0.00</span> million
                    </p>
                </div>
            
            </div>
            <div class="row">
                <div class="col s6 center">
                    <button class="btn waves-effect waves-light center" type="submit" name="sellBase{$currencyID}">Sell {$base_shortname}
                      <i class="material-icons right">attach_money</i>
                    </button>
                </div>
                <div class="col s6 center">
                    <button class="btn waves-effect waves-light center" type="submit" name="buyBase{$currencyID}">Buy {$base_shortname}
                      <i class="material-icons right">attach_money</i>
                    </button>
                </div>
                <p></p><!-- hacky solution for bottom padding -->
            </div>
        </form>
    </div>
</li>
HTML;
        }
        $this->return .= "</ul>";
        $db->close();
        return $this->return;
    }
 private static function EGOP_MinAndMaxWallets(Currency $currency)
 {
     $wallets = WalletsEgop::findBy(array('currency_id' => $currency->getId()));
     if (empty($wallets)) {
         return null;
     }
     $maxBalance = null;
     $keyMax = null;
     $minBalance = null;
     $keyMin = null;
     foreach ($wallets as $key => $value) {
         $oAuth = new EgoPayAuth($value['email'], $value['api_id'], $value['api_password']);
         $oEgoPayJsonAgent = new EgoPayJsonApiAgent($oAuth);
         $oEgoPayJsonAgent->setVerifyPeer(false);
         try {
             $balance = $oEgoPayJsonAgent->getBalance($currency->getName());
             if ($minBalance === null || $minBalance > $balance) {
                 $minBalance = $balance;
                 $keyMin = $key;
             }
             if ($maxBalance === null || $maxBalance < $balance) {
                 $maxBalance = $balance;
                 $keyMax = $key;
             }
         } catch (EgoPayApiException $e) {
             Core::write_log(EGOPAY_LOG_PATH, __FUNCTION__ . ' : getBalance Error: ' . $e->getCode() . " : " . $e->getMessage());
         }
     }
     $result['min'] = $wallets[$keyMin];
     $result['max'] = $wallets[$keyMax];
     return $result;
 }
Beispiel #4
0
 /**
  * @return \SimpleXMLElement
  */
 public function toXML($sendEmailFlag = true)
 {
     $orderXML = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>' . '<order></order>');
     $orderXML->addChild("id", $this->OrderID);
     $orderXML->addChild("vendor_id", $this->VendorID);
     $orderXML->addChild("first_name", $this->FirstName);
     $orderXML->addChild("last_name", $this->LastName);
     $orderXML->addChild("email", $this->EmailAddress);
     $orderXML->addChild("currency", Currency::getName($this->Currency));
     $c1 = $orderXML->addChild("custom_1", $this->Custom1);
     if (empty($this->Custom1)) {
         $c1->addAttribute("nil", "true");
     }
     $c2 = $orderXML->addChild("custom_2", $this->Custom2);
     if (empty($this->Custom2)) {
         $c2->addAttribute("nil", "true");
     }
     $c3 = $orderXML->addChild("custom_3", $this->Custom3);
     if (empty($this->Custom3)) {
         $c3->addAttribute("nil", "true");
     }
     $license_key = $orderXML->addChild("license_key", $this->LicenseKey);
     if (empty($this->LicenseKey)) {
         $license_key->addAttribute("nil", "true");
     }
     if (is_a($this->ExpirationDate, "DateTime")) {
         $expirationDateElement = $orderXML->addChild("expiration_date", $this->ExpirationDate->format(\DateTime::ISO8601));
         $expirationDateElement->addAttribute("type", "datetime");
     }
     $downloadLimitElement = $orderXML->addChild("download_limit", $this->DownloadLimit);
     $downloadLimitElement->addAttribute("type", "integer");
     $orderXML->addChild("send_email", $sendEmailFlag ? "true" : "false");
     $orderItemsElement = $orderXML->addChild("order_items");
     $orderItemsElement->addAttribute("type", "array");
     foreach ($this->items as $item) {
         $orderItem = $orderItemsElement->addChild("order_item");
         $orderItem->addChild("sku", $item->getSKU());
         $downloadsRemainingElement = $orderItem->addChild("downloads_remaining", $item->getDownloadCount());
         $downloadsRemainingElement->addAttribute("type", "integer");
         $priceElement = $orderItem->addChild("price", $item->getPrice());
         $priceElement->addAttribute("type", "float");
     }
     return $orderXML->asXML();
 }
Beispiel #5
0
 /**
  * @return \SimpleXMLElement
  */
 public function toXML($sendEmailFlag = true)
 {
     $productXML = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>' . '<product></product>');
     $productXML->addChild("id", $this->ProductID);
     $productXML->addChild("sku", $this->SKU);
     $productXML->addChild("name", $this->Name);
     $priceElement = $productXML->addChild("price", $this->Price);
     $priceElement->addAttribute("type", "float");
     $productXML->addChild("currency", Currency::getName($this->Currency));
     /* Confirm these elements are accepted; not in API spec */
     /* ToDo: Add these as HREF */
     $productXML->addChild("paypal_add_to_cart_link", $this->PaypalAddToCartLink);
     $productXML->addChild("paypal_buy_now_link", $this->PaypalBuyNowLink);
     $productXML->addChild("paypal_view_cart_link", $this->PaypalViewCartLink);
     $productXML->addChild("files_uri", $this->FilesUri);
     $productXML->addChild("downloads_uri", $this->DownloadsUri);
     if (is_a($this->CreationDate, "DateTime")) {
         $creationDateElement = $productXML->addChild("created_at", $this->CreationDate->format(\DateTime::ISO8601));
         $creationDateElement->addAttribute("type", "datetime");
     }
     $filesElement = $productXML->addChild("files");
     $filesElement->addAttribute("type", "array");
     foreach ($this->files as $file) {
         $fileElm = $filesElement->addChild("file");
         // Check This
         $fileElm->addChild("id", $file->getFileID());
     }
     return $productXML->asXML();
 }
 public static function internal_fees()
 {
     $currency = new Currency();
     $rates = Rate::getAll();
     foreach ($rates as $key => $value) {
         $currency->findById($value['FirstId']);
         $rates[$key]['firstCurrency'] = $currency->getName();
         $currency->findById($value['SecondId']);
         $rates[$key]['secondCurrency'] = $currency->getName();
     }
     Core::runView('ViewTemplate/account', array('pageName' => 'Internal fees', 'activeMenu' => 'Internal fees', 'pagePath' => 'Administration/admin_internal_fees', 'user' => self::$user, 'rates' => $rates));
 }
 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 getPages()
 {
     $usr = usr::getCurrentUser(1);
     if (!isset($usr)) {
         return;
     }
     $widget = new Widget();
     $widget->setUID($usr->getId());
     $pages = $widget->getAllPages();
     foreach ($pages as $key => $value) {
         $id = $value['rate'];
         $rt = new Rate();
         $rt->setId($id);
         $rt->findById($id);
         $fcId = $rt->getFirstCurrencyId();
         $scId = $rt->getSecondCurrencyId();
         $cur = new Currency();
         $cur->findById($fcId);
         $firstCurr = $cur->getName();
         $cur->findById($scId);
         $secondCurr = $cur->getName();
         $arr = array();
         $arr['firstCurrency'] = $firstCurr;
         $arr['secondCurrency'] = $secondCurr;
         $pages[$key]['rate'] = $arr;
     }
     return $pages;
 }
 public static function history()
 {
     $usr = self::getCurrentUser(1);
     if (!isset($usr)) {
         header("Location: /");
         return;
     }
     $orders = Order::findBy(array('UID' => $usr->getId()), ' ORDER BY Date DESC');
     $rate = new Rate();
     $currency = new Currency();
     foreach ($orders as $key => $order) {
         $rate->findById($order['RateId']);
         $currency->findById($rate->getFirstCurrencyId());
         $orders[$key]['FirstCurrency'] = $currency->getName();
         $currency->findById($rate->getSecondCurrencyId());
         $orders[$key]['SecondCurrency'] = $currency->getName();
         $orders[$key]['Type'] = $order['Type'] == OrderType::BUY ? 'Buy' : 'Sell';
         $status = '';
         switch ($order['Status']) {
             case OrderStatus::ACTIVE:
                 $status = 'Active';
                 break;
             case OrderStatus::DONE:
                 $status = 'Done';
                 break;
             case OrderStatus::PARTIALLY_DONE:
                 $status = 'Partially done';
                 break;
             case OrderStatus::CANCELLED:
                 $status = 'Cancelled';
                 break;
         }
         $orders[$key]['Status'] = $status;
         $orderDeals = Deal::findByAndOrderByDate(array('OrderId' => $order['id']));
         $deals = array();
         foreach ($orderDeals as $dealKey => $deal) {
             $deals[$dealKey]['id'] = $deal['id'];
             $deals[$dealKey]['Price'] = $deal['Price'];
             $deals[$dealKey]['Volume'] = $deal['Volume'];
             $deals[$dealKey]['Date'] = $deal['Date'];
             $deals[$dealKey]['Status'] = $deal['Done'] == 0 ? 'Active' : 'Done';
         }
         $orders[$key]['deals'] = $deals;
     }
     Core::runView('ViewTemplate/account', array('pageName' => 'Deals history', 'activeMenu' => 'Deals history', 'pagePath' => 'AccountProfile/usr_dealshistory', 'user' => $usr, 'dealsHistory' => $orders));
 }