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
e2790e4b
Commit
e2790e4b
authored
Jan 16, 2011
by
Petr Skoda
Browse files
improt conversion and other cleanup
parent
7a395b89
Changes
4
Hide whitespace changes
Inline
Side-by-side
edit.php
View file @
e2790e4b
...
...
@@ -32,10 +32,6 @@ $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
// =========================================================================
$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
);
...
...
@@ -47,10 +43,6 @@ require_capability('mod/book:edit', $context);
$PAGE
->
set_url
(
'/mod/book/edit.php'
,
array
(
'cmid'
=>
$cmid
,
'id'
=>
$chapterid
,
'pagenum'
=>
$pagenum
,
'subchapter'
=>
$subchapter
));
// =========================================================================
// security checks END
// =========================================================================
if
(
$chapterid
)
{
$chapter
=
$DB
->
get_record
(
'book_chapters'
,
array
(
'id'
=>
$chapterid
,
'bookid'
=>
$book
->
id
),
'*'
,
MUST_EXIST
);
}
else
{
...
...
import.php
View file @
e2790e4b
...
...
@@ -19,7 +19,7 @@
*
* @package mod
* @subpackage book
* @copyright 2004-201
0
Petr Skoda {@link http://skodak.org}
* @copyright 2004-201
1
Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
...
...
@@ -27,13 +27,8 @@ require('../../config.php');
require_once
(
$CFG
->
dirroot
.
'/mod/book/locallib.php'
);
require_once
(
'import_form.php'
);
$id
=
required_param
(
'id'
,
PARAM_INT
);
// Course Module ID
die
(
'Not converted to 2.0 yet, sorry'
);
// =========================================================================
// security checks START - only teachers edit
// =========================================================================
$id
=
required_param
(
'id'
,
PARAM_INT
);
// Course Module ID
$chapterid
=
optional_param
(
'chapterid'
,
0
,
PARAM_INT
);
// Chapter ID
$cm
=
get_coursemodule_from_id
(
'book'
,
$id
,
0
,
false
,
MUST_EXIST
);
$course
=
$DB
->
get_record
(
'course'
,
array
(
'id'
=>
$cm
->
course
),
'*'
,
MUST_EXIST
);
...
...
@@ -44,37 +39,40 @@ require_login($course, false, $cm);
$context
=
get_context_instance
(
CONTEXT_MODULE
,
$cm
->
id
);
require_capability
(
'mod/book:import'
,
$context
);
$PAGE
->
set_url
(
'/mod/book/import.php'
,
array
(
'id'
=>
$id
));
$PAGE
->
set_url
(
'/mod/book/import.php'
,
array
(
'id'
=>
$id
,
'chapterid'
=>
$chapterid
));
//check all variables
unset
(
$id
);
if
(
$chapterid
)
{
if
(
!
$chapter
=
$DB
->
get_record
(
'book_chapters'
,
array
(
'id'
=>
$chapterid
,
'bookid'
=>
$book
->
id
)))
{
$chapterid
=
0
;
}
}
else
{
$chapter
=
false
;
}
// =========================================================================
// security checks END
// =========================================================================
$PAGE
->
set_title
(
format_string
(
$book
->
name
));
$PAGE
->
add_body_class
(
'mod_book'
);
$PAGE
->
set_heading
(
format_string
(
$course
->
fullname
));
///prepare the page header
$strbook
=
get_string
(
'modulename'
,
'book'
);
$strbooks
=
get_string
(
'modulenameplural'
,
'book'
);
$strimport
=
get_string
(
'import'
,
'book'
);
$navlinks
=
array
();
$navlinks
[]
=
array
(
'name'
=>
$strimport
,
'link'
=>
''
,
'type'
=>
'title'
);
$navigation
=
build_navigation
(
$navlinks
,
$cm
);
$mform
=
new
book_import_form
(
null
,
$cm
);
$mform
->
set_data
(
array
(
'id'
=>
$cm
->
id
));
$mform
=
new
book_import_form
(
null
,
array
(
'id'
=>
$id
,
'chapterid'
=>
$chapterid
));
/// If data submitted, then process and store.
if
(
$mform
->
is_cancelled
())
{
if
(
empty
(
$chapter
->
id
))
{
//TODO: problem
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
))
{
}
else
if
(
$data
=
$mform
->
get_data
())
{
die
(
'TODO'
);
/*
$coursebase = $CFG->dataroot.'/'.$book->course;
$reference = book_prepare_link($data->reference);
...
...
@@ -139,18 +137,13 @@ if ($mform->is_cancelled()) {
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="pix/chapter.gif" alt="" /> '
;
print_heading_with_help
(
$pagehead
ing
,
'import'
,
'book'
,
$icon
);
echo
$OUTPUT
->
header
()
;
echo
$OUTPUT
->
heading
(
get_str
ing
(
'import
ingchapters
'
,
'book'
)
);
$mform
->
display
();
print_footer
(
$course
);
echo
$OUTPUT
->
footer
();
import_form.php
View file @
e2790e4b
...
...
@@ -19,7 +19,7 @@
*
* @package mod
* @subpackage book
* @copyright 2004-201
0
Petr Skoda {@link http://skodak.org}
* @copyright 2004-201
1
Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
...
...
@@ -30,54 +30,30 @@ class book_import_form extends moodleform {
function
definition
()
{
global
$CFG
;
$mform
=
$this
->
_form
;
$
cm
=
$this
->
_customdata
;
$
data
=
$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'
)
.
' ...'
);
$mform
->
addElement
(
'filepicker'
,
'importfile'
,
get_string
(
'file'
));
$mform
->
addRule
(
'importfile'
,
null
,
'required'
);
$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
->
addElement
(
'hidden'
,
'id'
);
$mform
->
setType
(
'id'
,
PARAM_INT
);
$mform
->
addElement
(
'hidden'
,
'chapterid'
);
$mform
->
setType
(
'chapterid'
,
PARAM_INT
);
$this
->
add_action_buttons
(
true
,
get_string
(
'import'
,
'book'
));
$this
->
set_data
(
$data
);
}
function
validation
(
$data
,
$files
)
{
global
$CFG
;
$cm
=
$this
->
_customdata
;
$errors
=
parent
::
validation
(
$data
,
$files
);
$reference
=
$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'
);
}
}
}
//TODO: validate package
return
$errors
;
}
...
...
print.php
View file @
e2790e4b
...
...
@@ -19,7 +19,7 @@
*
* @package mod
* @subpackage book
* @copyright 2004-201
0
Petr Skoda {@link http://skodak.org}
* @copyright 2004-201
1
Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment