diff -Naur book/db/install.xml mod/book/db/install.xml
--- mod/book/db/install.xml	2013-03-29 11:30:51.714883500 +0000
+++ mod/book/db/install.xml	2012-11-26 08:50:17.000000000 +0000
@@ -11,8 +11,9 @@
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="course" NEXT="intro"/>
         <FIELD NAME="intro" TYPE="text" NOTNULL="false" SEQUENCE="false" PREVIOUS="name" NEXT="introformat"/>
         <FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="intro" NEXT="numbering"/>
-        <FIELD NAME="numbering" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="introformat" NEXT="customtitles"/>
-        <FIELD NAME="customtitles" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="numbering" NEXT="revision"/>
+        <FIELD NAME="numbering" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="introformat" NEXT="linkstyle"/>
+        <FIELD NAME="linkstyle" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="numbering" NEXT="customtitles"/>
+        <FIELD NAME="customtitles" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="linkstyle" NEXT="revision"/>
         <FIELD NAME="revision" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="customtitles" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="revision" NEXT="timemodified"/>
         <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
diff -Naur book/db/upgrade.php mod/book/db/upgrade.php
--- mod/book/db/upgrade.php	2013-03-29 11:30:51.778883600 +0000
+++ mod/book/db/upgrade.php	2013-03-29 13:33:01.947735400 +0000
@@ -72,7 +72,7 @@
         if (!$dbman->field_exists($table, $field)) {
             $dbman->add_field($table, $field);
             // Conditionally migrate to html format in intro
-            // Si está activo el htmleditor!!!!!
+            // Si est� activo el htmleditor!!!!!
             if ($CFG->texteditors !== 'textarea') {
                 $rs = $DB->get_recordset('book', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
                 foreach ($rs as $b) {
@@ -186,6 +186,18 @@
         upgrade_mod_savepoint(true, 2012061710, 'book');
     }
     // End of MDL-35297 "replayed" steps.
+    if ($oldversion < 2012112301) {
+        $table = new xmldb_table('book');
+        $field = new xmldb_field('linkstyle', XMLDB_TYPE_INTEGER, '4' , XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
+
+        // Conditionally launch add field approvaldisplayformat
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012112301, 'book');
+    }
 
     return true;
 }
diff -Naur book/db/upgrade.php.bak mod/book/db/upgrade.php.bak
--- mod/book/db/upgrade.php.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/db/upgrade.php.bak	2013-03-29 13:32:47.701724000 +0000
@@ -0,0 +1,203 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * Book module upgrade code
+ *
+ * @package    mod_book
+ * @copyright  2009-2011 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+/**
+ * Book module upgrade task
+ *
+ * @param int $oldversion the version we are upgrading from
+ * @return bool always true
+ */
+function xmldb_book_upgrade($oldversion) {
+    global $CFG, $DB;
+
+    $dbman = $DB->get_manager();
+
+    // Moodle v2.2.0 release upgrade line
+    // Put any upgrade step following this
+
+    // Moodle v2.3.0 release upgrade line
+    // Put any upgrade step following this
+
+    // Note: The next steps (up to 2012061710 included, are a "replay" of old upgrade steps,
+    // because some sites updated to Moodle 2.3 didn't have the latest contrib mod_book
+    // installed, so some required changes were missing.
+    //
+    // All the steps are run conditionally so sites upgraded from latest contrib mod_book or
+    // new (2.3 and upwards) sites won't get affected.
+    //
+    // See MDL-35297 and commit msg for more information.
+
+    if ($oldversion < 2012061703) {
+        // Rename field summary on table book to intro
+        $table = new xmldb_table('book');
+        $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, null, null, null, null, null, 'name');
+
+        // Launch rename field summary
+        if ($dbman->field_exists($table, $field)) {
+            $dbman->rename_field($table, $field, 'intro');
+        }
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012061703, 'book');
+    }
+
+    if ($oldversion < 2012061704) {
+        // Define field introformat to be added to book
+        $table = new xmldb_table('book');
+        $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'intro');
+
+        // Launch add field introformat
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+            // Conditionally migrate to html format in intro
+            // Si est� activo el htmleditor!!!!!
+            if ($CFG->texteditors !== 'textarea') {
+                $rs = $DB->get_recordset('book', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
+                foreach ($rs as $b) {
+                    $b->intro       = text_to_html($b->intro, false, false, true);
+                    $b->introformat = FORMAT_HTML;
+                    $DB->update_record('book', $b);
+                    upgrade_set_timeout();
+                }
+                unset($b);
+                $rs->close();
+            }
+        }
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012061704, 'book');
+    }
+
+    if ($oldversion < 2012061705) {
+        // Define field introformat to be added to book
+        $table = new xmldb_table('book_chapters');
+        $field = new xmldb_field('contentformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'content');
+
+        // Launch add field introformat
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+
+            $DB->set_field('book_chapters', 'contentformat', FORMAT_HTML, array());
+        }
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012061705, 'book');
+    }
+
+    if ($oldversion < 2012061706) {
+        require_once("$CFG->dirroot/mod/book/db/upgradelib.php");
+
+        $sqlfrom = "FROM {book} b
+                    JOIN {modules} m ON m.name = 'book'
+                    JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = b.id)";
+
+        $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
+
+        if ($rs = $DB->get_recordset_sql("SELECT b.id, b.course, cm.id AS cmid $sqlfrom ORDER BY b.course, b.id")) {
+
+            $pbar = new progress_bar('migratebookfiles', 500, true);
+
+            $i = 0;
+            foreach ($rs as $book) {
+                $i++;
+                upgrade_set_timeout(360); // set up timeout, may also abort execution
+                $pbar->update($i, $count, "Migrating book files - $i/$count.");
+
+                $context = context_module::instance($book->cmid);
+
+                mod_book_migrate_moddata_dir_to_legacy($book, $context, '/');
+
+                // remove dirs if empty
+                @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/book/$book->id/");
+                @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/book/");
+                @rmdir("$CFG->dataroot/$book->course/$CFG->moddata/");
+                @rmdir("$CFG->dataroot/$book->course/");
+            }
+            $rs->close();
+        }
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012061706, 'book');
+    }
+
+    if ($oldversion < 2012061707) {
+        // Define field disableprinting to be dropped from book
+        $table = new xmldb_table('book');
+        $field = new xmldb_field('disableprinting');
+
+        // Conditionally launch drop field disableprinting
+        if ($dbman->field_exists($table, $field)) {
+            $dbman->drop_field($table, $field);
+        }
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012061707, 'book');
+    }
+
+    if ($oldversion < 2012061708) {
+        unset_config('book_tocwidth');
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012061708, 'book');
+    }
+
+    if ($oldversion < 2012061709) {
+        require_once("$CFG->dirroot/mod/book/db/upgradelib.php");
+
+        mod_book_migrate_all_areas();
+
+        upgrade_mod_savepoint(true, 2012061709, 'book');
+    }
+
+    if ($oldversion < 2012061710) {
+
+        // Define field revision to be added to book
+        $table = new xmldb_table('book');
+        $field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'customtitles');
+
+        // Conditionally launch add field revision
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012061710, 'book');
+    }
+    // End of MDL-35297 "replayed" steps.
+    if ($oldversion < 2012112301) {
+        $table = new xmldb_table('book');
+        $field = new xmldb_field('linkstyle', XMLDB_TYPE_INTEGER, '4' , XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
+
+        // Conditionally launch add field approvaldisplayformat
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+        // book savepoint reached
+        upgrade_mod_savepoint(true, 2012112301, 'book');
+    }
+
+    return true;
+}
diff -Naur book/lang/en/book.php mod/book/lang/en/book.php
--- mod/book/lang/en/book.php	2013-03-29 11:30:51.512883300 +0000
+++ mod/book/lang/en/book.php	2013-03-29 13:33:18.759748900 +0000
@@ -59,6 +59,15 @@
 $string['numbering3'] = 'Indented';
 $string['numberingoptions'] = 'Available options for chapter formatting';
 $string['numberingoptions_desc'] = 'Options for displaying chapters and subchapters in the table of contents';
+
+$string['linkstyle'] = 'Style of navigation';
+$string['linkstyle_help'] = '* Images - Icons are used for navigation
+* Text - Chapter titles are used for navigation';
+$string['linkstyle0'] = 'Images';
+$string['linkstyle1'] = 'Text';
+$string['linkstyle2'] = 'TOC Only';
+$string['linkoptions'] ='Available options for navigational links';
+$string['linkoptions_desc'] = 'Options for displaying navigation on the book pages';
 $string['addafter'] = 'Add new chapter';
 $string['confchapterdelete'] = 'Do you really want to delete this chapter?';
 $string['confchapterdeleteall'] = 'Do you really want to delete this chapter and all its subchapters?';
