[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Delete book chapter 19 * 20 * @package mod_book 21 * @copyright 2004-2011 Petr Skoda {@link http://skodak.org} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require(__DIR__.'/../../config.php'); 26 require_once (__DIR__.'/locallib.php'); 27 28 $id = required_param('id', PARAM_INT); // Course Module ID 29 $chapterid = required_param('chapterid', PARAM_INT); // Chapter ID 30 $confirm = optional_param('confirm', 0, PARAM_BOOL); 31 32 $cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST); 33 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); 34 $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST); 35 36 require_login($course, false, $cm); 37 require_sesskey(); 38 39 $context = context_module::instance($cm->id); 40 require_capability('mod/book:edit', $context); 41 42 $PAGE->set_url('/mod/book/delete.php', array('id'=>$id, 'chapterid'=>$chapterid)); 43 44 $chapter = $DB->get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$book->id), '*', MUST_EXIST); 45 46 47 // Header and strings. 48 $PAGE->set_title($book->name); 49 $PAGE->set_heading($course->fullname); 50 51 // Form processing. 52 if ($confirm) { // the operation was confirmed. 53 $fs = get_file_storage(); 54 if (!$chapter->subchapter) { // Delete all its sub-chapters if any 55 $chapters = $DB->get_recordset('book_chapters', array('bookid'=>$book->id), 'pagenum'); 56 $found = false; 57 foreach ($chapters as $ch) { 58 if ($ch->id == $chapter->id) { 59 $found = true; 60 } else if ($found and $ch->subchapter) { 61 $fs->delete_area_files($context->id, 'mod_book', 'chapter', $ch->id); 62 $DB->delete_records('book_chapters', array('id'=>$ch->id)); 63 \mod_book\event\chapter_deleted::create_from_chapter($book, $context, $ch)->trigger(); 64 } else if ($found) { 65 break; 66 } 67 } 68 $chapters->close(); 69 } 70 $fs->delete_area_files($context->id, 'mod_book', 'chapter', $chapter->id); 71 $DB->delete_records('book_chapters', array('id'=>$chapter->id)); 72 73 \mod_book\event\chapter_deleted::create_from_chapter($book, $context, $chapter)->trigger(); 74 75 book_preload_chapters($book); // Fix structure. 76 $DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id)); 77 78 redirect('view.php?id='.$cm->id); 79 } 80 81 echo $OUTPUT->header(); 82 echo $OUTPUT->heading($book->name); 83 84 // The operation has not been confirmed yet so ask the user to do so. 85 if ($chapter->subchapter) { 86 $strconfirm = get_string('confchapterdelete', 'mod_book'); 87 } else { 88 $strconfirm = get_string('confchapterdeleteall', 'mod_book'); 89 } 90 echo '<br />'; 91 $continue = new moodle_url('/mod/book/delete.php', array('id'=>$cm->id, 'chapterid'=>$chapter->id, 'confirm'=>1)); 92 $cancel = new moodle_url('/mod/book/view.php', array('id'=>$cm->id, 'chapterid'=>$chapter->id)); 93 $title = format_string($chapter->title); 94 echo $OUTPUT->confirm("<strong>$title</strong><p>$strconfirm</p>", $continue, $cancel); 95 96 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |