Added navmenu for journal edit page
[moodle.git] / mod / journal / edit.php
1 <?PHP // $Id$
3         require("../../config.php");
5     require_variable($id);    // Course Module ID
7     if (! $cm = get_record("course_modules", "id", $id)) {
8         error("Course Module ID was incorrect");
9     }
11     if (! $course = get_record("course", "id", $cm->course)) {
12         error("Course is misconfigured");
13     }
15     require_login($course->id);
17     if (isguest()) {
18         error("Guests are not allowed to edit journals", $HTTP_REFERER);
19     }
21     if (! $journal = get_record("journal", "id", $cm->instance)) {
22         error("Course module is incorrect");
23     }
25     $entry = get_record_sql("SELECT * FROM journal_entries 
26                              WHERE user='$USER->id' AND journal='$journal->id'");
29 /// If data submitted, then process and store.
31         if (match_referer() && isset($HTTP_POST_VARS)) {
33                 $timenow = time();
35         $text = clean_text($text, $format);
37                 if ($entry) {
38             $newentry->id = $entry->id;
39             $newentry->text = $text;
40             $newentry->modified = $timenow;
41             $newentry->format = $format;
42                         if (! update_record("journal_entries", $newentry)) {
43                                 error("Could not update your journal");
44                         }
45             add_to_log($course->id, "journal", "update entry", "view.php?id=$cm->id", "$newentry->id");
46                 } else {
47             $newentry->user = $USER->id;
48             $newentry->journal = $journal->id;
49             $newentry->modified = $timenow;
50             $newentry->text = $text;
51             $newentry->format = $format;
52                         if (! $newentry->id = insert_record("journal_entries", $newentry)) {
53                                 error("Could not insert a new journal entry");
54                         }
55             add_to_log($course->id, "journal", "add entry", "view.php?id=$cm->id", "$newentry->id");
56                 } 
57                 
58                 redirect("view.php?id=$cm->id");
59                 die;
60         }
62 /// Otherwise fill and print the form.
64     $strjournal = get_string("modulename", "journal");
65     $strjournals = get_string("modulenameplural", "journal");
66     $stredit = get_string("edit");
68     if ($usehtmleditor = can_use_richtext_editor()) {
69         $defaultformat = FORMAT_HTML;
70         $onsubmit = "onsubmit=\"copyrichtext(theform.text);\"";
71     } else {
72         $defaultformat = FORMAT_MOODLE;
73     }
75     if (! $entry ) {
76         $entry->text = "";
77         $entry->format = $defaultformat;
78     }
80     print_header("$course->shortname: $journal->name", "$course->fullname",
81                  "<A HREF=/course/view.php?id=$course->id>$course->shortname</A> -> 
82                   <A HREF=/mod/journal/index.php?id=$course->id>$strjournals</A> -> 
83                   <A HREF=\"view.php?id=$cm->id\">$journal->name</A> -> $stredit", "form.text",
84                   "", true, "", navmenu($course, $cm));
86     echo "<CENTER>\n";
88     print_simple_box( text_to_html($journal->intro) , "center");
90     echo "<BR>";
92         include("edit.html");
94     print_footer($course);
96 ?>