. /** * Table of contents. * * @package mod_game * @copyright 2007 Vasilis Daloukas * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); define('NUM_NONE', '0'); define('NUM_NUMBERS', '1'); define('NUM_BULLETS', '2'); define('NUM_INDENTED', '3'); $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.