commit ebeb7933b720c0fc3f6833d745ed56d524ae82be Author: T6nis Date: Fri Jun 1 16:35:32 2012 +0300 wip_MDL-33121_2.3_mod_book_fixes diff --git a/mod/book/backup/moodle1/lib.php b/mod/book/backup/moodle1/lib.php index 5a58526..00805bf 100644 --- a/mod/book/backup/moodle1/lib.php +++ b/mod/book/backup/moodle1/lib.php @@ -1,5 +1,5 @@ opening element + * This is executed when the parser reaches the opening element */ public function on_book_chapters_start() { $this->xmlwriter->begin_tag('chapters'); } /** - * This is executed when the parser reaches the closing element + * This is executed when the parser reaches the closing element */ public function on_book_chapters_end() { $this->xmlwriter->end_tag('chapters'); diff --git a/mod/book/db/access.php b/mod/book/db/access.php index d831e3b..850894d 100644 --- a/mod/book/db/access.php +++ b/mod/book/db/access.php @@ -1,5 +1,5 @@ . - /** * Book module upgrade code * diff --git a/mod/book/delete.php b/mod/book/delete.php index 02203bb..63c9507 100644 --- a/mod/book/delete.php +++ b/mod/book/delete.php @@ -1,5 +1,5 @@ get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$b // Header and strings. -$PAGE->set_title(format_string($book->name)); -$PAGE->add_body_class('mod_book'); -$PAGE->set_heading(format_string($course->fullname)); +$PAGE->set_title($book->name); +$PAGE->set_heading($course->fullname); // Form processing. if ($confirm) { // the operation was confirmed. diff --git a/mod/book/edit.php b/mod/book/edit.php index 50088ad..541233d 100644 --- a/mod/book/edit.php +++ b/mod/book/edit.php @@ -1,5 +1,5 @@ is_cancelled()) { } // Otherwise fill and print the form. -$PAGE->set_title(format_string($book->name)); -$PAGE->add_body_class('mod_book'); -$PAGE->set_heading(format_string($course->fullname)); +$PAGE->set_title($book->name); +$PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('editingchapter', 'mod_book')); diff --git a/mod/book/edit_form.php b/mod/book/edit_form.php index ca1e54f..d6f7c2c 100644 --- a/mod/book/edit_form.php +++ b/mod/book/edit_form.php @@ -1,5 +1,5 @@ libdir.'/formslib.php'); class book_chapter_edit_form extends moodleform { function definition() { - global $CFG; $chapter = $this->_customdata['chapter']; $options = $this->_customdata['options']; - + + //Disabled subchapter option when editing first node + $disabledmsg = null; + $disabledarr = null; + + if (!$chapter->id && $chapter->pagenum == 1 || $chapter->pagenum == 1) { + $disabledmsg = get_string('subchapternotice', 'book'); + $disabledarr = array('group' => 1, 'disabled' => 'disabled'); + } + $mform = $this->_form; $mform->addElement('header', 'general', get_string('edit')); @@ -42,7 +50,7 @@ class book_chapter_edit_form extends moodleform { $mform->setType('title', PARAM_RAW); $mform->addRule('title', null, 'required', null, 'client'); - $mform->addElement('advcheckbox', 'subchapter', get_string('subchapter', 'mod_book')); + $mform->addElement('advcheckbox', 'subchapter', get_string('subchapter', 'mod_book'), $disabledmsg, $disabledarr); $mform->addElement('editor', 'content_editor', get_string('content', 'mod_book'), null, $options); $mform->setType('content_editor', PARAM_RAW); diff --git a/mod/book/index.php b/mod/book/index.php index 02ed62d..7143719 100644 --- a/mod/book/index.php +++ b/mod/book/index.php @@ -1,5 +1,5 @@ section; } - } else { - $printsection = ''.userdate($book->timemodified).""; + } else { + $printsection = html_writer::tag('span', userdate($book->timemodified), array('class' => 'smallinfo')); } - $class = $book->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed + $class = $book->visible ? null : array('class' => 'dimmed'); // hidden modules are dimmed $table->data[] = array ( $printsection, - "id\">".format_string($book->name)."", + html_writer::link(new moodle_url('view.php', array('id' => $cm->id)), format_string($book->name), $class), format_module_intro('book', $book, $cm->id)); } diff --git a/mod/book/lang/en/book.php b/mod/book/lang/en/book.php index f737bda..687c722 100644 --- a/mod/book/lang/en/book.php +++ b/mod/book/lang/en/book.php @@ -1,5 +1,5 @@ cm->modname !== 'book') { - return; - } + + global $USER, $PAGE; $plugins = get_plugin_list('booktool'); + foreach ($plugins as $plugin => $dir) { if (file_exists("$dir/lib.php")) { require_once("$dir/lib.php"); diff --git a/mod/book/locallib.php b/mod/book/locallib.php index 96f9f45..35c10a9 100644 --- a/mod/book/locallib.php +++ b/mod/book/locallib.php @@ -1,5 +1,5 @@ libdir.'/filelib.php'); @@ -195,9 +197,7 @@ function book_add_fake_block($chapters, $chapter, $book, $cm, $edit) { $toc = book_get_toc($chapters, $chapter, $book, $cm, $edit, 0); if ($edit) { - $toc .= '
'; - $toc .= $OUTPUT->help_icon('faq', 'mod_book', get_string('faq', 'mod_book')); - $toc .= '
'; + $toc .= html_writer::tag('div', $OUTPUT->help_icon('faq', 'mod_book', get_string('faq', 'mod_book')), array('class' => 'book_faq')); } $bc = new block_contents(); @@ -222,8 +222,8 @@ function book_add_fake_block($chapters, $chapter, $book, $cm, $edit) { */ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { global $USER, $OUTPUT; - - $toc = ''; // Representation of toc (HTML) + + $toc =''; $nch = 0; // Chapter number $ns = 0; // Subchapter number $first = 1; @@ -232,27 +232,35 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { switch ($book->numbering) { case BOOK_NUM_NONE: - $toc .= '
'; + $toc .= html_writer::start_tag('div', array('class' => 'book_toc_none')); break; case BOOK_NUM_NUMBERS: - $toc .= '
'; + $toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered')); break; case BOOK_NUM_BULLETS: - $toc .= '
'; + $toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets')); break; case BOOK_NUM_INDENTED: - $toc .= '
'; + $toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented')); break; } if ($edit) { // Teacher's TOC - $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) { - $toc .= ($first) ? '
  • ' : '
  • '; + + 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; @@ -263,10 +271,18 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { if ($book->numbering == BOOK_NUM_NUMBERS) { $title = "x $title"; } - $title = ''.$title.''; + $title = html_writer::tag('span', $title, array('class' => 'dimmed_text')); } } else { - $toc .= ($first) ? '
    • ' : '
    • '; + + 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) { @@ -276,75 +292,109 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) { if ($book->numbering == BOOK_NUM_NUMBERS) { $title = "x.x $title"; } - $title = ''.$title.''; + $title = html_writer::tag('span', $title, array('class' => 'dimmed_text')); } } if ($ch->id == $chapter->id) { - $toc .= ''.$title.''; + $toc .= html_writer::tag('strong', $title); } else { - $toc .= ''.$title.''; + $toc .= html_writer::link(new moodle_url('view.php', array('id' => $cm->id, 'chapterid' => $ch->id)), $title, array('title' => s($title))); } $toc .= '  '; if ($i != 1) { - $toc .= ' '.get_string('up').''; + $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 .= ' '.get_string('down').''; + $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 .= ' '.get_string('edit').''; - $toc .= ' '.get_string('delete').''; + $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 .= ' '.get_string('show').''; + $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 .= ' '.get_string('hide').''; + $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 .= ' '.get_string('addafter', 'mod_book').''; - - $toc .= (!$ch->subchapter) ? '
        ' : ''; + $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 .= '
    '; + + $toc .= html_writer::end_tag('ul'); + $toc .= html_writer::end_tag('li'); + $toc .= html_writer::end_tag('ul'); + } else { // Normal students view - $toc .= '
      '; + $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; - $toc .= ($first) ? '
    • ' : '
  • '; + + 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++; - $toc .= ($first) ? '
    • ' : '
    • '; + + 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 .= ''.$title.''; + if ($ch->id == $chapter->id) { + $toc .= html_writer::tag('strong', $title); } else { - $toc .= ''.$title.''; + $toc .= html_writer::link(new moodle_url('view.php', array('id' => $cm->id, 'chapterid' => $ch->id)), $title, array('title' => s($title))); } - $toc .= (!$ch->subchapter) ? '
        ' : ''; + + if (!$ch->subchapter) { + $toc .= html_writer::start_tag('ul'); + } else { + $toc .= html_writer::end_tag('li'); + } + $first = 0; } } - $toc .= '
    '; + + $toc .= html_writer::end_tag('ul'); + $toc .= html_writer::end_tag('li'); + $toc .= html_writer::end_tag('ul'); + } - $toc .= '
  • '; + $toc .= html_writer::end_tag('div'); $toc = str_replace('
      ', '', $toc); // Cleanup of invalid structures. diff --git a/mod/book/mod_form.php b/mod/book/mod_form.php index d58cce3..b95f5e0 100644 --- a/mod/book/mod_form.php +++ b/mod/book/mod_form.php @@ -1,5 +1,5 @@ id); require_capability('mod/book:read', $context); require_capability('booktool/exportimscp:export', $context); -$strbooks = get_string('modulenameplural', 'book'); -$strbook = get_string('modulename', 'book'); -$strtop = get_string('top', 'book'); - add_to_log($course->id, 'book', 'exportimscp', 'tool/exportimscp/index.php?id='.$cm->id, $book->id, $cm->id); $file = booktool_exportimscp_build_package($book, $context); diff --git a/mod/book/tool/exportimscp/lang/en/booktool_exportimscp.php b/mod/book/tool/exportimscp/lang/en/booktool_exportimscp.php index 2273e55..58a90ef 100644 --- a/mod/book/tool/exportimscp/lang/en/booktool_exportimscp.php +++ b/mod/book/tool/exportimscp/lang/en/booktool_exportimscp.php @@ -1,5 +1,5 @@ cm->modname !== 'book') { - return; - } + + global $PAGE; if (has_capability('booktool/exportimscp:export', $PAGE->cm->context)) { $url = new moodle_url('/mod/book/tool/exportimscp/index.php', array('id'=>$PAGE->cm->id)); diff --git a/mod/book/tool/exportimscp/locallib.php b/mod/book/tool/exportimscp/locallib.php index 788c2f4..374dbd6 100644 --- a/mod/book/tool/exportimscp/locallib.php +++ b/mod/book/tool/exportimscp/locallib.php @@ -1,5 +1,5 @@ set_title(format_string($book->name)); -$PAGE->add_body_class('mod_book'); -$PAGE->set_heading(format_string($course->fullname)); +$PAGE->set_title($book->name); +$PAGE->set_heading($course->fullname); // Prepare the page header. $strbook = get_string('modulename', 'mod_book'); diff --git a/mod/book/tool/importhtml/lang/en/booktool_importhtml.php b/mod/book/tool/importhtml/lang/en/booktool_importhtml.php index c564009..e79fe27 100644 --- a/mod/book/tool/importhtml/lang/en/booktool_importhtml.php +++ b/mod/book/tool/importhtml/lang/en/booktool_importhtml.php @@ -1,5 +1,5 @@ cm->modname !== 'book') { - return; - } + + global $PAGE; if (has_capability('booktool/importhtml:import', $PAGE->cm->context)) { $url = new moodle_url('/mod/book/tool/importhtml/index.php', array('id'=>$PAGE->cm->id)); diff --git a/mod/book/tool/importhtml/locallib.php b/mod/book/tool/importhtml/locallib.php index 7aa04ca..571d1e6 100644 --- a/mod/book/tool/importhtml/locallib.php +++ b/mod/book/tool/importhtml/locallib.php @@ -1,5 +1,5 @@ cm->modname !== 'book') { - return; - } + + global $PAGE; $params = $PAGE->url->params(); diff --git a/mod/book/tool/print/locallib.php b/mod/book/tool/print/locallib.php index 524ad16..99b99a1 100644 --- a/mod/book/tool/print/locallib.php +++ b/mod/book/tool/print/locallib.php @@ -1,5 +1,5 @@ numbering) { case BOOK_NUM_NONE: - $toc .= '
      '; + $toc .= html_writer::start_tag('div', array('class' => 'book_toc_none')); break; case BOOK_NUM_NUMBERS: - $toc .= '
      '; + $toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered')); break; case BOOK_NUM_BULLETS: - $toc .= '
      '; + $toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets')); break; case BOOK_NUM_INDENTED: - $toc .= '
      '; + $toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented')); break; } - $toc .= ''; // Representation of toc (HTML). - + $toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML). + if ($book->customtitles) { - $toc .= '

      '.get_string('toc', 'mod_book').'

      '; + $toc .= html_writer::tag('h1', get_string('toc', 'mod_book')); } else { - $toc .= '

      '.get_string('toc', 'mod_book').'

      '; + $toc .= html_writer::tag('p', get_string('toc', 'mod_book'), array('class' => 'book_chapter_title')); } - $toc .= '
        '; + $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) { - $toc .= $first ? '
      • ' : '
    • '; + + 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 .= $first ? '
      • ' : '
      • '; + $toc .= html_writer::end_tag('li'); } - $titles[$ch->id] = $title; - $toc .= ''.$title.''; - $toc .= (!$ch->subchapter) ? '
          ' : ''; $first = false; } } - $toc .= '
      '; - $toc .= '
    • '; + + $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('
        ', '', $toc); // Cleanup of invalid structures. return array($toc, $titles); diff --git a/mod/book/tool/print/version.php b/mod/book/tool/print/version.php index 0251d1f..9bfcb4d 100644 --- a/mod/book/tool/print/version.php +++ b/mod/book/tool/print/version.php @@ -1,5 +1,5 @@ set_title(format_string($book->name)); -$PAGE->add_body_class('mod_book'); -$PAGE->set_heading(format_string($course->fullname)); +$PAGE->set_title($book->name); +$PAGE->set_heading($course->fullname); book_add_fake_block($chapters, $chapter, $book, $cm, $edit);