File: delete.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (57 lines) | stat: -rw-r--r-- 2,174 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

/******************* delete ************************************/

     if (!isteacher($course->id)) {
        error("Only teachers can look at this page");
    }

    confirm_sesskey();

    $pageid = required_param('pageid', PARAM_INT);
    if (!$thispage = get_record("lesson_pages", "id", $pageid)) {
        error("Delete: page record not found");
    }

    print_string("deleting", "lesson");
    // first delete all the associated records...
    delete_records("lesson_attempts", "pageid", $pageid);
    // ...now delete the answers...
    delete_records("lesson_answers", "pageid", $pageid);
    // ..and the page itself
    delete_records("lesson_pages", "id", $pageid);

    // repair the hole in the linkage
    if (!$thispage->prevpageid) {
        // this is the first page...
        if (!$page = get_record("lesson_pages", "id", $thispage->nextpageid)) {
            error("Delete: next page not found");
        }
        if (!set_field("lesson_pages", "prevpageid", 0, "id", $page->id)) {
            error("Delete: unable to set prevpage link");
        }
    } elseif (!$thispage->nextpageid) {
        // this is the last page...
        if (!$page = get_record("lesson_pages", "id", $thispage->prevpageid)) {
            error("Delete: prev page not found");
        }
        if (!set_field("lesson_pages", "nextpageid", 0, "id", $page->id)) {
            error("Delete: unable to set nextpage link");
        }
    } else {
        // page is in the middle...
        if (!$prevpage = get_record("lesson_pages", "id", $thispage->prevpageid)) {
            error("Delete: prev page not found");
        }
        if (!$nextpage = get_record("lesson_pages", "id", $thispage->nextpageid)) {
            error("Delete: next page not found");
        }
        if (!set_field("lesson_pages", "nextpageid", $nextpage->id, "id", $prevpage->id)) {
            error("Delete: unable to set next link");
        }
        if (!set_field("lesson_pages", "prevpageid", $prevpage->id, "id", $nextpage->id)) {
            error("Delete: unable to set prev link");
        }
    }
    redirect("view.php?id=$cm->id", get_string('deletedpage', 'lesson'));
?>