diff -Naur book/lang/en/book.php.bak mod/book/lang/en/book.php.bak
--- mod/book/lang/en/book.php.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/lang/en/book.php.bak	2013-03-29 13:14:58.598868800 +0000
@@ -0,0 +1,86 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Book module language strings
+ *
+ * @package    mod_book
+ * @copyright  2004-2012 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+$string['modulename'] = 'Book';
+$string['modulename_help'] = 'The book module enables a teacher to create a multi-page resource in a book-like format, with chapters and subchapters. Books can contain media files as well as text and are useful for displaying lengthy passages of information which can be broken down into sections.
+
+A book may be used
+
+* To display reading material for individual modules of study
+* As a staff departmental handbook
+* As a showcase portfolio of student work';
+$string['modulename_link'] = 'mod/book/view';
+$string['modulenameplural'] = 'Books';
+$string['pluginname'] = 'Book';
+$string['pluginadministration'] = 'Book administration';
+
+$string['toc'] = 'Table of contents';
+$string['customtitles'] = 'Custom titles';
+$string['customtitles_help'] = 'Normally the chapter title is displayed in the table of contents (TOC) AND as a heading above the content.
+
+If the custom titles checkbox is ticked, the chapter title is NOT displayed as a heading above the content. A different title (perhaps longer than the chapter title) may be entered as part of the content.';
+$string['chapters'] = 'Chapters';
+$string['editingchapter'] = 'Editing chapter';
+$string['chaptertitle'] = 'Chapter title';
+$string['content'] = 'Content';
+$string['subchapter'] = 'Subchapter';
+$string['numbering'] = 'Chapter formatting';
+$string['numbering_help'] = '* None - Chapter and subchapter titles have no formatting
+* Numbers - Chapters and subchapter titles are numbered 1, 1.1, 1.2, 2, ...
+* Bullets - Subchapters are indented and displayed with bullets in the table of contents
+* Indented - Subchapters are indented in the table of contents';
+$string['numbering0'] = 'None';
+$string['numbering1'] = 'Numbers';
+$string['numbering2'] = 'Bullets';
+$string['numbering3'] = 'Indented';
+$string['numberingoptions'] = 'Available options for chapter formatting';
+$string['numberingoptions_desc'] = 'Options for displaying chapters and subchapters in the table of contents';
+
+$string['linkstyle'] = 'Style of navigation';
+$string['linkstyle_help'] = '* Images - Icons are used for navigation
+* Text - Chapter titles are used for navigation';
+$string['linkstyle0'] = 'Images';
+$string['linkstyle1'] = 'Text';
+$string['linkstyle2'] = 'TOC Only';
+$string['linkoptions'] ='Available options for navigational links';
+$string['linkoptions_desc'] = 'Options for displaying navigation on the book pages';
+$string['addafter'] = 'Add new chapter';
+$string['confchapterdelete'] = 'Do you really want to delete this chapter?';
+$string['confchapterdeleteall'] = 'Do you really want to delete this chapter and all its subchapters?';
+$string['top'] = 'top';
+$string['navprev'] = 'Previous';
+$string['navnext'] = 'Next';
+$string['navexit'] = 'Exit book';
+$string['book:addinstance'] = 'Add a new book';
+$string['book:read'] = 'Read book';
+$string['book:edit'] = 'Edit book chapters';
+$string['book:viewhiddenchapters'] = 'View hidden book chapters';
+$string['errorchapter'] = 'Error reading chapter of book.';
+
+$string['page-mod-book-x'] = 'Any book module page';
+$string['subchapternotice'] = '(Only available once the first chapter has been created)';
+$string['subplugintype_booktool'] = 'Book tool';
+$string['subplugintype_booktool_plural'] = 'Book tools';
diff -Naur book/lib.php mod/book/lib.php
--- mod/book/lib.php	2013-03-29 11:30:51.036883000 +0000
+++ mod/book/lib.php	2013-03-29 13:14:38.914853000 +0000
@@ -41,6 +41,18 @@
     );
 }
 
