示例#1
0
function display_graph($d)
{
    $total_pages = 0;
    if ($d == 0) {
        $graph = init_pie_graph(660, 400, 5);
        $title = _("Net pages saved so far today");
        for ($rn = 1; $rn <= MAX_NUM_PAGE_EDITING_ROUNDS; $rn++) {
            $round = get_Round_for_round_number($rn);
            $site_stats = get_site_page_tally_summary($round->id);
            $data[] = $pages = $site_stats->curr_day_actual;
            $labels[] = "{$round->id} ({$pages})";
            $total_pages += $pages;
        }
    } else {
        $graph = init_pie_graph(660, 400, 60);
        $title = sprintf(_("Net pages saved in preceding %s days"), $d);
        $now = time();
        for ($rn = 1; $rn <= MAX_NUM_PAGE_EDITING_ROUNDS; $rn++) {
            $round = get_Round_for_round_number($rn);
            $tallyboard = new TallyBoard($round->id, 'S');
            $data[] = $pages = $tallyboard->get_delta_sum(1, $now - 60 * 60 * 24 * $d, $now);
            $labels[] = "{$round->id} ({$pages})";
            $total_pages += $pages;
        }
    }
    if ($total_pages == 0) {
        dpgraph_error(_("No pages saved in specified range"));
    }
    draw_pie_graph($graph, $labels, $data, $title);
}
function summarize_stage($stage, $desired_states, $show_filtered_projects = FALSE, $filter_type = "")
{
    global $pguser, $n_projects_in_state_, $n_projects_transitioned_to_state_;
    // Get the stage identifier.
    $stage_icon_url = get_dyn_image_url_for_file("stage_icons/{$stage->id}");
    if (!is_null($stage_icon_url)) {
        $stage_id_bit = "<img src='{$stage_icon_url}' alt='({$stage->id})' title='{$stage->id}'>";
    } else {
        $stage_id_bit = "{$stage->id}";
    }
    // Get the stage description for displaying in the title of the link.
    $description = attr_safe(strip_tags($stage->description));
    // Determine access eligibility for this stage.
    $uao = $stage->user_access($pguser);
    if ($uao->can_access) {
        $access_icon = "graphics/access_yes.png";
        $access_text = _("You can work in this activity");
        $access_link = '';
    } elseif ($uao->all_minima_satisfied) {
        $access_icon = "graphics/access_eligible.png";
        $access_text = _("You are eligible to work in this activity");
        $access_link = "{$stage->relative_url}#Entrance_Requirements";
    } else {
        $access_icon = "graphics/access_no.png";
        $access_text = _("You are not yet eligible to work in this activity");
        $access_link = "{$stage->relative_url}#Entrance_Requirements";
    }
    // If we're a round, get page information and calculate status.
    if (is_a($stage, 'Round')) {
        $round_stats = get_site_page_tally_summary($stage->id);
        list($progress_bar_width, $progress_bar_color, $percent_complete) = calculate_progress_bar_properties($round_stats->curr_day_actual, $round_stats->curr_day_goal);
    }
    // Calculate the total number of projects.
    $total_projects = 0;
    $stage_totals = array();
    foreach ($desired_states as $stage_state) {
        // Pull the number of completed projects from the project
        // transitions array and the others from the current state array.
        // Only sum the stats that aren't project_complete_state as they're
        // already included in the following round's numbers.
        // (Use '@' to suppress "Undefined property" notice:
        // not every stage has a 'project_complete_state'.)
        if ($stage_state == @$stage->project_complete_state) {
            $count = array_get($n_projects_transitioned_to_state_, $stage_state, 0);
        } else {
            $count = array_get($n_projects_in_state_, $stage_state, 0);
            $total_projects += $count;
        }
        $stage_totals[$stage_state] = $count;
    }
    // Pull the project filter
    $n_projects_in_state_by_filter_ = array();
    if ($show_filtered_projects) {
        $project_filter = get_project_filter_sql($pguser, $filter_type);
    }
    // We can't load filtered numbers without a filter and without
    // a list of desired states.
    $load_filtered_projects = FALSE;
    if ($show_filtered_projects && $project_filter != "" && count($desired_states) != 0) {
        $load_filtered_projects = TRUE;
    }
    // Load any projects based on filters
    if ($load_filtered_projects) {
        $states_list = '';
        foreach ($desired_states as $desired_state) {
            if ($states_list) {
                $states_list .= ',';
            }
            $states_list .= "'{$desired_state}'";
            $n_projects_in_state_by_filter_[$desired_state] = 0;
            // (Use '@' to suppress "Undefined property" notice:
            // not every stage has a 'project_complete_state'.)
            if ($desired_state == @$stage->project_complete_state) {
                $n_projects_in_state_by_filter_[$desired_state] = _("N/A");
            }
        }
        $res = mysql_query("\n            SELECT state, COUNT(*)\n            FROM projects\n            WHERE state IN ({$states_list}) {$project_filter}\n            GROUP BY state\n        ") or die(mysql_error());
        $total_projects = 0;
        while (list($project_state, $count) = mysql_fetch_row($res)) {
            $n_projects_in_state_by_filter_[$project_state] = $count;
            $total_projects += $count;
        }
    }
    // Output the table row.
    echo "<tr>";
    // If we're showing the filter for this line, we need the
    // round cell to span two rows.
    if ($show_filtered_projects) {
        $span_rows = "rowspan='2'";
    } else {
        $span_rows = "";
    }
    // Every row gets a label, name, and access information.
    echo "<td style='border-right: 0;' {$span_rows}>{$stage_id_bit}</td>";
    echo "<td style='text-align: left; border-left: 0; border-right: 0;' {$span_rows}><a href='{$stage->relative_url}' title='{$description}'>{$stage->name}</a></td>";
    // Output the access status icon. If the user does not yet have access
    // make the image a link to the access requirements.
    echo "<td style='border-left: 0;' {$span_rows}>";
    if ($access_link) {
        echo "<a href='{$access_link}'>";
    }
    echo "<img src='{$access_icon}' alt='" . attr_safe($access_text) . "' title='" . attr_safe($access_text) . "'>";
    if ($access_link) {
        echo "</a>";
    }
    echo "</td>";
    // Rounds and Pools also get project totals.
    if (is_a($stage, 'Round') || is_a($stage, 'Pool')) {
        echo "<td>{$total_projects}</td>";
        foreach ($desired_states as $desired_state) {
            echo "<td>";
            if ($load_filtered_projects) {
                echo $n_projects_in_state_by_filter_[$desired_state];
            } else {
                echo $stage_totals[$desired_state];
            }
            echo "</td>";
        }
    } else {
        echo "<td colspan='3' class='nocell'></td>";
    }
    // Rounds also get page totals.
    if (is_a($stage, 'Round')) {
        echo "<td>{$round_stats->curr_day_goal}</td>";
        echo "<td>{$round_stats->curr_day_actual}</td>";
        echo "<td><div class='progressbar' style='background-color: {$progress_bar_color}; width: {$progress_bar_width}%;'>&nbsp;</div><p style='clear: both; margin-top: 0;'>{$percent_complete}%</p></td>";
    } else {
        // IE6 & 7 do not display the top and left borders of a cell if
        // border-collapse=collapse and the border=1px. The following
        // tweak is to ensure that if we show the filter that the filter
        // cell has a border all the way around it.
        if ($show_filtered_projects) {
            echo "<td colspan='4' class='nocell' style='border-bottom: 1px solid black;'></td>";
        } else {
            echo "<td colspan='4' class='nocell'></td>";
        }
    }
    echo "</tr>\n";
    if ($show_filtered_projects) {
        if ($load_filtered_projects) {
            $display_filter = get_project_filter_display($pguser, $filter_type);
            $display_filter = preg_replace(array("/^<br>/", "/<br>/"), array("", " | "), $display_filter);
        } else {
            $display_filter = "<i>" . _("None") . "</i>";
        }
        echo "<tr>";
        echo "<td colspan='7' style='text-align: left;'>";
        echo "<small><a href='{$stage->relative_url}#filter_form'>" . _("Filter") . "</a>: {$display_filter}</small>";
        echo "</td>";
        echo "</tr>";
    }
}