Example #1
0
function regenerate_vote_summary($poll_id)
{
    // Find vote history file
    $history_fp = @fopen(vote_history_file_path($poll_id), "r");
    if ($history_fp === FALSE) {
        return FALSE;
    }
    // Read votes into summary array
    $count = 0;
    $votes = array();
    while (!@feof($history_fp)) {
        $history_line = @fgets($history_fp);
        if (empty($history_line)) {
            continue;
        }
        $history = explode_history($history_line);
        // Add to summary array
        $count++;
        $vote_value_id = $history[1];
        if (isset($votes[$vote_value_id])) {
            $votes[$vote_value_id]++;
        } else {
            $votes[$vote_value_id] = 1;
        }
    }
    @fclose($history_fp);
    // Open summary file
    $summary_fp = @fopen(vote_summary_file_path($poll_id), "a");
    if ($summary_fp === FALSE) {
        vote_die("Unable to open summary file for writing");
    }
    if (@ftruncate($summary_fp, 0) === FALSE) {
        @fclose($summary_fp);
        vote_die("Unable to truncate summary file");
    }
    // Regenerate summary based on counts from history in summary array
    fputs($summary_fp, $count . "\n");
    // Total count
    foreach ($votes as $vote_id => $value) {
        fputs($summary_fp, $vote_id . "|" . $value . "\n");
    }
    @fclose($summary_fp);
    return TRUE;
}
Example #2
0
function vote_history_list($poll_id)
{
    // Load existing vote history
    $summarylist = @file(vote_history_file_path($poll_id));
    if ($summarylist !== FALSE) {
        $summarylist = array_map("explode_history", $summarylist);
    }
    return $summarylist;
}