+function book_get_link_types() {
+    global $CFG; // required for the include
+
+    require_once(dirname(__FILE__).'/locallib.php');
+
+    return array (
+        BOOK_LINK_IMAGE     => get_string('linkstyle0', 'mod_book'),
+        BOOK_LINK_TEXT      => get_string('linkstyle1', 'mod_book'),
+        BOOK_LINK_TOCONLY   => get_string('linkstyle2', 'mod_book'),
+    );
+}
+
 /**
  * Returns all other caps used in module
  * @return array
diff -Naur book/locallib.php mod/book/locallib.php
--- mod/book/locallib.php	2013-03-29 11:30:50.887882800 +0000
+++ mod/book/locallib.php	2013-03-29 13:36:48.020916300 +0000
@@ -39,6 +39,9 @@
 define('BOOK_NUM_BULLETS',  '2');
 define('BOOK_NUM_INDENTED', '3');
 
+define ('BOOK_LINK_IMAGE', '0');
+define ('BOOK_LINK_TEXT', '1');
+define ('BOOK_LINK_TOCONLY', '2');
 /**
  * Preload book chapters and fix toc structure if necessary.
  *
diff -Naur book/locallib.php.bak mod/book/locallib.php.bak
--- mod/book/locallib.php.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/locallib.php.bak	2013-03-29 13:20:17.206123600 +0000
@@ -0,0 +1,473 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Book module local lib functions
+ *
+ * @package    mod_book
+ * @copyright  2010-2011 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+require_once(dirname(__FILE__).'/lib.php');
+require_once($CFG->libdir.'/filelib.php');
+
+/**
+ * The following defines are used to define how the chapters and subchapters of a book should be displayed in that table of contents.
+ * BOOK_NUM_NONE        No special styling will applied and the editor will be able to do what ever thay want in the title
+ * BOOK_NUM_NUMBERS     Chapters and subchapters are numbered (1, 1.1, 1.2, 2, ...)
+ * BOOK_NUM_BULLETS     Subchapters are indented and displayed with bullets
+ * BOOK_NUM_INDENTED    Subchapters are indented
+ */
+define('BOOK_NUM_NONE',     '0');
+define('BOOK_NUM_NUMBERS',  '1');
+define('BOOK_NUM_BULLETS',  '2');
+define('BOOK_NUM_INDENTED', '3');
+
+define ('BOOK_LINK_IMAGE', '0');
+define ('BOOK_LINK_TEXT', '1');
+define ('BOOK_LINK_TOCONLY', '2');
+/**
+ * Preload book chapters and fix toc structure if necessary.
+ *
+ * Returns array of chapters with standard 'pagenum', 'id, pagenum, subchapter, title, hidden'
+ * and extra 'parent, number, subchapters, prev, next'.
+ * Please note the content/text of chapters is not included.
+ *
+ * @param  stdClass $book
+ * @return array of id=>chapter
+ */
+function book_preload_chapters($book) {
+    global $DB;
+    $chapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum', 'id, pagenum, subchapter, title, hidden');
+    if (!$chapters) {
+        return array();
+    }
+
+    $prev = null;
+    $prevsub = null;
+
+    $first = true;
+    $hidesub = true;
+    $parent = null;
+    $pagenum = 0; // chapter sort
+    $i = 0;       // main chapter num
+    $j = 0;       // subchapter num
+    foreach ($chapters as $id => $ch) {
+        $oldch = clone($ch);
+        $pagenum++;
+        $ch->pagenum = $pagenum;
+        if ($first) {
+            // book can not start with a subchapter
+            $ch->subchapter = 0;
+            $first = false;
+        }
+        if (!$ch->subchapter) {
+            if ($ch->hidden) {
+                if ($book->numbering == BOOK_NUM_NUMBERS) {
+                    $ch->number = 'x';
+                } else {
+                    $ch->number = null;
+                }
+            } else {
+                $i++;
+                $ch->number = $i;
+            }
+            $j = 0;
+            $prevsub = null;
+            $hidesub = $ch->hidden;
+            $parent = $ch->id;
+            $ch->parent = null;
+            $ch->subchapters = array();
+        } else {
+            $ch->parent = $parent;
+            $ch->subchapters = null;
+            $chapters[$parent]->subchapters[$ch->id] = $ch->id;
+            if ($hidesub) {
+                // all subchapters in hidden chapter must be hidden too
+                $ch->hidden = 1;
+            }
+            if ($ch->hidden) {
+                if ($book->numbering == BOOK_NUM_NUMBERS) {
+                    $ch->number = 'x';
+                } else {
+                    $ch->number = null;
+                }
+            } else {
+                $j++;
+                $ch->number = $j;
+            }
+        }
+
+        if ($oldch->subchapter != $ch->subchapter or $oldch->pagenum != $ch->pagenum or $oldch->hidden != $ch->hidden) {
+            // update only if something changed
+            $DB->update_record('book_chapters', $ch);
+        }
+        $chapters[$id] = $ch;
+    }
+
+    return $chapters;
+}
+
+/**
+ * Returns the title for a given chapter
+ *
+ * @param int $chid
+ * @param array $chapters
+ * @param stdClass $book
+ * @param context_module $context
+ * @return string
+ */
+function book_get_chapter_title($chid, $chapters, $book, $context) {
+    $ch = $chapters[$chid];
+    $title = trim(format_string($ch->title, true, array('context'=>$context)));
+    $numbers = array();
+    if ($book->numbering == BOOK_NUM_NUMBERS) {
+        if ($ch->parent and $chapters[$ch->parent]->number) {
+            $numbers[] = $chapters[$ch->parent]->number;
+        }
+        if ($ch->number) {
+            $numbers[] = $ch->number;
+        }
+    }
+
+    if ($numbers) {
+        $title = implode('.', $numbers).' '.$title;
+    }
+
+    return $title;
+}
+
+/**
+ * Add the book TOC sticky block to the 1st region available
+ *
+ * @param array $chapters
+ * @param stdClass $chapter
+ * @param stdClass $book
+ * @param stdClass $cm
+ * @param bool $edit
+ */
+function book_add_fake_block($chapters, $chapter, $book, $cm, $edit) {
+    global $OUTPUT, $PAGE;
+
+    $toc = book_get_toc($chapters, $chapter, $book, $cm, $edit, 0);
+
+    $bc = new block_contents();
+    $bc->title = get_string('toc', 'mod_book');
+    $bc->attributes['class'] = 'block';
+    $bc->content = $toc;
+
+    $regions = $PAGE->blocks->get_regions();
+    $firstregion = reset($regions);
+    $PAGE->blocks->add_fake_block($bc, $firstregion);
+}
+
+/**
+ * Generate toc structure
+ *
+ * @param array $chapters
+ * @param stdClass $chapter
+ * @param stdClass $book
+ * @param stdClass $cm
+ * @param bool $edit
+ * @return string
+ */
+function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
+    global $USER, $OUTPUT;
+
+    $toc = '';
+    $nch = 0;   // Chapter number
+    $ns = 0;    // Subchapter number
+    $first = 1;
+
+    $context = context_module::instance($cm->id);
+
+    switch ($book->numbering) {
+        case BOOK_NUM_NONE:
+            $toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
+            break;
+        case BOOK_NUM_NUMBERS:
+            $toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
+            break;
+        case BOOK_NUM_BULLETS:
+            $toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
+            break;
+        case BOOK_NUM_INDENTED:
+            $toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
+            break;
+    }
+
+    if ($edit) { // Teacher's TOC
+        $toc .= html_writer::start_tag('ul');
+        $i = 0;
+        foreach ($chapters as $ch) {
+            $i++;
+            $title = trim(format_string($ch->title, true, array('context'=>$context)));
+            if (!$ch->subchapter) {
+
+                if ($first) {
+                    $toc .= html_writer::start_tag('li');
+                } else {
+                    $toc .= html_writer::end_tag('ul');
+                    $toc .= html_writer::end_tag('li');
+                    $toc .= html_writer::start_tag('li');
+                }
+
+                if (!$ch->hidden) {
+                    $nch++;
+                    $ns = 0;
+                    if ($book->numbering == BOOK_NUM_NUMBERS) {
+                        $title = "$nch $title";
+                    }
+                } else {
+                    if ($book->numbering == BOOK_NUM_NUMBERS) {
+                        $title = "x $title";
+                    }
+                    $title = html_writer::tag('span', $title, array('class' => 'dimmed_text'));
+                }
+            } else {
+
+                if ($first) {
+                    $toc .= html_writer::start_tag('li');
+                    $toc .= html_writer::start_tag('ul');
+                    $toc .= html_writer::start_tag('li');
+                } else {
+                    $toc .= html_writer::start_tag('li');
+                }
+
+                if (!$ch->hidden) {
+                    $ns++;
+                    if ($book->numbering == BOOK_NUM_NUMBERS) {
+                        $title = "$nch.$ns $title";
+                    }
+                } else {
+                    if ($book->numbering == BOOK_NUM_NUMBERS) {
+                        if (empty($chapters[$ch->parent]->hidden)) {
+                            $title = "$nch.x $title";
+                        } else {
+                            $title = "x.x $title";
+                        }
+                    }
+                    $title = html_writer::tag('span', $title, array('class' => 'dimmed_text'));
+                }
+            }
+
+            if ($ch->id == $chapter->id) {
+                $toc .= html_writer::tag('strong', $title);
+            } else {
+                $toc .= html_writer::link(new moodle_url('view.php', array('id' => $cm->id, 'chapterid' => $ch->id)), $title, array('title' => s($title)));
+            }
+            $toc .=  '&nbsp;&nbsp;';
+            if ($i != 1) {
+                $toc .= html_writer::link(new moodle_url('move.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'up' => '1', 'sesskey' => $USER->sesskey)),
+                                            $OUTPUT->pix_icon('t/up', get_string('up')), array('title' => get_string('up')));
+            }
+            if ($i != count($chapters)) {
+                $toc .= html_writer::link(new moodle_url('move.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'up' => '0', 'sesskey' => $USER->sesskey)),
+                                            $OUTPUT->pix_icon('t/down', get_string('down')), array('title' => get_string('down')));
+            }
+            $toc .= html_writer::link(new moodle_url('edit.php', array('cmid' => $cm->id, 'id' => $ch->id)),
+                                        $OUTPUT->pix_icon('t/edit', get_string('edit')), array('title' => get_string('edit')));
+            $toc .= html_writer::link(new moodle_url('delete.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'sesskey' => $USER->sesskey)),
+                                        $OUTPUT->pix_icon('t/delete', get_string('delete')), array('title' => get_string('delete')));
+            if ($ch->hidden) {
+                $toc .= html_writer::link(new moodle_url('show.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'sesskey' => $USER->sesskey)),
+                                            $OUTPUT->pix_icon('t/show', get_string('show')), array('title' => get_string('show')));
+            } else {
+                $toc .= html_writer::link(new moodle_url('show.php', array('id' => $cm->id, 'chapterid' => $ch->id, 'sesskey' => $USER->sesskey)),
+                                            $OUTPUT->pix_icon('t/hide', get_string('hide')), array('title' => get_string('hide')));
+            }
+            $toc .= html_writer::link(new moodle_url('edit.php', array('cmid' => $cm->id, 'pagenum' => $ch->pagenum, 'subchapter' => $ch->subchapter)),
+                                            $OUTPUT->pix_icon('add', get_string('addafter', 'mod_book'), 'mod_book'), array('title' => get_string('addafter', 'mod_book')));
+
+
+            if (!$ch->subchapter) {
+                $toc .= html_writer::start_tag('ul');
+            } else {
+                $toc .= html_writer::end_tag('li');
+            }
+            $first = 0;
+        }
+
+        $toc .= html_writer::end_tag('ul');
+        $toc .= html_writer::end_tag('li');
+        $toc .= html_writer::end_tag('ul');
+
+    } else { // Normal students view
+        $toc .= html_writer::start_tag('ul');
+        foreach ($chapters as $ch) {
+            $title = trim(format_string($ch->title, true, array('context'=>$context)));
+            if (!$ch->hidden) {
+                if (!$ch->subchapter) {
+                    $nch++;
+                    $ns = 0;
+
+                    if ($first) {
+                        $toc .= html_writer::start_tag('li');
+                    } else {
+                        $toc .= html_writer::end_tag('ul');
+                        $toc .= html_writer::end_tag('li');
+                        $toc .= html_writer::start_tag('li');
+                    }
+
+                    if ($book->numbering == BOOK_NUM_NUMBERS) {
+                          $title = "$nch $title";
+                    }
+                } else {
+                    $ns++;
+
+                    if ($first) {
+                        $toc .= html_writer::start_tag('li');
+                        $toc .= html_writer::start_tag('ul');
+                        $toc .= html_writer::start_tag('li');
+                    } else {
+                        $toc .= html_writer::start_tag('li');
+                    }
+
+                    if ($book->numbering == BOOK_NUM_NUMBERS) {
+                          $title = "$nch.$ns $title";
+                    }
+                }
+                if ($ch->id == $chapter->id) {
+                    $toc .= html_writer::tag('strong', $title);
+                } else {
+                    $toc .= html_writer::link(new moodle_url('view.php', array('id' => $cm->id, 'chapterid' => $ch->id)), $title, array('title' => s($title)));
+                }
+
+                if (!$ch->subchapter) {
+                    $toc .= html_writer::start_tag('ul');
+                } else {
+                    $toc .= html_writer::end_tag('li');
+                }
+
+                $first = 0;
+            }
+        }
+
+        $toc .= html_writer::end_tag('ul');
+        $toc .= html_writer::end_tag('li');
+        $toc .= html_writer::end_tag('ul');
+
+    }
+
+    $toc .= html_writer::end_tag('div');
+
+    $toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
+
+    return $toc;
+}
+
+
+/**
+ * File browsing support class
+ *
+ * @copyright  2010-2011 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class book_file_info extends file_info {
+    /** @var stdClass Course object */
+    protected $course;
+    /** @var stdClass Course module object */
+    protected $cm;
+    /** @var array Available file areas */
+    protected $areas;
+    /** @var string File area to browse */
+    protected $filearea;
+
+    /**
+     * Constructor
+     *
+     * @param file_browser $browser file_browser instance
+     * @param stdClass $course course object
+     * @param stdClass $cm course module object
+     * @param stdClass $context module context
+     * @param array $areas available file areas
+     * @param string $filearea file area to browse
+     */
+    public function __construct($browser, $course, $cm, $context, $areas, $filearea) {
+        parent::__construct($browser, $context);
+        $this->course   = $course;
+        $this->cm       = $cm;
+        $this->areas    = $areas;
+        $this->filearea = $filearea;
+    }
+
+    /**
+     * Returns list of standard virtual file/directory identification.
+     * The difference from stored_file parameters is that null values
+     * are allowed in all fields
+     * @return array with keys contextid, filearea, itemid, filepath and filename
+     */
+    public function get_params() {
+        return array('contextid'=>$this->context->id,
+                     'component'=>'mod_book',
+                     'filearea' =>$this->filearea,
+                     'itemid'   =>null,
+                     'filepath' =>null,
+                     'filename' =>null);
+    }
+
+    /**
+     * Returns localised visible name.
+     * @return string
+     */
+    public function get_visible_name() {
+        return $this->areas[$this->filearea];
+    }
+
+    /**
+     * Can I add new files or directories?
+     * @return bool
+     */
+    public function is_writable() {
+        return false;
+    }
+
+    /**
+     * Is directory?
+     * @return bool
+     */
+    public function is_directory() {
+        return true;
+    }
+
+    /**
+     * Returns list of children.
+     * @return array of file_info instances
+     */
+    public function get_children() {
+        global $DB;
+
+        $children = array();
+        $chapters = $DB->get_records('book_chapters', array('bookid'=>$this->cm->instance), 'pagenum', 'id, pagenum');
+        foreach ($chapters as $itemid => $unused) {
+            if ($child = $this->browser->get_file_info($this->context, 'mod_book', $this->filearea, $itemid)) {
+                $children[] = $child;
+            }
+        }
+        return $children;
+    }
+
+    /**
+     * Returns parent file_info instance
+     * @return file_info or null for root
+     */
+    public function get_parent() {
+        return $this->browser->get_file_info($this->context);
+    }
+}
diff -Naur book/mod_form.php mod/book/mod_form.php
--- mod/book/mod_form.php	2013-03-29 11:30:50.990882900 +0000
+++ mod/book/mod_form.php	2012-11-26 08:50:17.000000000 +0000
@@ -66,6 +66,26 @@
         $mform->addHelpButton('numbering', 'numbering', 'mod_book');
         $mform->setDefault('numbering', $config->numbering);
 
+
+        $alloptions2 = book_get_link_types();
+        $allowed2 = explode(',', $config->linkoptions);
+        $options2 = array();
+        foreach ($allowed2 as $type) {
+            if (isset($alloptions2[$type])) {
+                $options2[$type] = $alloptions2[$type];
+            }
+        }
+        if ($this->current->instance) {
+            if (!isset($options2[$this->current->linkstyle])) {
+                if (isset($alloptions2[$this->current->linkstyle])) {
+                    $options2[$this->current->linkstyle] = $alloptions2[$this->current->linkstyle];
+                }
+            }
+        }
+        $mform->addElement('select', 'linkstyle', get_string('linkstyle', 'book'), $options2);
+        $mform->addHelpButton('linkstyle', 'linkstyle', 'mod_book');
+        $mform->setDefault('linkstyle', $config->linkstyle);
+
         $mform->addElement('checkbox', 'customtitles', get_string('customtitles', 'book'));
         $mform->addHelpButton('customtitles', 'customtitles', 'mod_book');
         $mform->setDefault('customtitles', 0);
diff -Naur book/README.md mod/book/README.md
--- mod/book/README.md	2013-03-29 11:30:51.016883000 +0000
+++ mod/book/README.md	2013-03-29 13:37:16.950939400 +0000
@@ -26,3 +26,6 @@
 * PDF export - there is no elegant way AFAIK to convert HTML to PDF, use virtual PDF printer or better use DocBook format for authoring
 * detailed student tracking (postponed till officially supported)
 * export as zipped set of HTML pages - instead use browser command Save page as... in print view
+
+Modified by:
+* Matthew Cannings - Introduce text based and TOC only navigational option
\ No newline at end of file
diff -Naur book/README.md.bak mod/book/README.md.bak
--- mod/book/README.md.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/README.md.bak	2012-11-26 08:50:17.000000000 +0000
@@ -0,0 +1,31 @@
+Book module for Moodle (http://moodle.org/) - Copyright (C) 2004-2011  Petr Skoda (http://skodak.org/)
+
+The Book module makes it easy to create multi-page resources with a book-like format. This module can be used to build complete book-like websites inside of your Moodle course.
+This module was developed for Technical University of Liberec (Czech Republic). Many ideas and code were taken from other Moodle modules and Moodle itself
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details: http://www.gnu.org/copyleft/gpl.html
+
+
+Created by:
+
+* Petr Skoda (skodak) - most of the coding & design
+* Mojmir Volf, Eloy Lafuente, Antonio Vicent and others
+
+Intentionally omitted features:
+
+* more chapter levels - it would encourage teachers to write too much complex and long books, better use standard standalone HTML editor and import it as Resource. DocBook format is another suitable solution.
+* TOC hiding in normal view - instead use printer friendly view
+* PDF export - there is no elegant way AFAIK to convert HTML to PDF, use virtual PDF printer or better use DocBook format for authoring
+* detailed student tracking (postponed till officially supported)
+* export as zipped set of HTML pages - instead use browser command Save page as... in print view
+
+Modified by:
+* Matthew Cannings - Introduce text based navigational option
\ No newline at end of file
diff -Naur book/settings.php mod/book/settings.php
--- mod/book/settings.php	2013-03-29 11:30:51.050883000 +0000
+++ mod/book/settings.php	2012-11-26 08:50:17.000000000 +0000
@@ -38,6 +38,10 @@
         get_string('numberingoptions', 'mod_book'), get_string('numberingoptions_desc', 'mod_book'),
         array_keys($options), $options));
 
+    $options2 = book_get_link_types();
+    $settings->add(new admin_setting_configmultiselect('book/linkoptions',
+        get_string('linkoptions', 'mod_book'), get_string('linkoptions_desc', 'mod_book'),
+        array_keys($options2), $options2));
 
     // Modedit defaults.
 
@@ -46,4 +50,9 @@
     $settings->add(new admin_setting_configselect('book/numbering',
         get_string('numbering', 'mod_book'), '', BOOK_NUM_NUMBERS, $options));
 
+    $settings->add(new admin_setting_configselect('book/linkstyle',
+        get_string('linkstyle', 'mod_book'), '', BOOK_LINK_IMAGE, $options2));
+
+
+
 }
