3 require_once("../../config.php");
5 $id = required_param('id', PARAM_INT
); // Course Module ID
7 if (! $cm = get_coursemodule_from_id('journal', $id)) {
8 error("Course Module ID was incorrect");
11 if (! $course = get_record("course", "id", $cm->course
)) {
12 error("Course is misconfigured");
15 require_login($course->id
, false, $cm);
18 error("Guests are not allowed to edit journals", $_SERVER["HTTP_REFERER"]);
21 if (! $journal = get_record("journal", "id", $cm->instance
)) {
22 error("Course module is incorrect");
25 $entry = get_record("journal_entries", "userid", $USER->id
, "journal", $journal->id
);
28 /// If data submitted, then process and store.
30 if ($form = data_submitted()) {
34 //$form->text = clean_text($form->text, $form->format);
37 $newentry->id
= $entry->id
;
38 $newentry->text
= $form->text
;
39 $newentry->format
= $form->format
;
40 $newentry->modified
= $timenow;
41 if (! update_record("journal_entries", $newentry)) {
42 error("Could not update your journal");
44 add_to_log($course->id
, "journal", "update entry", "view.php?id=$cm->id", "$newentry->id", $cm->id
);
46 $newentry->userid
= $USER->id
;
47 $newentry->journal
= $journal->id
;
48 $newentry->text
= $form->text
;
49 $newentry->format
= $form->format
;
50 $newentry->modified
= $timenow;
51 if (! $newentry->id
= insert_record("journal_entries", $newentry)) {
52 error("Could not insert a new journal entry");
54 add_to_log($course->id
, "journal", "add entry", "view.php?id=$cm->id", "$newentry->id", $cm->id
);
57 redirect("view.php?id=$cm->id");
61 /// Otherwise fill and print the form.
63 $strjournal = get_string("modulename", "journal");
64 $strjournals = get_string("modulenameplural", "journal");
65 $stredit = get_string("edit");
67 if ($usehtmleditor = can_use_richtext_editor()) {
68 $defaultformat = FORMAT_HTML
;
70 $defaultformat = FORMAT_MOODLE
;
75 $entry->format
= $defaultformat;
78 $navigation = build_navigation($stredit, $cm);
79 print_header_simple(format_string($journal->name
), "", $navigation, "",
80 "", true, "", navmenu($course, $cm));
84 print_simple_box( format_text($journal->intro
, $journal->introformat
) , "center");
91 use_html_editor("text");
94 print_footer($course);