-$Id: README.txt,v 1.5 2008/07/22 14:59:13 skodak Exp $
+$Id: README.txt,v 1.6 2008/08/13 23:21:14 skodak Exp $
///////////////////////////////////////////////////////////////////////////
// //
Installation:
* see http://docs.moodle.org/en/Installing_contributed_modules_or_plugins
-List of features - version 1.2:
+List of features - version 1.4:
* easy to use - new teachers can quickly create multipage study materials
* two levels - only chapters and subchapters
* compatible with 1.8
* export link enabled - thanks Eloy!
* no new features
+== 1.5beta - 2008/08/14 ====================================================
+ * compatible with 1.9.1 and above
+ * xhtml strict and css improvements
+ * formslib conversion
+ * capabilities implemented
+ * no new features
skodak
-<?php // $Id: coursefiles.php,v 1.2 2007/05/20 06:00:26 skodak Exp $
+<?php // $Id: coursefiles.php,v 1.3 2008/08/13 23:21:13 skodak Exp $
// Manage all uploaded files in a course file area
admin_externalpage_print_header($adminroot);
print_heading(get_string("publicsitefileswarning"), "center", 2);
-
+
}
} else {
echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>";
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"coursefiles.php\">";
- echo "<div>";
+ echo "<div>";
echo "<table><tr><td colspan=\"2\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo "</div>";
echo "</form>";
echo "<form action=\"coursefiles.php\" method=\"get\">";
- echo "<div>";
+ echo "<div>";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
--- /dev/null
+<?php
+//
+// Capability definitions for the assignment module.
+//
+// The capabilities are loaded into the database table when the module is
+// installed or updated. Whenever the capability definitions are updated,
+// the module version number should be bumped up.
+//
+// The system has four possible values for a capability:
+// CAP_ALLOW, CAP_PREVENT, CAP_PROHIBIT, and inherit (not set).
+
+$mod_book_capabilities = array(
+
+ 'mod/book:read' => array(
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'guest' => CAP_ALLOW,
+ 'student' => CAP_ALLOW,
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW
+ )
+ ),
+
+ 'mod/book:viewhiddenchapters' => array(
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW
+ )
+ ),
+
+ 'mod/book:edit' => array(
+ 'riskbitmask' => RISK_XSS,
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'editingteacher' => CAP_ALLOW
+ )
+ ),
+
+ 'mod/book:import' => array(
+ 'riskbitmask' => RISK_XSS,
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'editingteacher' => CAP_ALLOW
+ )
+ ),
+
+ 'mod/book:print' => array(
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'legacy' => array(
+ 'guest' => CAP_ALLOW,
+ 'student' => CAP_ALLOW,
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW
+ )
+ ),
+
+ 'mod/book:exportimscp' => array(
+ 'captype' => 'read',
+ 'contextlevel' => CONTEXT_MODULE
+ ),
+
+);
+
+?>
+++ /dev/null
-<!-- $Id: edit.html,v 1.2 2007/04/24 19:20:52 stronk7 Exp $ //-->
-
-<form name="chaptereditform" method="post" action="edit.php">
-<table align="center" cellpadding="5">
-
-<tr valign="top">
- <td align="right">
- <b><?php print_string("chaptertitle", "book") ?>:</b>
- </td>
- <td align="left">
- <input type="text" name="title" size="30" value="<?php p($chapter->title) ?>">
- </td>
-</tr>
-
-<tr valign="top">
- <td align="right">
- <b><?php print_string('subchapter', 'book') ?>:</b>
- </td>
- <td align="left">
- <?php
- if ($chapter->subchapter) {
- $selected = ' checked="checked"';
- } else {
- $selected = '';
- }
- echo '<input name="subchapter" type="checkbox" value="1"'.$selected.' />';
- ?>
- </td>
-</tr>
-
-<tr valign="top">
- <td valign="top" align="right">
- <p><b><?php print_string('content', 'book') ?>:</b></p>
- <font size="1">
- <?PHP
- helpbutton('writing', get_string('helpwriting'), 'moodle', true, true);
- echo '<br />';
- if ($usehtmleditor) {
- helpbutton('richtext', get_string('helprichtext'), 'moodle', true, true);
- } else {
- emoticonhelpbutton('theform', 'text');
- }
- ?><br />
- </font>
- </td>
- <td align="center">
- <?php print_textarea($usehtmleditor, 20, 60, 630, 400, 'content', $chapter->content, $course->id); ?>
- </td>
-</tr>
-</table>
-<center>
- <input type="submit" value="<?php print_string('savechanges') ?>" />
- <input type="reset" value="<?php print_string('revert') ?>" />
- <?php
- if($chapter->id == -1) {
- echo '<font size="-1"> (<a href="import.php?id='.$cm->id.'">'.get_string('doimport', 'book').'</a>)</font>';
- }
- ?>
-</center>
- <input type="hidden" name="id" value="<?php p($cm->id) ?>" />
- <input type="hidden" name="pagenum" value="<?php p($chapter->pagenum) ?>" />
- <input type="hidden" name="chapterid" value="<?php p($chapter->id) ?>" />
- <input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
-</form>
-<?PHP // $Id: edit.php,v 1.3 2008/03/25 20:19:49 poltawski Exp $
+<?PHP // $Id: edit.php,v 1.4 2008/08/13 23:21:14 skodak Exp $
require_once('../../config.php');
require_once('lib.php');
+require_once('edit_form.php');
-$id = required_param('id', PARAM_INT); // Course Module ID
-$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
+$cmid = required_param('cmid', PARAM_INT); // Book Course Module ID
+$chapterid = optional_param('id', 0, PARAM_INT); // Chapter ID
$pagenum = optional_param('pagenum', 0, PARAM_INT);
$subchapter = optional_param('subchapter', 0, PARAM_BOOL);
// =========================================================================
// security checks START - only teachers edit
// =========================================================================
-require_login();
-if (!$cm = get_coursemodule_from_id('book', $id)) {
+if (!$cm = get_coursemodule_from_id('book', $cmid)) {
error('Course Module ID was incorrect');
}
error('Course is misconfigured');
}
+require_login($course, false, $cm);
+
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-require_capability('moodle/course:manageactivities', $context);
+require_capability('mod/book:edit', $context);
if (!$book = get_record('book', 'id', $cm->instance)) {
error('Course module is incorrect');
}
-$chapter = get_record('book_chapters', 'id', $chapterid);
-
-//check all variables
-unset($id);
-unset($chapterid);
-if ($chapter) {
+if ($chapterid) {
+ if (!$chapter = get_record('book_chapters', 'id', $chapterid)) {
+ error('Incorrect chapter id');
+ }
if ($chapter->bookid != $book->id) {//chapter id not in this book!!!!
error('Chapter not part of this book!');
}
- $pagenum = $chapter->pagenum;
} else {
- $pagenum = (integer)$pagenum;
+ $chapter = null;
}
+//check all variables
+unset($cmid);
+unset($chapterid);
+
// =========================================================================
// security checks END
// =========================================================================
+$mform = new book_chapter_edit_form(null, $cm);
+
+if ($chapter) {
+ $chapter->cmid = $cm->id;
+ $mform->set_data($chapter);
+} else {
+ $mform->set_data(array('cmid'=>$cm->id, 'pagenum'=>($pagenum+1), 'subchapter'=>$subchapter));
+}
/// If data submitted, then process and store.
-if (($form = data_submitted()) && (confirm_sesskey())) {
- //TODO: skip it for now
- //prepare data - security checks
- //$form->title = clean_text($form->title, FORMAT_HTML);
- //$form->content = clean_text($form->content, FORMAT_HTML);
-
- if (isset($form->subchapter) ) {
- $form->subchapter = 1;
+if ($mform->is_cancelled()) {
+ if (empty($chapter->id)) {
+ redirect("view.php?id=$cm->id");
} else {
- $form->subchapter = 0;
+ redirect("view.php?id=$cm->id&chapterid=$chapter->id");
}
- if ($chapter) {
- /// editing existing chapter
- $chapter->content = $form->content;
- $chapter->title = $form->title;
- $chapter->subchapter = $form->subchapter;
- $chapter->timemodified = time();
- $chapter->importsrc = addslashes($chapter->importsrc); //use already stored importsrc
- if (!update_record('book_chapters', $chapter)) {
+
+} else if ($data = $mform->get_data(false)) {
+
+ if ($data->id) {
+ if (!update_record('book_chapters', addslashes_recursive($data))) {
error('Could not update your book');
}
add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id);
- add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id);
+ add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id.'&chapterid='.$data->id, $book->id, $cm->id);
+
} else {
/// adding new chapter
- $chapter->bookid = $book->id;
- $chapter->pagenum = $form->pagenum + 1; //place after given pagenum, lets hope it is a number
- $chapter->subchapter = $form->subchapter;
- $chapter->title = $form->title;
- $chapter->content = $form->content;
- $chapter->hidden = 0;
- $chapter->timecreated = time();
- $chapter->timemodified = $chapter->timecreated;
- $chapter->importsrc = '';
-
- $chapters = get_records('book_chapters', 'bookid', $book->id, 'pagenum', 'id, pagenum');
- if ($chapters) {
- foreach($chapters as $ch) {
- if ($ch->pagenum > $pagenum) {
- $ch->pagenum = $ch->pagenum + 1;
- if (!update_record('book_chapters', $ch)) {
- error('Could not update your book');
- }
- }
- }
- }
- if (!$chapter->id = insert_record('book_chapters', $chapter)) {
+ $data->bookid = $book->id;
+ $data->hidden = 0;
+ $data->timecreated = time();
+ $data->timemodified = time();
+ $data->importsrc = '';
+
+ // make room for new page
+ $sql = "UPDATE {$CFG->prefix}book_chapters
+ SET pagenum = pagenum + 1
+ WHERE bookid = $book->id AND pagenum >= $data->pagenum";
+ execute_sql($sql, false);
+
+ if (!$data->id = insert_record('book_chapters', addslashes_recursive($data))) {
error('Could not insert a new chapter');
}
add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id);
- add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id);
+ add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id.'&chapterid='.$data->id, $book->id, $cm->id);
}
book_check_structure($book->id);
- redirect("view.php?id=$cm->id&chapterid=$chapter->id");
+ redirect("view.php?id=$cm->id&chapterid=$data->id");
die;
}
$stredit = get_string('edit');
$pageheading = get_string('editingchapter', 'book');
-$usehtmleditor = can_use_html_editor();
-
-if (!$chapter) {
- $chapter->id = -1;
- $chapter->title = '';
- $chapter->content = '';
- $chapter->subchapter = $subchapter;
- $chapter->pagenum = $pagenum;
-}
-
///prepare the page header
-$navigation = build_navigation('', $cm);
+$navlinks = array();
+$navlinks[] = array('name' => $stredit, 'link' => '', 'type' => 'title');
+
+$navigation = build_navigation($navlinks, $cm);
print_header("$course->shortname: $book->name", $course->fullname, $navigation);
-$icon = '<img align="absmiddle" height="16" width="16" src="icon_chapter.gif" /> ';
+$icon = '<img class="icon" src="icon_chapter.gif" alt="" /> ';
print_heading_with_help($pageheading, 'edit', 'book', $icon);
-print_simple_box_start('center', '');
-include('edit.html');
-print_simple_box_end();
-if ($usehtmleditor ) {
- use_html_editor();
-}
+$mform->display();
print_footer($course);
--- /dev/null
+<?php //$Id: edit_form.php,v 1.1 2008/08/13 23:21:14 skodak Exp $
+
+require_once($CFG->libdir.'/formslib.php');
+
+class book_chapter_edit_form extends moodleform {
+
+ function definition() {
+ global $CFG;
+ $mform =& $this->_form;
+ $cm = $this->_customdata;
+
+ $mform->addElement('header', 'general', get_string('edit'));
+
+ $mform->addElement('text', 'title', get_string('chaptertitle', 'book'), array('size'=>'30'));
+ $mform->setType('title', PARAM_RAW);
+ $mform->addRule('title', null, 'required', null, 'client');
+
+ $mform->addElement('advcheckbox', 'subchapter', get_string('subchapter', 'book'));
+
+ $mform->addElement('htmleditor', 'content', get_string('content', 'book'), array('cols'=>50, 'rows'=>30));
+ $mform->setType('content', PARAM_RAW);
+ $mform->setHelpButton('content', array('reading', 'writing', 'questions', 'richtext'), false, 'editorhelpbutton');
+
+ $mform->addElement('hidden', 'id');
+ $mform->setType('id', PARAM_INT);
+
+ $mform->addElement('hidden', 'cmid');
+ $mform->setType('cmid', PARAM_INT);
+
+ $mform->addElement('hidden', 'pagenum');
+ $mform->setType('pagenum', PARAM_INT);
+
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ if (has_capability('mod/book:import', $context)) {
+ $mform->addElement('static', 'doimport', get_string('importingchapters', 'book').':', '<a href="import.php?id='.$cm->id.'">'.get_string('doimport', 'book').'</a>');
+ }
+
+ $this->add_action_buttons(true);
+ }
+
+ function definition_after_data() {
+ global $CFG;
+ $mform =& $this->_form;
+
+ if ($mform->getElementValue('id')) {
+ if ($mform->elementExists('doimport')) {
+ $mform->removeElement('doimport');
+ }
+ }
+ }
+}
+
+?>
-<?PHP // $Id: generateimscp.php,v 1.2 2007/05/20 06:00:26 skodak Exp $
+<?PHP // $Id: generateimscp.php,v 1.3 2008/08/13 23:21:14 skodak Exp $
///////////////////////////////////////////////////////////////////////////
// //
// //
///////////////////////////////////////////////////////////////////////////
-require_once('../../config.php');
+require('../../config.php');
require_once('lib.php');
-require_once($CFG->dirroot . '/backup/lib.php');
-require_once($CFG->dirroot . '/lib/filelib.php');
+require_once($CFG->dirroot.'/backup/lib.php');
+require_once($CFG->libdir.'/filelib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
-require_login();
-
if (!$cm = get_coursemodule_from_id('book', $id)) {
error('Course Module ID was incorrect');
}
error('Course is misconfigured');
}
+require_login($course, true, $cm);
+
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-require_capability('moodle/course:manageactivities', $context);
-
+require_capability('mod/book:read', $context);
+require_capability('mod/book:exportimscp', $context);
+
if (!$book = get_record('book', 'id', $cm->instance)) {
error('Course module is incorrect');
}
/// Now delete all the temp dirs
delete_dir_contents($CFG->dataroot . "/$cm->course/moddata/book/$book->id");
/// Now serve the file
- send_file($zipfile, clean_filename($book->name) . '.zip', 86400, 0, false, true);
+ send_temp_file($zipfile, clean_filename($book->name) . '.zip');
/**
* This function will create the default imsmanifest plus contents for the book chapters passed as array
}
/**
- * This function will create one chaptercontent object, with the contents converted to html and
+ * This function will create one chaptercontent object, with the contents converted to html and
* one array of local images to be included
*/
function chapter2html($chapter, $courseid, $bookid) {
-<?PHP // $Id: import.php,v 1.4 2008/03/25 20:19:49 poltawski Exp $
+<?PHP // $Id: import.php,v 1.5 2008/08/13 23:21:13 skodak Exp $
-require_once('../../config.php');
+require('../../config.php');
require_once('lib.php');
+require_once('import_form.php');
-$id = required_param('id', PARAM_INT); // Course Module ID
-$subchapter = optional_param('subchapter', 0, PARAM_BOOL);
-$cancel = optional_param('cancel', 0, PARAM_BOOL);
+$id = required_param('id', PARAM_INT); // Course Module ID
// =========================================================================
// security checks START - only teachers edit
// =========================================================================
-require_login();
if (!$cm = get_coursemodule_from_id('book', $id)) {
error('Course Module ID was incorrect');
error('Course is misconfigured');
}
+require_login($course, false, $cm);
+
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-require_capability('moodle/course:manageactivities', $context);
+require_capability('mod/book:import', $context);
if (!$book = get_record('book', 'id', $cm->instance)) {
error('Course module is incorrect');
// security checks END
// =========================================================================
-///cancel pressed, go back to book
-if ($cancel) {
- redirect('view.php?id='.$cm->id);
- die;
-}
-
///prepare the page header
$strbook = get_string('modulename', 'book');
$strbooks = get_string('modulenameplural', 'book');
$navigation = build_navigation($navlinks, $cm);
-print_header("$course->shortname: $book->name", $course->fullname, $navigation);
+$mform = new book_import_form(null, $cm);
+$mform->set_data(array('id'=>$cm->id));
-/// If data submitted, then process, store and relink.
-if (($form = data_submitted()) && (confirm_sesskey())) {
- $form->reference = stripslashes($form->reference);
- if ($form->reference != '') { //null path is root
- $form->reference = book_prepare_link($form->reference);
- if ($form->reference == '') { //evil characters in $ref!
- error('Invalid character detected in given path!');
- }
+/// If data submitted, then process and store.
+if ($mform->is_cancelled()) {
+ if (empty($chapter->id)) {
+ redirect("view.php?id=$cm->id");
+ } else {
+ redirect("view.php?id=$cm->id&chapterid=$chapter->id");
}
+
+} else if ($data = $mform->get_data(false)) {
$coursebase = $CFG->dataroot.'/'.$book->course;
- if ($form->reference == '') {
+
+ $reference = book_prepare_link($data->reference);
+
+ if ($reference == '') {
$base = $coursebase;
} else {
- $base = $coursebase.'/'.$form->reference;
+ $base = $coursebase.'/'.$reference;
}
//prepare list of html files in $refs
}
asort($refs);
} else if (is_file($base)) { //import single file
- $refs[] = '/'.$form->reference;
+ $refs[] = '/'.$reference;
} else { //what is it???
error('Incorrect file/directory specified!');
}
+ print_header("$course->shortname: $book->name", $course->fullname, $navigation);
+
//import files
- echo '<center>';
- echo '<b>'.get_string('importing', 'book').':</b>';
+ print_box_start('generalbox boxaligncenter centerpara');
+ echo '<strong>'.get_string('importing', 'book').':</strong>';
echo '<table cellpadding="2" cellspacing="2" border="1">';
book_check_structure($book->id);
foreach($refs as $ref) {
$chapter->timecreated = time();
$chapter->timemodified = time();
echo "imsrc:".$chapter->importsrc;
- if (($subchapter) || preg_match('/_sub\.htm/i', $chapter->importsrc)) { //if filename or directory starts with sub_* treat as subdirecotories
+ if (($data->subchapter) || preg_match('/_sub\.htm/i', $chapter->importsrc)) { //if filename or directory starts with sub_* treat as subdirecotories
$chapter->subchapter = 1;
} else {
$chapter->subchapter = 0;
}
}
echo '</table><br />';
- echo '<b>'.get_string('relinking', 'book').':</b>';
+ echo '<strong>'.get_string('relinking', 'book').':</strong>';
echo '<table cellpadding="2" cellspacing="2" border="1">';
//relink whole book = all chapters
book_relink($cm->id, $book->id, $course->id);
echo '</table><br />';
- echo '<a href="view.php?id='.$cm->id.'">'.get_string('continue').'</a>';
- echo '</center>';
-} else {
-/// Otherwise fill and print the form.
- $strdoimport = get_string('doimport', 'book');
- $strchoose = get_string('choose');
- $pageheading = get_string('importingchapters', 'book');
-
- $icon = '<img align="absmiddle" height="16" width="16" src="icon_chapter.gif" /> ';
- print_heading_with_help($pageheading, 'import', 'book', $icon);
- print_simple_box_start('center', '');
- ?>
- <form name="theform" method="post" action="import.php">
- <table cellpadding="5" align="center">
- <tr valign="top">
- <td valign="top" align="right">
- <b><?php print_string('fileordir', 'book') ?>:</b>
- </td>
- <td>
- <?php
- echo '<input id="id_reference" name="reference" size="40" value="" /> ';
- button_to_popup_window ('/mod/book/coursefiles.php?choose=id_reference&id='.$course->id,
- 'coursefiles', $strchoose, 500, 750, $strchoose);
- ?>
- </td>
- </tr>
- <tr valign="top">
- <td valign="top" align="right">
- <b><?php print_string('subchapter', 'book') ?>:</b>
- </td>
- <td>
- <?php
- echo '<input name="subchapter" type="checkbox" value="1" />';
- ?>
- </td>
- </tr>
- <tr valign="top">
- <td valign="top" align="right"> </td>
- <td><p><?php print_string('importinfo', 'book') ?></p></td>
- </tr>
- </table>
- <center>
- <input type="submit" value="<?php echo $strdoimport ?>" />
- <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
- </center>
- <input type="hidden" name="id" value="<?php p($cm->id) ?>" />
- <input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>" />
- </form>
-
- <?php
- print_simple_box_end();
+ print_box_end();
+ print_continue('view.php?id='.$cm->id);
+ print_footer($course);
+ die;
}
+print_header("$course->shortname: $book->name", $course->fullname, $navigation);
+
+$strdoimport = get_string('doimport', 'book');
+$strchoose = get_string('choose');
+$pageheading = get_string('importingchapters', 'book');
+
+$icon = '<img class="icon" src="icon_chapter.gif" alt="" /> ';
+print_heading_with_help($pageheading, 'import', 'book', $icon);
+
+$mform->display();
+
print_footer($course);
?>
--- /dev/null
+<?php //$Id: import_form.php,v 1.1 2008/08/13 23:21:14 skodak Exp $
+
+require_once($CFG->libdir.'/formslib.php');
+
+class book_import_form extends moodleform {
+
+ function definition() {
+ global $CFG;
+ $mform =& $this->_form;
+ $cm = $this->_customdata;
+
+ $mform->addElement('header', 'general', get_string('import'));
+
+ $group = array();
+ $group[0] =& MoodleQuickForm::createElement('text', 'reference', get_string('fileordir', 'book'), array('size'=>'48'));
+ $group[1] =& MoodleQuickForm::createElement('button', 'popup', get_string('chooseafile', 'resource') .' ...');
+
+ $options = 'menubar=0,location=0,scrollbars,resizable,width=600,height=400';
+ $url = '/mod/book/coursefiles.php?choose=id_reference&id='.$cm->course;
+ $buttonattributes = array('title'=>get_string('chooseafile', 'resource'), 'onclick'=>"return openpopup('$url', '".$group[1]->getName()."', '$options', 0);");
+ $group[1]->updateAttributes($buttonattributes);
+
+ $mform->addGroup($group, 'choosesomething', get_string('fileordir', 'book'), array(''), false);
+
+ $mform->addElement('checkbox', 'subchapter', get_string('subchapter', 'book'));
+ $mform->addElement('static', 'importfileinfo', get_string('help'), get_string('importinfo', 'book'));
+
+ $mform->addElement('hidden', 'id', $cm->id);
+ $mform->setType('id', PARAM_INT);
+
+ $this->add_action_buttons(true, get_string('import', 'book'));
+ }
+
+ function validation($data, $files) {
+ global $CFG;
+ $cm = $this->_customdata;
+
+ $errors = parent::validation($data, $files);
+ $reference = stripslashes($data['reference']);
+
+ if ($reference != '') { //null path is root
+ $reference = book_prepare_link($reference);
+ if ($reference == '') { //evil characters in $ref!
+ $errors['choosesomething'] = get_string('error');
+ } else {
+ $coursebase = $CFG->dataroot.'/'.$cm->course;
+
+ if ($reference == '') {
+ $base = $coursebase;
+ } else {
+ $base = $coursebase.'/'.$reference;
+ }
+ if (!is_dir($base) and !is_file($base)) {
+ $errors['choosesomething'] = get_string('error');
+ }
+ }
+ }
+
+ return $errors;
+ }
+}
+
+?>
-<?PHP // $Id: book.php,v 1.4 2008/07/22 15:13:29 skodak Exp $
+<?PHP // $Id: book.php,v 1.5 2008/08/13 23:21:14 skodak Exp $
$string['modulename'] = 'Book';
$string['modulenameplural'] = 'Books';
$string['maindirectory'] = 'Main directory';
$string['fileordir'] = 'File or directory';
+$string['book:read'] = 'Read book';
+$string['book:edit'] = 'Edit book chapters';
+$string['book:viewhiddenchapters'] = 'View hidden book chapters';
+$string['book:import'] = 'Import chapters';
+$string['book:print'] = 'Print book';
+$string['book:exportimscp'] = 'Export book as IMS content package';
+
?>
-<?PHP // $Id: lib.php,v 1.5 2008/07/26 22:58:27 stronk7 Exp $
+<?PHP // $Id: lib.php,v 1.6 2008/08/13 23:21:14 skodak Exp $
define('NUM_NONE', '0');
define('NUM_NUMBERS', '1');
define('NUM_INDENTED', '3');
-if (!isset($CFG->book_tocwidth)) {
- set_config("book_tocwidth", 180); // default toc width
-}
-
function book_get_numbering_types() {
return array (NUM_NONE => get_string('numbering0', 'book'),
NUM_NUMBERS => get_string('numbering1', 'book'),
$contents = fread($handle, filesize($file));
fclose($handle);
//extract title
+ $chapter = new object();
if (preg_match('/<title>([^<]+)<\/title>/i', $contents, $matches)) {
$chapter->title = $matches[1];
} else {
}
foreach($chapters as $ch) {
$rel = substr($ch->importsrc, 0, strrpos($ch->importsrc, '/')+1);
- $base = $coursebase.strtr(urlencode($rel), array("%2F" => "/")); //for better internationalization (dlnsk)
+ $base = $coursebase.strtr(urlencode($rel), array("%2F" => "/")); //for better internationalization (dlnsk)
$modified = false;
//image relinking
if ($ch->importsrc && preg_match_all('/(<img[^>]+src=")([^"]+)("[^>]*>)/i', $ch->content, $images)) {
-<?PHP // $Id: print.php,v 1.2 2007/05/20 06:00:26 skodak Exp $
+<?PHP // $Id: print.php,v 1.3 2008/08/13 23:21:14 skodak Exp $
require_once('../../config.php');
require_once('lib.php');
}
require_course_login($course, true, $cm);
-
+
if (!$book = get_record('book', 'id', $cm->instance)) {
error('Course module is incorrect');
}
error('Printing is disabled');
}
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_capability('mod/book:read', $context);
+require_capability('mod/book:print', $context);
+
//check all variables
if ($chapterid) {
//single chapter printing
@header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
@header('Pragma: no-cache');
-@header('Expires: ');
+@header('Expires: ');
@header('Accept-Ranges: none');
@header('Content-type: text/html; charset=utf-8');
-<?PHP // $Id: restorelib.php,v 1.2 2006/03/29 06:21:56 skodak Exp $
+<?PHP // $Id: restorelib.php,v 1.3 2008/08/13 23:21:13 skodak Exp $
//This php script contains all the stuff to backup/restore
//book mods
//$GLOBALS['traverse_array']=""; //Debug
//Now, build the BOOK record structure
+ $book = new object();
$book->course = $restore->course_id;
$book->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
$book->summary = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
$old_id = backup_todb($sub_info['#']['ID']['0']['#']);
//Now, build the ASSIGNMENT_CHAPTERS record structure
+ $chapter = new object();
$chapter->bookid = $new_book_id;
$chapter->pagenum = backup_todb($sub_info['#']['PAGENUM']['0']['#']);
$chapter->subchapter = backup_todb($sub_info['#']['SUBCHAPTER']['0']['#']);
if ($log->cmid) {
//Get the new_id of the chapter (to recode the url field)
$ch = backup_getid($restore->backup_unique_code,"book_chapters",$log->info);
- if ($pag) {
+ if ($ch) {
$log->url = "view.php?id=".$log->cmid."&chapterid=".$ch->new_id;
$log->info = $ch->new_id;
$status = true;
-<?PHP // $Id: show.php,v 1.2 2006/11/21 19:26:36 skodak Exp $
+<?PHP // $Id: show.php,v 1.3 2008/08/13 23:21:14 skodak Exp $
require('teacheraccess.php'); //page only for teachers
///switch hidden state
+$chapter = new object();
$chapter->hidden = $chapter->hidden ? 0 : 1;
///add slashes to all text fields
-/* $Id: book_theme.css,v 1.2 2007/05/20 06:00:30 skodak Exp $*/
+/* $Id: styles.php,v 1.1 2008/08/13 23:21:13 skodak Exp $*/
/* later should be defined in themes*/
border:0px;
}
+#mod-book-view table.booktable {
+ border:0;
+}
+
+#mod-book-view .bookexport {
+ float:left;
+}
+
+#mod-book-view .booknav {
+ float:right;
+}
+
+#mod-book-view table.booktable tr.tocandchapter {
+ vertical-align:text-top;
+}
+
+#mod-book-view div.faq {
+ font-size: 0.7em;
+}
+
/* == TOC styles == */
/* toc style NONE */
+.book_toc_none {
+ font-size: 0.8em;
+}
.book_toc_none ul {
margin-left: 5px;
padding-left: 0px;
/* toc style NUMBERED */
+.book_toc_numbered {
+ font-size: 0.8em;
+}
.book_toc_numbered ul {
margin-left: 5px;
padding-left: 0px;
/*toc style BULLETS */
+.book_toc_bullets {
+ font-size: 0.8em;
+}
.book_toc_bullets ul {
margin-left: 5px;
padding-left: 0px;
/* toc style INDENTED*/
+.book_toc_indented {
+ font-size: 0.8em;
+}
.book_toc_indented ul {
margin-left: 5px;
padding-left: 0px;
-<?PHP // $Id: teacheraccess.php,v 1.2 2007/05/20 06:00:27 skodak Exp $
+<?PHP // $Id: teacheraccess.php,v 1.3 2008/08/13 23:21:14 skodak Exp $
///standard routine to allow only teachers in
///check of $id and $chapterid parameters
-require_once('../../config.php');
+require('../../config.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$chapterid = required_param('chapterid', PARAM_INT); // Chapter ID
-require_login();
-
if (!confirm_sesskey()) {
- error(get_string('confirmsesskeybad', 'error'));
+ error(get_string('confirmsesskeybad', 'error'));
}
if (!$cm = get_coursemodule_from_id('book', $id)) {
error('Course Module ID was incorrect');
error('Course is misconfigured');
}
+require_login($course, false, $cm);
+
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-require_capability('moodle/course:manageactivities', $context);
+require_capability('mod/book:edit', $context);
if (!$book = get_record('book', 'id', $cm->instance)) {
error('Course module is incorrect');
-<?PHP // $Id: toc.php,v 1.3 2007/05/20 06:00:30 skodak Exp $
+<?PHP // $Id: toc.php,v 1.4 2008/08/13 23:21:14 skodak Exp $
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
-
+
/// included from mod/book/view.php and print.php
///
/// uses:
$title = '';
$first = 1;
-if (!isset($print)) {
- $print = 0;
-}
-
switch ($book->numbering) {
case NUM_NONE:
$toc .= '<div class="book_toc_none">';
}
}
$titles[$ch->id] = $title;
- $toc .= '<a title="'.htmlspecialchars($title).'" href="#ch'.$ch->id.'">'.$title.'</a>';
+ $toc .= '<a title="'.s($title).'" href="#ch'.$ch->id.'">'.$title.'</a>';
$toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
$first = 0;
}
}
$toc .= '</ul></li></ul>';
} else if ($edit) { ///teacher's TOC
- $toc .= '<font size="-1"><ul>';
+ $toc .= '<ul>';
$i = 0;
foreach($chapters as $ch) {
$i++;
$currsubtitle = ' ';
}
} else {
- $toc .= '<a title="'.htmlspecialchars($title).'" href="view.php?id='.$cm->id.'&chapterid='.$ch->id.'">'.$title.'</a>';
+ $toc .= '<a title="'.s($title).'" href="view.php?id='.$cm->id.'&chapterid='.$ch->id.'">'.$title.'</a>';
}
$toc .= ' ';
if ($i != 1) {
if ($i != count($chapters)) {
$toc .= ' <a title="'.get_string('down').'" href="move.php?id='.$cm->id.'&chapterid='.$ch->id.'&up=0&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/down.gif" height="11" class="iconsmall" alt="'.get_string('down').'" /></a>';
}
- $toc .= ' <a title="'.get_string('edit').'" href="edit.php?id='.$cm->id.'&chapterid='.$ch->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" height="11" class="iconsmall" alt="'.get_string('edit').'" /></a>';
+ $toc .= ' <a title="'.get_string('edit').'" href="edit.php?cmid='.$cm->id.'&id='.$ch->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" height="11" class="iconsmall" alt="'.get_string('edit').'" /></a>';
$toc .= ' <a title="'.get_string('delete').'" href="delete.php?id='.$cm->id.'&chapterid='.$ch->id.'&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/delete.gif" height="11" class="iconsmall" alt="'.get_string('delete').'" /></a>';
if ($ch->hidden) {
$toc .= ' <a title="'.get_string('show').'" href="show.php?id='.$cm->id.'&chapterid='.$ch->id.'&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/show.gif" height="11" class="iconsmall" alt="'.get_string('show').'" /></a>';
} else {
$toc .= ' <a title="'.get_string('hide').'" href="show.php?id='.$cm->id.'&chapterid='.$ch->id.'&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/hide.gif" height="11" class="iconsmall" alt="'.get_string('hide').'" /></a>';
}
- $toc .= ' <a title="'.get_string('addafter', 'book').'" href="edit.php?id='.$cm->id.'&pagenum='.$ch->pagenum.'&subchapter='.$ch->subchapter.'"><img src="pix/add.gif" height="11" class="iconsmall" alt="'.get_string('addafter', 'book').'" /></a>';
+ $toc .= ' <a title="'.get_string('addafter', 'book').'" href="edit.php?cmid='.$cm->id.'&pagenum='.$ch->pagenum.'&subchapter='.$ch->subchapter.'"><img src="pix/add.gif" height="11" class="iconsmall" alt="'.get_string('addafter', 'book').'" /></a>';
$toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
$first = 0;
}
- $toc .= '</ul></li></ul></font>';
+ $toc .= '</ul></li></ul>';
} else { //normal students view
- $toc .= '<font size="-1"><ul>';
+ $toc .= '<ul>';
foreach($chapters as $ch) {
$title = trim(strip_tags($ch->title));
if (!$ch->hidden) {
$currsubtitle = ' ';
}
} else {
- $toc .= '<a title="'.htmlspecialchars($title).'" href="view.php?id='.$cm->id.'&chapterid='.$ch->id.'">'.$title.'</a>';
+ $toc .= '<a title="'.s($title).'" href="view.php?id='.$cm->id.'&chapterid='.$ch->id.'">'.$title.'</a>';
}
$toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
$first = 0;
}
}
- $toc .= '</ul></li></ul></font>';
+ $toc .= '</ul></li></ul>';
}
$toc .= '</div>';
-<?PHP // $Id: version.php,v 1.4 2007/09/24 08:47:36 skodak Exp $
+<?PHP // $Id: version.php,v 1.5 2008/08/13 23:21:13 skodak Exp $
/////////////////////////////////////////////////////////////////////////////////
/// Called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2007052001; // The current module version (Date: YYYYMMDDXX)
-$module->requires = 2007021505; // Requires this Moodle version
+$module->version = 2008081402; // The current module version (Date: YYYYMMDDXX)
+$module->requires = 2007101512; // Requires this Moodle version
$module->cron = 0; // Period for cron to check this module (secs)
-$release = "1.4alpha"; // User-friendly version number
+$release = "1.5beta"; // User-friendly version number
?>
-<?PHP // $Id: view.php,v 1.5 2008/03/25 20:19:49 poltawski Exp $
+<?PHP // $Id: view.php,v 1.6 2008/08/13 23:21:14 skodak Exp $
-require_once('../../config.php');
+require('../../config.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
-$edit = optional_param('edit', -1, PARAM_BOOL); // Edit mode
+$edit = optional_param('edit', -1, PARAM_BOOL); // Edit mode
// =========================================================================
// security checks START - teachers edit; students view
require_course_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-$allowedit = has_capability('moodle/course:manageactivities', $context);
+require_capability('mod/book:read', $context);
+
+$allowedit = has_capability('mod/book:edit', $context);
+$allowimport = has_capability('mod/book:import', $context);
+$allowprint = has_capability('mod/book:print', $context) and !$book->disableprinting;
+$allowexport = has_capability('mod/book:exportimscp', $context);
+$viewhidden = has_capability('mod/book:viewhiddenchapters', $context);
if ($allowedit) {
if ($edit != -1) {
}
/// read chapters
-$select = $allowedit ? "bookid = $book->id" : "bookid = $book->id AND hidden = 0";
+$select = $viewhidden ? "bookid = $book->id" : "bookid = $book->id AND hidden = 0";
$chapters = get_records_select('book_chapters', $select, 'pagenum', 'id, pagenum, subchapter, title, hidden');
if (!$chapters) {
if ($allowedit) {
- redirect('edit.php?id='.$cm->id); //no chapters - add new one
+ redirect('edit.php?cmid='.$cm->id); //no chapters - add new one
die;
} else {
error('Error reading book chapters.');
unset($chapterid);
/// chapter is hidden for students
-if (!$allowedit and $chapter->hidden) {
+if (!$viewhidden and $chapter->hidden) {
error('Error reading book chapters.');
}
$course->fullname,
$navigation,
'',
- '<style type="text/css">@import url('.$CFG->wwwroot.'/mod/book/book_theme.css);</style>',
+ '',
true,
$buttons,
navmenu($course, $cm)
}
/// prepare print icons
-if ($book->disableprinting) {
+if (!$allowprint) {
$printbook = '';
$printchapter = '';
} else {
}
// prepare $toc and $currtitle, $currsubtitle
+$print = 0;
require('toc.php');
if ($edit) {
$tocwidth = $CFG->book_tocwidth;
}
-$doimport = ($allowedit and $edit) ? '<a href="import.php?id='.$cm->id.'">'.get_string('doimport', 'book').'</a>' : '';
+$doimport = ($allowimport and $edit) ? '<div>(<a href="import.php?id='.$cm->id.'">'.get_string('doimport', 'book').'</a>)</div>' : '';
/// Enable the IMS CP button
-$generateimscp = ($allowedit) ? '<a title="'.get_string('generateimscp', 'book').'" href="generateimscp.php?id='.$cm->id.'"><img class="bigicon" src="pix/generateimscp.gif" height="24" width="24" border="0"></img></a>' : '';
+$generateimscp = ($allowexport) ? '<a title="'.get_string('generateimscp', 'book').'" href="generateimscp.php?id='.$cm->id.'"><img class="bigicon" src="pix/generateimscp.gif" alt="'.get_string('generateimscp', 'book').'"></img></a>' : '';
// =====================================================
// =====================================================
?>
-<table border="0" cellspacing="0" width="100%" valign="top" cellpadding="2">
+<table class="booktable" width="100%" cellspacing="0" cellpadding="2">
<!-- subchapter title and upper navigation row //-->
<tr>
- <td width="<?php echo $tocwidth ?>" valign="bottom">
+ <td style="width:<?php echo $tocwidth ?>px" valign="bottom">
<?php
print_string('toc', 'book');
- if (!empty($doimport)) {
- echo "<br/>($doimport)";
- }
+ echo $doimport;
?>
</td>
- <td valign="top">
- <table border="0" cellspacing="0" width="100%" valign="top" cellpadding="0">
- <tr>
- <td nowrap="nowrap" align="left"><?php echo $printbook.$printchapter.$generateimscp ?></td>
- <td nowrap ="nowrap" align="right"><?php echo $chnavigation ?></td>
- </tr>
- </table>
+ <td>
+ <div class="bookexport"><?php echo $printbook.$printchapter.$generateimscp ?></div>
+ <div class="booknav"><?php echo $chnavigation ?></div>
</td>
</tr>
<!-- toc and chapter row //-->
-<tr>
- <td width="<?php echo $tocwidth ?>" valign="top" align="left">
+<tr class="tocandchapter">
+ <td style="width:<?php echo $tocwidth ?>px" align="left"><div class="clearer"> </div>
<?php
print_box_start('generalbox');
echo $toc;
print_box_end();
if ($allowedit and $edit) {
- echo '<font size="1"><br />';
+ echo '<div class="faq">';
helpbutton('faq', get_string('faq','book'), 'book', true, true);
- echo '</font>';
+ echo '</div>';
}
?>
</td>
- <td valign="top" align="right">
+ <td align="right"><div class="clearer"> </div>
<?php
print_box_start('generalbox');
$content = '';
echo '</div>';
print_box_end();
/// lower navigation
- echo '<p>'.$chnavigation.'</p>';
+ echo '<div class="booknav">'.$chnavigation.'</div>';
?>
</td>
</tr>