コード例 #1
0
/**
 * Callback for Ajax to update wizard table for manual testing.
 */
require __DIR__ . "/../layout/templates.php";
$user = get_user(user_id());
require_user($user);
$exchange = require_get('exchange');
$id = require_get('id');
// make sure that we actually have a valid account
$account_data = false;
$accounts = array();
foreach (account_data_grouped() as $label => $data) {
    foreach ($data as $key => $value) {
        if ($key == $exchange) {
            // we've found a valid account type
            $account_data = get_accounts_wizard_config($key);
            $account_type = get_wizard_account_type($value['wizard']);
            $add_types[] = $key;
            $add_type_names[$key] = get_exchange_name($key) . (isset($value['suffix']) ? $value['suffix'] : "");
            $q = db()->prepare("SELECT * FROM " . $account_data['table'] . "\n        WHERE user_id=? AND id=? ORDER BY title ASC");
            $q->execute(array(user_id(), $id));
            while ($r = $q->fetch()) {
                $r['exchange'] = $key;
                $r['khash'] = $account_data['khash'];
                $accounts[] = $r;
            }
        }
    }
}
if (!$account_data) {
    throw new Exception("No account data found for exchange '" . htmlspecialchars($exchange) . "'");
コード例 #2
0
// process extra field inline edit
if (require_post("key", false) !== false && require_post("id", false)) {
    $id = require_post("id");
    $key = require_post("key");
    $value = require_post("value");
    $exchange = require_post("type");
    // check that this is a valid property to change for this wizard
    if (!isset($account_data['wizard'])) {
        throw new Exception("No wizard data found");
    }
    $wizard_type = get_wizard_account_type($account_data['wizard']);
    if (!isset($wizard_type['display_editable'][$key])) {
        throw new Exception("Key '" . htmlspecialchars($key) . "' is not a valid editable key");
    }
    // check that this is a valid input for this key
    $config = get_accounts_wizard_config($exchange);
    if (!isset($config['inputs'][$key])) {
        throw new Exception("A '" . htmlspecialchars($exchange) . "' does not have an input '" . htmlspecialchars($key) . "'");
    }
    if (isset($config['inputs'][$key]['number']) && $config['inputs'][$key]['number']) {
        // remove any commas
        $value = number_unformat($value);
    }
    $callback = $config['inputs'][$key]['callback'];
    if (!$callback($value)) {
        $errors[] = t("':value' is not a valid :title :label.", array(':value' => htmlspecialchars($value), ':title' => htmlspecialchars($account_data['title']), ':label' => htmlspecialchars($config['inputs'][$key]['title'])));
    } else {
        $q = db()->prepare("UPDATE " . $account_data['table'] . " SET " . $config['inputs'][$key]['key'] . "=? WHERE user_id=? AND id=?");
        $q->execute(array($value, user_id(), $id));
        $messages[] = t("Updated :title :label.", array(':title' => htmlspecialchars($account_data['title']), ':label' => htmlspecialchars($config['inputs'][$key]['inline_title'])));
        // redirect to GET
コード例 #3
0
ファイル: discovered.php プロジェクト: phpsource/openclerk
<?php

/**
 * Balance job for an account that has been discovered through
 * DiscoveredComponents\Accounts.
 */
if (!$exchange) {
    throw new JobException("No exchange defined");
}
$account_type = get_accounts_wizard_config($exchange);
$table = $account_type['table'];
// get the relevant account
$q = db()->prepare("SELECT * FROM {$table} WHERE user_id=? AND id=?");
$q->execute(array($job['user_id'], $job['arg_id']));
$account = $q->fetch();
if (!$account) {
    throw new JobException("Cannot find an account " . $job['arg_id'] . " for user " . $job['user_id']);
}
$factory = new \Core\DiscoveredCurrencyFactory();
$instance = \DiscoveredComponents\Accounts::getInstance($exchange);
/**
 * Handle {@link SelfUpdatingAccount} callbacks.
 */
class SelfUpdatingAccountCallback
{
    function __construct($account, $table)
    {
        $this->account = $account;
        $this->table = $table;
    }
    function callback($data)