* <li>$table->cellpadding - Padding on each cell
* <li>$table->cellspacing - Spacing between cells
* </ul>
- * @return boolean
+ * @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) {
+function print_table($table, $return=false) {
+ $output = '';
if (isset($table->align)) {
foreach ($table->align as $key => $aa) {
$tableid = empty($table->id) ? '' : 'id="'.$table->id.'"';
- echo '<table width="'.$table->width.'" border="0" align="'.$table->tablealign.'" ';
- echo " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"$table->class\" $tableid>\n";
+ $output .= '<table width="'.$table->width.'" border="0" align="'.$table->tablealign.'" ';
+ $output .= " cellpadding=\"$table->cellpadding\" cellspacing=\"$table->cellspacing\" class=\"$table->class\" $tableid>\n";
$countcols = 0;
if (!empty($table->head)) {
$countcols = count($table->head);
- echo '<tr>';
+ $output .= '<tr>';
foreach ($table->head as $key => $heading) {
if (!isset($size[$key])) {
if (!isset($align[$key])) {
$align[$key] = '';
}
- echo '<th valign="top" '. $align[$key].$size[$key] .' nowrap="nowrap" class="header c'.$key.'">'. $heading .'</th>';
+ $output .= '<th valign="top" '. $align[$key].$size[$key] .' nowrap="nowrap" class="header c'.$key.'">'. $heading .'</th>';
}
- echo '</tr>'."\n";
+ $output .= '</tr>'."\n";
}
if (!empty($table->data)) {
$oddeven = 1;
foreach ($table->data as $key => $row) {
$oddeven = $oddeven ? 0 : 1;
- echo '<tr class="r'.$oddeven.'">'."\n";
+ $output .= '<tr class="r'.$oddeven.'">'."\n";
if ($row == 'hr' and $countcols) {
- echo '<td colspan="'. $countcols .'"><div class="tabledivider"></div></td>';
+ $output .= '<td colspan="'. $countcols .'"><div class="tabledivider"></div></td>';
} else { /// it's a normal row of data
foreach ($row as $key => $item) {
if (!isset($size[$key])) {
if (!isset($wrap[$key])) {
$wrap[$key] = '';
}
- echo '<td '. $align[$key].$size[$key].$wrap[$key] .' class="cell c'.$key.'">'. $item .'</td>';
+ $output .= '<td '. $align[$key].$size[$key].$wrap[$key] .' class="cell c'.$key.'">'. $item .'</td>';
}
}
- echo '</tr>'."\n";
+ $output .= '</tr>'."\n";
}
}
- echo '</table>'."\n";
+ $output .= '</table>'."\n";
+ if ($return) {
+ return $output;
+ }
+
+ echo $output;
return true;
}
* @param string $baseurl The url which will be used to create page numbered links. Each page will consist of the base url appended by the page
var an equal sign, then the page number.
* @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
+ * @param bool $nocurr do not display the current page as a link
+ * @param bool $return whether to return an output string or echo now
+ * @return bool or string
*/
-function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false) {
-
+function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
$maxdisplay = 18;
+ $output = '';
if ($totalcount > $perpage) {
- echo '<div class="paging">';
- echo get_string('page') .':';
+ $output .= '<div class="paging">';
+ $output .= get_string('page') .':';
if ($page > 0) {
$pagenum = $page - 1;
- echo ' (<a href="'. $baseurl . $pagevar .'='. $pagenum .'">'. get_string('previous') .'</a>) ';
+ $output .= ' (<a href="'. $baseurl . $pagevar .'='. $pagenum .'">'. get_string('previous') .'</a>) ';
}
$lastpage = ceil($totalcount / $perpage);
if ($page > 15) {
$startpage = $page - 10;
- echo ' <a href="'. $baseurl . $pagevar .'=0">1</a> ...';
+ $output .= ' <a href="'. $baseurl . $pagevar .'=0">1</a> ...';
} else {
$startpage = 0;
}
while ($displaycount < $maxdisplay and $currpage < $lastpage) {
$displaypage = $currpage+1;
if ($page == $currpage && empty($nocurr)) {
- echo ' '. $displaypage;
+ $output .= ' '. $displaypage;
} else {
- echo ' <a href="'. $baseurl . $pagevar .'='. $currpage .'">'. $displaypage .'</a>';
+ $output .= ' <a href="'. $baseurl . $pagevar .'='. $currpage .'">'. $displaypage .'</a>';
}
$displaycount++;
$currpage++;
}
if ($currpage < $lastpage) {
$lastpageactual = $lastpage - 1;
- echo ' ...<a href="'. $baseurl . $pagevar .'='. $lastpageactual .'">'. $lastpage .'</a> ';
+ $output .= ' ...<a href="'. $baseurl . $pagevar .'='. $lastpageactual .'">'. $lastpage .'</a> ';
}
$pagenum = $page + 1;
if ($pagenum != $displaypage) {
- echo ' (<a href="'. $baseurl . $pagevar .'='. $pagenum .'">'. get_string('next') .'</a>)';
+ $output .= ' (<a href="'. $baseurl . $pagevar .'='. $pagenum .'">'. get_string('next') .'</a>)';
}
- echo '</div>';
+ $output .= '</div>';
}
+
+ if ($return) {
+ return $output;
+ }
+
+ echo $output;
+ return true;
}
/**