diff -Naur book/styles.css mod/book/styles.css
--- mod/book/styles.css	2013-03-29 11:30:50.863882800 +0000
+++ mod/book/styles.css	2013-03-29 13:26:40.725430500 +0000
@@ -115,3 +115,23 @@
     margin-top: 0px;
     list-style: none;
 }
+
+/* Text style links */
+.navtop.linkstyle1, .navbottom.linkstyle1{
+    font-size: small;
+}
+.navtop.linkstyle1 .chaptername, .navbottom.linkstyle1 .chaptername{
+    font-weight: bolder;
+}
+.navtop.linkstyle1 a[title="Next"], .navtop.linkstyle1 a[title="Exit book"]{
+    display: none;
+}
+.navtop.linkstyle1 a[title="Previous"]{
+    float:left;
+}
+.navbottom.linkstyle1 a[title="Previous"]{
+    display: none;
+}
+.navtop.linkstyle2, .navbottom.linkstyle2{
+    display: none;
+}
\ No newline at end of file
diff -Naur book/tool/importhtml/index.php.bak mod/book/tool/importhtml/index.php.bak
--- mod/book/tool/importhtml/index.php.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/tool/importhtml/index.php.bak	2012-11-26 08:50:17.000000000 +0000
@@ -0,0 +1,91 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Book import
+ *
+ * @package    booktool_importhtml
+ * @copyright  2004-2011 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require(dirname(__FILE__).'/../../../../config.php');
+require_once(dirname(__FILE__).'/locallib.php');
+require_once(dirname(__FILE__).'/import_form.php');
+
+$id        = required_param('id', PARAM_INT);           // Course Module ID
+$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
+
+$cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST);
+$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
+$book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
+
+require_login($course, false, $cm);
+
+$context = context_module::instance($cm->id);
+require_capability('booktool/importhtml:import', $context);
+
+$PAGE->set_url('/mod/book/tool/importhtml/index.php', array('id'=>$id, 'chapterid'=>$chapterid));
+
+if ($chapterid) {
+    if (!$chapter = $DB->get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$book->id))) {
+        $chapterid = 0;
+    }
+} else {
+    $chapter = false;
+}
+
+$PAGE->set_title($book->name);
+$PAGE->set_heading($course->fullname);
+
+// Prepare the page header.
+$strbook = get_string('modulename', 'mod_book');
+$strbooks = get_string('modulenameplural', 'mod_book');
+
+$mform = new booktool_importhtml_form(null, array('id'=>$id, 'chapterid'=>$chapterid));
+
+// If data submitted, then process and store.
+if ($mform->is_cancelled()) {
+    if (empty($chapter->id)) {
+        redirect("/mod/book/view.php?id=$cm->id");
+    } else {
+        redirect("/mod/book/view.php?id=$cm->id&chapterid=$chapter->id");
+    }
+
+} else if ($data = $mform->get_data()) {
+    echo $OUTPUT->header();
+    echo $OUTPUT->heading(get_string('importingchapters', 'booktool_importhtml'));
+
+    // this is a bloody hack - children do not try this at home!
+    $fs = get_file_storage();
+    $draftid = file_get_submitted_draft_itemid('importfile');
+    if (!$files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $draftid, 'id DESC', false)) {
+        redirect($PAGE->url);
+    }
+    $file = reset($files);
+    toolbook_importhtml_import_chapters($file, $data->type, $book, $context);
+
+    echo $OUTPUT->continue_button(new moodle_url('/mod/book/view.php', array('id'=>$id)));
+    echo $OUTPUT->footer();
+    die;
+}
+
+echo $OUTPUT->header();
+echo $OUTPUT->heading(get_string('import', 'booktool_importhtml'));
+
+$mform->display();
+
+echo $OUTPUT->footer();
diff -Naur book/tool/importhtml/locallib.php.bak mod/book/tool/importhtml/locallib.php.bak
--- mod/book/tool/importhtml/locallib.php.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/tool/importhtml/locallib.php.bak	2012-11-26 08:50:17.000000000 +0000
@@ -0,0 +1,346 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * HTML import lib
+ *
+ * @package    booktool_importhtml
+ * @copyright  2011 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+require_once(dirname(__FILE__).'/lib.php');
+require_once($CFG->dirroot.'/mod/book/locallib.php');
+
+/**
+ * Import HTML pages packaged into one zip archive
+ *
+ * @param stored_file $package
+ * @param string $type type of the package ('typezipdirs' or 'typezipfiles')
+ * @param stdClass $book
+ * @param context_module $context
+ * @param bool $verbose
+ */
+function toolbook_importhtml_import_chapters($package, $type, $book, $context, $verbose = true) {
+    global $DB, $OUTPUT;
+
+    $fs = get_file_storage();
+    $chapterfiles = toolbook_importhtml_get_chapter_files($package, $type);
+    $packer = get_file_packer('application/zip');
+    $fs->delete_area_files($context->id, 'mod_book', 'importhtmltemp', 0);
+    $package->extract_to_storage($packer, $context->id, 'mod_book', 'importhtmltemp', 0, '/');
+    // $datafiles = $fs->get_area_files($context->id, 'mod_book', 'importhtmltemp', 0, 'id', false);
+    // echo "<pre>";p(var_export($datafiles, true));
+
+    $chapters = array();
+
+    if ($verbose) {
+        echo $OUTPUT->notification(get_string('importing', 'booktool_importhtml'), 'notifysuccess');
+    }
+    if ($type == 0) {
+        $chapterfile = reset($chapterfiles);
+        if ($file = $fs->get_file_by_hash("$context->id/mod_book/importhtmltemp/0/$chapterfile->pathname")) {
+            $htmlcontent = toolbook_importhtml_fix_encoding($file->get_content());
+            $htmlchapters = toolbook_importhtml_parse_headings(toolbook_importhtml_parse_body($htmlcontent));
+            // TODO: process h1 as main chapter and h2 as subchapters
+        }
+    } else {
+        foreach ($chapterfiles as $chapterfile) {
+            if ($file = $fs->get_file_by_hash(sha1("/$context->id/mod_book/importhtmltemp/0/$chapterfile->pathname"))) {
+                $chapter = new stdClass();
+                $htmlcontent = toolbook_importhtml_fix_encoding($file->get_content());
+
+                $chapter->bookid        = $book->id;
+                $chapter->pagenum       = $DB->get_field_sql('SELECT MAX(pagenum) FROM {book_chapters} WHERE bookid = ?', array($book->id)) + 1;
+                $chapter->importsrc     = '/'.$chapterfile->pathname;
+                $chapter->content       = toolbook_importhtml_parse_styles($htmlcontent);
+                $chapter->content       .= toolbook_importhtml_parse_body($htmlcontent);
+                $chapter->title         = toolbook_importhtml_parse_title($htmlcontent, $chapterfile->pathname);
+                $chapter->contentformat = FORMAT_HTML;
+                $chapter->hidden        = 0;
+                $chapter->timecreated   = time();
+                $chapter->timemodified  = time();
+                if (preg_match('/_sub(\/|\.htm)/i', $chapter->importsrc)) { // If filename or directory ends with *_sub treat as subchapters
+                    $chapter->subchapter = 1;
+                } else {
+                    $chapter->subchapter = 0;
+                }
+
+                $chapter->id = $DB->insert_record('book_chapters', $chapter);
+                $chapters[$chapter->id] = $chapter;
+
+                add_to_log($book->course, 'book', 'update', 'view.php?id='.$context->instanceid.'&chapterid='.$chapter->id, $book->id, $context->instanceid);
+            }
+        }
+    }
+
+    if ($verbose) {
+        echo $OUTPUT->notification(get_string('relinking', 'booktool_importhtml'), 'notifysuccess');
+    }
+    $allchapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum');
+    foreach ($chapters as $chapter) {
+        // find references to all files and copy them + relink them
+        $matches = null;
+        if (preg_match_all('/(src|codebase|name|href)\s*=\s*"([^"]+)"/i', $chapter->content, $matches)) {
+            $file_record = array('contextid'=>$context->id, 'component'=>'mod_book', 'filearea'=>'chapter', 'itemid'=>$chapter->id);
+            foreach ($matches[0] as $i => $match) {
+                $filepath = dirname($chapter->importsrc).'/'.$matches[2][$i];
+                $filepath = toolbook_importhtml_fix_path($filepath);
+
+                if (strtolower($matches[1][$i]) === 'href') {
+                    // skip linked html files, we will try chapter relinking later
+                    foreach ($allchapters as $target) {
+                        if ($target->importsrc === $filepath) {
+                            continue 2;
+                        }
+                    }
+                }
+
+                if ($file = $fs->get_file_by_hash(sha1("/$context->id/mod_book/importhtmltemp/0$filepath"))) {
+                    if (!$oldfile = $fs->get_file_by_hash(sha1("/$context->id/mod_book/chapter/$chapter->id$filepath"))) {
+                        $fs->create_file_from_storedfile($file_record, $file);
+                    }
+                    $chapter->content = str_replace($match, $matches[1][$i].'="@@PLUGINFILE@@'.$filepath.'"', $chapter->content);
+                }
+            }
+            $DB->set_field('book_chapters', 'content', $chapter->content, array('id'=>$chapter->id));
+        }
+    }
+    unset($chapters);
+
+    $allchapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum');
+    foreach ($allchapters as $chapter) {
+        $newcontent = $chapter->content;
+        $matches = null;
+        if (preg_match_all('/(href)\s*=\s*"([^"]+)"/i', $chapter->content, $matches)) {
+            foreach ($matches[0] as $i => $match) {
+                if (strpos($matches[2][$i], ':') !== false or strpos($matches[2][$i], '@') !== false) {
+                    // it is either absolute or pluginfile link
+                    continue;
+                }
+                $chapterpath = dirname($chapter->importsrc).'/'.$matches[2][$i];
+                $chapterpath = toolbook_importhtml_fix_path($chapterpath);
+                foreach ($allchapters as $target) {
+                    if ($target->importsrc === $chapterpath) {
+                        $newcontent = str_replace($match, 'href="'.new moodle_url('/mod/book/view.php',
+                                array('id'=>$context->instanceid, 'chapter'=>$target->id)).'"', $newcontent);
+                    }
+                }
+            }
+        }
+        if ($newcontent !== $chapter->content) {
+            $DB->set_field('book_chapters', 'content', $newcontent, array('id'=>$chapter->id));
+        }
+    }
+
+    add_to_log($book->course, 'course', 'update mod', '../mod/book/view.php?id='.$context->instanceid, 'book '.$book->id);
+    $fs->delete_area_files($context->id, 'mod_book', 'importhtmltemp', 0);
+
+    // update the revision flag - this takes a long time, better to refetch the current value
+    $book = $DB->get_record('book', array('id'=>$book->id));
+    $DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
+}
+
+/**
+ * Parse the headings of the imported package of type 'typeonefile'
+ * (currently unsupported)
+ *
+ * @param string $html html content to parse
+ * @todo implement this once the type 'typeonefile' is enabled
+ */
+function toolbook_importhtml_parse_headings($html) {
+}
+
+/**
+ * Parse the links to external css sheets of the imported html content
+ *
+ * @param string $html html content to parse
+ * @return string all the links to external css sheets
+ */
+function toolbook_importhtml_parse_styles($html) {
+    $styles = '';
+    if (preg_match('/<head[^>]*>(.+)<\/head>/is', $html, $matches)) {
+        $head = $matches[1];
+        if (preg_match_all('/<link[^>]+rel="stylesheet"[^>]*>/i', $head, $matches)) { // Extract links to css.
+            for ($i=0; $i<count($matches[0]); $i++) {
+                $styles .= $matches[0][$i]."\n";
+            }
+        }
+    }
+    return $styles;
+}
+
+/**
+ * Normalize paths to be absolute
+ *
+ * @param string $path original path with MS/relative separators
+ * @return string the normalized and cleaned absolute path
+ */
+function toolbook_importhtml_fix_path($path) {
+    $path = str_replace('\\', '/', $path); // anti MS hack
+    $path = '/'.ltrim($path, './'); // dirname() produces . for top level files + our paths start with /
+
+    $cnt = substr_count($path, '..');
+    for ($i=0; $i<$cnt; $i++) {
+        $path = preg_replace('|[^/]+/\.\./|', '', $path, 1);
+    }
+
+    $path = clean_param($path, PARAM_PATH);
+    return $path;
+}
+
+/**
+ * Convert some html content to utf8, getting original encoding from html headers
+ *
+ * @param string $html html content to convert
+ * @return string html content converted to utf8
+ */
+function toolbook_importhtml_fix_encoding($html) {
+    if (preg_match('/<head[^>]*>(.+)<\/head>/is', $html, $matches)) {
+        $head = $matches[1];
+        if (preg_match('/charset=([^"]+)/is', $head, $matches)) {
+            $enc = $matches[1];
+            return textlib::convert($html, $enc, 'utf-8');
+        }
+    }
+    return iconv('UTF-8', 'UTF-8//IGNORE', $html);
+}
+
+/**
+ * Extract the body from any html contents
+ *
+ * @param string $html the html to parse
+ * @return string the contents of the body
+ */
+function toolbook_importhtml_parse_body($html) {
+    $matches = null;
+    if (preg_match('/<body[^>]*>(.+)<\/body>/is', $html, $matches)) {
+        return $matches[1];
+    } else {
+        return '';
+    }
+}
+
+/**
+ * Extract the title of any html content, getting it from the title tag
+ *
+ * @param string $html the html to parse
+ * @param string $default default title to apply if no title is found
+ * @return string the resulting title
+ */
+function toolbook_importhtml_parse_title($html, $default) {
+    $matches = null;
+    if (preg_match('/<title>([^<]+)<\/title>/i', $html, $matches)) {
+        return $matches[1];
+    } else {
+        return $default;
+    }
+}
+
+/**
+ * Returns all the html files (chapters) from a file package
+ *
+ * @param stored_file $package file to be processed
+ * @param string $type type of the package ('typezipdirs' or 'typezipfiles')
+ *
+ * @return array the html files found in the package
+ */
+function toolbook_importhtml_get_chapter_files($package, $type) {
+    $packer = get_file_packer('application/zip');
+    $files = $package->list_files($packer);
+    $tophtmlfiles = array();
+    $subhtmlfiles = array();
+    $topdirs = array();
+
+    foreach ($files as $file) {
+        if (empty($file->pathname)) {
+            continue;
+        }
+        if (substr($file->pathname, -1) === '/') {
+            if (substr_count($file->pathname, '/') !== 1) {
+                // skip subdirs
+                continue;
+            }
+            if (!isset($topdirs[$file->pathname])) {
+                $topdirs[$file->pathname] = array();
+            }
+
+        } else {
+            $mime = mimeinfo('icon', $file->pathname);
+            if ($mime !== 'html') {
+                continue;
+            }
+            $level = substr_count($file->pathname, '/');
+            if ($level === 0) {
+                $tophtmlfiles[$file->pathname] = $file;
+            } else if ($level === 1) {
+                $subhtmlfiles[$file->pathname] = $file;
+                $dir = preg_replace('|/.*$|', '', $file->pathname);
+                $topdirs[$dir][$file->pathname] = $file;
+            } else {
+                // lower levels are not interesting
+                continue;
+            }
+        }
+    }
+
+    collatorlib::ksort($tophtmlfiles, collatorlib::SORT_NATURAL);
+    collatorlib::ksort($subhtmlfiles, collatorlib::SORT_NATURAL);
+    collatorlib::ksort($topdirs, collatorlib::SORT_NATURAL);
+
+    $chapterfiles = array();
+
+    if ($type == 2) {
+        $chapterfiles = $tophtmlfiles;
+
+    } else if ($type == 1) {
+        foreach ($topdirs as $dir => $htmlfiles) {
+            if (empty($htmlfiles)) {
+                continue;
+            }
+            collatorlib::ksort($htmlfiles, collatorlib::SORT_NATURAL);
+            if (isset($htmlfiles[$dir.'/index.html'])) {
+                $htmlfile = $htmlfiles[$dir.'/index.html'];
+            } else if (isset($htmlfiles[$dir.'/index.htm'])) {
+                $htmlfile = $htmlfiles[$dir.'/index.htm'];
+            } else if (isset($htmlfiles[$dir.'/Default.htm'])) {
+                $htmlfile = $htmlfiles[$dir.'/Default.htm'];
+            } else {
+                $htmlfile = reset($htmlfiles);
+            }
+            $chapterfiles[$htmlfile->pathname] = $htmlfile;
+        }
+    } else if ($type == 0) {
+        if ($tophtmlfiles) {
+            if (isset($tophtmlfiles['index.html'])) {
+                $htmlfile = $tophtmlfiles['index.html'];
+            } else if (isset($tophtmlfiles['index.htm'])) {
+                $htmlfile = $tophtmlfiles['index.htm'];
+            } else if (isset($tophtmlfiles['Default.htm'])) {
+                $htmlfile = $tophtmlfiles['Default.htm'];
+            } else {
+                $htmlfile = reset($tophtmlfiles);
+            }
+        } else {
+            $htmlfile = reset($subhtmlfiles);
+        }
+        $chapterfiles[$htmlfile->pathname] = $htmlfile;
+    }
+
+    return $chapterfiles;
+}
diff -Naur book/tool/print/index.php.bak mod/book/tool/print/index.php.bak
--- mod/book/tool/print/index.php.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/tool/print/index.php.bak	2012-11-26 08:50:17.000000000 +0000
@@ -0,0 +1,176 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Book printing
+ *
+ * @package    booktool_print
+ * @copyright  2004-2011 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require(dirname(__FILE__).'/../../../../config.php');
+require_once(dirname(__FILE__).'/locallib.php');
+
+$id        = required_param('id', PARAM_INT);           // Course Module ID
+$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
+
+// =========================================================================
+// security checks START - teachers and students view
+// =========================================================================
+
+$cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST);
+$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
+$book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
+
+require_course_login($course, true, $cm);
+
+$context = context_module::instance($cm->id);
+require_capability('mod/book:read', $context);
+require_capability('booktool/print:print', $context);
+
+// Check all variables.
+if ($chapterid) {
+    // Single chapter printing - only visible!
+    $chapter = $DB->get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$book->id), '*', MUST_EXIST);
+} else {
+    // Complete book.
+    $chapter = false;
+}
+
+$PAGE->set_url('/mod/book/print.php', array('id'=>$id, 'chapterid'=>$chapterid));
+
+unset($id);
+unset($chapterid);
+
+// Security checks END.
+
+// read chapters
+$chapters = book_preload_chapters($book);
+
+$strbooks = get_string('modulenameplural', 'mod_book');
+$strbook  = get_string('modulename', 'mod_book');
+$strtop   = get_string('top', 'mod_book');
+
+@header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
+@header('Pragma: no-cache');
+@header('Expires: ');
+@header('Accept-Ranges: none');
+@header('Content-type: text/html; charset=utf-8');
+
+if ($chapter) {
+
+    if ($chapter->hidden) {
+        require_capability('mod/book:viewhiddenchapters', $context);
+    }
+
+    add_to_log($course->id, 'book', 'print', 'tool/print/index.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id);
+
+    // page header
+    ?>
+    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+    <html>
+    <head>
+      <title><?php echo format_string($book->name, true, array('context'=>$context)) ?></title>
+      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+      <meta name="description" content="<?php echo s(format_string($book->name, true, array('context'=>$context))) ?>" />
+      <link rel="stylesheet" type="text/css" href="print.css" />
+    </head>
+    <body>
+    <a name="top"></a>
+    <div class="chapter">
+    <?php
+
+
+    if (!$book->customtitles) {
+        if (!$chapter->subchapter) {
+            $currtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context);
+            echo '<p class="book_chapter_title">'.$currtitle.'</p>';
+        } else {
+            $currtitle = book_get_chapter_title($chapters[$chapter->id]->parent, $chapters, $book, $context);
+            $currsubtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context);
+            echo '<p class="book_chapter_title">'.$currtitle.'<br />'.$currsubtitle.'</p>';
+        }
+    }
+
+    $chaptertext = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id, 'mod_book', 'chapter', $chapter->id);
+    echo format_text($chaptertext, $chapter->contentformat, array('noclean'=>true, 'context'=>$context));
+    echo '</div>';
+    echo '</body> </html>';
+
+} else {
+    add_to_log($course->id, 'book', 'print', 'tool/print/index.php?id='.$cm->id, $book->id, $cm->id);
+    $allchapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum');
+    $book->intro = file_rewrite_pluginfile_urls($book->intro, 'pluginfile.php', $context->id, 'mod_book', 'intro', null);
+
+    // page header
+    ?>
+    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+    <html>
+    <head>
+      <title><?php echo format_string($book->name, true, array('context'=>$context)) ?></title>
+      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+      <meta name="description" content="<?php echo s(format_string($book->name, true, array('noclean'=>true, 'context'=>$context))) ?>" />
+      <link rel="stylesheet" type="text/css" href="print.css" />
+    </head>
+    <body>
+    <a name="top"></a>
+    <p class="book_title"><?php echo format_string($book->name, true, array('context'=>$context)) ?></p>
+    <p class="book_summary"><?php echo format_text($book->intro, $book->introformat, array('noclean'=>true, 'context'=>$context)) ?></p>
+    <div class="book_info"><table>
+    <tr>
+    <td><?php echo get_string('site') ?>:</td>
+    <td><a href="<?php echo $CFG->wwwroot ?>"><?php echo format_string($SITE->fullname, true, array('context'=>$context)) ?></a></td>
+    </tr><tr>
+    <td><?php echo get_string('course') ?>:</td>
+    <td><?php echo format_string($course->fullname, true, array('context'=>$context)) ?></td>
+    </tr><tr>
+    <td><?php echo get_string('modulename', 'mod_book') ?>:</td>
+    <td><?php echo format_string($book->name, true, array('context'=>$context)) ?></td>
+    </tr><tr>
+    <td><?php echo get_string('printedby', 'booktool_print') ?>:</td>
+    <td><?php echo fullname($USER, true) ?></td>
+    </tr><tr>
+    <td><?php echo get_string('printdate', 'booktool_print') ?>:</td>
+    <td><?php echo userdate(time()) ?></td>
+    </tr>
+    </table></div>
+
+    <?php
+    list($toc, $titles) = booktool_print_get_toc($chapters, $book, $cm);
+    echo $toc;
+    // chapters
+    $link1 = $CFG->wwwroot.'/mod/book/view.php?id='.$course->id.'&chapterid=';
+    $link2 = $CFG->wwwroot.'/mod/book/view.php?id='.$course->id;
+    foreach ($chapters as $ch) {
+        $chapter = $allchapters[$ch->id];
+        if ($chapter->hidden) {
+            continue;
+        }
+        echo '<div class="book_chapter"><a name="ch'.$ch->id.'"></a>';
+        if (!$book->customtitles) {
+            echo '<p class="book_chapter_title">'.$titles[$ch->id].'</p>';
+        }
+        $content = str_replace($link1, '#ch', $chapter->content);
+        $content = str_replace($link2, '#top', $content);
+        $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $context->id, 'mod_book', 'chapter', $ch->id);
+        echo format_text($content, $chapter->contentformat, array('noclean'=>true, 'context'=>$context));
+        echo '</div>';
+        // echo '<a href="#toc">'.$strtop.'</a>';
+    }
+    echo '</body> </html>';
+}
+
diff -Naur book/tool/print/locallib.php.bak mod/book/tool/print/locallib.php.bak
--- mod/book/tool/print/locallib.php.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/tool/print/locallib.php.bak	2012-11-26 08:50:17.000000000 +0000
@@ -0,0 +1,112 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Book print lib
+ *
+ * @package    booktool_print
+ * @copyright  2011 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die;
+
+require_once(dirname(__FILE__).'/lib.php');
+require_once($CFG->dirroot.'/mod/book/locallib.php');
+
+/**
+ * Generate toc structure and titles
+ *
+ * @param array $chapters
+ * @param stdClass $book
+ * @param stdClass $cm
+ * @return array
+ */
+function booktool_print_get_toc($chapters, $book, $cm) {
+    $first = true;
+    $titles = array();
+
+    $context = context_module::instance($cm->id);
+
+    $toc = ''; // Representation of toc (HTML).
+
+    switch ($book->numbering) {
+        case BOOK_NUM_NONE:
+            $toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
+            break;
+        case BOOK_NUM_NUMBERS:
+            $toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
+            break;
+        case BOOK_NUM_BULLETS:
+            $toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
+            break;
+        case BOOK_NUM_INDENTED:
+            $toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
+            break;
+    }
+
+    $toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML).
+
+    if ($book->customtitles) {
+        $toc .= html_writer::tag('h1', get_string('toc', 'mod_book'));
+    } else {
+        $toc .= html_writer::tag('p', get_string('toc', 'mod_book'), array('class' => 'book_chapter_title'));
+    }
+    $toc .= html_writer::start_tag('ul');
+    foreach ($chapters as $ch) {
+        if (!$ch->hidden) {
+            $title = book_get_chapter_title($ch->id, $chapters, $book, $context);
+            if (!$ch->subchapter) {
+
+                if ($first) {
+                    $toc .= html_writer::start_tag('li');
+                } else {
+                    $toc .= html_writer::end_tag('ul');
+                    $toc .= html_writer::end_tag('li');
+                    $toc .= html_writer::start_tag('li');
+                }
+
+            } else {
+
+                if ($first) {
+                    $toc .= html_writer::start_tag('li');
+                    $toc .= html_writer::start_tag('ul');
+                    $toc .= html_writer::start_tag('li');
+                } else {
+                    $toc .= html_writer::start_tag('li');
+                }
+
+            }
+            $titles[$ch->id] = $title;
+            $toc .= html_writer::link(new moodle_url('#ch'.$ch->id), $title, array('title' => s($title)));
+            if (!$ch->subchapter) {
+                $toc .= html_writer::start_tag('ul');
+            } else {
+                $toc .= html_writer::end_tag('li');
+            }
+            $first = false;
+        }
+    }
+
+    $toc .= html_writer::end_tag('ul');
+    $toc .= html_writer::end_tag('li');
+    $toc .= html_writer::end_tag('ul');
+    $toc .= html_writer::end_tag('div');
+
+    $toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
+
+    return array($toc, $titles);
+}
diff -Naur book/version.php mod/book/version.php
--- mod/book/version.php	2013-03-29 11:30:51.003882900 +0000
+++ mod/book/version.php	2013-03-29 13:11:25.929698600 +0000
@@ -25,6 +25,6 @@
 defined('MOODLE_INTERNAL') || die;
 
 $module->component = 'mod_book'; // Full name of the plugin (used for diagnostics)
