conversion to 2.0
[moodle.git] / delete.php
CommitLineData
8d623d14 1<?php
02039379
PS
2
3require('teacheraccess.php'); //page only for teachers
e355240d
PS
4
5require_once($CFG->dirroot.'/mod/book/locallib.php');
6
02039379
PS
7$confirm = optional_param('confirm', 0, PARAM_BOOL);
8
9
10///header and strings
11$strbooks = get_string('modulenameplural', 'book');
12$strbook = get_string('modulename', 'book');
13
50c53e20 14$navigation = build_navigation('', $cm);
02039379 15
50c53e20 16print_header("$course->shortname: $book->name", $course->fullname, $navigation);
02039379
PS
17
18///form processing
19if ($confirm) { // the operation was confirmed.
20 if (!$chapter->subchapter) { //delete all its subchapters if any
21 $chapters = get_records('book_chapters', 'bookid', $book->id, 'pagenum', 'id, subchapter');
22 $found = false;
23 foreach($chapters as $ch) {
2ced61eb 24 if ($ch->id == $chapter->id) {
02039379
PS
25 $found = true;
26 } else if ($found and $ch->subchapter) {
27 if (!delete_records('book_chapters', 'id', $ch->id)) {
28 error('Could not update your book');
29 }
30 } else if ($found) {
31 break;
32 }
33 }
34 }
35 if (!delete_records('book_chapters', 'id', $chapter->id)) {
36 error('Could not update your book');
37 }
38
39 add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id);
40 add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id, $book->id, $cm->id);
41 book_check_structure($book->id);
42 redirect('view.php?id='.$cm->id);
43 die;
44} else {
45 // the operation has not been confirmed yet so ask the user to do so
46 if ($chapter->subchapter) {
47 $strconfirm = get_string('confchapterdelete','book');
48 } else {
49 $strconfirm = get_string('confchapterdeleteall','book');
50 }
51 echo '<br />';
52 notice_yesno("<b>$chapter->title</b><p>$strconfirm</p>",
53 "delete.php?id=$cm->id&chapterid=$chapter->id&confirm=1&sesskey=$USER->sesskey",
54 "view.php?id=$cm->id&chapterid=$chapter->id");
55}
56
57print_footer($course);