Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
2c1e98e6
Commit
2c1e98e6
authored
Dec 08, 2010
by
Petr Skoda
Browse files
conversion to 2.0
parent
3c5e59cb
Changes
19
Hide whitespace changes
Inline
Side-by-side
README
View file @
2c1e98e6
Book module for Moodle
Copyright (C) 2004-2010 Petr Skoda (http:skodak.org)
Copyright (C) 2004-2010 Petr Skoda (http:
//
skodak.org)
This program is free software; you can redistribute it and/or modify
...
...
@@ -28,7 +28,6 @@ Installation:
* see http://docs.moodle.org/en/Installing_contributed_modules_or_plugins
List of features - version 2.0:
* easy to use - new teachers can quickly create multipage study materials
* two levels - only chapters and subchapters
* possible automatic chapter numbering
...
...
@@ -39,11 +38,10 @@ List of features - version 2.0:
* support for global searching in study materials (see contrib/search)
* import from html files (relinking of images, flash, Java applets and
relative links)
* works with
MySQL and PostgreSQL
databases
* works with
all supported
databases
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.
...
...
@@ -55,7 +53,7 @@ Intentionally omitted features:
Save page as... in print view
Future:
* I like eXe editor, I would like to improve Book in this direction ...
;-)
* I like eXe editor, I would like to improve Book in this direction ...
CHANGELOG:
== 1.1RC1 - 2004/11/15 =======================================================
...
...
db/upgrade.php
View file @
2c1e98e6
...
...
@@ -66,17 +66,7 @@ function xmldb_book_upgrade($oldversion) {
$dbman
->
add_field
(
$table
,
$field
);
}
// conditionally migrate to html format in intro
if
(
$CFG
->
texteditors
!==
'textarea'
)
{
$rs
=
$DB
->
get_recordset
(
'book'
,
array
(
'introformat'
=>
FORMAT_MOODLE
),
''
,
'id,intro,introformat'
);
foreach
(
$rs
as
$r
)
{
$r
->
intro
=
text_to_html
(
$r
->
intro
,
false
,
false
,
true
);
$r
->
introformat
=
FORMAT_HTML
;
$DB
->
update_record
(
'book'
,
$r
);
upgrade_set_timeout
();
}
$rs
->
close
();
}
$DB
->
set_field
(
'book'
,
'introformat'
,
FORMAT_HTML
,
array
());
// book savepoint reached
upgrade_mod_savepoint
(
true
,
2010120802
,
'book'
);
...
...
@@ -114,6 +104,7 @@ function xmldb_book_upgrade($oldversion) {
}
//TODO: add contentformat into book_chapters
//TODO: migrate the legacy file.php links to new pluginfile.php and file areas per chapter
...
...
delete.php
View file @
2c1e98e6
<?php
// This file is part of Book module for 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/>.
require
(
'teacheraccess.php'
);
//page only for teachers
/**
* Delete book chapter
*
* @package mod
* @subpackage book
* @copyright 2004-2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require
(
'../../config.php'
);
require_once
(
$CFG
->
dirroot
.
'/mod/book/locallib.php'
);
$confirm
=
optional_param
(
'confirm'
,
0
,
PARAM_BOOL
);
$id
=
required_param
(
'id'
,
PARAM_INT
);
// Course Module ID
$chapterid
=
required_param
(
'chapterid'
,
PARAM_INT
);
// Chapter ID
$confirm
=
optional_param
(
'confirm'
,
0
,
PARAM_BOOL
);
$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
);
require_sesskey
();
$context
=
get_context_instance
(
CONTEXT_MODULE
,
$cm
->
id
);
require_capability
(
'mod/book:edit'
,
$context
);
$chapter
=
$DB
->
get_record
(
'book_chapters'
,
array
(
'id'
=>
$chapterid
,
'bookid'
=>
$book
->
id
),
'*'
,
MUST_EXIST
);
///header and strings
...
...
@@ -18,29 +54,26 @@ print_header("$course->shortname: $book->name", $course->fullname, $navigation);
///form processing
if
(
$confirm
)
{
// the operation was confirmed.
if
(
!
$chapter
->
subchapter
)
{
//delete all its subchapters if any
$chapters
=
get_records
(
'book_chapters'
,
'bookid'
,
$book
->
id
,
'pagenum'
,
'id, subchapter'
);
$chapters
=
$DB
->
get_records
(
'book_chapters'
,
array
(
'bookid'
=>
$book
->
id
)
,
'pagenum'
,
'id, subchapter'
);
$found
=
false
;
foreach
(
$chapters
as
$ch
)
{
if
(
$ch
->
id
==
$chapter
->
id
)
{
$found
=
true
;
}
else
if
(
$found
and
$ch
->
subchapter
)
{
if
(
!
delete_records
(
'book_chapters'
,
'id'
,
$ch
->
id
))
{
error
(
'Could not update your book'
);
}
$DB
->
delete_records
(
'book_chapters'
,
array
(
'id'
=>
$ch
->
id
));
}
else
if
(
$found
)
{
break
;
}
}
}
if
(
!
delete_records
(
'book_chapters'
,
'id'
,
$chapter
->
id
))
{
error
(
'Could not update your book'
);
}
$DB
->
delete_records
(
'book_chapters'
,
array
(
'id'
=>
$chapter
->
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
,
$book
->
id
,
$cm
->
id
);
book_check_structure
(
$book
->
id
);
redirect
(
'view.php?id='
.
$cm
->
id
);
die
;
}
else
{
// the operation has not been confirmed yet so ask the user to do so
if
(
$chapter
->
subchapter
)
{
...
...
edit.php
View file @
2c1e98e6
<?php
// This file is part of Book module for 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/>.
/**
* Edit book chapter
*
* @package mod
* @subpackage book
* @copyright 2004-2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require
(
'../../config.php'
);
require_once
(
$CFG
->
dirroot
.
'/mod/book/locallib.php'
);
require_once
(
'edit_form.php'
);
require_once
(
$CFG
->
dirroot
.
'edit_form.php'
);
$cmid
=
required_param
(
'cmid'
,
PARAM_INT
);
// Book Course Module ID
$chapterid
=
optional_param
(
'id'
,
0
,
PARAM_INT
);
// Chapter ID
...
...
@@ -13,30 +36,17 @@ $subchapter = optional_param('subchapter', 0, PARAM_BOOL);
// security checks START - only teachers edit
// =========================================================================
if
(
!
$cm
=
get_coursemodule_from_id
(
'book'
,
$cmid
))
{
error
(
'Course Module ID was incorrect'
);
}
if
(
!
$course
=
get_record
(
'course'
,
'id'
,
$cm
->
course
))
{
error
(
'Course is misconfigured'
);
}
$cm
=
get_coursemodule_from_id
(
'book'
,
$cmid
,
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
=
get_context_instance
(
CONTEXT_MODULE
,
$cm
->
id
);
require_capability
(
'mod/book:edit'
,
$context
);
if
(
!
$book
=
get_record
(
'book'
,
'id'
,
$cm
->
instance
))
{
error
(
'Course module is incorrect'
);
}
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!'
);
}
$chapter
=
$DB
->
get_record
(
'book_chapters'
,
array
(
'id'
=>
$chapterid
,
'bookid'
=>
$book
->
id
),
'*'
,
MUST_EXIST
);
}
else
{
$chapter
=
null
;
}
...
...
@@ -66,12 +76,11 @@ if ($mform->is_cancelled()) {
redirect
(
"view.php?id=
$cm->id
&chapterid=
$chapter->id
"
);
}
}
else
if
(
$data
=
$mform
->
get_data
(
false
))
{
}
else
if
(
$data
=
$mform
->
get_data
())
{
if
(
$data
->
id
)
{
if
(
!
update_record
(
'book_chapters'
,
addslashes_recursive
(
$data
)))
{
error
(
'Could not update your book'
);
}
$DB
->
update_record
(
'book_chapters'
,
$data
);
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='
.
$data
->
id
,
$book
->
id
,
$cm
->
id
);
...
...
@@ -84,21 +93,19 @@ if ($mform->is_cancelled()) {
$data
->
importsrc
=
''
;
// make room for new page
$sql
=
"UPDATE
{
$CFG
->
prefix
}
book_chapters
$sql
=
"UPDATE
{
book_chapters
}
SET pagenum = pagenum + 1
WHERE bookid =
$book->id
AND pagenum >=
$data->pagenum
"
;
execute_sql
(
$sql
,
false
);
WHERE bookid = ? AND pagenum >= ?"
;
$DB
->
execute
(
$sql
,
array
(
$book
->
id
,
$data
->
pagenum
));
$data
->
id
=
$DB
->
insert_record
(
'book_chapters'
,
$data
);
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='
.
$data
->
id
,
$book
->
id
,
$cm
->
id
);
}
book_check_structure
(
$book
->
id
);
redirect
(
"view.php?id=
$cm->id
&chapterid=
$data->id
"
);
die
;
}
/// Otherwise fill and print the form.
...
...
edit_form.php
View file @
2c1e98e6
<?php
// This file is part of Book module for 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/>.
/**
* Chapter edit form
*
* @package mod
* @subpackage book
* @copyright 2004-2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined
(
'MOODLE_INTERNAL'
)
||
die
;
...
...
@@ -8,7 +31,7 @@ class book_chapter_edit_form extends moodleform {
function
definition
()
{
global
$CFG
;
$mform
=
&
$this
->
_form
;
$mform
=
$this
->
_form
;
$cm
=
$this
->
_customdata
;
$mform
->
addElement
(
'header'
,
'general'
,
get_string
(
'edit'
));
...
...
@@ -21,7 +44,6 @@ class book_chapter_edit_form extends moodleform {
$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
);
...
...
@@ -42,7 +64,7 @@ class book_chapter_edit_form extends moodleform {
function
definition_after_data
()
{
global
$CFG
;
$mform
=
&
$this
->
_form
;
$mform
=
$this
->
_form
;
if
(
$mform
->
getElementValue
(
'id'
))
{
if
(
$mform
->
elementExists
(
'doimport'
))
{
...
...
import.php
View file @
2c1e98e6
<?php
// This file is part of Book module for 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 mod
* @subpackage book
* @copyright 2004-2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require
(
'../../config.php'
);
require_once
(
$CFG
->
dirroot
.
'/mod/book/locallib.php'
);
...
...
@@ -10,23 +33,15 @@ $id = required_param('id', PARAM_INT); // Course Module ID
// security checks START - only teachers edit
// =========================================================================
if
(
!
$cm
=
get_coursemodule_from_id
(
'book'
,
$id
))
{
error
(
'Course Module ID was incorrect'
);
}
if
(
!
$course
=
get_record
(
'course'
,
'id'
,
$cm
->
course
))
{
error
(
'Course is misconfigured'
);
}
$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
=
get_context_instance
(
CONTEXT_MODULE
,
$cm
->
id
);
require_capability
(
'mod/book:import'
,
$context
);
if
(
!
$book
=
get_record
(
'book'
,
'id'
,
$cm
->
instance
))
{
error
(
'Course module is incorrect'
);
}
//check all variables
unset
(
$id
);
...
...
@@ -94,12 +109,9 @@ if ($mform->is_cancelled()) {
foreach
(
$refs
as
$ref
)
{
$chapter
=
book_read_chapter
(
$coursebase
,
$ref
);
if
(
$chapter
)
{
$chapter
->
title
=
addslashes
(
$chapter
->
title
);
$chapter
->
content
=
addslashes
(
$chapter
->
content
);
$chapter
->
importsrc
=
addslashes
(
$chapter
->
importsrc
);
$chapter
->
bookid
=
$book
->
id
;
$chapter
->
pagenum
=
count_records
(
'book_chapters'
,
'bookid'
,
$book
->
id
)
+
1
;
$chapter
->
timecreated
=
time
();
$chapter
->
bookid
=
$book
->
id
;
$chapter
->
pagenum
=
$DB
->
count_records
(
'book_chapters'
,
array
(
'bookid'
=>
$book
->
id
)
+
1
;
$chapter
->
timecreated
=
time
();
$chapter
->
timemodified
=
time
();
echo
"imsrc:"
.
$chapter
->
importsrc
;
if
((
$data
->
subchapter
)
||
preg_match
(
'/_sub\.htm/i'
,
$chapter
->
importsrc
))
{
//if filename or directory starts with sub_* treat as subdirecotories
...
...
@@ -107,9 +119,8 @@ if ($mform->is_cancelled()) {
}
else
{
$chapter
->
subchapter
=
0
;
}
if
(
!
$chapter
->
id
=
insert_record
(
'book_chapters'
,
$chapter
))
{
error
(
'Could not update your book'
);
}
$chapter
->
id
=
$DB
->
insert_record
(
'book_chapters'
,
$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
);
}
...
...
import_form.php
View file @
2c1e98e6
<?php
// This file is part of Book module for 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 form
*
* @package mod
* @subpackage book
* @copyright 2004-2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once
(
$CFG
->
libdir
.
'/formslib.php'
);
...
...
@@ -6,7 +29,7 @@ class book_import_form extends moodleform {
function
definition
()
{
global
$CFG
;
$mform
=
&
$this
->
_form
;
$mform
=
$this
->
_form
;
$cm
=
$this
->
_customdata
;
$mform
->
addElement
(
'header'
,
'general'
,
get_string
(
'import'
));
...
...
@@ -36,7 +59,7 @@ class book_import_form extends moodleform {
$cm
=
$this
->
_customdata
;
$errors
=
parent
::
validation
(
$data
,
$files
);
$reference
=
stripslashes
(
$data
[
'reference'
]
)
;
$reference
=
$data
[
'reference'
];
if
(
$reference
!=
''
)
{
//null path is root
$reference
=
book_prepare_link
(
$reference
);
...
...
index.php
View file @
2c1e98e6
...
...
@@ -11,9 +11,7 @@ $id = required_param('id', PARAM_INT); // Course Module ID
// security checks START - teachers and students view
// =========================================================================
if
(
!
$course
=
get_record
(
'course'
,
'id'
,
$id
))
{
error
(
'Course ID is incorrect'
);
}
$course
=
$DB
->
get_record
(
'course'
,
array
(
'id'
=>
$id
),
'*'
,
MUST_EXIST
);
require_course_login
(
$course
,
true
);
...
...
@@ -65,7 +63,7 @@ $currentsection = '';
foreach
(
$books
as
$book
)
{
$nocleanoption
=
new
object
();
$nocleanoption
->
noclean
=
true
;
$book
->
summary
=
format_text
(
$book
->
summary
,
FORMAT_HTML
,
$nocleanoption
,
$course
->
id
);
$book
->
summary
=
format_text
(
$book
->
intro
,
$book
->
introformat
,
$nocleanoption
,
$course
->
id
);
$book
->
summary
=
'<span style="font-size:x-small;">'
.
$book
->
summary
.
'</span>'
;
if
(
!
$book
->
visible
)
{
...
...
@@ -76,7 +74,7 @@ foreach ($books as $book) {
$link
=
'<a href="view.php?id='
.
$book
->
coursemodule
.
'">'
.
$book
->
name
.
'</a>'
;
}
$count
=
count_records
(
'book_chapters'
,
'bookid'
,
$book
->
id
,
'hidden'
,
'0'
);
$count
=
$DB
->
count_records
(
'book_chapters'
,
array
(
'bookid'
=>
$book
->
id
,
'hidden'
=>
'0'
)
)
;
if
(
$course
->
format
==
'weeks'
or
$course
->
format
==
'topics'
)
{
$printsection
=
''
;
...
...
locallib.php
View file @
2c1e98e6
...
...
@@ -44,11 +44,16 @@ function book_get_numbering_types() {
/// Any other book functions go here. Each of them must have a name that
/// starts with book_
//check chapter ordering and
//make sure subchapter is not first in book
//hidden chapter must have all subchapters hidden too
/**
* check chapter ordering and make sure subchapter is not first
* in book hidden chapter must have all subchapters hidden too
* @param int $id
* @return void
*/
function
book_check_structure
(
$bookid
)
{
if
(
$chapters
=
get_records
(
'book_chapters'
,
'bookid'
,
$bookid
,
'pagenum'
,
'id, pagenum, subchapter, hidden'
))
{
global
$DB
;
if
(
$chapters
=
$DB
->
get_records
(
'book_chapters'
,
array
(
'bookid'
=>
$bookid
),
'pagenum'
,
'id, pagenum, subchapter, hidden'
))
{
$first
=
true
;
$hidesub
=
true
;
$i
=
1
;
...
...
@@ -63,7 +68,7 @@ function book_check_structure($bookid) {
$ch
->
hidden
=
$hidesub
?
true
:
$ch
->
hidden
;
}
$ch
->
pagenum
=
$i
;
update_record
(
'book_chapters'
,
$ch
);
$DB
->
update_record
(
'book_chapters'
,
$ch
);
$i
++
;
}
}
...
...
@@ -71,11 +76,11 @@ function book_check_structure($bookid) {
/// prepare button to turn chapter editing on - connected with course editing
function
book_edit_button
(
$
id
,
$courseid
,
$chapter
id
)
{
function
book_edit_button
(
$
book
,
$cm
,
$chapter
)
{
global
$CFG
,
$USER
;
if
(
isteacheredit
(
$course
id
))
{
if
(
has_capability
(
'mod/book:edit'
,
get_context_instance
(
CONTEXT_MODULE
,
$cm
->
id
))
)
{
if
(
!
empty
(
$USER
->
editing
))
{
$string
=
get_string
(
"turneditingoff"
);
$edit
=
'0'
;
...
...
@@ -84,8 +89,8 @@ function book_edit_button($id, $courseid, $chapterid) {
$edit
=
'1'
;
}
return
'<form method="get" action="'
.
$CFG
->
wwwroot
.
'/mod/book/view.php"><div>'
.
'<input type="hidden" name="id" value="'
.
$id
.
'" />'
.
'<input type="hidden" name="chapterid" value="'
.
$chapterid
.
'" />'
.
'<input type="hidden" name="id" value="'
.
$
cm
->
id
.
'" />'
.
'<input type="hidden" name="chapterid" value="'
.
$chapter
->
id
.
'" />'
.
'<input type="hidden" name="edit" value="'
.
$edit
.
'" />'
.
'<input type="submit" value="'
.
$string
.
'" /></div></form>'
;
}
else
{
...
...
@@ -179,13 +184,14 @@ function book_read_chapter($base, $ref) {
///relink images and relative links
function
book_relink
(
$id
,
$bookid
,
$courseid
)
{
global
$CFG
;
global
$CFG
,
$DB
;
if
(
$CFG
->
slasharguments
)
{
$coursebase
=
$CFG
->
wwwroot
.
'/file.php/'
.
$courseid
;
}
else
{
$coursebase
=
$CFG
->
wwwroot
.
'/file.php?file=/'
.
$courseid
;
}
$chapters
=
get_records
(
'book_chapters'
,
'bookid'
,
$bookid
,
'pagenum'
,
'id, pagenum, title, content, importsrc'
);
$chapters
=
$DB
->
get_records
(
'book_chapters'
,
array
(
'bookid'
=>
$bookid
)
,
'pagenum'
,
'id, pagenum, title, content, importsrc'
);
$originals
=
array
();
foreach
(
$chapters
as
$ch
)
{
$originals
[
$ch
->
importsrc
]
=
$ch
;
...
...
@@ -312,12 +318,7 @@ function book_relink($id, $bookid, $courseid) {
}
}
if
(
$modified
)
{
$ch
->
title
=
addslashes
(
$ch
->
title
);
$ch
->
content
=
addslashes
(
$ch
->
content
);
$ch
->
importsrc
=
addslashes
(
$ch
->
importsrc
);
if
(
!
update_record
(
'book_chapters'
,
$ch
))
{
error
(
'Could not update your book'
);
}
$DB
->
update_record
(
'book_chapters'
,
$ch
);
}
}
}
mod_form.php
View file @
2c1e98e6
<?php
// This file is part of Book module for 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/>.
/**
* Instance add/edit form
*
* @package mod
* @subpackage book
* @copyright 2004-2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined
(
'MOODLE_INTERNAL'
)
||
die
;
...
...
@@ -8,21 +31,23 @@ require_once($CFG->dirroot.'/course/moodleform_mod.php');
class
mod_book_mod_form
extends
moodleform_mod
{
function
definition
()
{
global
$CFG
;
$mform
=&
$this
->
_form
;
$mform
=
$this
->
_form
;
//-------------------------------------------------------------------------------
$mform
->
addElement
(
'header'
,
'general'
,
get_string
(
'general'
,
'form'
));
$mform
->
addElement
(
'text'
,
'name'
,
get_string
(
'name'
),
array
(
'size'
=>
'64'
));
$mform
->
setType
(
'name'
,
PARAM_TEXT
);
if
(
!
empty
(
$CFG
->
formatstringstriptags
))
{
$mform
->
setType
(
'name'
,
PARAM_TEXT
);
}
else
{
$mform
->
setType
(
'name'
,
PARAM_CLEANHTML
);
}
$mform
->
addRule
(
'name'
,
null
,
'required'
,
null
,
'client'
);
$mform
->
addElement
(
'htmleditor'
,
'summary'
,
get_string
(
'summary'
));
$mform
->
setType
(
'summary'
,
PARAM_RAW
);
$mform
->
addRule
(
'summary'
,
null
,
'required'
,
null
,
'client'
);
$mform
->
setHelpButton
(
'summary'
,
array
(
'writing'
,
'questions'
,
'richtext'
),
false
,
'editorhelpbutton'
);
$this
->
add_intro_editor
(
true
,
get_string
(
'summary'
));
$mform
->
addElement
(
'select'
,
'numbering'
,
get_string
(
'numbering'
,
'book'
),
book_get_numbering_types
());
$mform
->
setHelpButton
(
'numbering'
,
array
(
'numberingtype'
,
get_string
(
'numbering'
,
'book'
),
'book'
));
...
...
@@ -35,10 +60,10 @@ class mod_book_mod_form extends moodleform_mod {
$mform
->
setHelpButton
(
'customtitles'
,
array
(
'customtitles'
,
get_string
(
'customtitles'
,
'book'
),
'book'
));
$mform
->
setDefault
(
'customtitles'
,
0
);
$this
->
standard_coursemodule_elements
(
array
(
'groups'
=>
false
,
'groupmembersonly'
=>
true
,
'gradecat'
=>
false
));
//-------------------------------------------------------------------------------
$this
->
standard_coursemodule_elements
();
//-------------------------------------------------------------------------------
// buttons
$this
->
add_action_buttons
();
}
...
...
move.php
View file @
2c1e98e6
<?php
// This file is part of Book module for 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.