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