-$module->version   = 2012061710; // The current module version (Date: YYYYMMDDXX)
+$module->version   = 2012112301; // The current module version (Date: YYYYMMDDXX)
 $module->requires  = 2012061700; // Requires this Moodle version
 $module->cron      = 0;          // Period for cron to check this module (secs)
diff -Naur book/view.php mod/book/view.php
--- mod/book/view.php	2013-03-29 11:30:50.909882900 +0000
+++ mod/book/view.php	2013-03-29 13:39:22.418039800 +0000
@@ -125,7 +125,9 @@
 
 // prepare chapter navigation icons
 $previd = null;
+$prevtitle = null;
 $nextid = null;
+$nexttitle = null;
 $last = null;
 foreach ($chapters as $ch) {
     if (!$edit and $ch->hidden) {
@@ -133,24 +135,41 @@
     }
     if ($last == $chapter->id) {
         $nextid = $ch->id;
+        $nexttitle = book_get_chapter_title($ch->id, $chapters, $book, $context);
         break;
     }
     if ($ch->id != $chapter->id) {
         $previd = $ch->id;
+        $prevtitle = book_get_chapter_title($ch->id, $chapters, $book, $context);
     }
     $last = $ch->id;
 }
 
 $chnavigation = '';
 if ($previd) {
-    $chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id.
+    if ($book->linkstyle == 0){
+        $chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id.
             '&amp;chapterid='.$previd.'"><img src="'.$OUTPUT->pix_url('nav_prev', 'mod_book').'" class="bigicon" alt="'.get_string('navprev', 'book').'"/></a>';
+    } else {
+        $chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id.
+            '&amp;chapterid='.$previd.'"><span class="chaptername"><span class="arrow">'.$OUTPUT->larrow().'&nbsp;</span></span>'.get_string('navprev', 'book').':&nbsp;<span class="chaptername">'.$prevtitle.'</span></a>';
+    }
+
 } else {
-    $chnavigation .= '<img src="'.$OUTPUT->pix_url('nav_prev_dis', 'mod_book').'" class="bigicon" alt="" />';
+    if ($book->linkstyle == 0){
+        $chnavigation .= '<img src="'.$OUTPUT->pix_url('nav_prev_dis', 'mod_book').'" class="bigicon" alt="" />';
+    }
 }
