Commit c6d2eda2 authored by Petr Skoda's avatar Petr Skoda
Browse files

book v1.5beta compatible with 1.9.1 or later, not 2.0dev

parent 817e3a80
$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 $
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// // // //
...@@ -42,7 +42,7 @@ Many ideas and code were taken from other Moodle modules and Moodle itself;-) ...@@ -42,7 +42,7 @@ Many ideas and code were taken from other Moodle modules and Moodle itself;-)
Installation: Installation:
* see http://docs.moodle.org/en/Installing_contributed_modules_or_plugins * 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 * easy to use - new teachers can quickly create multipage study materials
* two levels - only chapters and subchapters * two levels - only chapters and subchapters
...@@ -110,5 +110,11 @@ CHANGELOG: ...@@ -110,5 +110,11 @@ CHANGELOG:
* compatible with 1.8 * compatible with 1.8
* export link enabled - thanks Eloy! * export link enabled - thanks Eloy!
* no new features * 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 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 // Manage all uploaded files in a course file area
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
admin_externalpage_print_header($adminroot); admin_externalpage_print_header($adminroot);
print_heading(get_string("publicsitefileswarning"), "center", 2); print_heading(get_string("publicsitefileswarning"), "center", 2);
} }
} else { } else {
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>"; echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>";
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"coursefiles.php\">"; echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"coursefiles.php\">";
echo "<div>"; echo "<div>";
echo "<table><tr><td colspan=\"2\">"; echo "<table><tr><td colspan=\"2\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
...@@ -211,7 +211,7 @@ ...@@ -211,7 +211,7 @@
echo "</div>"; echo "</div>";
echo "</form>"; echo "</form>";
echo "<form action=\"coursefiles.php\" method=\"get\">"; echo "<form action=\"coursefiles.php\" method=\"get\">";
echo "<div>"; echo "<div>";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />'; echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />"; echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />"; echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
......
<?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
),
);
?>
<!-- $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('../../config.php');
require_once('lib.php'); require_once('lib.php');
require_once('edit_form.php');
$id = required_param('id', PARAM_INT); // Course Module ID $cmid = required_param('cmid', PARAM_INT); // Book Course Module ID
$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID $chapterid = optional_param('id', 0, PARAM_INT); // Chapter ID
$pagenum = optional_param('pagenum', 0, PARAM_INT); $pagenum = optional_param('pagenum', 0, PARAM_INT);
$subchapter = optional_param('subchapter', 0, PARAM_BOOL); $subchapter = optional_param('subchapter', 0, PARAM_BOOL);
// ========================================================================= // =========================================================================
// security checks START - only teachers edit // 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 Module ID was incorrect');
} }
...@@ -21,88 +21,83 @@ if (!$course = get_record('course', 'id', $cm->course)) { ...@@ -21,88 +21,83 @@ if (!$course = get_record('course', 'id', $cm->course)) {
error('Course is misconfigured'); error('Course is misconfigured');
} }
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $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)) { if (!$book = get_record('book', 'id', $cm->instance)) {
error('Course module is incorrect'); error('Course module is incorrect');
} }
$chapter = get_record('book_chapters', 'id', $chapterid); if ($chapterid) {
if (!$chapter = get_record('book_chapters', 'id', $chapterid)) {
//check all variables error('Incorrect chapter id');
unset($id); }
unset($chapterid);
if ($chapter) {
if ($chapter->bookid != $book->id) {//chapter id not in this book!!!! if ($chapter->bookid != $book->id) {//chapter id not in this book!!!!
error('Chapter not part of this book!'); error('Chapter not part of this book!');
} }
$pagenum = $chapter->pagenum;
} else { } else {
$pagenum = (integer)$pagenum; $chapter = null;
} }
//check all variables
unset($cmid);
unset($chapterid);
// ========================================================================= // =========================================================================
// security checks END // 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 data submitted, then process and store.
if (($form = data_submitted()) && (confirm_sesskey())) { if ($mform->is_cancelled()) {
//TODO: skip it for now if (empty($chapter->id)) {
//prepare data - security checks redirect("view.php?id=$cm->id");
//$form->title = clean_text($form->title, FORMAT_HTML);
//$form->content = clean_text($form->content, FORMAT_HTML);
if (isset($form->subchapter) ) {
$form->subchapter = 1;
} else { } else {
$form->subchapter = 0; redirect("view.php?id=$cm->id&chapterid=$chapter->id");
} }
if ($chapter) {
/// editing existing chapter } else if ($data = $mform->get_data(false)) {
$chapter->content = $form->content;
$chapter->title = $form->title; if ($data->id) {
$chapter->subchapter = $form->subchapter; if (!update_record('book_chapters', addslashes_recursive($data))) {
$chapter->timemodified = time();
$chapter->importsrc = addslashes($chapter->importsrc); //use already stored importsrc
if (!update_record('book_chapters', $chapter)) {
error('Could not update your book'); 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, '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 { } else {
/// adding new chapter /// adding new chapter
$chapter->bookid = $book->id; $data->bookid = $book->id;
$chapter->pagenum = $form->pagenum + 1; //place after given pagenum, lets hope it is a number $data->hidden = 0;
$chapter->subchapter = $form->subchapter; $data->timecreated = time();
$chapter->title = $form->title; $data->timemodified = time();
$chapter->content = $form->content; $data->importsrc = '';
$chapter->hidden = 0;
$chapter->timecreated = time(); // make room for new page
$chapter->timemodified = $chapter->timecreated; $sql = "UPDATE {$CFG->prefix}book_chapters
$chapter->importsrc = ''; SET pagenum = pagenum + 1
WHERE bookid = $book->id AND pagenum >= $data->pagenum";
$chapters = get_records('book_chapters', 'bookid', $book->id, 'pagenum', 'id, pagenum'); execute_sql($sql, false);
if ($chapters) {
foreach($chapters as $ch) { if (!$data->id = insert_record('book_chapters', addslashes_recursive($data))) {
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)) {
error('Could not insert a new chapter'); 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, '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); book_check_structure($book->id);
redirect("view.php?id=$cm->id&chapterid=$chapter->id"); redirect("view.php?id=$cm->id&chapterid=$data->id");
die; die;
} }
...@@ -112,30 +107,18 @@ $strbooks = get_string('modulenameplural', 'book'); ...@@ -112,30 +107,18 @@ $strbooks = get_string('modulenameplural', 'book');
$stredit = get_string('edit'); $stredit = get_string('edit');
$pageheading = get_string('editingchapter', 'book'); $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 ///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); print_header("$course->shortname: $book->name", $course->fullname, $navigation);
$icon = '<img align="absmiddle" height="16" width="16" src="icon_chapter.gif" />&nbsp;'; $icon = '<img class="icon" src="icon_chapter.gif" alt="" />&nbsp;';
print_heading_with_help($pageheading, 'edit', 'book', $icon); print_heading_with_help($pageheading, 'edit', 'book', $icon);
print_simple_box_start('center', '');
include('edit.html');
print_simple_box_end();
if ($usehtmleditor ) { $mform->display();
use_html_editor();
}
print_footer($course); print_footer($course);
......
<?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 $
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// // // //
...@@ -24,15 +24,13 @@ ...@@ -24,15 +24,13 @@
// // // //
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
require_once('../../config.php'); require('../../config.php');
require_once('lib.php'); require_once('lib.php');
require_once($CFG->dirroot . '/backup/lib.php'); require_once($CFG->dirroot.'/backup/lib.php');
require_once($CFG->dirroot . '/lib/filelib.php'); require_once($CFG->libdir.'/filelib.php');
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
require_login();
if (!$cm = get_coursemodule_from_id('book', $id)) { if (!$cm = get_coursemodule_from_id('book', $id)) {
error('Course Module ID was incorrect'); error('Course Module ID was incorrect');
} }
...@@ -41,9 +39,12 @@ if (!$course = get_record('course', 'id', $cm->course)) { ...@@ -41,9 +39,12 @@ if (!$course = get_record('course', 'id', $cm->course)) {
error('Course is misconfigured'); error('Course is misconfigured');
} }
require_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $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)) { if (!$book = get_record('book', 'id', $cm->instance)) {
error('Course module is incorrect'); error('Course module is incorrect');
} }
...@@ -71,7 +72,7 @@ add_to_log($course->id, 'book', 'generateimscp', 'generateimscp.php?id='.$cm->id ...@@ -71,7 +72,7 @@ add_to_log($course->id, 'book', 'generateimscp', 'generateimscp.php?id='.$cm->id
/// Now delete all the temp dirs /// Now delete all the temp dirs
delete_dir_contents($CFG->dataroot . "/$cm->course/moddata/book/$book->id"); delete_dir_contents($CFG->dataroot . "/$cm->course/moddata/book/$book->id");
/// Now serve the file /// 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 the default imsmanifest plus contents for the book chapters passed as array
...@@ -192,7 +193,7 @@ $cssresource = ' <resource identifier="RES-' . $book->course . '-' . $book-> ...@@ -192,7 +193,7 @@ $cssresource = ' <resource identifier="RES-' . $book->course . '-' . $book->
} }
/** /**
* 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 * one array of local images to be included
*/ */
function chapter2html($chapter, $courseid, $bookid) { 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('lib.php');
require_once('import_form.php');
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$subchapter = optional_param('subchapter', 0, PARAM_BOOL);
$cancel = optional_param('cancel', 0, PARAM_BOOL);
// ========================================================================= // =========================================================================
// security checks START - only teachers edit // security checks START - only teachers edit
// ========================================================================= // =========================================================================
require_login();
if (!$cm = get_coursemodule_from_id('book', $id)) { if (!$cm = get_coursemodule_from_id('book', $id)) {
error('Course Module ID was incorrect'); error('Course Module ID was incorrect');
...@@ -20,8 +18,10 @@ if (!$course = get_record('course', 'id', $cm->course)) { ...@@ -20,8 +18,10 @@ if (!$course = get_record('course', 'id', $cm->course)) {
error('Course is misconfigured'); error('Course is misconfigured');
} }
require_login($course, false, $cm);
$context = get_context_instance(CONTEXT_MODULE