Пример #1
0
$user = get_user(user_id());
require_user($user);
$messages = array();
// get all of our accounts
global $accounts;
$accounts = user_limits_summary(user_id());
// get our currency preferences
require __DIR__ . "/../graphs/util.php";
$summaries = get_all_summary_currencies();
$currencies = get_all_currencies();
require __DIR__ . "/../graphs/types.php";
global $graphs;
$graphs = graph_types();
// work out which graphs we would have
require __DIR__ . "/../graphs/managed.php";
$auto_graphs = calculate_user_graphs($user, 'auto');
$managed_graphs = calculate_all_managed_graphs($user);
$managed_preferences = array();
$q = db()->prepare("SELECT * FROM managed_graphs WHERE user_id=?");
$q->execute(array(user_id()));
while ($m = $q->fetch()) {
    $managed_preferences[$m['preference']] = $m;
}
require_template("wizard_reports");
?>

<div class="wizard">

<form action="<?php 
echo htmlspecialchars(url_for('wizard_reports_post'));
?>
Пример #2
0
/**
 * Update all of the managed graphs of the given user.
 * This handles both 'auto' and 'managed' graph types.
 * This does not automatically delete all of the graphs on a user page - this is done in wizard_reports_post if necessary.
 * But it will delete any graphs that shouldn't be here. This way, any modified graphs should retain their changes
 * (especially if the graphs are 'managed' and not 'auto').
 */
function update_user_managed_graphs($user)
{
    global $messages;
    // find all of the graphs this user should have
    $managed = calculate_user_graphs($user);
    // does this user at least have a graph page?
    $q = db()->prepare("SELECT * FROM graph_pages WHERE user_id=? AND is_removed=0 ORDER BY page_order ASC, id ASC");
    $q->execute(array($user['id']));
    $page = $q->fetch();
    if (!$page) {
        // insert a new page
        $q = db()->prepare("INSERT INTO graph_pages SET user_id=?, title=?, is_managed=1");
        $q->execute(array($user['id'], t("Summary")));
        $page = array('id' => db()->lastInsertId());
        if (is_admin()) {
            $messages[] = "(admin) Added new graph_page " . htmlspecialchars($page['id']) . ".";
        }
    } else {
        if ($user['graph_managed_type'] == 'auto' && !$page['is_managed']) {
            // re-enable the managed flag on this page
            $q = db()->prepare("UPDATE graph_pages SET is_managed=1 WHERE id=? AND user_id=?");
            $q->execute(array($page['id'], $user['id']));
            if (is_admin()) {
                $messages[] = "(admin) Re-enabled is_managed flag on graph_page " . htmlspecialchars($page['id']) . ".";
            }
        }
    }
    // get all the graphs on this page
    $q = db()->prepare("SELECT * FROM graphs WHERE page_id=?");
    $q->execute(array($page['id']));
    $graphs = $q->fetchAll();
    $graphs_added = 0;
    $graphs_deleted = 0;
    // go through each managed graph, and see if we already have one defined
    foreach ($managed as $key => $config) {
        $found_graph = false;
        foreach ($graphs as $graph) {
            if ($graph['graph_type'] == $key) {
                $found_graph = true;
            }
        }
        if ($found_graph) {
            continue;
        }
        // no - we need to insert a new one
        $q = db()->prepare("INSERT INTO graphs SET graph_type=:graph_type,\n      width=:width,\n      height=:height,\n      page_order=:page_order,\n      days=:days,\n      page_id=:page_id,\n      is_managed=1");
        $q->execute(array("graph_type" => $key, "width" => isset($config['width']) ? $config['width'] : get_site_config('default_user_graph_width'), "height" => isset($config['height']) ? $config['height'] : get_site_config('default_user_graph_height'), "page_order" => $config['order'], "page_id" => $page['id'], "days" => isset($config['height']) ? $config['height'] : get_site_config('default_user_graph_days')));
        $graphs_added++;
    }
    // go through each existing graph, and remove any graphs that shouldn't be here
    foreach ($graphs as $graph) {
        $found_graph = false;
        foreach ($managed as $key => $config) {
            if ($graph['graph_type'] == $key) {
                $found_graph = true;
            }
        }
        if ($found_graph) {
            continue;
        }
        // no - we need to delete this graph
        $q = db()->prepare("DELETE FROM graphs WHERE id=?");
        $q->execute(array($graph['id']));
        $graphs_deleted++;
    }
    if (is_admin()) {
        $args = array(':added' => plural("graph", $graphs_added), ':removed' => plural("graph", $graphs_deleted));
        if ($graphs_deleted) {
            $messages[] = t("Added :added and removed :removed.", $args);
        } else {
            $messages[] = t("Added :added.", $args);
        }
    }
    // finally, update the needs_managed_update flag
    $q = db()->prepare("UPDATE user_properties SET needs_managed_update=0, last_managed_update=NOW() WHERE id=?");
    $q->execute(array($user['id']));
}
Пример #3
0
    $errors[] = t("Invalid graph management preference.");
}
if ($preference != "none" && !$preferred_fiat) {
    $errors[] = t("You need to select at least :one_currency in order to use managed graphs.", array(':one_currency' => link_to(url_for('wizard_currencies'), t("one fiat currency"))));
}
if ($preference != "none" && !$preferred_crypto) {
    $errors[] = t("You need to select at least :one_currency in order to use managed graphs.", array(':one_currency' => link_to(url_for('wizard_currencies'), t("one cryptocurrency"))));
}
foreach ($managed as $m) {
    if (!isset($categories[$m])) {
        $errors[] = "'" . htmlspecialchars($m) . "' is not a valid graph portfolio preference.";
    }
}
// check that this user can have this many graphs
if ($preference != 'none') {
    $generated_graphs = calculate_user_graphs($user, $preference, $managed);
    // if 'managed', also merge in any graphs that are already present on the final page
    // ('auto' will reset the page anyway)
    if ($preference == 'managed') {
        $q = db()->prepare("SELECT * FROM graph_pages WHERE is_managed=1 AND user_id=?");
        $q->execute(array(user_id()));
        if ($graph_page = $q->fetch()) {
            $q = db()->prepare("SELECT * FROM graphs WHERE page_id=?");
            $q->execute(array($graph_page['id']));
            while ($graph = $q->fetch()) {
                // only add it if it's not managed, because otherwise we can remove it
                if (!$graph['is_managed']) {
                    $generated_graphs[$graph['graph_type']] = $graph;
                }
            }
        }