Beispiel #1
0
function do_summary(&$count, &$hours, &$room_hash, &$name_hash)
{
    global $output_format, $csv_col_sep;
    global $times_somewhere, $periods_somewhere;
    // Sort the room and name arrays
    ksort($room_hash);
    ksort($name_hash);
    // Initialise grand total counters
    foreach (array(MODE_TIMES, MODE_PERIODS) as $m) {
        $grand_count_total[$m] = 0;
        $grand_hours_total[$m] = 0;
    }
    // TABLE HEAD
    // ----------
    $head_rows = array();
    $row1_cells = array('');
    $row2_cells = array('');
    foreach ($room_hash as $room => $mode) {
        $col_count_total[$room] = 0;
        $col_hours_total[$room] = 0.0;
        $mode_text = $mode == MODE_TIMES ? get_vocab("mode_times") : get_vocab("mode_periods");
        $row1_cells[] = $room;
        $row1_cells[] = '';
        // The cell before is really spanning two columns.   We'll sort it out with JavaScript
        $row2_cells[] = get_vocab("entries");
        $row2_cells[] = $mode == MODE_PERIODS ? get_vocab("periods") : get_vocab("hours");
    }
    // Add the total column(s) onto the end
    if ($times_somewhere) {
        $row1_cells[] = get_vocab("total") . " (" . get_vocab("mode_times") . ")";
        $row1_cells[] = '';
        $row2_cells[] = get_vocab("entries");
        $row2_cells[] = get_vocab("hours");
    }
    if ($periods_somewhere) {
        $row1_cells[] = get_vocab("total") . " (" . get_vocab("mode_periods") . ")";
        $row1_cells[] = '';
        $row2_cells[] = get_vocab("entries");
        $row2_cells[] = get_vocab("periods");
    }
    // Add the rows to the array of header rows, for output later
    $head_rows[] = $row1_cells;
    $head_rows[] = $row2_cells;
    // TABLE BODY
    // ----------
    $body_rows = array();
    foreach ($name_hash as $name => $is_present) {
        foreach (array(MODE_TIMES, MODE_PERIODS) as $m) {
            $row_count_total[$m] = 0;
            $row_hours_total[$m] = 0;
        }
        $cells = array();
        $cells[] = $name;
        foreach ($room_hash as $room => $mode) {
            if (isset($count[$room][$name])) {
                $count_val = $count[$room][$name];
                $hours_val = $hours[$room][$name];
                $cells[] = entries_format($count_val);
                $format = $mode == MODE_TIMES ? FORMAT_TIMES : FORMAT_PERIODS;
                $cells[] = sprintf($format, $hours_val);
                $row_count_total[$mode] += $count_val;
                $row_hours_total[$mode] += $hours_val;
                $col_count_total[$room] += $count_val;
                $col_hours_total[$room] += $hours_val;
            } else {
                $cells[] = $output_format == OUTPUT_HTML ? " " : '';
                $cells[] = $output_format == OUTPUT_HTML ? " " : '';
            }
        }
        // Add the total column(s) onto the end
        if ($times_somewhere) {
            $cells[] = entries_format($row_count_total[MODE_TIMES]);
            $cells[] = sprintf(FORMAT_TIMES, $row_hours_total[MODE_TIMES]);
        }
        if ($periods_somewhere) {
            $cells[] = entries_format($row_count_total[MODE_PERIODS]);
            $cells[] = sprintf(FORMAT_PERIODS, $row_hours_total[MODE_PERIODS]);
        }
        $body_rows[] = $cells;
        foreach (array(MODE_TIMES, MODE_PERIODS) as $m) {
            $grand_count_total[$m] += $row_count_total[$m];
            $grand_hours_total[$m] += $row_hours_total[$m];
        }
    }
    // TABLE FOOT
    // ----------
    $foot_rows = array();
    $cells = array();
    $cells[] = get_vocab("total");
    foreach ($room_hash as $room => $mode) {
        $cells[] = entries_format($col_count_total[$room]);
        $format = $mode == MODE_TIMES ? FORMAT_TIMES : FORMAT_PERIODS;
        $cells[] = sprintf($format, $col_hours_total[$room]);
    }
    // Add the total column(s) onto the end
    if ($times_somewhere) {
        $cells[] = entries_format($grand_count_total[MODE_TIMES]);
        $cells[] = sprintf(FORMAT_TIMES, $grand_hours_total[MODE_TIMES]);
    }
    if ($periods_somewhere) {
        $cells[] = entries_format($grand_count_total[MODE_PERIODS]);
        $cells[] = sprintf(FORMAT_PERIODS, $grand_hours_total[MODE_PERIODS]);
    }
    $foot_rows[] = $cells;
    // OUTPUT THE TABLE
    // ----------------
    if ($output_format == OUTPUT_HTML) {
        // <tfoot> has to come before <tbody>
        output_head_rows($head_rows, $output_format);
        output_foot_rows($foot_rows, $output_format);
        output_body_rows($body_rows, $output_format);
    } else {
        output_head_rows($head_rows, $output_format);
        output_body_rows($body_rows, $output_format);
        output_foot_rows($foot_rows, $output_format);
    }
}
function do_summary(&$count, &$hours, &$room_hash, &$name_hash)
{
    global $output_as_csv, $csv_col_sep;
    global $times_somewhere, $periods_somewhere;
    // Sort the room and name arrays
    ksort($room_hash);
    ksort($name_hash);
    // Initialise grand total counters
    foreach (array(MODE_TIMES, MODE_PERIODS) as $m) {
        $grand_count_total[$m] = 0;
        $grand_hours_total[$m] = 0;
    }
    // TABLE HEAD
    // ----------
    $head_rows = array();
    $row1_cells = array();
    $row2_cells = array();
    foreach ($room_hash as $room => $mode) {
        $col_count_total[$room] = 0;
        $col_hours_total[$room] = 0.0;
        $mode_text = $mode == MODE_TIMES ? get_vocab("mode_times") : get_vocab("mode_periods");
        if ($output_as_csv) {
            $row1_cells[] = $room . ' - ' . get_vocab("entries");
            $row1_cells[] = $room . ' - ' . ($mode == MODE_PERIODS ? get_vocab("periods") : get_vocab("hours"));
            $row2_cells[] = $mode_text;
            $row2_cells[] = $mode_text;
        } else {
            $row1_cells[] = $room;
            $row2_cells[] = $mode_text;
        }
    }
    // Add the total column(s) onto the end
    if ($output_as_csv) {
        if ($times_somewhere) {
            $row1_cells[] = get_vocab("mode_times") . ": " . get_vocab("total") . ' - ' . get_vocab("entries");
            $row1_cells[] = get_vocab("mode_times") . ": " . get_vocab("total") . ' - ' . get_vocab("hours");
            $row2_cells[] = '';
            $row2_cells[] = '';
        }
        if ($periods_somewhere) {
            $row1_cells[] = get_vocab("mode_periods") . ": " . get_vocab("total") . ' - ' . get_vocab("entries");
            $row1_cells[] = get_vocab("mode_periods") . ": " . get_vocab("total") . ' - ' . get_vocab("hours");
            $row2_cells[] = '';
            $row2_cells[] = '';
        }
    } else {
        if ($times_somewhere) {
            $row1_cells[] = get_vocab("total") . "<br>" . get_vocab("mode_times");
            $row2_cells[] = "&nbsp;";
        }
        if ($periods_somewhere) {
            $row1_cells[] = get_vocab("total") . "<br>" . get_vocab("mode_periods");
            $row2_cells[] = "&nbsp;";
        }
    }
    // Implode the cells and add a label column on to the beginning (we have to
    // do it this way because the head is a bit more complicated than the body and
    // the foot as it has cells which span two columns)
    if ($output_as_csv) {
        $row1 = '""' . $csv_col_sep . implode_cells($row1_cells);
        $row2 = '"Mode"' . $csv_col_sep . implode_cells($row2_cells);
    } else {
        $row1 = "<th>&nbsp;</th>\n";
        $row1 .= implode_cells($row1_cells, 'th', 'colspan="2"');
        $row2 = "<th>" . get_vocab("mode") . "</th>\n";
        $row2 .= implode_cells($row2_cells, 'th', 'colspan="2"');
    }
    $head_rows[] = $row1;
    // Only use the second row if we need to, that is if we have both times and periods
    if ($times_somewhere && $periods_somewhere) {
        $head_rows[] = $row2;
    }
    $head = implode_rows($head_rows, 'thead');
    // TABLE BODY
    // ----------
    $body_rows = array();
    foreach ($name_hash as $name => $is_present) {
        foreach (array(MODE_TIMES, MODE_PERIODS) as $m) {
            $row_count_total[$m] = 0;
            $row_hours_total[$m] = 0;
        }
        $cells = array();
        $cells[] = $name;
        foreach ($room_hash as $room => $mode) {
            if (isset($count[$room][$name])) {
                $count_val = $count[$room][$name];
                $hours_val = $hours[$room][$name];
                $cells[] = entries_format($count_val);
                $format = $mode == MODE_TIMES ? FORMAT_TIMES : FORMAT_PERIODS;
                $cells[] = sprintf($format, $hours_val);
                $row_count_total[$mode] += $count_val;
                $row_hours_total[$mode] += $hours_val;
                $col_count_total[$room] += $count_val;
                $col_hours_total[$room] += $hours_val;
            } else {
                $cells[] = $output_as_csv ? '' : "&nbsp;";
                $cells[] = $output_as_csv ? '' : "&nbsp;";
            }
        }
        // Add the total column(s) onto the end
        if ($times_somewhere) {
            $cells[] = entries_format($row_count_total[MODE_TIMES]);
            $cells[] = sprintf(FORMAT_TIMES, $row_hours_total[MODE_TIMES]);
        }
        if ($periods_somewhere) {
            $cells[] = entries_format($row_count_total[MODE_PERIODS]);
            $cells[] = sprintf(FORMAT_PERIODS, $row_hours_total[MODE_PERIODS]);
        }
        $body_rows[] = implode_cells($cells, 'td');
        foreach (array(MODE_TIMES, MODE_PERIODS) as $m) {
            $grand_count_total[$m] += $row_count_total[$m];
            $grand_hours_total[$m] += $row_hours_total[$m];
        }
    }
    $body = implode_rows($body_rows, 'tbody');
    // TABLE FOOT
    // ----------
    $foot_rows = array();
    $cells = array();
    $cells[] = get_vocab("total");
    foreach ($room_hash as $room => $mode) {
        $cells[] = entries_format($col_count_total[$room]);
        $format = $mode == MODE_TIMES ? FORMAT_TIMES : FORMAT_PERIODS;
        $cells[] = sprintf($format, $col_hours_total[$room]);
    }
    // Add the total column(s) onto the end
    if ($times_somewhere) {
        $cells[] = entries_format($grand_count_total[MODE_TIMES]);
        $cells[] = sprintf(FORMAT_TIMES, $grand_hours_total[MODE_TIMES]);
    }
    if ($periods_somewhere) {
        $cells[] = entries_format($grand_count_total[MODE_PERIODS]);
        $cells[] = sprintf(FORMAT_PERIODS, $grand_hours_total[MODE_PERIODS]);
    }
    $foot_rows[] = implode_cells($cells, 'th');
    $foot = implode_rows($foot_rows, 'tfoot');
    // OUTPUT THE TABLE
    // ----------------
    if ($output_as_csv) {
        echo $head;
        echo $body;
        echo $foot;
    } else {
        echo "<div id=\"div_summary\">\n";
        echo "<h1>";
        if ($times_somewhere) {
            echo $periods_somewhere ? get_vocab("summary_header_both") : get_vocab("summary_header");
        } else {
            echo get_vocab("summary_header_per");
        }
        echo "</h1>\n";
        echo "<table>\n";
        echo $head;
        echo $foot;
        // <tfoot> has to come before <tbody>
        echo $body;
        echo "</table>\n";
        echo "</div>\n";
    }
}