. defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.'); define('NUM_NONE', '0'); define('NUM_NUMBERS', '1'); define('NUM_BULLETS', '2'); define('NUM_INDENTED', '3'); /* Included from mod/book/view.php and print.php. * * uses: * $chapters - all book chapters * $chapter - may be false * $cm - course module * $book - book * $edit - force editing view * * fills: * $toc * $title (not for print) */ $currtitle = ''; // Active chapter title (plain text). $currsubtitle = ''; // Active subchapter if any. $prevtitle = ' '; $toc = ''; // Representation of toc (HTML). $nch = 0; // Chapter number. $ns = 0; // Subchapter number. $title = ''; $first = 1; if (!isset($print)) { $print = 0; } switch ($book->numbering) { case NUM_NONE: $toc .= '
'; break; case NUM_NUMBERS: $toc .= '
'; break; case NUM_BULLETS: $toc .= '
'; break; case NUM_INDENTED: $toc .= '
'; break; } if ($print) { // TOC for printing. $toc .= ''; if ($book->customtitles) { $toc .= '

'.get_string('toc', 'book').'

'; } else { $toc .= '

'.get_string('toc', 'book').'

'; } $titles = array(); $toc .= '
    '; foreach ($chapters as $ch) { $title = trim(strip_tags($ch->title)); if (!$ch->hidden) { if (!$ch->subchapter) { $nch++; $ns = 0; $toc .= ($first) ? '
  • ' : '
  • '; if ($book->numbering == NUM_NUMBERS) { $title = "$nch $title"; } } else { $ns++; $toc .= ($first) ? '
    • ' : '
    • '; if ($book->numbering == NUM_NUMBERS) { $title = "$nch.$ns $title"; } } $titles[$ch->id] = $title; $toc .= ''.$title.''; $toc .= (!$ch->subchapter) ? '
        ' : ''; $first = 0; } } $toc .= '
    '; } else { // Normal students view. $toc .= '
      '; foreach ($chapters as $ch) { $title = trim(strip_tags($ch->title)); if (!$ch->hidden) { if (!$ch->subchapter) { $nch++; $ns = 0; $toc .= ($first) ? '
    • ' : '
  • '; if ($book->numbering == NUM_NUMBERS) { $title = "$nch $title"; } $prevtitle = $title; } else { $ns++; $toc .= ($first) ? '
    • ' : '
    • '; if ($book->numbering == NUM_NUMBERS) { $title = "$nch.$ns $title"; } } if ($ch->id == $chapter->id) { $toc .= ''.$title.''; if ($ch->subchapter) { $currtitle = $prevtitle; $currsubtitle = $title; } else { $currtitle = $title; $currsubtitle = ' '; } } else { if (array_key_exists( $ch->id, $okchapters)) { $toc .= ''.$title.''; } else { $toc .= htmlspecialchars($title); } } $toc .= (!$ch->subchapter) ? '
        ' : ''; $first = 0; } } $toc .= '
    '; } $toc .= '
  • '; $toc = str_replace('
      ', '', $toc); // Cleanup of invalid structures.