File: edit.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 (97 lines) | stat: -rw-r--r-- 2,976 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php // $Id: edit.php,v 1.25.2.1 2006/08/10 15:30:54 skodak Exp $

    require_once("../../config.php");

    $id = required_param('id', PARAM_INT);    // Course Module ID

    if (! $cm = get_coursemodule_from_id('journal', $id)) {
        error("Course Module ID was incorrect");
    }

    if (! $course = get_record("course", "id", $cm->course)) {
        error("Course is misconfigured");
    }

    require_login($course->id, false, $cm);

    if (isguest()) {
        error("Guests are not allowed to edit journals", $_SERVER["HTTP_REFERER"]);
    }

    if (! $journal = get_record("journal", "id", $cm->instance)) {
        error("Course module is incorrect");
    }

    $entry = get_record("journal_entries", "userid", $USER->id, "journal", $journal->id);


/// If data submitted, then process and store.

    if ($form = data_submitted()) {

        $timenow = time();

        //$form->text = clean_text($form->text, $form->format);

        if ($entry) {
            $newentry->id = $entry->id;
            $newentry->text = $form->text;
            $newentry->format = $form->format;
            $newentry->modified = $timenow;
            if (! update_record("journal_entries", $newentry)) {
                error("Could not update your journal");
            }
            add_to_log($course->id, "journal", "update entry", "view.php?id=$cm->id", "$newentry->id", $cm->id);
        } else {
            $newentry->userid = $USER->id;
            $newentry->journal = $journal->id;
            $newentry->text = $form->text;
            $newentry->format = $form->format;
            $newentry->modified = $timenow;
            if (! $newentry->id = insert_record("journal_entries", $newentry)) {
                error("Could not insert a new journal entry");
            }
            add_to_log($course->id, "journal", "add entry", "view.php?id=$cm->id", "$newentry->id", $cm->id);
        }

        redirect("view.php?id=$cm->id");
        die;
    }

/// Otherwise fill and print the form.

    $strjournal = get_string("modulename", "journal");
    $strjournals = get_string("modulenameplural", "journal");
    $stredit = get_string("edit");

    if ($usehtmleditor = can_use_richtext_editor()) {
        $defaultformat = FORMAT_HTML;
    } else {
        $defaultformat = FORMAT_MOODLE;
    }

    if (empty($entry)) {
        $entry->text = "";
        $entry->format = $defaultformat;
    }

    print_header_simple(format_string($journal->name), "",
                 "<a href=\"index.php?id=$course->id\">$strjournals</a> ->
                  <a href=\"view.php?id=$cm->id\">".format_string($journal->name,true)."</a> -> $stredit", "",
                  "", true, "", navmenu($course, $cm));

    echo "<center>\n";

    print_simple_box( format_text($journal->intro, $journal->introformat) , "center");

    echo "<br />";

    include("edit.html");

    if ($usehtmleditor) {
        use_html_editor("text");
    }

    print_footer($course);

?>