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