/** * Renders HTML table * * This method may modify the passed instance by adding some default properties if they are not set yet. * If this is not what you want, you should make a full clone of your data before passing them to this * method. In most cases this is not an issue at all so we do not clone by default for performance * and memory consumption reasons. * * Please do not use .r0/.r1 for css, as they will be removed in Moodle 2.9. * @todo MDL-43902 , remove r0 and r1 from tr classes. * * @param html_table $table data to be rendered * @return string HTML code */ public static function table(html_table $table) { // prepare table data and populate missing properties with reasonable defaults if (!empty($table->align)) { foreach ($table->align as $key => $aa) { if ($aa) { $table->align[$key] = 'text-align:' . fix_align_rtl($aa) . ';'; // Fix for RTL languages } else { $table->align[$key] = null; } } } if (!empty($table->size)) { foreach ($table->size as $key => $ss) { if ($ss) { $table->size[$key] = 'width:' . $ss . ';'; } else { $table->size[$key] = null; } } } if (!empty($table->wrap)) { foreach ($table->wrap as $key => $ww) { if ($ww) { $table->wrap[$key] = 'white-space:nowrap;'; } else { $table->wrap[$key] = ''; } } } if (!empty($table->head)) { foreach ($table->head as $key => $val) { if (!isset($table->align[$key])) { $table->align[$key] = null; } if (!isset($table->size[$key])) { $table->size[$key] = null; } if (!isset($table->wrap[$key])) { $table->wrap[$key] = null; } } } if (empty($table->attributes['class'])) { $table->attributes['class'] = 'generaltable'; } if (!empty($table->tablealign)) { $table->attributes['class'] .= ' boxalign' . $table->tablealign; } // explicitly assigned properties override those defined via $table->attributes $table->attributes['class'] = trim($table->attributes['class']); $attributes = array_merge($table->attributes, array('id' => $table->id, 'width' => $table->width, 'summary' => $table->summary, 'cellpadding' => $table->cellpadding, 'cellspacing' => $table->cellspacing)); $output = html_writer::start_tag('table', $attributes) . "\n"; $countcols = 0; if (!empty($table->head)) { $countcols = count($table->head); $output .= html_writer::start_tag('thead', array()) . "\n"; $output .= html_writer::start_tag('tr', array()) . "\n"; $keys = array_keys($table->head); $lastkey = end($keys); foreach ($table->head as $key => $heading) { // Convert plain string headings into html_table_cell objects if (!$heading instanceof html_table_cell) { $headingtext = $heading; $heading = new html_table_cell(); $heading->text = $headingtext; $heading->header = true; } if ($heading->header !== false) { $heading->header = true; } if ($heading->header && empty($heading->scope)) { $heading->scope = 'col'; } $heading->attributes['class'] .= ' header c' . $key; if (isset($table->headspan[$key]) && $table->headspan[$key] > 1) { $heading->colspan = $table->headspan[$key]; $countcols += $table->headspan[$key] - 1; } if ($key == $lastkey) { $heading->attributes['class'] .= ' lastcol'; } if (isset($table->colclasses[$key])) { $heading->attributes['class'] .= ' ' . $table->colclasses[$key]; } $heading->attributes['class'] = trim($heading->attributes['class']); $attributes = array_merge($heading->attributes, array('style' => $table->align[$key] . $table->size[$key] . $heading->style, 'scope' => $heading->scope, 'colspan' => $heading->colspan)); $tagtype = 'td'; if ($heading->header === true) { $tagtype = 'th'; } $output .= html_writer::tag($tagtype, $heading->text, $attributes) . "\n"; } $output .= html_writer::end_tag('tr') . "\n"; $output .= html_writer::end_tag('thead') . "\n"; if (empty($table->data)) { // For valid XHTML strict every table must contain either a valid tr // or a valid tbody... both of which must contain a valid td $output .= html_writer::start_tag('tbody', array('class' => 'empty')); $output .= html_writer::tag('tr', html_writer::tag('td', '', array('colspan' => count($table->head)))); $output .= html_writer::end_tag('tbody'); } } if (!empty($table->data)) { $oddeven = 1; $keys = array_keys($table->data); $lastrowkey = end($keys); $output .= html_writer::start_tag('tbody', array()); foreach ($table->data as $key => $row) { if ($row === 'hr' && $countcols) { $output .= html_writer::tag('td', html_writer::tag('div', '', array('class' => 'tabledivider')), array('colspan' => $countcols)); } else { // Convert array rows to html_table_rows and cell strings to html_table_cell objects if (!$row instanceof html_table_row) { $newrow = new html_table_row(); foreach ($row as $cell) { if (!$cell instanceof html_table_cell) { $cell = new html_table_cell($cell); } $newrow->cells[] = $cell; } $row = $newrow; } $oddeven = $oddeven ? 0 : 1; if (isset($table->rowclasses[$key])) { $row->attributes['class'] .= ' ' . $table->rowclasses[$key]; } $row->attributes['class'] .= ' r' . $oddeven; if ($key == $lastrowkey) { $row->attributes['class'] .= ' lastrow'; } // Explicitly assigned properties should override those defined in the attributes. $row->attributes['class'] = trim($row->attributes['class']); $trattributes = array_merge($row->attributes, array('id' => $row->id, 'style' => $row->style)); $output .= html_writer::start_tag('tr', $trattributes) . "\n"; $keys2 = array_keys($row->cells); $lastkey = end($keys2); $gotlastkey = false; //flag for sanity checking foreach ($row->cells as $key => $cell) { if ($gotlastkey) { //This should never happen. Why do we have a cell after the last cell? mtrace("A cell with key ({$key}) was found after the last key ({$lastkey})"); } if (!$cell instanceof html_table_cell) { $mycell = new html_table_cell(); $mycell->text = $cell; $cell = $mycell; } if ($cell->header === true && empty($cell->scope)) { $cell->scope = 'row'; } if (isset($table->colclasses[$key])) { $cell->attributes['class'] .= ' ' . $table->colclasses[$key]; } $cell->attributes['class'] .= ' cell c' . $key; if ($key == $lastkey) { $cell->attributes['class'] .= ' lastcol'; $gotlastkey = true; } $tdstyle = ''; $tdstyle .= isset($table->align[$key]) ? $table->align[$key] : ''; $tdstyle .= isset($table->size[$key]) ? $table->size[$key] : ''; $tdstyle .= isset($table->wrap[$key]) ? $table->wrap[$key] : ''; $cell->attributes['class'] = trim($cell->attributes['class']); $tdattributes = array_merge($cell->attributes, array('style' => $tdstyle . $cell->style, 'colspan' => $cell->colspan, 'rowspan' => $cell->rowspan, 'id' => $cell->id, 'abbr' => $cell->abbr, 'scope' => $cell->scope)); $tagtype = 'td'; if ($cell->header === true) { $tagtype = 'th'; } $output .= html_writer::tag($tagtype, $cell->text, $tdattributes) . "\n"; } } $output .= html_writer::end_tag('tr') . "\n"; } $output .= html_writer::end_tag('tbody') . "\n"; } $output .= html_writer::end_tag('table') . "\n"; return $output; }
/** * Print a nicely formatted table. * * @param array $table is an object with several properties. * <ul> * <li>$table->head - An array of heading names. * <li>$table->align - An array of column alignments * <li>$table->size - An array of column sizes * <li>$table->wrap - An array of "nowrap"s or nothing * <li>$table->data[] - An array of arrays containing the data. * <li>$table->width - A percentage of the page * <li>$table->tablealign - Align the whole table * <li>$table->cellpadding - Padding on each cell * <li>$table->cellspacing - Spacing between cells * <li>$table->class - class attribute to put on the table * <li>$table->id - id attribute to put on the table. * <li>$table->rowclass[] - classes to add to particular rows. * <li>$table->summary - Description of the contents for screen readers. * </ul> * @param bool $return whether to return an output string or echo now * @return boolean or $string * @todo Finish documenting this function */ function print_table($table, $return = false) { $output = ''; if (isset($table->align)) { foreach ($table->align as $key => $aa) { if ($aa) { $align[$key] = ' text-align:' . fix_align_rtl($aa) . ';'; // Fix for RTL languages } else { $align[$key] = ''; } } } if (isset($table->size)) { foreach ($table->size as $key => $ss) { if ($ss) { $size[$key] = ' width:' . $ss . ';'; } else { $size[$key] = ''; } } } if (isset($table->wrap)) { foreach ($table->wrap as $key => $ww) { if ($ww) { $wrap[$key] = ' white-space:nowrap;'; } else { $wrap[$key] = ''; } } } if (empty($table->width)) { $table->width = '80%'; } if (empty($table->tablealign)) { $table->tablealign = 'center'; } if (!isset($table->cellpadding)) { $table->cellpadding = '5'; } if (!isset($table->cellspacing)) { $table->cellspacing = '1'; } if (empty($table->class)) { $table->class = 'generaltable'; } $tableid = empty($table->id) ? '' : 'id="' . $table->id . '"'; $output .= '<table width="' . $table->width . '" '; if (!empty($table->summary)) { $output .= " summary=\"{$table->summary}\""; } $output .= " cellpadding=\"{$table->cellpadding}\" cellspacing=\"{$table->cellspacing}\" class=\"{$table->class} boxalign{$table->tablealign}\" {$tableid}>\n"; $countcols = 0; if (!empty($table->head)) { $countcols = count($table->head); $output .= '<tr>'; $keys = array_keys($table->head); $lastkey = end($keys); foreach ($table->head as $key => $heading) { if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if ($key == $lastkey) { $extraclass = ' lastcol'; } else { $extraclass = ''; } $output .= '<th style="vertical-align:top;' . $align[$key] . $size[$key] . ';white-space:nowrap;" class="header c' . $key . $extraclass . '" scope="col">' . $heading . '</th>'; } $output .= '</tr>' . "\n"; } if (!empty($table->data)) { $oddeven = 1; $keys = array_keys($table->data); $lastrowkey = end($keys); foreach ($table->data as $key => $row) { $oddeven = $oddeven ? 0 : 1; if (!isset($table->rowclass[$key])) { $table->rowclass[$key] = ''; } if ($key == $lastrowkey) { $table->rowclass[$key] .= ' lastrow'; } $output .= '<tr class="r' . $oddeven . ' ' . $table->rowclass[$key] . '">' . "\n"; if ($row == 'hr' and $countcols) { $output .= '<td colspan="' . $countcols . '"><div class="tabledivider"></div></td>'; } else { /// it's a normal row of data $keys2 = array_keys($row); $lastkey = end($keys2); foreach ($row as $key => $item) { if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if (!isset($wrap[$key])) { $wrap[$key] = ''; } if ($key == $lastkey) { $extraclass = ' lastcol'; } else { $extraclass = ''; } $output .= '<td style="' . $align[$key] . $size[$key] . $wrap[$key] . '" class="cell c' . $key . $extraclass . '">' . $item . '</td>'; } } $output .= '</tr>' . "\n"; } } $output .= '</table>' . "\n"; if ($return) { return $output; } echo $output; return true; }
/** * Print a nicely formatted table. * * @param array $table is an object with several properties. * <ul> * <li>$table->head - An array of heading names. * <li>$table->align - An array of column alignments * <li>$table->size - An array of column sizes * <li>$table->wrap - An array of "nowrap"s or nothing * <li>$table->data[] - An array of arrays containing the data. * <li>$table->width - A percentage of the page * <li>$table->tablealign - Align the whole table * <li>$table->cellpadding - Padding on each cell * <li>$table->cellspacing - Spacing between cells * <li>$table->class - class attribute to put on the table * <li>$table->id - id attribute to put on the table. * <li>$table->rowclass[] - classes to add to particular rows. (space-separated string) * <li>$table->colclass[] - classes to add to every cell in a particular colummn. (space-separated string) * <li>$table->summary - Description of the contents for screen readers. * <li>$table->headspan can be used to make a heading span multiple columns. * <li>$table->rotateheaders - Causes the contents of the heading cells to be rotated 90 degrees. * </ul> * @param bool $return whether to return an output string or echo now * @return boolean or $string * @todo Finish documenting this function */ function print_table($table, $return = false) { $output = ''; if (isset($table->align)) { foreach ($table->align as $key => $aa) { if ($aa) { $align[$key] = ' text-align:' . fix_align_rtl($aa) . ';'; // Fix for RTL languages } else { $align[$key] = ''; } } } if (isset($table->size)) { foreach ($table->size as $key => $ss) { if ($ss) { $size[$key] = ' width:' . $ss . ';'; } else { $size[$key] = ''; } } } if (isset($table->wrap)) { foreach ($table->wrap as $key => $ww) { if ($ww) { $wrap[$key] = ' white-space:nowrap;'; } else { $wrap[$key] = ''; } } } if (empty($table->width)) { $table->width = '80%'; } if (empty($table->tablealign)) { $table->tablealign = 'center'; } if (!isset($table->cellpadding)) { $table->cellpadding = '5'; } if (!isset($table->cellspacing)) { $table->cellspacing = '1'; } if (empty($table->class)) { $table->class = 'generaltable'; } if (!empty($table->rotateheaders)) { $table->class .= ' rotateheaders'; } else { $table->rotateheaders = false; // Makes life easier later. } $tableid = empty($table->id) ? '' : 'id="' . $table->id . '"'; $output .= '<table width="' . $table->width . '" '; if (!empty($table->summary)) { $output .= " summary=\"{$table->summary}\""; } $output .= " cellpadding=\"{$table->cellpadding}\" cellspacing=\"{$table->cellspacing}\" class=\"{$table->class} boxalign{$table->tablealign}\" {$tableid}>\n"; $countcols = 0; if (!empty($table->head)) { $countcols = count($table->head); $output .= '<tr>'; $keys = array_keys($table->head); $lastkey = end($keys); foreach ($table->head as $key => $heading) { $classes = array('header', 'c' . $key); if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if (isset($table->headspan[$key]) && $table->headspan[$key] > 1) { $colspan = ' colspan="' . $table->headspan[$key] . '"'; } else { $colspan = ''; } if ($key == $lastkey) { $classes[] = 'lastcol'; } if (isset($table->colclasses[$key])) { $classes[] = $table->colclasses[$key]; } if ($table->rotateheaders) { $wrapperstart = '<span>'; $wrapperend = '</span>'; } else { $wrapperstart = ''; $wrapperend = ''; } $output .= '<th style="' . $align[$key] . $size[$key] . ';white-space:nowrap;" class="' . implode(' ', $classes) . '" scope="col"' . $colspan . '>' . $wrapperstart . $heading . $wrapperend . '</th>'; } $output .= '</tr>' . "\n"; } if (!empty($table->data)) { $oddeven = 1; $keys = array_keys($table->data); $lastrowkey = end($keys); foreach ($table->data as $key => $row) { $oddeven = $oddeven ? 0 : 1; if (!isset($table->rowclass[$key])) { $table->rowclass[$key] = ''; } if ($key == $lastrowkey) { $table->rowclass[$key] .= ' lastrow'; } $output .= '<tr class="r' . $oddeven . ' ' . $table->rowclass[$key] . '">' . "\n"; if ($row == 'hr' and $countcols) { $output .= '<td colspan="' . $countcols . '"><div class="tabledivider"></div></td>'; } else { /// it's a normal row of data $keys2 = array_keys($row); $lastkey = end($keys2); foreach ($row as $key => $item) { $classes = array('cell', 'c' . $key); if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if (!isset($wrap[$key])) { $wrap[$key] = ''; } if ($key == $lastkey) { $classes[] = 'lastcol'; } if (isset($table->colclasses[$key])) { $classes[] = $table->colclasses[$key]; } $output .= '<td style="' . $align[$key] . $size[$key] . $wrap[$key] . '" class="' . implode(' ', $classes) . '">' . $item . '</td>'; } } $output .= '</tr>' . "\n"; } } $output .= '</table>' . "\n"; if ($table->rotateheaders && can_use_rotated_text()) { require_js(array('yui_yahoo', 'yui_event', 'yui_dom')); require_js('course/report/progress/textrotate.js'); } if ($return) { return $output; } echo $output; return true; }
function css_styles() { ?> <style type="text/css"> body { background-color: #fafafa; } p, li, td { font-family: helvetica, arial, sans-serif; font-size: 10pt; } a { text-decoration: none; color: blue; } a img { border: none; } .errormsg { color: red; font-weight: bold; } blockquote { font-family: courier, monospace; font-size: 10pt; } .input_database { width: 270px; } .install_table { width: 500px; margin-left:auto; margin-right:auto; } .td_left { text-align: <?php echo fix_align_rtl("right"); ?> ; font-weight: bold; } .td_left_nowrap{ text-align: <?php echo fix_align_rtl("right"); ?> ; font-weight: bold; white-space: nowrap; width: 160px; padding-left: 10px; } .td_right { text-align: <?php echo fix_align_rtl("left"); ?> ; } .main { width: 80%; border-width: 1px; border-style: solid; border-color: #dddddd; margin-left:auto; margin-right:auto; -moz-border-radius-bottomleft: 15px; -moz-border-radius-bottomright: 15px; } .td_mainheading { background-color: #eeeeee; padding-left: 10px; } .td_main { text-align: center; } .td_mainlogo { vertical-align: middle; } .p_mainlogo { margin-top: 0px; margin-bottom: 0px; } .p_mainheading { font-size: 11pt; margin-top: 16px; margin-bottom: 16px; } .p_subheading { font-size: 10pt; padding-left: 10px; margin-top: 16px; margin-bottom: 16px; } .p_mainheader{ text-align: right; font-size: 20pt; font-weight: bold; margin-top: 0px; margin-bottom: 0px; } .p_pass { color: green; font-weight: bold; margin-top: 0px; margin-bottom: 0px; } .p_fail { color: red; font-weight: bold; margin-top: 0px; margin-bottom: 0px; } .p_caution { color: #660000; font-weight: bold; margin-top: 0px; margin-bottom: 0px; } .p_help { text-align: center; font-family: helvetica, arial, sans-serif; font-size: 14pt; font-weight: bold; color: #333333; margin-top: 0px; margin-bottom: 0px; } /* This override the p tag for every p tag in this installation script, but not in lang\xxx\installer.php */ .p_install { margin-top: 0px; margin-bottom: 0px; } .environmenttable { font-size: 10pt; border-color: #eeeeee; } .header { background-color: #dddddd; font-size: 10pt; } .cell { background-color: #eeeeee; font-size: 10pt; } .error { color: #ff0000; } .errorboxcontent { text-align: center; font-weight: bold; padding-left: 20px; color: #ff0000; } .invisiblefieldset { display:inline; border:0px; padding:0px; margin:0px; } </style> <?php }
function css_styles() { ?> <style type="text/css"> body { background-color: #ffeece; } p, li, td { font-family: helvetica, arial, sans-serif; font-size: 10pt; } a { text-decoration: none; color: blue; } a img { border: none; } .errormsg { color: red; font-weight: bold; } blockquote { font-family: courier, monospace; font-size: 10pt; } .install_table { width: 500px; } .td_left { text-align: <?php echo fix_align_rtl("right"); ?> ; font-weight: bold; } .td_right { text-align: <?php echo fix_align_rtl("left"); ?> ; } .main { width: 500px; border-width: 1px; border-style: solid; border-color: #ffc85f; -moz-border-radius-bottomleft: 15px; -moz-border-radius-bottomright: 15px; } .td_mainheading { background-color: #fee6b9; padding: 10px; } .td_main { text-align: center; } .td_mainlogo { } .p_mainlogo { } .p_mainheading { font-size: 11pt; } .p_subheading { font-size: 10pt; padding: 10px; } .p_mainheader{ text-align: right; font-size: 20pt; font-weight: bold; } .p_pass { color: green; font-weight: bold; } .p_fail { color: red; font-weight: bold; } .p_caution { color: #ff6600; font-weight: bold; } .p_help { text-align: center; font-family: helvetica, arial, sans-serif; font-size: 14pt; font-weight: bold; color: #333333; } .environmenttable { font-size: 10pt; border-color: #ffc85f; } table.environmenttable .error { background-color : red; color : inherit; } table.environmenttable .warn { background-color : yellow; } table.environmenttable .ok { background-color : lightgreen; } .header { background-color: #fee6b9; font-size: 10pt; } .cell { background-color: #ffeece; font-size: 10pt; } .error { color: #ff0000; } .errorboxcontent { text-align: center; font-weight: bold; padding: 20px; color: #ff0000; } .invisiblefieldset { display:inline; border:0px; padding:0px; margin:0px; } #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po { display: none; } </style> <?php }
/** * Print a nicely formatted table. * Note: This function is copied from core Moodle and contains modifications by RL * * @param array $table is an object with several properties. * <ul> * <li>$table->head - An array of heading names. * <li>$table->align - An array of column alignments * <li>$table->size - An array of column sizes * <li>$table->wrap - An array of "nowrap"s or nothing * <li>$table->data[] - An array of arrays containing the data. * <li>$table->width - A percentage of the page * <li>$table->tablealign - Align the whole table * <li>$table->class - class attribute to put on the table * <li>$table->id - id attribute to put on the table. * <li>$table->rowclass[] - classes to add to particular rows. * <li>$table->summary - Description of the contents for screen readers. * <li>$table->firstcolumn - If set, only use first column * <li>$table->spanrow - If set, span entire row * <li>$table->headercolumncss - CSS for specific columns in header * <li>$table->columncss - CSS for specific columns in data * </ul> * @param bool $return whether to return an output string or echo now * @return boolean or $string * @todo Finish documenting this function */ function print_table($table, $return=false) { $output = ''; if (isset($table->align)) { foreach ($table->align as $key => $aa) { if ($aa) { $align[$key] = ' text-align:'. fix_align_rtl($aa) .';'; // Fix for RTL languages } else { $align[$key] = ''; } } } if (isset($table->size)) { foreach ($table->size as $key => $ss) { if ($ss) { $size[$key] = ' width:'. $ss .';'; } else { $size[$key] = ''; } } } if (isset($table->wrap)) { foreach ($table->wrap as $key => $ww) { if ($ww) { $wrap[$key] = ''; } else { $wrap[$key] = ' white-space:nowrap;'; } } } if (isset($table->header_wrap)) { foreach ($table->header_wrap as $key => $ww) { if ($ww) { $header_wrap[$key] = ''; } else { $header_wrap[$key] = '; white-space:nowrap;'; } } } if (empty($table->width)) { $table->width = '80%'; } if (empty($table->tablealign)) { $table->tablealign = 'center'; } if (empty($table->class)) { $table->class = ''; //removed generaltable } $tableid = empty($table->id) ? '' : 'id="'.$table->id.'"'; $output .= '<table width="'.$table->width.'" '; if (!empty($table->summary)) { $output .= " summary=\"$table->summary\""; } $output .= " class=\"$table->class boxalign$table->tablealign\" $tableid>\n"; $countcols = 0; // Toggle for whether a column header should be shown $need_columns_header = false; if (!empty($table->head)) { $countcols = count($table->head); $columns_header_output = '<tr class="column_header">'."\n"; $keys=array_keys($table->head); $lastkey = end($keys); foreach ($table->head as $key => $heading) { if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if ($key == $lastkey) { $extraclass = ' lastcol'; } else { $extraclass = ''; } if (!isset($header_wrap[$key])) { $header_wrap[$key] = ''; } $columns_header_output .= '<th style="vertical-align:top;'. $align[$key].$size[$key].$header_wrap[$key] . '" class="c'.$key.$extraclass. ' ' . $table->headercolumncss[$key] . '" scope="col">'. $heading .'</th>'; } $columns_header_output .= '</tr>'."\n"; // Only display column header if no groupings defined if (empty($this->groupings)) { $output .= $columns_header_output; } else { $need_columns_header = true; } } if (!empty($table->data)) { $oddeven = 1; $keys=array_keys($table->data); $lastrowkey = end($keys); // we must locate multiline groupby data $pseudogroupby = $table->pseudogroupby; foreach ($table->data as $key => $row) { //this needs to be row and grouping specific $oddeven = $oddeven ? 0 : 1; if (!isset($table->rowclass[$key])) { $table->rowclass[$key] = ''; } if ($key == $lastrowkey) { $table->rowclass[$key] .= ' lastrow'; } if ($row == 'hr' and $countcols) { $output .= '<tr class="r'.$oddeven.' '.$table->rowclass[$key].'">'."\n"; $output .= '<td colspan="'. $countcols .'"></td>'; } else if (!empty($table->spanrow[$key])) { //reset oddeven $oddeven = 1; $output .= '<tr class="'.$table->rowclass[$key].'">'."\n"; $output .= '<td colspan="'. $countcols .'">' . $row[0] . '</td>'; } else if (!empty($table->firstcolumn[$key])) { //reset oddeven $oddeven = 1; $output .= '<tr class="'.$table->rowclass[$key].'">'."\n"; $output .= '<td colspan="'. $countcols .'">' . $row[0] . '</td>'; $need_columns_header = true; } else { // Handle display of column headers if ($need_columns_header) { $output .= $columns_header_output; $need_columns_header = false; } //check to see if this row is a hidden grouping break if (stripos($table->rowclass[$key], get_string('group_class_id', 'local_elisreports')) !== FALSE) { //reset oddeven $oddeven = 1; $output .= '<tr class="'.$table->rowclass[$key].'">'."\n"; } else //check to see if this row is a hidden summary break if (stripos($table->rowclass[$key], 'summary') !== FALSE) { //reset oddeven $oddeven = 1; $output .= '<tr class="'.$table->rowclass[$key].'">'."\n"; } else { /// it's a normal row of data $output .= '<tr class="r'.$oddeven.' '.$table->rowclass[$key].'">'."\n"; } $keys2=array_keys($row); $lastkey = end($keys2); $i = 0; foreach ($row as $key => $item) { if (in_array($key, $pseudogroupby)) { continue; } if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if (!isset($wrap[$key])) { $wrap[$key] = ''; } if ($key == $lastkey) { $extraclass = ' lastcol'; } else { $extraclass = ''; } //Handle non-numerically indexed data $num_key = array_search($key, array_keys($row)); $output .= '<td style="'. $align[$num_key].$size[$num_key].$wrap[$num_key] .'" class="cell c'.$key.$extraclass. ' ' . $table->columncss[$i] . '">'. $item .'</td>'; $i++; } } $output .= '</tr>'."\n"; } } $output .= '</table>'."\n"; if ($return) { return $output; } echo $output; return true; }
/** * @see moodle_html_component::prepare() * @return void */ public function prepare() { if (!empty($this->align)) { foreach ($this->align as $key => $aa) { if ($aa) { $this->align[$key] = 'text-align:' . fix_align_rtl($aa) . ';'; // Fix for RTL languages } else { $this->align[$key] = ''; } } } if (!empty($this->size)) { foreach ($this->size as $key => $ss) { if ($ss) { $this->size[$key] = 'width:' . $ss . ';'; } else { $this->size[$key] = ''; } } } if (!empty($this->wrap)) { foreach ($this->wrap as $key => $ww) { if ($ww) { $this->wrap[$key] = 'white-space:nowrap;'; } else { $this->wrap[$key] = ''; } } } if (!empty($this->head)) { foreach ($this->head as $key => $val) { if (!isset($this->align[$key])) { $this->align[$key] = ''; } if (!isset($this->size[$key])) { $this->size[$key] = ''; } if (!isset($this->wrap[$key])) { $this->wrap[$key] = ''; } } } if (empty($this->classes)) { // must be done before align $this->set_classes(array('generaltable')); } if (!empty($this->tablealign)) { $this->add_class('boxalign' . $this->tablealign); } if (!empty($this->rotateheaders)) { $this->add_class('rotateheaders'); } else { $this->rotateheaders = false; // Makes life easier later. } parent::prepare(); }
function cr_print_table($table, $return = false) { global $COURSE; $output = ''; if (isset($table->align)) { foreach ($table->align as $key => $aa) { if ($aa) { $align[$key] = ' text-align:' . fix_align_rtl($aa) . ';'; // Fix for RTL languages } else { $align[$key] = ''; } } } if (isset($table->size)) { foreach ($table->size as $key => $ss) { if ($ss) { $size[$key] = ' width:' . $ss . ';'; } else { $size[$key] = ''; } } } if (isset($table->wrap)) { foreach ($table->wrap as $key => $ww) { if ($ww) { $wrap[$key] = ' white-space:nowrap;'; } else { $wrap[$key] = ''; } } } if (empty($table->width)) { $table->width = '80%'; } if (empty($table->tablealign)) { $table->tablealign = 'center'; } if (!isset($table->cellpadding)) { $table->cellpadding = '5'; } if (!isset($table->cellspacing)) { $table->cellspacing = '1'; } if (empty($table->class)) { $table->class = 'generaltable'; } $tableid = empty($table->id) ? '' : 'id="' . $table->id . '"'; $output .= '<form action="send_emails.php" method="post" id="sendemail">'; $output .= '<table width="' . $table->width . '" '; if (!empty($table->summary)) { $output .= " summary=\"$table->summary\""; } $output .= " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"$table->class boxalign$table->tablealign\" $tableid>\n"; $countcols = 0; $isuserid = -1; if (!empty($table->head)) { $countcols = count($table->head); $output .= '<thead><tr>'; $keys = array_keys($table->head); $lastkey = end($keys); foreach ($table->head as $key => $heading) { if ($heading == 'sendemail') { $isuserid = $key; } if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if ($key == $lastkey) { $extraclass = ' lastcol'; } else { $extraclass = ''; } $output .= '<th style="vertical-align:top;' . $align[$key] . $size[$key] . ';white-space:normal;" class="header c' . $key . $extraclass . '" scope="col">' . ucfirst($heading) . '</th>'; } $output .= '</tr></thead>' . "\n"; } if (!empty($table->data)) { $oddeven = 1; $keys = array_keys($table->data); $lastrowkey = end($keys); foreach ($table->data as $key => $row) { $oddeven = $oddeven ? 0 : 1; if (!isset($table->rowclass[$key])) { $table->rowclass[$key] = ''; } if ($key == $lastrowkey) { $table->rowclass[$key] .= ' lastrow'; } $output .= '<tr class="r' . $oddeven . ' ' . $table->rowclass[$key] . '">' . "\n"; if ($row == 'hr' and $countcols) { $output .= '<td colspan="' . $countcols . '"><div class="tabledivider"></div></td>'; } else { /// it's a normal row of data $keys2 = array_keys($row); $lastkey = end($keys2); foreach ($row as $key => $item) { if (!isset($size[$key])) { $size[$key] = ''; } if (!isset($align[$key])) { $align[$key] = ''; } if (!isset($wrap[$key])) { $wrap[$key] = ''; } if ($key == $lastkey) { $extraclass = ' lastcol'; } else { $extraclass = ''; } if ($key == $isuserid) { $output .= '<td style="' . $align[$key] . $size[$key] . $wrap[$key] . '" class="cell c' . $key . $extraclass . '"><input name="userids[]" type="checkbox" value="' . $item . '"></td>'; } else { $output .= '<td style="' . $align[$key] . $size[$key] . $wrap[$key] . '" class="cell c' . $key . $extraclass . '">' . $item . '</td>'; } } } $output .= '</tr>' . "\n"; } } $output .= '</table>' . "\n"; $output .= '<input type="hidden" name="courseid" value="' . $COURSE->id . '">'; if ($isuserid != -1) { $output .= '<input type="submit" value="send emails">'; } $output .= '</form>'; if ($return) { return $output; } echo $output; return true; }