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
c6d2eda2
Commit
c6d2eda2
authored
Aug 13, 2008
by
Petr Skoda
Browse files
book v1.5beta compatible with 1.9.1 or later, not 2.0dev
parent
817e3a80
Changes
19
Hide whitespace changes
Inline
Side-by-side
README.txt
View file @
c6d2eda2
$Id: README.txt,v 1.
5
2008/0
7/22 14:59
:1
3
skodak Exp $
$Id: README.txt,v 1.
6
2008/0
8/13 23:21
:1
4
skodak Exp $
///////////////////////////////////////////////////////////////////////////
// //
...
...
@@ -42,7 +42,7 @@ Many ideas and code were taken from other Moodle modules and Moodle itself;-)
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
...
...
@@ -110,5 +110,11 @@ CHANGELOG:
* 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
coursefiles.php
View file @
c6d2eda2
<?php
// $Id: coursefiles.php,v 1.
2
200
7
/0
5/20 06:00:26
skodak Exp $
<?php
// $Id: coursefiles.php,v 1.
3
200
8
/0
8/13 23:21:13
skodak Exp $
// Manage all uploaded files in a course file area
...
...
@@ -126,7 +126,7 @@
admin_externalpage_print_header
(
$adminroot
);
print_heading
(
get_string
(
"publicsitefileswarning"
),
"center"
,
2
);
}
}
else
{
...
...
@@ -198,7 +198,7 @@
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
\"
/>"
;
...
...
@@ -211,7 +211,7 @@
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
\"
/>"
;
...
...
db/access.php
0 → 100644
View file @
c6d2eda2
<?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
),
);
?>
edit.html
deleted
100644 → 0
View file @
817e3a80
<!-- $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>
edit.php
View file @
c6d2eda2
<?PHP
// $Id: edit.php,v 1.
3
2008/0
3/25 20:19:49 poltawski
Exp $
<?PHP
// $Id: edit.php,v 1.
4
2008/0
8/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
(
'
chapter
id'
,
0
,
PARAM_INT
);
// Chapter ID
$
cm
id
=
required_param
(
'
cm
id'
,
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'
,
$
cm
id
))
{
error
(
'Course Module ID was incorrect'
);
}
...
...
@@ -21,88 +21,83 @@ if (!$course = get_record('course', 'id', $cm->course)) {
error
(
'Course is misconfigured'
);
}
require_login
(
$course
,
false
,
$cm
);
$context
=
get_context_instance
(
CONTEXT_MODULE
,
$cm
->
id
);
require_capability
(
'mo
odle/course:manageactivities
'
,
$context
);
require_capability
(
'mo
d/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
;
}
...
...
@@ -112,30 +107,18 @@ $strbooks = get_string('modulenameplural', 'book');
$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
);
...
...
edit_form.php
0 → 100644
View file @
c6d2eda2
<?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'
);
}
}
}
}
?>
generateimscp.php
View file @
c6d2eda2
<?PHP
// $Id: generateimscp.php,v 1.
2
200
7
/0
5/20 06:00:26
skodak Exp $
<?PHP
// $Id: generateimscp.php,v 1.
3
200
8
/0
8/13 23:21:14
skodak Exp $
///////////////////////////////////////////////////////////////////////////
// //
...
...
@@ -24,15 +24,13 @@
// //
///////////////////////////////////////////////////////////////////////////
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'
);
}
...
...
@@ -41,9 +39,12 @@ if (!$course = get_record('course', 'id', $cm->course)) {
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'
);
}
...
...
@@ -71,7 +72,7 @@ add_to_log($course->id, 'book', 'generateimscp', 'generateimscp.php?id='.$cm->id
/// 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
...
...
@@ -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
*/
function
chapter2html
(
$chapter
,
$courseid
,
$bookid
)
{
...
...
import.php
View file @
c6d2eda2
<?PHP
// $Id: import.php,v 1.
4
2008/0
3/25 20:19:49 poltawski
Exp $
<?PHP
// $Id: import.php,v 1.
5
2008/0
8/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'
);
...
...
@@ -20,8 +18,10 @@ if (!$course = get_record('course', 'id', $cm->course)) {
error
(
'Course is misconfigured'
);
}
require_login
(
$course
,
false
,
$cm
);
$context
=
get_context_instance
(
CONTEXT_MODULE
,
$cm
->
id
);
require_capability
(
'mo
odle/course:manageactivities
'
,
$context
);
require_capability
(
'mo
d/book:import
'
,
$context
);
if
(
!
$book
=
get_record
(
'book'
,
'id'
,
$cm
->
instance
))
{
error
(
'Course module is incorrect'
);
...
...
@@ -34,12 +34,6 @@ unset($id);
// 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'
);
...
...
@@ -50,22 +44,26 @@ $navlinks[] = array('name' => $strimport, 'link' => '', 'type' => 'title');
$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
...
...
@@ -81,14 +79,16 @@ if (($form = data_submitted()) && (confirm_sesskey())) {
}
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
)
{
...
...
@@ -102,7 +102,7 @@ if (($form = data_submitted()) && (confirm_sesskey())) {
$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
;
...
...
@@ -115,64 +115,28 @@ if (($form = data_submitted()) && (confirm_sesskey())) {
}
}
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
);