From b40a2b43be3c9b617f3ce7a2f2437bfc54cbc38a Mon Sep 17 00:00:00 2001 From: moquist Date: Thu, 1 Jun 2006 05:51:45 +0000 Subject: [PATCH] Added $return parameters to print_paging_bar() and print_table(). --- lib/weblib.php | 63 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 0a38a7f0bd..7408ee78d2 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2971,10 +2971,12 @@ function print_png($url, $sizex, $sizey, $returnstring, $parameters='alt=""') { *
  • $table->cellpadding - Padding on each cell *
  • $table->cellspacing - Spacing between cells * - * @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) { @@ -3026,14 +3028,14 @@ function print_table($table) { $tableid = empty($table->id) ? '' : 'id="'.$table->id.'"'; - echo 'cellpadding\" cellspacing=\"$table->cellspacing\" class=\"$table->class\" $tableid>\n"; + $output .= '
    cellpadding\" cellspacing=\"$table->cellspacing\" class=\"$table->class\" $tableid>\n"; $countcols = 0; if (!empty($table->head)) { $countcols = count($table->head); - echo ''; + $output .= ''; foreach ($table->head as $key => $heading) { if (!isset($size[$key])) { @@ -3042,18 +3044,18 @@ function print_table($table) { if (!isset($align[$key])) { $align[$key] = ''; } - echo ''; + $output .= ''; } - echo ''."\n"; + $output .= ''."\n"; } if (!empty($table->data)) { $oddeven = 1; foreach ($table->data as $key => $row) { $oddeven = $oddeven ? 0 : 1; - echo ''."\n"; + $output .= ''."\n"; if ($row == 'hr' and $countcols) { - echo ''; + $output .= ''; } else { /// it's a normal row of data foreach ($row as $key => $item) { if (!isset($size[$key])) { @@ -3065,14 +3067,19 @@ function print_table($table) { if (!isset($wrap[$key])) { $wrap[$key] = ''; } - echo ''; + $output .= ''; } } - echo ''."\n"; + $output .= ''."\n"; } } - echo '
    '. $heading .''. $heading .'
    '. $item .''. $item .'
    '."\n"; + $output .= ''."\n"; + if ($return) { + return $output; + } + + echo $output; return true; } @@ -4416,22 +4423,25 @@ function obfuscate_mailto($email, $label='', $dimmed=false) { * @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 '
    '; - echo get_string('page') .':'; + $output .= '
    '; + $output .= get_string('page') .':'; if ($page > 0) { $pagenum = $page - 1; - echo ' ('. get_string('previous') .') '; + $output .= ' ('. get_string('previous') .') '; } $lastpage = ceil($totalcount / $perpage); if ($page > 15) { $startpage = $page - 10; - echo ' 1 ...'; + $output .= ' 1 ...'; } else { $startpage = 0; } @@ -4440,23 +4450,30 @@ function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page while ($displaycount < $maxdisplay and $currpage < $lastpage) { $displaypage = $currpage+1; if ($page == $currpage && empty($nocurr)) { - echo '  '. $displaypage; + $output .= '  '. $displaypage; } else { - echo '  '. $displaypage .''; + $output .= '  '. $displaypage .''; } $displaycount++; $currpage++; } if ($currpage < $lastpage) { $lastpageactual = $lastpage - 1; - echo ' ...'. $lastpage .' '; + $output .= ' ...'. $lastpage .' '; } $pagenum = $page + 1; if ($pagenum != $displaypage) { - echo '  ('. get_string('next') .')'; + $output .= '  ('. get_string('next') .')'; } - echo '
    '; + $output .= '
    '; } + + if ($return) { + return $output; + } + + echo $output; + return true; } /** -- 2.39.5