Beispiel #1
0
/**
 * Calculate all of the graphs that would be created for a given user,
 * with a given graph calculation strategy.
 * @param $strategy 'auto', 'managed' or '' (use user-defined)
 * @param $managed an array of categories or use, or empty to use user-defined
 */
function calculate_user_graphs($user, $strategy = false, $categories = array())
{
    if ($strategy === false) {
        if (!$user['graph_managed_type']) {
            throw new ManagedGraphException("User has no managed graph type, so cannot select user-defined strategy");
        }
        return calculate_user_graphs($user, $user['graph_managed_type'], $categories);
    }
    $managed = calculate_all_managed_graphs($user);
    // merge them all together based on user preferences
    if ($strategy == "managed") {
        if (!$categories) {
            $q = db()->prepare("SELECT * FROM managed_graphs WHERE user_id=?");
            $q->execute(array($user['id']));
            while ($m = $q->fetch()) {
                $categories[] = $m['preference'];
            }
        }
    } else {
        // default categories for auto
        $categories = get_auto_managed_graph_categories();
    }
    // merge all graphs based on categories
    $result = array();
    foreach ($categories as $key) {
        if (isset($managed[$key])) {
            foreach ($managed[$key] as $graph_key => $graph) {
                // remove any graphs that are not free priorities for non-premium users
                if ($user['is_premium'] || isset($graph['free']) && $graph['free']) {
                    $result[$graph_key] = $graph;
                }
            }
        }
    }
    // limit to the maximum number of graphs that we can support, if necessary
    // sort by priority
    uasort($result, '_sort_by_priority_key');
    if (count($result) > get_premium_value($user, 'graphs_per_page')) {
        $result = array_slice($result, 0, get_premium_value($user, 'graphs_per_page'));
    }
    // sort by order
    uasort($result, '_sort_by_order_key');
    return $result;
}
Beispiel #2
0
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'));
?>
" method="post">