+$chnavigation .= '&nbsp;';
 if ($nextid) {
-    $chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id.
+    if ($book->linkstyle == 0){
+        $chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id.
             '&amp;chapterid='.$nextid.'"><img src="'.$OUTPUT->pix_url('nav_next', 'mod_book').'" class="bigicon" alt="'.get_string('navnext', 'book').'" /></a>';
+    } else {
+        $chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id.
+            '&amp;chapterid='.$nextid.'">'.get_string('navnext', 'book').':<span class="chaptername">&nbsp;'.$nexttitle.'<span class="arrow">&nbsp;'.$OUTPUT->rarrow().'</span></span></a>';
+    }
+
 } else {
     $sec = '';
     if ($section = $DB->get_record('course_sections', array('id'=>$cm->section))) {
@@ -161,8 +180,12 @@
     } else {
         $returnurl = "$CFG->wwwroot/course/view.php?id=$course->id#section-$sec";
     }
-    $chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="'.$returnurl.'"><img src="'.$OUTPUT->pix_url('nav_exit', 'mod_book').
-            '" class="bigicon" alt="'.get_string('navexit', 'book').'" /></a>';
+    if ($book->linkstyle == 0){
+        $chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="'.$returnurl.'"><img src="'.$OUTPUT->pix_url('nav_exit', 'mod_book').
+                '" class="bigicon" alt="'.get_string('navexit', 'book').'" /></a>';
+    } else {
+        $chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="'.$returnurl.'"><span class="chaptername">'.get_string('navexit', 'book').'<span class="chaptername"></a>';
+    }
 
     // we are cheating a bit here, viewing the last page means user has viewed the whole book
     $completion = new completion_info($course);
@@ -176,7 +199,7 @@
 echo $OUTPUT->header();
 
 // upper nav
-echo '<div class="navtop">'.$chnavigation.'</div>';
+echo '<div class="navtop linkstyle'.$book->linkstyle.'">'.$chnavigation.'</div>';
 
 // chapter itself
 echo $OUTPUT->box_start('generalbox book_content');
@@ -198,6 +221,6 @@
 echo $OUTPUT->box_end();
 
 // lower navigation
-echo '<div class="navbottom">'.$chnavigation.'</div>';
+echo '<div class="navbottom linkstyle'.$book->linkstyle.'">'.$chnavigation.'</div>';
 
 echo $OUTPUT->footer();
diff -Naur book/view.php.bak mod/book/view.php.bak
--- mod/book/view.php.bak	1970-01-01 00:00:00.000000000 +0000
+++ mod/book/view.php.bak	2013-03-29 13:27:59.092493200 +0000
@@ -0,0 +1,222 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Book view page
+ *
+ * @package    mod_book
+ * @copyright  2004-2011 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require(dirname(__FILE__).'/../../config.php');
+require_once(dirname(__FILE__).'/locallib.php');
+require_once($CFG->libdir.'/completionlib.php');
+
+$id        = optional_param('id', 0, PARAM_INT);        // Course Module ID
+$bid       = optional_param('b', 0, PARAM_INT);         // Book id
+$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
+$edit      = optional_param('edit', -1, PARAM_BOOL);    // Edit mode
+
+// =========================================================================
+// security checks START - teachers edit; students view
+// =========================================================================
+if ($id) {
+    $cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST);
+    $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
+    $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
+} else {
+    $book = $DB->get_record('book', array('id'=>$bid), '*', MUST_EXIST);
+    $cm = get_coursemodule_from_instance('book', $book->id, 0, false, MUST_EXIST);
+    $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
+    $id = $cm->id;
+}
+
+require_course_login($course, true, $cm);
+
+$context = context_module::instance($cm->id);
+require_capability('mod/book:read', $context);
+
+$allowedit  = has_capability('mod/book:edit', $context);
+$viewhidden = has_capability('mod/book:viewhiddenchapters', $context);
+
+if ($allowedit) {
+    if ($edit != -1 and confirm_sesskey()) {
+        $USER->editing = $edit;
+    } else {
+        if (isset($USER->editing)) {
+            $edit = $USER->editing;
+        } else {
+            $edit = 0;
+        }
+    }
+} else {
+    $edit = 0;
+}
+
+// read chapters
+$chapters = book_preload_chapters($book);
+
+if ($allowedit and !$chapters) {
+    redirect('edit.php?cmid='.$cm->id); // No chapters - add new one.
+}
+// Check chapterid and read chapter data
+if ($chapterid == '0') { // Go to first chapter if no given.
+    foreach ($chapters as $ch) {
+        if ($edit) {
+            $chapterid = $ch->id;
+            break;
+        }
+        if (!$ch->hidden) {
+            $chapterid = $ch->id;
+            break;
+        }
+    }
+}
+
+if (!$chapterid or !$chapter = $DB->get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$book->id))) {
+    print_error('errorchapter', 'mod_book', new moodle_url('/course/view.php', array('id'=>$course->id)));
+}
+
+// chapter is hidden for students
+if ($chapter->hidden and !$viewhidden) {
+    print_error('errorchapter', 'mod_book', new moodle_url('/course/view.php', array('id'=>$course->id)));
+}
+
+$PAGE->set_url('/mod/book/view.php', array('id'=>$id, 'chapterid'=>$chapterid));
+
+
+// Unset all page parameters.
+unset($id);
+unset($bid);
+unset($chapterid);
+
+// Security checks END.
+
+add_to_log($course->id, 'book', 'view', 'view.php?id='.$cm->id.'&amp;chapterid='.$chapter->id, $book->id, $cm->id);
+
+// Read standard strings.
+$strbooks = get_string('modulenameplural', 'mod_book');
+$strbook  = get_string('modulename', 'mod_book');
+$strtoc   = get_string('toc', 'mod_book');
+
+// prepare header
+$pagetitle = $book->name . ": " . $chapter->title;
+$PAGE->set_title($pagetitle);
+$PAGE->set_heading($course->fullname);
+
+book_add_fake_block($chapters, $chapter, $book, $cm, $edit);
+
+// prepare chapter navigation icons
+$previd = null;
+$prevtitle = null;
+$nextid = null;
+$nexttitle = null;
+$last = null;
+foreach ($chapters as $ch) {
+    if (!$edit and $ch->hidden) {
+        continue;
+    }
+    if ($last == $chapter->id) {
+        $nextid = $ch->id;
+        $nexttitle = book_get_chapter_title($ch->id, $chapters, $book, $context);
+        break;
+    }
+    if ($ch->id != $chapter->id) {
+        $previd = $ch->id;
+        $prevtitle = book_get_chapter_title($ch->id, $chapters, $book, $context);
+    }
+    $last = $ch->id;
+}
+
+$chnavigation = '';
+if ($previd) {
+    if ($book->linkstyle == 0){
+        $chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id.
+            '&amp;chapterid='.$previd.'"><img src="'.$OUTPUT->pix_url('nav_prev', 'mod_book').'" class="bigicon" alt="'.get_string('navprev', 'book').'"/></a>';
+    } else {
+        $chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id.
+            '&amp;chapterid='.$previd.'"><span class="chaptername"><span class="arrow">'.$OUTPUT->larrow().'&nbsp;</span></span>'.get_string('navprev', 'book').':&nbsp;<span class="chaptername">'.$prevtitle.'</span></a>';
+    }
+
+} else {
+    if ($book->linkstyle == 0){
+        $chnavigation .= '<img src="'.$OUTPUT->pix_url('nav_prev_dis', 'mod_book').'" class="bigicon" alt="" />';
+    }
+}
+$chnavigation .= '&nbsp;';
+if ($nextid) {
+    if ($book->linkstyle == 0){
+        $chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id.
+            '&amp;chapterid='.$nextid.'"><img src="'.$OUTPUT->pix_url('nav_next', 'mod_book').'" class="bigicon" alt="'.get_string('navnext', 'book').'" /></a>';
+    } else {
+        $chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id.
+            '&amp;chapterid='.$nextid.'">'.get_string('navnext', 'book').':<span class="chaptername">&nbsp;'.$nexttitle.'<span class="arrow">&nbsp;'.$OUTPUT->rarrow().'</span></span></a>';
+    }
+
+} else {
+    $sec = '';
+    if ($section = $DB->get_record('course_sections', array('id'=>$cm->section))) {
+        $sec = $section->section;
+    }
+    if ($course->id == $SITE->id) {
+        $returnurl = "$CFG->wwwroot/";
+    } else {
+        $returnurl = "$CFG->wwwroot/course/view.php?id=$course->id#section-$sec";
+    }
+    if ($book->linkstyle == 0){
+        $chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="'.$returnurl.'"><img src="'.$OUTPUT->pix_url('nav_exit', 'mod_book').
+                '" class="bigicon" alt="'.get_string('navexit', 'book').'" /></a>';
+    } else {
+        $chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="'.$returnurl.'"><span class="chaptername">'.get_string('navexit', 'book').'<span class="chaptername"></a>';
+    }
+
+    // we are cheating a bit here, viewing the last page means user has viewed the whole book
+    $completion = new completion_info($course);
+    $completion->set_module_viewed($cm);
+}
+
+// =====================================================
+// Book display HTML code
+// =====================================================
+
+echo $OUTPUT->header();
+
+// upper nav
+echo '<div class="navtop linkstyle'.$book->linkstyle.'">'.$chnavigation.'</div>';
+
+// chapter itself
+echo $OUTPUT->box_start('generalbox book_content');
+if (!$book->customtitles) {
+    $hidden = $chapter->hidden ? 'dimmed_text' : '';
+    if (!$chapter->subchapter) {
+        $currtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context);
+        echo '<p class="book_chapter_title '.$hidden.'">'.$currtitle.'</p>';
+    } else {
+        $currtitle = book_get_chapter_title($chapters[$chapter->id]->parent, $chapters, $book, $context);
+        $currsubtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context);
+        echo '<p class="book_chapter_title '.$hidden.'">'.$currtitle.'<br />'.$currsubtitle.'</p>';
+    }
+}
+$chaptertext = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id, 'mod_book', 'chapter', $chapter->id);
+echo format_text($chaptertext, $chapter->contentformat, array('noclean'=>true, 'context'=>$context));
+
+echo $OUTPUT->box_end();
+
+// lower navigation
+echo '<div class="navbottom linkstyle'.$book->linkstyle.'">'.$chnavigation.'</div>';
+
+echo $OUTPUT->footer();
